图像坐标与真实位置的对应方法

图像坐标与真实位置的对应方法

 

图像坐标与真实位置的对应方法,将图像中的任意点对应到真实坐标中去,可测量物体大小,物体位置等。

这个做法与图像配准中的寻找H矩阵做法相同,图像配准中,算法如surf,sift寻找特征点,穷举匹配点与点之间的对应关系。

本文做法类似标定的方法,Matlab中有对应工具,代码如下:


unregistered = imread('5.jpg');

ortho = imread('25.jpg');

h  = cpselect(ortho,unregistered);

t_concord = fitgeotrans(fixedPoints,movingPoints,'projective');

Rfixed = imref2d(size(ortho));
registered = imwarp(unregistered,t_concord,'OutputView',Rfixed);        

figure, imshowpair(ortho,registered,'blend');
imwrite(registered,'5-.jpg');

C++,opencv代码如下:

	vector imagePoints1, imagePoints2;
	imagePoints1.push_back(Point(118, 288));
	imagePoints1.push_back(Point(347, 285));
	imagePoints1.push_back(Point(585, 281));
	imagePoints1.push_back(Point(11, 460));
	imagePoints1.push_back(Point(351, 456));

	imagePoints2.push_back(Point(-60, 85));
	imagePoints2.push_back(Point(0, 85));
	imagePoints2.push_back(Point(60, 85));
	imagePoints2.push_back(Point(-60, 25));
	imagePoints2.push_back(Point(0, 25));


	Mat homo = findHomography(imagePoints1, imagePoints2, CV_RANSAC);

	Mat dd = (Mat_(3, 1) << 346, 248, 1);
	std::vector obj_corners(1);
	obj_corners[0] = cvPoint(346, 248); //obj_corners[1] = cvPoint(img_object.cols, 0);
	//obj_corners[2] = cvPoint(img_object.cols, img_object.rows); obj_corners[3] = cvPoint(0, img_object.rows);
	std::vector scene_corners(1);
	perspectiveTransform(obj_corners, scene_corners, homo);

 

 

你可能感兴趣的:(算法,图像处理)