好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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实现目标检测与识别的示例代码全部内容,感谢大家支持自学php网。

查看更多关于Python 使用Opencv实现目标检测与识别的示例代码的详细内容...

  阅读:49次