motion-capture 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 098882fee3cdac39ac683f6add7df21009187b01
4
- data.tar.gz: 95a133286c70f6bab31ce7410056046df6ed2231
3
+ metadata.gz: d2ea866d57338e676627eaa74c23c490d6e8fd06
4
+ data.tar.gz: 0f31ebdf4127769dbfac818379cb5372e45f870e
5
5
  SHA512:
6
- metadata.gz: 1957c4720f94d8fb3aaf998535a6865fa2b98d37daed7469703920f21167b15b64a029607644345c350d9477584cff1a2524707d76f08997b9e3496411bc06ce
7
- data.tar.gz: ec63205dae5efc7e59eecbdc569f07b91c99c862dd47952446c5964bdb1ea18e733b19c789d5dbc9a0ac5bd02c72ed2b997cb3bd222f499949964b1feb219e25
6
+ metadata.gz: e5e8c4a930c9b6cc47e7479b0ddd84cc186ae717a8dc27f850c4e544fff6c48d43d4ba15d0c5d5a3d8a3a212bd65da00166c17fc010e6adc92d3b5e66167502c
7
+ data.tar.gz: d719496998b5a1f5d80ba12da71d9a8dff5265d7ece8c37feb262d719cb19ef592e60d66bfa412e3684a606cb84036dcc95cece83dd51b06e4df3082426710a5
data/README.md CHANGED
@@ -4,25 +4,31 @@ Camera support for custom camera controllers
4
4
 
5
5
  ## Usage
6
6
 
7
- motion_capture = Motion::Capture.new
8
- motion_capture = Motion::Capture.new(device: :front) # specify camera
7
+ ``` ruby
8
+ motion_capture = Motion::Capture.new
9
+ motion_capture = Motion::Capture.new(device: :front) # specify camera
9
10
 
10
- preview = motion_capture.capture_preview_view(frame: view.bounds)
11
- view.addSubview(preview) # UIView containing AVCaptureVideoPreviewLayer
11
+ preview = motion_capture.capture_preview_view(frame: view.bounds)
12
+ view.addSubview(preview) # UIView containing AVCaptureVideoPreviewLayer
12
13
 
13
- motion_capture.toggle_camera # Switch between front/rear cameras
14
- motion_capture.toggle_flash # Switch bettwen flash on/off
14
+ motion_capture.toggle_camera # Switch between front/rear cameras
15
+ motion_capture.toggle_flash # Switch bettwen flash on/off
15
16
 
16
- motion_capture.turn_flash_on
17
- motion_capture.turn_flash_off
17
+ motion_capture.turn_flash_on
18
+ motion_capture.turn_flash_off
18
19
 
19
- motion_capture.use_camera(:default)
20
- motion_capture.use_camera(:front)
21
- motion_capture.use_camera(:rear)
20
+ motion_capture.use_camera(:default)
21
+ motion_capture.use_camera(:front)
22
+ motion_capture.use_camera(:rear)
22
23
 
23
- motion_capture.capture do |image|
24
- # Use UIImage
25
- end
24
+ motion_capture.capture do |image_data|
25
+ # Use NSData
26
+ end
27
+
28
+ motion_capture.capture_and_save do |asset_url|
29
+ # Use NSURL
30
+ end
31
+ ```
26
32
 
27
33
  ## Setup
28
34
 
@@ -14,22 +14,59 @@ class Motion
14
14
  add_ouput(still_image_output)
15
15
  end
16
16
 
17
+ def stop!
18
+ session.stopRunning
19
+
20
+ remove_outputs
21
+ remove_inputs
22
+
23
+ @_still_image_output = nil
24
+ @_session = nil
25
+ @_capture_preview_view = nil
26
+ end
27
+
17
28
  def capture(&block)
18
- still_image_connection = still_image_output.connections.first
29
+ still_image_connection = still_image_output.connectionWithMediaType(AVMediaTypeVideo)
30
+
31
+ if still_image_connection.isVideoOrientationSupported
32
+ still_image_connection.setVideoOrientation(UIDevice.currentDevice.orientation)
33
+ end
19
34
 
