|
|
|
@ -84,6 +84,13 @@ void Feature::write(FileStorage& fs) const |
|
|
|
|
|
|
|
|
|
// struct Template
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \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<Template>& templates) |
|
|
|
|
{ |
|
|
|
|
int min_x = std::numeric_limits<int>::max(); |
|
|
|
@ -246,7 +253,18 @@ void colormap(const Mat& quantized, Mat& dst) |
|
|
|
|
void hysteresisGradient(Mat& magnitude, Mat& angle, |
|
|
|
|
Mat& ap_tmp, float threshold); |
|
|
|
|
|
|
|
|
|
// Implements section 2.2
|
|
|
|
|
/**
|
|
|
|
|
* \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) |
|
|
|
|
{ |
|
|
|
@ -598,6 +616,20 @@ static void accumBilateral(long delta, long i, long j, long * A, long * b, int t |
|
|
|
|
b[1] += fj * delta; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \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) |
|
|
|
|
{ |
|
|
|
@ -948,6 +980,15 @@ void orUnaligned8u(const uchar * src, const int src_stride, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Spread binary labels in a quantized image. |
|
|
|
|
* |
|
|
|
|
* Implements section 2.3 "Spreading the Orientations." |
|
|
|
|
* |
|
|
|
|
* \param[in] src The source 8-bit quantized image. |
|
|
|
|
* \param[out] dst Destination 8-bit spread image. |
|
|
|
|
* \param T Sampling step. Spread labels T/2 pixels in each direction. |
|
|
|
|
*/ |
|
|
|
|
void spread(const Mat& src, Mat& dst, int T) |
|
|
|
|
{ |
|
|
|
|
// Allocate and zero-initialize spread (OR'ed) image
|
|
|
|
@ -968,6 +1009,14 @@ void spread(const Mat& src, Mat& dst, int T) |
|
|
|
|
// Auto-generated by create_similarity_lut.py
|
|
|
|
|
CV_DECL_ALIGNED(16) static const unsigned char SIMILARITY_LUT[256] = {0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4, 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 4, 4, 3, 3, 4, 4, 2, 3, 4, 4, 3, 3, 4, 4, 0, 1, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 0, 2, 1, 2, 0, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 0, 3, 2, 3, 1, 3, 2, 3, 0, 3, 2, 3, 1, 3, 2, 3, 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 0, 4, 3, 4, 2, 4, 3, 4, 1, 4, 3, 4, 2, 4, 3, 4, 0, 1, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 3, 4, 4, 3, 3, 4, 4, 2, 3, 4, 4, 3, 3, 4, 4, 0, 2, 1, 2, 0, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 0, 2, 3, 3, 4, 4, 4, 4, 3, 3, 3, 3, 4, 4, 4, 4, 0, 3, 2, 3, 1, 3, 2, 3, 0, 3, 2, 3, 1, 3, 2, 3, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Precompute response maps for a spread quantized image. |
|
|
|
|
* |
|
|
|
|
* Implements section 2.4 "Precomputing Response Maps." |
|
|
|
|
* |
|
|
|
|
* \param[in] src The source 8-bit spread quantized image. |
|
|
|
|
* \param[out] response_maps Vector of 8 response maps, one for each bit label. |
|
|
|
|
*/ |
|
|
|
|
void computeResponseMaps(const Mat& src, std::vector<Mat>& response_maps) |
|
|
|
|
{ |
|
|
|
|
CV_Assert((src.rows * src.cols) % 16 == 0); |
|
|
|
@ -1039,6 +1088,16 @@ void computeResponseMaps(const Mat& src, std::vector<Mat>& response_maps) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Convert a response map to fast linearized ordering. |
|
|
|
|
* |
|
|
|
|
* Implements section 2.5 "Linearizing the Memory for Parallelization." |
|
|
|
|
* |
|
|
|
|
* \param[in] response_map The 2D response map, an 8-bit image. |
|
|
|
|
* \param[out] linearized The response map in linearized order. It has T*T rows, |
|
|
|
|
* each of which is a linear memory of length (W/T)*(H/T). |
|
|
|
|
* \param T Sampling step. |
|
|
|
|
*/ |
|
|
|
|
void linearize(const Mat& response_map, Mat& linearized, int T) |
|
|
|
|
{ |
|
|
|
|
CV_Assert(response_map.rows % T == 0); |
|
|
|
@ -1098,7 +1157,17 @@ const unsigned char* accessLinearMemory(const std::vector<Mat>& linear_memories, |
|
|
|
|
return memory + lm_index; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NOTE: Returning dst as uint8 instead of uint16
|
|
|
|
|
/**
|
|
|
|
|
* \brief Compute similarity measure for a given template at each sampled image location. |
|
|
|
|
* |
|
|
|
|
* Uses linear memories to compute the similarity measure as described in Fig. 7. |
|
|
|
|
* |
|
|
|
|
* \param[in] linear_memories Vector of 8 linear memories, one for each label. |
|
|
|
|
* \param[in] templ Template to match against. |
|
|
|
|
* \param[out] dst Destination 8-bit similarity image of size (W/T, H/T). |
|
|
|
|
* \param size Size (W, H) of the original input image. |
|
|
|
|
* \param T Sampling step. |
|
|
|
|
*/ |
|
|
|
|
void similarity(const std::vector<Mat>& linear_memories, const Template& templ, |
|
|
|
|
Mat& dst, Size size, int T) |
|
|
|
|
{ |
|
|
|
@ -1183,7 +1252,16 @@ void similarity(const std::vector<Mat>& linear_memories, const Template& templ, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NOTE: Returning dst as uint8 instead of uint16
|
|
|
|
|
/**
|
|
|
|
|
* \brief Compute similarity measure for a given template in a local region. |
|
|
|
|
* |
|
|
|
|
* \param[in] linear_memories Vector of 8 linear memories, one for each label. |
|
|
|
|
* \param[in] templ Template to match against. |
|
|
|
|
* \param[out] dst Destination 8-bit similarity image, 16x16. |
|
|
|
|
* \param size Size (W, H) of the original input image. |
|
|
|
|
* \param T Sampling step. |
|
|
|
|
* \param center Center of the local region. |
|
|
|
|
*/ |
|
|
|
|
void similarityLocal(const std::vector<Mat>& linear_memories, const Template& templ, |
|
|
|
|
Mat& dst, Size size, int T, Point center) |
|
|
|
|
{ |
|
|
|
@ -1272,6 +1350,12 @@ void addUnaligned8u16u(const uchar * src1, const uchar * src2, ushort * res, int |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Accumulate one or more 8-bit similarity images. |
|
|
|
|
* |
|
|
|
|
* \param[in] similarities Source 8-bit similarity images. |
|
|
|
|
* \param[out] dst Destination 16-bit similarity image. |
|
|
|
|
*/ |
|
|
|
|
void addSimilarities(const std::vector<Mat>& similarities, Mat& dst) |
|
|
|
|
{ |
|
|
|
|
if (similarities.size() == 1) |
|
|
|
@ -1299,13 +1383,11 @@ Detector::Detector() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Detector::Detector(const std::vector< Ptr<Modality> >& modalities, |
|
|
|
|
const std::vector<int>& T_pyramid, double pyramid_distance) |
|
|
|
|
const std::vector<int>& T_pyramid) |
|
|
|
|
: modalities(modalities), |
|
|
|
|
pyramid_levels(T_pyramid.size()), |
|
|
|
|
pyramid_distance(pyramid_distance), |
|
|
|
|
T_at_level(T_pyramid) |
|
|
|
|
{ |
|
|
|
|
CV_Assert(pyramid_distance == 2.0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Detector::match(const std::vector<Mat>& sources, float threshold, std::vector<Match>& matches, |
|
|
|
@ -1397,13 +1479,6 @@ struct MatchPredicate |
|
|
|
|
float threshold; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
bool non_negative_assert(const Template& templ) |
|
|
|
|
{ |
|
|
|
|
for(size_t j = 0; j < templ.features.size(); ++j) |
|
|
|
|
assert(templ.features[j].x >= 0 && templ.features[j].y >= 0); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Detector::matchClass(const LinearMemoryPyramid& lm_pyramid, |
|
|
|
|
const std::vector<Size>& sizes, |
|
|
|
|
float threshold, std::vector<Match>& matches, |
|
|
|
@ -1478,7 +1553,7 @@ void Detector::matchClass(const LinearMemoryPyramid& lm_pyramid, |
|
|
|
|
for (int m = 0; m < (int)candidates.size(); ++m) |
|
|
|
|
{ |
|
|
|
|
Match& match = candidates[m]; |
|
|
|
|
int x = match.x * 2 + 1; /// @todo Support other pyramid_distance
|
|
|
|
|
int x = match.x * 2 + 1; /// @todo Support other pyramid distance
|
|
|
|
|
int y = match.y * 2 + 1; |
|
|
|
|
|
|
|
|
|
// Require 8 (reduced) row/cols to the up/left
|
|
|
|
@ -1617,7 +1692,6 @@ void Detector::read(const FileNode& fn) |
|
|
|
|
{ |
|
|
|
|
class_templates.clear(); |
|
|
|
|
pyramid_levels = fn["pyramid_levels"]; |
|
|
|
|
pyramid_distance = fn["pyramid_distance"]; |
|
|
|
|
fn["T"] >> T_at_level; |
|
|
|
|
|
|
|
|
|
modalities.clear(); |
|
|
|
@ -1632,7 +1706,6 @@ void Detector::read(const FileNode& fn) |
|
|
|
|
void Detector::write(FileStorage& fs) const |
|
|
|
|
{ |
|
|
|
|
fs << "pyramid_levels" << pyramid_levels; |
|
|
|
|
fs << "pyramid_distance" << pyramid_distance; |
|
|
|
|
fs << "T" << "[:" << T_at_level << "]"; |
|
|
|
|
|
|
|
|
|
fs << "modalities" << "["; |
|
|
|
@ -1655,7 +1728,6 @@ void Detector::write(FileStorage& fs) const |
|
|
|
|
for ( ; mod_it != mod_it_end; ++mod_it, ++i) |
|
|
|
|
CV_Assert(modalities[i]->name() == (std::string)(*mod_it)); |
|
|
|
|
CV_Assert((int)fn["pyramid_levels"] == pyramid_levels); |
|
|
|
|
CV_Assert((int)fn["pyramid_distance"] == pyramid_distance); |
|
|
|
|
|
|
|
|
|
// Detector should not already have this class
|
|
|
|
|
std::string class_id; |
|
|
|
@ -1708,7 +1780,6 @@ void Detector::writeClass(const std::string& class_id, FileStorage& fs) const |
|
|
|
|
fs << modalities[i]->name(); |
|
|
|
|
fs << "]"; // modalities
|
|
|
|
|
fs << "pyramid_levels" << pyramid_levels; |
|
|
|
|
fs << "pyramid_distance" << pyramid_distance; |
|
|
|
|
fs << "template_pyramids" << "["; |
|
|
|
|
for (size_t i = 0; i < tps.size(); ++i) |
|
|
|
|
{ |
|
|
|
@ -1752,7 +1823,6 @@ void Detector::writeClasses(const std::string& format) const |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const int T_DEFAULTS[] = {5, 8}; |
|
|
|
|
|
|
|
|
|
Ptr<Detector> getDefaultLINE() |
|
|
|
|