def __init__(self, q1, q2):
        self.queue_MAIN_2_VS = q1
        self.queue_VS_2_STM = q2
        self.resolution = (320, 240)
        self.video_stream = PiVideoStream(self.resolution, 60)

        self.settings = {
            'disp': False,
            'dispThresh': False,
            'dispContours': False,
            'dispApproxContours': False,
            'dispVertices': False,
            'dispNames': False,
            'dispCenters': False,
            'dispTHEcenter': False,
            'erodeValue': 0,
            'lowerThresh': 40,
            'working': True,
            'autoMode': False,
            'dispGoal': True
        }

        self.prevStateDisp = self.settings['disp']
        self.prevStateDispThresh = self.settings['dispThresh']

        self.objs = []

        self.classLogger = logging.getLogger('droneNav.VisionSys')

        self.working = True
        self.t = Thread(target=self.update, args=())
        self.t.daemon = True
Esempio n. 2
0
    def __init__(self,
                 src=0,
                 usePiCamera=False,
                 resolution=(320, 240),
                 framerate=60):
        if usePiCamera:
            from pivideostream import PiVideoStream

            self.stream = PiVideoStream(resolution=resolution,
                                        framerate=framerate)

        else:
            self.stream = WebcamVideoStream(src=src)

        def start(self):
            return self.stream.start()

        def update(self):
            self.stream.update()

        def read(self):
            return self.stream.read()

        def stop(self):
            self.stream.stop()
Esempio n. 3
0
def picamera_ndvi(preview=False, resolution=(640, 480), framerate=60):
    stream = PiVideoStream(resolution=resolution, framerate=framerate).start()
    time.sleep(2)
    print('Video stream started.')

    directory = 'capture_' + str(get_time_ms()) + '/'

    # loop over the frames from the video stream indefinitely
    while True:
        # grab the frame from the threaded video stream
        frame = stream.read()
        if frame is not None:
            b, g, r = cv2.split(frame)
            # get NDVI from RGB image
            ndvi = vegevision.get_ndvi(b, r)
            ndvi_colorized = apply_custom_colormap(
                255 * ndvi.astype(np.uint8),
                cmap=vegevision.load_cmap('NDVI_VGYRM-lut.csv'))
            # show the frame
            if preview:
                cv2.imshow("Video Input with NDVI", ndvi_colorized)
                print('Displaying NDVI...')
            else:
                save_image(ndvi, directory=directory)

        # if the `q` key was pressed, break from the loop
        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
            break

    # do a bit of cleanup
    cv2.destroyAllWindows()
    stream.stop()
Esempio n. 4
0
    def __init__(self,
                 src=0,
                 usePiCamera=False,
                 resolution=(320, 240),
                 framerate=32):
        if usePiCamera:
            from pivideostream import PiVideoStream

            self.stream = PiVideoStream(resolution=resolution,
                                        framerate=framerate)
        else:
            self.stream = WebcamVideoStream(src=src)
	def __init__(self, src=0, usePiCamera=False, resolution=(720, 480),
		framerate=32):
		if usePiCamera:
			# only import this package if using PiCamera
			from pivideostream import PiVideoStream
 
			self.stream = PiVideoStream(resolution=resolution,
				framerate=framerate)
 
		# otherwise, we are using OpenCV so initialize the webcam
		# stream
		else:
			self.stream = WebcamVideoStream(src=src)
Esempio n. 6
0
 def __init__(self,
              src=0,
              usePiCamera=False,
              resolution=(320, 240),
              framerate=32):
     # pycam modulu ?*
     if usePiCamera:
         # gerekli kurulum
         from pivideostream import PiVideoStream
         self.stream = PiVideoStream(resolution=resolution,
                                     framerate=framerate)
     # else
     else:
         self.stream = WebcamVideoStream(src=src)
Esempio n. 7
0
 def __init__(self, resolution=(320, 240), framerate=32):
     self.conf = json.load(open("conf.json"))
     self.lt = LocalTime("Baltimore")
     self.avg = None
     self.avg_count = 0
     self.motionCounter = 0
     self.motion_frames = []
     self.x = 0
     self.y = 0
     self.w = 0
     self.h = 0
     self.contour_area = 0
     self.vs = PiVideoStream(resolution, framerate).start()
     time.sleep(self.conf["camera_warmup_time"])
