cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
555 Views
Registered: ‎03-14-2019

Help implementing Remap() with xfOpenCV

Jump to solution

Hi! I'm trying to write a program to perform a remap based in the camera parameters to solve the barrel effect.

I have calculated the camera matrix and distortion coefficients with an OpenCV program, and the new camera matrix with another OpenCV function, and those are the input values I used for xf::InitUndistortRectifyMapInverse(), which returns the maps I need to use in xf::remap(). The program is like the following:

int main(int argc, char** argv){

	//The input matrix representing the camera in the old coordinate system
	ap_fixed<32, 12> cameraMatrix[9] = {2.0275377339070669e+03, 0., 9.5950000000000000e+02,
										0., 2.0275377339070669e+03, 5.3950000000000000e+02,
										0., 0., 1.};

	//The input distortion coefficients (k1,k2,p1,p2,k3)
	ap_fixed<32, 12> distCoeffs[5] = {-4.2891185432986179e-01, -4.4634579643931555e-02, 0., 0., 1.0981159168852910e+00};

	//The input transformation matrix is equal to Invert(newCameraMatrix*R), where
	//newCameraMatrix represents the camera in the new coordinate system and R is the rotation
	//matrix.. This processing will be done outside the synthesizable block
	ap_fixed<32, 12> ir[9] = {1.8051848144531250e+03, 0., 9.5899829962644435e+02,
								0., 1.8044514160156250e+03, 5.3899986425434327e+02,
								0., 0., 1.};



	xf::Mat<XF_32FC1, HEIGHT, WIDTH, XF_NPPC1> map_x(HEIGHT, WIDTH);
	xf::Mat<XF_32FC1, HEIGHT, WIDTH, XF_NPPC1> map_y(HEIGHT, WIDTH);


	xf::InitUndistortRectifyMapInverse<9, 5, XF_32FC1, HEIGHT, WIDTH, XF_NPPC1>
				(cameraMatrix,
				 distCoeffs,
				 ir,
				 map_x,
				 map_y,
				 9,
				 5);


	xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> in(HEIGHT, WIDTH);
	xf::Mat<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1> out(HEIGHT, WIDTH);

	in = xf::imread<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1>("im0.jpg", 0);

	xf::remap<2, XF_INTERPOLATION_BILINEAR , XF_8UC1, XF_32FC1, XF_8UC1, HEIGHT, WIDTH, XF_NPPC1, false>(in, out, map_x, map_y);

	xf::imwrite<XF_8UC1, HEIGHT, WIDTH, XF_NPPC1>("out.jpg", out);

	return 0;
}

The thing is, with this program I'm getting a black image as output, I don't know the reason. The ir parameter I'm usign is the original newCameraMatrix I got from the OpenCV program, do I have to change it in some way?

Also, actually I want to get the maps like in InitUndistortRectifyMap, not InitUndistortRectifyMapInverse. What changes should I do in order to obtain those maps?

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
Highlighted
522 Views
Registered: ‎03-14-2019

Re: Help implementing Remap() with xfOpenCV

Jump to solution

I figured it out. I had to invert the ir matrix in order to get the right map values.

Also, I had to increase the remap WIN_ROWS from 2 to 128 for it to process a 1920x1080 image. 

After changing that, I'm getting the desired result.

View solution in original post

0 Kudos
1 Reply
Highlighted
523 Views
Registered: ‎03-14-2019

Re: Help implementing Remap() with xfOpenCV

Jump to solution

I figured it out. I had to invert the ir matrix in order to get the right map values.

Also, I had to increase the remap WIN_ROWS from 2 to 128 for it to process a 1920x1080 image. 

After changing that, I'm getting the desired result.

View solution in original post

0 Kudos