I'm trying to transform an image into a matrix of it's rbg values in c++, i really like the simplicity of PIL on handling different images extensions, so i currently have two codes
from PIL import Image
img=Image.open("oi.png")
pixel=img.load()
width,height=img.size
print(height)
print(width)
def rgb(r, g, b):
return ((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff)
for x in range(width):
for y in range(height):
print(rgb(pixel[x,y][0],pixel[x,y][1],pixel[x,y][2]))
and to recieve in C++
#include <bits/stdc++.h>
using namespace std;
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);
int main(){__
long long height,width;cin>>height>>width;
unsigned long img[width][height];
for(long long j=0; j<height;j++) for (long long i=0; i<width;i++){
cin>>img[i][j];
}
return 0;}
and i am connecting both trough terminal withpython3 code.py | ./code
it works for really small images, but for bigger ones it returns BrokenPipeError: [Errno 32] Broken pipe
What should i do? is there a better way to achieve what i am trying to achieve?
I want to connect python output to c++ input even with big outputs without Broken pipe error
width
andheight
arelong long
s, then why arei
andj
int
s?unsigned long img[width][height];
- is not valid standard C++. See: Why aren't variable-length arrays part of the C++ standard?.