Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in compiling np_opencv_converter #1

Open
armandok opened this issue Dec 6, 2020 · 5 comments
Open

Error in compiling np_opencv_converter #1

armandok opened this issue Dec 6, 2020 · 5 comments

Comments

@armandok
Copy link

armandok commented Dec 6, 2020

When compiling the wrapper, I get this error:

Scanning dependencies of target np_opencv_converter
[ 20%] Building CXX object CMakeFiles/np_opencv_converter.dir/lib/conversion.cpp.o
In file included from /projectnb/semslam/armandok/.conda/envs/pyslamu/lib/python3.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1822:0,
from /projectnb/semslam/armandok/.conda/envs/pyslamu/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.h:10,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:4:
/projectnb/semslam/armandok/.conda/envs/pyslamu/lib/python3.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^~~~~~~
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp: In function 'int init()':
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:12:5: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
import_array();
^~~~~~~~~~~~
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp: In member function 'cv::UMatData* NumpyAllocator::allocate(int, const int*, int, void*, size_t*, int, cv::UMatUsageFlags) const':
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:99:92: error: invalid conversion from 'int' to 'cv::AccessFlag' [-fpermissive]
return stdAllocator->allocate(dims0, sizes, type, data, step, flags, usageFlags);
^
In file included from /share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/core.hpp:59:0,
from /share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/opencv.hpp:52,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.h:8,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:4:
/share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/core/mat.hpp:475:23: note: initializing argument 6 of 'virtual cv::UMatData* cv::MatAllocator::allocate(int, const int*, int, void*, size_t*, cv::AccessFlag, cv::UMatUsageFlags) const'
virtual UMatData* allocate(int dims, const int* sizes, int type,
^~~~~~~~
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp: In member function 'bool NumpyAllocator::allocate(cv::UMatData*, int, cv::UMatUsageFlags) const':
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:124:59: error: invalid conversion from 'int' to 'cv::AccessFlag' [-fpermissive]
return stdAllocator->allocate(u, accessFlags, usageFlags);
^
In file included from /share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/core.hpp:59:0,
from /share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/opencv.hpp:52,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.h:8,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:4:
/share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/core/mat.hpp:477:18: note: initializing argument 2 of 'virtual bool cv::MatAllocator::allocate(cv::UMatData*, cv::AccessFlag, cv::UMatUsageFlags) const'
virtual bool allocate(UMatData* data, AccessFlag accessflags, UMatUsageFlags usageFlags) const = 0;
^~~~~~~~
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp: At global scope:
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:194:16: error: cannot declare variable 'g_numpyAllocator' to be of abstract type 'NumpyAllocator'
NumpyAllocator g_numpyAllocator;
^~~~~~~~~~~~~~~~
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:73:7: note: because the following virtual functions are pure within 'NumpyAllocator':
class NumpyAllocator : public MatAllocator
^~~~~~~~~~~~~~
In file included from /share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/core.hpp:59:0,
from /share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/opencv.hpp:52,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.h:8,
from /usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:4:
/share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/core/mat.hpp:475:23: note: virtual cv::UMatData* cv::MatAllocator::allocate(int, const int*, int, void*, size_t*, cv::AccessFlag, cv::UMatUsageFlags) const
virtual UMatData* allocate(int dims, const int* sizes, int type,
^~~~~~~~
/share/pkg.7/opencv/4.5.0/install/include/opencv4/opencv2/core/mat.hpp:477:18: note: virtual bool cv::MatAllocator::allocate(cv::UMatData*, cv::AccessFlag, cv::UMatUsageFlags) const
virtual bool allocate(UMatData* data, AccessFlag accessflags, UMatUsageFlags usageFlags) const = 0;
^~~~~~~~
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp: In member function 'int NDArrayConverter::init()':
/usr3/graduate/armandok/pyslamu/pyfbow/src/lib/conversion.cpp:200:5: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
import_array();
^~~~~~~~~~~~
make[2]: *** [CMakeFiles/np_opencv_converter.dir/lib/conversion.cpp.o] Error 1
make[1]: *** [CMakeFiles/np_opencv_converter.dir/all] Error 2
make: *** [all] Error 2

@vik748
Copy link
Owner

vik748 commented Dec 7, 2020

This is not working code yet, I haven't had the time to get all the pieces working. Having said that it should still be able to compile. Follow the steps in .travis.yml to ensure you have everything setup correctly.

@rener2020
Copy link

many bugs here

if u ONLY want to solve this bug just rewrite some codes in src/lib/conversion.cpp

good luck

#if OPENCV_3
class NumpyAllocator : public MatAllocator
{
public:
NumpyAllocator() { stdAllocator = Mat::getStdAllocator(); }
~NumpyAllocator() {}

UMatData* allocate(PyObject* o, int dims, const int* sizes, int type, size_t* step) const
{
    UMatData* u = new UMatData(this);
    u->data = u->origdata = (uchar*)PyArray_DATA((PyArrayObject*) o);
    npy_intp* _strides = PyArray_STRIDES((PyArrayObject*) o);
    for( int i = 0; i < dims - 1; i++ )
        step[i] = (size_t)_strides[i];
    step[dims-1] = CV_ELEM_SIZE(type);
    u->size = sizes[0]*step[0];
    u->userdata = o;
    return u;
}

UMatData *allocate(int dims, const int *sizes, int type, void *data, size_t *step, AccessFlag flags, UMatUsageFlags usageFlags) const
{
	USAGE_DEFAULT;
    if( data != 0 )
    {
        CV_Error(Error::StsAssert, "The data should normally be NULL!");
        // probably this is safe to do in such extreme case
        return stdAllocator->allocate(dims, sizes, type, data, step, flags, usageFlags);
    }
    PyEnsureGIL gil;

    int depth = CV_MAT_DEPTH(type);
    int cn = CV_MAT_CN(type);
    const int f = (int)(sizeof(size_t)/8);
    int typenum = depth == CV_8U ? NPY_UBYTE : depth == CV_8S ? NPY_BYTE :
    depth == CV_16U ? NPY_USHORT : depth == CV_16S ? NPY_SHORT :
    depth == CV_32S ? NPY_INT : depth == CV_32F ? NPY_FLOAT :
    depth == CV_64F ? NPY_DOUBLE : f*NPY_ULONGLONG + (f^1)*NPY_UINT;
    int i = dims;
    cv::AutoBuffer<npy_intp> _sizes(dims + 1);
    for( i = 0; i < dims; i++ )
        _sizes[i] = sizes[i];
    if( cn > 1 )
        _sizes[dims++] = cn;
    PyObject* o = PyArray_SimpleNew(dims, _sizes, typenum);
    if(!o)
        CV_Error_(Error::StsError, ("The numpy array of typenum=%d, ndims=%d can not be created", typenum, dims));
    return allocate(o, dims, sizes, type, step);
}

bool allocate(UMatData* data, AccessFlag accessflags, UMatUsageFlags usageFlags) const
{
	return stdAllocator->allocate(data, accessflags, usageFlags);
}

void deallocate(UMatData* data) const
{
    if(data)
    {
        PyEnsureGIL gil;
        PyObject* o = (PyObject*)data->userdata;
        Py_XDECREF(o);
        delete data;
    }
}

const MatAllocator* stdAllocator;

};

@iljastas
Copy link

many bugs here

if u ONLY want to solve this bug just rewrite some codes in src/lib/conversion.cpp

good luck

#if OPENCV_3 class NumpyAllocator : public MatAllocator { public: NumpyAllocator() { stdAllocator = Mat::getStdAllocator(); } ~NumpyAllocator() {}

UMatData* allocate(PyObject* o, int dims, const int* sizes, int type, size_t* step) const
{
    UMatData* u = new UMatData(this);
    u->data = u->origdata = (uchar*)PyArray_DATA((PyArrayObject*) o);
    npy_intp* _strides = PyArray_STRIDES((PyArrayObject*) o);
    for( int i = 0; i < dims - 1; i++ )
        step[i] = (size_t)_strides[i];
    step[dims-1] = CV_ELEM_SIZE(type);
    u->size = sizes[0]*step[0];
    u->userdata = o;
    return u;
}

UMatData *allocate(int dims, const int *sizes, int type, void *data, size_t *step, AccessFlag flags, UMatUsageFlags usageFlags) const
{
	USAGE_DEFAULT;
    if( data != 0 )
    {
        CV_Error(Error::StsAssert, "The data should normally be NULL!");
        // probably this is safe to do in such extreme case
        return stdAllocator->allocate(dims, sizes, type, data, step, flags, usageFlags);
    }
    PyEnsureGIL gil;

    int depth = CV_MAT_DEPTH(type);
    int cn = CV_MAT_CN(type);
    const int f = (int)(sizeof(size_t)/8);
    int typenum = depth == CV_8U ? NPY_UBYTE : depth == CV_8S ? NPY_BYTE :
    depth == CV_16U ? NPY_USHORT : depth == CV_16S ? NPY_SHORT :
    depth == CV_32S ? NPY_INT : depth == CV_32F ? NPY_FLOAT :
    depth == CV_64F ? NPY_DOUBLE : f*NPY_ULONGLONG + (f^1)*NPY_UINT;
    int i = dims;
    cv::AutoBuffer<npy_intp> _sizes(dims + 1);
    for( i = 0; i < dims; i++ )
        _sizes[i] = sizes[i];
    if( cn > 1 )
        _sizes[dims++] = cn;
    PyObject* o = PyArray_SimpleNew(dims, _sizes, typenum);
    if(!o)
        CV_Error_(Error::StsError, ("The numpy array of typenum=%d, ndims=%d can not be created", typenum, dims));
    return allocate(o, dims, sizes, type, step);
}

bool allocate(UMatData* data, AccessFlag accessflags, UMatUsageFlags usageFlags) const
{
	return stdAllocator->allocate(data, accessflags, usageFlags);
}

void deallocate(UMatData* data) const
{
    if(data)
    {
        PyEnsureGIL gil;
        PyObject* o = (PyObject*)data->userdata;
        Py_XDECREF(o);
        delete data;
    }
}

const MatAllocator* stdAllocator;

};

Hi rener2020,

where is the file src/lib/conversion.cpp?
Is this a file in openCV?

@rener2020
Copy link

no
in this project

@rener2020
Copy link

pyfbow/src/lib/conversion.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants