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