I capture some image data from a HD cam using OpenCV and this code (relevant snippets only):
data->capture =cvCaptureFromCAM(data->config.device); // open the device
...
IplImage *grabFrame=cvQueryFrame(data->capture);
Using this code I always get a grabFrame with a size of 640x480 while the camera supports 1920x1080. When I do something like that after initialisation:
cvSetCaptureProperty(data->capture,CV_CAP_PROP_FRAME_WIDTH,1920);
cvSetCaptureProperty(data->capture,CV_CAP_PROP_FRAME_HEIGHT,1080);
I get results in real HD resolution - but blurred images, means it is only upscaled from 640x480 to HD resolution. So: how can I force OpenCV to really use the fill native resolution?
It does not seem to be a driver/HW problem since it happens on Windows and Linux - and when I try any other application on these systems I get the full, native resolution as expected.
Thanks!
1. From (old) opencv C documentation :
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.
2. You can try to compile opencv with openNI since VideoCapture class make use of it for setting capture device options.
It helped me:
static const int MAX_WIDTH_RESOLUTION = 7680;
static const int MAX_HEIGHT_RESOLUTION = 4800;
cvCreateCameraCapture(...);
cvSetCaptureProperty(pCam, CV_CAP_PROP_FRAME_WIDTH, MAX_WIDTH_RESOLUTION);
cvSetCaptureProperty(pCam, CV_CAP_PROP_FRAME_HEIGHT, MAX_HEIGHT_RESOLUTION);
cvQueryFrame(...);
With two different webcams i've got 1900x1080 and 1280x960 frames.
Related
im using OpenCV 4.3 with c++ and the VideoCapture to get the videostream from a Logitech C922 Pro Webcam.
Im changing the resolution with
cap.set(CAP_PROP_FRAME_HEIGHT,height)
cap.set(CAP_PROP_FRAME_WIDTH,width)
This works fine until im using either the resolution of 640x480 or 640x360. In this cases OpenCV stays in the aspect ratio it was before (640x480 on startup).
Is there an efficitent way to change the resolution to the right one instead of changing it to another one before?
CAP_PROP_FRAME_HEIGHT or CAP_PROP_FRAME_WIDTH are used to switch the resolution of your camera. If your camera doesn't support that resolution you set, the code will not work. If you check the specs of Logitech C922, you will see that it doesn't include the resolutions you desired.
There are other options you can apply:
1- You can crop the desired sizes(ex. 640,360) from the main frame.
2- You can resize the frame but this will crash the aspect ratio.
I'd like to capture high resolution still images using AVCaptureSession. Therefore AVCaptureSession preset is set to Photo.
This is working well so far. On an iPhone 4 the final still image resolution is at its maximum of 2448x3264 pixels and the preview (video) resolution is 852x640 pixels.
Now, because the preview frames are analyzed to detect objects in the scene, I'd like to lower their resolution. How can this be done?
I've tried to set AVVideoSettings with a lower width/height to AVCaptureVideoDataOutput, but this leads to the following error message:
AVCaptureVideoDataOutput setVideoSettings:] - videoSettings dictionary contains one or more unsupported (ignored) keys: (AVVideoHeightKey, AVVideoWidthKey
So it seems this is not the right approach to configure the size of the preview frames received by AVCaptureVideoDataOutput / AVCaptureVideoDataOutputSampleBufferDelegate. Do you have any ideas how the resolution of the preview frames can be configured?
Any advise is welcome,
Thank you.
If you want to specify the settings manually, you need to set activeFormat on the AVCaptureDevice. This will be implicitly set the session preset to AVCaptureSessionPresetInputPriority.
The activeFormat takes a AVCaptureDeviceFormat but you can only take one from the list of AVCaptureDevice.formats. You'll need to go through the list and find one that fits your needs. Specifically, check that highResolutionStillImageDimensions is high enough for desired still capture and formatDescription (which needs to be inspected with CMFormatDescription* functions, e.g., CMVideoFormatDescriptionGetDimensions) matches your desired preview settings.
Just for the records: I ended up configuring AVCaptureSession in preset Low while aiming the camera. As soon as the shutter is triggered, the app switches to preset Photo, performs a focus run and takes the picture. This way it takes between 1 and 2.5 seconds to take a picture, which isn't that great, but it's at least a workaround.
To lower the size of the output of AVCaptureVideoDataOutput you can set the bitrate to be lower thus producing a small sample size.
commonly used keys for AVCaptureVideoDataOutput are:
AVVideoAverageBitRateKey
AVVideoProfileLevelKey
AVVideoExpectedSourceFrameRateKey
AVVideoMaxKeyFrameIntervalKey
For example:
private static let videoCompressionOptionsMedium = [AVVideoAverageBitRateKey : 1750000,
AVVideoProfileLevelKey : AVVideoProfileLevelH264BaselineAutoLevel,
AVVideoExpectedSourceFrameRateKey : Int(30),
AVVideoMaxKeyFrameIntervalKey : Int(30)]
In iOS, I would like to get frame-by-frame images from a movie file,
I tried it by using AVAssetImageGenerator. But it gets one image per second for a 30fps movie. It should be 30images!
I heard that there is a way to use FFmpeg.
But in newer OSs like iOS7, is there a new API to do this without using external libraries like FFmpeg?
You can also try OpenCV to capture the frames. But the speed will be dependent on the device and processor. Hope for iPhone5 the speed is perfect to capture all the frames. You can have a look at this link if it helps.
i tried to run the tutorial code for object detection. i have logitech c170 webcam with me. i am not able to run any tutorial codes with this cam connected.
HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP --(!) No captured frame -- Break!
but the same program runs effectively with my built in webcam. since i am a newbie to openCV i am not able to understand the mistakes.
when i took the details of the both cams(built in and logitech c170) using
v4l2-ctl --device=/dev/video0 --all
Driver Info (not using libv4l2):
Driver name : uvcvideo
Card type : Webcam C170
Bus info : usb-0000:00:1d.0-1.2
Driver version: 3.2.50
Capabilities : 0x04000001
Video Capture
Streaming
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'MJPG'
Field : None
Bytes per Line: 0
Size Image : 921600
Colorspace : SRGB
Crop Capability Video Capture:
Bounds : Left 0, Top 0, Width 640, Height 480
Default : Left 0, Top 0, Width 640, Height 480
Pixel Aspect: 1/1
Video input : 0 (Camera 1: ok)
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30/1)
Read buffers : 0
i got the difference that the pixel formats of both are different. the built in cam is YUYV while logitech is MJPG. more over i am completely unaware of MJPG format..i tried to change the formate to YUYV using
v4l2-ctl --device=/dev/video1 --set-fmt-video=width=640,height=480,pixelformat=0
i could change the format.but when i run the program again the error repeats the format is again changed to MJPG by the system.
consider me as smallest guy in OpenCV..
I've been trying to use my Logitech C170 with the V4L2 API for a couple of days, and capturing YUYV uncompressed images doesn't seem to work in 640x480 nor 640x360 resolutions. Waiting for the frame buffer filling makes V4L2 stall.
But that works well with all the other resolutions reported in the UVC capabilities, e.g. 352x288, 320x240, 176x144, 160x120, 544x288, 432x240 and 320x176.
For 640x480 resolution, I've only managed to dump JFIF compressed frames from the camera.
Maybe you could make your codes work with this camera if you try image widths lowerer than 640 pixels.
When capturing video with phonegap on iOS the file size for a even a 1min capture is ridiculously large. Well, far to large to upload over a 3G connection reliably. I read that there is a native AVCaptureSession object that will allow the bitrate to be altered in order to reduce the file size. Has anyone implemented this in the phonegap video capture or can give me any pointers?
Found the deatils I needed here:
How can I reduce the file size of a video created with UIImagePickerController?
The important line for Phonegap users is in CDVCapture.m:
pickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
There are several presets that can be used e.g.
UIImagePickerControllerQualityTypeLow
phonegap provide quality argument when to navigate camera set :
quality:50
this is recommended for ios. if u need to reduce mean reduce quality.It have integer value (0-100) use this .....