OPEN-CV错误:(-215:断言失败)函数'cv :: resize'中的!ssize.empty()

时间:2019-11-07 18:23:52

标签: python opencv face-recognition

我正在尝试从流式视频中获取图像,并且花了几分钟,但是随后出现以下错误: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摄像机获取视频流

1 个答案:

答案 0 :(得分:0)

读取帧失败。当您进行框架读取时,它会返回该框架和一个布尔值,指示读取是否成功-以测试/预防您所面临的问题。

尝试一下:

ret, frame = video_capture.read()

if ret:
    [frame processing code]