From 26d9a7cd400921b4c2b2bc6ecafd30873d848084 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 10 Jun 2015 13:00:36 +0300 Subject: [PATCH 1/2] Trying to fix flann python wrapper issue --- modules/features2d/src/matchers.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 8d2f69ec8..a37ef0693 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -1022,12 +1022,27 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr& _indexParam void FlannBasedMatcher::add( InputArrayOfArrays _descriptors ) { DescriptorMatcher::add( _descriptors ); - std::vector descriptors; - _descriptors.getUMatVector(descriptors); - - for( size_t i = 0; i < descriptors.size(); i++ ) + if(_descriptors.isUMatVector() || _descriptors.isUMat()) { - addedDescCount += descriptors[i].rows; + std::vector descriptors; + _descriptors.getUMatVector(descriptors); + for( size_t i = 0; i < descriptors.size(); i++ ) + { + addedDescCount += descriptors[i].rows; + } + } + else if(_descriptors.isMatVector() || _descriptors.isMat()) + { + std::vector descriptors; + _descriptors.getMatVector(descriptors); + for( size_t i = 0; i < descriptors.size(); i++ ) + { + addedDescCount += descriptors[i].rows; + } + } + else + { + CV_Assert( _descriptors.isUMat() || _descriptors.isUMatVector() || _descriptors.isMat() || _descriptors.isMatVector()); } } From fef7509eed59567c3e3ac52d5b1efd42ddb3af3e Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 17 Jun 2015 12:07:57 +0300 Subject: [PATCH 2/2] NumpyAllocator: check reference count before actual release, revert flann changes --- modules/features2d/src/matchers.cpp | 25 +++++-------------------- modules/python/src2/cv2.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index a37ef0693..8d2f69ec8 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -1022,27 +1022,12 @@ FlannBasedMatcher::FlannBasedMatcher( const Ptr& _indexParam void FlannBasedMatcher::add( InputArrayOfArrays _descriptors ) { DescriptorMatcher::add( _descriptors ); - if(_descriptors.isUMatVector() || _descriptors.isUMat()) + std::vector descriptors; + _descriptors.getUMatVector(descriptors); + + for( size_t i = 0; i < descriptors.size(); i++ ) { - std::vector descriptors; - _descriptors.getUMatVector(descriptors); - for( size_t i = 0; i < descriptors.size(); i++ ) - { - addedDescCount += descriptors[i].rows; - } - } - else if(_descriptors.isMatVector() || _descriptors.isMat()) - { - std::vector descriptors; - _descriptors.getMatVector(descriptors); - for( size_t i = 0; i < descriptors.size(); i++ ) - { - addedDescCount += descriptors[i].rows; - } - } - else - { - CV_Assert( _descriptors.isUMat() || _descriptors.isUMatVector() || _descriptors.isMat() || _descriptors.isMatVector()); + addedDescCount += descriptors[i].rows; } } diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 974545994..2ffb609ca 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -190,9 +190,13 @@ public: void deallocate(UMatData* u) const { - if(u) + if(!u) + return; + PyEnsureGIL gil; + CV_Assert(u->urefcount >= 0); + CV_Assert(u->refcount >= 0); + if(u->refcount == 0) { - PyEnsureGIL gil; PyObject* o = (PyObject*)u->userdata; Py_XDECREF(o); delete u;