So I don't have the code right now, as I am not home... but i used the boost library for python in C++ to allow python to access a function called something like loadImageIntoMainWindow(string filepath)
in the C++ source code the method calls opencv methods that are imported at the top of the file, I included opencv in my Jamroot file, and also found a way to compile and link manually on the command line... in either case when I run my python file it complains that the symbols aren't found for the first function call to an opencv method...
I will update as soon as I get home with the C++, the command line compilation lines, the Jamroot, and the python files
here is the 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
after I run bjam --preserve-test-targets
or
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
I get this:
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$
and in the cpp file I'm doing a litte more than this:
#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);
}