Ask Your Question
1

videwriter not working after image resize

asked 2015-12-17 23:33:59 -0600

Prakash gravatar image

i am using opencv 3 & visual studio. issue here is that i am unable to save video for any particular resolution other than default full camera resolution there is no error, only thing is video file doesn't grow. it stays at 5.54kb. here is my code

#include"opencv2\opencv.hpp"
using namespace cv;
using namespace std;

VideoCapture cap_cam1(0);

double Width = cap_cam1.get(CV_CAP_PROP_FRAME_WIDTH);
double Height = cap_cam1.get(CV_CAP_PROP_FRAME_HEIGHT); 
cv::Size frameSize(static_cast<int>(Width), static_cast<int>(Height));
string videoFileName = "D://current.avi";
VideoWriter cam1_write(videoFileName, CV_FOURCC('D', 'I', 'V', '3'), 10.0, frameSize, true);
Mat image;
int main()
{
    while (true)
    {
        cap_cam1 >> image;
        resize(image, image, Size(320, 240));
        imshow("image", image);
        cam1_write.write(image);
        if (waitKey(33) == 27)break;
    }

}

if i comment remove resize function, then file size grows and frames are added i also tried adding below lines after videowriter definition

cap_cam1.set(CV_CAP_PROP_FRAME_WIDTH, 240);
cap_cam1.set(CAP_PROP_FRAME_HEIGHT,320);

also tried changing resolution at videowriter definition, after everything file size remains at 5.54kb.

how to record video at custom resolution? Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2015-12-18 00:04:16 -0600

berak gravatar image

updated 2015-12-18 00:05:41 -0600

if you want to write a 320x240 video, you have to pass this Size to the VideoWriter constructor, not the (original) frameSize !

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-12-17 23:33:59 -0600

Seen: 935 times

Last updated: Dec 17 '15