train_faces.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:tbotnav 作者: patilnabhi 项目源码 文件源码
def process_image(self, inImg):
        (self.frame_width, self.frame_height) = (112, 92)        
        frame = cv2.flip(inImg,1,0)
        grayImg = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
        cropped = cv2.resize(grayImg, (grayImg.shape[1] / self.size, grayImg.shape[0] / self.size))        
        faces = self.haar_cascade.detectMultiScale(cropped)
        faces = sorted(faces, key=lambda x: x[3])  
        if faces:
            face_i = faces[0] 
            x = face_i[0] * self.size
            y = face_i[1] * self.size
            w = face_i[2] * self.size
            h = face_i[3] * self.size
            face = grayImg[y:y + h, x:x + w]
            face_resize = cv2.resize(face, (self.frame_width, self.frame_height))
            img_no = sorted([int(fn[:fn.find('.')]) for fn in os.listdir(self.path) if fn[0]!='.' ]+[0])[-1] + 1
            if self.count % self.cp_rate == 0:
                cv2.imwrite('%s/%s.png' % (self.path, img_no), face_resize)
                print "Captured Img: ", self.count/self.cp_rate + 1
            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)
            cv2.putText(frame, self.face_name, (x - 10, y - 10), cv2.FONT_HERSHEY_PLAIN, 1,(0, 255, 0))            
            self.count += 1 
        return frame
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号