我遇到过这个link用于面部检测和图像裁剪。我想使用这个脚本,但我有cv2安装,只导入cv2工作但不导入简历。
如何将以下函数中的cv函数转换为cv2函数?
def faces_from_pil_image(pil_image):
"Return a list of (x,y,h,w) tuples for faces detected in the PIL image"
storage = cv.CreateMemStorage(0)
facial_features = cv.Load('haarcascade_frontalface_alt.xml', storage=storage)
cv_im = cv.CreateImageHeader(pil_image.size, cv.IPL_DEPTH_8U, 3)
cv.SetData(cv_im, pil_image.tostring())
faces = cv.HaarDetectObjects(cv_im, facial_features, storage)
# faces includes a `neighbors` field that we aren't going to use here
return [f[0] for f in faces]
答案 0 :(得分:0)
使用
import cv2
storage = cv2.cv.CreateMemStorage(0)
或
from cv2 import *
storage = cv.CreateMemStorage(0)