The quality of video recording that is required for our project is not met by the webcams. Is it possible to use high megapixel digital cameras (Sony, Canon, Olympus) with OpenCV ?
How to talk to the digital cameras using OpenCV (and specifically using Python)
Install Drivers for required camera, connect it, and use cv2.VideoCapture(int). Here, instead of 0, use a different integer according to the camera. By default, 0 is for the inbuilt webcam.
e.g.: cv2.VideoCapture(1)
Related
Is there a way to track down and nicely blur faces or part of face (like hair) for multiple 360 degree images via python opencv. ? I'am using Windows OS and python3.8
Two methods with opencv and python
Using a Gaussian blur to anonymize faces in images and video streams
Applying a “pixelated blur” effect to anonymize faces in images and video
The method is well explained here and you can access code.
Now, a more advance solution if you are using GPU, and you want to run the application on a live video stream.. its with nvidia DS and Deep Learning. The github here reports results on T4, i believe you should be able to run it on Jetson nano. Here is the link
Yes, there is. First you need to detect the face(s) using Haar-cascade, which will provide you the rectangle coordinates of the face location. Then you can use this answer to blur the desired portion of an image.
I have a system with 3 actual webcams and one "webcam"(actually a gvUSB2 - a USB converter from RCA jacks). When using capture software like OBS, I can access all cameras at the same time (although I do notice occasional glitching). When I try to do the same with openCV, the result depends on which cameras are plugged in, but it seems like I can only use openCV to open the gvUSB2 camera if only 1 other camera is plugged in. I don't get an error message if it fails, rather when I access the gvUSB2 slot I get a duplicate of another camera. Using Python3.7 and freshly installed openCV.
I've tried moving around the USB slots. The drivers should be up to date for the "webcam". Like I said, using capture software I am able to collect data from all cameras simultaneously, while I can't capture from the "webcam" at all in openCV.
My test program is very simple, I just rotate through the camera index values here(ie, 0, 1, 2, 3):
import cv2
import sys
print(sys.argv[1])
s_video = cv2.VideoCapture(int(sys.argv[1]))
while True:
ret, img = s_video.read()
cv2.imshow("Stream Video",img)
key = cv2.waitKey(1) & 0xff
if key == ord('q'):
break
When the above code is run with 3 traditional webcams I am able to access all of them. However if the convertor "webcam" is installed, I get a duplicate image. IE, for all 3 traditional cams I will have 0, 1 and 2 showing the traditional images, and then 3 will be a duplicate of 2. On the other hand with just 1 traditional webcam installed, 0 will be the traditional webcam and 1 will be the correct image of the converter "webcam".
My thinking:
It seems like I am not overwhelming my USB system, because it can handle all the traditional webcams, and the resolution of the converter is much lower than the traditional ones (704x480 IIRC). My guess is a driver problem with the converter, and unfortunately since I am up to date, I may be out of luck. The counter evidence for this is that a capture program like OBS IS capable of reading from all webcams, suggesting that this may be a problem with openCV (or more likely, how I am using it). I can't find any google posts coming within 10 miles of this problem, so I'm pretty stuck. Any ideas?
I am trying to do face recognition of multiple people using logitech c930e webcam. so i want to zoom the c930e webcam using opencv Programming in python.
I had tried resizing the image but i want camera should be zoom and focused on a fixed distance using python programming.
I expect multiple webcam to be connected on one computer and all webcam is having different value of fixed zoom using programming.
According to its specs, the C930e is UVC-compatible (as most webcams are), and it most likely allows zoom level control via UVC.
To figure out what controls the camera provides via UVC, on Ubuntu you can use v4l2-ctl, which is in package v4l-utils. Here part of the output of v4l2-ctl -d 0 -l for a Microsoft LifeCam Cinema:
...
focus_absolute (int) : min=0 max=40 step=1 default=0 value=8
focus_auto (bool) : default=0 value=0
zoom_absolute (int) : min=0 max=10 step=1 default=0 value=0
You can change the controls, e.g., with v4l2-ctl -d 0 -c zoom_absolute=10.
To do this from Python, I used subprocess.check_output(). The utility function I wrote for getting and setting V4L2 controls is on GitHub and has a bunch of additional functionality such as handling of default values, multiple controls, and multiple batches of controls, which makes the code more intricate than a simple "change zoom level" example would be. (The function is part of SkinnerTrax, a real-time tracker for Drosophila I wrote.) There is also pyuvc, which seems relatively cross-platform but I have not tried it.
Logitech c930e webcam is just an external hardware and if you want it to zoom and focus using python programming, you need a library to control the webcam (unfortunately, there isn't any library for it). Without library to control the webcam, you can only do zooming and focus by software way, i.e using opencv, there is no other available way. Or you can get a programmable camera such as a Canon digital camera and use the library canon-remote to control it.
I've got a Raspberry pi compute module setup with two PiNoIR camera modules.
I'm trying to capture 2 video streams to be used on a raspberry pi 3 at a later date. Here is the configuration:
Frame rate = 30
resolution = 640x480
language = Python (with picamera)
chosen libraries = Opencv 3.1.0
The idea originally was to use the hardware device (e.g. /dev/videoX), but the bcm2835_v4l2 kernel module currently only supports 1 camera, and I'm not experienced with developing kernel modules do try and get it to support 2 cameras.
I've tried using the test code from the picamera docs, but this only works for a single camera. I know that defining PiCamera(0) or PiCamera(1) will select either camera, however I do not know how to get it to record two streams together.
I've tried the below, and I've tried using this guide for working with python and opencv. The guide is only focused around one camera, and I need both working.
!/usr/bin/python
import picamera
import time
cameraOne = picamera.PiCamera(0)
cameraTwo = picamera.PiCamera(1)
cameraOne.resolution = (640,480)
cameraTwo.resolution = (640,480)
cameraOne.framerate = 30
cameraOne.framerate = 30
cameraOne.start_recording('CameraOne.mjpg')
cameraTwo.start_recording('CameraTwo.mjpg')
counter = 0
while 1:
cameraOne.wait_recording(0.1)
cameraTwo.wait_recording(0.1)
counter += 1
if counter == 30:
break
cameraOne.stop_recording()
cameraTwo.stop_recording()
The code snippet above generates two 10 second videos with a single frame from each camera
I'm not sure where to go from here, as I'm not well versed in python, and I'm more experienced in C++, hence the want for hardware device control (e.g. /dev/videoX).
All I require is the ability to record the streams of both cameras simultaneously to be used in processing stereo vision.
If you can provide me with either a pure python-picamera solution, or an opencv integrated solution, I would be very thankful.
Just as an update, I've still not gotten very far on this, and could really use some help.
I'm using openCV via python on linux (ubuntu 12.04), and I have a logitech c920 from which I'd like to grab images. Cheese is able to grab frames up to really high resolutions, but whenever I try to use openCV, I only get 640x480 images. I have tried:
import cv
cam = cv.CaptureFromCAM(-1)
cv.SetCaptureProperty(cam,cv.CV_CAP_PROP_FRAME_WIDTH,1920)
cv.SetCaptureProperty(cam,cv.CV_CAP_PROP_FRAME_WIDTH,1080)
but this yields output of "0" after each of the last two lines, and when I subsequently grab a frame via:
image = cv.QueryFrame(cam)
The resulting image is still 640x480.
I've tried installing what seemed to be related tools via (outside of python):
sudo apt-get install libv4l-dev v4l-utils qv4l2 v4l2ucp
and I can indeed apparently manipulate the camera's settings (again, outside of python) via:
v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=1
v4l2-ctl --set-parm=30
and observe that:
v4l2-ctl -V
indeed suggests that something has been changed:
Format Video Capture:
Width/Height : 1920/1080
Pixel Format : 'H264'
Field : None
Bytes per Line : 3840
Size Image : 4147200
Colorspace : sRGB
But when I pop into the python shell, the above code behaves exactly the same as before (printing zeros when trying to set the properties and obtaining an image that is 640x480).
Being able to bump up the resolution of the capture is pretty mission critical for me, so I'd greatly appreciate any pointers anyone can provide.
From the docs,
The function cvSetCaptureProperty sets the specified property of video capturing. Currently the function supports only video files: CV_CAP_PROP_POS_MSEC, CV_CAP_PROP_POS_FRAMES, CV_CAP_PROP_POS_AVI_RATIO .
NB This function currently does nothing when using the latest CVS download on linux with FFMPEG (the function contents are hidden if 0 is used and returned).
I had the same problem as you. Ended up going into the OpenCV source and changing the default parameters in modules/highgui/src/cap_v4l.cpp, lines 245-246 and rebuilding the project.
#define DEFAULT_V4L_WIDTH 1920
#define DEFAULT_V4L_HEIGHT 1080
This is for OpenCV 2.4.8
It seems to be variable by cammera.
AFIK, Logitech cameras have particularly bad linux support (though It;s gotten better) Most of their issues are with advanced features like focus control. i would advise sticking with basic cameras (IE manual focus Logitech cameras) just to play it safe.
My built in laptop camera has no issue and displays at normal resolution.
My external logitech pro has issues initalizing.
However, I can overcome the resolution issue with these two lines.
Yes, they are the same as you used.
cv.SetCaptureProperty(self.capture,cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
cv.SetCaptureProperty(self.capture,cv.CV_CAP_PROP_FRAME_HEIGHT, 720)
My Logitech still throws errors but the resolution is fine.
Please make sure the resolution you set is a supported by your camera or v4l will yell at you. If I set an unsupported native resolution, I have zero success.
Not sure if it works, but you can try to force the parameters to your values after you instantiate camera object:
import cv
cam = cv.CaptureFromCAM(-1)
os.system("v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=1")
os.system("v4l2-ctl --set-parm=30")
image = cv.QueryFrame(cam)
That's a bit hacky, so expect a crash.
## Sets up the camera to capture video
cap = cv2.VideoCapture(device)
width = 1280
height = 720
#set the width and height
cap.set(3,width)
cap.set(4,height)