lava-frame_compare 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 135845266a14a87775f1777e86d6c03e5990fbe0
4
+ data.tar.gz: e36c97766577ac1dc6433d250496b3eb7decc83f
5
+ SHA512:
6
+ metadata.gz: 9f84ebf91ebcd2780dbefdacddb8bb522006b7a84706c1aab56b733c1aab1dc024ed66075a316363d1977de92a8fcdab465812cdef73a431d632d8f4b930ce3f
7
+ data.tar.gz: 861c332f21baf00ead2caf1f0910dea792ee741cb6defc7573289ebc27e15373cd0725545f454b2e712cc9af32f41594bd55f04c305365e080fb520e00e2bf4e
@@ -0,0 +1,30 @@
1
+ require 'lava/session'
2
+
3
+ module Lava
4
+
5
+ class FrameCompare
6
+
7
+
8
+ # Initialize a frame comparison session
9
+ # Takes a number of args:
10
+ # * name (optional) -- name for the session
11
+ # * dir (optional) -- directory to store frame captures
12
+ # * frame_capture (required) -- lambda for performing a frame capture
13
+ # The lambda should take a single argument, filename:
14
+ # capture_frame = ->(filename) {
15
+ # code_to_perform_frame_capture( :save_to => filename )
16
+ # }
17
+ def self.start_session( args )
18
+
19
+ raise "frame_capture lambda function required" if !args[:frame_capture] || args[:capture]
20
+
21
+ Lava::Session.new( :name => args[:name],
22
+ :frame_capture => args[:frame_capture] || args[:capture],
23
+ :dir => args[:dir],
24
+ :audio_sample => args[:audio_sample] )
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,39 @@
1
+ module Lava
2
+
3
+ # Class representing an image capture
4
+ class Sample
5
+
6
+ attr_accessor :volume, :blur, :file, :rimage, :time, :last, :raw
7
+
8
+ def initialize( args = {} )
9
+
10
+ @file = args[:file]
11
+ @time = args[:time] || Time.now
12
+ @last = args[:last]
13
+ @volume = args[:volume]
14
+ @raw = {};
15
+ @rimage = Magick::ImageList.new(file).first
16
+ enrich_previous_sample if last
17
+ analyze
18
+ end
19
+
20
+ def enrich_previous_sample
21
+ delay = (time - last.time).to_i
22
+ last.rimage.delay = delay
23
+ end
24
+
25
+ def analyze
26
+ if last
27
+ raw[:mean_error_per_pixel], raw[:normalized_mean_error], raw[:normalized_max_error] = last.rimage.difference(rimage)
28
+ end
29
+ raw
30
+ end
31
+
32
+ def diff
33
+ raw[:mean_error_per_pixel].to_i
34
+ end
35
+
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,87 @@
1
+ require 'rmagick'
2
+ require 'fileutils'
3
+
4
+ module Lava
5
+
6
+ DEFAULT_TMP_DIR = '/tmp/lava'
7
+ DEFAULT_MAX_HEIGHT = 750
8
+ DEFAULT_MAX_WIDTH = 750
9
+ DEFAULT_SPEED = 2
10
+
11
+
12
+ # Main class for managing the capture sessions
13
+ class Session
14
+
15
+ attr_accessor :name, :dir, :samples, :frame_capture #, :audio_sample
16
+
17
+ # Initialize a capture session
18
+ def initialize( args = {} )
19
+ @name = args[:name] || Time.now.to_i
20
+ @dir = args[:dir] || "#{DEFAULT_TMP_DIR}/#{@name}"
21
+ @frame_capture = args[:frame_capture] or raise ArgumentError, 'Need to provide a lambda to the constructor'
22
+ @samples = []
23
+ FileUtils.mkdir_p(@dir)
24
+ File.directory?(@dir) or raise "Couldn't create session directory for screen grabs"
25
+ end
26
+
27
+ # Perform a frame capture
28
+ def capture
29
+ filename = Time.now.to_f.to_s + '.png'
30
+
31
+ file = "#{dir}/#{filename}"
32
+
33
+ capture_time = Time.now
34
+
35
+ @frame_capture.call(file)
36
+
37
+ File.exist? file or raise "Couldn't capture frame"
38
+
39
+ sample = Lava::Sample.new( :file => file, :time => capture_time, :last => samples.last )
40
+ samples << sample
41
+ sample
42
+ end
43
+
44
+ # Performs a capture and diffs it with the last image
45
+ def diff
46
+ if samples.count == 0
47
+ self.capture
48
+ end
49
+
50
+ current = self.capture
51
+
52
+ current.diff
53
+ end
54
+
55
+ # Finalize the capture session, and create an animated gif
56
+ # of the capture session
57
+ def end(args = {})
58
+
59
+ if args[:file]
60
+ file = args[:file]
61
+ else
62
+ if !args[:filename]
63
+ file = "#{@dir}/#{@name}.gif"
64
+ else
65
+ file = "#{@dir}/#{filename}"
66
+ end
67
+ end
68
+
69
+ rotate = args[:rotate] || 0
70
+ max_width = args[:max_width] || Lava::DEFAULT_MAX_WIDTH
71
+ max_height = args[:max_height] || Lava::DEFAULT_MAX_HEIGHT
72
+ speed = args[:speed] || Lava::DEFAULT_SPEED
73
+
74
+
75
+ rimages = Magick::ImageList.new
76
+ samples.each do |s|
77
+ s.rimage.resize_to_fit!(max_width, max_height)
78
+ s.rimage.rotate! rotate
79
+ rimages << s.rimage
80
+ end
81
+ rimages.ticks_per_second = speed
82
+ rimages.write(file)
83
+ end
84
+
85
+ end
86
+
87
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lava-frame_compare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BBC
8
+ - David Buckhurst
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rmagick
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: Analysis tool for performing video frame comparisons
29
+ email: david.buckhurst@bbc.co.uk
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/lava/frame_compare.rb
35
+ - lib/lava/sample.rb
36
+ - lib/lava/session.rb
37
+ homepage: https://github.com/bbc/lava-frame_compare
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.4.5.1
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Lava FrameCompare
61
+ test_files: []