ERR “Assertion `img_input.empty() == false' failed” in convert YUV to Grayscale
I am trying to verify bgslibrary(background substraction algorithm in ) performance in my simple program. first, convert YUV422 to grayscale, it is just extract Y part from YUV and save it to memory of gray image:
void yuv_to_gray(void *yuv_ptr, void *gray_ptr, size_t size) {
for (int i = 0; i!= size; i+=2) {
*(((unsigned char *)gray_ptr)+i/2) = *(((unsigned char *)yuv_ptr)+1+i);
}
}
then I constructed opencv MAT types, which used in process function, main part of the code shown as below:
{
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);
delete fd;
free(gray);
}
then start to run program, error reported as:
void bgslibrary::algorithms::IBGS::init(const cv::Mat&, cv::Mat&, cv::Mat&): Assertion `img_input.empty() == false' failed.
Concluded from the error, Mat frame_in_gray is empty , but I do use the correct construction function, and make its data link to *gray pointer. Any guys can give some suggestion ?
how would we know, what your 3rdparty library expects there ?