Esempio n. 8
0
    def __init__(self,
                 src=0,
                 isPiCamera=False,
                 resolution=(320, 240),
                 framerate=32):

        if isPiCamera:
            from pivideostream import PiVideoStream

            self.stream = PiVideoStream(resolution=resolution,
                                        framerate=framerate)

        else:
            from usbvideostream import usbVideoStream

            self.stream = usbVideoStream(src, resolution=resolution)
Esempio n. 9
0
    def __init__(self,
                 src=0,
                 usePiCamera=False,
                 resolution=(320, 240),
                 framerate=32):
        # check to see if the picamera module should be used
        # if usePiCamera:
        # only import the picamera packages unless we are
        # explicity told to do so -- this helps remove the
        # requirement of `picamera[array]` from desktops or
        # laptops that still want to use the `imutils` package
        from pivideostream import PiVideoStream

        # initialize the picamera stream and allow the camera
        # sensor to warmup
        self.stream = PiVideoStream(resolution=resolution, framerate=framerate)
Esempio n. 10
0
	def __init__(self, src=0, usePiCamera=False, resolution=(320, 240),
		framerate=32):
		# check to see if the picamera module should be used
		if usePiCamera:
			# only import the picamera packages unless we are
			# explicity told to do so -- this helps remove the
			# requirement of `picamera[array]
			from pivideostream import PiVideoStream

			# initialize the picamera stream and allow the camera
			# sensor to warmup
			self.stream = PiVideoStream(resolution=resolution,
				framerate=framerate)

		# otherwise, we are using OpenCV so initialize the webcam
		# stream
		else:
			self.stream = WebcamVideoStream(src=src)
Esempio n. 11
0
	def __init__(self, src=0,usePiCamera=False, resolution=(320,240),framerate=32):
		#check to see if the picamera module should be used
		if usePiCamera:
			from pivideostream import PiVideoStream
			self.stream = PiVideoStream(resolution=resolution, framerate=framerate)
		else:
			self.stream = WebcamVideoStream(src=src)
			
		def start(self):
			#start the threaded video stream
			return self.stream.start()
		
		def update(self):
			#grab the next frame from the stream
			self.stream.update()
			
		def read(self):
			#return the current frame
			return self.stream.read()
		
		def stop(self):
			# stop the thread and release any resources
			self.stream.stop()
Esempio n. 12
0
def read_settings():
    settings_file = open("settings.json", "r")
    settings_json = settings_file.read()
    return json.loads(settings_json)
def write_settings(settings):
    settings_json = json.dumps(settings)
    settings_file = open("settings.json", "w")
    settings_file.write(settings_json)

settings = read_settings()

# -----------------------------------------------------------------------------
# Camera
# -----------------------------------------------------------------------------

vs = PiVideoStream(resolution=(1280, 720), framerate=60).start()
def set_camera_settings():
    # Default settings
    vs.camera.brightness = 50
    vs.camera.contrast = 0
    vs.camera.awb_mode = "off"
    vs.camera.awb_gains = (1, 1)
    vs.drc_strength = "off"
    vs.exposure_mode = "off"
    # Customized settings
    vs.camera.shutter_speed = settings["shutter_speed"]

set_camera_settings()

def get_raw_readings():
    result = {}
Esempio n. 13
0
}

colors = {
    'red': (0, 0, 255),
    'green': (0, 255, 0),
    'blue': (255, 0, 0),
    'yellow': (0, 255, 217),
    'orange': (0, 140, 255)
}

x = servo(180)
pwm_1.start(x)
time.sleep(.5)
pwm_1.stop()

vs = PiVideoStream()

vs.start()
time.sleep(2.0)

while True:

    pwm_2.start(servo(30))
    time.sleep(3)
    pwm_2.stop()

    pwm_2.start(servo(135))
    time.sleep(2)
    pwm_2.stop()

    frame = vs.read()
