One of the most used tool for corner detection is the Harris Corner Detector operator. OpenCV provide a function that implement this operator. The name of the function is CornerHarris(...) and the corners in the image can be found as the local maxima of the returned image. Let's see how to use it in Python:
imcolor = cv.LoadImage('stairs.jpg') image = cv.LoadImage('stairs.jpg',cv.CV_LOAD_IMAGE_GRAYSCALE) cornerMap = cv.CreateMat(image.height, image.width, cv.CV_32FC1) # OpenCV corner detection cv.CornerHarris(image,cornerMap,3) for y in range(0, image.height): for x in range(0, image.width): harris = cv.Get2D(cornerMap, y, x) # get the x,y value # check the corner detector response if harris[0] > 10e-06: # draw a small circle on the original image cv.Circle(imcolor,(x,y),2,cv.RGB(155, 0, 25)) cv.NamedWindow('Harris', cv.CV_WINDOW_AUTOSIZE) cv.ShowImage('Harris', imcolor) # show the image cv.SaveImage('harris.jpg', imcolor) cv.WaitKey()The following image is the result of the program:
The red markers are the corners found by the OpenCV's function.
Ok for the method, but it would have been much nicer with some toughtbacks, wouldn't it?
ReplyDeleteOpenCV do contain lots of "magical" functions like this one. And more and more people use it without knowing what they. And so they finally become really "magic" ^^
Simple thought for example, why did you choose this exact threshold?
And what can you use your output for?
Hi jlengrand, thanks for your comment.
ReplyDeleteUsually I put a links that contains the theoretical background of the post and sometimes I try to explain what's under the hood by myself. Anyway, the original purpose of this blog is to provide snippets that you can reuse in another program just modifying some lines.
And it is nice to have :).
ReplyDeleteI think we do miss open source code for image processing in Python.
So you are doing it the right way :).
What I don't like (if you subscribe to the opencv channel you must have seen it) is the huge number of people using this code without thinking about it and posting for any dumm typo problem...
See what I mean ?
Are you writing a lots of code for IP in Python?
Yes, I am writing lots of code using opencv because I'm involved in various computer vision projects.
ReplyDeleteI'm not subscribed to the opencv channel, but I agree with you. You need a strong mathematical background to understand how opencv's functions work and some people use it without.
By the way, the main lack of OpenCV is that there's few examples in Python and sometimes the documentation is not enough to understand how to use some of its function.
I clearly agree.
ReplyDeleteI have worked on computer vision for some time, in several langagues (most with Matlab though), and I really felt in love with Python/OpenCV.
I hope it could somehow outfit the Matlab image processing toolbox.
I am currently writing lots of functions in order to reduce the amount of code needed to deploy applications in Python, based on my matlab experience.
I hope it will promoting Computer Vision :).
Is there a list of IP projects you are involved in somewhere? I would love to know about them
I'm sorry, at moment I can't share any official documentation.
ReplyDeleteKeep in touch via twitter or linkedin.
It is very helpful. Thanks :-)
ReplyDeleteThaks for this help
ReplyDeleteHI, could you please post the java equivalent code?
ReplyDeleteHi Tharaka, you can take a look at this:
Deletehttp://svg.dmi.unict.it/iplab/imagej/Plugins/Feature%20Point%20Detectors/Harris/harris.htm