OpenCV linemod learning operation

Keywords: OpenCV xml

Recently, I am working on the object pose recognition program, and I have read many related papers. However, it can't be mastered just by looking at it. It is found that there is implementation of linemod in opencv. I'm going to look at this method first. I'll talk about the specific implementation process in the future and see how to use it first.

Application examples in openCV

In fact, it is important to use these sentences

// Initialization of LINEMOD probe (can read existing model or empty model)
cv::Ptr<cv::linemod::Detector> detector; // linemod probe initialization
// detector can read yml and xml files
detector = readLinemod(fileName); //absPath + 'name.yml"
static cv::Ptr<cv::linemod::Detector> readLinemod(const std::string& filename)
{
	cv::Ptr<cv::linemod::Detector> detector = cv::makePtr<cv::linemod::Detector>();
	cv::FileStorage fs(filename, cv::FileStorage::READ);
	detector->read(fs.root());
	
	cv::FileNode fn = fs["classes"];
	for (cv::FileNodeIterator i = fn.begin(), iend = fn.end(); i != iend; ++i)
		detector->readClass(*i);
	return detector;
}
// detector can also be empty
detector = cv::linemod::getDefaultLINEMOD();

When learning the template, you need to input the corresponding color data and depth image data. However, alignment is not detailed. In the example given, the openni interface is used to directly call kinect to obtain a set of rgbd data. Since kinect v1 is not available, it is not necessary to do so. I think you should enter the aligned rgbd data. After changing the camera interface, continue with the following operations

// Generate template data for probe sub storage
// cv::Mat rgb,depth; aligned rgbd data
std::vector<cv::Mat> sources;	//Save rgbd data with a vector
sources.push_back(color); sources.push_back(depth);
// A mask is also needed to represent the area of the object to be recognized, which is actually the silhouette of the object
// Add a new template
std::string class_id = cv::format("class%d", num_classes);  // Class labels
cv::Rect bb; // The bounding Qu box of an object
int template_id = detector->addTemplate(sources, class_id, mask, &bb);
// When template ﹣ ID returns - 1, recognition fails
// After having the corresponding template data, compare it with the data obtained again to find the template
std::vector<cv::linemod::Match> matches;	
std::vector<cv::String> class_ids;
std::vector<cv::Mat> quantized_images;
// This matches...
// All matching results are stored in matches,
detector->match(sources, (float)matching_threshold, matches, class_ids, quantized_images);

// m is a result of matches The evaluation criteria are as follows
printf("Similarity: %5.1f%%; x: %3d; y: %3d; class: %s; template: %3d\n",
       m.similarity, m.x, m.y, m.class_id.c_str(), m.template_id);

opencv is still a little bit 6. It will take a while to understand the source code

Posted by sunilmadhav on Thu, 28 Nov 2019 09:10:22 -0800