From f174b001f3f10aec9396a45b144623b1b29ea5d9 Mon Sep 17 00:00:00 2001 From: Patrick Mihelich Date: Sun, 26 Feb 2012 23:55:18 +0000 Subject: [PATCH] Initial commit of LINE-MOD source code to objdetect module. --- .../include/opencv2/objdetect/objdetect.hpp | 529 +++++- modules/objdetect/src/linemod.cpp | 1774 ++++++++++++++++++++ modules/objdetect/src/normal_lut.i | 4 + 3 files changed, 2306 insertions(+), 1 deletion(-) create mode 100644 modules/objdetect/src/linemod.cpp create mode 100644 modules/objdetect/src/normal_lut.i diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index 355bb46..bbf9fd7 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -47,6 +47,9 @@ #include "opencv2/features2d/features2d.hpp" #ifdef __cplusplus +#include +#include + extern "C" { #endif @@ -655,8 +658,532 @@ struct CV_EXPORTS CvDataMatrixCode { CvMat *corners; }; -#include CV_EXPORTS std::deque cvFindDataMatrix(CvMat *im); + +/****************************************************************************************\ +* LINE-MOD * +\****************************************************************************************/ + +namespace cv { +namespace linemod { + +using cv::FileNode; +using cv::FileStorage; +using cv::Mat; +using cv::noArray; +using cv::OutputArrayOfArrays; +using cv::Point; +using cv::Ptr; +using cv::Rect; +using cv::Size; + +/// @todo Convert doxy comments to rst +/// @todo Move stuff that doesn't need to be public into linemod.cpp +/** + * \brief Compute quantized orientation image from color image. + * + * Implements section 2.2 "Computing the Gradient Orientations." + * + * \param[in] src The source 8-bit, 3-channel image. + * \param[out] magnitude Destination floating-point array of squared magnitudes. + * \param[out] angle Destination 8-bit array of orientations. Each bit + * represents one bin of the orientation space. + * \param threshold Magnitude threshold. Keep only gradients whose norms are + * larger than this. + */ +void quantizedOrientations(const Mat& src, Mat& magnitude, + Mat& angle, float threshold); + +/** + * \brief Compute quantized normal image from depth image. + * + * Implements section 2.6 "Extension to Dense Depth Sensors." + * + * \param[in] src The source 16-bit depth image (in mm). + * \param[out] dst The destination 8-bit image. Each bit represents one bin of + * the view cone. + * \param distance_threshold Ignore pixels beyond this distance. + * \param difference_threshold When computing normals, ignore contributions of pixels whose + * depth difference with the central pixel is above this threshold. + * + * \todo Should also need camera model, or at least focal lengths? Replace distance_threshold with mask? + */ +void quantizedNormals(const Mat& src, Mat& dst, int distance_threshold, + int difference_threshold = 50); + +/** + * \brief Discriminant feature described by its location and label. + */ +struct Feature +{ + int x; ///< x offset + int y; ///< y offset + int label; ///< Quantization + + Feature() {} + Feature(int x, int y, int label) : x(x), y(y), label(label) {} + + void read(const FileNode& fn); + void write(FileStorage& fs) const; +}; + +struct Template +{ + int width; + int height; + int pyramid_level; + std::vector features; + + void read(const FileNode& fn); + void write(FileStorage& fs) const; +}; + +/** + * \brief Crop a set of overlapping templates from different modalities. + * + * \param[in,out] templates Set of templates representing the same object view. + * + * \return The bounding box of all the templates in original image coordinates. + */ +Rect cropTemplates(std::vector