Home > Blockchain >  Compact form for read and return frame from VideoCapture
Compact form for read and return frame from VideoCapture

Time:10-14

I have for example this easy function, but i would like make it more compact, have you suggestion for me?

VideoCapture camera = VideoCapture(0);

cv::Mat& OpenCvCamera::getFrame()
{
    Mat frame;
    camera >> frame;
    return frame;
}

I'd like to make it inline without using temporary variable "frame".

Is it possible?

CodePudding user response:

cv::VideoCapture::read is probably what you're looking for.

Allows you to get rid of the whole getFrame() function:

VideoCapture camera = VideoCapture(0);
cv::Mat frame;
camera.read(frame);

CodePudding user response:

It looks like you want to hide the existence of the VideoCapture object. If so, just do only it. i.e. Just wrap the VideoCapture::read(). No other change will not be needed.

//This object is invisible from the function user.
VideoCapture camera = VideoCapture(0);

//Type of this function (argument and return) is same as VideoCapture::read().
bool OpenCvCamera::getFrame( cv::Mat &frame )
{   return camera.read( frame );    }
  • Related