我看了一整天网站上的相关帖子。但似乎这是一个由不同原因引起的普遍错误。所以我还是把我的问题贴在这里。如有任何意见,将不胜感激!!!在
我正试图包装一个c++代码,它有一个h\u特性_功能.cpp只有一个h_f.pyx文件的文件。以下是我的h_f.pyx文件:
from libcpp cimport bool
cdef extern from "h_feature.h" namespace "h2":
cdef cppclass feature:
feature() except +
feature(char* modelDir, bool) except +
bool load_feature_extractor(char* modelDir, bool)
cdef cppclass Image: # this is a struct in .h file, but i write it as class in pyx file here
pass
cdef class PyImage:
cdef Image* image
cdef class PyFeature:
cdef feature* c_feature
def __cinit__(self, bytes modelDir, bint useGPU = 0):
self.c_feature = new feature(modelDir, useGPU)
def Pyload_feature_extractor(self, bytes modelDir, bint useGPU = 0):
return self.c_feature.load_feature_extractor(modelDir, useGPU)
def __dealloc__(self):
del self.c_feature
下面是我的设置.py公司名称:
^{pr2}$以下是编译期间的警告:
^{3}$根据评论,我在下面添加了我的c_feature.h:
namespace h2 {
typedef unsigned char pixel_type;
struct Image;
class feature_impl;
class DllExport feature
{
public:
feature();
feature(const char* modelDir, bool useGPU = false);
~feature();
/*-------------------------------------------------------
Method to load feature extractor
Input: modelDir model directory (...model/)
*/
bool load_feature_extractor(const char* modelDir, bool useGPU = false);
}
struct Image {
Image() { }
Image(const Image& i) : width(i.width), height(i.height), bytes_per_row(i.bytes_per_row), pixels(i.pixels) { }
Image(pixel_type* p, int w, int h, int bpr) : width(w), height(h), bytes_per_row(bpr), pixels(p) { }
int width,height,bytes_per_row;
pixel_type* pixels;
};
}
h_功能.cpp下图:
namespace h2 {
typedef std::mutex Mutex;
// use the Lock primitive to acquire a given mutex for the object's lifetime.
// the mutex is released when the object is destroyed, typically when it goes
// out of scope.
class Lock {
public:
Lock(Mutex& _m) : m(_m) { m.lock(); }
~Lock() { m.unlock(); }
private:
Mutex& m;
// don't allow copying or NULL constructor
Lock(); // unimplemented
Lock(const Lock&); // unimplemented
Lock& operator=(const Lock&); // unimplemented
};
// for now, use a heavyweight mutex to prevent concurrency issues in the API.
// that is, all API calls must acquire the mutex and hold it for the entire call.
static Mutex threadMutex;
class feature_impl
{
// the base class for feature. threadMutex is used in this class. ommitted all implementation of this class.
}
feature::feature() : fi(new feature_impl)
{
}
feature::feature(const char* modelDir, bool useGPU) : fi(new feature_impl)
{
fi->load_feat_extractor(modelDir, useGPU);
}
feature::~feature()
{
if(fi != NULL) delete fi;
}
bool feature::load_feature_extractor(const char* modelDir, bool useGPU)
{
return fi->load_feat_extractor(std::string(modelDir), useGPU);
}
}; // namespace h2
目前没有回答
相关问题 更多 >
编程相关推荐