After update to opencv - python 4.4.0.40, abnormal (was good), the following code single-step found ret, frame=cap. The read () this sentence is often abnormal
The import cv2
Cap=cv2. VideoCapture (0)
I=0
While (True) :
Ret, frame=cap. The read ()
If (ret) :
Cv2. Imshow (" capture ", frame)
K=cv2. WaitKey (1)
If k==27:
Break
Elif k==32:
Cv2. Imwrite (' testCapPic + STR (I) + 'JPG', frame)
I +=1
The else:
Break
Cap. Release ()
Cv2. DestroyAllWindows ()
Execute the following a stock image,
The import cv2
Cap=cv2. VideoCapture (0)
Ret, frame=cap. The read ()
Cv2. Imwrite (' testCapPic. JPG, frame)
Cap. Release ()
Cv2. DestroyAllWindows ()
CodePudding user response:
PIP install opencv - python==4.1.2.30, solve the problem