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.