setting webcam camera parameter in opencv python - python

I am using Windows 7 64 bit operation system together with Python 3 and OpenCV. My computer is interfaced to two Logitech webcam of the following model:
1) Logitech HD Webcam C615
2) Logitech QuickCam Pro 9000
In Python I am running the below script
import cv2
cap1 = cv2.VideoCapture()
cap2 = cv2.VideoCapture()
cap1.set(cv2.CAP_PROP_AUTOFOCUS,0) # I want to change the focus manually myself
cap1.set(cv2.CAP_PROP_FOCUS,10)
cap2.set(cv2.CAP_PROP_FOCUS,10)
cap1.set(cv2.CAP_PROP_EXPOSURE,25)
cap2.set(cv2.CAP_PROP_EXPOSURE,25)
#get frame
ret, frame1 = cap1.read()
ret, frame2 = cap2.read()
#display result
cv2.imshow('cam 1',frame1)
cv2.imshow('cam 2',frame2)
The problem is, regardless on how I change the parameters in my cv2.set, I don't see the change being reflected in the captured image.
I then went to download Logitech's driver for the camera called Logitech Webcam Software. Using their software I can make the appropriate settings in both of the cameras. When closing the software, and restart python and running the script, the captured images appear exactly according to the settings that I have set in the Logitech Webcam Software.
My questions are:
1) Why can I not set the camera settings directly using Python and OpenCV?
2) How should I change my script in order to interface the camera settings direct from Python?
Thanks!

Related

Set Frame for the Explorer Preview in Windows for a self written Video

I am writing a Webcam Videostream to a *.mp4 File(cv2.videowriter). In the first Frames it shows some Informations with cv2.putText on a black Recktangle .
I would like to see these Frames as the Thumbnail in the Windows Explorer.
At the Moment the Thumbnail/Preview Image is somehow set after that Information Frames.
How can I set this Thumbnail/Preview Image to the first Frame while writing?
It would be nice, if it could work without ffmpeg.
Greetings
Chorum

Asynchronous usage of cv::imshow

I would like to get this functionality with OpenCV 4.5.3 and Python 3.7 on Raspberry Pi 4 with 2021-05-07-raspios-buster-armhf-full:
cv::imshow("window", img);
do_something_while_img_is_displayed();
cv::destroyWindow("window");
I tried 2 options after a call to cv::imshow:
cv::waitKey(10)
cv::pollKey()
both of which display only a window frame without an image
What is the way to accomplish it?
NOTE
My intent is to have an image persistently displayed on the screen and be able to call other OpenCV functions at that time, e.g. capture and process images from a camera. I don't care about event processing loop - there will be no UI interaction at that time.
This snippet works on Ubuntu 18.04 and on 2021-05-07-raspios-buster-armhf-full:
import cv2, sys, time
image = cv2.imread("t1-4.png")
cv2.imshow("window", image)
cv2.waitKey(1000) # this delay has to be long on RPi
time.sleep(3) # substitute for do something
cv2.destroyWindow("window")
Equivalent C++ code works on both OSes as well.

OpenCV streamming ip camera always return False

So far I have used OpenCV for streamming ip camera from Raspberry pi + pi camera. I want to save the video from ip camera with codec H.264 and it didn't work. I find out from this post https://github.com/skvark/opencv-python/issues/100 which told me that only manually built opencv library would support H264 codec.
So i followed this link to manually build opencv https://www.learnopencv.com/install-opencv3-on-ubuntu/ and succeeded. But when I use manually built opencv, I can no longer access my ip camera, the cap.open() always return None. Here is my code:
import cv2
cap = cv2.VideoCapture("http://10.10.1.240:8081/")
while True:
ret, frame = cap.read()
frame2 = cv2.flip(frame, 1)
cv2.imshow("frame2", frame)
key = cv2.waitKey(25)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
In the above code, ret is always False.
I have been stucked in this for 2 days without a real solution and explaination. Any help would be appriciated, thanks!
But when I use manually built opencv, I can no longer access my ip camera, the cap.open() always returns none.
Have you tried, checking if your ip camera is working properly and present on your network after building opencv from source? Did you try to stream from the camera using any media player after installation off opencv from source?.
As far as your code is concerned, try the following format for cv2.VideoCapture
cap = cv2.VideoCapture()
cap.open("rtsp://yourusername:yourpassword#172.16.30.248:555/Streaming/channels/2/")
yourusername-username given to your ip camera.
yourpassword-password for the given user name.
You can try the following as well.
cv2.VideoCapture("rstp://admin:PASSWORD#192.168.1.64/doc/page/previw.asp")
Thanks.
Make sure the ip address of your computer and your camera are in the same subnet mask.

Getting Python input from Webcam on raspberry pi?

i'm using a sony ps3 eye as webcam input on my pi for an OpenCL python program I'm writing, but for some reason no matter what i do the pi python compiler isn't accessing the webcam. Yet the same code when run on my laptop using the same webcam runs perfectly. Then i checked the usb devices on my pi and it state that "sony playstation 3 eye cam" was on usb port 6. also when using the "motion" package on the pi i was able to use the camera perfectly as input. So my problem is again that the python compiler isn't communicating with my webcam on the pi. Please, think about this and tell me how to fix it; i simply can't think of what's wrong. Here's the sample code I used, and please help me out. Thank you very much.
import cv2.cv as cv
#cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
while not capture:
print "error opening capture device, correction attempt"
while True:
frame = cv.QueryFrame(capture)
if frame is None:
print "fail with putting in frame"
else:
c = cv.WaitKey(100)
print 'capturing!'
cv.SaveImage("pictest.png", frame)
I never updated this but my solution was: I used the Motion Package for Raspberry Pi to receive images (since the Sony Ps3 EyeToy Camera did not have drivers written that were compatible with the Pi) and then Used OpenCV to analyze each Image. Doing this as each image came in, many times a second, is the same as analyzing video through OpenCV.This implementation worked perfectly for my needs, and I used other Bash tools to delete old image files after a certain time period so my memory was not unnecessarily filled.
There are some known problems with isochronous USB. Some camera issues have been addressed with recent fixes, but others remain (and apparently being worked upon). What kernel version are you using (uname -a)?
The fixes have not worked their way into the official distribution yet, so if you don't want to wait can run rpi-update to pick up the latest kernel (assuming you're using Raspbian). You want at least #389.

OpenCV+Python: Firewire Cams not supported on Windows XP?

I'm trying to capture frames from a Firewire Cam (Firefyl MV) using OpenCV 2.3.1 and Python 2.7 on Windows XP.
My example finds the Camera when i use
capture = cv.CaptureFromCAM(-1)
but i cant capture the frames with
frame = cv.QueryFrame(capture)
Here http://opencv.willowgarage.com/documentation/python/highgui_reading_and_writing_images_and_video.html#capturefromcam they write:
Currently two camera interfaces can be used on Windows: Video for Windows (VFW) and Matrox Imaging Library (MIL); and two on Linux: V4L and FireWire (IEEE1394).
So is it not possible to use a Firewire Cam with OpenCV+Python on WinXP? Is there any simple workaround?
Only if the firewire camera maker included a VFW driver.
It's also possible to grab data from a DirectShow filter which the camera maker might provide instead

Categories

Resources