用于 C++ 的 Python API
我有一个 C++ 代码,它创建文件并向其中写入数据。是否可以在我的 C++ 代码中使用 Python 的函数来使用 Python 的功能?例如,我想这样做:
# 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)
我想使用 C++ 可能性将 pixColor 写入文本文件:
#include <fstream>
#include <iostream>
int main()
{
ofstream fout('color.txt', ios_base::out | ios_base::binary);
fout << pixColor;
}
这只是示例。我的应用程序将真正检测每个像素的颜色并将其输出到“color.txr”文件中,因此我需要比 Python 更快的东西。有可能做到吗?多谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会看看 boost::python 库,它对于连接 python 和 C++ 非常有用。
You may have a look to boost::python library which is really great for interfacing python and C++.