Code for controlling mbed hardware (LED's, motors), as well as code for the Raspberry Pi to run a Support Vector Machine that identifies objects using the Pi camera
Dependencies: mbed Motordriver mbed-rtos PololuLedStrip
pi/collectImages.py@3:a3ed7ff99772, 2019-12-06 (annotated)
- Committer:
- arogliero3
- Date:
- Fri Dec 06 00:58:02 2019 -0500
- Revision:
- 3:a3ed7ff99772
- Parent:
- 1:183a8efd562a
update img6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
arogliero3 | 1:183a8efd562a | 1 | import sys |
arogliero3 | 1:183a8efd562a | 2 | import time |
arogliero3 | 1:183a8efd562a | 3 | import picamera |
arogliero3 | 1:183a8efd562a | 4 | |
arogliero3 | 1:183a8efd562a | 5 | |
arogliero3 | 1:183a8efd562a | 6 | |
arogliero3 | 1:183a8efd562a | 7 | myargs = sys.argv[1:] |
arogliero3 | 1:183a8efd562a | 8 | |
arogliero3 | 1:183a8efd562a | 9 | camera = picamera.PiCamera() |
arogliero3 | 1:183a8efd562a | 10 | camera.resolution = (352, 240) |
arogliero3 | 1:183a8efd562a | 11 | camera.color_effects = (128, 128) # turn camera to black and white |
arogliero3 | 1:183a8efd562a | 12 | camera.start_preview() |
arogliero3 | 1:183a8efd562a | 13 | time.sleep(2) |
arogliero3 | 1:183a8efd562a | 14 | |
arogliero3 | 1:183a8efd562a | 15 | |
arogliero3 | 1:183a8efd562a | 16 | if len(myargs) <= 1: |
arogliero3 | 1:183a8efd562a | 17 | sys.exit("Incorrect arguments") |
arogliero3 | 1:183a8efd562a | 18 | |
arogliero3 | 1:183a8efd562a | 19 | num_images_per_type = int(myargs[0]) # number of images to take of each type of object |
arogliero3 | 1:183a8efd562a | 20 | |
arogliero3 | 1:183a8efd562a | 21 | print("Taking ", num_images_per_type, "images each of ", myargs[1:]) |
arogliero3 | 1:183a8efd562a | 22 | |
arogliero3 | 1:183a8efd562a | 23 | for image_type in myargs[1:]: |
arogliero3 | 1:183a8efd562a | 24 | for i in range(num_images_per_type): |
arogliero3 | 1:183a8efd562a | 25 | filename = image_type + "_" + str(i) + ".bmp" |
arogliero3 | 1:183a8efd562a | 26 | camera.capture("images/"+filename, format='bmp', resize=(352, 240)) |
arogliero3 | 1:183a8efd562a | 27 | print(filename) |
arogliero3 | 1:183a8efd562a | 28 | time.sleep(1) |