栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

使用opencv中匹配点对的坐标提取方式

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用opencv中匹配点对的坐标提取方式

在opencv中,特征检测、描述、匹配都有集成的函数。vector bestMatches;用来存储得到的匹配点对。那么如何提取出其中的坐标呢?

 int index1, index2;
 for (int i = 0; i < bestMatches.size(); i++)//将匹配的特征点坐标赋给point
 {
 index1 = bestMatches.at(i).queryIdx;
 index2 = bestMatches.at(i).trainIdx;
 
 cout << keyImg1.at(index1).pt.x << " "
    << keyImg1.at(index1).pt.y << " "
    << keyImg2.at(index2).pt.x << " "
    << keyImg2.at(index2).pt.y << endl;
 }

补充知识:OpenCV 如何获取一个连通域中的所有坐标点

#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
 
int main(int argc, char* argv[])
{
    IplImage* img;
    img = cvLoadImage("D:\OOTT\WEEK5\2.png");
    IplImage* gray = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
    cvCvtColor(img,gray,CV_BGR2GRAY);
    cvThreshold(gray,gray,128,255,CV_THRESH_BINARY);
    CvMemStorage* storage = cvCreateMemStorage();
    CvSeq * first_contour = NULL;
    int Ncontour = cvFindContours(gray,storage,&first_contour,sizeof(CvContour),CV_RETR_LIST); 
    //Ncontour为cvFindContours函数返回的轮廓个数
    for(CvSeq* c = first_contour;c!= NULL;c=c->h_next)
    { 
    //    cvDrawContours(img,c,cvScalar(255,255,0),cvScalar(255,0,255),0,2,8);
 cvNamedWindow("contours",CV_WINDOW_AUTOSIZE);
    //    cvShowImage("contours",img);
 for(int k = 0;k total;++k)
 {
     CvPoint* p = CV_GET_SEQ_ELEM(CvPoint,c,k);
     printf("(%d,%d)n",p->x,p->y);
 
 }    
 CvRect rect;
 rect = cvBoundingRect(c,0);
 cvFloodFill(img,cvPoint(img->width/2,img->height/2),cvScalar(255,255,255),cvScalar(20),cvScalar(20),NULL,4,NULL);
cvShowImage("contours",img); 
 
 int Num[500][500];
 for (int i=0;i<(img->height-5);i++)
     for (int j=0;j<(img->width-5);j++)
     {
  CvScalar S0;
  S0=cvGet2D(img,i,j);
  if(S0.val[0] == 255)
      Num[i][j]=1;
  else
      Num[i][j]=0;
  printf("(%d,%d)n",i,j);
     }
 
    }
    cvWaitKey(0);
    cvReleaseImage(&img);
    cvReleaseImage(&gray);
    cvDestroyWindow("contours");
    return 0;
}

以上这篇使用opencv中匹配点对的坐标提取方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/18988.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号