Esempio n. 14
0
#!/usr/bin/env python
# coding=utf-8
import cv2
import time
#from settings import *
#from picamera.array import PiRGBArray
#from picamera import PiCamera
from pivideostream import PiVideoStream
vs = PiVideoStream((1920, 1088)).start()
time.sleep(1)
#time.sleep(3)
runVideo = True
#vs.SetParam()
while (runVideo == True):
    #for i in range(0,3):
    frame = vs.readCropped(20, 36, 44, 15)
    #frame = vs.read()
    #qprint("shape:",frame.shape[:2])
    cv2.imshow('Test', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        runVideo = False
        break
    time.sleep(0.1)
    #runVideo=False
Esempio n. 15
0
from constantes import *

#Load model
model = load_model(sys.argv[1])
print("Model loaded")

# Init engines and hat
i2c = busio.I2C(board.SCL, board.SDA)
hat = adafruit_pca9685.PCA9685(i2c)
kit = ServoKit(channels=16)

hat.frequency = 50
kit.servo[0].angle = 100
kit.servo[1].angle = 100    

vs = PiVideoStream().start()
time.sleep(2.0)

from PIL import Image
frame = vs.read()
img = Image.fromarray(frame)
img.save("test.png")

was_direction = 0

# Starting loop
print("Ready ! press CTRL+C to START/STOP :")

try:
    
    while True:
Esempio n. 16
0
# import the necessary packages
from pivideostream import PiVideoStream
import datetime
import imutils
import time
import cv2
import numpy as np

death = 0.0
temp = 0
counter = 0

cond = False

# initialize the video stream and allow the cammera sensor to warmup
vs = PiVideoStream(resolution=(320, 240), framerate=32)
vs.start()
time.sleep(2.0)

start_time = time.time()

while (True):
    elapsed_time = time.time() - start_time
    elap = time.strftime("%H:%M:%S", time.gmtime(elapsed_time))

    onset = time.time()

    # grab the frame from the threaded video stream and resize it
    # to have a maximum width of 400 pixels
    frame = vs.read()
    frame = imutils.resize(frame, width=400)
Esempio n. 17
0
def main():
    # create queues in shared memory so each process can access it
    mainQueue = Queue(maxsize=70)
    xyDoneQueue = Queue(maxsize=70)
    hudDoneQueue = Queue(maxsize=70)
    resizeDoneQueue = Queue(maxsize=70)

    # start VideoStream process
    vs = PiVideoStream(mainQueue, file1)
    time.sleep(1)  # allow pi camera to "warm up"
    vsP1 = Process(target=vs.update,
                   name='videoStreamProcess',
                   args=(resolution, framerate,
                         awb_mode))  # passing these parameters here because
    time.sleep(
        0.5
    )  # put some frames into mainQueue to stop other processes from throwing errors
    # passing to PiVideoStream instantiation causes pi camera to be accessed by two different processes which breaks it
    vsP1.daemon = True
    vsP1.start()

    # start ColorTracker process
    tracker = ColorTracker(mainQueue, xyDoneQueue, file2)  # pass shared queues
    trackerP1 = Process(target=tracker.update, name='trackerProcess', args=())
    trackerP1.daemon = True
    trackerP1.start()

    # start Hud process
    hud = Hud(resolution, xyDoneQueue, hudDoneQueue, file3, hud_done)
    hudP1 = Process(target=hud.draw, name='hudProcess', args=())
    hudP1.daemon = True
    hudP1.start()

    # start ResizeFrame process 1
    resize = ResizeFrame(hudDoneQueue,
                         resizeDoneQueue,
                         file4,
                         hud_done,
                         instance_name='resizer1')
    resizeP1 = Process(target=resize.resize, name='resizeProcess', args=())
    resizeP1.daemon = True
    resizeP1.start()

    # start ResizeFrame process 2
    resize2 = ResizeFrame(hudDoneQueue,
                          resizeDoneQueue,
                          file4B,
                          hud_done,
                          instance_name='resizer2')
    resizeP2 = Process(target=resize2.resize, name='resizeProcess2', args=())
    resizeP2.daemon = True
    resizeP2.start()

    # start DisplayFrame process
    display = DisplayFrame(resizeDoneQueue, file5, done)
    displayP1 = Process(target=display.show, name='displayProcess', args=())
    displayP1.daemon = True
    displayP1.start()

    while not done.is_set():
        continue

    else:
        print('Terminating processes')
        file1.close()
        file2.close()
        file3.close()
        file4.close()
        file4B.close()
        vsP1.terminate()
        trackerP1.terminate()
        hudP1.terminate()
        resizeP1.terminate()
        resizeP2.terminate()
        displayP1.terminate()
Esempio n. 18
0
    img1 = cv2.imread(fn1, 0)
    """
    camera = PiCamera()
    #camera.resolution = (640, 480)
    #camera.framerate = 32
    rawCapture = PiRGBArray(camera)
    #rawCapture = io.BytesIO()

    time.sleep(0.1)

    """

    # initialize the picamera stream and allow the camera
    # sensor to warmup
    stream = PiVideoStream(resolution=(640, 480), framerate=32)

    vs = stream.start()
    time.sleep(2.0)

    img1 = resize(img1, preferred_dimensions=(640, 480))

    kp = detector.detect(img1, None)

    kp, desc = compute.compute(img1, kp)

    count = 0
    start_time = timer()

    frame = vs.read()
Esempio n. 19
0
def main():
    pwm = PWM(0x40)
    pwm.setPWMFreq(100)
    vs = PiVideoStream(resolution=(640, 480)).start()
    time.sleep(1.0)
    frame = vs.read()
    prvs = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    hsv = np.zeros_like(frame)
    hsv[..., 1] = 255
    mode = 0
    speed = 0
    steer = 0

    while True:
        frame = vs.read()
        #frame = rotate_image(frame)
        next = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        if mode == 3:
            flow = cv2.calcOpticalFlowFarneback(prvs, next, 0.5, 3, 15, 3, 5,
                                                1.2, 0)
            mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1])
            hsv[..., 0] = ang * 180 / 3.14 / 2
            hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
            bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)

        cv2.putText(frame, "Speed: {}, Steer: {}".format(speed, steer),
                    (10, 20), cv2.FONT_HERSHEY_PLAIN, 1.0, (255, 0, 0))
        if mode == 1:
            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        if mode == 2:
            frame = cv2.Canny(frame, 20, 100)
        if mode == 3:
            cv2.imshow("Frame", bgr)
        else:
            cv2.imshow("Frame", frame)

        key = cv2.waitKey(1) & 0xFF
        if key == ord("q"):
            break
        if key == ord("f"):
            mode = 3
        if key == ord("e"):
            mode = 2
        if key == ord("g"):
            mode = 1
        if key == ord("c"):
            mode = 0
        if key == ord("l"):
            pwm.setPWM(0, 0, 500)
        if key == ord("r"):
            pwm.setPWM(0, 0, 300)
        if key == 81:  # left
            if steer > -1:
                steer = steer - 0.1
        if key == 83:  # right
            if steer < 1:
                steer = steer + 0.1
        if key == 82:  # up
            if speed < 1:
                speed = speed + 0.1
        if key == 84:  # down
            if steer > -1:
                speed = speed - 0.1
        if key == ord("s"):
            speed = 0
            steer = 0
        pwm.setPWM(0, 0, 500 + int(speed * 100))
        pwm.setPWM(2, 0, 670 - int(steer * 100))
        prvs = next

    cv2.destroyAllWindows()
    vs.stop()
