赞
踩
CV之IC:基于OpenCV的CascadeClassifier级联分类器利用python语言加载猫脸检测文件haarcascade_frontalcatface.xml实现对猫脸检测并标注文本标签
目录
基于OpenCV的CascadeClassifier级联分类器利用python语言加载猫脸检测文件haarcascade_frontalcatface.xml实现对猫脸检测并标注文本标签
- @author: niu
- '''
- import cv2
- catPath = "haarcascade_frontalcatface.xml"
- faceCascade = cv2.CascadeClassifier(catPath)
- img = cv2.imread("F:\File_Python\Resources\cat.jpg")
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- faces = faceCascade.detectMultiScale(
- gray,
- scaleFactor= 1.02,
- minNeighbors=3,
- minSize=(150, 150),
- flags=cv2.CASCADE_SCALE_IMAGE
- )
- for (x, y, w, h) in faces:
- cv2.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 2)
- cv2.putText(img,'Persian cat',(x,y-7), 3, 1.2, (0, 255, 0), 2, cv2.LINE_AA)
- cv2.imshow('Jason niu', img)
- cv2.imwrite("cat.jpg",img)
- c = cv2.waitKey(0)
参考文献
CV:利用OpenCV的CascadeClassifier级联分类器加载猫脸检测文件haarcascade_frontalcatface.xml实现对猫脸检测并加文本cat
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。