create FrameSource for super-res using createFrameSource_Empty
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;
}
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?
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.