Skip to content

Instantly share code, notes, and snippets.

@jayrambhia
Created June 27, 2012 10:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jayrambhia/3003247 to your computer and use it in GitHub Desktop.
Save jayrambhia/3003247 to your computer and use it in GitHub Desktop.
Comparison between run time of SimpleCV, OpenCV(python) and OpenCV(C++) Boost::Python bindings.
PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
# compile mesh classes
TARGET = opencvtest
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -lboost_python -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so `pkg-config --libs opencv` `pkg-config --cflags opencv`
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp
import time
def foo():
image = "/home/jay/Pictures/python.jpg"
t = time.time()
from cv2.cv import LoadImage
img = LoadImage(image)
t1 = time.time()
from SimpleCV import Image
img1 = Image(image)
t2 = time.time()
from opencvtest import load
img3 = load(image)
t3 = time.time()
print t1-t
print t2-t1
print t3-t2
foo()
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int load(string filename)
{
Mat img = imread(filename,CV_LOAD_IMAGE_COLOR);
//imshow("opencvtest",img);
//waitKey(0);
return 1;
}
//#include<boost/python/detail/wrap_python.hpp>
#include<boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(opencvtest)
{
def("load",load);
}
echo "Compiling"
make
echo "Please change the image filename in opencv_load.py"
python opencv_load.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment