Reputation: 1
The function ProcessFrames takes in one quadrant of the image, and applies a Canny Filter to it. But the thread created does not give out a Canny detected image. instead, I get the color quadrant of the image in imshow().
void ProcessFrames(Mat &image)
{
Mat test = image;
Canny(test, image, 5, 60, 3);
}
void main()
{
Mat frame;
Mat top_left, top_right, bot_left, bot_right;
String filename = "C:\\Users\\operator\\Downloads\\MODFAM1080I.mpg";
VideoCapture capture(filename);
if (!capture.isOpened())
throw "Error when reading video file!!";
while (1)
{
capture >> frame;
if (frame.empty())
break;
top_left = frame(Range(0, frame.rows / 2 - 1), Range(0, frame.cols / 2 - 1));
top_right = frame(Range(0, frame.rows / 2 - 1), Range(frame.cols / 2, frame.cols - 1));
bot_left = frame(Range(frame.rows / 2, frame.rows - 1), Range(0, frame.cols / 2 - 1));
bot_right = frame(Range(frame.rows / 2, frame.rows - 1), Range(frame.cols / 2, frame.cols - 1));
//Cropping the image into four quadrants to process it separately.
thread t1(ProcessFrames,top_left); //invoking a thread and passing first quadrant.
t1.join(); //joing the thread with the main function
imshow("Canny", top_left); // still shows color image of the first quadrant. Canny not reflected.
cvWaitKey(10);
}
}
Upvotes: 0
Views: 96
Reputation: 2355
std::thread
constructor copies everything.
If you want to pass data pointer and this data to be changed in the thread you must wrap it with std::ref()
.
Upvotes: 2