1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-02-20 20:09:11 +00:00

Merge pull request #278 from marcbonnici/revent_statedetection

ReventWorkload: Modified statedection to vary scale of images
This commit is contained in:
setrofim 2016-11-04 15:39:23 +00:00 committed by GitHub
commit 2becd94381

View File

@ -91,14 +91,24 @@ def match_state(screenshot_file, defpath, state_definitions): # pylint: disable
for template_png in template_list:
template = cv2.imread(os.path.join(defpath, 'templates', template_png + '.png'), 0)
template_edge = auto_canny(template)
template_height, template_width = template_edge.shape[:2]
res = cv2.matchTemplate(img_edge, template_edge, cv2.TM_CCOEFF_NORMED)
threshold = 0.5
loc = np.where(res >= threshold)
zipped = zip(*loc[::-1])
# loop over the scales of the image
for scale in np.linspace(1.4, 0.6, 61):
resized = imutils.resize(img_edge, width=int(img_edge.shape[1] * scale))
if len(zipped) > 0:
matched_templates.append(template_png)
# skip if the resized image is smaller than the template
if resized.shape[0] < template_height or resized.shape[1] < template_width:
break
res = cv2.matchTemplate(resized, template_edge, cv2.TM_CCOEFF_NORMED)
threshold = 0.4
loc = np.where(res >= threshold)
zipped = zip(*loc[::-1])
if len(zipped) > 0:
matched_templates.append(template_png)
break
# determine the state according to the matched templates
matched_state = "none"