OpenCV cannot read from my VGA Webcam
Ok I will crack down on the issue fast, as I don't want waste anyone's time:
I have a laptop MODEL: ACER ASPIRE 3(A315-42) with a VGA Camera built into it. Here is the simple code I'm trying to run(in python)
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
print(ret)
it seems to only return False
.
Now if you want a little more detail I ran another program.
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I receive this error cv2.error: C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:281: error: (-215) size.width>0 && size.height>0 in function cv::imshow
Unfortunately I'm not too great with OpenCV just begun today, so if anyone can help me out I would be so happy as this is required for a project I'm working on.
Thank you to whom who answers to this in advance.
try another backend, like
(default is CAP_MSMF, which has some warts)
@berak No change, the first one still returns
False
and the second code still spits out cv2.error. Code after change:Further information I went ahead and used OpenCV version 3.1.0.5 as I heard it brings a prompt for the user to select which device. It seems to be able to detect the device just cant read from it. Hope this helps.
Could there be a camera setting restriction or a driver issue? I just checked online for drivers for the webcam in Device Manager as far as it seems its the latest model. I'm out of ideas why this issue will occur.
btw, os ? opencv version ? where's the cv2 from ?
that's the old VFW api, but neither opencv nor ms supports it anymore
btw, almost same machine here (aspire es1-311) and the DSHOW backend runs nicely on win7/win10
reinstall drivers, i guess ... ;(
@berak I'm on the Windows 10 operating system, with the latest OpenCV version. I had only downgraded to 3.1.0.5, to see if OpenCV was able to detect the webcam in the first place.
@berak how would i go about reinstalling my webcam drivers? Do you have a source on which you refer me to.
@berak cv2 was installed via cmd line using command "pip install opencv-python".
^^ yea, ok. nothing unusual (we could pick on), unfortunately ;(
@berak I have reinstalled my webcam drivers and this has not fixed anything. I'm sorry to have bothered you but is there other ways in which I can get my PC via code to get just one frame from a USB camera? If I can at least get one frame I can develop a loop for my project. Which I want to connect 2 webcams to a computer at my workplace these cameras need to get a frame every second or two seconds, i was planning to use pyzbar to scan barcodes and collect data. But this one barrier is preventing me. I wonder if i got external webcams(connected via USB) will it work? If I got frame from each camera every second.