Esempio n. 1
0
def _get_roi(size, ratio=0.42, position='tl'):
    '''
    根据缩放比计算指定的举行区域的坐标

    Parameters
    :param size: 图像大小
    :param ratio: 缩放比
    :param position: 缩放方式
    '''
    width, height = Util.round_int(size[0] * ratio), Util.round_int(size[1] *
                                                                    ratio)

    if position == 'tl':
        x, y = 0, 0
    elif position == 'tr':
        x, y = size[0] - width, 0
    elif position == 'bl':
        x, y = 0, size[1] - height
    elif position == 'br':
        x, y = size[0] - width, size[1] - height

    return (x, y, width, height)
Esempio n. 2
0
def _get_tip_position(array, contour, verbose=False):
    approx_contour = cv2.approxPolyDP(contour,
                                      0.08 * cv2.arcLength(contour, True),
                                      True)
    convex_points = cv2.convexHull(approx_contour, returnPoints=True)

    cx, cy = 999, 999

    for point in convex_points:
        cur_cx, cur_cy = point[0][0], point[0][1]

        if verbose:
            cv2.circle(array, (cur_cx, cur_cy), 4, _COLOR_GREEN, 4)

        if (cur_cy < cy):
            cx, cy = cur_cx, cur_cy

    (screen_x, screen_y) = pyautogui.size()

    height, width, _ = array.shape
    x = Util.round_int((float(cx)) / (width - 0) * (screen_x + 1))
    y = Util.round_int((float(cy)) / (height - 0) * (screen_y + 1))
    return (array, (x, y))