1

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]
Fe Ri
  • 195
  • 1
  • 1
  • 9
  • Possible duplicate of [Comparing 2 images/pictures, and mark the difference](http://stackoverflow.com/questions/26773850/comparing-2-images-pictures-and-mark-the-difference) – Mike Scotty Apr 10 '17 at 15:38
  • 1
    You certainly want to have a look at `numpy`. – DYZ Apr 10 '17 at 15:38
  • @DYZ Could you please specify what part of numpy I should look at? I tried it a certain numpy way, but using it I got a longer runtime/image-difference. – Fe Ri Apr 10 '17 at 15:45
  • 1
    Convert both images to numpy matrices, take the difference, and find the locations and values of non-zero elements. – DYZ Apr 10 '17 at 15:47

0 Answers0