artoo-opencv 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/LICENSE +2 -0
- data/README.md +23 -0
- data/Rakefile +10 -0
- data/artoo-opencv.gemspec +27 -0
- data/examples/ardrone_face_tracking.rb +54 -0
- data/examples/ardrone_tracking.rb +51 -0
- data/examples/ball_tracking.rb +27 -0
- data/examples/capture.rb +13 -0
- data/examples/face_detect.rb +21 -0
- data/examples/haarcascade_frontalface_alt.xml +26161 -0
- data/lib/artoo-opencv.rb +3 -0
- data/lib/artoo-opencv/version.rb +5 -0
- data/lib/artoo/adaptors/opencv.rb +36 -0
- data/lib/artoo/adaptors/opencv_capture.rb +42 -0
- data/lib/artoo/adaptors/opencv_window.rb +36 -0
- data/lib/artoo/drivers/opencv.rb +40 -0
- data/lib/artoo/drivers/opencv_capture.rb +41 -0
- data/lib/artoo/drivers/opencv_window.rb +43 -0
- data/test/adaptors/opencv_adaptor_test.rb +4 -0
- data/test/drivers/opencv_driver_test.rb +4 -0
- data/test/test_helper.rb +5 -0
- metadata +95 -0
data/lib/artoo-opencv.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'artoo/adaptors/adaptor'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Adaptors
|
5
|
+
# Connect to a opencv device
|
6
|
+
# @see device documentation for more information
|
7
|
+
class Opencv < Adaptor
|
8
|
+
finalizer :finalize
|
9
|
+
attr_reader :device
|
10
|
+
|
11
|
+
# Closes connection with device if connected
|
12
|
+
# @return [Boolean]
|
13
|
+
def finalize
|
14
|
+
disconnect if connected?
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates a connection with device
|
18
|
+
# @return [Boolean]
|
19
|
+
def connect
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
# Closes connection with device
|
24
|
+
# @return [Boolean]
|
25
|
+
def disconnect
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# Uses method missing to call device actions
|
30
|
+
# @see device documentation
|
31
|
+
def method_missing(method_name, *arguments, &block)
|
32
|
+
device.send(method_name, *arguments, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'artoo/adaptors/adaptor'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Adaptors
|
5
|
+
# Connect to a opencv device
|
6
|
+
# @see device documentation for more information
|
7
|
+
class OpencvCapture < Adaptor
|
8
|
+
finalizer :finalize
|
9
|
+
attr_reader :capture
|
10
|
+
|
11
|
+
# Closes connection with device if connected
|
12
|
+
# @return [Boolean]
|
13
|
+
def finalize
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a connection with device
|
17
|
+
# @return [Boolean]
|
18
|
+
def connect
|
19
|
+
require 'opencv' unless defined?(::OpenCV)
|
20
|
+
source = additional_params[:source] || ""
|
21
|
+
if source.to_s.empty?
|
22
|
+
@capture = ::OpenCV::CvCapture::open
|
23
|
+
else
|
24
|
+
@capture = ::OpenCV::CvCapture::open source
|
25
|
+
end
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# Closes connection with device
|
30
|
+
# @return [Boolean]
|
31
|
+
def disconnect
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
# Uses method missing to call device actions
|
36
|
+
# @see device documentation
|
37
|
+
def method_missing(method_name, *arguments, &block)
|
38
|
+
device.send(method_name, *arguments, &block)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'artoo/adaptors/adaptor'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Adaptors
|
5
|
+
# Connect to a opencv device
|
6
|
+
# @see device documentation for more information
|
7
|
+
class OpencvWindow < Adaptor
|
8
|
+
finalizer :finalize
|
9
|
+
attr_reader :window
|
10
|
+
|
11
|
+
# Closes connection with device if connected
|
12
|
+
# @return [Boolean]
|
13
|
+
def finalize
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a connection with device
|
17
|
+
# @return [Boolean]
|
18
|
+
def connect
|
19
|
+
require 'opencv' unless defined?(::OpenCV)
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
# Closes connection with device
|
24
|
+
# @return [Boolean]
|
25
|
+
def disconnect
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# Uses method missing to call device actions
|
30
|
+
# @see device documentation
|
31
|
+
def method_missing(method_name, *arguments, &block)
|
32
|
+
device.send(method_name, *arguments, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'artoo/drivers/driver'
|
2
|
+
|
3
|
+
module Artoo
|
4
|
+
module Drivers
|
5
|
+
# The opencv driver behaviors
|
6
|
+
class Opencv < Driver
|
7
|
+
attr_accessor :image
|
8
|
+
|
9
|
+
def initialize image
|
10
|
+
@image = image
|
11
|
+
end
|
12
|
+
|
13
|
+
def detect_circles(lower, upper)
|
14
|
+
tmp_image = ::OpenCV::BGR2HSV(@image)
|
15
|
+
tmp_image = tmp_image.in_range(::OpenCV::CvScalar.new(lower[:b], lower[:g], lower[:r]), ::OpenCV::CvScalar.new(upper[:b], upper[:g], upper[:r]))
|
16
|
+
return tmp_image.hough_circles(::OpenCV::CV_HOUGH_GRADIENT, 2.0, 10, 200, 50)
|
17
|
+
end
|
18
|
+
|
19
|
+
def draw_circles!(circles=[])
|
20
|
+
circles.each do |circle|
|
21
|
+
@image.circle! circle.center, circle.radius, :color => ::OpenCV::CvColor::Red, :thickness => 3
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def detect_faces(haar)
|
26
|
+
::OpenCV::CvHaarClassifierCascade::load(haar).detect_objects(@image)
|
27
|
+
end
|
28
|
+
|
29
|
+
def draw_rectangles!(rectangles=[])
|
30
|
+
rectangles.each { |rect|
|
31
|
+
@image.rectangle! rect.top_left, rect.bottom_right, :color => ::OpenCV::CvColor::Red, :thickness => 3
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def refresh
|
36
|
+
connection.connect
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'artoo/drivers/driver'
|
2
|
+
require 'artoo/drivers/opencv'
|
3
|
+
|
4
|
+
module Artoo
|
5
|
+
module Drivers
|
6
|
+
# The opencv driver behaviors
|
7
|
+
class OpencvCapture < Driver
|
8
|
+
|
9
|
+
COMMANDS = [:opencv].freeze
|
10
|
+
|
11
|
+
attr_accessor :opencv
|
12
|
+
# Start driver and any required connections
|
13
|
+
def start_driver
|
14
|
+
begin
|
15
|
+
every(interval) do
|
16
|
+
handle_frame
|
17
|
+
end
|
18
|
+
super
|
19
|
+
rescue Exception => e
|
20
|
+
Logger.error "Error starting Opencv driver!"
|
21
|
+
Logger.error e.message
|
22
|
+
Logger.error e.backtrace.inspect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def handle_frame
|
27
|
+
if !connection.capture.nil?
|
28
|
+
frame = connection.capture.query
|
29
|
+
if !frame.nil?
|
30
|
+
@opencv = Artoo::Drivers::Opencv.new(frame)
|
31
|
+
publish(event_topic_name("frame"), @opencv)
|
32
|
+
else
|
33
|
+
connection.connect
|
34
|
+
end
|
35
|
+
else
|
36
|
+
connection.connect
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'artoo/drivers/driver'
|
2
|
+
require 'opencv'
|
3
|
+
|
4
|
+
module Artoo
|
5
|
+
module Drivers
|
6
|
+
class OpencvWindow < Driver
|
7
|
+
|
8
|
+
COMMANDS = [:image=].freeze
|
9
|
+
|
10
|
+
attr_accessor :image, :window
|
11
|
+
|
12
|
+
def initialize(params={})
|
13
|
+
super
|
14
|
+
title = additional_params[:title] || ""
|
15
|
+
@window = ::OpenCV::GUI::Window.new(title)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Start driver and any required connections
|
19
|
+
def start_driver
|
20
|
+
begin
|
21
|
+
every(interval) do
|
22
|
+
show_image
|
23
|
+
end
|
24
|
+
super
|
25
|
+
rescue Exception => e
|
26
|
+
Logger.error "Error starting Opencv driver!"
|
27
|
+
Logger.error e.message
|
28
|
+
Logger.error e.backtrace.inspect
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def show_image
|
34
|
+
begin
|
35
|
+
window.show @image if !@image.nil?
|
36
|
+
::OpenCV::GUI::wait_key(1)
|
37
|
+
rescue Exception => e
|
38
|
+
Logger.error e.message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: artoo-opencv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adrian Zankich
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: artoo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-opencv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.10
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.10
|
41
|
+
description: Artoo adaptor and driver for Opencv
|
42
|
+
email:
|
43
|
+
- artoo@hybridgroup.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- artoo-opencv.gemspec
|
55
|
+
- examples/ardrone_face_tracking.rb
|
56
|
+
- examples/ardrone_tracking.rb
|
57
|
+
- examples/ball_tracking.rb
|
58
|
+
- examples/capture.rb
|
59
|
+
- examples/face_detect.rb
|
60
|
+
- examples/haarcascade_frontalface_alt.xml
|
61
|
+
- lib/artoo-opencv.rb
|
62
|
+
- lib/artoo-opencv/version.rb
|
63
|
+
- lib/artoo/adaptors/opencv.rb
|
64
|
+
- lib/artoo/adaptors/opencv_capture.rb
|
65
|
+
- lib/artoo/adaptors/opencv_window.rb
|
66
|
+
- lib/artoo/drivers/opencv.rb
|
67
|
+
- lib/artoo/drivers/opencv_capture.rb
|
68
|
+
- lib/artoo/drivers/opencv_window.rb
|
69
|
+
- test/adaptors/opencv_adaptor_test.rb
|
70
|
+
- test/drivers/opencv_driver_test.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
homepage: http://artoo.io
|
73
|
+
licenses: []
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project: artoo-opencv
|
91
|
+
rubygems_version: 2.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Artoo adaptor and driver for Opencv
|
95
|
+
test_files: []
|