簡體   English   中英

small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

[英]small_frame = cv2.resize(frame, (128,128)) cv2.error: OpenCV(3.4.5) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

我正在使用 python 3.6,但出現此錯誤

回溯(最近一次調用):文件“C:\\Users\\mchaf\\Music\\face\\facerec_from_webcam_faster.py”,第 49 行,在 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()

嘗試將幀處理置於此條件下

if ret:
    cv2.resize...

並刪除行

Video_capture.release()
cv2.destroyAllWindows()

看起來您的框架是空的,這就是您無法調整大小的原因是您從網絡攝像頭中釋放了捕獲(某種斷開連接)。 釋放后你想讀取新幀但它是空的

您的代碼顯然是從不同地方復制的。 即使你更正了這些你的代碼也不會工作。

例如:

...
name = "Unknown"
time.sleep(5) # Why sleep? 
imshow("Operator",frame) # OpenCV cv2 class is missing
video_capture.release() # Why you release the capture? - main error
cv2.destroyAllWindows()   # Why you destroy window if you will want to see result in the next loop
subprocess.call([r'C:\Users\mchaf\Desktop\run.bat'])
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM