Home > Mobile >  OpenCV: Difference between cap.set(CAP_PROP_FRAME_WIDTH or CAP_PROP_FRAME_HEIGHT) and resize()
OpenCV: Difference between cap.set(CAP_PROP_FRAME_WIDTH or CAP_PROP_FRAME_HEIGHT) and resize()

Time:03-18

I am working on OpenCV (4.3.0) and trying to understand how I can change the resolution of the image.

To my understanding there are 2 ways that I can do this,

  1. Using "cap.set()" function

         cv::VideoCapture cap(0)
         cap.set(CAP_PROP_FRAME_WIDTH, 320);//Setting the width of the video 
         cap.set(CAP_PROP_FRAME_HEIGHT, 240);//Setting the height of the video 
    
  2. Using "resize()" function,

    int up_width = 600;
    int up_height = 400;
    Mat resized_up;
    resize(image, resized_up, Size(up_width, up_height), INTER_LINEAR);
    

I wanted to understand if they both are the same or if they are different. What are the exact differences between them?

CodePudding user response:

cap means capability of a camera. we set the required resolution before capturing from camera. If the resolution is supported only then we get a valid frame from the camera. For example a webcam might support some fixed number of resolutions like 1280x720, 640x480 etc and we can only set the cam for those resolutions.

resize is an interpolation (bilinear or bicubic or anyohter)function which resizes(upscale or downscale) a frame to any desired size.

CodePudding user response:

Here is one of your question's answer. CAP_PROP_FRAME_WIDTH and CAP_PROP_FRAME_HEIGHT are some of capture properties. Documentation says:

Reading / writing properties involves many layers. Some unexpected result might happens along this chain. Effective behaviour depends from device hardware, driver and API Backend.

So if your camera backend matches with the opencv supported backends, then you will be able to change the resolution of your camera (if your camera configuration supports different resolution). For example a camera can support 640x480 and 1920x1080 at the same time. If opencv backend support this camera backend you can switch the resolution configurations by the code:

cap.set(CAP_PROP_FRAME_WIDTH, 640);
cap.set(CAP_PROP_FRAME_HEIGHT, 480);

or

cap.set(CAP_PROP_FRAME_WIDTH, 1920);
cap.set(CAP_PROP_FRAME_HEIGHT, 1080);

What about resize ?

resize() is totally different than the concept we talked above. Video properties are based on hardware, if you use a camera with 640x480 resolution. It means that camera sensor has specified perceptron cells inside for each pixel. However, resize deal with the resulted image via on software. What resize is doing is that interpolating(manipulating) image's height and width. Otherwords, it looks like you are looking at somewhere very close(zoom in) or very far(zoom out).

  • Related