How do I integrate C++ library with Python? - c++

I want to integrate Berkelium (www.berkelium.org) with Blender to render browser in Blender scenes. Blender allows you to write python add-ons (http://wiki.blender.org/index.php/Doc:2.6/Manual/Extensions). I know only a little bit python what would be a good starting point for me? How do I call Berkelium methods in my python add-ons? Here is the link for Berkelium builds: https://github.com/sirikata/berkelium/downloads

It seems this is covered by the python docs. Perhaps this will be of interest.

Related

OpenFrameworks + Python

Is there any bindings to execute functions in OpenFrameworks (C++ toolkit) using Python 2.7? Or any alternative for this available?
Experiments on python 2.6 has been made, see #Babu answer. But not updates..
I don't know a lot about it but you can try to have a look at SIP (even i think it is an hard task to let it work completely):
SIP is a tool for quickly writing Python modules that interface with
C++ and C libraries. Its home page is at
http://riverbankcomputing.co.uk/software/sip/intro. It was written by
Phil Thompson who is still actively maintaining it.
I don't think there is a binding available for Python 2.7. For 2.6, it's available here,
For Windows: http://forum.openframeworks.cc/index.php/topic,3031.0.html
For OSX: http://forum.openframeworks.cc/index.php/topic,2763.0.html
I am also very interested by Python bindings, but it seems quite hard to implement...
That's why things like cppyy could be really handy! I didn't have a close look yet, but it's definitely on my todo list.
Interesting thing to checkout when working with OpenFrameWorks + Python is using BeautifulSoup to parse HTML and use that in OPenFrameworks to visualize the informations.

OpenCV as a web service

i am looking into facial recognitions using Local Binary Pattern Histogram have came across OpenCV. Within OpenCV, the Local Binary Pattern Histogram has a function which compares histograms "compareHist". How can i perform this function on a web server?. Is it possible to run OpenCV on a web server? (i am thinking about writing the whole function myself however it is based on multiple custom created classes and its rather troublesome - what language should i use? - this would be my last resort).
OpenCV comes with cv::FaceRecognizer, which includes Eigenfaces, Fisherfaces and Local Binary Patterns Histograms. It comes with a very detailed documentation, please see:
http://docs.opencv.org/trunk/modules/contrib/doc/facerec/index.html
No need to implement it yourself. If you want to do this in another language, then you can easily look up the implementation in the contrib module of OpenCV. I am sure you can get some impression there.
As for the webserver. If you have a real server, then sure you could put OpenCV up there and interface with it. If you want to get something going real quick, have a look at the OpenCV Python bindings for cv::FaceRecognizer. I did a post on the OpenCV QA page just yesterday:
http://answers.opencv.org/question/253/broken-python-bindings-with/?answer=255#post-id-255
However, it's a bit complicated due to an error on my side. There was a bug in the official OpenCV 2.4.2 release, so for the Python bindings to work you'll need the trunk version. Note, that the source code is now hosted with git, so you can get it with:
git clone git://code.opencv.org/opencv.git
for example. Then if you are in Linux, you can follow this tutorial on how to install OpenCV:
http://docs.opencv.org/trunk/doc/tutorials/introduction/linux_install/linux_install.html
or if you are in Windows, then:
http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html
might help. Make sure you have python-dev and python-numpy installed, so the Python bindings are compiled. If you are in Windows, simply install Python2.7 and NumPy (http://www.numpy.org).
You might be interested in my Guide to Face Recognition with Python also, which is available at:
https://github.com/bytefish/facerecognition_guide
That shows a really lightweight implementation of two algorithms.
Disclaimer I am a founder.
Algorithmia provides OpenCV as a service through our API.
http://algorithmia.com/users/opencv

Embedded Python Module Configuration

I'm looking at adding Python support to my game engine project, with the intent of using it as a scripting language for much of the game logic and world building. I'd like to expose a lot of the C++ code to Python. I've already gone through the relevant documentation on the Python site, and I'm fairly confident that I understand the basic requirements for embedding Python and communicating back and forth between Python and the core engine components.
I'm going to embedding Python into the engine itself, rather than compiling the engine as a Python module, since one of my target platforms is the iPhone.
One question I haven't been able to answer myself is how to introduce structure to the C++ modules. For example, I'd like to be able to do something along the lines of:
from engine.scene import skyobject
import engine.core.platforminfo
Would you just create a single "engine" module, and then add some sort of sub module for scene, core, etc? Or should there be separate modules for each of the exposed components, i.e. defining the skyobject module with the name "engine.scene.skyobject"?
Any insight on this is appreciated.

Using Blender for physics simulations

I've been looking at different ways of creating a certain physics simulation. What I am trying to do is to 3D model the motion of a body under the effects of various forces over time. I was originally looking at coding something in c++ using a physics engine (Bullet) and a 3d engine (Irrlicht). However, I noticed that Blender already allows one to do physical simulations since Bullet is integrated with it (correct me if I'm wrong). This seems like it would make it much easier to design the simulation exactly how I want it (with Blender's extensive GUI).
My issue is that I would like to use the results from the simulation (basically x,y,z,pitch,roll,yaw of the body at each timestep) for input into c/c++ code (or another language if its much easier for this). Can this be done with Blender? Is there a better software package for this that I am overlooking? Thanks, any advice is appreciated.
I would use a Python script for that task, as Blender has a nice interface getting/setting the objects and their properties programmatically through .py files.
So after you are done with your animation you can call a script to walk through the frames and save the required data into a file.
A getting started doc can be found here: http://wiki.blender.org/index.php/Doc:Manual/Extensions/Python or here: http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro
There is a huge list of scripts worth browsing for similar routines you need. http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts
As mentioned before, it would be very easy to use python for this. For more specific use if using Blender, perhaps you should consult the main Blender forum www.blenderartists.org
Blenderartists python support: http://blenderartists.org/forum/forumdisplay.php?11-Python-Support
Blender 2.5 code snippets (Introduction to scripting for Blender 2.5): http://blenderartists.org/forum/showthread.php?193908-Code-snippets.-Introduction-to-Python-scripting-in-Blender-2.5x

Is there any python implementation for text replacement with truetype fonts?

I have searched and there are some php or flash based solutions, but none in Python.
PIL (Python Image Library) could be the starting point, but if anybody knows something done or half done I will gladly use it for my Django projects, finish or polish the library and release it for everyone.
It's actually fairly easy in Django. Jacob Kaplan-Moss posted about it years ago. I used this on my site for a while.
Apparently there's a django-rendertext project based on that code, but I haven't used it.
The nicest text comes from PyCairo, but having said that, I've not seen any project that just spits out images with the desired text in that manner, for any web framework.