首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >imshow窗口在我把连接python和arduino的代码放入循环后没有响应,这是为什么呢?

imshow窗口在我把连接python和arduino的代码放入循环后没有响应,这是为什么呢?
EN

Stack Overflow用户
提问于 2021-02-09 15:10:14
回答 1查看 26关注 0票数 1

这个项目是带条形码的人脸识别。它需要首先检测人脸,然后才能扫描条形码。流程是正常的,除非它检测到有人面对imshow中的窗口不再响应,网络摄像头被冻结。我想让摄像头在处理代码的同时继续移动,我该怎么做呢?

代码语言:javascript
复制
cap = cv2.VideoCapture(0)

if not cap.isOpened():
      raise IOError("Cannot open webcam") \

temp = ""
while True:

    success, eImgs = cap.read()
    if success:
         font = cv2.FONT_HERSHEY_PLAIN
         datet = str(datetime.now())
         frame = cv2.putText(eImgs, datet, (10, 50), font, 1, (0, 0, 128), 1, cv2.LINE_AA)
         # eImgs_v1 = cv2.resize (eImgs, (0, 0), None, 0.25, 0,25)
         eImgs_v1 = cv2.cvtColor(eImgs, cv2.COLOR_BGR2RGB)

         facesWebcam = face_recognition.face_locations(eImgs_v1)
         encodesWebcam = face_recognition.face_encodings(eImgs_v1, facesWebcam)

        for encodeKnown_v2, faceLoc in zip(encodesWebcam, facesWebcam):
            facesCompared = face_recognition.compare_faces(encodeKnown, encodeKnown_v2)
            faceDistance = face_recognition.face_distance(encodeKnown, encodeKnown_v2)
            faceIndex = np.argmin(faceDistance)

            if facesCompared[faceIndex]:
                 employeeName = ListNames[faceIndex]
                 y = employeeName
                 if temp == "" or temp != name:
                      print(name)
                      temp = name

                      if y:
                          print(y)
                          print("AUTHORIZED")

                          time.sleep(1)

                          **# Arduino and Python connection**
                          *arduino = serial.Serial('COM9', 115200, timeout=.1)
                          time.sleep(1)
                          print("The system is ready!")
                          while True:
                               barcode = arduino.readline()[:-2]
                               strbarcode = barcode.decode('utf-8')
                               if strbarcode:
                                     x = strbarcode
                                     print(x)
                                     if y == x:
                                         print('Have a nice day!')
                                         time.sleep(3)
                                         print("Next Employee please!")
                                     else:
                                         print('This is not yours!')*


                      else:
                          print("UNAUTHORIZED")

                 p1, p2, p3, p4 = faceLoc
                 cv2.rectangle(eImgs, (p1, p2), (p3, p4), (0, 255, 0), 2)
                 cv2.putText(eImgs, y, (p1, p3), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 2)

        

    cv2.imshow('EMPLOYEE', eImgs)
    cv2.waitKey(1)

cap.release()
cv2.destroyAllWindows()
EN

回答 1

Stack Overflow用户

发布于 2021-02-10 15:51:58

我推荐你使用deepface。它的流函数应用于人脸识别与几种最先进的人脸识别模型。

代码语言:javascript
复制
models = ['VGG-Face', 'Facenet', 'OpenFace', 'DeepFace', 'DeepID', 'Dlib', 'ArcFace']

#!pip install deepface
from deepface import DeepFace
DeepFace.stream(db_path = 'C:/my_db'
   , model_name = models[0]
   , enable_face_analysis = False #to disable age, gender, emotion prediction
)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66114447

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档