opencv 用于从VideoCapture读取和返回帧的压缩表单

lnlaulya  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(100)

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?

zour9fqk

zour9fqk1#

看起来您想隐藏VideoCapture对象的存在。如果是这样,只需执行此操作即可。例如,只需 Package VideoCapture::read()。无需进行其他更改。

//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 );    }
y1aodyip

y1aodyip2#

cv::VideoCapture::read可能是您正在寻找的内容。
允许您摆脱整个getFrame()函数:

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

相关问题