Commit bcfa8196 authored by anonym's avatar anonym
Browse files

Test suite: add OpenCV module (to replace Sikuli).

Basically it is a wrapper around OpenCV's matchTemplate() which can be
used for image matching, just like Sikuli's find() etc. Since Ruby
doesn't have any (working) OpenCV bindings we resort to calling a
Python script.

Currently it's not used, but stay tuned!

Refs: #15460
parent 9b9edcf8
class OpenCVInternalError < StandardError
end
module OpenCV
if cmd_helper('lsb_release --short --codename').chomp == 'stretch'
@python = 'python2.7'
else
@python = 'python3'
end
def self.matchTemplate(image, screen, sensitivity)
assert(sensitivity < 1.0)
code = <<EOF
#!/usr/bin/env python3
from __future__ import print_function
import cv2
import os
import sys
from PIL import Image
class FindFailed(RuntimeError):
pass
# Returns the pos of candidate inside image, or raises if no match
def match(image, candidate, sensitivity):
assert(sensitivity < 1.0)
image_rgb = cv2.imread(image, 1)
image_gray = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(candidate, 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(image_gray, template, cv2.TM_CCOEFF_NORMED)
_, val, _, pos = cv2.minMaxLoc(res)
if val < sensitivity:
raise FindFailed
return list(pos) + [w, h]
try:
print(*match("#{screen}", "#{image}", #{sensitivity}))
except FindFailed:
sys.exit(1)
except:
sys.exit(127)
EOF
p = IO.popen([@python, '-c', code], err: [:child, :out])
out = p.readlines.join("\n")
p.close
case $?.exitstatus
when 0
return out.chomp.split.map { |s| s.to_i }
when 1
return nil
else
raise OpenCVInternalError.new(out)
end
end
end
......@@ -45,6 +45,12 @@ virt-viewer
xvfb
"
if [ "$(lsb_release --short --codename)" = "stretch" ]; then
GENERAL_DEPENDENCIES="${GENERAL_DEPENDENCIES} python-opencv python-pil"
else
GENERAL_DEPENDENCIES="${GENERAL_DEPENDENCIES} python3-opencv python3-pil"
fi
usage() {
echo "Usage: $NAME [OPTION]... [--] [CUCUMBER_ARGS]...
Sets up an appropriate environment and invokes cucumber. Note that this script
......
......@@ -58,6 +58,8 @@ To install the dependencies on our test suite:
pry \
python-jabberbot \
python-potr \
python-opencv \
python-pil \
qemu-kvm \
qemu-system-common \
qemu-system-x86 \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment