我目前正試圖加快和運行SURF算法檢測視頻對象的應用程序。OpenCV多線程與TBB的視頻處理
我想什麼做的是使用線程(可能提振線程),以加快這一進程,並有兩個線程:
- 一個是拍攝圖像,並對其進行處理,當算法終止框架上先前拍攝,取當前幀並再次運行
- 另一個側重於從相機中凝視圖像並顯示它。
如果你想僞代碼這裏就是我的主要功能有現:
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);
}
我不知道真正如何開始與多線程,因爲我從來沒有這麼做過。我應該用互斥還是信號來做?是否有簡單的代碼可以在幾行內完成此操作?
謝謝!