博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python3.6(python-gcc:7.3)-anaconda-写c扩展-undefined symbol:找错误-ubuntu
阅读量:2050 次
发布时间:2019-04-28

本文共 29253 字,大约阅读时间需要 97 分钟。

 

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/# 设置搜索时显示通道地址conda config --set show_channel_urls yes

python setup.py build

python steup.py install --record log.txt

cat log.txt | xargs rm -rf

 

对于python setup.py install安装的包如何卸载

帮助你纪录安装细节方便你卸载python setup.py install --record log这时所有的安装细节都写到 log 里了想要卸载的时候通过以下命令cat log | xagrs rm -rf

快速定位:

echo xxx| c++filt

错误:

ImportError: /home/spple/anaconda3/envs/pytorch1_1_0--py3_6--cuda9_0/lib/python3.6/site-packages/siftgpu-0.0.0-py3.6-linux-x86_64.egg/siftgpu.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2cv7imwriteERKSsRKNS_11_InputArrayERKSt6vectorIiSaIiEE

 

快速定位:

echo xxx| c++filt

echo _ZN2cv7imwriteERKSsRKNS_11_InputArrayERKSt6vectorIiSaIiEE| c++filt

spple@spple:~/CLionProjects/python_asift_gpu/siftgpu_wu$ echo _ZN2cv7imwriteERKSsRKNS_11_InputArrayERKSt6vectorIiSaIiEE| c++filt

cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)

 

 

视频资源:

 

opencv

API:

资料:boost 利用Boost.Python实现Python C/C++混合编程

谷歌:

#include 
#include

 

 

 

如果使用C++

那么:

extern “C"

 

python2和python3不相同,导致我找了很多网上的方法无法实现,这个可以实现

我使用的是setup.py的方式:

from distutils.core import setup, ExtensionMOD = 'Extest'setup(name=MOD, ext_modules=[Extension(MOD, sources=['Extest.c'])])
#include 
#include
#include
#include
#define BUFSIZE 10int fac(int n) { if (n < 2) return 1; return n * fac(n - 1);}static PyObject * Extest_fac(PyObject *self, PyObject *args) { int res;//计算结果值 int num;//参数 PyObject* retval;//返回值 //i表示需要传递进来的参数类型为整型,如果是,就赋值给num,如果不是,返回NULL; res = PyArg_ParseTuple(args, "i", &num); if (!res) { //包装函数返回NULL,就会在Python调用中产生一个TypeError的异常 return NULL; } res = fac(num); //需要把c中计算的结果转成python对象,i代表整数对象类型。 retval = (PyObject *)Py_BuildValue("i", res); return retval;}char *reverse(char *s) { register char t; char *p = s; char *q = (s + (strlen(s) - 1)); while (p < q) { t = *p; *p++ = *q; *q-- = t; } return s;}static PyObject *Extest_reverse(PyObject *self, PyObject *args) { char *orignal; if (!(PyArg_ParseTuple(args, "s", &orignal))) { return NULL; } return (PyObject *)Py_BuildValue("s", reverse(orignal));}static PyObject *Extest_doppel(PyObject *self, PyObject *args) { char *orignal; char *reversed; PyObject * retval; if (!(PyArg_ParseTuple(args, "s", &orignal))) { return NULL; } retval = (PyObject *)Py_BuildValue("ss", orignal, reversed=reverse(strdup(orignal))); free(reversed); return retval;}static PyMethodDefExtestMethods[] = { {"fac", Extest_fac, METH_VARARGS}, {"doppel", Extest_doppel, METH_VARARGS}, {"reverse", Extest_reverse, METH_VARARGS}, {NULL, NULL},};static struct PyModuleDef ExtestModule = { PyModuleDef_HEAD_INIT, "Extest", NULL, -1, ExtestMethods};PyMODINIT_FUNC PyInit_Extest(void){ return PyModule_Create(&ExtestModule);}

 ~/anaconda3/envs/py3_6/bin/python setup.py build

~/anaconda3/envs/py3_6/bin/python setup.py install
~/anaconda3/envs/py3_6/bin/python

import Extest

Extest
Extest.fac(4)
Extest.reverse("pengdonglin")
Extest.doppel("pengdonglin")

参考上一篇文章-如果有opencv操作:

 

ImportError: libopencv_core.so.3.4: cannot open shared object file:

sudo vim /etc/ld.so.conf

添加:

/media/X/NO_1/ubuntu16.04/opencv-3.4.2-build/install/lib

sudo ldconfig

