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

2024-02-02

我正在开发c++我在那里使用的应用程序boost, opencv。并创建 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");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

c++ opencv图像不显示在boost线程内 的相关文章

随机推荐

  • 无法让浏览器启动 Express 下载

    继从this https stackoverflow com questions 53981780 angular cannot get file download from express using res download nored
  • 使用 Spring 表达式语言访问属性文件

    我使用 Spring Boot 使用 Thymeleaf 创建了一个简单的 Web 应用程序 我使用 application properties 文件作为配置 我想要做的是将名称和版本等新属性添加到该文件并访问 Thymeleaf 中的值
  • “easy_install -U cython”未能抱怨 vcvarsall.bat 和 -mno-cygwin

    在Windows下 似乎easy install具有 C 依赖关系并不是很容易 尝试 1 vcvarsall bat errors 我正在安装cython在Windows7下 与MinGw 我修改了Windows7的PATH包括C MinG
  • 在 Switch 语句中使用 Double

    下面的所有值都是双精度值 但 switch 需要整数值 有没有办法解决 switch fivePercentValue case floor 5 fivePercentValue 100 fivePercent backgroundColo
  • 开源项目但对 API 密钥保密

    我想使用 GitHub API 创建一个开源项目 但我在源代码中遇到了我的密钥的问题 我从不同的地方读到 永远不要在源代码中包含任何密钥 我同意这一点 我还发现了一些关于通过网络服务器进行身份验证而不是让用户获取自己的 API 密钥的模糊参
  • Rails Byebug 没有停止应用程序

    我想使用 byebug 来调试我的应用程序 但应用程序永远不会停止 尽管我已经把byebug在我的代码中 这是我的 Gemfile group development test do Call byebug anywhere in the
  • 为什么使用 CvScalar

    我需要帮助来理解 CvScalar 的功能到底是什么 例如下面的代码中 scalar 的任务是什么 for int i 0 i lt faces size i Point center Point faces i x faces i wid
  • C 编译中出现错误“错误:杂散'\342'”,“杂散'\200'”,“杂散'\234'”[重复]

    这个问题在这里已经有答案了 I used 记事本 https en wikipedia org wiki Notepad 2B 2B编写代码 当我尝试编译它时 我使用cc lab7 c o test1编译它 我得到了一堆杂散 342 杂散
  • setup.py install_require 带选项

    我需要添加rjsmin通过我的依赖install require在 setup py 中 rjsmin提供了一种通过使用禁用 c 扩展的方法 without c extensions像下面这样切换 python setup py insta
  • 如何在Android上启动NotificationListenerService

    我想使用NotificationListenerService 访问Android 手机上的通知 我检查了很多教程 但找不到他们在哪里调用该服务 我应该在MainActivity 上使用bindService 还是startService
  • 使用 doctest 测试异常链接和回溯输出

    如何使用 doctest 测试 多重回溯 看来要用几个ELLIPSIS and
  • 在 Angular 中页面加载(模态显示)后焦点输入后在 Safari iOS 中显示键盘

    我需要在页面加载或显示输入模式后设置焦点并打开键盘 简单的 focus 适用于 Android 以及 iPad 的横向模式 然而 在纵向模式和 iPhone 上 焦点已设置 但未显示键盘 我还尝试了添加并关注附加元素的解决方案 但它不适用于
  • Python 变量作用域和类

    在Python中 如果我定义一个变量 my var 1 2 3 并尝试访问它 init 类的功能 class MyClass def init self print my var 我可以访问它并打印my var没有说明 全局 my var
  • VSCode 找不到 python(Anaconda 安装)

    我刚刚在 windows10 上安装了 anaconda3 5 2 0 和 vscode 1 27 2 实际上是删除并重新安装 并尝试在终端上执行最简单的 python 代码 但是 我收到以下错误 jac p50 mnt c Users j
  • 对于方案中的每个和地图

    这两个功能在方案上有什么区别吗 我正在使用 Dr Racket R5RS 语言制作一个模拟器游戏 我无法决定哪个更好 for each从左到右计算列表元素上的给定函数 并丢弃函数的返回值 它非常适合对列表中的每个元素进行副作用操作 map以
  • Java中的构造函数继承

    您能告诉我以下代码中的问题吗 class boxdemo1 public static void main String args boxweight weightbox new boxweight 2 3 5 4 System out p
  • 如何在 Windows 命令行上使用 Unicode 字符?

    我们有一个项目在团队基础服务器 https en wikipedia org wiki Azure DevOps Server TFS 中包含非英语字符 当尝试编写一些与构建相关的事情的脚本时 我们偶然发现了一个问题 我们无法通过 给命令行
  • 为 Github Pages 中托管的 Jekyll 博客设置自定义子域

    我创建了一个由 Jekyll 驱动的博客 并通过 GitHub Pages 托管它 现在 我想设置一个子域 blog example com 但无法使其工作 我添加了一个 CNAME 文件 其文本为 blog example com 我在我
  • 在 Windows 8.1 上安装 PHP 5.6 后 Apache 2.2 无法启动

    我正在 Windows 8 1 计算机上设置开发环境 我成功安装了Apache 2 2 并下载了php 5 6 3 Win32 VC11 x86 我在 httpd conf 的末尾添加了以下几行 PHPIniDir C PHP5 LoadM
  • c++ opencv图像不显示在boost线程内

    我正在开发c 我在那里使用的应用程序boost opencv 并创建 boost 线程并调用该线程内的函数 该函数已得到 opencv imread 我使用 cvLoadimage 检查过 但得到了相同的结果 但程序无法完成并且程序退出 请