import numpy as np
import cv2
import matplotlib.pyplot as plt
cam=cv2.VideoCapture(1)
while True:
ret,frame=cam.read()
#cv2.imshow('frame',frame)
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
gray=np.float32(gray)
#cv2.imshow('gray',gray)
corners=cv2.goodFeaturesToTrack(gray,10,0.01,10)
corners=np.int0(corners)
for corner in corners:
x,y=corner.ravel()
cv2.circle(frame,(x,y),4,255,-1)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
cv2.destroyAllWindows()
这是我使用Shi-Tomasi算法进行角点检测的代码。与我的一个网络摄像头完美结合的代码,但是当我与另一个网络摄像头一起运行时显示错误。 我收到一个错误:
Traceback (most recent call last):
File "C:/Users/IESHAAN .LAPTOP-
U40CT3MF/AppData/Local/Programs/Python/Python36-32/progs/imcorner.py", line
20, in <module>
corners=np.int0(corners)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
据我了解,使用第二台相机时,灰色返回无。我不明白为什么会这样。