多线程问题 opencv打开一个视频。。。

菜豆豆 2015-08-15 06:21:01
想让滚动条跟着视频帧来变化,我这样做合理吗!?程序一直闪退,求解决方法

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <cv.h>
#include <windows.h>
#include <iostream>
using namespace std;
using namespace cv;

int g_slider_position = 0;
CvCapture *g_capture = NULL;
static int g_frame_count = 0;

HANDLE mutex;

DWORD WINAPI funproc(LPVOID LP);

void onTrackbarSlide(int pos)
{
g_frame_count = pos;
cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);

}

int main()
{

/************************************************************************/
/* 滚动条控制视频播放进度 */
/************************************************************************/
mutex = CreateMutex(NULL,FALSE,"");
cvNamedWindow("aviControl");
g_capture = cvCreateFileCapture("C:\\Users\\Public\\Videos\\Sample Videos\\A.avi");

int frame = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
HANDLE hand = CreateThread(NULL,0,funproc,NULL,0,NULL);
CloseHandle(hand);
if (frame != 0)
{
cvCreateTrackbar("pos","aviControl",&g_slider_position,frame,onTrackbarSlide);
}
IplImage *frames;
while (1)
{
frames = cvQueryFrame(g_capture);
WaitForSingleObject(mutex,INFINITE);
g_frame_count++;
ReleaseMutex(mutex);
if (!frames)
break;
cvShowImage("aviControl",frames);
char c = cvWaitKey(33);
if (c==27)
{
break;
}
}
cvReleaseCapture(&g_capture);
cvDestroyWindow("aviControl");
return 0;
}

DWORD WINAPI funproc(LPVOID LP)
{
WaitForSingleObject(mutex,INFINITE);
onTrackbarSlide(g_frame_count);
ReleaseMutex(mutex);
cout<<g_frame_count<<endl;
return 0;
}
...全文
332 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-08-17
  • 打赏
  • 举报
回复
Multiple Threads in the User Interface http://msdn.microsoft.com/zh-cn/library/ms810439.aspx

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