gpt4 book ai didi

c++ - 检测图像上标记的最佳方法是什么?打开简历

转载 作者:太空宇宙 更新时间:2023-11-03 22:30:10 24 4
gpt4 key购买 nike

我一直在尝试检测图像上的一些标记。我使用 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(甚至蛮力)等特征匹配器以获得最佳结果。
此外,尽量减少噪声以获得更准确的特征检测(高斯滤波器或去噪函数)。

关于c++ - 检测图像上标记的最佳方法是什么?打开简历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27804705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com