cat /etc/ld.so.confinclude /etc/ld.so.conf.d/*.conf/home/spple/CLionProjects/SIFT-GPU/cmake-build-debug/src/SiftGPU

 

想直接使用PCL:

未成功

from setuptools import setupfrom torch.utils.cpp_extension import CppExtension, BuildExtensionimport ospcl_inc_dir = '/media/spple/新加卷/Dataset/pcl-master/install/include/pcl-1.9'pcl_inc_dir2 = '/usr/include/eigen3'pcl_lib_dir = '/media/spple/新加卷/Dataset/pcl-master/install/lib'#include 
#include
#include
#include
#include
// TicTocif len(pcl_inc_dir) == 0: print("Error: You have to provide an PCL include directory. Edit this file.") exit()if len(pcl_lib_dir) == 0: print("Error: You have to provide an PCL library directory. Edit this file.") exit()setup( name='interactive_icp', ext_modules=[CppExtension( name='interactive_icp', sources=['interactive_icp.cpp'], include_dirs=[pcl_inc_dir, pcl_inc_dir2], library_dirs=[pcl_lib_dir], libraries=['pcl_io','pcl_io_ply','pcl_search','pcl_registration','pcl_visualization','pcl_common','pcl_segmentation'], extra_compile_args=['-fopenmp'] )], cmdclass={'build_ext': BuildExtension})

想直接使用OpenCV和SIFTGPU:

from setuptools import setupfrom torch.utils.cpp_extension import CppExtension, BuildExtensionimport os siftgpu_inc_dir = '/home/spple/CLionProjects/SIFT-GPU/src/SiftGPU'siftgpu_lib_dir = '/home/spple/CLionProjects/SIFT-GPU/cmake-build-debug/src/SiftGPU'opencv_inc_dir = '/media/spple/新加卷1/opencv-3.4.1/install_2/include'opencv_lib_dir = '/media/spple/新加卷1/opencv-3.4.1/install_2/lib'if len(siftgpu_inc_dir) == 0:	print("Error: You have to provide an PCL include directory. Edit this file.")	exit()if len(siftgpu_lib_dir) == 0:	print("Error: You have to provide an PCL library directory. Edit this file.")	exit() setup(	name='siftgpu',	ext_modules=[CppExtension(		name='siftgpu',		sources=['siftgpu.cpp'],		include_dirs=[siftgpu_inc_dir, opencv_inc_dir],		library_dirs=[siftgpu_lib_dir, opencv_lib_dir],		libraries=['siftgpu', 'opencv_core', 'opencv_calib3d'],		extra_compile_args=['-fopenmp']		)],			cmdclass={'build_ext': BuildExtension})

opencv这里一直报错:

 undefined symbol: _ZN2cv6String10deallocateEv

我以为是gcc版本不同(这个也很重要),编译两次opencv和siftgpu。都使用gcc-6

还是有错误,后来发现

系统识别成了我之前安装的Ubuntu默认的opencv的lib库

pkg-config opencv --libs

/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d /usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib /usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core /usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d /usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann /usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu /usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc /usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy /usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml /usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect /usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl /usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo /usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching /usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres /usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts /usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video /usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab

pkg-config opencv --modversion
2.4.9.1
 

opencv_inc_dir = '/usr/include'opencv_lib_dir = '/usr/lib/x86_64-linux-gnu'

放出正确的一版本:

from setuptools import setupfrom torch.utils.cpp_extension import CppExtension, BuildExtensionimport os siftgpu_inc_dir = '/home/spple/CLionProjects/SIFT-GPU/src/SiftGPU'siftgpu_lib_dir = '/home/spple/CLionProjects/SIFT-GPU/cmake-build-debug/src/SiftGPU'# opencv_inc_dir = '/media/spple/新加卷1/opencv-3.4.1/install_4/include'# opencv_lib_dir = '/media/spple/新加卷1/opencv-3.4.1/install_4/lib/'opencv_inc_dir = '/usr/include'opencv_lib_dir = '/usr/lib/x86_64-linux-gnu'if len(siftgpu_inc_dir) == 0:	print("Error: You have to provide an siftgpu include directory. Edit this file.")	exit()if len(siftgpu_lib_dir) == 0:	print("Error: You have to provide an siftgpu library directory. Edit this file.")	exit()if len(opencv_inc_dir) == 0:	print("Error: You have to provide an opencv include directory. Edit this file.")	exit()if len(opencv_lib_dir) == 0:	print("Error: You have to provide an opencv library directory. Edit this file.")	exit() setup(	name='siftgpu',	ext_modules=[CppExtension(		name='siftgpu',		sources=['siftgpu.cpp'],		# include_dirs=[siftgpu_inc_dir],		# library_dirs=[siftgpu_lib_dir],		# libraries=['siftgpu'],		include_dirs=[siftgpu_inc_dir, opencv_inc_dir],		library_dirs=[opencv_lib_dir, siftgpu_lib_dir],		libraries=['siftgpu', 'opencv_core', 'opencv_calib3d', 'opencv_imgproc', 'opencv_highgui', 'opencv_legacy'],		extra_compile_args=['-fopenmp']		)],			cmdclass={'build_ext': BuildExtension})
#include 
#include
#include
#include
#include
#include "SiftGPU.h"#include
#include
#include
#include
using std::vector;using std::iostream;#include
#include
#include
#include
#include
#if !defined(SIFTGPU_STATIC) && !defined(SIFTGPU_DLL_RUNTIME)// SIFTGPU_STATIC comes from compiler#define SIFTGPU_DLL_RUNTIME// Load at runtime if the above macro defined// comment the macro above to use static linking#endif#ifdef SIFTGPU_DLL_RUNTIME #include
#define FREE_MYLIB dlclose #define GET_MYPROC dlsym#endifstatic PyObject * siftgpu_match(PyObject *self, PyObject *args) { PyObject *size; PyArrayObject *image;// if (!PyArg_ParseTuple(args, "O!O!", &PyTuple_Type, &size, &PyArray_Type, &image)) {// std::cout << "111111111" << std::endl;// //包装函数返回NULL,就会在Python调用中产生一个TypeError的异常// return NULL;// } if (!PyArg_ParseTuple(args, "OO", &size, &image)) { //包装函数返回NULL,就会在Python调用中产生一个TypeError的异常 return NULL; } int rows = PyLong_AsLong(PyTuple_GetItem(size ,0)); int cols = PyLong_AsLong(PyTuple_GetItem(size ,1)); //int nchannels = PyLong_AsLong(PyTuple_GetItem(size ,2)); //char my_arr[rows * nchannels * cols]; char my_arr[rows * cols]; // for(size_t length = 0; length<(rows * nchannels * cols); length++){ // my_arr[length] = (*(char *)PyArray_GETPTR1(image, length)); // } for(size_t length = 0; length<(rows * cols); length++){ my_arr[length] = (*(char *)PyArray_GETPTR1(image, length)); } cv::Mat my_img = cv::Mat(cv::Size(cols, rows), CV_8UC1, &my_arr); std::cout << my_img.cols << std::endl; //先别用imwrite。youbug //cv::imwrite("./test.jpg", my_img); PyObject* retval;//返回值 #ifdef SIFTGPU_DLL_RUNTIME void * hsiftgpu = dlopen("libsiftgpu.so", RTLD_LAZY); if(hsiftgpu == NULL) return 0; #ifdef REMOTE_SIFTGPU ComboSiftGPU* (*pCreateRemoteSiftGPU) (int, char*) = NULL; pCreateRemoteSiftGPU = (ComboSiftGPU* (*) (int, char*)) GET_MYPROC(hsiftgpu, "CreateRemoteSiftGPU"); ComboSiftGPU * combo = pCreateRemoteSiftGPU(REMOTE_SERVER_PORT, REMOTE_SERVER); SiftGPU* sift = combo; SiftMatchGPU* matcher = combo; #else SiftGPU* (*pCreateNewSiftGPU)(int) = NULL; SiftMatchGPU* (*pCreateNewSiftMatchGPU)(int) = NULL; pCreateNewSiftGPU = (SiftGPU* (*) (int)) GET_MYPROC(hsiftgpu, "CreateNewSiftGPU"); pCreateNewSiftMatchGPU = (SiftMatchGPU* (*)(int)) GET_MYPROC(hsiftgpu, "CreateNewSiftMatchGPU"); SiftGPU* sift = pCreateNewSiftGPU(1); SiftMatchGPU* matcher = pCreateNewSiftMatchGPU(4096); #endif #elif defined(REMOTE_SIFTGPU) ComboSiftGPU * combo = CreateRemoteSiftGPU(REMOTE_SERVER_PORT, REMOTE_SERVER); SiftGPU* sift = combo; SiftMatchGPU* matcher = combo; #else //this will use overloaded new operators SiftGPU *sift = new SiftGPU; SiftMatchGPU *matcher = new SiftMatchGPU(4096); #endif vector
descriptors1(1), descriptors2(1); vector
keys1(1), keys2(1); int num1 = 0, num2 = 0; //process parameters //The following parameters are default in V340 //-m, up to 2 orientations for each feature (change to single orientation by using -m 1) //-s enable subpixel subscale (disable by using -s 0) char * argv[] = {"-fo", "-1", "-v", "1"};// //char * argv[] = {"-fo", "-1", "-v", "1", "-cuda", "0"}; //-fo -1 staring from -1 octave //-v 1 only print out # feature and overall time //-loweo add a (.5, .5) offset //-tc
set a soft limit to number of detected features //NEW: parameters for GPU-selection //1. CUDA. Use parameter "-cuda", "[device_id]" //2. OpenGL. Use "-Display", "display_name" to select monitor/GPU (XLIB/GLUT) // on windows the display name would be something like \\.\DISPLAY4 // //You use CUDA for nVidia graphic cards by specifying //-cuda : cuda implementation (fastest for smaller images) // CUDA-implementation allows you to create multiple instances for multiple threads // Checkout src\TestWin\MultiThreadSIFT / // Two Important Parameters/// // First, texture reallocation happens when image size increases, and too many // reallocation may lead to allocatoin failure. You should be careful when using // siftgpu on a set of images with VARYING imag sizes. It is recommended that you // preset the allocation size to the largest width and largest height by using function // AllocationPyramid or prameter '-p' (e.g. "-p", "1024x768"). // Second, there is a parameter you may not be aware of: the allowed maximum working // dimension. All the SIFT octaves that needs a larger texture size will be skipped. // The default prameter is 2560 for the unpacked implementation and 3200 for the packed. // Those two default parameter is tuned to for 768MB of graphic memory. You should adjust // it for your own GPU memory. You can also use this to keep/skip the small featuers. // To change this, call function SetMaxDimension or use parameter "-maxd". // // NEW: by default SiftGPU will try to fit the cap of GPU memory, and reduce the working // dimension so as to not allocate too much. This feature can be disabled by -nomc // int argc = sizeof(argv)/sizeof(char*); sift->ParseParam(argc, argv); /// //Only the following parameters can be changed after initialization (by calling ParseParam). //-dw, -ofix, -ofix-not, -fo, -unn, -maxd, -b //to change other parameters at runtime, you need to first unload the dynamically loaded libaray //reload the libarary, then create a new siftgpu instance //Create a context for computation, and SiftGPU will be initialized automatically //The same context can be used by SiftMatchGPU if(sift->CreateContextGL() != SiftGPU::SIFTGPU_FULL_SUPPORTED) return 0; if(sift->RunSIFT("/home/spple/CLionProjects/SIFT-GPU/data/800-1.jpg")) { //Call SaveSIFT to save result to file, the format is the same as Lowe's //sift->SaveSIFT("../data/800./-1.sift"); //Note that saving ASCII format is slow //get feature count num1 = sift->GetFeatureNum(); //allocate memory keys1.resize(num1); descriptors1.resize(128*num1); //reading back feature vectors is faster than writing files //if you dont need keys or descriptors, just put NULLs here sift->GetFeatureVector(&keys1[0], &descriptors1[0]); //this can be used to write your own sift file. } //You can have at most one OpenGL-based SiftGPU (per process). //Normally, you should just create one, and reuse on all images. if(sift->RunSIFT("/home/spple/CLionProjects/SIFT-GPU/data/640-1.jpg")) { num2 = sift->GetFeatureNum(); keys2.resize(num2); descriptors2.resize(128*num2); sift->GetFeatureVector(&keys2[0], &descriptors2[0]); } //Testing code to check how it works when image size varies //sift->RunSIFT("../data/256.jpg");sift->SaveSIFT("../data/256.sift.1"); //sift->RunSIFT("../data/1024.jpg"); //this will result in pyramid reallocation //sift->RunSIFT("../data/256.jpg"); sift->SaveSIFT("../data/256.sift.2"); //two sets of features for 256.jpg may have different order due to implementation //************************************************************************* /compute descriptors for user-specified keypoints (with or without orientations) //Method1, set new keypoints for the image you've just processed with siftgpu //say vector
mykeys; //sift->RunSIFT(mykeys.size(), &mykeys[0]); //sift->RunSIFT(num2, &keys2[0], 1); sift->SaveSIFT("../data/640-1.sift.2"); //sift->RunSIFT(num2, &keys2[0], 0); sift->SaveSIFT("../data/640-1.sift.3"); //Method2, set keypoints for the next coming image //The difference of with method 1 is that method 1 skips gaussian filtering //SiftGPU::SiftKeypoint mykeys[100]; //for(int i = 0; i < 100; ++i){ // mykeys[i].s = 1.0f;mykeys[i].o = 0.0f; // mykeys[i].x = (i%10)*10.0f+50.0f; // mykeys[i].y = (i/10)*10.0f+50.0f; //} //sift->SetKeypointList(100, mykeys, 0); //sift->RunSIFT("../data/800-1.jpg"); sift->SaveSIFT("../data/800-1.sift.2"); //### for comparing with method1: //sift->RunSIFT("../data/800-1.jpg"); //sift->RunSIFT(100, mykeys, 0); sift->SaveSIFT("../data/800-1.sift.3"); //********************************************************************************* //**********************GPU SIFT MATCHING********************************* //**************************select shader language************************* //SiftMatchGPU will use the same shader lanaguage as SiftGPU by default //Before initialization, you can choose between glsl, and CUDA(if compiled). //matcher->SetLanguage(SiftMatchGPU::SIFTMATCH_CUDA); // +i for the (i+1)-th device //Verify current OpenGL Context and initialize the Matcher; //If you don't have an OpenGL Context, call matcher->CreateContextGL instead; matcher->VerifyContextGL(); //must call once //Set descriptors to match, the first argument must be either 0 or 1 //if you want to use more than 4096 or less than 4096 //call matcher->SetMaxSift() to change the limit before calling setdescriptor matcher->SetDescriptors(0, num1, &descriptors1[0]); //image 1 matcher->SetDescriptors(1, num2, &descriptors2[0]); //image 2 //match and get result. int (*match_buf)[2] = new int[num1][2]; //use the default thresholds. Check the declaration in SiftGPU.h int num_match = matcher->GetSiftMatch(num1, match_buf); std::cout << num_match << " sift matches were found;\n"; //enumerate all the feature matches for(int i = 0; i < num_match; ++i) { //How to get the feature matches: //SiftGPU::SiftKeypoint & key1 = keys1[match_buf[i][0]]; //SiftGPU::SiftKeypoint & key2 = keys2[match_buf[i][1]]; //key1 in the first image matches with key2 in the second image } //*****************GPU Guided SIFT MATCHING*************** //example: define a homography, and use default threshold 32 to search in a 64x64 window //float h[3][3] = { {0.8f, 0, 0}, {0, 0.8f, 0}, {0, 0, 1.0f}}; //matcher->SetFeatureLocation(0, &keys1[0]); //SetFeatureLocaiton after SetDescriptors //matcher->SetFeatureLocation(1, &keys2[0]); //num_match = matcher->GetGuidedSiftMatch(num1, match_buf, h, NULL); //std::cout << num_match << " guided sift matches were found;\n"; //if you can want to use a Fundamental matrix, check the function definition // clean up.. delete[] match_buf;#ifdef REMOTE_SIFTGPU delete combo;#else delete sift; delete matcher;#endif#ifdef SIFTGPU_DLL_RUNTIME FREE_MYLIB(hsiftgpu);#endif retval = (PyObject *)Py_BuildValue("i", 1000); return retval;}static PyMethodDefsiftgpuMethods[] = { {"match", siftgpu_match, METH_VARARGS}, {NULL, NULL},};static struct PyModuleDef siftgpuModule = { PyModuleDef_HEAD_INIT, "siftgpu", NULL, -1, siftgpuMethods};PyMODINIT_FUNC PyInit_siftgpu(void){ return PyModule_Create(&siftgpuModule);}

 

img1 = cv.imread(fn1, cv.IMREAD_GRAYSCALE)    img2 = cv.imread(fn2, cv.IMREAD_GRAYSCALE)    testimg = cv.cvtColor(img1,cv.COLOR_GRAY2RGB)    import siftgpu    dims = testimg.shape  # get image shape (h, w, c)    my_image = testimg.ravel()  # flattens 3d array into 1d    X = siftgpu.match(dims, my_image)

 好吧,尴尬了,错误解决。。。。。。。可是这个opencv不是我们想要的opencv怎么办

呃呃呃额额----解决了看最后

cat /etc/ld.so.conf.d/cuda.conf                       x86_64-linux-gnu.conffakeroot-x86_64-linux-gnu.conf  x86_64-linux-gnu_EGL.confi386-linux-gnu.conf             x86_64-linux-gnu_GL.confi386-linux-gnu_GL.conf          zz_i386-biarch-compat.conflibc.conf                       cat /etc/ld.so.conf.d/x86_64-linux-gnu.conf # Multiarch support/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu
cat /etc/ld.so.conf.d/*/usr/local/cuda/lib64/usr/lib/x86_64-linux-gnu/libfakeroot# Multiarch support/lib/i386-linux-gnu/usr/lib/i386-linux-gnu/lib/i686-linux-gnu/usr/lib/i686-linux-gnu/usr/lib/i386-linux-gnu/mesa# libc default configuration/usr/local/lib# Multiarch support/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/mesa-egl/usr/lib/x86_64-linux-gnu/mesa# Legacy biarch compatibility support/lib32/usr/lib32cat /etc/ld.so.conf.d/*.conf/usr/local/cuda/lib64/usr/lib/x86_64-linux-gnu/libfakeroot# Multiarch support/lib/i386-linux-gnu/usr/lib/i386-linux-gnu/lib/i686-linux-gnu/usr/lib/i686-linux-gnu/usr/lib/i386-linux-gnu/mesa# libc default configuration/usr/local/lib# Multiarch support/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/usr/lib/x86_64-linux-gnu/mesa-egl/usr/lib/x86_64-linux-gnu/mesa# Legacy biarch compatibility support/lib32/usr/lib32

