Documente Academic
Documente Profesional
Documente Cultură
GPIO as GPIO
import cv2
import numpy as np
GPIO.setmode(GPIO.BCM)
GPIO.setup(26,GPIO.OUT)
GPIO.setup(14,GPIO.OUT)
ancho = 640
largo = 480
centrox = ancho/2
minArea = 50
class VideoCamera(object):
# from a webcam, comment the line below out and use a video file
# instead.
cap.video = cv2.VideoCapture(0)
kernel=np.ones((5,5),np.uint8)
cap.video.set(cv2.CAP_PROP_FRAME_WIDTH, ancho)
cap.video.set(cv2.CAP_PROP_FRAME_HEIGHT, largo)
# If you decide to use video.mp4, you must have this file in the folder
# as the main.py.
# self.video = cv2.VideoCapture('video.mp4')
def __del__(cap):
cap.video.release()
def get_frame(cap):
h,w,m=image.shape
kernel=np.ones((5,5),np.uint8)
# kernel=np.ones((3,3),np.uint8)
#amarillo
colorLower = (28,100,100)
colorUpper = (38,255,255)
moments = cv2.moments(mask)
area=int(moments['m00'])
f = open ('coordenadas.txt','w')
f.write ('area')
f.close
x=0
y=0
dist=0
# print (area)
x = int(moments['m10']/moments['m00'])
y = int(moments['m01']/moments['m00'])
if area>=845695.7:
if area>=2301333.5:
dist=-(area/307781.175)+37.4771743
if area<2301333.5:
if area>=859737.4:
dist=-(area/72079.83)+61.9275725
if area<859737.4:
dist=-(area/19652.8425)+93.74622211
if int(dist)<=15:
dist=15
if int(dist)>=70:
dist=70
if (x-w/2) == 0:
paro()
# adelante()
# else:
# paro()
#Giro derecha
# GPIO.output(14,True)
# derecha()
# else:
# GPIO.output(14,False)
# adelante()
#Giro izquierda
# GPIO.output(26,True)
# izquierda()
# else:
# GPIO.output(26,False)
# cv2.line(image,(0,h//2),(w,h//2),(150,200,0),2)
# cv2.line(image,(w//2,0),(w//2,h),(150,200,0),2)
x,y,w,h=cv2.boundingRect(opening)
cv2.circle(image,(x+w//2,y+h//2),5,(0,0,255),-1)
# We are using Motion JPEG, but OpenCV defaults to capture raw images,
# video stream.
return jpeg.tobytes()