Simple logical operations on images.

I’ve recently recived the OpenVm7 and I’m playing with it.
I just want perform some logical operation on two image but I got and syntax error when i try to perform the and operation :

# Untitled - By: HomeLenovo - ven giu 2 2017

import sensor
import image
import pyb


    img = sensor.snapshot()
    img2 = sensor.snapshot()
    img3 = img.and(img2)

Where is the problem ?

The problem is those binary ops are reserved keywords. This issue was supposed to be fixed a while back (maybe by using upper case) but we forgot about it completely, so it will have to wait until the next release.

One note on your code, that snapshot function doesn’t return a copy of the image, it returns an image that points to the framebuffer (like a pointer), so with your code there img == img2 == img3, the result is and’ing the image with itself. If you want you could make a copy of the image, but keep an eye on memory usage.

Hi ,
Thanks for the fast reply !
OK now is clear .
Thanks Roberto.

Note that the nand and nor and invert methods still work. You can just use them to get he same effect.

To copy an image use the copy() method.

Finally, to avoid memory problems note that these functions, nand and nor, can operate on a file pulled from disk. See the frame differencing code for an example. It’s under one of the low numbered example folders.