sudo ldconfig -v | grep opencv 

/sbin/ldconfig.real: 无法对 /lib/i686-linux-gnu 进行 stat 操作: 没有那个文件或目录/sbin/ldconfig.real: 无法对 /usr/lib/i686-linux-gnu 进行 stat 操作: 没有那个文件或目录/sbin/ldconfig.real: 多次给出路径“/lib/x86_64-linux-gnu”/sbin/ldconfig.real: 多次给出路径“/usr/lib/x86_64-linux-gnu”/sbin/ldconfig.real: /lib/i386-linux-gnu/ld-2.23.so is the dynamic linker, ignoring/sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.23.so is the dynamic linker, ignoring	libopencv_objdetect.so.2.4 -> libopencv_objdetect.so.2.4.9	libopencv_gpu.so.2.4 -> libopencv_gpu.so.2.4.9	libopencv_imgproc.so.2.4 -> libopencv_imgproc.so.2.4.9	libopencv_ocl.so.2.4 -> libopencv_ocl.so.2.4.9	libopencv_legacy.so.2.4 -> libopencv_legacy.so.2.4.9	libopencv_highgui.so.2.4 -> libopencv_highgui.so.2.4.9	libopencv_videostab.so.2.4 -> libopencv_videostab.so.2.4.9	libopencv_calib3d.so.2.4 -> libopencv_calib3d.so.2.4.9	libopencv_core.so.2.4 -> libopencv_core.so.2.4.9	libopencv_flann.so.2.4 -> libopencv_flann.so.2.4.9	libopencv_ml.so.2.4 -> libopencv_ml.so.2.4.9	libopencv_superres.so.2.4 -> libopencv_superres.so.2.4.9	libopencv_video.so.2.4 -> libopencv_video.so.2.4.9	libopencv_stitching.so.2.4 -> libopencv_stitching.so.2.4.9	libopencv_contrib.so.2.4 -> libopencv_contrib.so.2.4.9	libopencv_features2d.so.2.4 -> libopencv_features2d.so.2.4.9	libopencv_ts.so.2.4 -> libopencv_ts.so.2.4.9	libopencv_photo.so.2.4 -> libopencv_photo.so.2.4.9/sbin/ldconfig.real: /lib32/ld-2.23.so is the dynamic linker, ignoring/sbin/ldconfig.real: 无法对 /usr/lib/libopen-rte.so 进行 stat 操作: 没有那个文件或目录/sbin/ldconfig.real: 无法对 /usr/lib/libopen-pal.so 进行 stat 操作: 没有那个文件或目录/sbin/ldconfig.real: 无法对 /usr/lib/libmca_common_sm.so 进行 stat 操作: 没有那个文件或目录/sbin/ldconfig.real: 无法对 /usr/lib/liboshmem.so 进行 stat 操作: 没有那个文件或目录

