Harris corner detection demo

In [ ]:
#Ref: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html
In [5]:
# tested on 3.4.2
import cv2
cv2.__version__
Out[5]:
'3.4.2'
In [12]:
import cv2
import platform

cap=cv2.VideoCapture(0)


# Detector parameters
blockSize = 2
apertureSize = 3
k = 0.04

while (True):
    
    ret,frame=cap.read()
    
    cv2.namedWindow("camera",cv2.WND_PROP_FULLSCREEN)
    cv2.setWindowProperty("camera",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
    
    gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY);
    
    dst = cv2.cornerHarris(gray, blockSize, apertureSize, k)
    
    #result is dilated for marking the corners, not important
    dst = cv2.dilate(dst,None)

    # Threshold for an optimal value, it may vary depending on the image.
    frame[dst>0.01*dst.max()]=[0,0,255]
    
    cv2.imshow('camera',frame)
    
    if cv2.waitKey(1) &0xFF == ord('q'): # press q or ESC to quit. You probably need to hit the screen first
        break

        
cap.release()
cv2.destroyAllWindows()