Esempio n. 20
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
      '--model', help='File path of Tflite model.', required=True)
    parser.add_argument(
      '--dims', help='Model input dimension', required=True)
    args = parser.parse_args()

    #Set all input params equal to the input dimensions expected by the model
    mdl_dims = int(args.dims) #dims must be a factor of 32 for picamera resolution to work

    #Set max num of objects you want to detect per frame
    max_obj = 10
    engine = edgetpu.detection.engine.DetectionEngine(args.model)
    pygame.init()
    pygame.display.set_caption('Face Detection')
    screen = pygame.display.set_mode((mdl_dims, mdl_dims), pygame.DOUBLEBUF|pygame.HWSURFACE)
    pygame.font.init()
    fnt_sz = 18
    myfont = pygame.font.SysFont('Arial', fnt_sz)

    camera = picamera.PiCamera()
    strm_thread = PiVideoStream().start()
    strm_thread.rgbCapture = bytearray(strm_thread.camera.resolution[0] * strm_thread.camera.resolution[1] * 3)
    #Set camera resolution equal to model dims
    camera.resolution = (mdl_dims, mdl_dims)
    #rgb = bytearray(camera.resolution[0] * camera.resolution[1] * 3)
    camera.framerate = 30
    _, width, height, channels = engine.get_input_tensor_shape()
    x1, x2, x3, x4, x5 = 0, 50, 50, 0, 0
    y1, y2, y3, y4, y5 = 50, 50, 0, 0, 50
    z = 5
    last_tm = time.time()
    i = 0

    exitFlag = True
    while(exitFlag):
        for event in pygame.event.get():
             keys = pygame.key.get_pressed()
             if(keys[pygame.K_ESCAPE] == 1):
                exitFlag = False
        with picamera.array.PiRGBArray(camera, size=(mdl_dims, mdl_dims)) as stream:        
            #stream = io.BytesIO()
            start_ms = time.time()
            camera.capture(stream, use_video_port=True, format='rgb')
            elapsed_ms = time.time() - start_ms
            stream.seek(0)
            stream.readinto(stream.rgbCapture)
            #stream.truncate() #needed??
            img = pygame.image.frombuffer(stream.rgbCapture[0:
            (camera.resolution[0] * camera.resolution[1] * 3)],
            camera.resolution, 'RGB')
            input = np.frombuffer(stream.getvalue(), dtype=np.uint8)
            #Inference
            results = engine.DetectWithInputTensor(input, top_k=max_obj)
            stream.close()                                                                 
            if img:
                 screen.blit(img, (0,0))
                 if results:
                      num_obj = 0
                      for obj in results:
                           num_obj = num_obj + 1
                      for obj in results:
                           bbox = obj.bounding_box.flatten().tolist()
                           score = round(obj.score,2)
                           x1 = round(bbox[0] * mdl_dims)
                           y1 = round(bbox[1] * mdl_dims)
                           x2 = round(bbox[2] * mdl_dims)
                           y2 = round(bbox[3] * mdl_dims)
                           rect_width = x2 - x1
                           rect_height = y2 - y1
                           class_score = "%.2f" % (score)
                           ms = "(%d) %s%.2fms" % (num_obj, "faces detected in ", elapsed_ms*1000)
                           fnt_class_score = myfont.render(class_score, True, (0,0,255))
                           fnt_class_score_width = fnt_class_score.get_rect().width
                           screen.blit(fnt_class_score,(x1, y1-fnt_sz))
                           fnt_ms = myfont.render(ms, True, (255,255,255))
                           fnt_ms_width = fnt_ms.get_rect().width
                           screen.blit(fnt_ms,((mdl_dims / 2) - (fnt_ms_width / 2), 0))
                           bbox_rect = pygame.draw.rect(screen, (0,0,255), (x1, y1, rect_width, rect_height), 2)
                           #pygame.display.update(bbox_rect)
                 else:
                      elapsed_ms = time.time() - start_ms
                      ms = "%s %.2fms" % ("No faces detected in", elapsed_ms*1000)
                      fnt_ms = myfont.render(ms, True, (255,0,0))
                      fnt_ms_width = fnt_ms.get_rect().width
                      screen.blit(fnt_ms,((mdl_dims / 2) - (fnt_ms_width / 2), 0))

        pygame.display.update()

    pygame.display.quit()
