1010#include < rtabmap/utilite/UConversion.h>
1111#include < rtabmap/utilite/UTimer.h>
1212
13+ #include < pybind11/embed.h>
14+
1315#define NPY_NO_DEPRECATED_API NPY_API_VERSION
1416#include < numpy/arrayobject.h>
1517
@@ -39,7 +41,7 @@ PyMatcher::PyMatcher(
3941 return ;
4042 }
4143
42- lock () ;
44+ pybind11::gil_scoped_acquire acquire ;
4345
4446 std::string matcherPythonDir = UDirectory::getDir (path_);
4547 if (!matcherPythonDir.empty ())
@@ -59,15 +61,13 @@ PyMatcher::PyMatcher(
5961 if (!pModule_)
6062 {
6163 UERROR (" Module \" %s\" could not be imported! (File=\" %s\" )" , scriptName.c_str (), path_.c_str ());
62- UERROR (" %s" , getTraceback ().c_str ());
64+ UERROR (" %s" , getPythonTraceback ().c_str ());
6365 }
64-
65- unlock ();
6666}
6767
6868PyMatcher::~PyMatcher ()
6969{
70- lock () ;
70+ pybind11::gil_scoped_acquire acquire ;
7171 if (pFunc_)
7272 {
7373 Py_DECREF (pFunc_);
@@ -76,7 +76,6 @@ PyMatcher::~PyMatcher()
7676 {
7777 Py_DECREF (pModule_);
7878 }
79- unlock ();
8079}
8180
8281std::vector<cv::DMatch> PyMatcher::match (
@@ -104,7 +103,7 @@ std::vector<cv::DMatch> PyMatcher::match(
104103 imageSize.width >0 && imageSize.height >0 )
105104 {
106105
107- lock () ;
106+ pybind11::gil_scoped_acquire acquire ;
108107
109108 UDEBUG (" matchThreshold=%f, iterations=%d, cuda=%d" , matchThreshold_, iterations_, cuda_?1 :0 );
110109
@@ -120,7 +119,7 @@ std::vector<cv::DMatch> PyMatcher::match(
120119 if (result == NULL )
121120 {
122121 UERROR (" Call to \" init(...)\" in \" %s\" failed!" , path_.c_str ());
123- UERROR (" %s" , getTraceback ().c_str ());
122+ UERROR (" %s" , getPythonTraceback ().c_str ());
124123 return matches;
125124 }
126125 Py_DECREF (result);
@@ -133,7 +132,7 @@ std::vector<cv::DMatch> PyMatcher::match(
133132 else
134133 {
135134 UERROR (" Cannot find method \" match(...)\" in %s" , path_.c_str ());
136- UERROR (" %s" , getTraceback ().c_str ());
135+ UERROR (" %s" , getPythonTraceback ().c_str ());
137136 if (pFunc_)
138137 {
139138 Py_DECREF (pFunc_);
@@ -145,15 +144,15 @@ std::vector<cv::DMatch> PyMatcher::match(
145144 else
146145 {
147146 UERROR (" Cannot call method \" init(...)\" in %s" , path_.c_str ());
148- UERROR (" %s" , getTraceback ().c_str ());
147+ UERROR (" %s" , getPythonTraceback ().c_str ());
149148 return matches;
150149 }
151150 Py_DECREF (pFunc);
152151 }
153152 else
154153 {
155154 UERROR (" Cannot find method \" init(...)\" " );
156- UERROR (" %s" , getTraceback ().c_str ());
155+ UERROR (" %s" , getPythonTraceback ().c_str ());
157156 return matches;
158157 }
159158 UDEBUG (" init time = %fs" , timer.ticks ());
@@ -216,7 +215,7 @@ std::vector<cv::DMatch> PyMatcher::match(
216215 if (pReturn == NULL )
217216 {
218217 UERROR (" Failed to call match() function!" );
219- UERROR (" %s" , getTraceback ().c_str ());
218+ UERROR (" %s" , getPythonTraceback ().c_str ());
220219 }
221220 else
222221 {
@@ -260,7 +259,6 @@ std::vector<cv::DMatch> PyMatcher::match(
260259
261260 UDEBUG (" Fill matches (%d/%d) and cleanup time = %fs" , matches.size (), std::min (descriptorsQuery.rows , descriptorsTrain.rows ), timer.ticks ());
262261 }
263- unlock ();
264262 }
265263 else
266264 {
0 commit comments