detect.py 文件源码

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

项目:age-gender-classification 作者: yunsangq 项目源码 文件源码
def run(self, filename):
        img = cv2.imread(filename)
        self.h_img, self.w_img, _ = img.shape
        img_resized = cv2.resize(img, (448, 448))
        img_RGB = cv2.cvtColor(img_resized, cv2.COLOR_BGR2RGB)
        img_resized_np = np.asarray(img_RGB)
        inputs = np.zeros((1, 448, 448, 3), dtype='float32')
        inputs[0] = (img_resized_np / 255.0) * 2.0 - 1.0
        in_dict = {self.x: inputs}
        net_output = self.sess.run(self.fc_19, feed_dict=in_dict)
        faces = self.interpret_output(net_output[0])
        images = []
        for i, (x, y, w, h, p) in enumerate(faces):
            images.append(self.sub_image('%s/%s-%d.jpg' % (self.tgtdir, self.basename, i + 1), img, x, y, w, h))

        print('%d faces detected' % len(images))

        for (x, y, w, h, p) in faces:
            print('Face found [%d, %d, %d, %d] (%.2f)' % (x, y, w, h, p));
            self.draw_rect(img, x, y, w, h)
            # Fix in case nothing found in the image
        outfile = '%s/%s.jpg' % (self.tgtdir, self.basename)
        cv2.imwrite(outfile, img)
        return images, outfile
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号