东瑜

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

思路:先获取10000张自己的图像,然后通过CNN神经网络进行学习。
第一步:先获取自己的脸的数据。如何做?
代码如下:

import cv2
import os
import sys
import random

output_dir = 'E:/myface'

# 上述目录不存在,创建一个temp目录
if not os.path.exists(output_dir):
    os.makedirs(output_dir)


# 打开摄像头 参数为输入流,可以为摄像头或视频文件
camera = cv2.VideoCapture(0)

index = 1
while True:
	if (index <= 10000):
		print('Being processed picture %s' % index)
## 获取我的脸部图片
		success, img = camera.read()
		cv2.imshow('image', img)
		cv2.imwrite(output_dir+'/'+str(index)+'.jpg', img)
		index += 1
	else:
		print('Finished!')
		break

图像效果:

posted on 2020-04-11 20:54  东瑜  阅读(459)  评论(0编辑  收藏  举报
\\页脚html代码