How to detect vertical and horizontal lines ? i know opencv provide the function based on hough transform to detect all direction lines,but it`s low_performance to compute all direction lines because i just want to dectect Ver and Hon lines .Any suggestion, thanks!
HoughLinesP is the easiest approach. You can filter out the angles that aren't horizontal or vertical.
However, if you want to use a potentially faster approach that only detects certain angles, you can try cv::Sobel. There's some sample code here that detects vertical and horizontal edges:
http://subversion.assembla.com/svn/CoffeeWatcher/trunk/ImageUtils.cpp
Related
I'm trying to automatically detect if an image is a collage vs a single photograph. I'm not too concerned with edge cases. What I'm trying to solve is rectangular collages like below. I've tried edge detection (canny) + vertical and horizontal sobel filtering + line detection (Hough transform) to try to identify perpendicular lines but am getting too many false positives. I'm not very good at image processing so any input would be welcome. Thx!
This is a challenge, because images "have the right" to contain verticals and horizontals, and there can be sudden changes in the background due to occlusion for instance.
But a clue can help you: the borders between two pictures are perfectly straight, "unnaturally" straight, and they are long.
I'm trying to write an algorithm to detect blobs using connected component labeling on an image. I'm having difficulty on how to merge different labels if they are connected diagonally. Doing it for horizontally and vertically connected pixels seems easy . But i can't figure out a way to detect the pixels that are connected diagonally .because if it changes then there is a need to relabel the image w.r.t to that change for each changed pixel . I'm confused . Can you explain me how to handle this. I may be totally wrong about what i said (but i have achieved reasonable results doing only the horizontal and vertical connected components) , but it isn't the correct way. please advice to how to approach connected component labeling accurately. I'm only using arrays of image dimensions for comparing and labelling.
Well you are able to do horizontal and vertical, just add another direction for the diagonal, so you are looking for neighboring pixels in all directions as opposed just to vertical and horizontal.
I have an airplane. I use rectangle for bounding this airplane to detect collision and it works great. When the airplane begin falling down I rotate airplane's texture, but rectangle remains unchanged. I don't know how to rotate it. I need to rotate it with airplane's texture because my shell doesn't collide the airplane's tail and cabine.
How to rotate rectangle or perhaps create polygon shape to wrap all airplane? Any help will be appreciated!
#jellyfication's answer points to raycasting, but a different and also simple approach you could implement is the Separating Axis Theorem. The links below will show you in detail what the algorithm is about and how to implement it. They also have some interactive demos so you get the 'feel' for what the algorithm is doing.
http://www.metanetsoftware.com/technique/tutorialA.html
http://www.sevenson.com.au/actionscript/sat/
http://www.codezealot.org/archives/55 (this one has a lot of code)
http://gamedev.tutsplus.com/tutorials/implementation/collision-detection-with-the-separating-axis-theorem/
Good luck!
Use the polygon class to and draw your bounding Box.
Then within the polygon class there is a method to rotate.
Rotate and move the polygon with the plane.
Is there a way to draw a triangle with line only ?
I think GL_TRIANGLES option make triangle filled with color.
Set the fill mode with glPolygonMode(face, model):
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
You have to set this every frame
Is there a way to draw a triangle with line only?
Use GL_LINES, GL_LINE_STRIP , or GL_LINE_LOOP (difference see here) with the same vertices that you use for GL_TRIANGLES.
if you are only rendering a single triangle at a time you can use GL_LINE_LOOP. it will connect the first and last, so if you have more than one triangle, it won't work.
I was wondering if anyone knew of any algorithm to draw a line with specific thickness, based on Bresenham's line algorithm or any similar.
On a second thought, I've been wondering about for each setPixel(x,y) I'd just draw a circle, e.g.:
filledCircle(x,y,thickness); for every x,y but that would of course be very slow. I also tried to use dictionary but that would fill the memory in no time. Check the pixels I'm about to draw on if they have the same color, but that's also not efficient enough for large brushes.
Perhaps I could somehow draw half circles depending on the angle?
Any input would be appreciated.
Thanks.
duplicate: how do I create a line of arbitrary thickness using Bresenham?
You cannot actually draw circles along the line. This approach is patented. :)
You can still read patent for inspiration.
I don't know what is commonly used, but it seems to me that you could use Bresenham for the 1-pixel-wide line, but extend it a set number of pixels vertically or horizonally. For instance, suppose your line is roughly 30 degrees away from the horizontal, and you want it to be four pixels wide. You calculate that the vertical thickness of the line should be five pixels. You run Bresenham, but for each pixel (x,y), you actually draw (x,y), (x,y+1), ... (x,y+4). And if you want the ends of the line to be rounded, draw a circle at each end.
For overkill, make a pixel map of the stylus (a circle or diagonal nib, or whatever), then draw a set of parallel Bresenham lines, one for each pixel in the stylus.
There are variations on Bresenhams which calculate pixel coverage, such as those used in the anti-grain geometry libraries; whether you want something that quality - you don't say what the output medium is, and most systems more capable than on-off LCDS support pens with thickness anyway.