我正在尝试在我的简单程序中验证bgslibrary(背景扣除算法)的性能。 首先,将YUV422转换为灰度,它只是从YUV中提取Y部分并将其保存到灰度图像的内存中:
void yuv_to_gray(void *yuv_ptr, void *gray_ptr, size_t size) { //size is YUY2 format bytes used, that is width*height*2
for (int i = 0; i!= size; i+=2) {
*(((unsigned char *)gray_ptr)+i/2) = *(((unsigned char *)yuv_ptr)+1+i);
}
}
然后我构建了opencv MAT类型,该类型用于过程函数,代码的主要部分如下所示:
{
void * gray;
if ((gray = (void *)malloc(size/2*sizeof(unsigned char)))==NULL){
cout << "malloc error" << endl;
return 1;
}
memset(gray, 0, size/2*sizeof(unsigned char));
yuv_to_gray(ptr, gray, size);
Mat frame_in_gray(height, width, CV_8UC1, gray);
Mat frame_out(height, width, CV_8UC1);
Mat frame_bg(height, width, CV_8UC1);
IBGS *fd;
fd = new FrameDifference;
clock_t start = clock();
fd->process(frame_in_gray, frame_out, frame_bg);
}
运行程序,错误报告为:
void bgslibrary :: algorithms :: IBGS :: init(const cv :: Mat&,cv :: Mat&,cv :: Mat&):断言img_input.empty()== false'失败。
从错误中得出的结论是,Mat frame_in_gray为空,但我确实使用了正确的构造函数,并将其数据链接指向* gray指针。有人可以提出建议吗?