Ask Your Question
0

DrawKeypoints() shows no Keypoints

asked 2017-09-27 06:47:02 -0500

Grillteller gravatar image

I am converting some corners (Point2f) to KeyPoints and afterwards I want to draw them with the OpenCV function drawKeypoints. But no KeyPoint is drawn after all. I get no error but just my input image.

Here is my code:

Mat img_1, img_2;
img_1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);

// Retrieving some corners (Point2f)
// ....

// Convert to keypoints

vector<KeyPoint> keypoints_1;
KeyPoint::convert(corners_1, keypoints_1, 1, 1, 0, -1);

// Draw the keypoints

Mat keypoint_img;
drawKeypoints(img_1, keypoints_1, keypoint_img, Scalar::all(-1), 4);
imshow("Keypoints", keypoint_img);
imwrite("Keypoints.bmp", keypoint_img);
waitKey(0)

I tried changing the Flag of drawKeypoints and I printed the following

float x = keypoints_1[0].pt.x;
float y = keypoints_1[0].pt.y;
cout << keypoints_1.size() << " " << x << " " << y << endl;

which gives me:

960 932.142 1448.33

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-09-27 08:35:19 -0500

LBerger gravatar image

updated 2017-09-27 08:36:36 -0500

I think your keypoint are small and in gray image withe pixels cannot be seen easily.

{
    Mat img_1, img_2;
    img_1 = imread("g:/lib/opencv/samples/data/lena.jpg", CV_LOAD_IMAGE_GRAYSCALE);

    vector<Point2f> corners_1={Point(10,10),Point(30,100) ,Point(100,100) ,Point(30,200) ,Point(300,100) };

    vector<KeyPoint> keypoints_1;
    KeyPoint::convert(corners_1, keypoints_1, 10, 1, 0, -1);

    // Draw the keypoints

    Mat keypoint_img;
    Mat img;
    cvtColor(img_1,img,CV_GRAY2BGR);
    drawKeypoints(img, keypoints_1, keypoint_img, Scalar(127,200,10), 4);
    imshow("Keypoints", keypoint_img);
    imwrite("Keypoints.bmp", keypoint_img);
    waitKey(0);
}

image description

edit flag offensive delete link more

Comments

Thanks! When I checked all the coordinates most of the points were also out of bounds... I fixed the calculation of corners and it works now.

Grillteller gravatar imageGrillteller ( 2017-09-28 06:18:34 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-27 06:47:02 -0500

Seen: 540 times

Last updated: Sep 27 '17