コード例 #1
0
ファイル: imageFollower.py プロジェクト: tobybreckon/bee-wi
                    # Result
                    max_res_SIGN_FORWARD = np.amax(cv2.matchTemplate(crop_img,SIGN_FORWARD,cv2.TM_CCOEFF_NORMED))
                    max_res_SIGN_BACKWARD = np.amax(cv2.matchTemplate(crop_img,SIGN_BACKWARD,cv2.TM_CCOEFF_NORMED))

                    """ DETECTING SIGNS """
                    turn_angle = circle_x
                    while turn_angle > 160:
                        turn_angle -= 160
                    turn_angle = 100 - int(round((float(turn_angle)/160)*100))
                    
                    if max_res_SIGN_FORWARD >= max_res_SIGN_BACKWARD and max_res_SIGN_FORWARD >= MATCH_THRESHOLD:
                        # Turn towards it
                        if circle_x > 170:
                            print 'circle_x', circle_x, 'turning right', turn_angle
                            buggy.turnRight(turn_angle)
                        elif circle_x < 150:
                            print 'circle_x', circle_x, 'turning left', turn_angle
                            buggy.turnLeft(turn_angle)
                        # Change Status
                        moving_status = "forward"
                        
                    elif max_res_SIGN_BACKWARD >= max_res_SIGN_FORWARD and max_res_SIGN_BACKWARD >= MATCH_THRESHOLD:
                        # Turn away from it
                        if circle_x > 170:
                            print 'circle_x', circle_x, 'turning left', turn_angle
                            buggy.turnLeft(turn_angle)
                        elif circle_x < 150:
                            print 'circle_x', circle_x, 'turning right', turn_angle
                            buggy.turnRight(turn_angle)
                        # Change Status
コード例 #2
0
ファイル: imageFollower.py プロジェクト: tobybreckon/bee-wi
                                          cv2.TM_CCOEFF_NORMED))
                    max_res_SIGN_BACKWARD = np.amax(
                        cv2.matchTemplate(crop_img, SIGN_BACKWARD,
                                          cv2.TM_CCOEFF_NORMED))
                    """ DETECTING SIGNS """
                    turn_angle = circle_x
                    while turn_angle > 160:
                        turn_angle -= 160
                    turn_angle = 100 - int(
                        round((float(turn_angle) / 160) * 100))

                    if max_res_SIGN_FORWARD >= max_res_SIGN_BACKWARD and max_res_SIGN_FORWARD >= MATCH_THRESHOLD:
                        # Turn towards it
                        if circle_x > 170:
                            print 'circle_x', circle_x, 'turning right', turn_angle
                            buggy.turnRight(turn_angle)
                        elif circle_x < 150:
                            print 'circle_x', circle_x, 'turning left', turn_angle
                            buggy.turnLeft(turn_angle)
                        # Change Status
                        moving_status = "forward"

                    elif max_res_SIGN_BACKWARD >= max_res_SIGN_FORWARD and max_res_SIGN_BACKWARD >= MATCH_THRESHOLD:
                        # Turn away from it
                        if circle_x > 170:
                            print 'circle_x', circle_x, 'turning left', turn_angle
                            buggy.turnLeft(turn_angle)
                        elif circle_x < 150:
                            print 'circle_x', circle_x, 'turning right', turn_angle
                            buggy.turnRight(turn_angle)
                        # Change Status
コード例 #3
0
ファイル: pathFollower.py プロジェクト: tobybreckon/bee-wi
             # If more than MAX, go with average
             if len(arrow_buffer) >= MAX_RECOGNISING_COUNT:
                 print "Taking average arrow direction...", arrow_buffer
                 best_arrow = mean(arrow_buffer)
                 # Follow arrow
                 moving_forward, wheel_direction, confident_match, arrow_buffer = follow_arrow_direction(best_arrow, moving_forward, wheel_direction, arrow_buffer)
                 buggy.clearBuffer() # Moved, so clear the buffer
             else:
                 if len(arrow_buffer) == 1:
                     print "Learning direction of arrow..."
                 wait_once = True
         else:
             # Move towards sign
             print "Moving towards sign..."
             if circle_x > 160:
                 buggy.turnRight((circle_x/320)*100)
             else:
                 buggy.turnLeft((circle_x/160)*100)
             creep_once, moving_forward = True, False
 else:
     # Move towards largest contour
     # Countours (already threshed)
     contours, hierarchy = cv2.findContours(Chroma_red, cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
     # Find the index of the largest contour
     areas = [cv2.contourArea(c) for c in contours]
     if areas:
         max_index = np.argmax(areas)
         cnt = contours[max_index]
         # Straight Bounding Rectangle
         x,y,w,h = cv2.boundingRect(cnt)
         center_x = x + w/2