Ask Your Question
0

Change resolution of extracted frame in Opencv

asked 2013-11-10 01:24:45 -0500

yum gravatar image

updated 2013-11-10 22:45:29 -0500

Haris gravatar image

I have an H.264 video stream and I need to extract frames from it. However when I extract the frames,the quality is really poor since I need to perform color segmentation!I want to know how can i extract the frame and convert it to B G R so as to have a better quality picture. Here is the code :

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(){
    VideoCapture capture("1.dv4");
    if(!capture.isOpened())
        return 1;

    double rate=capture.get(CV_CAP_PROP_FPS);

    bool stop(false);

    Mat frame;
    namedWindow("Extracted Frame",CV_WINDOW_NORMAL);

    cout <<"Rate is="<<rate;

    int delay=1000/rate;

    while(!stop){
        if(!capture.read(frame))
            break;

            imshow("Extracted Frame",frame);
            imwrite("C:/Users/DELL/Documents/Visual Studio 2010/Projects/VideoFrameCapture/VideoFrameCapture/frame.jpg",frame);

        if(waitKey(delay)>=0)
            stop=true;
    }
    capture.release();
    waitKey(0);
    return 1;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-11-10 04:34:59 -0500

ThomasB gravatar image

Well, you might not be able to extract something better than there's encoded in the video. Normally the VideoCapture captures the video frames with their full resolution, thus your video resolution is that poor.

H264 is a compression format which uses the relation between frames to cut down on file size. I'm not entirely sure how the Videocapture behaves here, I'd expect it delivers you useable frames, but might also be it just delivers the "difference"-frames. Does your code perform well on uncompressed video data?

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-11-10 01:24:45 -0500

Seen: 195 times

Last updated: Nov 10 '13