1.获取视频流的第一帧并存储
为了显示视频文件的缩略图,将视频文件的第一帧取出来进行处理
eg:
bool CuseMat::captureAvFirst(CString av, CString keepPath, int resizeW , int resizeH )
{
cv::VideoCapture capture(av.GetString());//读取本地视频
if (capture.isOpened())
{
cv::Mat frame;
if (capture.read(frame))//读取视频的一帧
{
if(resizeW != 0 && resizeW != 0)
cv::resize(frame, frame, cv::Size(resizeW, resizeH));
cv::imwrite(keepPath.GetString(), frame);
return true;
}
}
return false;
}
2.修改png图像文件大小并进行存储
用到的png图片太大了,需要改小一点
eg:
//--https://pythonexamples.org/python-opencv-cv2-resize-image/
bool resizePic(CString picPath, CString outPath, int resizeW, int resizeH, bool isPng)
{
cv::Mat readyPic = cv::imread(picPath.GetString(), cv::IMREAD_UNCHANGED);
if (readyPic.empty())
{
return false;
}
if (readyPic.size().width == resizeW && readyPic.size().height == resizeH)
{
cv::imwrite(outPath.GetString(), readyPic);
return true;
}
cv::resize(readyPic, readyPic, cv::Size(resizeW, resizeH), cv::INTER_AREA);
if (readyPic.empty())
{
return false;
}
if (isPng) //另存为png
{
cv::imwrite(outPath.GetString(), readyPic, { CV_IMWRITE_PNG_COMPRESSION,9 });
}else
cv::imwrite(outPath.GetString(), readyPic);
return true;
}