Ask Your Question
0

Conver cv::KeyPoint::pt to 8 bit unsigned int in opencv C++

asked 2019-10-18 07:24:19 -0600

Dimitar Veljanovski gravatar image

updated 2019-10-21 08:25:46 -0600

I want to use a mask FAST keypoints to improve the SIFT detector and find keypoints more easily.

I have tried doing this many times but i have a problem with converting the point to 8 bit unsigned int. Here is my code:

fast->detect(frame, fkps2);
cv::Mat mask = cv::Mat();
for (int i = 0; i < size(fkps2); i++) {
    mask.push_back(cv::Mat(fkps2[i].pt));
}

This does generate the mask without a problem, but the problem occures when passing the mask in the detect function of SIFT:

algo->detect(frame, keypoints2, mask);

Here it says that types of points in mask must be 8 bit unsigned ints. Basically, the each of fkps2[i].pt needs to be converted to an unsigned int.

I have done research and tried many ways of doing this but was unsuccessful in doing so.

edit retag flag offensive close merge delete

Comments

2

use a mask FAST keypoints to improve the SIFT detector

where did you find that idea ?

basically, the each of fkps2[i].pt needs to be converted to an unsigned int.

no, no, no, you entirely misunderstood it. the mask needs to be an image same size of your frame, with white pixels, where you want detection to happen.

berak gravatar imageberak ( 2019-10-21 09:09:45 -0600 )edit
1

The idea was not mine, it was my coworkers'. I have done this same thing in python with the following line:

mask = np.array([np.uint8(k.pt[0]) for k in kp2])

When converting the types in python i used numpy, but in c++ that proves to be a problem. also from my understanding the mask just passes coordinates to the detect method which tells it where to look for the keypoints.

Dimitar Veljanovski gravatar imageDimitar Veljanovski ( 2019-10-22 08:27:21 -0600 )edit

mask Mask specifying where to look for keypoints (optional). It must be a 8-bit integer matrix with non-zero values in the region of interest. Here is the docs written for the function in c++

Dimitar Veljanovski gravatar imageDimitar Veljanovski ( 2019-10-22 08:30:32 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-10-24 06:41:40 -0600

berak gravatar image

updated 2019-10-24 08:13:56 -0600

ok, i looked it up, KeyPointsFilter::runByPixelsMask is used in the SIFT code, and it only checks a +-0.5 pixel border around the keypoint. so you could try the following:

given you have existing keypoints from FAST...:

Mat mask(image.size(), CV_8U, Scalar(0));

for (size_t i=0; i<keypoints.size(); i++) {
    circle(mask, keypoints[i].pt, 1, Scalar(255), -1); // a small white filled circle
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-10-18 07:24:19 -0600

Seen: 913 times

Last updated: Oct 24 '19