Learn Before
Drawing Detected Corners in OpenCV
Once we have the NumPy array of floating-point coordinates for the detected corners, we convert them from floats to ints so they can serve as pixel positions. The ravel() method flattens each corner array (for example [[0,1],[2,3]] becomes [0,1,2,3]), letting us unpack the x and y values directly. python corners = np.int0(corners) for corner in corners: x, y = corner.ravel() cv2.circle(img, (x, y), 5, (255, 0, 0), -1) Note that if the image is still grayscale, a colored (BGR) drawing parameter will not display correctly. To make the corners more obvious, we can also draw lines connecting every pair of corners: python for i in range(len(corners)): for j in range(i + 1, len(corners)): corner1 = tuple(corners[i][0]) corner2 = tuple(corners[j][0]) cv2.line(img, corner1, corner2, (255, 0, 0), 1) The [0] indexing is only needed when the corner array has not been flattened.
0
1
Contributors are:
Who are from:
Tags
Python Programming Language
Data Science