我如何在OpenCV中找到模板的所有匹配项
How do I find all matches of a template in OpenCV?
本文关键字:OpenCV 更新时间:2023-10-16
我正在尝试使用 matchTemplate
函数在源图像中找到公司的徽标。
但是我的问题是:
源图像可能包含与模板匹配的几乎相同的徽标,以及其他公司的徽标(无与伦比)。
如何找到所有匹配不仅是最佳匹配,就像detectMultiscale一样,它在向量中提供输出。
在一个段循环中运行模板匹配的情况,在此条件下,您询问是否找到了匹配项(有一定确定的阈值)。在每个循环结束时,保存比赛并掩盖了该区域,以免再次找到它。当确定性下降到水平下时,请从循环中脱颖而出。
伪代码:
while true:
maxLoc, maxVal = template_matching() # perform the matching
if(maxVal < threshold) # check if it is a good match and break if not
break
list.append(maxLoc) # save the location of a good match
mask_out(src, (maxLoc.x + template.cols , maxLoc.y + template.rows)) # mask out the area, so that it's not found again
draw_all_rectangles(list)
请记住,根据所使用的模板匹配方法,您将使用MINVAL和MINLOC或MAXVAL和MAXLOC。使用Minval,条件将使用相反的不等式符号。我将实施给您。祝你好运。
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 哪些库可以通过Opencv调整曝光率
- 安装opencv失败-粘贴CMakeError.log的内容
- C++中的openCV Mat访问冲突
- OpenCV Android C++ imwrite not found
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- C++ OpenCV 卡尔曼滤波器构造函数错误
- 使用OpenCV和覆盆子上的多个网络摄像头拍摄延时摄影,出现多个V4L错误
- 如何使用OpenCV-C++编写*.mp4视频?
- Mingw-64 在构建和安装后不会编译 openCV 代码