Adding templates to linemod fails

asked 2018-07-05 08:49:51 -0500

pwharton gravatar image

updated 2018-07-05 11:34:44 -0500

Hello all,

I'm attempting to implement opencv linemod, however I've come upon an issue that I can't seem to solve. Essentially whenever I run the addTemplate function on a detector class it simply fails to add (returns -1, and numTemplates is 0). Does anybody have any ideas what might be causing this behaviour?

#include <iostream>                                                                                                                                                                                 
#include <opencv2/core/core.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/rgbd.hpp>
#include <opencv2/objdetect/objdetect.hpp>

using namespace std;
int main() {
//Instantiate detector
cv::Ptr<cv::linemod::Detector> detector;
detector = cv::linemod::getDefaultLINEMOD();

//load ims 
cv::Mat rgb_im;
cv::Mat depth_im;
rgb_im = cv::imread("/home/pete/work/data/train/15/rgb/0300.png", CV_LOAD_IMAGE_COLOR);
depth_im = cv::imread("/home/pete/work/data/train/15/depth/0300.png", CV_LOAD_IMAGE_ANYDEPTH);
vector<cv::Mat> sources= {rgb_im,depth_im}; //load to vector for template adding
cv::Mat mask(rgb_im.size(), CV_8UC1, cv::Scalar::all(255));
string class_id="testclass";
//cv::Rect bb;

int Templ_ID =detector->addTemplate(sources, class_id, mask);
cout<<"Templ_ID: "<<Templ_ID<<endl;
return 0;
}

A few weird quirks- using the empty intialiser will add templates just fine, however this seems to be designed for loading pre-stored detectors from file, and fails to match holding some pretty wild and seemingly random parameter values.

Another unexpected thing is that despite failing to load the template the detector somehow updates that it has a class loaded into it.

The mask I've currently just put as all white but all sorts of mask variations get the same results. Bounding box or not doesn't seem to affect results either.

Thanks everyone!

edit retag flag offensive close merge delete