Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing in a cv::Mat? #23

Closed
antithing opened this issue Oct 10, 2017 · 1 comment
Closed

passing in a cv::Mat? #23

antithing opened this issue Oct 10, 2017 · 1 comment

Comments

@antithing
Copy link

antithing commented Oct 10, 2017

Hi, Thank you again for this code. i am attempting to pass cv::mat frames in,instead of using pangolin::Image format. I have this working, but the results are different when i run Mats, vs when I run the pangolin Image as in the example. My code is:

Eigen::Matrix4f IcpCuda::RunIcp(cv::Mat frame1, cv::Mat frame2)
{

        cv::Mat mat_ushort1(frame1.cols,frame1.rows, CV_16UC1);
	frame1.convertTo(mat_ushort1, CV_16UC1);

	cv::Mat mat_ushort2(frame1.cols, frame1.rows, CV_16UC1);
	frame2.convertTo(mat_ushort2, CV_16UC1);

	unsigned short* dataMat1 = mat_ushort1.ptr<unsigned short>();
	unsigned short* dataMat2 = mat_ushort2.ptr<unsigned short>();
	
	icpOdom.initICPModel(dataMat1);
	icpOdom.initICP(dataMat2);


.............

The working pangolin code I am using is:

uint64_t loadDepthFromPath(std::string filepath, pangolin::Image<unsigned short> & depth)
{

	pangolin::TypedImage depthRaw = pangolin::LoadImage(filepath, pangolin::ImageFileTypePng);

	pangolin::Image<unsigned short> depthRaw16((unsigned short*)depthRaw.ptr, depthRaw.w, depthRaw.h, depthRaw.w * sizeof(unsigned short));

	for (unsigned int i = 0; i < 480; i++)
	{
		for (unsigned int j = 0; j < 640; j++)
		{
			depth.RowPtr(i)[j] = depthRaw16(j, i) / 5;
		}
	}

	uint64_t time = getCurrTime();
	return time;
}

I realize this is a little off topic, but if you could help me out here it would be very much appreciated.

results:

//using the Mat frames
GeForce GTX 1080 Ti
ICP: 2.5480ms
ICP speed: 392Hz
 0.9998  0.0172 -0.0087  0.0003
-0.0172  0.9999 -0.0010  0.0002
 0.0087  0.0012  1.0000 -0.0002
 0.0000  0.0000  0.0000  1.0000

//using pangolin images
GeForce GTX 1080 Ti
ICP: 2.7740ms
ICP speed: 360Hz
 0.9998 -0.0184  0.0104  0.0068
 0.0184  0.9998  0.0039  0.0025
-0.0105 -0.0037  0.9999 -0.0094
 0.0000  0.0000  0.0000  1.0000

Thanks!

@antithing
Copy link
Author

antithing commented Oct 10, 2017

Solved. For anyone else who wants to do this:

 cv::Mat mat_ushort1(frame1.cols,frame1.rows, CV_16UC1);
	for (unsigned int i = 0; i < height; i++)
	{
		for (unsigned int j = 0; j < width; j++)
		{
			mat_ushort1.at<unsigned short>(i,j) = frame1.at<unsigned short>(i, j) / 5;
			mat_ushort2.at<unsigned short>(i, j) = frame2.at<unsigned short>(i, j) / 5;
		}
	}
	

	icpOdom.initICPModel((unsigned short*)mat_ushort1.data);
	icpOdom.initICP((unsigned short*)mat_ushort2.data);

Thank you again for the code. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant