opencv.rb 791 Bytes
Newer Older
1
2
require 'English'

3
4
5
6
class OpenCVInternalError < StandardError
end

module OpenCV
7
  def self.matchTemplate(image, screen, sensitivity, show_match)
8
    assert(sensitivity < 1.0)
9
10
11
12
13
14
15
    # Do a deep-copy so we don't mess up the outer environment
    env = Hash[ENV]
    if ENV['USER_DISPLAY'].nil? || ENV['USER_DISPLAY'] == ''
      show_match = false
    else
      env['DISPLAY'] = ENV['USER_DISPLAY']
    end
anonym's avatar
anonym committed
16
    p = popen_wait(
17
      [env, 'python3', "#{GIT_DIR}/features/scripts/opencv_match_template.py",
18
       screen, image, sensitivity.to_s, show_match.to_s,],
19
20
      err: [:child, :out]
    )
21
    out = p.readlines.join("\n")
22
    case $CHILD_STATUS.exitstatus
23
    when 0
24
      out.chomp.split.map(&:to_i)
25
    when 1
26
      nil
27
    else
28
      raise OpenCVInternalError, out
29
30
31
    end
  end
end