Exemple #1
0
#Allowable width/height error, measured in boxes
WH_ERROR = 0.35
#Allowable area error from W*H, measured in percentage/100.
AREA_ERROR = 0.35
#Spacing between boxes for both x and y directions, measured in boxes.
BOX_SPACING = 0.35
#Allowable spacing error for both x and y directions, measured in boxes
SPACING_ERROR = 0.35
#The x offset of center, in pixels, created by the position of the camera on the robot.
CENTER_OFFSET_X = 0
#The dimensions of the image.
IMAGE_DIMENSIONS = [240, 180]

kernel = numpy.ones((3, 3), numpy.uint8)  #used to do dialate
video = pistream.PiVideoStream((IMAGE_DIMENSIONS[0],IMAGE_DIMENSIONS[1])).start()
time.sleep(2)

def findPattern(contours, standard):
    #The standard contour properties, defined by the current baseline contour (assumed the top-middle square in the pattern)
    stX, stY, stH, stW = cv2.boundingRect(contours[standard])    #Whether or not contours have been verified for the bottom left and right positions of the pattern.
    signHeight = None
    leftVerified = False
    rightVerified = False
    turnError = 0
    distance = 0
    global pattern
        
    #Cycle through all contours and check against position and congruency relative to standard contour.
    counter = 0
    while counter < len(contours):
import pistream
from picamera.array import PiRGBArray
from picamera import PiCamera
import cv2
import time
import numpy

LOWER_HSV = numpy.array([111, 117, 142])
UPPER_HSV = numpy.array([180, 255, 255])

video = pistream.PiVideoStream((240, 180)).start()
time.sleep(0.5)
while True:
    image = video.read()
    cv2.imshow('Image', image)
    imageHSV = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    imageThresh = cv2.inRange(imageHSV, LOWER_HSV, UPPER_HSV)
    cv2.imshow('Threshhold', imageThresh)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.imwrite('/home/pi/FollowBot/capture.jpg', image,
                    [cv2.IMWRITE_JPEG_QUALITY, 90])
        break
Exemple #3
0
GOAL_RATIO = 25.0 / 55.0  #Retroreflective tape Height/Width (pixel counted from camera view)
GOAL_MINIMUM_AREA = 50  #The smallest number of pixel area that a goal should be
GOAL_MAXIMUM_AREA = 550
GOAL_RATIO_ERROR = 0.20  #Allowable error from ratio
GOAL_CENTER = 129  #X position within camera frame where we need to center goal
GOAL_CENTER_ERROR = 4  #Allowable error from center, in pixels.

#Parameters for robot turning speed
TURN_SCALE = 0.01  #Multiplier to determine turn rate, given error from center in pixels that will determine the robot turn rate
TURN_MAX_RATE = 0.9  #Fastest turn rate allowed
TURN_MIN_RATE = 0.55  #was .7 Slowest turn rate allowed

# Setup PiCamera for capture
IMG_WIDTH = 240
IMG_HEIGHT = 180
video = pistream.PiVideoStream((IMG_WIDTH, IMG_HEIGHT)).start()
time.sleep(2)  #Give camera a chance to stablize

# Connect to roboRio via NetworkTable
NetworkTable.setIPAddress("10.45.64.2")
NetworkTable.setClientMode()
NetworkTable.initialize()

table = NetworkTable.getTable("visionTracking")


# Based on the error from target center, in pixels, this function will
# calculate the appropriate rate at which the robot should turn.
def calcTurnRate(error):
    # Determine magnitude of turn using the scale factor
    absRate = abs(error) * TURN_SCALE
Exemple #4
0
import pistream
import cv2
imageCounter = 0

# Setup PiCamera for capture
IMG_WIDTH = 240
IMG_HEIGHT = 180

try:
    video = pistream.PiVideoStream((IMG_WIDTH, IMG_HEIGHT),
                                   format="bgr").start()

    while raw_input("Enter to capture or 'q' to quit") != "q":
        image = video.read()
        cv2.imwrite("captures/image" + str(imageCounter) + ".jpg", image,
                    [cv2.IMWRITE_JPEG_QUALITY, 90])
        print "saved image " + str(imageCounter)
        imageCounter += 1

finally:
    video.stop()