Don't call loadImage() in draw()!
Actually, don;t call loadImage() at all.
There is no need to save the file to disk while merging the two sketches.
Actually, don;t call loadImage() at all.
There is no need to save the file to disk while merging the two sketches.
You can create a PImage from the camera directly:
img = cam.get();