【发布时间】:2020-02-18 06:05:52
【问题描述】:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <thread>
using namespace std;
using namespace cv;
void testThread(OutputArray image){
image.create(100,32,CV_8U);
}
// void testThread(Mat image){
// image.create(100,32,CV_8U);
// }
// void testThread(Mat& image){
// image.create(100,32,CV_8U);
// }
int main(int argc,char** argv){
Mat left= imread("./left.png",CV_8U);
Mat right=imread("./right.png",CV_8U) ;
thread t1(testThread,left);
thread t2(testThread,right);
t1.join();
t2.join();
// testThread(left);
// testThread(right);
return 0;
}
为什么串行执行正常,并行抛出异常? 此外,如果您将 testThread 的原型更改为第二个原型,它也会在并行中正常执行,但第三个原型会失败。 打印到控制台的异常信息如下:
OpenCV(3.4.1) Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows)) in create, file /home/linjiaqin/software/opencv-3.4.1/modules/core/src/matrix_wrap.cpp, line 1240
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /home/linjiaqin/software/opencv-3.4.1/modules/core/src/matrix_wrap.cpp:1240: error: (-215) !fixedSize() || ((Mat*)obj)->size.operator()() == Size(_cols, _rows) in function create
【问题讨论】:
-
对不起,我忘了取消注释“Mat right”,我只想测试一个线程。
-
我不明白。那么它只能串行吗?
标签: c++ multithreading opencv opencv3.0