Skip to content

Commit

Permalink
fix: contain_image allow kwargs only (for extra args in findit)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Dec 5, 2019
1 parent d9aee84 commit 1c9f989
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
14 changes: 3 additions & 11 deletions stagesepx/cutter/cut_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,12 @@ def contain(self, frame_id: int) -> bool:
def contain_image(
self, image_path: str = None, image_object: np.ndarray = None, *args, **kwargs
) -> typing.Dict[str, typing.Any]:
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 pick only one picture?
target_id = self.pick(*args, **kwargs)[0]
operator = self.video.get_operator()
frame = operator.get_frame_by_id(target_id)

return toolbox.match_template_with_object(
image_object, frame.data, *args, **kwargs
return frame.contain_image(
image_path=image_path, image_object=image_object, **kwargs
)

def pick(
Expand Down
10 changes: 5 additions & 5 deletions stagesepx/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,20 @@ def fps_convert(


def match_template_with_object(
template: np.ndarray, target: np.ndarray, *args, **kwargs
template: np.ndarray, target: np.ndarray, **kwargs
) -> typing.Dict[str, typing.Any]:
fi = FindIt(engine=["template"])
# load template
fi_template_name = "default"
fi.load_template(fi_template_name, pic_object=template, *args, **kwargs)
fi.load_template(fi_template_name, pic_object=template)

result = fi.find("", target_pic_object=target)
result = fi.find(target_pic_name="", target_pic_object=target, **kwargs)
return result["data"][fi_template_name]["TemplateEngine"]


def match_template_with_path(
template: str, target: np.ndarray, *args, **kwargs
template: str, target: np.ndarray, **kwargs
) -> typing.Dict[str, typing.Any]:
assert os.path.isfile(template), f"image {template} not existed"
template_object = turn_grey(imread(template))
return match_template_with_object(template_object, target, *args, **kwargs)
return match_template_with_object(template_object, target, **kwargs)
12 changes: 4 additions & 8 deletions stagesepx/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ def copy(self):
return VideoFrame(self.frame_id, self.timestamp, self.data[:])

def contain_image(
self, image_path: str = None, image_object: np.ndarray = None, *args, **kwargs
self, *, image_path: str = None, image_object: np.ndarray = None, **kwargs
) -> typing.Dict[str, typing.Any]:
assert image_path or image_object, "should fill image_path or image_object"
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, *args, **kwargs
)
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, *args, **kwargs
)
return toolbox.match_template_with_object(image_object, self.data, **kwargs)


class _BaseFrameOperator(object):
Expand Down

0 comments on commit 1c9f989

Please sign in to comment.