Skip to content

Commit

Permalink
refine template extractions
Browse files Browse the repository at this point in the history
  • Loading branch information
meiqua committed May 31, 2020
1 parent 058d4ea commit 6abde91
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 40 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ project(shape_based_matching)

# debug or release
SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_BUILD_TYPE "Debug")


# arm or x86
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ Comparing to opencv linemod src, we improve from 6 aspects:

6. use [MIPP](https://github.com/aff3ct/MIPP) for multiple platforms SIMD, for example, x86 SSE AVX, arm neon.
To have better performance, we have extended MIPP to uint8_t for some instructions.(Otherwise we can only use
half feature points to avoid int8_t overflow)
half feature points to avoid int8_t overflow)

7. rotate features directly to speed up template extractions; selectScatteredFeatures more
evenly; exautive select all features if not enough rather than abort templates(but features <= 4 will abort)

## some test

Expand Down
28 changes: 15 additions & 13 deletions line2Dup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,7 @@ bool ColorGradientPyramid::selectScatteredFeatures(const std::vector<Candidate>
}
}
}
if (features.size() >= num_features)
{
return true;
}
else
{
std::cout << "this templ has no enough features, but we let it go" << std::endl;
return true;
}
return true;
}

/****************************************************************************************\
Expand Down Expand Up @@ -469,6 +461,7 @@ bool ColorGradientPyramid::extractTemplate(Template &templ) const
break;
}
}
if(!is_max) break;
}

if(is_max){
Expand All @@ -490,13 +483,21 @@ bool ColorGradientPyramid::extractTemplate(Template &templ) const
}
}
// We require a certain number of features
if (candidates.size() < num_features)
return false;
if (candidates.size() < num_features){
if(candidates.size() <= 4) {
std::cout << "too few features, abort" << std::endl;
return false;
}
std::cout << "have no enough features, exaustive mode" << std::endl;
}

// NOTE: Stable sort to agree with old code, which used std::list::sort()
std::stable_sort(candidates.begin(), candidates.end());

// Use heuristic based on surplus of candidates in narrow outline for initial distance threshold
float distance = static_cast<float>(candidates.size() / num_features + 1);

// selectScatteredFeatures always return true
if (!selectScatteredFeatures(candidates, templ.features, num_features, distance))
{
return false;
Expand Down Expand Up @@ -601,9 +602,10 @@ static void spread(const Mat &src, Mat &dst, int T)
}
}

// 1,2-->0 3-->1
static const unsigned char LUT3 = 3;
// 1,2-->0 3-->LUT3
CV_DECL_ALIGNED(16)
static const unsigned char SIMILARITY_LUT[256] = {0, 4, 1, 4, 0, 4, 1, 4, 0, 4, 1, 4, 0, 4, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 4, 4, 1, 1, 4, 4, 0, 1, 4, 4, 1, 1, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 4, 1, 4, 0, 4, 1, 4, 0, 4, 1, 4, 0, 4, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 4, 1, 1, 4, 4, 0, 1, 4, 4, 1, 1, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4};
static const unsigned char SIMILARITY_LUT[256] = {0, 4, LUT3, 4, 0, 4, LUT3, 4, 0, 4, LUT3, 4, 0, 4, LUT3, 4, 0, 0, 0, 0, 0, 0, 0, 0, LUT3, LUT3, LUT3, LUT3, LUT3, LUT3, LUT3, LUT3, 0, LUT3, 4, 4, LUT3, LUT3, 4, 4, 0, LUT3, 4, 4, LUT3, LUT3, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, LUT3, LUT3, 4, 4, 4, 4, LUT3, LUT3, LUT3, LUT3, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, LUT3, LUT3, LUT3, LUT3, 4, 4, 4, 4, 4, 4, 4, 4, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, 0, 0, 0, 0, 0, 0, 0, LUT3, LUT3, LUT3, LUT3, LUT3, LUT3, LUT3, LUT3, 0, 4, LUT3, 4, 0, 4, LUT3, 4, 0, 4, LUT3, 4, 0, 4, LUT3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, LUT3, 4, 4, LUT3, LUT3, 4, 4, 0, LUT3, 4, 4, LUT3, LUT3, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, LUT3, LUT3, 4, 4, 4, 4, LUT3, LUT3, LUT3, LUT3, 4, 4, 4, 4, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, LUT3, 0, 0, 0, 0, LUT3, LUT3, LUT3, LUT3, 4, 4, 4, 4, 4, 4, 4, 4};

static void computeResponseMaps(const Mat &src, std::vector<Mat> &response_maps)
{
Expand Down
2 changes: 2 additions & 0 deletions line2Dup.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class shapeInfo_producer{
}

void produce_infos(){
infos.clear();

assert(angle_range.size() <= 2);
assert(scale_range.size() <= 2);
assert(angle_step > eps*10);
Expand Down
Loading

0 comments on commit 6abde91

Please sign in to comment.