Harris corner detection and localization in OpenCV with Python -
i'm using following code try detect corners of polylines in order 'measure' lines. code based on snippet found somewhere on so , based on cv2.cornerharris():
cornerimg = cv2.cornerharris( gray, # src 2, # blocksize 3, # ksize / aperture 0.04 # k # dst # bordertype ) # ? cornerimg = cv2.normalize( cornerimg, # src none, # dst 0, # alpha 255, # beta cv2.norm_minmax, # norm type cv2.cv_32fc1, # dtype none # mask ) # ? cornerimg = cv2.convertscaleabs( cornerimg ) cornershow = cornerimg.copy() # iterate on pixels corner positions w, h = gray.shape y in range(0, h): x in range (0, w): #harris = cv2.cv.get2d( cv2.cv.fromarray(cornerimg), y, x) #if harris[0] > 10e-06: if cornerimg[x,y] > 64: print("corner @ ", x, y) cv2.circle( cornershow, # dest (x,y), # pos 4, # radius (115,0,25) # color ) cv2.imshow('harris cornerimg', cornershow)
the original code results in white spots @ corner location , level seems indicator of "corneryness". snippet (updated use cv2) iterates on resulting image , scans values lager 10e-06 reason, have replaced comparison of think should brightness in image.
however, circles drawn @ locations near actual hot-spots found in normalized harris output.
what doing wrong?
alternatively, cv2.goodfeaturestotrack() can set use harris (useharrisdetector=true) attempt use not result in cornerharris appears detect properly:
cv2.goodfeaturestotrack( blurred, # img 500, # maxcorners 0.03, # qualitylevel 10, # mindistance none, # corners, none, # mask, 2, # blocksize, useharrisdetector=true, # useharrisdetector, k=0.04 # k )
what equivalent function call cv2.cornerharris()?
the output seems transposed, swapping x , y indices on square image fixes (circles on corner maxima).
Comments
Post a Comment