mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fix GC guard functions for FaceRecognition
This commit is contained in:
parent
5626b55cc5
commit
cf9b314b92
4 changed files with 7 additions and 22 deletions
|
@ -17,7 +17,6 @@ __NAMESPACE_BEGIN_OPENCV
|
|||
__NAMESPACE_BEGIN_EIGENFACES
|
||||
|
||||
VALUE rb_klass;
|
||||
std::map<long, cv::Ptr<cv::FaceRecognizer> > ptr_guard_map;
|
||||
|
||||
VALUE
|
||||
rb_class()
|
||||
|
@ -25,19 +24,6 @@ rb_class()
|
|||
return rb_klass;
|
||||
}
|
||||
|
||||
void
|
||||
release_facerecognizer(void *ptr) {
|
||||
long key = (long)ptr;
|
||||
ptr_guard_map[key].release();
|
||||
ptr_guard_map.erase(key);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_allocate(VALUE klass)
|
||||
{
|
||||
return Data_Wrap_Struct(klass, 0, release_facerecognizer, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* EigenFaces.new(num_components=0, threshold=DBL_MAX)
|
||||
|
@ -55,8 +41,7 @@ rb_initialize(int argc, VALUE argv[], VALUE self)
|
|||
cv::Ptr<cv::FaceRecognizer> ptr = cv::createEigenFaceRecognizer(num_components, threshold);
|
||||
DATA_PTR(self) = ptr;
|
||||
|
||||
long key = (long)(DATA_PTR(self));
|
||||
ptr_guard_map[key] = ptr; // To avoid cv::Ptr's GC
|
||||
cFaceRecognizer::guard_facerecognizer(DATA_PTR(self), ptr);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -73,7 +58,7 @@ define_ruby_class()
|
|||
*/
|
||||
VALUE opencv = rb_module_opencv();
|
||||
rb_klass = rb_define_class_under(opencv, "EigenFaces", cFaceRecognizer::rb_class());
|
||||
rb_define_alloc_func(rb_klass, rb_allocate);
|
||||
rb_define_alloc_func(rb_klass, cFaceRecognizer::allocate_facerecognizer);
|
||||
rb_define_private_method(rb_klass, "initialize", RUBY_METHOD_FUNC(rb_initialize), -1);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ __NAMESPACE_BEGIN_EIGENFACES
|
|||
VALUE rb_class();
|
||||
|
||||
void define_ruby_class();
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE argv[], VALUE self);
|
||||
|
||||
__NAMESPACE_END_EIGENFACES
|
||||
|
|
|
@ -18,15 +18,17 @@ __NAMESPACE_BEGIN_FACERECOGNIZER
|
|||
|
||||
VALUE rb_klass;
|
||||
|
||||
std::map<long, cv::Ptr<cv::FaceRecognizer> > ptr_guard_map;
|
||||
std::map< long, cv::Ptr<cv::FaceRecognizer> > ptr_guard_map;
|
||||
|
||||
void
|
||||
guard_facerecognizer(void* data_ptr, cv::Ptr<cv::FaceRecognizer> ptr) {
|
||||
guard_facerecognizer(void* data_ptr, cv::Ptr<cv::FaceRecognizer> ptr)
|
||||
{
|
||||
ptr_guard_map[(long)data_ptr] = ptr;
|
||||
}
|
||||
|
||||
void
|
||||
release_facerecognizer(void *ptr) {
|
||||
release_facerecognizer(void *ptr)
|
||||
{
|
||||
long key = (long)ptr;
|
||||
ptr_guard_map[key].release();
|
||||
ptr_guard_map.erase(key);
|
||||
|
|
|
@ -21,7 +21,6 @@ __NAMESPACE_BEGIN_FISHERFACES
|
|||
VALUE rb_class();
|
||||
|
||||
void define_ruby_class();
|
||||
VALUE rb_allocate(VALUE klass);
|
||||
VALUE rb_initialize(int argc, VALUE argv[], VALUE self);
|
||||
|
||||
__NAMESPACE_END_FISHERFACES
|
||||
|
|
Loading…
Add table
Reference in a new issue