這只是意味着該圖像不存在,嘗試使用絕對路徑。如果無效再嘗試以下方案:
解決方案非常簡單。請記住一件事,如果圖像的RGB值在0-255的範圍內,請確保這些值不是數據類型“ float”。由於OpenCV僅在值範圍爲0-1時才考慮float。如果發現浮點值大於1,則會認爲該浮點僅存在於0-1之間,因此會截斷該值。因此產生了這樣的錯誤。因此,如果值介於0-255之間,則將數據類型轉換爲uint8。image = image.astype('uint8')
frame = np.asarray(frame, dtype=np.uint8)
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break