ruby-opencv 0.0.15 → 0.0.16

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: 40401c95ab8f679c62f524003fe0a0c43abb0681
4
- data.tar.gz: ffe7858c51e1ccb47c416cd465a6a0061a3c8cc6
3
+ metadata.gz: 4167570217e86b8b50a744e19375a4e6691f879a
4
+ data.tar.gz: 3bb849ae998b8330cecfcc29ba8e2cd164b0168d
5
5
  SHA512:
6
- metadata.gz: 4e298023316425072af0c0ed97e681a31b8526cc1014d57ab4cfec3df804195582824b81a435676fc45d479f79d3e6de4c1a87359a6bf2ec74b4be746d7bf7bf
7
- data.tar.gz: aec9e0aa7e67b5f500ca1131b52d8a4de62ca167e535398329eb09c53727e9bc2a916b114f81a93bda0dbc1a5d70e9349eab2d5df70a22d8fa80d7262b5d46fa
6
+ metadata.gz: a5a43d61e47c1364e42b0a33b27b589939caace91b878dcfda4174a02d0be78ac631e39c20e7b2af55766089bb01abd1c8be8a8f701542d36ef3806ddb121fb3
7
+ data.tar.gz: a577c48d4261d033b25fd5e72e1f108db091920604ab95d1bc7482ba129303d2bc6641ca8c5e993fa41e73c6c65588f331001eec1f84aaf5038855e60f8cd536
@@ -27,8 +27,12 @@ rb_class()
27
27
  void
28
28
  cvcapture_free(void *ptr)
29
29
  {
30
- if (ptr)
31
- cvReleaseCapture((CvCapture**)&ptr);
30
+ if (ptr) {
31
+ sCvCapture* scap = (sCvCapture*)ptr;
32
+ if (scap->opened)
33
+ cvReleaseCapture(&scap->ptr);
34
+ delete scap;
35
+ }
32
36
  }
33
37
 
34
38
  /*
@@ -49,6 +53,7 @@ rb_open(int argc, VALUE *argv, VALUE self)
49
53
  VALUE device;
50
54
  rb_scan_args(argc, argv, "01", &device);
51
55
  CvCapture *capture = 0;
56
+ sCvCapture *scap = new sCvCapture();
52
57
  try {
53
58
  switch (TYPE(device)) {
54
59
  case T_STRING:
@@ -74,7 +79,27 @@ rb_open(int argc, VALUE *argv, VALUE self)
74
79
  }
75
80
  if (!capture)
76
81
  rb_raise(rb_eStandardError, "Invalid capture format.");
77
- return Data_Wrap_Struct(rb_klass, 0, cvcapture_free, capture);
82
+ scap->ptr = capture;
83
+ scap->opened = true;
84
+ return Data_Wrap_Struct(rb_klass, 0, cvcapture_free, scap);
85
+ }
86
+
87
+ /*
88
+ * Releases an opened video file or a capturing device
89
+ * @return [boolean] False if the device was already closed
90
+ */
91
+
92
+ VALUE
93
+ rb_close(VALUE self)
94
+ {
95
+ sCvCapture *scap;
96
+ Data_Get_Struct(self, sCvCapture, scap);
97
+ if (scap->opened) {
98
+ scap->opened = false;
99
+ cvReleaseCapture(&scap->ptr);
100
+ return true;
101
+ } else
102
+ return false;
78
103
  }
79
104
 
80
105
  /*
@@ -570,6 +595,7 @@ init_ruby_class()
570
595
  rb_hash_aset(video_interface, ID2SYM(rb_intern("quicktime")), INT2FIX(CV_CAP_QT));
571
596
 
572
597
  rb_define_singleton_method(rb_klass, "open", RUBY_METHOD_FUNC(rb_open), -1);
598
+ rb_define_method(rb_klass, "close", RUBY_METHOD_FUNC(rb_close), 0);
573
599
 
574
600
  rb_define_method(rb_klass, "grab", RUBY_METHOD_FUNC(rb_grab), 0);
575
601
  rb_define_method(rb_klass, "retrieve", RUBY_METHOD_FUNC(rb_retrieve), 0);
@@ -16,6 +16,12 @@
16
16
  #define __NAMESPACE_END_CVCAPTURE }
17
17
 
18
18
  __NAMESPACE_BEGIN_OPENCV
19
+
20
+ typedef struct {
21
+ CvCapture* ptr;
22
+ bool opened;
23
+ } sCvCapture;
24
+
19
25
  __NAMESPACE_BEGIN_CVCAPTURE
20
26
 
21
27
 
@@ -26,6 +32,8 @@ void init_ruby_class();
26
32
  void cvcapture_free(void *ptr);
27
33
  VALUE rb_open(int argc, VALUE *argv, VALUE klass);
28
34
 
35
+ VALUE rb_close(VALUE self);
36
+
29
37
  VALUE rb_grab(VALUE self);
30
38
  VALUE rb_retrieve(VALUE self);
31
39
  VALUE rb_query(VALUE self);
@@ -62,9 +70,11 @@ __NAMESPACE_END_CVCAPTURE
62
70
 
63
71
  inline CvCapture*
64
72
  CVCAPTURE(VALUE object) {
65
- CvCapture *ptr;
66
- Data_Get_Struct(object, CvCapture, ptr);
67
- return ptr;
73
+ sCvCapture *scap;
74
+ Data_Get_Struct(object, sCvCapture, scap);
75
+ if (!scap->opened)
76
+ rb_raise(rb_eIOError, "Resource is not available!");
77
+ return scap->ptr;
68
78
  }
69
79
 
70
80
  __NAMESPACE_END_OPENCV
@@ -1,4 +1,4 @@
1
1
  module OpenCV
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
4
4
 
@@ -1,15 +1,15 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ruby-opencv 0.0.15.20160408012232 ruby lib
2
+ # stub: ruby-opencv 0.0.16.20160417000540 ruby lib
3
3
  # stub: ext/opencv/extconf.rb
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "ruby-opencv".freeze
7
- s.version = "0.0.15.20160408012232"
7
+ s.version = "0.0.16.20160417000540"
8
8
 
9
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
10
10
  s.require_paths = ["lib".freeze]
11
11
  s.authors = ["lsxi".freeze, "ser1zw".freeze, "pcting".freeze]
12
- s.date = "2016-04-07"
12
+ s.date = "2016-04-16"
13
13
  s.description = "ruby-opencv is a wrapper of OpenCV for Ruby. It helps you to write computer vision programs (e.g. detecting faces from pictures) with Ruby.".freeze
14
14
  s.email = ["masakazu.yonekura@gmail.com".freeze, "azariahsawtikes@gmail.com".freeze, "pcting@gmail.com".freeze]
15
15
  s.extensions = ["ext/opencv/extconf.rb".freeze]
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.homepage = "https://github.com/ruby-opencv/ruby-opencv/".freeze
19
19
  s.licenses = ["The BSD License".freeze]
20
20
  s.rdoc_options = ["--main".freeze, "README.md".freeze]
21
- s.rubygems_version = "2.6.2".freeze
21
+ s.rubygems_version = "2.6.3".freeze
22
22
  s.summary = "OpenCV wrapper for Ruby".freeze
23
23
 
24
24
  if s.respond_to? :specification_version then
@@ -50,6 +50,14 @@ class TestCvCapture < OpenCVTestCase
50
50
  # }
51
51
  end
52
52
 
53
+ def test_close
54
+ cap1 = CvCapture.open(AVI_SAMPLE)
55
+ cap1.close
56
+ assert_raise(IOError) do
57
+ cap1.query
58
+ end
59
+ end
60
+
53
61
  def test_grab
54
62
  assert(@cap.grab)
55
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-opencv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - lsxi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-04-07 00:00:00.000000000 Z
13
+ date: 2016-04-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdoc
@@ -346,7 +346,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
346
346
  version: '0'
347
347
  requirements: []
348
348
  rubyforge_project:
349
- rubygems_version: 2.6.2
349
+ rubygems_version: 2.6.3
350
350
  signing_key:
351
351
  specification_version: 4
352
352
  summary: OpenCV wrapper for Ruby