Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

import cv2 import numpy as np

filename = 'chessboard2.jpg' img = cv2.imread(filename) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

find Harris corners

gray = np.float32(gray) dst = cv2.cornerHarris(gray,2,3,0.04) dst = cv2.dilate(dst,None) ret, dst = cv2.threshold(dst,0.01*dst.max(),255,0) dst = np.uint8(dst)

find centroids

ret, labels, stats, centroids = cv2.connectedComponentsWithStats(dst)

define the criteria to stop and refine the corners

criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001) corners = cv2.cornerSubPix(gray,np.float32(centroids),(5,5),(-1,-1),criteria) print corners #here u can get corners check for more information follow the link...........http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html

Now draw them

res = np.hstack((centroids,corners)) res = np.int0(res) img[res[:,1],res[:,0]]=[0,0,255] img[res[:,3],res[:,2]] = [0,255,0]

cv2.imwrite('subpixel5.png',img)

click to hide/show revision 2
No.2 Revision

updated 2018-12-14 03:05:49 -0600

berak gravatar image

.

import cv2
import numpy as np

np

filename = 'chessboard2.jpg' img = cv2.imread(filename) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# find Harris corners

corners gray = np.float32(gray) dst = cv2.cornerHarris(gray,2,3,0.04) dst = cv2.dilate(dst,None) ret, dst = cv2.threshold(dst,0.01*dst.max(),255,0) dst = np.uint8(dst)

np.uint8(dst)

# find centroids

centroids ret, labels, stats, centroids = cv2.connectedComponentsWithStats(dst)

cv2.connectedComponentsWithStats(dst)

# define the criteria to stop and refine the corners

corners criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001) corners = cv2.cornerSubPix(gray,np.float32(centroids),(5,5),(-1,-1),criteria) print corners #here u can get corners check for more information follow the link...........http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html

link...........http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html # Now draw them

them res = np.hstack((centroids,corners)) res = np.int0(res) img[res[:,1],res[:,0]]=[0,0,255] img[res[:,3],res[:,2]] = [0,255,0]

[0,255,0] cv2.imwrite('subpixel5.png',img)

cv2.imwrite('subpixel5.png',img)