Esempio n. 21
0
def main(argv):	
	#todo: crop xy threshold, pipette, mask, contours 
	use_gui=0
	simulate=0
	try: 
			opts, args =getopt.getopt(sys.argv[1:], "g:s:",["gui=","sim="])
	except getopt.GetoptError as err:
		usage()
		sys.exit(2)
	#print("opts: ",opts)
	#print("args: ",sys.argv[1:])
	if len(opts)<1:
		use_gui=0
		simulate=0
	for o,a, in opts:
		if o=="-g":
			use_gui=int(a)
		elif o=="-s":
			simulate=int(a)
		
	t_gui=Thread(target=guiThread)
	if use_gui>0: 
		t_gui.start()
	else:
		load_settings()
		#print("set guiCommands nogui:",guiCommands)
		guiCommands['previewRaw']=False
	if simulate==0:
		import RPi.GPIO as GPIO
		from pivideostream import PiVideoStream
		#vs = PiVideoStream((1296, 736)).start()
		vs = PiVideoStream((1920, 1088)).start()
		time.sleep(2)
	runVideo=True
	imageCounter=0
	#print("picSavePath: ",picSavePath)
	while (runVideo==True):
		#print("mainloop")
		runVideo=guiCommands['runVideo']
		if simulate==0:
			grabbedFrame = vs.readCropped(guiCommands['cropleft'],guiCommands['croptop'],guiCommands['cropright'],guiCommands['cropbottom'])
		else:
			grabbedFrame=cv2.imread("images/image_001.png", -1)
			#runVideo=False
		if guiCommands['takePic']==True and simulate==0:
			filename="images/image_"+str(imageCounter).zfill(3)+".png"
			cv2.imwrite(filename, grabbedFrame)
			imageCounter+=1
			guiCommands['takePic']=False
		Live=ContourOperations()
		frame_hsv= cv2.cvtColor(grabbedFrame,cv2.COLOR_BGR2HSV)
		lower_red=np.array([guiCommands['lowerhue'],guiCommands['lowersat'],guiCommands['lowerval']])
		upper_red=np.array([guiCommands['upperhue'],guiCommands['uppersat'],guiCommands['upperval']])
		mask=cv2.inRange(frame_hsv, lower_red, upper_red)
		filtered= cv2.bitwise_and(grabbedFrame, grabbedFrame, mask=mask)
		blue, green, red = cv2.split(grabbedFrame)
		background=cv2.imread("background/image_000.png", -1)
		#bluebg, greenbg, redbg = cv2.split(grabbedFrame)
		#redOnly=Live.computeRedMinusGB(grabbedFrame)
		#red_Threshold=Live.computeThreshold(redOnly, guiCommands['threshold'])
		#redThresContour=red_Threshold.copy()
		#contour_ext=Live.get_selected_contour(mask, 0)
		
		if guiCommands['previewRaw']==True: 
			cv2.imshow('All',grabbedFrame)
			cv2.imshow('Mask',mask)
			cv2.imshow('Filtered',filtered)
			#cv2.imshow('All-BG',cv2.subtract(grabbedFrame,background))
			#Live.showContour(grabbedFrame, contour_ext)
			#cv2.imshow('red',red_Threshold)
			#cv2.imshow('RedOnly',redOnly)
			'''
			red=Live.showRed(False)
			#print("Type grabbedFrame",grabbedFrame.dtype())
			green=Live.showGreen(False)
			blue=Live.showBlue(False)
			#cv2.imshow('Red-Green',red-green)
			#cv2.imshow('Red-Blue',red-blue)
			#cv2.imshow('Red-Blue-Green',red-blue-green)
			Live.showPixelValue(cv2.subtract(cv2.subtract(red,blue),green),60,95, 'r-b-g')
			Live.showPixelValue(red-blue,60,95, 'r-b')
			Live.showPixelValue(red,60,95, 'r')
			Live.showPixelValue(red-green,60,95, 'r-g')
			red[95][60]=red[95][60]-65
			Live.showPixelValue(red,60,95, 'r new')
			Live.showPixelValue(red-green,60,95, 'r-g new')
			'''
		else:
			cv2.destroyAllWindows()
		if cv2.waitKey(1) & 0xFF == ord('q'):
			runVideo=False
			break
