簡體   English   中英

錯誤:(-215:Assertion failed).ssize.empty() in function 'resize' 在為框架設置 cv2.resize 時出現

[英]error: (-215:Assertion failed) !ssize.empty() in function 'resize' shows up when setting a cv2.resize for frame

我正在按照教程構建面部識別軟件:

small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25),
rgb_small_frame = small_frame[:,:,::-1]

當出現此錯誤時:

cv2.error:OpenCV(4.6.0)/Users/xperience/actions-runner/_work/opencv-python/opencv-python/opencv/modules/imgproc/src/resize.cpp:4052:錯誤:(-215:斷言failed).ssize.empty() 在 function 'resize'

這個問題在 Stackoverflow 上出現過幾次。

cv2無法從文件或網絡攝像頭獲取frame時,它不會引發錯誤,但會返回狀態False和幀None並且您應該在運行 rest 代碼之前檢查其中一個值

ret, frame = cap.read()

if ret:  # if ret is True:
    small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25)
    # ... rest of code ...

或者

ret, frame = cap.read()

if frame is not None:  # it can't be `if not frameret is True:`
    small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25)
    # ... rest of code ...

暫無
暫無

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

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