【发布时间】:2015-07-06 01:58:15
【问题描述】:
我在进行面部检测和将图像裁剪为面部工作时遇到问题,下面是我的代码。
import cv2
class Crop:
#constructor
def __init__(self, image):
self.data = image
def facechop(self):
# read xml for training data
facedata = "haarcascade_frontalface_default.xml"
cascade = cv2.CascadeClassifier(facedata)
# read image file
img = cv2.imread(self.data, 0)
minisize = (img.shape[1], img.shape[0])
miniframe = cv2.resize(img, minisize)
faces = cascade.detectMultiScale(miniframe)
for f in faces:
x, y, w, h = [ v for v in f ]
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 255))
sub_face = self.data[y:y + h, x:x + w]
# Show picture
cv2.imshow('img', sub_face)
return
输入图片文件
picture = 'izz.jpg'
pic = Crop(gambar)
pic.facechop()
# keyboard input to destroy the window
while(True):
key = cv2.waitKey(0)
if key in [27, ord('Q'), ord('q')]:
break
当它运行时,它在for 函数之后直到sub_face = self.data[y:y + h, x:x + w] 才执行原始操作。它直接转到cv2.imshow('img', sub_face)。所以,sub_face 是未知的。为什么效果不好?
我正在使用 Aptana 来调试它。谢谢。
【问题讨论】:
标签: python opencv camera capture