cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sarslan
Visitor
Visitor
244 Views
Registered: ‎10-31-2019

xfopencv - uyvy2nv12 conversion failure

I am trying to use uyvy2nv12 hardware function for related conversion.

First of all I tried the cvtcolor example of the xfopencv library but at the end of the hardware function, the Y plane that is generated by uyvy2nv12, didn't turn out as expected. For the simplicity, I pasted the example code that is shared by xilinx in here:

 

	inputimg = cv::imread(argv[1], -1);
	if(!inputimg.data)
	{
		return -1;
	}
	int newwidth_y = inputimg.cols;
	int newheight_y = inputimg.rows;
	int newwidth_u_v = inputimg.cols>>1;
	int newheight_u_v = inputimg.rows>>1;

	cv::Size S0(newwidth_y,newheight_y);
	outputimg0.create(S0,CV_8UC1);
	error_img0.create(S0,CV_8UC1);

	cv::Size S1(newwidth_u_v,newheight_u_v);
	outputimg1.create(S1,CV_16UC1);
	error_img1.create(S1,CV_16UC1);

	img_width = inputimg.cols;
	img_height = inputimg.rows;


	static xf::Mat<XF_16UC1, HEIGHT, WIDTH, NPC1> imgInput(inputimg.rows,inputimg.cols);

	static xf::Mat<XF_8UC1, HEIGHT, WIDTH, NPC1> imgOutput0(newheight_y,newwidth_y);
	static xf::Mat<XF_8UC2, HEIGHT/2, WIDTH/2, NPC2> imgOutput1(newheight_u_v,newwidth_u_v);

	imgInput.copyTo((unsigned short int*)inputimg.data);

	printf ("About to call hardware function\n");

#if __SDSCC__
	hw_ctr.start();
#endif
	cvtcolor_uyvy2nv12(imgInput,imgOutput0,imgOutput1);
#if __SDSCC__
	hw_ctr.stop();
	uint64_t hw_cycles = hw_ctr.avg_cpu_cycles();
#endif
	
	printf("Returned from hardware function\n");

	outputimg0.data = imgOutput0.copyFrom();
	outputimg1.data = (unsigned char*)imgOutput1.copyFrom();

	xf::imwrite("out_UV.png",imgOutput1);
	xf::imwrite("out_Y.png",imgOutput0);

	refimage0 = cv::imread(argv[2],0);
	if(!refimage0.data)
	{
		std::cout << "Can't open Y ref image !!" << std::endl;
		return -1;
	}

 

 

I tried this code partition with the given input.jpg(2nd picture) and ref_Y.png(3rd picture). (I attached these files.)

So, I attached the resulting out_Y.png (1st picture). Why the output Y plane of uyvy2nv12 is so different from the reference Y plane ?

 

Thanks.

out_Y.png
input.jpg
ref_Y.png
0 Kudos
0 Replies