我使用的是python3.6,我得到了这个错误
Traceback (most recent call last): File "C:\Users\mchaf\Music\face\facerec_from_webcam_faster.py", line 49, in small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:3784: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
我该怎么解决这个问题? 这是我的行号
from distutils.core import setup
import face_recognition
from cv2 import *
import subprocess
import time
video_capture = cv2.VideoCapture(0)
obama_image = face_recognition.load_image_file("obama.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
biden_image = face_recognition.load_image_file("biden.jpg")
biden_face_encoding = face_recognition.face_encodings(biden_image)[0]
known_face_encodings = [
obama_face_encoding,
biden_face_encoding
]
known_face_names = [
"Barack Obama",
"Joe Biden"
]
face_locations = []
face_encodings = []
face_names = []
process_this_frame = True
while True:
ret, frame = video_capture.read()
small_frame = cv2.resize(frame, (128,128))
rgb_small_frame = small_frame[:, :, ::-1]
if process_this_frame:
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
face_names = []
for face_encoding in face_encodings:
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"
time.sleep(5)
imshow("Operator",frame)
video_capture.release()
cv2.destroyAllWindows()
subprocess.call([r'C:\Users\mchaf\Desktop\run.bat'])
if True in matches:
first_match_index = matches.index(True)
name = known_face_names[first_match_index]
face_names.append(name)
process_this_frame = not process_this_frame
for (top, right, bottom, left), name in zip(face_locations, face_names):
top *= 4
right *= 4
bottom *= 4
left *= 4
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
尝试将帧处理置于这种情况下
并用删除行
^{pr2}$它看起来你的框架是空的,这就是为什么你不能调整大小 原因是你从你的网络摄像头中释放了捕获(某种程度上是断开连接)。释放后,你想阅读新的框架,但它是空的
你的代码显然是从不同的地方复制的。即使你纠正了这些,你的代码也不会工作。在
例如:
相关问题 更多 >
编程相关推荐