先说说opencv,直接转载:https://www.cnblogs.com/WushiShengFei/p/11202250.html
怎么得到qimage就不说了,他的核心函数为:
bool g_needstop =false;void Record()
{
RECT rect;
//获取窗体位置大小
GetWindowRect(hd,&rect);
cv::Size frameSize;
frameSize.width=rect.right-rect.left;
frameSize.height=rect.bottom-rect.top;
cv::VideoWriter VideoWriter;
if(!VideoWriter.open("d:\\1.avi",CV_FOURCC('M', 'J', 'P', 'G'),40,frameSize))
return;
while(!g_needstop)
{
QPixmap pm;
GetGDIBitmap(hd,pm,0,0,frameSize.width,frameSize.height);
VideoWriter.write(ImageToMat(pm.toImage()));
} VideoWriter.release();
}
Mat ImageToMat(QImage img,QString imgFormat)
{
if(img.isNull())
return Mat();
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer,imgFormat.toLatin1().data());
_InputArray arrSrc(ba.data(), ba.size());
Mat mat = cv::imdecode(arrSrc, CV_LOAD_IMAGE_COLOR);
return mat;
}
继续说说用avilib来生成avi文件,实际是使用mjpg格式生成:
https://labisart.com/blog/index.php/Home/Index/article/aid/221