コード例 #1
0
def sun_percent(testing=False):
    left = 0
    top = 0
    right = 1600
    bottom = 700
    screen = get_screen(left,top,right,bottom)
    screen = scaleImage(screen,5) #reduce the resolution, not image data is needed
    filtered = filter_sun(screen,testing=testing)
    white = sum(filtered == 255)
    black = sum(filtered != 255)
    result = white / black
    return result * 100
コード例 #2
0
def getSpectrumOffset(testing=False):

    left = 458
    top = 598
    right = 961
    bottom = 628

    screen = get_screen(left, top, right, bottom)
    height = right - top
    width = right - left

    spots = filter_Signals(screen)
    curser = filter_Curser(screen)

    scanLine = 7

    x1 = 0
    curserPos = 0
    spotPos = 0

    for i in range(1, width):
        if (curser[scanLine][i] == 255):
            screen = cv2.line(screen, (i, 0), (i, height), (0, 255, 0, 1))
            curserPos = i
            break
    for i in range(1, width):
        if (spots[scanLine][i] == 255 and spots[scanLine][i - 1] == 0):
            x1 = i
        if (spots[scanLine][i] == 0 and spots[scanLine][i - 1] != 0):
            x2 = i
            CenterX = int((x2 - x1) / 2) + x1
            spotPos = CenterX
            screen = cv2.line(screen, (CenterX, 0), (CenterX, height),
                              (0, 0, 255), 1)
            break

    screen = cv2.line(screen, (curserPos, int(height / 2)),
                      (spotPos, int(height / 2)), (255, 0, 0), 1)
    offset = curserPos - spotPos

    # print(curser)

    # if testing:
    cv2.line(screen, (pt, 0), (pt, height), (0, 0, 255), 1)
    show_immage('Spectrum', screen)
    show_immage('Spectrum spots', spots)
    show_immage('Spectrum curser', curser)

    return offset
コード例 #3
0
def get_destination_offset(testing=True, close=None):

    pt = (0, 0)

    left = 300
    top = 200
    right = 1300
    bottom = 700

    width = right - left
    height = bottom - top

    centerx = int((1 / 2) * width)
    centery = int((1 / 2) * height)

    screen = get_screen(left, top, right, bottom)
    mask_orange = filter_orange2(screen)

    match = cv2.matchTemplate(mask_orange, destination_template,
                              cv2.TM_CCOEFF_NORMED)
    show_immage('Destination match', scaleImage(match, 50))

    threshold = 0.2
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(match)
    pt = (0, 0)
    if max_val >= threshold:
        pt = max_loc

    final_x = int((pt[0] + ((1 / 2) * destination_width)) - ((1 / 2) * width))
    final_y = int(((1 / 2) * height) - (pt[1] +
                                        ((1 / 2) * destination_height)))

    endx = int((pt[0] + ((1 / 2) * destination_width)))
    endy = int((pt[1] + ((1 / 2) * destination_height)))
    result = {'x': final_x, 'y': final_y}
    # if testing:
    cv2.rectangle(screen, pt,
                  (pt[0] + destination_width, pt[1] + destination_height),
                  (0, 0, 255), 2)
    if (not close == None):
        cv2.rectangle(screen, (centerx - close['x'], centery - close['y']),
                      (centerx + close['x'], centery + close['y']),
                      (255, 0, 0), 2)
    cv2.line(screen, (centerx, centery), (endx, endy), (0, 255, 0), 2)
    show_immage('Destination Found', scaleImage(screen, 50))
    show_immage('Destination Mask', scaleImage(mask_orange, 50))
    return result
コード例 #4
0
def get_compass_image(testing=False):

    doubt = 7

    left = 530
    top = 610
    right = 720
    bottom = 800

    screenWidth = right - left

    screen = get_screen(left, top, right, bottom)
    mask_orange = filter_orange(screen, testing=testing)
    # mask_orange = equalize(screen,testing=testing)
    # justCompass = cv2.bitwise_and(screen, screen, mask=mask_orange)

    match = cv2.matchTemplate(mask_orange, compass_template,
                              cv2.TM_CCOEFF_NORMED)
    show_immage('Compass match', match)

    threshold = 0.2
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(match)
    pt = (0, 0)
    if max_val >= threshold:
        pt = max_loc
        compass_image = screen[pt[1] - doubt:pt[1] + compass_height + doubt,
                               pt[0] - doubt:pt[0] + compass_width +
                               doubt].copy()
        if compass_image.size == 0:
            compass_image = cv2.cvtColor(compass_template.copy(),
                                         cv2.COLOR_GRAY2BGR)
    else:
        compass_image = cv2.cvtColor(compass_template.copy(),
                                     cv2.COLOR_GRAY2BGR)

    # if testing:
    cv2.rectangle(screen, pt, (pt[0] + compass_width, pt[1] + compass_height),
                  (0, 0, 255), 2)
    # showHSV('justCompass', justCompass)
    show_immage('Compass Found', screen)
    show_immage('Compass Mask', mask_orange)

    return compass_image, compass_width + (2 * doubt), compass_height + (2 *
                                                                         doubt)
コード例 #5
0
def getAltitude(testing=True):

    left = 935
    top = 320
    right = 1150
    bottom = 620

    screen = get_screen(left,top,right,bottom)
    # screen = cv2.imread(resource_path("examples/altitude.png"))
    # screen = screen[300:600, 900:1100]

    mask_Altidude = filterAltidude(screen)

    # if ship()['status'] == 'in_orbitalcruise' or ship()['status'] == 'in_glide':
    #
    #     points = getaltLinePoints(mask_Altidude,screen)
    #
    #     screen = cv2.circle(screen,points[0],2,(128,0,0),2)
    #     screen = cv2.circle(screen,points[-1],2,(128,0,0),2)
    #     screen = cv2.line(screen,points[0],points[-1],(128,0,0),2)

    show_immage('screen', screen)
    show_immage('mask_Altidude', mask_Altidude)