1.环境配置见上篇,大差不差就改了几个路径。其中lib库变成了opencv_world346d.lib,对应的dll库也变成了opencv_world346d.dll
2. 在XXXDlg.h中加入以下代码:
VideoCapture capture;
Mat frame;
Mat frame1;
CRect rect1;
string path = "D:\\1.mp4";
//读取已采集到本地计算机的视频
capture.open(path);
GetDlgItem(IDC_VIDEO)->GetClientRect(rect1);
//"video"进行imshow的窗口名
namedWindow("video", WINDOW_AUTOSIZE);
HWND hWnd1 = (HWND)cvGetWindowHandle("video");
HWND hParent1 = ::GetParent(hWnd1);
::SetParent(hWnd1, GetDlgItem(IDC_VIDEO)->m_hWnd);
::ShowWindow(hParent1, SW_HIDE);
if (!capture.isOpened())
{
//弹出MFC的消息窗口,提示视频打开失败
MessageBox(_T("打开视频失败!"));
}
else {
//设置定时器,定时器事件1, 触发频率是每30ms
SetTimer(1, 30, NULL);
}
if (nIDEvent == 1) {
capture >> frame;
//如果图像是空的,把这个事件关闭
if (frame.empty()) {
KillTimer(1);
}
else {
resize(frame, frame1, Size(rect1.Width(), rect1.Height()));
//显示画面
imshow("video", frame1);
}
}
#include
#include
//为了解决找不到cvGetWindowHandle()
#include
//添加opencv的头文件
#include
using namespace std;
using namespace cv;
成功显示录像文件