python 出现 " .... Attempt to start .....This probably means...if __name__ == '__main__':cuow

 当python出现

“ Attempt to start a new process before the current process

            has finished its bootstrapping phase.


            This probably means that you are on Windows 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 a Windows executable.” 

这是因为多进程原因,解决办法,在你使用多进程的模块前添加   if __name__ == '__main__':

例如:

detector = MtcnnDetector(model_folder='model', ctx=mx.cpu(0), num_worker = 4 , accurate_landmark = False)

img = cv2.imread('test.jpg')

# run detector
results = detector.detect_face(img)
if results is not None:
   total_boxes = results[0]
   points = results[1]
    
   # extract aligned face chips
   chips = detector.extract_image_chips(img, points, 144, 0.37)
   for i, chip in enumerate(chips):
     cv2.imshow('chip_'+str(i), chip)
     cv2.imwrite('chip_'+str(i)+'.png', chip)
     draw = img.copy()
   for b in total_boxes:
     cv2.rectangle(draw, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])), (255, 255, 255))
   for p in points:
     for i in range(5):
       cv2.circle(draw, (p[i], p[i + 5]), 1, (0, 0, 255), 2)
   cv2.imshow("detection result", draw)
   cv2.waitKey(0)
需要这样修改

if __name__ == '__main__':
    detector = MtcnnDetector(model_folder='model', ctx=mx.cpu(0), num_worker = 4 , accurate_landmark = False)


    img = cv2.imread('test.jpg')




 # run detector
    results = detector.detect_face(img)


    if results is not None:


        total_boxes = results[0]
        points = results[1]
    
        # extract aligned face chips
        chips = detector.extract_image_chips(img, points, 144, 0.37)
        for i, chip in enumerate(chips):
            cv2.imshow('chip_'+str(i), chip)
            cv2.imwrite('chip_'+str(i)+'.png', chip)


        draw = img.copy()
        for b in total_boxes:
            cv2.rectangle(draw, (int(b[0]), int(b[1])), (int(b[2]), int(b[3])), (255, 255, 255))


        for p in points:
            for i in range(5):
                cv2.circle(draw, (p[i], p[i + 5]), 1, (0, 0, 255), 2)


        cv2.imshow("detection result", draw)
        cv2.waitKey(0)  
 就可以了




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寰宇的行者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值