我正在尝试从流式视频中获取图像,并且花了几分钟,但是随后出现以下错误:cv2.error:OpenCV(4.1.1)C:\ projects \ opencv-python \ opencv \ modules \ imgproc \ src \ resize.cpp:3720:错误:(-215:断言失败)!函数'cv :: resize'中的ssize.empty()我的代码:
while True:
ret, frame = video_capture.read()
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1]
#
if process_this_frame:
face_locations = face_recognition.face_locations(rgb_small_frame, number_of_times_to_upsample=2)
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 = "None"
# #
# if True in matches:
# first_match_index = matches.index(True)
# name = known_face_names[first_match_index]
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
name = known_face_names[best_match_index]
face_names.append(name)
if matches[best_match_index]:
adicionar_json()
process_this_frame = not process_this_frame
font = cv2.FONT_ITALIC
for (top, right, bottom, left), name in zip(face_locations, face_names):
top *= 4
right *= 4
bottom *= 4
left *= 4
我正在尝试从rtsp摄像机获取视频流
这是不成功的框架读取。当您进行框架读取时,它将返回该框架和一个布尔值,指示读取是否成功-测试/防止您遇到的问题。
尝试一下:
ret, frame = video_capture.read()
if ret:
[frame processing code]