|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是教的代码,教程能正常运行,我的却一直报错
import cv2
import os
import time
from mxnet_mtcnn_face_detection.mtcnn_detector import MtcnnDetector
import mxnet as mx
import numpy as np
detector = MtcnnDetector(model_folder="./mxnet_mtcnn_face_detection/model", ctx=mx.cpu(0), num_worker=4, accurate_landmark=False)
imgdir = 'face_images'
graydir = 'gray_face_images'
def captureface(someone=None, number=600, waiktey=0):
capture=cv2.VideoCapture(0) # 调用摄像头
time.sleep(1) # 等待一秒钟 让摄像头预热
file_path = os.path.join(imgdir, someone) # 某个人的照片的存放路径
if not os.path.exists(file_path):
os.makedirs(os.path.join(imgdir, file_path))
for i in range(number):
_, img = capture.read() # 拍照
cv2.imwrite(os.path.join(file_path, str(i)+'.jpg'), img)
cv2.imshow(file_path, img)
if cv2.waitKey(waiktey) == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
captureface(someone='zhangsan', waiktey=600)
someone = 'zhangsan'
size = 64
img = cv2.imread('zhangmin1 .jpg')
result = detector.detect_face(img) #检测图片中的人脸
newPath = os.path.join(graydir, someone)
if not os.path.exists(newPath):
os.makedirs(newPath)
if result is not None:
faceboxes = result[0]
index = np.sum(faceboxes < 0,axis=1) == 0
faceboxes = faceboxes[index] # 删除人脸不全的信息
for a in faceboxes:
face = img[int(a[1]):int([3])+1, int(a[0]):int(a[2])+1] # 将图片中的人脸部位截取出来
gray = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY) # 将彩色图转换成灰色图
gray = cv2.resize(gray, (size, size)) #
cv2.imwrite()
cv2.imshow('face1', face)
cv2.waitKey(10000)
报错如下:
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
Traceback (most recent call last):
File "<string>", line 1, in <module>
|
|