I already wrote a program that detects different objects, and i'm now working on a tracking module to track the objects of interest. Because the detection isn't as fast, I'm hoping to pass in one frame with the detected objects about every 10-30 frames, and have the tracking module use camshift + kalman filtering to track the objects in the video stream until another new image with the detected objects is received from the detection module.
I'm pretty new to boost and c++ multi-threading in general and I wrote the following code just to see if I can be passing in frames from the detection module to the tracking module. For some reason, everything just freezes after the tracking module has received two imags. Any ideas why? Is there a better way to go about this? Thanks!
Main Thread (Detection module might work in a similar manner)
int main(int argc, char *argv[]){
cout << "main started" << endl;
Tracker tracker("Tracker");
tracker.start(imread("/home/cosyco/Desktop/images/lambo1.jpeg", CV_LOAD_IMAGE_COLOR));
boost::posix_time::seconds sleepTime(5);
cout << "main starting sleep" << endl;
boost::this_thread::sleep(sleepTime);
cout << "main just woke up, switching image" << endl;
tracker.resetImage(imread("/home/cosyco/Desktop/images/lambo2.jpeg", CV_LOAD_IMAGE_COLOR));
cout << "main sleeping second time" << endl;
boost::this_thread::sleep(sleepTime);
cout << "main just woke up, switching image" << endl;
tracker.resetImage(imread("/home/cosyco/Desktop/images/lambo3.jpeg", CV_LOAD_IMAGE_COLOR));
cout << "main sleeping third time" << endl;
boost::this_thread::sleep(sleepTime);
cout << "main just woke up, switching image" << endl;
tracker.resetImage(imread("/home/cosyco/Desktop/images/lambo4.jpeg", CV_LOAD_IMAGE_COLOR));
tracker.join();
cout << "main done" << endl;
return 0;
}
Tracker:
#include <iostream>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
class Tracker{
private:
string name;
Mat trackerImage;
boost::thread trackerThread;
public:
Tracker (string newName){
cout << "creating tracker : " << newName << "created" << endl;
name = newName;
}
void track(Mat image){
image.copyTo(trackerImage);
informUpdate();
// use this new image to generate a histogram for camshift on the next
//few images in the video stream before a new image with the detected object is received
for (; ; ){
// cout << "tracking" << endl;
}
}
void start(Mat image){
cout << "in tracker's start" << endl;
// trackerThread = boost::thread(&Tracker::track, this, trackLimit);
trackerThread = boost::thread(&Tracker::track, this, image);
}
void join(){
trackerThread.join();
}
void resetImage(Mat image){
track(image);
}
void informUpdate(){
cout << "\033[1;31m image updated \033[0m" << endl;
}
};