HackUTOKYOv2Pim

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4434fbe00526b3880d91d25e0ba4c20778b580dc
parent c9ec6d701e0f76f7933942d681fdee6f3630d689
Author: 諒太 林 <ryouturn@gmail.com>
Date:   Fri, 30 Aug 2024 17:40:55 +0900

add test code

Diffstat:
Atest.py | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+), 0 deletions(-)

diff --git a/test.py b/test.py @@ -0,0 +1,96 @@ +import RPi.GPIO as GPIO +import time +import sys +import cv2 +import os + +stepPin = 22 +dircPin = 17 +enabPin = 23 + +GPIO.setmode(GPIO.BCM) # GPIOで指定 +GPIO.setup(enabPin, GPIO.OUT) # 2:Enableに定義 +GPIO.setup(dircPin, GPIO.OUT) # 3:Dir +GPIO.setup(stepPin, GPIO.OUT) # 4:Step + +#GPIO.setup(17, GPIO.OUT)#17:MS1 +#GPIO.setup(27, GPIO.OUT)#27:MS2 +#GPIO.setup(22, GPIO.OUT)#22:MS3 + +def main(): + GPIO.output(enabPin, 0) + while(True): + escapeR + GPIO.cleanup() + +#逆かもしれない +def escapeR(): + GPIO.output(dircPin, 0) + for num in range(0,200): + GPIO.output(stepPin, 1) + time.sleep(0.001) + GPIO.output(stepPin, 0) + time.sleep(0.001) + time.sleep(1) +def escapeL(): + GPIO.output(dircPin, 1) + for num in range(0,200): + GPIO.output(stepPin, 1) + time.sleep(0.001) + GPIO.output(stepPin, 0) + time.sleep(0.001) + time.sleep(1) + +def mosaic(src): + dst = cv2.resize(src, None, fx=0.1, fy=0.1, interpolation=cv2.INTER_NEAREST) + return cv2.resize(dst, src.shape[:2][::-1], interpolation=cv2.INTER_NEAREST) + +def difference(a, b): + if(a < b): + return b - a + return a - b + +def kora(): + os.system('mpg321 -q /home/pi/camera/kora.mp3&') + +def dump(src, keep): + os.system('clear') + RightCount = 0 + LeftCount = 0 + for x in range(0, 32): + str = '' + for y in range(0, 24): + target = src[y*10][x*10] + diff = difference(keep[y][x],target) + if diff > 50: + str += '{:02} '.format(diff) + if(y >= 12): + RightCount += 1 + else: + LeftCount += 1 + else: + str += '-- ' + keep[y][x] = target + print(str) + count=[RightCount,LeftCount] + return count +# 仕様メモcount=[RightCount,LeftCount] + +cap = cv2.VideoCapture(0) + +cap.set(3,320) # WIDTH +cap.set(4,240) # HEIGHT +cap.set(5,30) # FPS + +keep = [[0] * 32 for i in range(24)] + +busy = True + +try: + main() +except KeyboardInterrupt: + print('interrupted!') + GPIO.cleanup() + +cap.release() +cv2.destroyAllWindows()+ \ No newline at end of file