2012-03-28 8 views
0

weiß jemand, wie funktioniert die detect-Funktion? zum Beispiel hier:Funktionserkennung in Features2d

Mat img = imread (...);  
SurfFeatureDetector detector(400); 
vector<KeyPoint> keypoints; 
detector.detect(img, keypoints); 

vor allem, wie es in den Schlüsselpunkten schreibt.

ich einige Koordinaten in keypoints schreiben müssen ohne

detector.detect(...); 
mit

Dies funktioniert nicht

keypoints.push_back(KeyPoint(i,j); 

nächste Problem: Ich habe die Funktion:

void trajkovic(Mat img, vector<KeyPoint> keypoints) 
{ for(int i = 0; i < img.rows-3; i++) 
     for(int j = 0; j < img.cols-3; j++) 
     { Point2f keyPointLocation(i, j); 
      keypoints.push_back(KeyPoint(keyPointLocation, 1)); } } 

int main() 
{ Mat img_object = imread(".../box.png", CV_LOAD_IMAGE_GRAYSCALE); 
    Mat img_scene = imread(".../box_in_scene.png", CV_LOAD_IMAGE_GRAYSCALE); 

    std::vector<KeyPoint> keypoints_object, keypoints_scene; 
    trajkovic(img_object, keypoints_object); 
    trajkovic(img_scene, keypoints_scene); 
  • anstelle von (* detector.detect (img_object, keypoints_object); *)

    //-- Step 2: Calculate descriptors (feature vectors) 
    SurfDescriptorExtractor extractor; 
    
    Mat descriptors_object, descriptors_scene; 
    
    extractor.compute(img_object, keypoints_object, descriptors_object); 
    extractor.compute(img_scene, keypoints_scene, descriptors_scene); 
    
    //-- Step 3: Matching descriptor vectors using FLANN matcher 
    FlannBasedMatcher matcher; 
    std::vector<DMatch> matches; 
    matcher.match(descriptors_object, descriptors_scene, matches); 
    
    double max_dist = 0; double min_dist = 100; 
    
    //-- Quick calculation of max and min distances between keypoints 
    for(int i = 0; i < descriptors_object.rows; i++) 
    { double dist = matches[i].distance; 
        if(dist < min_dist) min_dist = dist; 
        if(dist > max_dist) max_dist = dist; 
    } 
    
    printf("-- Max dist : %f \n", max_dist); 
    printf("-- Min dist : %f \n", min_dist); 
    
    //-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist) 
    std::vector<DMatch> good_matches; 
    
    for(int i = 0; i < descriptors_object.rows; i++) 
    { if(matches[i].distance < 3*min_dist) 
        { good_matches.push_back(matches[i]); } 
    } 
    
    Mat img_matches; 
    drawMatches(img_object, keypoints_object, img_scene, keypoints_scene, 
          good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), 
          vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); 
    
    
    //-- Localize the object from img_1 in img_2 
    std::vector<Point2f> obj; 
    std::vector<Point2f> scene; 
    
    for(int i = 0; i < good_matches.size(); i++) 
    { 
        //-- Get the keypoints from the good matches 
        obj.push_back(keypoints_object[ good_matches[i].queryIdx ].pt); 
        scene.push_back(keypoints_scene[ good_matches[i].trainIdx ].pt); 
    } 
    
    Mat H = findHomography(obj, scene, CV_RANSAC); 
    
    cvWaitKey(0); 
    return 0; 
    

    }

in findHomography habe ich einen Fehler: „Assertion fehlgeschlagen (npoints> = 0 & & points2.Vector (2) == npoints)) in findHomography, Datei /modules/calib3d/src/fundam.cpp, Linie 1062"

was falsch ist ? Ich denke, dass etwas nicht stimmt mit

keypoints.push_back(KeyPoint(keyPointLocation, 1)); 

Dank viel

+0

Sie sollten anrufen 'keypoints.push_back (KeyPoint (i, j));' – karlphillip

+0

Ich habe den gleichen Fehler, das spielt keine Rolle Point2f keyPointLocation (i, j); keypoints.push_back (KeyPoint (keyPointLocation, 1)); oder keypoints.push_back (KeyPoint (i, j, 1)); – fen1ksss

Antwort

1

Zunächst einmal sollten Sie die opencv documentation gehen zu werfen. cv::KeyPoint ist eine Struktur zum Speichern von Punkten von cv::FeatureDetector Objekt erkannt. Es enthält Koordinaten des Schlüsselpunkts, Durchmesser der sinnvollen Nachbarschaft, Orientierung und Antwort. Die Berechnung von Schlüsselpunkten hängt von der Detektordefinition ab (Sift, Surf, Mser, ...)

Start here!

+0

"Es enthält Koordinaten des Schlüsselpunkts, Durchmesser der sinnvollen Nachbarschaft, Orientierung und Antwort." für (int i = 0; i fen1ksss

+0

Wahrscheinlich verstehe ich den Prozess nicht, wie man in cv :: KeyPoint schreibt, richtig ? – fen1ksss

1

Wenn Sie manuell KeyPoint's erstellen, ist hier eine kleine Probe für den Einstieg:

vector<KeyPoint> keyPoints; 
for(int i = 0; i < 10; i++) 
{ 
    for(int j = 0; j < 10; j++) 
    { 
     Point2f keyPointLocation(i, j); 
     float meaningfulNeighborhoodDiameter = 5.0; 
     keyPoints.push_back(KeyPoint(keyPointLocation, meaningfulNeighborhoodDiameter)); 
    } 
} 

Hoffnung, das hilft!

+0

so das, fast das gleiche: keypoints.push_back (KeyPoint (i, j, 5.0); und ich habe immer noch einen Fehler mit der Funktion, ich werde den Text in meiner bearbeiteten Frage – fen1ksss

+1

Nein zeigen. Das ist nicht das Gleiche. 'KeyPoint' verwendet ein' Point2f'-Objekt, nicht zwei ganzzahlige Werte.So könnten Sie die folgenden 'keyPoints.push_back (Point2f (i, j), 5.0);'. – mevatron