Python API for C++
I have a code on C++, that creates file and writes data to it. Is it possible to use Python's functions to use Python's functionality in my C++ 开发者_JAVA百科code? For example, I'd like to do this:
# Content of function.py
from PIL import Image
imgObject = Image.open('myfile.jpg') # Create Image object
pixArray = imgObject.load() # Create array of pixels
pixColor = pixArray[25, 25] # Get color of pixel (25,25)
I want to write pixColor to text file using C++ possibilities:
#include <fstream>
#include <iostream>
int main()
{
ofstream fout('color.txt', ios_base::out | ios_base::binary);
fout << pixColor;
}
That's only example. My application will really detect color of each pixel and will output it in 'color.txr' file, so I need something faster than Python. Is there a possibility to do it? Thanks a lot!
You may have a look to boost::python library which is really great for interfacing python and C++.
精彩评论