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.
Related
I would like to take a picture from my back camera on my ios.
I am using webcamtexture to get the back camera status.
I print those pixels on a UI Texture, after that I capture a screenshot.
Everything works fine, but the quality is pixelated because the webcamtexture has a maximum of 1920x1080 resolution.
Is there any other way to get a picture from a device camera in unity?
I already tried a lot of plugins but none of them seem to work better.
I am developing a custom camera in which the camera is set to the Image Capture mode. I need to increase the zoom level of camera preview according to the app requirements. The preview currently being displayed is perfect I just need to increase the zoom-out in current preview. I searched over internet but didn't find any solution. Please tell me how can I do this. I am attaching the example image for better understanding. first image is of my camera app and second image is of Scanner Pro app which shows view with more covered area while I focus both the apps for the same object on the same distance. My camera don't have any space but the Scanner camera has spacing all over the image. Both the camera are on the same distance from the paper.
i don't know whether you still need this answer. Probably not, but still for you and everyone else looking out:
When you set the Session Preset, try using SessionPresetPhotofor the device object. This should resolve the weird zoom issue.
Your preview view is probably spilling over the edge of the screen. Make sure it is a 4:3 aspect ratio and that it doesn’t overflow your screen edges. With that you should see more of your image.
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.
I'm using the two OpenCV functions mentioned above to retrieve frames from my webcam. No additional properties are set, just running with default parameters.
Here cvQueryFrame() always returns frames in size 640x480, independent from the native resolution of the camera. But how can I get full size frames when I don't know the exact resolution of it and therefore can't set width and height property? Is there a way to reset these 640x480 settings? Or is there a possibility to query the device for the maximum resolution it supports?
Thanks!
I was having a look at the RosyWriter Sample Code provided by Apple as a starting point and I'd like to find a way how to crop a video.
So i have the full resolution video from the iPhones Camera, but I just want to use a cropped part of it (and also rotate this subpart).
I figured that in captureOutput:didOutputSampleBuffer: fromConnection: i can modify each frame by modifying the CMSampleBufferRef that i get passed in.
So my questions now are:
Is this the right place to crop my video?
Where do I specify that the final video (that get's saved to disc) has a smaller resolution than the full video captured by AVCaptureSession? Setting the AVVideoWidthKey and AVVideoHeightKey has no effect.
How can I crop the video and still have good performance?
Any help is appreciated!
Thanks a lot!
EDIT:
Maybe I just need to know how I can make a video that was shot in portrait a landscape one by turning the images of the video by 90 degrees and then zoom in to fit the width again...?!?
In AVVideoSetttings.h there is the AVVideoScalingModeKey. This key combined with the defined values control how the video is scaled/cropped when encoding the images to the video container. For example if you specified a value of AVVideoScalingModeFit then cropping is used. Check out the header for how other values effect the video images.