Ejemplo n.º 1
0
def fase2():
    from Arduino.Arduino import Arduino
    arduino = Arduino(baudrate=9600,timeout=1)
    ret = arduino.setup(port= 0)
    arduino.write("Is90F")
    arduino.write("Im0&0F")

    cap = cv2.VideoCapture(0)
    #Factor para pixelar la imagen manteninendo la raelación de aspecto
    factor_reescalado = 4
    #Respecto al denoise multiple almacena frames anteriores
    pila_denoise = []
    len_pila_denoise = 3
    while True:
        margin = 30
        in_front = 100
        ret,frame = cap.read()
        resized = cv2.resize(frame,(frame.shape[1]//factor_reescalado,frame.shape[0]//factor_reescalado))
        resized = cv2.resize(resized,(resized.shape[1]*factor_reescalado,resized.shape[0]*factor_reescalado))
        #Denoise multiple
        dst = resized
        pila_denoise.append(resized)
        if(len(pila_denoise)>len_pila_denoise):
            #https://docs.opencv.org/3.4/d1/d79/group__photo__denoise.html#ga723ffde1969430fede9241402e198151
            dst = cv2.fastNlMeansDenoisingMulti(pila_denoise, len(pila_denoise)-1, (len_pila_denoise-1)//2, None, 4, 7, 5)
            del pila_denoise[0]

        blur = cv2.GaussianBlur(dst,(5,5),0)
        gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
        edges = auto_canny(gray,sigma = 0.7)
        circles = cv2.HoughCircles(edges,cv2.HOUGH_GRADIENT,1,35,
            param1=50,param2=30,minRadius=0,maxRadius=edges.shape[1])

        if (circles is not None):
            circles = np.round(circles[0,:].astype("int"))
            for i in circles:
                #cv2.circle(gray,(i[0],i[1]),i[2],(0,255,0),2)
                #cv2.circle(gray,(i[0],i[1]),2,(0,0,255),3)
                while(check_size()<in_front):
                    if(i[1]>frame.shape[1]/2+margin):
                        arduino.move_motors(240,0)
                    elif(i[1]<frame.shape[1]/2-margin):
                        arduino.move_motors(0,240)
                    else:
                        arduino.move_motors(240,240)
                    sleep(0.01)
                recoger()

        res = np.hstack((gray,edges))
        #cv2.imshow("resized",res)
        cv2.imshow("dst",res)
        k = cv2.waitKey(1)
        if (ord('k')==k):
            cv2.destroyAllWindows()
            break
    pass
Ejemplo n.º 2
0
from picamera import PiCamera
from fase2 import fase2
from time import sleep
import cv2
import numpy as np
import atexit
"""import subprocess
from crash_watchdog.file.file import File
from crash_watchdog.file.crash_watchdog import check_state<<
stat_storage = File()
path_stat_file = r'{}'.format(os.getcwd()+"/"+os.path.basename(__file__))"""
#subprocess.call("raspivid -t 999999 -h 720 -w 1080 -fps 30 -hf -vf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! queue ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host= port=5000")

from Arduino.Arduino import Arduino
arduino = Arduino(baudrate=9600, timeout=1)
ret = arduino.setup(port=0)

arduino.write("Is90F")
arduino.write("Im0&0F")
#Line following & camera variables
rango_reescalar = 4
last_line_position = 0
black = 0
white = 255
parametro_threshold = 90
#Cantidad minima de pixeles rojos en la linea para considerarlo un cuadro rojo
min_red_pixels = 20
delta_red = 50
camera = PiCamera()
camera.rotation = 180
camera.resolution = (640, 480)
Ejemplo n.º 3
0
import RPi.GPIO as GPIO
from Arduino.Arduino import Arduino
from time import sleep
arduino = Arduino()
arduino.setup()
high_vel = 250
low_vel = 165

pulses_encoder = 8
reduction = 48
rpm_max = 120
pin_encoder_l=26
pin_encoder_r=19
#bouncetime_calc = int((1000*(rpm_max/60))//(reduction*pulses_encoder))
last_state_l = 0
last_state_r = 0
encoder_counter_l = 0
encoder_counter_r = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin_encoder_l, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin_encoder_r, GPIO.IN,pull_up_down=GPIO.PUD_UP)
def callback_l(chanel):
    global last_state_l,encoder_counter_l,pin_encoder_l
    #Chequea si el estado ha cambiado y si este es de "subida" solamente
    stat = GPIO.input(chanel)
    if(stat!=last_state_l):
        last_state_l = stat
        encoder_counter_l+=1

def callback_r(chanel):
    global last_state_l,encoder_counter_l,pin_encoder_l