【发布时间】:2014-07-24 14:31:07
【问题描述】:
我目前正在尝试加快运行 SURF 算法以检测视频对象的应用程序。
我想做的是使用线程(可能是boost线程)来加速进程并拥有两个线程:
- 获取图像并对其进行处理,当算法在先前拍摄的帧上终止时,获取当前帧并再次运行
- 另一个专注于从相机获取图像并显示它。
如果你想要伪代码,这里是我现在在 main 函数中的代码:
Mat imageReference, imageFromVideo;
imageReference = imread(argv[1], CV_LOAD_IMAGE_COLOR);
VideoCapture camVid(0);
namedWindow("Display video");
namedWindow("Display ref");
imshow("Display ref", imageReference);
// Surf algo on reference image
FastHessian fh(&image);
Surf surf(fh.GetIntegralImg(), fh.GetIptVect());
surf.descriptors(false);
while (true) {
camVid >> imageFromVideo;
// Surf on frame from video
FastHessian fh2(&imageFromVideo);
Surf surf2(fh2.GetIntegralImg(), fh2.GetIptVect());
surf2.descriptors(false);
// Compare the two interest points from images
vector<pair<InterestPoint, InterestPoint> > matches;
matchIpoints(surf.getInterestPoints(), surf2.getInterestPoints(), matches);
drawIPoints(&imageFromVideo, matches);
int c = cvWaitKey(1);
if ((char) c == 27) break;
imshow("Display video", imageFromVideo);
imshow("Display ref", imageRef);
}
我真的不知道如何开始使用多线程,因为我以前从未这样做过。我应该使用 Mutex 还是使用 Semaphore?有没有几行代码可以做到这一点?
谢谢!
【问题讨论】:
标签: c++ multithreading opencv mutex