#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include <opencv2/features2d/features2d.hpp> 
#include <opencv2/xfeatures2d/nonfree.hpp> 
#include <vector>
#include <opencv2/opencv.hpp>
#include <cmath>
#include<iostream>

using namespace cv;
using namespace std; 

void uniquePoint(vector<Point2f> &imagePoints1, vector<Point2f> &imagePoints2, vector<vector<float>> imagevec)
{
	vector<Point2f> imagePoints3, imagePoints4;
	imagePoints3 = imagePoints1;
	imagePoints4 = imagePoints2;
	for (int i = 0; i < imagePoints1.size(); i++)
	{
		imagevec[i].push_back(imagePoints1[i].x);
		imagevec[i].push_back(imagePoints1[i].y);
	}
	sort(imagevec.begin(), imagevec.end());
	imagevec.erase(unique(imagevec.begin(), imagevec.end()), imagevec.end());

	int j = 0;
	for (int i = 0; i < imagePoints3.size(); i++)
	{
		if (j < imagevec.size())
		{
			if (imagePoints3[i].x == imagevec[j][0] && imagePoints3[i].y == imagevec[j][1])
			{
				imagePoints1[j].x = imagePoints3[i].x;
				imagePoints1[j].y = imagePoints3[i].y;
				imagePoints2[j].x = imagePoints4[i].x;
				imagePoints2[j].y = imagePoints4[i].y;
				j++;
			}
		}
	}
	imagePoints1.resize(imagevec.size());
    imagePoints2.resize(imagevec.size());
}

int main()
{
	vector<Point2f> imagePoints1(5), imagePoints2(5);
	imagePoints1[0].x = 1; imagePoints1[0].y = 2;
	imagePoints1[1].x = 3; imagePoints1[1].y = 4;
	imagePoints1[2].x = 3; imagePoints1[2].y = 6;
	imagePoints1[3].x = 1; imagePoints1[3].y = 2;
	imagePoints1[4].x = 3; imagePoints1[4].y = 6;
	imagePoints2[0].x = 1; imagePoints2[0].y = 2;
	imagePoints2[1].x = 4; imagePoints2[1].y = 7;
	imagePoints2[2].x = 4; imagePoints2[2].y = 8;
	imagePoints2[3].x = 1; imagePoints2[3].y = 2;
	imagePoints2[4].x = 3; imagePoints2[4].y = 4;
	vector<vector<float>> imagevec(imagePoints1.size());
	uniquePoint(imagePoints1, imagePoints2, imagevec);
	return 0;
	system("pause");
}

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