vim ~/.bashrc 

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64

 

快速定位:

echo xxx| c++filt

错误:

ImportError: /home/spple/anaconda3/envs/pytorch1_1_0--py3_6--cuda9_0/lib/python3.6/site-packages/siftgpu-0.0.0-py3.6-linux-x86_64.egg/siftgpu.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _ZN2cv7imwriteERKSsRKNS_11_InputArrayERKSt6vectorIiSaIiEE

 

快速定位:

echo xxx| c++filt

echo _ZN2cv7imwriteERKSsRKNS_11_InputArrayERKSt6vectorIiSaIiEE| c++filt

spple@spple:~/CLionProjects/python_asift_gpu/siftgpu_wu$ echo _ZN2cv7imwriteERKSsRKNS_11_InputArrayERKSt6vectorIiSaIiEE| c++filt

cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)
 

还是没法解决,imwrite一直出错,

到这里其实已经解决了问题,那么就是自带的opencv2.4.9,缺少imwrite的问题

但是现在总是使用默认,无法切换

那么我们这么改:::::

 

Find the folder containing the shared library libopencv_core.so.3.2 using the following command line.sudo find / -name "libopencv_core.so.3.2*"Then I got the result: /usr/local/lib/libopencv_core.so.3.2.2. Create a file called /etc/ld.so.conf.d/opencv.conf and write to it the path to the folder where the binary is stored.For example, I wrote /usr/local/lib/ to my opencv.conf file.3. Run the command line as follows.sudo ldconfig -vTry to run the test binary again.

