开发者

Python API for C++

开发者 https://www.devze.com 2023-04-11 20:36 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号