gpt4 book ai didi

c++ - 主函数跳过线程并且不加入以显示所需的输出

转载 作者:行者123 更新时间:2023-11-28 01:47:04 26 4
gpt4 key购买 nike

ProcessFrames 函数获取图像的一个象限,并对其应用 Canny 过滤器。但是创建的线程不会给出 Canny 检测到的图像。相反,我在 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);
}
}

最佳答案

std::thread 构造函数复制所有内容。如果你想传递数据指针并且这个数据要在线程中改变,你必须用 std::ref() 包装它。

关于c++ - 主函数跳过线程并且不加入以显示所需的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44634117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com