示例#1
0
def checkColor(image):
    count=0
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, (36, 25, 25), (70, 255,255))
    res = cv2.bitwise_and(image,image, mask=mask)
    ret,thrshed = cv2.threshold(cv2.cvtColor(res,cv2.COLOR_BGR2GRAY),3,255,cv2.THRESH_BINARY)
    _,contours,hier = cv2.findContours(thrshed,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
    for cnt in contours:
        area = cv2.contourArea(cnt)
        if area >10000:
            print('object found')
            gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
            corners()
            cv2.putText(image, 'Green Object Detected', (10,80), cv2.FONT_HERSHEY_SIMPLEX, 1.0,(255, 255, 255),lineType=cv2.LINE_AA)
            cv2.rectangle(image,(5,40),(400,100),(0,255,255),2)
            count+=1
    print('count', count)
    if count==10:
        gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
        a=corners(gray)
        j=0
        while j<20:
            dr.goCustom(90,90)
            j+=1
            n=0
            while n<1:
                dr.stop(2)
                if a =='Left':
                    dr.left()
                else:
                    dr.right()
                n=n+1
示例#2
0
def turn(direction):
    if direction == 'Left':
        dr.left()
        print('Turning left')
    if direction == 'Right':
        dr.right()
        print('Turning right')
示例#3
0
def turn_motion(direction):
    if direction=="Left":
        dr.left()
    elif direction=="Right":
        dr.right()
    else:
        pass
示例#4
0
def turn(direction):
    if direction == 'Left':
        stop(3)
        dr.goStraight()
        time.sleep(2)
        dr.stop(1)
        dr.left()
        #print('Turning left')
    if direction == 'Right':
        stop(3)
        dr.goStraight()
        time.sleep(2)
        dr.stop(1)
        dr.right()
示例#5
0
    def tick(self):
        pacmanLoc = self.coordinates
        pacman = self.game.getPacman()
        if (pacman):
            pacmanLoc = pacman.coordinates

        if (self.panicked() is True):
            self.direction = avoid(self.coordinates, pacmanLoc)
            self.panicLevel -= 1

        front = self.direction
        directions = [front, left(front), right(front)]
        choices = []
        for option in directions:
            if self.clear(self.nextMove(option)):
                choices.append(option)
        if len(choices) > 0:
            self.direction = choices[randint(0, len(choices)-1)]
        elif self.panicked() is False:
            self.direction = opposite(front)

        nextLocation = self.nextMove(self.direction)
        if ((self.panicLevel % 2) == 0) and self.clear(nextLocation):
            self.coordinates = (nextLocation)

        if (self.game.isPacman(self.coordinates)):
            if (self.panicked() is True):
                self.game.killGhost(self)
            else:
                self.game.killPacman()
        if (self.game.isGate(self.coordinates)):
            self.passedGate = True
        self.icon = Ghost.iconByState[self.panicLevel > 0]
示例#6
0
 def handleKey(self, event):
     if event.key == pygame.K_LEFT:
         self.decision = direction.left()
     elif event.key == pygame.K_RIGHT:
         self.decision = direction.right()
     elif event.key == pygame.K_DOWN:
         self.decision = direction.down()
     elif event.key == pygame.K_UP:
         self.decision = direction.up()
示例#7
0
import RoboPiLib as RPL
import setup
import direction

print('Type "stop" to stop the motors and then type "exit" to close the program')

while True:
  usrin = input(' ')
  
  if usrin == 'w':
    direction.front()
  elif usrin == 's':
    direction.back()
  elif usrin == 'a':
    direction.left()
  elif usrin == 'd':
    direction.right()
  elif usrin == 'stop':
    direction.stop
  else:
    print('please input a w,a,s,d,stop,exit')
示例#8
0
import RoboPiLib as RPL
import setup
import direction
apin = PIN  #right side

while True:
    analog = RPL.analogRead(apin)
    if analog >= 300 and analog <= 400:
        direction.front(10)
    elif analog > 400:
        direction.left(7)
    elif analog < 300:
        direction.right(7)
                                    1,
                                    np.pi / 180,
                                    50,
                                    np.array([]),
                                    minLineLength=20,
                                    maxLineGap=50)
            averaged_lines, distances = average_slope_intercept(
                lane_image, lines)
            line_image = display_lines(lane_image, averaged_lines)
            combo_image = cv2.addWeighted(lane_image, 0.8, line_image, 1, 1)
            cv2.imshow("Result", combo_image)
            check_turning(distances)
            i += 1
            print(i)
        except:
            cv2.imshow("Result", image)
            dr.goCustom(60, 75)
            i -= 1
            print(i)

        if cv2.waitKey(10) & 0xFF == ord('q'):
            cap.release()
            cv2.destroyAllWindows()
            break

    i = 0
    dr.stop(1)
    dr.right()
    #dr.goStraight()

cv2.waitKey(0)
示例#10
0
 def __init__(self, x=5, y=3, length=3):
     self.direction = direction.right()
     self.body = []
     self.growLength = 0
     for i in range(0, length):
         self.body.append((x - i, y))
示例#11
0
import RoboPiLib as RPL
import setup
import direction

apin = 7  #place the analog sensor on the front right

while True:
    sense = RPL.analogRead(apin)
    if sense >= 400:
        direction.right(4)
    else:
        direction.front(0)