I am trying to release a cam capture which has been acquired by the API call
camera = cv.CaptureFromCAM(-1)
How can I release it. There is a function named "ReleaseCapture" but it has no python binding.
Can anybody suggest any alternative?
Thanks a lot
I found a similar answered question here
capture = cv.CaptureFromCAM(0)
frame = cv.QueryFrame(capture)
#some code ...
del(capture)
be carefull of using frame or another image captured from cam after deleting capture
regards
Related
I have a problem with using external camera in Python OpenCV.
I am using Windows.
In device manager, camera is not under "Cameras", but under "Imaging devices" and is called USB3 Vision compliant camera.
The camera is working fine on app given by company (UcamViewer).
I want to connect to this camera using cv2.VideoCapture().
I have of course tried:
cv2.VideoCapture(k)
for k = [0..100]
Only k = 0 is occupied and works - that is my webcam.
I have also tried adding multiple possible values to the second parameter of the VideoCapture(), which did not work.
how to get video from a "USB3 Vision" device?
This question suggested to use cv.CAP_XIMEA as the second parameter of VideoCapture(), but CAP_XIMEA does not seem to be a possible value.
If I can not fix this issue and use VideoCapture(), what would you suggest to use to capture the video and convert it to format that can be used by openCV methods?
Any ideas how could I solve this issue will be appreciated.
Thank you for your help.
I am trying to stream live video from an external camera using cv2. I was able to write the simple code to stitch the frames and stream it. But am struggling to find how to change the camera.
I tried to run it after disabling the main webcam from the task manager, but it still did not work.
So, if anyone can help me with some clue regarding the same, that would be a great help.
Cameras are numbered for Windows. You can try a few indeces and check which camera index belongs to the camera you want.
capture = cv2.VideoCapture(index)
I just installed opencv and was following a tutorial and realized that when I type down capture. vscode is not giving me the suggestions for the functions available for the 'capture' pointer. It is, however, showing me sugestions from the cv2 library.
This is what I want to see
but
This is what I am getting
So my question basically is, How can I fix this? I havnet been able to find any solution online. I want to be able to see what functions are available so I can learn and explore the library better.
Here's the complete code, just in case:
import cv2 as cv
capture = cv.VideoCapture('video.mp4')
while True:
isTrue, frame = capture.read() #grab video frame by frame
cv.imshow('Camera', frame)
if cv.waitKey(20) & 0xFF==ord('d'):
break
capture.release()
cv.destroyAllWindows()
Thanks in advance!
This problem has been answered here.
Python Language Server does not support Intesllisense from the .pyd file for now.
I am just trying a simple OpenCV code test in PyCharm but every time I run the code it just ends. I know it is not an issue with my webcam as I have run the code using Anaconda's command prompt and it works though it does take some time to start up.
The code I am using is:
import cv2
cap = cv2.VideoCapture(0)
while True:
success, img = cap.read()
cv2.imshow('Image', img)
cv2.waitKey(1)
I feel that OpenCV is taking time to open up my webcam and so the first few reads are coming back as false and causing the code to end before my webcam can show but I don't know how to fix it. I tried googling around but I was not able to find anything. If anyone knows how I can fix this I would really appreciate your help!
Edit: nevermind I was being dumb. PyCharm was not executing the file I was on! 😅
I don't know if the problem is hardware related but, you can try something like this:
import cv2
cap = cv2.VideoCapture(0)
while True:
try:
success, img = cap.read()
cv2.imshow('Image', img)
cv2.waitKey(1)
except Exception as e:
print("Exception happened: {}".format(e))
continue
This basically tries to execute the code inside of try and if an exception happens it executes the code inside of except. It also informs what the error is. You can also add some sleep using time.sleep(), before trying to read the webcam again.
For time.sleep(), you need to import time.
Hopefully this helps. :)
I think your error can be from the your interpreter.Or you can try kick in your code and run it. Dont use the triangle symbol in the above right corner for the first attemp
If you are running on Mac, the PyCharm usually does not have access to webcam. So, its best you run your application from the terminal when you need to access the webcam.
I am trying to code up simple face detection in python using opencv. But unfortunately my opencv is refusing to detect my webcam. I am not sure how it works internally, as documentation is very limited, but CaptureFromCAM(-1) returns some object, but QueryFrame returns nones. When I try to use one of my two cameras for example in cheese, I get video without a problem.
capture = cv.CaptureFromCAM(-1)
faceCascade = cv.Load("haarcascade_frontalface_alt.xml")
while (cv.WaitKey(15)==-1):
img = cv.QueryFrame(capture)
if img != None:
image = DetectFace(img, faceCascade)
cv.ShowImage("face detection test", image)
cv.ReleaseCapture(capture)
Any ideas?
Ok, I have figured it out. Basically my openvc was compiled with v4l (video for linux) support.
When solving this problem you first need to make sure your camera is working with some other application using v4l. If that is the case then you can try to recompile openvc with v4l support. For gentoo (which uses portage) it is very simple:
sudo su
USE="v4l v4l2" emerge -av opencv
for other package managers either figure something out or compile from source with USE_V4L=ON.