2008年2月1日金曜日

Interface python.numarray and c++ using boost.python and cmake

Let us call the following c++ functions from python



#include <boost/python.hpp>
#include <boost/python/numeric.hpp>
using namespace boost::python;

char const* say_yes(){return "YES!!";}


// See if we can invoke array() from C++
object new_array()
{
return numeric::array(make_tuple(
make_tuple(1,2.2,3)
, make_tuple(4,5,6)
, make_tuple(7,8,9)
),'d');
}


// test argument conversion
void take_array(numeric::array x){x[make_tuple(0,0)]= 0.5;}

BOOST_PYTHON_MODULE(libboopy)
{
def("yes", say_yes);
def("new_array", new_array);
def("take_array", take_array);
}



This c++ code can compile

$ cmake .
$ make

with file CMakeLists.txt



INCLUDE_DIRECTORIES( /usr/include/python2.4 )
ADD_LIBRARY(boopy SHARED boopy.cpp )
TARGET_LINK_LIBRARIES(boopy boost_python python2.4 )



Then libboopy.so is genereated. libboopy.so can call from python as the fllowing


def boopy_test():
import sys
import numarray
import libboopy
print libboopy.yes()
x = libboopy.new_array()
 print x
libboopy.take_array(x)
print x
z=numarray.array([[0,1],[1,3]], numarray.Float)
print z
libboopy.take_array(z) # note here
print z

if __name__ == '__main__':
print "running..."
import sys
boopy_test()



output is



YES!!
[[ 1. 2.2 3. ]
[ 4. 5. 6. ]
[ 7. 8. 9. ]]
[[ 0.5 2.2 3. ]
[ 4. 5. 6. ]
[ 7. 8. 9. ]]
[[ 0. 1.]
[ 1. 3.]]
[[ 0.5 1. ]
[ 1. 3. ]]


2008年1月30日水曜日

BIAS - Basic Image AlgorithmS Library on ubuntu

BIAS - Basic Image AlgorithmS Library can be installed by the following simple procedure to ubuntu 7.10 linux
  1. sudo apt-get install g++ checkinstall cmake libglew-dev libglut-dev libmagick++9-dev libcv-dev lapack3-dev libf2c2-dev uuid-dev libxmu-dev libxxf86vm-dev libgsl0-dev
  2. wget http://www.mip.informatik.uni-kiel.de/~wwwadmin/
    Software/Download/BIAS-2.5.0.tar.gz
  3. tar zxf BIAS-2.5.0.tar.gz
  4. cd BIAS-2.5.0
  5. ccmake .
    1. enable use gsl
    2. disaple wxWidgets
    3. [c]onfigre then [g]enerate
    4. close ccmake
  6. make -k
  7. sudo checkinstall (or sudo make install)

maybe apt-get install libwxgtk-dev libwxbase-dev also required

in japanese http://d.hatena.ne.jp/niitsuma/20080107/1201322983