VS2013+opencv3.0实现多线程摄像头和视频文件的同时播放

首先放上图像控件和按钮以及文本框控件。
MFC界面
其中主要遇到的问题是静态成员函数中参数传递第问题,后面通过采用结构体的方式将参数传入
在****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();
}

最终界面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值