2017-11-08 4 views
0

SIFT 설명자와 FLANN 일치 프로그램을 사용하여 두 그림 사이의 최소 일치 거리를 얻습니다. 첫 번째 그림은 쿼리 그림이고 두 번째 그림은 데이터 집합의 그림입니다. 루프를 사용하여 하나씩 두 번째 그림을로드하려고하지만 첫 번째 반복 직후에 프로그램은 런타임에 첫 번째 반복 결과를 표시 한 후 충돌하고 두 번째 반복을 입력하지 못합니다. 나는 opencv 2.4.13과 vs2017을 사용하고있다. 내가 많이 시도하고 여기 내 문제와 관찰이다설명자 일치 후 opencv 프로그램 충돌

#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include "opencv2/nonfree/nonfree.hpp" 
#include "opencv2/nonfree/features2d.hpp" 
#include <opencv2/legacy/legacy.hpp> 

#include <iostream> 
#include <stdio.h> 
#include <algorithm> 
#include <vector> 

using namespace std; 
using namespace cv; 

#define IMAGE_folder "D:\\Project\\dataset1" // change to your folder location 

int main() 
{ 
    initModule_nonfree(); 
    const int filename_len = 900; 
    char tempname1[filename_len]; 
    sprintf_s(tempname1, filename_len, "%s\\%s", IMAGE_folder, "995.jpg"); 
    Mat i1 = imread(tempname1); 
    Mat img1, img2; 
    cvtColor(i1, img1, COLOR_BGR2GRAY); 

    if (!i1.data) 
    { 
     printf("Cannot find the input image!\n"); 
     system("pause"); 
     return -1; 
    } 

    std::vector<KeyPoint> key_points1, key_points2; 
    Mat descriptors1, descriptors2; 

    SIFT sift; 
    sift(img1, Mat(), key_points1, descriptors1); 

    for (int i = 990; i < 1000; i++) 
    { 
     initModule_nonfree(); 
     cout << i << endl; 
     char tempname2[filename_len]; 
     sprintf_s(tempname2, filename_len, "%s\\%d.jpg", IMAGE_folder, i); 
     Mat i2 = imread(tempname2); 
     if (!i2.data) 
     { 
      printf("Cannot find the input image!\n"); 
      system("pause"); 
      return -1; 
     } 
     cvtColor(i2, img2, COLOR_BGR2GRAY); 
     sift(img2, Mat(), key_points2, descriptors2); 

     FlannBasedMatcher matcher; 
     vector<DMatch> matches; 
     matches.clear(); 
     matcher.match(descriptors1, descriptors2, matches); //if I comment this line and the code below to show the distance, it can work 

     double max_dist = 0; 
     double min_dist = 100; 

     for (int j = 0; j < descriptors1.rows; j++) 
     { 
      double dist = matches[j].distance; 
      if (dist < min_dist) 
       min_dist = dist; 
      if (dist > max_dist) 
       max_dist = dist; 
     } 

     //matcher.clear(); //I've tried these four but still cannot help 
     //matches.clear(); 
     //key_points1.clear(); 
     //key_points2.clear(); 

     printf("-- Max dist : %f \n", max_dist); 
     printf("-- Min dist : %f \n", min_dist); 
     cout << "Done!" << endl; 
    } 

    //waitKey(0); 
    return 0; 
} 

: 나는 반복을 사용하기 때문에

  1. 그것은하지 않습니다 아래는 내 코드입니다. matcher.match(descriptors1, descriptors2, matches); 만 실행하면 실행 후 충돌이 발생합니다.
  2. SURF 설명자 또는 BruteForceMatcher에도 작동하지 않습니다. 위의 코드와 동일한 문제가 있습니다. SURF를 사용하여 opencv 자습서와 다른 코드 조각을 사용했지만 결과를 표시 한 후에도 여전히 충돌합니다. Example code from opencv tutorial see here
  3. 나는 또한 대답 했는데도 initModule_nonfree();을 시도했지만 여전히 도움이되지 않았습니다.
  4. "완료!"표시 후 프로그램이 충돌합니다. 다음 반복으로 들어 가지 않습니다.
  5. matcher.match(descriptors1, descriptors2, matches); 및 아래 관련 코드를 삭제하면 제대로 작동 할 수 있습니다. 따라서 문제는 "일치"기능을 사용해야합니다.

미리 감사드립니다.

----------------------------- 업데이트 ---------------- -------------

내 포함과 연결 라이브러리는 다음과 같습니다

C : \의 Program Files (x86) \ OpenCV의 \ 구축 \이 C 포함 : \ 프로그램 파일 C : \ Program Files (x86) \ opencv \ build \ include \ opencv2

C : \ Program Files (x86) \ opencv \ build \ x64 \ vc12 \ staticlib \ opencv \ build \ include \ opencv C : \ Program Files (x86) \ opencv \ build \ x64 \ vc12 \ lib

opencv_objdetect2413.lib opencv_ts2413.lib opencv_video2413.lib opencv_nonfree2413.lib opencv_ocl2413.lib opencv_photo2413.lib opencv_stitching2413.lib opencv_superres2413.lib opencv_videostab2413.lib opencv_calib3d2413.lib opencv_contrib2413.lib opencv_core2413.lib opencv_imgproc2413.lib 개방 opencv_highgui2413.lib opencv_gpu2413.lib opencv_flann2413.lib opencv_features2d2413.lib cv_legacy2413.lib opencv_ml2413.lib

구성에 문제가 없을 것 같아요 ... x86의 릴리스 모드에서 사용합니다.

+0

표시 및 링크 된 라이브러리 표시 – Miki

+0

감사합니다. 내 질문에 추가되었습니다. – Wendy

+0

64 비트 라이브러리에 연결하고 vc12로 빌드하십시오 (Visual Studio 2013). 분명히 이것은 작동하지 않습니다 – Miki

답변

0

나는이 문제를 발견했다. 이 코드는 vs2017 대신 opencv2.4.13 및 vs2012에서 작동합니다. 아마도 opencv2.4.13이 vs2017과 호환되지 않기 때문일 수 있습니다.