コード例 #1
0
void
findPairs( const CvSeq* objectKeypoints, const CvSeq* objectDescriptors,
           const CvSeq* imageKeypoints, const CvSeq* imageDescriptors, struct pairList * ptpairs )
{
    CvSeqReader reader, kreader;
    cvStartReadSeq( objectKeypoints, &kreader , 0 );
    cvStartReadSeq( objectDescriptors, &reader , 0 );


    struct pairList * pairs = initializePairList(ptpairs,objectDescriptors->total);
    if (pairs==0) { fprintf(stderr,"Could not allocate enough memory for pointer pairs\n"); return ; }

    int i;
    for( i = 0; i < objectDescriptors->total; i++ )
    {
        const CvSURFPoint* kp = (const CvSURFPoint*)kreader.ptr;
        const float* descriptor = (const float*)reader.ptr;
        CV_NEXT_SEQ_ELEM( kreader.seq->elem_size, kreader );
        CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader );
        int nearest_neighbor = naiveNearestNeighbor( descriptor, kp->laplacian, imageKeypoints, imageDescriptors );
        if( nearest_neighbor >= 0 )
        {
            pairs->item[i].p1 = i;
            pairs->item[i].p2 = nearest_neighbor;
        }
    }

    destroyPairList(&pairs);
}
コード例 #2
0
ファイル: vpKeyPointSurf.cpp プロジェクト: 976717326/visp
std::list<int*>* vpKeyPointSurf::matchPoint(std::list<float*> descriptorList, std::list<int> laplacianList)
{
  std::list<int*>* pairPoints = new std::list<int*>;

  if(descriptorList.size() != laplacianList.size()){
    vpTRACE("Error, the two lists have different number of element");
    return pairPoints;
  }

  CvSeqReader reader;
  cvStartReadSeq( ref_descriptors, &reader );

  std::list<float*>::const_iterator descriptorListIter = descriptorList.begin();
  std::list<int>::const_iterator laplacianListIter = laplacianList.begin();
  descriptorList.front();
  int indexList = 0;
  while(descriptorListIter != descriptorList.end()){
    float* descriptor = *descriptorListIter;

    int nearest_neighbor = naiveNearestNeighbor( descriptor, *laplacianListIter, ref_keypoints, ref_descriptors);

    if(nearest_neighbor >= 0){
      int* tab;
      tab = new int[2];
      tab[0] = nearest_neighbor;
      tab[1] = indexList;
      pairPoints->push_back(tab);
    }
    indexList++;
    ++descriptorListIter;
    ++laplacianListIter;
  }

  return pairPoints;
}
コード例 #3
0
ファイル: vpKeyPointSurf.cpp プロジェクト: 976717326/visp
//Find all the matched points
void findPairs( const CvSeq* objectKeypoints,
                const CvSeq* objectDescriptors,
                const CvSeq* imageKeypoints,
                const CvSeq* imageDescriptors,
                std::vector<int>& ptpairs )
{
  int i;
  CvSeqReader reader, kreader;
  cvStartReadSeq( objectKeypoints, &kreader );
  cvStartReadSeq( objectDescriptors, &reader );
  ptpairs.clear();

  for( i = 0; i < objectDescriptors->total; i++ )
  {
    const CvSURFPoint* kp = (const CvSURFPoint*)kreader.ptr;
    const float* descriptor = (const float*)reader.ptr;
    CV_NEXT_SEQ_ELEM( kreader.seq->elem_size, kreader );
    CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader );
    int nearest_neighbor = naiveNearestNeighbor( descriptor,
						 kp->laplacian,
						 imageKeypoints,
						 imageDescriptors );
    if( nearest_neighbor >= 0 )
    {
      ptpairs.push_back(i);
      ptpairs.push_back(nearest_neighbor);
    }
  }
}
コード例 #4
0
/*!

  \deprecated This method is deprecated, you should use
  matchPoint(std::list<float*> , std::list<int> )
  instead.

  Computes the SURF points given by their descriptor and laplacian and try to match
  them with the points in the reference list. Only the matched points
  are stored. The two lists must have the same number of element while they correspond
  the same unique list of point.

  \warning The list returned contains allocated data (2 int per element). Must be deleted to avoid memory leak.

  \param descriptorList : The list of the descriptor

  \param laplacianList  : The list of laplacian

  \return the list of the pair, the first element contains the index in the reference sequence and the second element contains the index in the list given in parameter.
*/
vp_deprecated vpList<int*>* vpKeyPointSurf::matchPoint(vpList<float*> descriptorList, vpList<int> laplacianList)
{
	vpList<int*>* pairPoints = new vpList<int*>;

	if(descriptorList.nb != laplacianList.nb){
		vpTRACE("Error, the two lists have different number of element");
		return pairPoints;
	}

  CvSeqReader reader;
  cvStartReadSeq( ref_descriptors, &reader );

  descriptorList.front();
  pairPoints->front();
  laplacianList.front();
  int indexList = 0;
  while(!descriptorList.outside()){
  	float* descriptor = descriptorList.value();

  	int nearest_neighbor = naiveNearestNeighbor( descriptor, laplacianList.value(), ref_keypoints, ref_descriptors);

		if(nearest_neighbor >= 0){
			int* tab;
			tab = new int[2];
			tab[0] = nearest_neighbor;
			tab[1] = indexList;
			pairPoints->addRight(tab);
		}
		indexList++;
		descriptorList.next();
		laplacianList.next();
  }

  return pairPoints;
}
コード例 #5
0
void ObjectAspect::findCorrespondences(const ObjectAspect& other, std::vector<cv::Point2i>& ptpairs) {
    const std::vector<cv::KeyPoint>& imageKeypoints = other.keypoints;
    const std::vector<float>& imageDescriptors = other.descriptors;
    const std::map<int,int>& imageMap2D3D = other.map2D3D;
    ptpairs.clear();

    for(size_t i = 0; i < keypoints.size(); i++) {
        if(map2D3D.find(i)==map2D3D.end())
            continue;

        const float* mvec = &descriptors[i*64];

        int nearest_neighbor = naiveNearestNeighbor(mvec,
                                                    imageKeypoints,
                                                    &imageDescriptors[0] ,
                                                    imageMap2D3D);
        if (nearest_neighbor >= 0) {
            ptpairs.push_back(cv::Point2i(i,nearest_neighbor));
        }
    }
}
コード例 #6
0
ファイル: vpKeyPointSurf.cpp プロジェクト: 976717326/visp
/*!

  Computes the SURF points in the current image I and try to matched
  them with the points in the reference list. Only the matched points
  are stored.

  \param I : The gray scaled image where the points are computed.

  \return the number of point which have been matched.
*/
unsigned int vpKeyPointSurf::matchPoint(const vpImage<unsigned char> &I)
{
  IplImage* currentImage = NULL;

  if((I.getWidth() % 8) == 0){
    int height = (int)I.getHeight();
    int width  = (int)I.getWidth();
    CvSize size = cvSize(width, height);
    currentImage = cvCreateImageHeader(size, IPL_DEPTH_8U, 1);
    currentImage->imageData = (char*)I.bitmap;
  }else{
    vpImageConvert::convert(I,currentImage);
  }
  
  /* we release the memory storage for the current points (it has to be kept 
      allocated for the get descriptor points, ...) */
  if(storage_cur != NULL){
    cvReleaseMemStorage(&storage_cur);
    storage_cur = NULL;
  }
  storage_cur = cvCreateMemStorage(0);

  cvExtractSURF( currentImage, 0, &image_keypoints, &image_descriptors,
     storage_cur, params );

  CvSeqReader reader, kreader;
  cvStartReadSeq( ref_keypoints, &kreader );
  cvStartReadSeq( ref_descriptors, &reader );


  std::list<int> indexImagePair;
  std::list<int> indexReferencePair;


  unsigned int nbrPair = 0;

  for(int i = 0; i < ref_descriptors->total; i++ )
  {
    const CvSURFPoint* kp = (const CvSURFPoint*)kreader.ptr;
    const float* descriptor = (const float*)reader.ptr;
    CV_NEXT_SEQ_ELEM( kreader.seq->elem_size, kreader );
    CV_NEXT_SEQ_ELEM( reader.seq->elem_size, reader );
    int nearest_neighbor = naiveNearestNeighbor( descriptor,
						 kp->laplacian,
						 image_keypoints,
						 image_descriptors );
    if( nearest_neighbor >= 0 )
    {
      indexReferencePair.push_back(i);
      indexImagePair.push_back(nearest_neighbor);
      nbrPair++;
    }
  }

  std::list<int>::const_iterator indexImagePairIter = indexImagePair.begin();
  std::list<int>::const_iterator indexReferencePairIter = indexReferencePair.begin();

  matchedReferencePoints.resize(0);

  if (nbrPair == 0)
    return (0);

  currentImagePointsList.resize(nbrPair);
  matchedReferencePoints.resize(nbrPair);

  for (unsigned int i = 0; i < nbrPair; i++)
  {
      int index = *indexImagePairIter;

      CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem(image_keypoints, index);

      currentImagePointsList[i].set_i(r1->pt.y);
      currentImagePointsList[i].set_j(r1->pt.x);

      matchedReferencePoints[i] = (unsigned int)*indexReferencePairIter;


      ++indexImagePairIter;
      ++indexReferencePairIter;
  }

  if((I.getWidth() % 8) == 0){
    currentImage->imageData = NULL;
    cvReleaseImageHeader(&currentImage);
  }else{
    cvReleaseImage(&currentImage);
  }

  return nbrPair;
}