gpt4 book ai didi

c++ - 使用 boost.python 导入带有 opencv 调用的方法但由于编译后未找到符号而失败

转载 作者:太空宇宙 更新时间:2023-11-04 14:27:40 26 4
gpt4 key购买 nike

所以我现在没有代码,因为我不在家...但是我在 C++ 中使用了 python 的 boost 库来允许 python 访问一个名为 loadImageIntoMainWindow(string filepath) 的函数

在 C++ 源代码中,该方法调用在文件顶部导入的 opencv 方法,我将 opencv 包含在我的 Jamroot 文件中,并且还找到了一种在命令行上手动编译和链接的方法...当我运行我的 python 文件时,它提示说找不到第一次函数调用 opencv 方法的符号...

我一回到家就会更新 C++、命令行编译行、Jamroot 和 python 文件

这是 Jamroot:

# Copyright David Abrahams 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

using python ;
lib libboost_python : : <name>boost_python-mt-py26 ;
# Specify the path to the Boost project. If you move this project,
# adjust this path to refer to the Boost root directory.
use-project boost
: ./ ;

# Set up the project-wide requirements that everything uses the
# boost_python library from the project whose global ID is
# /boost/python.

project
: requirements
<search>/usr
<library>libboost_python
<include>/usr/include/opencv ;
# Declare the three extension modules. You can specify multiple
# source files after the colon separated by spaces.
python-extension uTrackSpheresForPyInterface : uTrackSpheresForPyInterface.cpp ;

# A little "rule" (function) to clean up the syntax of declaring tests
# of these extension modules.
local rule run-test ( test-name : sources + )
{
import testing ;
testing.make-test run-pyd : $(sources) : : $(test-name) ;
}

# Declare test targets

在我运行 bjam --preserve-test-targets 之后

g++ -c -g -Wall -fPIC -pipe -DBOOST_PYTHON_MAX_ARITY=20 -I.  -I/usr/include/opencv/ - /usr/include/python2.6 `pkg-config --libs opencv` uTrackSpheresForPyInterface.cpp
g++ -shared -o uTrackSpheresForPyInterface.so uTrackSpheresForPyInterface.o -L/usr/lib - python2.6 -lboost_python-mt-py26

我明白了:

nathan@innovation:~/Research RIT/openCv$ python uTrackSpheres.py
Traceback (most recent call last):
File "uTrackSpheres.py", line 18, in <module>
import uTrackSpheresForPyInterface
ImportError: /home/nathan/Research RIT/openCv/uTrackSpheresForPyInterface.so: undefined symbol: cvCvtColor
nathan@innovation:~/Research RIT/openCv$

在 cpp 文件中我做的比这多一点:

#include <iostream>
using namespace std;
#ifdef _CH_
#pragma package <opencv>
#endif

#ifndef _EiC
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#endif

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>


int loadImageIntoMainWindow(string imgPath) {

if( (imgLoaded = cvLoadImage(imgPath.c_str(),1)) == 0 )
return 0;
imgMain = cvCreateImage( cvSize(imgLoaded->width, imgLoaded->height), 8, 1 );
cvCvtColor( imgLoaded, imgMain, CV_BGR2GRAY );

cvNamedWindow( charCurrentFilename,CV_WINDOW_AUTOSIZE);
cvSetMouseCallback(charCurrentFilename, on_mouse_imgMain, 0 );
cvShowImage(charCurrentFilename, imgMain);

return 1;
}

BOOST_PYTHON_MODULE(uTrackSpheresForPyInterface)
{
using namespace boost::python;
def("loadImageIntoMainWindow", loadImageIntoMainWindow);
}

最佳答案

添加行(根据需要编辑 /your/lib/path...):

lib cvlib : : <name>cv <search>/your/lib/path/lib ;
lib cxcorelib : : <name>cxcore <search>/your/lib/path/lib ;

到你的 Jamfile,并编辑

python-extension uTrackSpheresForPyInterface : uTrackSpheresForPyInterface.cpp ;

这样写:

python-extension uTrackSpheresForPyInterface :
uTrackSpheresForPyInterface.cpp
cvlib
cxcorelib ;

关于c++ - 使用 boost.python 导入带有 opencv 调用的方法但由于编译后未找到符号而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2502921/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com