sudo vim /etc/ld.so.conf.d/opencv.conf

/media/spple/新加卷1/opencv-3.4.1/install_4/lib

sudo ldconfig -v

看来sudo vim /etc/ld.so.conf 的优先级不高,必须通过sudo vim /etc/ld.so.conf.d/opencv.conf去改了

我们把/etc/ld.so.conf的删除了就行

 

这下可以了,但是记住

还是不能使用imwrite

有bug,哈哈哈(我真的放弃了)

改了一些东西为了验证是3.4.1

#include "opencv2/opencv.hpp"#include "opencv2/core/core.hpp"#include "opencv2/imgcodecs/imgcodecs.hpp"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/calib3d/calib3d.hpp"#include "opencv2/highgui/highgui.hpp"#include "opencv2/cudawarping.hpp"#include "opencv2/cudafeatures2d.hpp"using namespace cv;	    int flag = cuda::getCudaEnabledDeviceCount();	if (flag != 0) { cuda::setDevice(0); }	    std::cout << flag << " AAA\n";    PyObject *size;    PyArrayObject *image;//    if (!PyArg_ParseTuple(args, "O!O!", &PyTuple_Type, &size, &PyArray_Type, &image)) {//        std::cout << "111111111" << std::endl;//        //包装函数返回NULL,就会在Python调用中产生一个TypeError的异常//        return NULL;//    }    if (!PyArg_ParseTuple(args, "OO", &size, &image)) {        //包装函数返回NULL,就会在Python调用中产生一个TypeError的异常        return NULL;    }    int rows = PyLong_AsLong(PyTuple_GetItem(size ,0));    int cols = PyLong_AsLong(PyTuple_GetItem(size ,1));    //int nchannels = PyLong_AsLong(PyTuple_GetItem(size ,2));    //char my_arr[rows * nchannels * cols];    char my_arr[rows * cols];    //    for(size_t length = 0; length<(rows * nchannels * cols); length++){    //        my_arr[length] = (*(char *)PyArray_GETPTR1(image, length));    //    }    for(size_t length = 0; length<(rows * cols); length++){        my_arr[length] = (*(char *)PyArray_GETPTR1(image, length));    }    cv::Mat my_img = cv::Mat(cv::Size(cols, rows), CV_8UC1, &my_arr);    std::cout << my_img.cols << std::endl;	std::vector
kp1, kp2; Mat d1, d2; std::vector
matches_all, matches_gms; //该超参数可以修改,但是至少保证50000以上 Ptr
orb = ORB::create(100000); orb->setFastThreshold(0); orb->detectAndCompute(my_img, Mat(), kp1, d1); orb->detectAndCompute(my_img, Mat(), kp2, d2); std::cout << "Get total " << kp1.size() << " kp1." << std::endl; std::cout << "Get total " << kp2.size() << " kp2." << std::endl; std::cout << "CV_VERSION " << CV_VERSION << std::endl;
from setuptools import setupfrom torch.utils.cpp_extension import CppExtension, BuildExtensionimport ossiftgpu_inc_dir = '/home/spple/CLionProjects/SIFT-GPU/src/SiftGPU'siftgpu_lib_dir = '/home/spple/CLionProjects/SIFT-GPU/cmake-build-debug/src/SiftGPU'opencv_inc_dir = '/media/spple/新加卷1/opencv-3.4.1/install_4/include'opencv_lib_dir = '/media/spple/新加卷1/opencv-3.4.1/install_4/lib'# opencv_inc_dir = '/usr/include'# opencv_lib_dir = '/usr/lib/x86_64-linux-gnu'if len(siftgpu_inc_dir) == 0:	print("Error: You have to provide an siftgpu include directory. Edit this file.")	exit()if len(siftgpu_lib_dir) == 0:	print("Error: You have to provide an siftgpu library directory. Edit this file.")	exit()if len(opencv_inc_dir) == 0:	print("Error: You have to provide an opencv include directory. Edit this file.")	exit()if len(opencv_lib_dir) == 0:	print("Error: You have to provide an opencv library directory. Edit this file.")	exit() setup(	name='siftgpu',	ext_modules=[CppExtension(		name='siftgpu',		sources=['siftgpu.cpp'],		# include_dirs=[siftgpu_inc_dir],		# library_dirs=[siftgpu_lib_dir],		# libraries=['siftgpu'],		include_dirs=[siftgpu_inc_dir, opencv_inc_dir],		library_dirs=[opencv_lib_dir, siftgpu_lib_dir],		libraries=['siftgpu', 'opencv_core', 'opencv_calib3d', 'opencv_imgproc', 'opencv_highgui', 'opencv_cudawarping','opencv_cudafeatures2d'],		extra_compile_args=['-fopenmp']		)],			cmdclass={'build_ext': BuildExtension})

 

输出信息,可以看到,opencv的版本已经是3.4.1了 

all time: ...using sift0 AAA2064Get total 99934 kp1.Get total 99934 kp2.CV_VERSION 3.4.1[SiftGPU Language]:	GLSL[GPU VENDOR]:	Intel Open Source Technology CenterTEXTURE:	16384Image size :	800x600Image loaded :	/home/spple/CLionProjects/SIFT-GPU/data/800-1.jpg#Features:	3359#Features MO:	3927[RUN SIFT]:	0.132Image size :	640x480Image loaded :	/home/spple/CLionProjects/SIFT-GPU/data/640-1.jpg#Features:	2377#Features MO:	2784[RUN SIFT]:	0.046[SiftMatchGPU]: GLSL2276 sift matches were found;ASIFT yangninghua;

python3--c扩展传输list:

static PyObject * PCLICP(PyObject *self, PyObject *args) {    PyObject *image1, *image2;    PyObject *pList;    if (!PyArg_ParseTuple(args, "OOO!", &image1, &image2, &PyList_Type, &pList)) {        PyErr_SetString(PyExc_TypeError, "parameter3 must be a list.");        return NULL;    }    std::vector
namelist; PyObject *pItem; Py_ssize_t n; n = PyList_Size(pList); for (int i=0; i
testGray = cv.imread("Bit.png", cv.IMREAD_GRAYSCALE)    testDep = cv.imread("Map.tif", -1)    import PCLICP    sssssssss = ["aaa", "bbbbbbbbbbbbbb", "vvvvvvvvvvvvvvvvvv"]    XXX = PCLICP.ICP(testGray, testDep, sssssssss)    print(XXX)
static PyObject * PCLICP(PyObject *self, PyObject *args) {    PyObject *image1, *image2;    PyObject *pList1;    PyObject *pList2;    PyObject *pList3;    if (!PyArg_ParseTuple(args, "OOO!O!O!", &image1, &image2, &PyList_Type, &pList1,&PyList_Type, &pList2,&PyList_Type, &pList3)) {        PyErr_SetString(PyExc_TypeError, "parameter3 must be a list.");        return NULL;    }    std::vector
namelist; PyObject *pItem1; Py_ssize_t n1; n1 = PyList_Size(pList1); for (int i=0; i
testGray = cv.imread("Bit.png", cv.IMREAD_GRAYSCALE)    testDep = cv.imread("Map.tif", -1)    import PCLICP    sssssssss = ["aaa", "bbbbbbbbbbbbbb", "vvvvvvvvvvvvvvvvvv"]    XXX = PCLICP.ICP(testGray, testDep, sssssssss, sssssssss, sssssssss)    print(XXX)

转载地址:http://legof.baihongyu.com/

你可能感兴趣的文章
Intellij IDEA使用(五)—— Intellij IDEA在使用中的一些其他常用功能或常用配置收集
查看>>
Intellij IDEA使用(六)—— 使用Intellij IDEA创建Java项目并配置jar包
查看>>
Eclipse使用(十)—— 使用Eclipse创建简单的Maven Java项目
查看>>
Eclipse使用(十一)—— 使用Eclipse创建简单的Maven JavaWeb项目
查看>>
Intellij IDEA使用(十三)—— 在Intellij IDEA中配置Maven
查看>>
面试题 —— 关于main方法的十个面试题
查看>>
集成测试(一)—— 使用PHP页面请求Spring项目的Java接口数据
查看>>
使用Maven构建的简单的单模块SSM项目
查看>>
Intellij IDEA使用(十四)—— 在IDEA中创建包(package)的问题
查看>>
Redis学习笔记(四)—— redis的常用命令和五大数据类型的简单使用
查看>>
Kubelet 中的 “PLEG is not healthy” 到底是个什么鬼?
查看>>
超详细的网络抓包神器 Tcpdump 使用指南
查看>>
从 Kubernetes 资源控制到开放应用模型,控制器的进化之旅
查看>>
从此以后运维与开发过上了没羞没臊的性福生活
查看>>
教你如何优雅地魔改 Grafana 主题,太实用了!
查看>>
让我们来看看回到单体的 Istio 到底该怎么部署
查看>>
超详细的网络抓包神器 tcpdump 使用指南
查看>>
iTerm2 都不会用,还敢自称老司机?(上)
查看>>
两个奇技淫巧,将 Docker 镜像体积减小 99%
查看>>
Istio 1.5 部署指南修正版
查看>>