0
我在C++上有一個代碼,它創建文件並向其寫入數據。是否有可能使用Python的函數在我的C++代碼中使用Python的功能?例如,我想這樣做:用於C++的Python API
# 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)
我想寫pixColor使用C++的可能性文本文件:
#include <fstream>
#include <iostream>
int main()
{
ofstream fout('color.txt', ios_base::out | ios_base::binary);
fout << pixColor;
}
這是唯一的例子。我的應用程序會真正檢測每個像素的顏色,並將它輸出到'color.txr'文件中,所以我需要比Python更快的東西。有沒有可能做到這一點?非常感謝!
使用C++圖像庫。從C++調用Python來運行你已經決定的代碼太慢無法幫助。這只是增加了一個額外的層,只能更慢。 –
@ david-heffernan:我已經問過如何使用C++圖像庫從圖像獲取顏色,但沒有得到答案:http://stackoverflow.com/questions/7678511/getting-pixel-color-with-magick和http: //stackoverflow.com/questions/7645168/freeimage-get-pixel-color。所以我不知道如何使用C++來實現它:-(。 – ghostmansd