20
35
  still_image_output.captureStillImageAsynchronouslyFromConnection(still_image_connection, completionHandler: lambda { |image_data_sample_buffer, error|
21
36
  if image_data_sample_buffer
22
37
  image_data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(image_data_sample_buffer)
23
38
 
24
- image = UIImage.alloc.initWithData(image_data)
39
+ block.call(image_data)
40
+ else
41
+ p "Error capturing image: #{error.localizedDescription}"
42
+ end
43
+ })
44
+ end
45
+
46
+ def capture_and_save(&block)
47
+ still_image_connection = still_image_output.connectionWithMediaType(AVMediaTypeVideo)
48
+
49
+ if still_image_connection.isVideoOrientationSupported
50
+ still_image_connection.setVideoOrientation(UIDevice.currentDevice.orientation)
51
+ end
52
+
53
+ still_image_output.captureStillImageAsynchronouslyFromConnection(still_image_connection, completionHandler: lambda { |image_data_sample_buffer, error|
54
+ if image_data_sample_buffer
55
+ image_data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(image_data_sample_buffer)
25
56
 
26
- block.call(image)
57
+ assets_library.writeImageDataToSavedPhotosAlbum(image_data, metadata: nil, completionBlock: lambda { |asset_url, error|
58
+ block.call(asset_url)
59
+ })
27
60
  else
28
- p "Error capturing image: #{error[0].description}"
61
+ p "Error capturing image: #{error.localizedDescription}"
29
62
  end
30
63
  })
31
64
  end
32
65
 
66
+ def assets_library
67
+ @_assets_library ||= ALAssetsLibrary.alloc.init
68
+ end
69
+
33
70
  def capture_preview_view(options)
34
71
  @_capture_preview_view ||= begin
35
72
  start!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-capture
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devon Blandin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-08 00:00:00.000000000 Z
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -34,7 +34,6 @@ files:
34
34
  - README.md
35
35
  - lib/motion-capture.rb
36
36
  - lib/project/motion-capture.rb
37
- - lib/project/views/overlay_view.rb
38
37
  homepage: https://github.com/dblandin/motion-capture
39
38
  licenses:
40
39
  - MIT
@@ -1,112 +0,0 @@
1
- class GridOverlayView < UIView
2
- DEFAULTS = { stroke_color: UIColor.grayColor,
3
- stroke_width: 1.0,
4
- x_lines: 3,
5
- y_lines: 3 }
6
-
7
- attr_accessor :x_interval, :y_interval
8
- attr_reader :stroke_color, :stroke_width
9
-
10
- def initWithFrame(frame)
11
- super.tap do |view|
12
- view.backgroundColor = UIColor.clearColor
13
-
14
- self.x_lines = DEFAULTS[:x_lines]
15
- self.y_lines = DEFAULTS[:y_lines]
16
- self.stroke_color = DEFAULTS[:stroke_color]
17
- self.stroke_width = DEFAULTS[:stroke_width]
18
- end
19
- end
20
-
21
- def hidden?
22
- stroke_color == UIColor.clearColor
23
- end
24
-
25
- def toggle
26
- if hidden?
27
- show
28
- else
29
- hide
30
- end
31
- end
32
-
33
- def show
34
- self.stroke_color = @original_color
35
-
36
- setNeedsDisplay
37
- end
38
-
39
- def hide
40
- unless hidden?
41
- @original_color = stroke_color
42
-
43
- self.stroke_color = UIColor.clearColor
44
-
45
- setNeedsDisplay
46
- end
47
- end
48
-
49
- def x_lines=(lines)
50
- self.x_interval = frame.size.width / lines
51
-
52
- setNeedsDisplay
53
- end
54
-
55
- def y_lines=(lines)
56
- self.y_interval = frame.size.height / lines
57
-
58
- setNeedsDisplay
59
- end
60
-
61
- def stroke_width=(width)
62
- @stroke_width = width
63
-
64
- setNeedsDisplay
65
- end
66
-
67
- def stroke_color=(color)
68
- @stroke_color = color
69
-
70
- setNeedsDisplay
71
- end
72
-
73
- def setup_drawing
74
- CGContextSetStrokeColorWithColor(context, stroke_color.CGColor)
75
-
76
- CGContextSetLineWidth(context, stroke_width)
77
- end
78
-
79
- def drawRect(rect)
80
- super
81
-
82
- setup_drawing
83
- draw_vertical_lines
84
- draw_horizontal_lines
85
-
86
- fill_path
87
- end
88
-
89
- def fill_path
90
- CGContextStrokePath(context)
91
- end
92
-
93
- def draw_horizontal_lines
94
- draw_line([0, y_interval], [size.width, y_interval])
95
- draw_line([0, y_interval * 2], [size.width, y_interval * 2])
96
- end
97
-
98
- def draw_vertical_lines
99
- draw_line([x_interval, 0], [x_interval, size.height])
100
- draw_line([x_interval * 2, 0], [x_interval * 2.0, size.height])
101
- end
102
-
103
- def draw_line(start_point, end_point)
104
- CGContextMoveToPoint(context, start_point[0], start_point[1])
105
-
106
- CGContextAddLineToPoint(context, end_point[0], end_point[1])
107
- end
108
-
109
- def context
110
- @_context ||= UIGraphicsGetCurrentContext()
111
- end
112
- end