Esempio n. 1
0
def capture_color1color2(c):
    color1Pix = mult_rect(c["calibration.game_coords"], c["calibration.pct.color1"])
    color1Img = captureArea(color1Pix)

    color2Pix = mult_rect(c["calibration.game_coords"], c["calibration.pct.color2"])
    color2Img = captureArea(color2Pix)

    return color1Img, color2Img
Esempio n. 2
0
def capture_split_digits(c):
    scorePix = mult_rect(c["calibration.game_coords"], c["calibration.pct.score"])
    linesPix = mult_rect(c["calibration.game_coords"], c["calibration.pct.lines"])
    levelPix = mult_rect(c["calibration.game_coords"], c["calibration.pct.level"])

    scoreImg = captureArea(scorePix)
    linesImg = captureArea(linesPix)
    levelImg = captureArea(levelPix)

    return scoreImg, linesImg, levelImg
Esempio n. 3
0
def capture_das_trainer(c):
    currentPiecePix = mult_rect(c["calibration.game_coords"],
                                c["calibration.pct.das.current_piece"])
    currentPieceImg = captureArea(currentPiecePix)

    currentPieceDasPix = mult_rect(c["calibration.game_coords"],
                                   c["calibration.pct.das.current_piece_das"])
    currentPieceDasImg = captureArea(currentPieceDasPix)

    instantDasPix = mult_rect(c["calibration.game_coords"],
                              c["calibration.pct.das.instant_das"])
    instantDasImg = captureArea(instantDasPix)

    return currentPieceImg, currentPieceDasImg, instantDasImg
Esempio n. 4
0
def get_window_areas():
    mapping = {
        "score": config["calibration.pct.score"],
        "lines": config["calibration.pct.lines"],
        "level": config["calibration.pct.level"],
        "field": config["calibration.pct.field"],
        "black_n_white": config["calibration.pct.black_n_white"],
        "stats2": config.stats2_percentages,
        "preview": config["calibration.pct.preview"],
        "flash": config["calibration.pct.flash"],
        # das trainer
        "current_piece": config["calibration.pct.das.current_piece"],
        "current_piece_das": config["calibration.pct.das.current_piece_das"],
        "instant_das": config["calibration.pct.das.instant_das"],
    }

    base_map = {
        key: xywh_to_ltrb(mult_rect(config["calibration.game_coords"], value))
        for key, value in mapping.items()
    }

    # stats are handled in a special manner
    base_map["stats"] = {
        piece: xywh_to_ltrb(coords)
        for (piece, coords) in generate_stats(
            config["calibration.game_coords"],
            config["calibration.pct.stats"],
            config["calibration.pct.score"][3],
        ).items()
    }

    # calibration of the color blocks include the edges (black),
    # and some of the "shine" white pixels
    # For the stats pieces, the color is in the lower-right quadrant of the piece block
    for color in ("color1", "color2"):
        x, y, w, h = mult_rect(config["calibration.game_coords"],
                               config["calibration.pct." + color])

        xywh = (
            x + floor(w * 0.5),
            y + floor(h * 0.5),
            ceil(w * 0.4),
            ceil(h * 0.4),
        )

        base_map[color] = xywh_to_ltrb(xywh)

    return base_map
Esempio n. 5
0
def capture_blackwhite(c):
    blackWhitePix = mult_rect(
        c["calibration.game_coords"], c["calibration.pct.black_n_white"]
    )
    blackWhiteImg = captureArea(blackWhitePix)

    return blackWhiteImg
Esempio n. 6
0
def autoAdjustRectangle(capture_coords, rect, numDigits):
    # we can only run multi-thread on certain frameworks.
    if config["calibration.capture_method"] in ["OPENCV", "FILE"]:
        multi_thread = False
    else:
        multi_thread = True

    if multi_thread:
        p = multiprocessing.Pool()

    lowestScore = None
    # lowestOffset = None
    bestRect = None
    pattern = "D" * numDigits
    left, right = -3, 4
    results = []
    total = (right - left)**4
    i = 0
    for x in range(left, right):
        for y in range(left, right):
            for w in range(left, right):
                for h in range(left, right):
                    newRect = (
                        rect[0] + x * 0.001,
                        rect[1] + y * 0.001,
                        rect[2] + w * 0.001,
                        rect[3] + h * 0.001,
                    )
                    pixRect = mult_rect(capture_coords, newRect)
                    if multi_thread:
                        results.append(
                            p.apply_async(adjustTask,
                                          (pixRect, pattern, newRect)))
                    else:  # run directly.
                        results.append(adjustTask(pixRect, pattern, newRect))
                        progressBar(i, total)
                    i += 1

    for (i, r) in enumerate(results):
        if multi_thread:
            result, newRect = r.get()
        else:
            result, newRect = r
        progressBar(i, total)
        if result is not None:
            if lowestScore is None or result < lowestScore:
                bestRect = newRect
                lowestScore = result

    if multi_thread:
        p.close()
        p.join()

    return bestRect
Esempio n. 7
0
def generate_stats(captureCoords, statBoxPerc, statHeight, do_mult=True):
    statGap = (statBoxPerc[3] - (7 * statHeight)) / 6
    statGap = statGap + statHeight
    offsets = [i * (statGap) for i in range(7)]
    pieces = ["T", "J", "Z", "O", "S", "L", "I"]
    result = {}
    for i, piece in enumerate(pieces):
        offset = offsets[i]
        box = (statBoxPerc[0], statBoxPerc[1] + offset, statBoxPerc[2],
               statHeight)
        if do_mult:
            result[piece] = mult_rect(captureCoords, box)
        else:
            result[piece] = box
    return result
Esempio n. 8
0
def auto_adjust_numrect(capture_coords, rect, numDigits, updateUI):

    pattern = "D" * numDigits

    i = 0

    NES_WIDTH = 256.0
    NES_HEIGHT = 224.0
    NES_SUB_PIXELS = 4  # how accurate are we?
    NES_FULL_PIXELS = 3  # how far do we search?
    SUB_PIXEL_PERC = 1.0 / NES_SUB_PIXELS
    left = (-1 // NES_SUB_PIXELS) * NES_FULL_PIXELS
    right = -left + 1
    total = (right - left) ** 4

    stock_img = captureArea(None, None)
    lowestScore = None
    bestRect = None
    # adjust rect by up to NES_FULL_PIXELS in any direction,
    # accurate to NES_SUB_PIXELS
    for x in range(left, right):
        for y in range(left, right):
            for w in range(left, right):
                for h in range(left, right):
                    newRect = (
                        rect[0] + x * SUB_PIXEL_PERC / NES_WIDTH,
                        rect[1] + y * SUB_PIXEL_PERC / NES_HEIGHT,
                        rect[2] + w * SUB_PIXEL_PERC / NES_WIDTH,
                        rect[3] + h * SUB_PIXEL_PERC / NES_HEIGHT,
                    )
                    pixRect = mult_rect(capture_coords, newRect)
                    result = adjust_task(pixRect, pattern, newRect, stock_img)
                    i += 1
                    print_progress(i, total)
                    updateUI(i / float(total))

                    lowestScore, bestRect = track_best_result(
                        lowestScore, bestRect, result
                    )

    return bestRect
Esempio n. 9
0
def capture_preview(c):
    previewPix = mult_rect(c["calibration.game_coords"],
                           c["calibration.pct.preview"])
    previewImg = captureArea(previewPix)
    return previewImg