我正在尝试使用TBB来提升使用OpenCV的计算机视觉项目的性能。以下是代码中提供访问冲突的部分。
#include <opencv/cv.h>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "tbb/pipeline.h"
#include "tbb/tick_count.h"
#include "tbb/task_scheduler_init.h"
#include "tbb/tbb_allocator.h"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
string file = "myimage.jpg";
Mat* mats2=tbb::tbb_allocator<Mat>().allocate(100);
for (int i = 0 ; i < 100 ; ++i)
{
mats2[i]=imread(file); <===== Access Violation
imshow("temp",mats3[i]);
waitKey(1);
}
}
为什么这是访问冲突? Mats2不为0,并且明确分配给内存中的地址。我知道我可以使用的link中的其他函数,但我想知道tbb_allocator中会发生什么导致此错误。如果与malloc或scalable_malloc一起使用,代码不会出错。
答案 0 :(得分:0)
看起来,这是一个C-C ++问题。新建和删除工作但仍可扩展分配会导致访问冲突。听起来像是OpenCV用户的唯一选择。
答案 1 :(得分:-1)
我不知道这是否有帮助
imread(filename)
只是尝试从其内容推断文件的格式。 只需检查您需要如何使用此通话。