question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change frame size of video Capture

See original GitHub issue

Summary of your issue

I have 5MP camera, and I can use opencvsharp to capture(or liveview ) at 2 resolution 2592x1944 and 1280x1024, but I want to make liveview at 1280 and capture single image at 2592, it return black image at size 2592, how to do that, I stop camera and re-init it but it does not work.

Environment

window 7, opencv sharp 4.1.0 Write your environment.

What did you do when you faced the problem?

//write here

Example code:

bool InitCamCapture()
        {
            _capture = new VideoCapture();

            _nCamIndex = CheckCamID();

            if (_nCamIndex <= -1) return false;

            if (_capture.IsOpened())
                _capture.Release();

            _capture.Open(_nCamIndex);

            _capture.FrameWidth = 1280;
            _capture.FrameHeight = 1044;

            _capture.Read(_framePreview);

            if (_framePreview.Height > 0)
            {
                timerWebCam.Enabled = true;

                _bmpCam = _framePreview.ToBitmap();

                //_bmpCam.RotateFlip(RotateFlipType.Rotate90FlipNone);

                picCamera.Image = _bmpCam;
                return true;
            }

            return false;
        }

private void btCapture_Click(object sender, EventArgs e)

        {
            _nCamIndex = 1;
            timerWebCam.Enabled = false;
            Thread.Sleep(100);

            if (_capture.IsOpened())
            {
                _capture.Release();
            }

            _capture = new VideoCapture();
            _capture.FrameWidth = 2592;
            _capture.FrameHeight = 1944;

            _frameCapture = new Mat();

            _capture.Open(_nCamIndex);

            _capture.Read(_frameCapture);

            _frameCapture.SaveImage("cap.bmp");

            InitCamCapture();
        }

Output:

paste your output

What did you intend to be?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ydeydiercommented, Apr 17, 2023

After lots of searching, I discovered that there’s a way to reduce the resolution but you have to structure your code in a specific way.

  • First of all, Define the VideoCapture
// 0 is the device index, you can change it as per your needs
deviceIndex = 0;
capture = new VideoCapture(deviceIndex);
  • Then Open the Device

capture.Open(deviceIndex);

  • Then define the frame height and frame width
capture.FrameHeight = 64;
capture.FrameWidth = 36;
  • Finally, write it into a file

outputVideo = new VideoWriter("video.mp4", FourCC.AVC, 29, new OpenCvSharp.Size(capture.FrameWidth, capture.FrameHeight));

“Open” BEFORE “FrameHeight” and “FrameWidth” did the job for me. Thanks a lot.

1reaction
ticTechtoeecommented, Jul 30, 2022

After lots of searching, I discovered that there’s a way to reduce the resolution but you have to structure your code in a specific way.

  • First of all, Define the VideoCapture
// 0 is the device index, you can change it as per your needs
deviceIndex = 0;
capture = new VideoCapture(deviceIndex);
  • Then Open the Device

capture.Open(deviceIndex);

  • Then define the frame height and frame width
capture.FrameHeight = 64;
capture.FrameWidth = 36;
  • Finally, write it into a file

outputVideo = new VideoWriter("video.mp4", FourCC.AVC, 29, new OpenCvSharp.Size(capture.FrameWidth, capture.FrameHeight));

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't set frame width and height with [OpenCV] cv2. ...
The idea is to resize the frame without having to worry about setting the default frame size. Instead of using cv2.VideoCapture().set() ...
Read more >
OpenCV & Python: How to Change Resolution or Rescale ...
OpenCV makes it easy to change resolution of your video. ... VideoCapture(0) def rescale_frame(frame, percent=75): width ...
Read more >
How to change video resolution in OpenCV in Python
Step 1: Importing the libraries Step 2: Define a video capture object Step 3: Capture video frame by frame Step 4: Declare the...
Read more >
How to set cv2.VideoCapture() image size in Python
Use cv2.CAP_PROP_FRAME_WIDTH and cv2.CAP_PROP_FRAME_HEIGHT in order to tell OpenCV which image size you would like.
Read more >
Manually Resize Height and Width of Display Capture
Right Click on the Source, Transform -> Edit Transform ... am resizing (and/or cropping) lots of pre-recorded videos from different sources.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found