OpenCV在新版本中把很多C语言的代码都重新整理成了C++代码,让我们在使用的时候更加方便灵活。其中对于特征点的提取和匹配,充分体现了C++的强大。下面直接用例子来说明。假设我们有两幅图:1.bmp和2.bmp,要从中提取体征点并匹配,代码如下: // Load image from file IplImage *pLeftImage = cvLoadImage('1.bmp',CV_LOAD_IMAGE_GRAYSCALE); IplImage *pRightImage = cvLoadImage('2.bmp',CV_LOAD_IMAGE_GRAYSCALE); // Convert IplImage to cv::Mat Mat matLeftImage = Mat(pLeftImage, false); // Do not copy Mat matRightImage = Mat(pRightImage, false); // Key point and its descriptor vector vector Mat LeftDescriptor; Mat RightDescriptor; vector // Detect key points from image FeatureDetector *pDetector = new SurfFeatureDetector; //这里我们用了SURF特征点 pDetector->detect(matLeftImage, LeftKey); pDetector->detect(matRightImage, RightKey); delete pDetector; // Extract descriptors DescriptorExtractor *pExtractor = new SurfDescriptorExtractor; //提取SURF描述向量 pE |
|
来自: 昵称30114049 > 《待分类》