0

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++ 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!

ghostmansd
  • 3,285
  • 5
  • 30
  • 44
  • 3
    Use a C++ image library. Calling into Python from C++ to run code that you have already decided is too slow cannot help. That just adds an extra layer and can only be slower still. – David Heffernan Oct 10 '11 at 18:22
  • @david-heffernan: I've already asked about using C++ image libraries to get color from image but got no answer: http://stackoverflow.com/questions/7678511/getting-pixel-color-with-magick and http://stackoverflow.com/questions/7645168/freeimage-get-pixel-color. So I don't know how to realize it using C++ :-(. – ghostmansd Oct 10 '11 at 18:42

1 Answers1

1

You may have a look to boost::python library which is really great for interfacing python and C++.

neodelphi
  • 2,706
  • 1
  • 15
  • 22