PHP头条
热点:

Python使用Opencv实现目标检测与识别代码示例


本篇文章小编给大家分享一下Python使用Opencv实现目标检测与识别代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

使用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()

运行结果如图所示:

Python使用Opencv实现目标检测与识别代码示例

这个例子是使用HOG特征进行SVM算法训练,这部分已开始涉及到机器学习的方面,通过SVM算法训练数据集,然后根据某图像与数据集进行匹配。

  • 上一篇: MybatisPlus自动填充如何实现 MybatisPlus自动填充实现代码示例

  • 下一篇: springboot整合mybatis-plus实现分页查询功能代码示例

www.phpzy.comtrue/php/39496.htmlTechArticlePython使用Opencv实现目标检测与识别代码示例 本篇文章小编给大家分享一下Python使用Opencv实现目标检测与识别代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大...

相关文章

    暂无相关文章

PHP之友评论

今天推荐