Recently I started developing a WebViewer, basically the Web TeamViewer. I'm writing the back-end in python. Right now I arrived at a point, where I only send pixel differences between images, not the whole image using PIL and FLASK. Unfortunately checking for differences between two bidimensional arrays with double for cycles does not seem to be the fastest solution. I was wondering if there is a faster solution, like knowing the trigger position of the event that changed the image in the first place. Here is the code I'm currently using. I would aprecciate any helpful advice. After identifying my question as a duplicate, I would like to emphasize the fact, that I need to know the differences between the two images. I just find it totally useless to check for differences in the whole matrix.
global differences, img
img = ImageGrab.grab()
img = img.resize((int(img.width/2), int(img.height/2)), Image.ANTIALIAS)
b = img.load()
while True:
img1 = ImageGrab.grab()
img1 = img1.resize((int(img1.width/2), int(img1.height/2)), Image.ANTIALIAS)
c = img1.load()
for i in range(0, img.width):
for j in range(0, img.height):
if b[i,j] != c[i,j]:
foo = {
"i" : i,
"j" : j,
"val" : b[i,j]
}
differences.append(foo)
b[i, j] = c[i, j]