hello, everyone.I get an error when using cv::merge:
OpenCV(4.5.4) Error: Assertion failed (mv[i].size == mv[0].size && mv[i].depth() == depth) in cv::merge, file C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\merge.dispatch.cpp, line 129
my code:
unsigned char* y_data = new unsigned char[1920 * 1080];
unsigned char* u_data = new unsigned char[960 * 540];
unsigned char* v_data = new unsigned char[960 * 540];
FILE* file = fopen("MY_PATH\\test.yuv", "rb");
if (file != NULL) {
fread(y_data, 1, 1920 * 1080, file);
fread(u_data, 1, 960 * 540, file);
fread(v_data, 1, 960 * 540, file);
}
fclose(file);
file = NULL;
cv::Mat y(1080, 1920, CV_8UC1, y_data);
cv::Mat u(540, 960, CV_8UC1, u_data);
cv::Mat v(540, 960, CV_8UC1, v_data);
cv::resize(u, u, { u.size().width * 2, u.size().height * 2 }, 0, 0);
cv::resize(v, v, { u.size().width * 2, u.size().height * 2 }, 0, 0);
cv::Mat result;
std::vector<cv::Mat> channels{ y,u,v };
printf("channel number: %d\n", channels.size());
printf("channels: %d, %d, %d\n", y.channels(), u.channels(), v.channels());
printf("channels type: %d,%d,%d\n", y.type(), u.type(), v.type());
cv::merge(channels, result);//**here I get error**
cv::imshow("result", result);
cv::waitKey();
delete y_data;
delete u_data;
delete v_data;
the printf:
channel number: 3
channels: 1, 1, 1
channels type: 0,0,0
I’m using visual studio 2017 and opencv 4.5.4. The “test.yuv” is a yuv420 frame.
Could you tell me what’t wrong with my code? thank you in advance