Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mask for detector #116

Open
pak-da opened this issue Sep 1, 2021 · 5 comments
Open

mask for detector #116

pak-da opened this issue Sep 1, 2021 · 5 comments

Comments

@pak-da
Copy link

pak-da commented Sep 1, 2021

Hi,
I am using find_object_2d for a single object detection and manipulation task with a robot arm.The object is well known so I can detect it even with a single RGB camera. I need precious and robust result that seems to be reached with SIFT detector and description however I'm sure that I can do something better with a color based mask in order to filter out all the keypoints that can be similar but belong to a region with different color. So how can I impose a mask for detector?

Thanks

@matlabbe
Copy link
Member

matlabbe commented Sep 5, 2021

The function here:

if(findObject_->detect(sceneImage_, info))
can use a mask as parameter. You may create a mask from the input depth image topic like this.
You would have to create a fake depth image from the color mask, then feed that depth image to find_object_node.

@pak-da
Copy link
Author

pak-da commented Sep 6, 2021

It seems that findObject::detect doesn't accept directly a mask.

bool FindObject::detect(const cv::Mat & image, find_object::DetectionInfo & info) const

However it uses the class ExtractFeaturesThread

ExtractFeaturesThread extractThread(detector_, extractor_, -1, grayscaleImg);

in which the mask seems just initialized

computeFeatures(
detector_,
extractor_,
image_,
cv::Mat(),
keypoints_,
descriptors_,
timeDetection_,

If I've understood fine you are suggesting to replace the initialization of the mask with a variable mask that is the 4th channel. Of course I have to give as input a 4 channel image. Is it right?

I'm not very experienced in programming in C++ so if you could give me some examples i would be grateful

@matlabbe
Copy link
Member

matlabbe commented Sep 8, 2021

If you are using ROS, we can make rtabmap subscribe to a depth image (single channel 16bits unsigned short, or CV_16UC1). The depth image is passed here before FindObject::detect() gets called:

void MainWindow::update(const cv::Mat & image, const QString & frameId, double stamp, const cv::Mat & depth, float depthConstant)

As I said, you can add a new parameter to the function FindObject::detect(..., const cv::Mat & mask), and you can convert the depth to a mask matrix (CV_8UC1) using the conversion code I linked to pass the mask to that function. The mask can be then redirected to ExtractFeaturesThread.

Regards,
Mathieu

@pak-da
Copy link
Author

pak-da commented Sep 15, 2021

I've tried what you suggested and it works fine. Thanks
Is there any way in order to avoid the tf publishing? (it is wrong because the depth channel is fake)

@matlabbe
Copy link
Member

You could set if(0) here:

if(info.objDetected_.size() && !depth.empty() && depthConstant != 0.0f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants