'the list in QThread class can't get data

I intend to use face_recognition's face_location function to identify the position of the face in the image and add a box. The image is then displayed in the GUI designed in PYQT5 However, only camera images can be displayed, but there is no box after debugging, I found that the list that gets the location of the face cannot get the data, but this works in programs that do not use threads of PYQT5

enter image description here

enter image description here

here is my code QThread class

class camera_Thread(QThread):

    def __init__(self, sign_face_ui_obj):
        super(camera_Thread, self).__init__()
        self.sign_face_ui_obj = sign_face_ui_obj
        self.camera = cv2.VideoCapture(0, cv2.CAP_DSHOW)
        self.face_names = ""


    def run(self):
        process_this_frame = True
        while True:
            try:
                ret, frame = self.camera.read()
                # Resize frame of video to 1/4 size for faster face recognition processing
                small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
            except:
                continue
            # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
            small_frame = cv2.cvtColor(small_frame, cv2.COLOR_BGR2RGB)
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            rgb_small_frame = small_frame
            if process_this_frame:
                # Find all the faces and face encodings in the current frame of video
                face_locations = face_recognition.face_locations(rgb_small_frame)
            process_this_frame = not process_this_frame

            for (top, right, bottom, left), name in zip(face_locations, self.face_names):
                # Scale back up face locations since the frame we detected in was scaled to 1/4 size
                top *= 4
                right *= 4
                bottom *= 4
                left *= 4

                # Draw a box around the face
                cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

                # Draw a label with a name below the face
                cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)

            show = QImage(frame.data, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
            self.sign_face_ui_obj.ui.cameraLb.setPixmap(QPixmap.fromImage(show))
            self.sign_face_ui_obj.ui.cameraLb.setScaledContents(True) 

MainWindow

    def __init__(self, parent=None):
        super(Sign_Face_Logic, self).__init__(parent)
        self.ui=Ui_SignFace()
        self.ui.setupUi(self)






if __name__ == '__main__':
    App = QApplication(sys.argv)
    user_interface = Sign_Face_Logic()
    th = funtion_ui_v1.camera_Thread(user_interface)
    th.start()
    user_interface.show()
    sys.exit(App.exec_()) ```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source