检测图像上标记的最佳方法是什么?开放简历
What is the best way to detect mark on an image? OpenCV
我一直在尝试检测图像上的一些标记。我使用 OpenCV 的 matchShapes 和 matchTemplate 函数来检测符号"X"、"O"、"+",甚至是三角形,但我遇到了太小的精度:(有时它会正确检测。有时它会检测图像的小片段,例如小点或破折号,而不是三角形或"X"符号。
以下是源代码:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <limits>
using namespace cv;
int main(int argc, char** argv)
{
Mat src;
Mat sample;
Mat circle;
int idx = 0;
int ind_min;
double ret;
double min = std::numeric_limits<double>::max();
src = imread("triangle.jpg", 0); // Example
sample = imread("tri4.jpg", 0); // Photo to compare with example
adaptiveThreshold(sample, sample, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY_INV, 51, 10);
threshold(src, src, 140, 255, 1);
Mat dst2 = Mat::zeros(sample.rows, sample.cols, CV_8UC3);
src = src > 1;
sample = sample > 1;
namedWindow("Source", 1);
imshow("Source", src);
namedWindow("Sample", 1);
imshow("Sample", sample);
vector<vector<Point> > contours; //Contour of an example
vector<Vec4i> hierarchy;
vector<vector<Point> > contours2; //Contours of a photo
vector<Vec4i> hierarchy2;
findContours(src, contours, hierarchy,
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
findContours(sample, contours2, hierarchy2,
CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
//Matching example contours[0] with contours of the photo contours2[idx].
//Comparing output of matchShapes function, the lower is better.
for (; idx >= 0; idx = hierarchy2[idx][0])
{
ret = matchShapes(contours[0], contours2[idx], CV_CONTOURS_MATCH_I1, 0.0);
if (ret < min && ret > 0)
{
min = ret;
ind_min = idx;
}
}
Scalar color(rand() & 255, rand() & 255, rand() & 255);
drawContours(dst2, contours2, ind_min, color, CV_FILLED, 8, hierarchy2);
namedWindow("Components", 1);
imshow("Components", dst2);
waitKey(0);
}
检测为标记的最佳符号是什么?什么是最简单的具有良好准确性的 opencv 解决方案?
如果精度是一个问题,请确保标记的比例和投影与要比较的图像足够接近。您可以缩放图像以帮助匹配。
使用像SIFT(或SURF)这样的特征检测器和像FLANN(甚至蛮力)这样的特征匹配器来获得最佳结果。
此外,尝试尽可能降低噪声,以获得更准确的特征检测(高斯滤波器或去噪函数)。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 通过JNI传递数据数组的最快方法是什么
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 使用不同的CRT将新的C++代码与旧的(二进制)组件隔离开来的最佳方法是什么
- 当无法使用模板和宏时,生成类型变体C++代码的最简单方法是什么?
- 在另一个类视图中添加最多2个图表的正确方法是什么
- 在C++中样板"冷/never_inline"错误处理技术的最佳方法是什么?
- 在 c++ 中对类中的 c 字符串动态数组进行排序的最佳方法是什么?
- 在C++中包含原型文件的正确方法是什么?
- 在 OpenCV C++ 中估计基本矩阵之前对相应点进行归一化的正确方法是什么?
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- 在OSX上使用CMake将Adobe的XMP工具包构建为共享库的最简单方法是什么?
- 将一系列整数放入类的最佳方法是什么?
- 从长整整转换为uint64_t的推荐方法是什么?
- C++:使用方法调用析构函数的顺序是什么?
- 将此布尔值传递给此函数的最有效方法是什么?