I am trying to compute the difference between two images with OpenCV on Raspberry Pi and I want the script to run continually like in a while loop and then after the first button press store the first image then wait for the second and store the second image and once that has happened it should run the function to compute the difference. I am using gpiozero and I've tried using a while loop as well as some of the gpiozero functions but the script doesn't wait correctly.
What I've tried:
def capture(): # create flag to track second button click secondClick = False # take the first image image1 = capture_stream(True) while secondClick == False: # pauses the script until button is pressed again button.wait_for_press(timeout=None) secondClick = True # take second picture and compute image2 = capture_stream(True) diff = compute_diff(image1, image2) insert(diff) print("Structural difference: %s %%" % (diff*100)) button.when_pressed = capture print("running...") pause()
I've tried something similar within a while loop with some if statements on the number of pictures already taken but I feel like the while loop method is messy.
Let me know if I can provide any aditional information and thank you for your time.