Hello, I am currently trying to use multithreading in opencv. However, this code is not working.
#include <iostream>
#include <thread>
#include "opencv2/nonfree/features2d.hpp"
#include "FeatureMatching.h"
#include "FaceDetection.h"
#include "AugmentedReality.h"
Mat colorImg;
VideoCapture capture(0);
//Captures image from camera
void doCapture(VideoCapture capture)
{
while (true)
{
capture.read(colorImg);
imshow("HUD", colorImg);
cvWaitKey(1);
}
}
//Deicides what to do
void doDecision()
{
while (true)
{
int k = waitKey(1);
if (k == 49)
{
cout << "Detecting..." << endl;
doMatch(colorImg);
}
else if (k == 50)
{
cout << "Detecting..." << endl;
doDetect(colorImg);
}
else if (k == 51)
{
cout << "Displaying..." << endl;
while (waitKey(1) != 51)
{
doAR(capture);
}
}
else if (k == 27)
{
cout << "Stop";
}
}
}
//Main function
int main()
{
thread t1(doCapture, capture);
thread t2(doDecision);
//cvNamedWindow("HUD", 0);
//cvSetWindowProperty("HUD", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
initMatch();
initFace();
initAR();
t1.join();
t2.join();
}
If anyone needs to see more of my code, I'll will do so. Can someone please tell what's the problem? Thanks in advance.