Ask Your Question
0

create FrameSource for super-res using createFrameSource_Empty

asked 2014-02-07 13:53:12 -0600

TerryS gravatar image

I am looking to perform SuperResolution in OpenCV using an image stack as opposed to a video file. Due to the number of images/file size I would prefer to not have an intermediate step creating a video file from the images. I created a function that calls createFrameSource_Empty and return a pointer to the main super-res code. However, I keep getting seg faults later on. Here is my function. Any help is appreciated.

// Creates a frame source from an image stack Ptr<framesource> createFrameSource_imageStack() { VideoCapture g_cap; Mat frame; int i = 270330; // should include leading zero int d = 1; char filename[1024];

// Generate an empty frame source structure
Ptr<FrameSource> frameSource;
frameSource = createFrameSource_Empty();

// Process 20 frames
while(1)
{
    // Get frame from capture
    //cout << "Variable i is " << i << endl;
    sprintf(filename, "/Users/terry/Documents/video_product_20frame/1_1_%07d.tif",i);
    g_cap.open(filename);
    g_cap >> frame;

    // Check if the frame was retrieved
    if(!frame.data)
    {
        cerr << "Could not retrieve frame.";
        exit (-1);
    }

    frameSource->nextFrame(frame);
    // quit after the 20th frame
    if (d == 20)
        break;
    i+=4;
    d++;
}
return frameSource;

}

edit retag flag offensive close merge delete

Comments

It is possible to call createFrameSource_Video on individual image files. However, each time it returns a new frameSource. Is it possible to append one frameSource to another? Note also that frame_source.cpp contains useful classes such as CaptureFrameSource and VideoFrameSource. However, I have been unable to call them without compiler errors. Is there a way to include these classes into my code?

TerryS gravatar imageTerryS ( 2014-02-13 11:47:04 -0600 )edit

A simple solution extend cv::superres::FrameSource with a setFrame member

class MyFrameSource : public cv::superres::FrameSource cv::Mat origFrame_; void MyFrameSource::setFrame(Mat & frame) { frame.copyTo(origFrame_); } void MyFrameSource::nextFrame(cv::OutputArray frame) { origFrame_.copyTo(frame); }

then cv::Ptr<myframesource> lowresSource(new MyFrameSource(cv::superres::createFrameSource_Empty(), scale));

and superRes->setInput(lowresSource);

then, in a i-loop, first copy your i-frame with setFrame then you call superRes->nextFrame(dest) and you will be using that frame. But you will get a TemporalAreaRadius*2+1 frames latency for superres begin to work as it should. You can, for example, loop your frameslist to use the first umprocesed frames.

MikeSZ gravatar imageMikeSZ ( 2016-08-30 14:35:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-07 09:26:53 -0600

MikeSZ gravatar image

updated 2016-09-07 09:30:26 -0600

A simple solution I'm using right now. Extend cv::superres::FrameSource with a setFrame member

class MyFrameSource : public cv::superres::FrameSource { cv::Mat origFrame_; void MyFrameSource::setFrame(Mat & frame) { frame.copyTo(origFrame_); } void MyFrameSource::nextFrame(cv::OutputArray frame) { origFrame_.copyTo(frame); } } then cv::Ptr<myframesource> lowresSource(new MyFrameSource(cv::superres::createFrameSource_Empty(), scale)); and superRes->setInput(lowresSource);

then, in the process loop, first copy your nput frame to framesource with setFrame(), then call superRes->nextFrame(dest) and you will be using that frame. But you will get a TemporalAreaRadius*2+1 frames latency for superres to begin to work as it should. You can, for example, loop your frameslist to use the first umprocesed frames. is not the best but it works.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-07 13:53:12 -0600

Seen: 1,557 times

Last updated: Sep 07 '16