Esempio n. 22
0
import requests
import json
import cv2
from pivideostream import PiVideoStream
import numpy as np
import base64

addr = 'http://192.168.0.6:5000'
test_url = addr + '/api/test'

content_type = 'image/jpeg'
headers = {'content-type': content_type}

video_capture = PiVideoStream().start()

while True:
    try:
        frame = video_capture.read()
        #print(frame)
        _, img_encoded = cv2.imencode('.jpg', frame)
        response = requests.post(test_url,
                                 data=img_encoded.tostring(),
                                 headers=headers)
        str_response = json.loads(response.text)
        arr = np.fromstring(base64.b64decode(
            str_response['message']['py/b64']),
                            dtype=np.uint8)
        img = cv2.imdecode(arr, -1)
        print(img)
        cv2.imshow('frame', img)
        if cv2.waitKey(1) & 0xFF == ord('q'):
Esempio n. 23
0

# DEBUG values
SET_GUI = False  # Do or do not show GUI
DEBUG_MOTORSPEED = False  # Do or do not write motor speed commands on console
DEBUG_TIMING = False  # Do or do not write how much time each processing step takes on console
DEBUG_CIRCLEPOS = True  # Do or do not write detected circle position on console

# Initialize the motor object
motor = mw.MyMotor("/dev/ttyACM0", 115200)
motor.pwm = 50

# initialize the camera
width = 320
height = 240
camera = PiVideoStream((width, height), 30).start()
counter = FPS()
counter.start()
# allow the camera to warmup capture frames from the camera
time.sleep(0.5)

# detection variables
posX = None  # X position
posX_prev = 0  # X position in the previous iteration
posY = None  # Y position
posX_exp_filter_coeff = 0.8  # The amount of how much the current measurement changes the position. [0,1]. current = alpha * measurement + (1-alpha) * previous
radius = None  # Circle radius
radius_prev = 0  # Previous circle radius
rad_exp_filter_coeff = 0.8  # The amount of how much the current measurement changes the radius. [0,1]. current = alpha * measurement + (1-alpha) * previous
speed = 0  # Speed to send to the motor controller
angleCorr = 0  # The difference between the two tracks so the robot turns
 def __init__(self, flip=False, fps=10, res=(160, 128)):
     self.vs = PiVideoStream(resolution=res, framerate=fps).start()
     self.flip = flip
     print("cam init")
     time.sleep(2.0)