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!

2
  • 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. Commented Oct 10, 2011 at 18:22
  • @david-heffernan: I've already asked about using C++ image libraries to get color from image but got no answer: stackoverflow.com/questions/7678511/… and stackoverflow.com/questions/7645168/freeimage-get-pixel-color. So I don't know how to realize it using C++ :-(. Commented Oct 10, 2011 at 18:42

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.