我需要使用haar级联来检测图像的上身和下身。 我尝试使用haarcascade_lowerbody.xml和haarcascade_upperbody.xml,但是我没有得到想要的正确输出。
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('image1.png',cv2.IMREAD_COLOR)
face_cascade = cv2.CascadeClassifier('haarcascade_lowerbody1.xml')
low_cascade = cv2.CascadeClassifier('haarcascade_upperbody.xml')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY )
faces = face_cascade.detectMultiScale(gray, 1.05 , 4)
low = low_cascade.detectMultiScale(gray, 1.1 , 3)
for (x,y,w,h) in faces:
cv2.rectangle(img, (x,y), (x+w, y+h), (12,150,100),2)
for (x,y,w,h) in low:
cv2.rectangle(img, (x,y), (x+w, y+h), (12,150,100),2)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()