Auto image capture with stepper pauses

asked 2020-02-03 14:19:35 -0600

updated 2020-02-03 15:19:07 -0600

berak gravatar image

So I have been looking for a solution for this and have been coming up empty. I am looking to capture images at the times the stepper motor stops moving. Essentially the stepper moves (x) steps, system pause for 2 seconds, image capture, stepper moves (x) steps, system pause for 2 seconds, image capture so on... Right now I have it set up to where the stepper moves (x) steps, pause, waits for key input to capture, key input to close camera, stepper moves (x) steps and repeat. Below is the program at is being used as far as the image capture is concerned.

import cv2

cam = cv2.VideoCapture(0)
cv2.namedWindow("test")
img_counter = 0

while True:
    ret, frame = cam.read()
    cv2.imshow("test", frame)
    if not ret:
        break
    k = cv2.waitKey(3)

    if k%256 == 27:
        # ESC pressed
        print("Escape hit, closing...")
        break
    elif k%256 == 32:
        # SPACE pressed
        img_name = "opencv_frame_{}.png".format(img_counter)
        cv2.imwrite(img_name, frame)
        print("{} written!".format(img_name))
        img_counter += 1

cam.release()

cv2.destroyAllWindows()

My end goal is to set the program to go to 10 random points 10 times each and capture those images autonomously. So my only input on the program is the start button. I thank anyone with input on this.

edit retag flag offensive close merge delete

Comments

How did you get stepper work work? You have hardware such esp32, raspberry pi zero, etc

supra56 gravatar imagesupra56 ( 2020-02-03 21:25:58 -0600 )edit