鱼C论坛

 找回密码
 立即注册
查看: 948|回复: 0

python 人工智能—人脸检测

[复制链接]
发表于 2021-12-26 17:34:40 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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>
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-30 16:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表