首先放上图像控件和按钮以及文本框控件。
其中主要遇到的问题是静态成员函数中参数传递第问题,后面通过采用结构体的方式将参数传入
在****dlg.h头文件中声明
struct info
{
CWnd *wnd;
char *path;
CWnd *nID;
};
public:
static UINT ReadVideo(LPVOID pParam);
在打开视频的按钮下启动线程
info *wndinfos = (info*)malloc(sizeof(info));
wndinfos->wnd = AfxGetMainWnd();//获取MFC框架
wndinfos->path = Edit_Path.GetBuffer(0);//传入文件路径
wndinfos->nID = AfxGetMainWnd();//传入显示控件的ID
AfxBeginThread(ReadVideo,wndinfos);//启动线程
读取视频的线程
UINT Cthread_cam_videoDlg::ReadVideo(LPVOID pParam)
{
info *dlg = (info*)pParam;
VideoCapture capture;
capture.open(dlg->path);
CRect rect;
dlg->nID->GetDlgItem(IDC_VIDEO)->GetClientRect(&rect);
int x = rect.Width();
int y = rect.Height();
/*********************获取视频参数信息******************************************/
const int FrameCount = (int)capture.get(CV_CAP_PROP_FRAME_COUNT);
int FrameNumber = (int)capture.get(CV_CAP_PROP_POS_FRAMES);
Mat frame,frame_show;
if (FrameCount == FrameNumber)
{
return 1;
}
while (FrameNumber<FrameCount)
{
capture >> frame;
FrameNumber++;
resize(frame, frame_show, Size(x, y), 0, 0, 1);
imshow("VIDEO", frame_show);
waitKey(30);
}
capture.release();
}