gpt4 book ai didi

c++ opencv图像不显示在boost线程内

转载 作者:行者123 更新时间:2023-11-28 06:16:04 27 4
gpt4 key购买 nike

我正在开发 c++ 应用程序,我使用了 boostopencv。并创建 boost 线程并调用该线程内的函数。该函数已获取 opencv imread(我使用 cvLoadimage 检查但我得到了相同的结果)但是程序无法完成并且程序退出。

请在下面找到我使用的代码

boost::thread *thread_reconstruct; 

int main( int argc, const char** argv )
{

thread_reconstruct = new boost::thread( &FuncCreate );

return 0;

}

void FuncCreate()
{
while (true)
{
compute_left_descriptors(g_nameRootFolder.c_str());
}

}

void compute_left_descriptors(const char* name_dir)
{

char namebuf[1024];


sprintf(namebuf, "%s/Left/%04d_left.bmp", name_dir, 1);

// Program ended with exit code: 0 programe exit from here.
Mat input_left = imread(namebuf, CV_LOAD_IMAGE_COLOR);

imshow("Right View", input_left);
waitKey(0);

printf("done\n");
}

最佳答案

请试试这个版本的代码并告诉我们它是否有效

boost::thread *thread_reconstruct; 

int main( int argc, const char** argv )
{

cv::namedWindow("Right View"); // this will create a window. Sometimes new windows can't be created in another thread, so we do it here in the main function.

thread_reconstruct = new boost::thread( &FuncCreate );

thread_reconstruct->join(); // this will make your program wait here until the thread has finished processing. Otherwise your program would exit directly.

return 0;

}

void FuncCreate()
{
while (true)
{
compute_left_descriptors(g_nameRootFolder.c_str());
}
}

void compute_left_descriptors(const char* name_dir)
{

char namebuf[1024];


sprintf(namebuf, "%s/Left/%04d_left.bmp", name_dir, 1);

// Program ended with exit code: 0 programe exit from here.
Mat input_left = imread(namebuf, CV_LOAD_IMAGE_COLOR);

if(input_left.empty()) printf("could not load image\n");

imshow("Right View", input_left);
waitKey(0); // if you dont want to press a key before each new image, you can change this to waitKey(30);

printf("done\n");
}

关于c++ opencv图像不显示在boost线程内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30286144/

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