Extraction of coordinates of corners using Harris Corner detection ,and also retention of coordinates of points not lost during movement

Viewed 2303

Its a school project i am working on .I want to detect and extract coordinates of corners .As this is a screen capture ,things will move ,so i want to retain the points that are not lost during the movement ,and get the new coordinates .Please help me .

I am using python

Currently I am using this for corner detection,if someone has a faster method please let me know :

import numpy as np
from PIL import ImageGrab
import cv2
import time

last_time=time.time()
while(True):
    screen = np.array(ImageGrab.grab(bbox=(0,40,800,640)))
    print ('Loop took {} seconds'.format(time.time()-last_time))
    last_time=time.time()
    gray=cv2.cvtColor(screen,cv2.COLOR_BGR2GRAY)
    gray=np.float32(gray)
    dst=cv2.cornerHarris(gray,2,3,0.04)
    dst=cv2.dilate(dst,None)
    screen[dst>0.01*dst.max()]=[0,0,255]


    cv2.imshow('window',screen)
    if cv2.waitKey(25) & 0xFF== ord('q') :
         cv2.destroyAllWindows()
         break
1 Answers

You can use this link which has answer to your problem.

http://answers.opencv.org/question/186538/to-find-the-coordinates-of-corners-detected-by-harris-corner-detection/

import cv2
import numpy as np

filename = '1.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)
#here u can get corners
print (corners)

#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('1.png',img)
Related