线程末尾未处理的异常

时间:2019-06-06 18:00:02

标签: c++ windows multithreading opencv

您好,我现在正试图使用​​一个线程使用OpenCV 2.3.1读取有关2张图像的一些信息,尽管我可以毫无问题地检索2张图像的大小,但是当到达末尾时会出现错误线程。

  

OpenCvDemo.exe中0x00348A56处未处理的异常:无效参数已传递给认为无效参数致命的函数。

因为我可以很好地读取图像的大小,所以我知道它们不是空的或任何东西。在另一项测试中,我分离了线程并将其置于“睡眠”状态5秒钟,主函数执行正常并显示了图像,但是一旦线程醒来并到达末尾,它将使应用程序崩溃并显示与上述相同的错误。

不幸的是,我需要使用OpenCV 2.3.1,因为这只是对更大应用程序的测试。

我该如何解决这个问题,或者至少是什么原因造成的?

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <thread>
#include <opencv2/opencv.hpp>

void Loop(cv::Mat &image1, cv::Mat &image2) {

    std::vector<uchar> buff1;
    std::vector<uchar> buff2;

    cv::imencode(".png", image1, buff1);
    cv::imencode(".png", image2, buff2);

    int imageSize1 = buff1.size();
    int imageSize2 = buff2.size();

    std::cout << "Size " << imageSize1 << "\n";
    std::cout << "Size " << imageSize2 << "\n";
}

int main()
{
    cv::Mat image1 = cv::imread("C:\\Users\\Cesar\\Pictures\\happyface.png", 1);
    cv::Mat image2 = cv::imread("C:\\Users\\Cesar\\Pictures\\happyface.png", 1);

    std::thread mythread(Loop, std::ref(image1), std::ref(image2));
    mythread.join();

    cv::imshow("name", image1);
    cv::waitKey(0);

    return 0;
}

调用栈

OpenCvDemo.exe!_invoke_watson(const wchar_t * expression, const wchar_t * function_name, const wchar_t * file_name, unsigned int line_number, unsigned int reserved) Line 224   C++
OpenCvDemo.exe!_invalid_parameter(const wchar_t * expression, const wchar_t * function_name, const wchar_t * file_name, unsigned int line_number, unsigned int reserved) Line 113   C++
[External Code] 
OpenCvDemo.exe!Loop(cv::Mat & image1, cv::Mat & image2) Line 23 C++
[External Code] 
OpenCvDemo.exe!invoke_thread_procedure(unsigned int(__stdcall*)(void *) procedure, void * const context) Line 92    C++
OpenCvDemo.exe!thread_start<unsigned int (__stdcall*)(void *)>(void * const parameter) Line 115 C++
[External Code] 
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]  

0 个答案:

没有答案
相关问题