#include "pch.h"
#include "line2Dup.h"
#include <iostream>
using namespace std;
using namespace cv;
#include <chrono>
class Timer
{
public:
Timer() : beg_(clock_::now()) {}
void reset() { beg_ = clock_::now(); }
double elapsed() const {
return std::chrono::duration_cast<second_>
(clock_::now() - beg_).count(); }
void out(std::string message = ""){
double t = elapsed();
std::cout << message << "\nelasped time:" << t << "s\n" << std::endl;
reset();
}
private:
typedef std::chrono::high_resolution_clock clock_;
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> beg_;
};
namespace line2Dup
{
/**
* \brief Get the label [0,8) of the single bit set in quantized.
*/
static inline int getLabel(int quantized)
{
switch (quantized)
{
case 1:
return 0;
case 2:
return 1;
case 4:
return 2;
case 8:
return 3;
case 16:
return 4;
case 32:
return 5;
case 64:
return 6;
case 128:
return 7;
default:
CV_Error(Error::StsBadArg, "Invalid value of quantized parameter");
return -1; //avoid warning
}
}
void Feature::read(const FileNode &fn)
{
FileNodeIterator fni = fn.begin();
fni >> x >> y >> label;
}
void Feature::write(FileStorage &fs) const
{
fs << "[:" << x << y << label << "]";
}
void Template::read(const FileNode &fn)
{
width = fn["width"];
height = fn["height"];
tl_x = fn["tl_x"];
tl_y = fn["tl_y"];
pyramid_level = fn["pyramid_level"];
FileNode features_fn = fn["features"];
features.resize(features_fn.size());
FileNodeIterator it = features_fn.begin(), it_end = features_fn.end();
for (int i = 0; it != it_end; ++it, ++i)
{
features[i].read(*it);
}
}
void Template::write(FileStorage &fs) const
{
fs << "width" << width;
fs << "height" << height;
fs << "tl_x" << tl_x;
fs << "tl_y" << tl_y;
fs << "pyramid_level" << pyramid_level;
fs << "features"
<< "[";
for (int i = 0; i < (int)features.size(); ++i)
{
features[i].write(fs);
}
fs << "]"; // features
}
static Rect cropTemplates(std::vector<Template> &templates)
{
int min_x = std::numeric_limits<int>::max();
int min_y = std::numeric_limits<int>::max();
int max_x = std::numeric_limits<int>::min();
int max_y = std::numeric_limits<int>::min();
// First pass: find min/max feature x,y over all pyramid levels and modalities
for (int i = 0; i < (int)templates.size(); ++i)
{
Template &templ = templates[i];
for (int j = 0; j < (int)templ.features.size(); ++j)
{
int x = templ.features[j].x << templ.pyramid_level;
int y = templ.features[j].y << templ.pyramid_level;
min_x = std::min(min_x, x);
min_y = std::min(min_y, y);
max_x = std::max(max_x, x);
max_y = std::max(max_y, y);
}
}
/// @todo Why require even min_x, min_y?
if (min_x % 2 == 1)
--min_x;
if (min_y % 2 == 1)
--min_y;
// Second pass: set width/height and shift all feature positions
for (int i = 0; i < (int)templates.size(); ++i)
{
Template &templ = templates[i];
templ.width = (max_x - min_x) >> templ.pyramid_level;
templ.height = (max_y - min_y) >> templ.pyramid_level;
templ.tl_x = min_x >> templ.pyramid_level;
templ.tl_y = min_y >> templ.pyramid_level;
for (int j = 0; j < (int)templ.features.size(); ++j)
{
templ.features[j].x -= templ.tl_x;
templ.features[j].y -= templ.tl_y;
}
}
return Rect(min_x, min_y, max_x - min_x, max_y - min_y);
}
bool ColorGradientPyramid::selectScatteredFeatures(const std::vector<Candidate> &candidates,
std::vector<Feature> &features,
size_t num_features, float distance)
{
features.clear();
float distance_sq = distance * distance;
int i = 0;
bool first_select = true;
while(true)
{
Candidate c = candidates[i];
// Add if sufficient distance away from any previously chosen feature
bool keep = true;
for (int j = 0; (j < (int)features.size()) && keep; ++j)
{
Feature f = features[j];
keep = (c.f.x - f.x) * (c.f.x - f.x) + (c.f.y - f.y) * (c.f.y - f.y) >= distance_sq;
}
if (keep)
features.push_back(c.f);
if (++i == (int)candidates.size()){
bool num_ok = features.size() >= num_features;
if(first_select){
if(num_ok){
features.clear(); // we don't want too many first time
i = 0;
distance += 1.0f;
distance_sq = distance * distance;
continue;
}else{
first_select = false;
}
}
// Start back at beginning, and relax required distance
i = 0;
distance -= 1.0f;
distance_sq = distance * distance;
if (num_ok || distance < 3){
break;
}
}
}
return true;
}
/****************************************************************************************\
* Color gradient ColorGradient *
\****************************************************************************************/
void hysteresisGradient(Mat &magnitude, Mat &quantized_angle,
Mat &angle, float threshold)
{
// Quantize 360 degree range of orientations into 16 buckets
// Note that [0, 11.25), [348.75, 360) both get mapped in the end to label 0,
// for stability of horizontal and vertical features.
Mat_<unsigned char> quantized_unfiltered;
angle.convertTo(quantized_unfiltered, CV_8U, 16.0 / 360.0);
// Zero out top and bottom rows
/// @todo is this necessary, or even correct?
memset(quantized_unfiltered.ptr(), 0, quantized_unfiltered.cols);
memset(quantized_unfiltered.ptr(quantized_unfiltered.rows - 1), 0, quantized_unfiltered.cols);
// Zero out first and last columns
for (int r = 0; r < quantized_unfiltered.rows; ++r)
{
quantized_unfiltered(r, 0) = 0;
quantized_unfiltered(r, quantized_unfiltered.cols - 1) = 0;
}
// Mask 16 buckets into 8 quantized orientations
for (int r = 1; r < angle.rows - 1; ++r)
{
uchar *quant_r = quantized_unfiltered.ptr<uchar>(r);
for (int c = 1; c < angle.cols - 1; ++c)
{
quant_r[c] &= 7;
}
}
// Filter the raw quantized image. Only accept pixels where the magnitude is above some
// threshold, and there is local agreement on the quantization.
quantized_angle = Mat::zeros(angle.size(), CV_8U);
for (int r = 1; r < angle.rows - 1; ++r)
{
float *mag_r = magnitude.ptr<float>(r);
for (int c = 1; c < angle.cols - 1; ++c)
{
if (mag_r[c] > threshold)
{
// Compute histogram of quantized bins in 3x3 patch around pixel
int histogram[8] = {0, 0, 0, 0, 0, 0, 0, 0};
uchar *patch3x3_row = &quantized_unfiltered(r - 1, c - 1);
histogram[patch3x3_row[0]]++;
histogram[patch3x3_row[1]]++;
histogram[patch3x3_row[2]]++;
patch3x3_row += quantized_unfiltered.step1();
histogram[patch3x3_row[0]]++;
histogram[patch3x3_row[1]]++;
histogram[patch3x3_row[2]]++;
patch3x3_row += quantized_unfiltered.step1();
histogram[patc
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
vs2022/C++/opencv4.52 ShapedMatch源码
(572个子文件)
ShapedMatch.aps 109KB
fileList.bin 103KB
line2Dup.cpp 53KB
test.cpp 20KB
ShapedMatchDlg.cpp 17KB
ShapedMatch.cpp 3KB
pch.cpp 158B
Browse.VC.db 76.77MB
opencv_world452d.dll 116.12MB
opencv_world452.dll 58.76MB
ShapedMatch.vcxproj.filters 3KB
core_c.h 129KB
msa_macros.h 82KB
PCI_DMC.H 74KB
PCI_DMC_01.h 72KB
types_c.h 72KB
logging.h 66KB
imgproc_c.h 51KB
mipp.h 44KB
kmeans_index.h 37KB
cvdef.h 33KB
constants_c.h 31KB
gflags.h 30KB
dist.h 28KB
hierarchical_clustering_index.h 26KB
cv_cpu_helper.h 25KB
autotuned_index.h 21KB
kdtree_single_index.h 20KB
kdtree_index.h 20KB
lsh_table.h 19KB
types_c.h 18KB
lsh_index.h 16KB
result_set.h 15KB
PCI_DMC_Err.h 13KB
index_testing.h 11KB
highgui_c.h 11KB
line2Dup.h 10KB
PCI_DMC_01_Err.h 10KB
any.h 9KB
stl_logging.h 8KB
cv_cpu_dispatch.h 7KB
hdf5.h 7KB
raw_logging.h 7KB
allocator.h 6KB
composite_index.h 6KB
nn_index.h 6KB
vlog_is_on.h 6KB
all_indices.h 6KB
saving.h 6KB
simplex_downhill.h 6KB
gflags_completions.h 6KB
videoio_c.h 6KB
calib3d_c.h 5KB
gflags_declare.h 5KB
cap_ios.h 5KB
interface.h 5KB
dynamic_bitset.h 5KB
defines.h 4KB
PCI_DMC_B02.h 4KB
random.h 4KB
heap.h 4KB
gflags_gflags.h 4KB
logger.h 4KB
linear_index.h 4KB
cvconfig.h 3KB
matrix.h 3KB
ground_truth.h 3KB
log_severity.h 3KB
params.h 3KB
config.h 3KB
object_factory.h 3KB
sampling.h 3KB
timer.h 3KB
ModelType.h 3KB
ios.h 3KB
PCI_DMC_B01.h 2KB
general.h 2KB
config.h 2KB
constants_c.h 2KB
sse_mathfun.h 2KB
avx_mathfun.h 2KB
framework.h 2KB
neon_mathfun.h 1KB
resource.h 1KB
ShapedMatchDlg.h 1KB
interface.h 1KB
PCI_DMC_B02_Err.h 987B
macosx.h 751B
mipp_scalar_op.h 748B
avx512_mathfun.h 600B
interface.h 584B
pch.h 544B
ShapedMatch.h 508B
constants_c.h 478B
constants_c.h 412B
TYPE_DEF.H 323B
targetver.h 295B
dummy.h 178B
imgcodecs_c.h 145B
imgproc.hpp 228KB
共 572 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
- 眠橘2024-11-14大神大神,这个可以商用嘛
- 我爱编程_st2023-02-21可以使用,就是训练速度和匹配速度是真的慢,非常慢墨客淘金2023-06-26release版本,会快很多
墨客淘金
- 粉丝: 3064
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Linux Shell 特殊符号及其用法详解
- 基于STM32的交流电流测量系统(程序+电路资料全)
- “戏迷导航”:戏剧推广网站的个性化推荐系统
- Laser MFP 133 136 138不加电如何确认电源板还是主板故障
- STM32F030单片机采集ADC值并从串口2打印.zip
- java版socket NIO实现,包含客户端和服务端
- 21数科-苏秀娟-论文初稿.pdf
- STM32F030单片机串口1、串口2配置及数据打印.zip
- STM32F030单片机串口2发送接收.zip
- 探秘 Docker 网络:高效容器通信的关键
- STM32F030单片机控制LED灯.zip
- 基于 PyQt 的弱口令检测工具程序设计与实现
- 证件照提取矫正,能提取各种证件并矫正
- STM32F103+PWM+DMA精准控制输出脉冲的数量和频率 源程序
- 篡改猴插件中很实用的脚本
- stm32+SCD40二氧化碳传感器源程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功