Пример #1
0
    def contain_image(self,
                      image_path: str = None,
                      image_object: np.ndarray = None,
                      *args,
                      **kwargs) -> typing.Dict:
        assert image_path or image_object, 'should fill image_path or image_object'

        if image_path:
            logger.debug(f'found image path, use it first: {image_path}')
            assert os.path.isfile(
                image_path), f'image {image_path} not existed'
            image_object = toolbox.imread(image_path)
        image_object = toolbox.turn_grey(image_object)

        # TODO use client or itself..?
        fi = FindIt(engine=['template'])
        fi_template_name = 'default'
        fi.load_template(fi_template_name, pic_object=image_object)

        with toolbox.video_capture(self.video.path) as cap:
            target_id = self.pick(*args, **kwargs)[0]
            frame = toolbox.get_frame(cap, target_id)
            frame = toolbox.turn_grey(frame)

            result = fi.find(str(target_id), target_pic_object=frame)
        return result['data'][fi_template_name]['TemplateEngine']
Пример #2
0
    def contain_image(self,
                      image_path: str = None,
                      image_object: np.ndarray = None,
                      threshold: float = None,
                      *args,
                      **kwargs):
        assert image_path or image_object, 'should fill image_path or image_object'
        if not threshold:
            threshold = 0.99

        if image_path:
            logger.debug(f'found image path, use it first: {image_path}')
            assert os.path.isfile(
                image_path), f'image {image_path} not existed'
            image_object = cv2.imread(image_path)
        image_object = toolbox.turn_grey(image_object)

        # TODO use client or itself..?
        fi = FindIt(engine=['template'])
        fi_template_name = 'default'
        fi.load_template(fi_template_name, pic_object=image_object)

        with toolbox.video_capture(self.video.path) as cap:
            target_id = self.pick(*args, **kwargs)[0]
            frame = toolbox.get_frame(cap, target_id)
            frame = toolbox.turn_grey(frame)

            result = fi.find(str(target_id), target_pic_object=frame)
        find_result = result['data'][fi_template_name]['TemplateEngine']
        position = find_result['target_point']
        sim = find_result['target_sim']
        logger.debug(f'position: {position}, sim: {sim}')
        return sim > threshold
Пример #3
0
    def contain_image(self,
                      image_path: str = None,
                      image_object: np.ndarray = None,
                      *args,
                      **kwargs) -> typing.Dict:
        assert image_path or image_object, "should fill image_path or image_object"

        if image_path:
            logger.debug(f"found image path, use it first: {image_path}")
            assert os.path.isfile(
                image_path), f"image {image_path} not existed"
            image_object = toolbox.imread(image_path)
        image_object = toolbox.turn_grey(image_object)

        # TODO use client or itself..?
        fi = FindIt(engine=["template"])
        fi_template_name = "default"
        fi.load_template(fi_template_name, pic_object=image_object)

        target_id = self.pick(*args, **kwargs)[0]
        operator = self.video.get_operator()
        frame = operator.get_frame_by_id(target_id)

        result = fi.find(str(target_id), target_pic_object=frame.data)
        return result["data"][fi_template_name]["TemplateEngine"]
Пример #4
0
    def contain_image(self,
                      *,
                      image_path: str = None,
                      image_object: np.ndarray = None,
                      **kwargs) -> typing.Dict[str, typing.Any]:
        assert image_path or (
            image_object is not None), "should fill image_path or image_object"

        if image_path:
            logger.debug(f"found image path, use it first: {image_path}")
            return toolbox.match_template_with_path(image_path, self.data,
                                                    **kwargs)
        image_object = toolbox.turn_grey(image_object)
        return toolbox.match_template_with_object(image_object, self.data,
                                                  **kwargs)
Пример #5
0
    def do(self, frame: VideoFrame, *_, **__) -> typing.Optional[VideoFrame]:
        super().do(frame, *_, **__)

        # you can get frame_id and frame data here
        # and use them to custom your own function

        # add your code here
        # ...

        # for example, i want to turn grey, and save size of each frames
        frame.data = toolbox.turn_grey(frame.data)
        self.result[frame.frame_id] = frame.data.shape

        # if you are going to change the origin frame
        # just return the changed frame
        # and set 'overwrite' to 'True' when you are calling __init__
        return frame
Пример #6
0
 def do(
     self, frame_id: int, frame: np.ndarray, *_, **__
 ) -> typing.Optional[np.ndarray]:
     super().do(frame_id, frame, *_, **__)
     return toolbox.turn_grey(frame)
Пример #7
0
def test_turn_grey():
    image = toolbox.imread(IMAGE_PATH)
    toolbox.turn_grey(image)
Пример #8
0
def test_turn_blur():
    image = toolbox.imread(IMAGE_PATH)
    grey = toolbox.turn_grey(image)
    toolbox.turn_blur(grey)
Пример #9
0
 def init(cls, cap: cv2.VideoCapture, frame: np.ndarray) -> "VideoFrame":
     frame_id = toolbox.get_current_frame_id(cap)
     timestamp = toolbox.get_current_frame_time(cap)
     grey = toolbox.turn_grey(frame)
     logger.debug(f"new a frame: {frame_id}({timestamp})")
     return VideoFrame(frame_id, timestamp, grey)
Пример #10
0
 def init(cls, cap: cv2.VideoCapture, frame: np.ndarray) -> "VideoFrame":
     frame_id = toolbox.get_current_frame_id(cap)
     timestamp = toolbox.get_current_frame_time(cap)
     grey = toolbox.turn_grey(frame)
     return VideoFrame(frame_id, timestamp, grey)
Пример #11
0
 def do(self, frame: VideoFrame, *_, **__) -> typing.Optional[VideoFrame]:
     super().do(frame, *_, **__)
     frame.data = toolbox.turn_grey(frame.data)
     return frame