Corners detection – OpenCV 3.4 with python 3 Tutorial 22

Corners detection image:

[python]
import cv2
import numpy as np

img = cv2.imread("squares.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

corners = cv2.goodFeaturesToTrack(gray, 150, 0.8, 50)
corners = np.int0(corners)

for corner in corners:
x, y = corner.ravel()
cv2.circle(img, (x, y), 5, (0, 0, 255), -1)

cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
[/python]

 

Corners detection Video real time:

[python]
import cv2
import numpy as np

cap = cv2.VideoCapture(0)

def nothing(x):
pass

cv2.namedWindow("Frame")
cv2.createTrackbar("quality", "Frame", 1, 100, nothing)

while True:
_, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

quality = cv2.getTrackbarPos("quality", "Frame")
quality = quality / 100 if quality > 0 else 0.01
corners = cv2.goodFeaturesToTrack(gray, 100, quality, 20)

if corners is not None:
corners = np.int0(corners)

for corner in corners:
x, y = corner.ravel()
cv2.circle(frame, (x, y), 3, (0, 0, 255), -1)

cv2.imshow("Frame", frame)

key = cv2.waitKey(1)
if key == 27:
break

cap.release()
cv2.destroyAllWindows()
[/python]

 

Files:

  1. squares.jpg
Blueprint

Learn to build Computer Vision Software easily and efficiently.

This is a FREE Workshop where I'm going to break down the 4 steps that are necessary to build software to detect and track any object.

Sign UP for FREE