这是我正在研究的一个学校项目。我想检测并提取角落的坐标。由于这是一个屏幕截图,事物会移动,所以我想保留在运动过程中没有丢失的点,并得到新的坐标。请帮助我。
我正在使用python
目前我正在使用它进行角点检测,如果某人有更快的方法请告诉我:
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
答案 0 :(得分:0)
您可以使用此链接来解决您的问题。
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)