处理中发送的函数无法更改类字段的值

时间:2018-12-27 08:30:18

标签: python python-3.x multiprocessing

变量self.process_this_frame在过程中未更改。 现在,我只想处理应处理的上一帧并跳过其他帧。

import cv2
import face_recognition
import multiprocessing


class FaceLocationSender:
    def __init__(self, camera_url):
        self.video_capture = cv2.VideoCapture(camera_url)
        self.face_locations = []
        self.process_this_frame = True

    def get_faces_from_frame(self, frame):
        self.face_locations = face_recognition.face_locations(frame)
        self.process_this_frame = True

    def start(self):
        while True:
            ret, frame = self.video_capture.read()

            small_frame = cv2.resize(frame, (0, 0), fx=1/2, fy=1/2)

            rgb_small_frame = small_frame[:, :, ::-1]

            if self.process_this_frame:
                self.process_this_frame = False
                process = multiprocessing.Process(target=self.get_faces_from_frame, args=(rgb_small_frame,))
                process.start()

            for (top, right, bottom, left) in self.face_locations:
                top *= 2
                right *= 2
                bottom *= 2
                left *= 2

                cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 0), 2)

            cv2.imshow('Video', cv2.resize(frame, (1200, 600)))

            if cv2.waitKey(1) & 0xFF == ord('q'):
                break

        self.video_capture.release()
        cv2.destroyAllWindows()

0 个答案:

没有答案