如何解决我正在学习 [python + opencv + mediapipe] Hand Tracking 的教程,但出现以下错误:
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wvn_it83\opencv\modules\imgproc\src\color.cpp:182: 错误: ( -215: 断言失败) !_src.empty() 在函数 'cv::cvtColor' 中import mediapipe as mp
import time
cap = cv2.VideoCapture(1)
mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils
pTime = 0
cTime = 0
while True:
success,img = cap.read()
imgRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
results = hands.process(imgRGB)
# print(results.multi_hand_landmarks)
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
for id,lm in enumerate(handLms.landmark):
# print(id,lm)
h,w,c = img.shape
cx,cy = int(lm.x * w),int(lm.y * h)
print(id,cx,cy)
# if id == 4:
cv2.circle(img,(cx,cy),15,(255,255),cv2.FILLED)
mpDraw.draw_landmarks(img,handLms,mpHands.HAND_CONNECTIONS)
cTime = time.time()
fps = 1 / (cTime - pTime)
pTime = cTime
cv2.putText(img,str(int(fps)),(10,70),cv2.FONT_HERSHEY_PLAIN,3,3)
cv2.imshow("Image",img)
cv2.waitKey(1)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。