Reputation: 21
import cv2
import sys
cpt=0
vidStream=cv2.videoCapture(0)
while True:
ret,frame=vidStream.read()
cv2.imshow("test frame",frame)
cv2.imwrite(r"C:\Users\Abhishek\PycharmProjects\images\0\image%04i.jpg"%cpt,frame)
cpt +=1
if cv2.waitKey(10)==ord('q'):
break
anyone please help me fix the error I'm getting an error which says"module 'cv2.cv2' has no attribute 'videoCapture'"and "unable to import cv2"
Upvotes: 1
Views: 5812
Reputation: 41
1)It's not cv2.videoCapture() but try instead cv2.VideoCapture().
Python 2.7.18rc1 (default, Apr 7 2020, 12:05:55)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> vid = cv2.videoCapture(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'videoCapture'
>>> vid = cv2.VideoCapture(0) #like that it works fine.
>>>
Try to install opencv with the command pip install opencv-python
or pip install opencv-contrib-python
, and check if you still get the "unable to import cv2" error
Upvotes: 3
Reputation: 692
Please install
pip install opencv-python
and
pip install opencv-contrib-python
and then run below code....
import cv2
import sys
cpt=0
vidStream=cv2.videoCapture(0)
while True:
ret,frame=vidStream.read()
cv2.imshow("test frame",frame)
cv2.imwrite(r"C:\Users\Abhishek\PycharmProjects\images\0\image%04i.jpg"%cpt,frame)
cpt +=1
if cv2.waitKey(10)==ord('q'):
break
Upvotes: 1