线程中的一个入口

时间:2017-02-02 13:42:39

标签: python-2.7 pthreads pyqt4 raspbian

我正在使用pyqt4,python2.7。 opencv3,raspbian 我使用名称Vision_thread()创建Function来搜索每个帧中的面。并使用名称start_thread()创建函数以通过线程执行Vision_thread()函数。看这里:

def start_thread():
    t1 = threading.Thread(target=Vision_thread)
    t1.start()
    #t1.join()

现在我按PYqt4创建的按钮调用Funcation:

self.pushButtonStart.setText(_translate("MainWindow", "Start Vision", None))
         # program event click for start Vision button
        self.pushButtonStart.clicked.connect(start_thread)

我的问题是:点击按钮时。函数Vision_thread()中的循环仅执行第一次入口。并且不要连续。 但是当我写道:

t1 = threading.Thread(target=Vision_thread())

insted of

t1 = threading.Thread(target=Vision_thread)

函数Vision_thread()执行没有任何问题。但这不是主题。 什么是问题?????? Vision_thread()代码是:

def Vision_thread():

        print("Vision")
        print (search)
        GPIO.output(32,True)

        for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
              image = frame.array
              gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
              faces = face_cascade.detectMultiScale(gray, 1.3, 5)
              for (x,y,w,h) in faces:
                  cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),2)
                  face = gray[y:y + h, x:x + w]
                  face_resize = cv2.resize(face, (width, height))
                  #Try to recognize the face
                  prediction = model.predict(face_resize)
                  cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 3)
                  x_left=160
                  if prediction[1]<500:
                      cv2.putText(image,'%s - %.0f' % (names[prediction[0]],prediction[1]),(x-10, y-10), cv2.FONT_HERSHEY_PLAIN,1,(0, 255, 0))
                      if names[prediction[0]]==search:
                          x_left = x-width
                          x_right = width - w - x
                          sum_final=x_left+x_right

                          if x_left>180:
                              Left_thread()


                          if x_left<140:
                            Right_thread()


                          print "left={0}\nright={1}\nsum={2}".format(x_left, x_right,sum_final)

                  else:
                     cv2.putText(image,'not recognized',(x-10, y-10), cv2.FONT_HERSHEY_PLAIN,1,(0, 255, 0))

              cv2.imshow('OpenCV', image)
              key = cv2.waitKey(10)
              rawCapture.truncate(0)

              if key == 27:
                GPIO.output(32,False)
                break

0 个答案:

没有答案