|
1 | 1 | # -*-coding:Utf-8 -*
|
2 | 2 |
|
3 |
| -"""This script is the main program of our project. |
| 3 | +"""This is the main Raspberry Pi's program of our project. |
4 | 4 |
|
5 |
| -It was developped for Python version 2.7.13 |
6 |
| -If you wish to upgrade to Python3, you must install the Pillow |
7 |
| -library instead of PIL. |
| 5 | +It it for use with Python version 2.7.13 |
| 6 | +If you wish to upgrade to Python3, you must use Pillow instead of PIL. |
8 | 7 |
|
9 | 8 | The goal is to capture the image of the PiCamera, convert it to black & white,
|
10 |
| -cut the image in 12*10 squares of pixels, get the grayscale values of each of |
| 9 | +cut the image in the required squares of pixels, get the grayscale values of each of |
11 | 10 | those squares, and then send these values to each Arduino via I2C.
|
12 | 11 |
|
13 | 12 | You can find the Arduino's code at :
|
|
29 | 28 | camera = picamera.PiCamera()
|
30 | 29 | stream = BytesIO()
|
31 | 30 |
|
32 |
| -output_width = 12 # Number of Arduinos |
33 |
| -output_height = 10 # Number of Servos an Arduino controls |
| 31 | +output_width = 8 # Number of Arduinos |
| 32 | +output_height = 6 # Number of Servos per Arduino |
34 | 33 |
|
35 | 34 | # The larger the resolution, the clearer the image
|
36 | 35 | # This also means bigger procession time
|
37 |
| -camera.resolution = (800, 600) |
| 36 | +camera.resolution = (480, 360) |
38 | 37 | (width, height) = camera.resolution
|
39 | 38 |
|
40 | 39 | # We calculate the width and height of each square in the grid
|
|
45 | 44 | nb_pixels = tailleH * tailleL
|
46 | 45 |
|
47 | 46 | # Uncomment below this if you want a live preview of what the camera captures
|
48 |
| -# It only works if the Raspberry Pi's is connected to a monitor, not VNC |
| 47 | +# It only works if the Raspberry Pi's is connected to a monitor, not VNC or SSH |
49 | 48 | ### camera.start_preview()
|
50 | 49 |
|
51 | 50 | # Let enough time for the camera to warmup
|
|
83 | 82 | coordY = y + (pixHDepart)
|
84 | 83 | current_pixel_value = Image.getpixel(image, (coordX, coordY))
|
85 | 84 | sum_gray += current_pixel_value
|
86 |
| - a += 1 |
87 | 85 |
|
88 | 86 | # We divide the sum of gray in the square by the number
|
89 | 87 | # of pixels the square have, to get its average greyscale value
|
90 |
| - average_gray = int(sum_gray / nb_pixels) |
| 88 | + average_gray = int(sum_gray/nb_pixels) |
91 | 89 |
|
92 | 90 | # Each Arduino treats a row, so we send 12 values to each of them.
|
93 | 91 | # That means if we have sent 12 values, we change Arduinos.
|
94 |
| - if (case%12)+1 == 1 : |
| 92 | + if (case%output_width)+1 == 1 : |
95 | 93 | arduino += 1
|
96 | 94 | case +=1
|
97 | 95 |
|
|
100 | 98 |
|
101 | 99 | # Let the program rest a bit
|
102 | 100 | sleep(0.001)
|
| 101 | + sleep(0.01) |
0 commit comments