1 Star 0 Fork 0

nwpu_a409/hand-writing-optical

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Detector.cpp 2.68 KB
一键复制 编辑 原始数据 按行查看 历史
fandikai 提交于 2017-10-06 20:25 . first commit
//
// Created by fandikai on 17-10-5.
//
#include "Detector.h"
#include <fast/fast.h>
float Detector::shiTomasiScore(const cv::Mat& img, int u, int v) {
assert(img.type() == CV_8UC1);
float dXX = 0.0;
float dYY = 0.0;
float dXY = 0.0;
const int halfbox_size = 4;
const int box_size = 2*halfbox_size;
const int box_area = box_size*box_size;
const int x_min = u-halfbox_size;
const int x_max = u+halfbox_size;
const int y_min = v-halfbox_size;
const int y_max = v+halfbox_size;
if(x_min < 1 || x_max >= img.cols-1 || y_min < 1 || y_max >= img.rows-1)
return 0.0; // patch is too close to the boundary
const int stride = img.step.p[0];
for( int y=y_min; y<y_max; ++y ) {
const uint8_t* ptr_left = img.data + stride*y + x_min - 1;
const uint8_t* ptr_right = img.data + stride*y + x_min + 1;
const uint8_t* ptr_top = img.data + stride*(y-1) + x_min;
const uint8_t* ptr_bottom = img.data + stride*(y+1) + x_min;
for(int x = 0; x < box_size; ++x, ++ptr_left, ++ptr_right, ++ptr_top, ++ptr_bottom)
{
float dx = *ptr_right - *ptr_left;
float dy = *ptr_bottom - *ptr_top;
dXX += dx*dx;
dYY += dy*dy;
dXY += dx*dy;
}
}
// Find and return smaller eigenvalue:
dXX = dXX / (2.0f * box_area);
dYY = dYY / (2.0f * box_area);
dXY = dXY / (2.0f * box_area);
return 0.5f * (dXX + dYY - std::sqrt( (dXX + dYY) * (dXX + dYY) - 4.0f * (dXX * dYY - dXY * dXY)));
}
void Detector::detect(cv::Mat &img, const float detection_threshold, std::vector<cv::Point2f> &feats, short barrier) {
std::vector<fast::fast_xy> fast_corners;
#if __SSE2__
fast::fast_corner_detect_10_sse2(
(fast::fast_byte*) img.data, img.cols,
img.rows, img.cols, barrier, fast_corners);
#elif HAVE_FAST_NEON
fast::fast_corner_detect_9_neon(
(fast::fast_byte*) img.data, img.cols,
img.rows, img.cols, barrier, fast_corners);
#else
fast::fast_corner_detect_10(
(fast::fast_byte*)img.data, img.cols,
img.rows, img.cols, barrier, fast_corners);
#endif
std::vector<int> scores, nm_corners;
fast::fast_corner_score_10((fast::fast_byte*) img.data, img.cols, fast_corners, barrier, scores);
fast::fast_nonmax_3x3(fast_corners, scores, nm_corners);
for (auto it = nm_corners.begin(); it != nm_corners.end(); ++it) {
fast::fast_xy &xy = fast_corners.at(*it);
const float score = shiTomasiScore(img, xy.x, xy.y);
if (score > detection_threshold)
feats.emplace_back(xy.x, xy.y);
}
printf("result [%lu]s points!\n",feats.size());
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/nwpua409/hand-writing-optical.git
git@gitee.com:nwpua409/hand-writing-optical.git
nwpua409
hand-writing-optical
hand-writing-optical
master

搜索帮助