TA的每日心情 | 无聊 2019-6-2 14:11 |
---|
签到天数: 4 天 [LV.2]圆转纯熟
|
在上章节讲述到图像特征检测与匹配 ,本章节是讲述目标检测与识别。后者是在前者的基础上进一步完善。
在本章中,我们使用HOG算法,HOG和SIFT、SURF同属一种类型的描述符。功能代码如下:- import cv2
- def is_inside(o, i):
- ox, oy, ow, oh = o
- ix, iy, iw, ih = i
- # 如果符合条件,返回True,否则返回False
- return ox > ix and oy > iy and ox + ow < ix + iw and oy + oh < iy + ih
- # 根据坐标画出人物所在的位置
- def draw_person(img, person):
- x, y, w, h = person
- cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 255), 2)
- # 定义HOG特征+SVM分类器
- img = cv2.imread("people.jpg")
- hog = cv2.HOGDescriptor()
- hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
- found, w = hog.detectMultiScale(img, winStride=(8, 8), scale=1.05)
- # 判断坐标位置是否有重叠
- found_filtered = []
- for ri, r in enumerate(found):
- for qi, q in enumerate(found):
- a = is_inside(r, q)
- if ri != qi and a:
- break
- else:
- found_filtered.append(r)
- # 勾画筛选后的坐标位置
- for person in found_filtered:
- draw_person(img, person)
- # 显示图像
- cv2.imshow("people detection", img)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
复制代码 运行结果如图所示:
这个例子是使用HOG特征进行SVM算法训练,这部分已开始涉及到机器学习的方面,通过SVM算法训练数据集,然后根据某图像与数据集进行匹配。
到此这篇关于Python 使用Opencv实现目标检测与识别的示例代码的文章就介绍到这了,更多相关Opencv 目标检测与识别内容请搜索咔叽论坛以前的文章或继续浏览下面的相关文章希望大家以后多多支持咔叽论坛!
原文地址:https://www.jb51.net/article/195145.htm |
|