Esempio n. 1
0
        video_input = self.get_input(
            "videoInput")  #obiekt interfejsu wejściowego
        video_output = self.get_output(
            "videoOutput")  #obiekt interfejsu wyjściowego

        while self.running():  #pętla główna usługi
            frame_obj = video_input.read(
            )  #odebranie danych z interfejsu wejściowego
            frame = np.loads(frame_obj)  #załadowanie ramki do obiektu NumPy

            with self.service_lock:  # blokada wątku
                resize_coeff = self.resize_coeff

            frame = cv2.resize(frame,
                               None,
                               fx=resize_coeff,
                               fy=resize_coeff,
                               interpolation=cv2.INTER_AREA)

            #frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)

            video_output.send(frame.dumps(
            ))  #przesłanie ramki za pomocą interfejsu wyjściowego


if __name__ == "__main__":
    sc = ServiceController(
        ResizeService,
        "resizeService.json")  #utworzenie obiektu kontrolera usługi
    sc.start()  #uruchomienie usługi
            frame = np.loads(frame_obj)
            # resize
            frame_resized = FrameResizeService.__resize_frame(
                frame, self.thumb_width)
            video_output_resized.send(frame_resized.dumps())

            self.__debug_loop_iterations()

    @log_called_times_decorator
    def __debug_loop_iterations(self):
        pass

    @staticmethod
    def __resize_frame(frame, expected_w):
        h, width, channels = frame.shape
        scale_factor = expected_w * 1.0 / width
        frame_thumb = cv2.resize(frame,
                                 dsize=(0, 0),
                                 fx=scale_factor,
                                 fy=scale_factor,
                                 interpolation=cv2.INTER_CUBIC)
        return frame_thumb


if __name__ == "__main__":
    config_name = os.path.join(
        os.path.dirname(__file__),
        "service.json")  # f.e. src\mark_frame_service\service.json
    sc = ServiceController(FrameResizeService, config_name)
    sc.start()
        while self.running():   #pętla główna usługi
            try:
                frame_obj = video_input.read()  #odebranie danych z interfejsu wejściowego
            except Exception as e:
                video_input.close()
                video_output.close()
                break
            frame = np.loads(frame_obj)     #załadowanie ramki do obiektu NumPy
            with self.filters_lock:     #blokada wątku
                current_filters = self.get_parameter("filtersOn") #pobranie wartości parametru "filtersOn"

            if 1 in current_filters:    #sprawdzenie czy parametr "filtersOn" ma wartość 1, czyli czy ma być stosowany filtr
                frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #zastosowanie filtru COLOR_BGR2GRAY z biblioteki OpenCV na ramce wideo
                frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) # by można było zapisać jako obraz kolorowy
            
            if 2 in current_filters:
                frame = cv2.blur(frame,(7,7))
                
            if 3 in current_filters:
                frame = cv2.GaussianBlur(frame,(5,5),0)
                
            if 4 in current_filters:
                frame = cv2.medianBlur(frame,9) ## nieparzysta liczba
                
            video_output.send(frame.dumps()) #przesłanie ramki za pomocą interfejsu wyjściowego

if __name__=="__main__":
    sc = ServiceController(FilterAudioService, "filter_video_service.json") #utworzenie obiektu kontrolera usługi
    sc.start() #uruchomienie usługi

        video_input = self.get_input("videoInput")
        video_output_resized = self.get_output("videoOutputResized")
        self.thumb_width = self.get_parameter("out_width")
        print "thumb width: " +str(self.thumb_width) + str(type(self.thumb_width))

        while self.running():
            # read frame object
            frame_obj = video_input.read()
            frame = np.loads(frame_obj)
            # resize
            frame_resized = FrameResizeService.__resize_frame(frame, self.thumb_width)
            video_output_resized.send(frame_resized.dumps())

            self.__debug_loop_iterations()

    @log_called_times_decorator
    def __debug_loop_iterations(self):
        pass

    @staticmethod
    def __resize_frame(frame, expected_w):
        h, width, channels = frame.shape
        scale_factor = expected_w * 1.0 / width
        frame_thumb = cv2.resize( frame, dsize=(0,0), fx=scale_factor, fy=scale_factor, interpolation=cv2.INTER_CUBIC)
        return frame_thumb

if __name__=="__main__":
    config_name = os.path.join( os.path.dirname(__file__), "service.json") # f.e. src\mark_frame_service\service.json
    sc = ServiceController(FrameResizeService, config_name)
    sc.start()