示例#1
0
def red_detect(frame):  # オレンジ色を検出し、画像加工を施す。
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    lower = (0, 230, 150)
    upper = (30, 255, 255)
    red = cv2.inRange(hsv, lower, upper)
    kernal = np.ones((5, 5), "uint8")
    red = cv2.dilate(red, kernal)
    res = cv2.bitwise_and(frame, frame, mask=red)
    (ret, contours, hierarchy) = cv2.findContours(
        red, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    x = 0
    y = 0
    w = 0
    h = 0
    for pic, contour in enumerate(contours):
        area = cv2.contourArea(contour)
        if (area > 100):
            x, y, w, h = cv2.boundingRect(contour)
            frame = cv2.rectangle(
                frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
            cv2.putText(frame, "RED color", (x, y),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255))
            cv2.drawMarker(frame, (480, 350), (255, 255, 0),
                           markerType=cv2.MARKER_SQUARE, markerSize=5, thickness=10)
            cv2.drawMarker(frame, ((x + w//2), (y + h//2)), (255, 255, 0),
                           markerType=cv2.MARKER_SQUARE, markerSize=5, thickness=10)
            cv2.arrowedLine(frame, (480, 350),
                            ((x + w//2), (y + h//2)), (255, 0, 0), 5)
            cv2.rectangle(frame, (330, 200), (630, 500), (0, 255, 0), 1)
    return frame, x, y, w, h  # 動画データとピクセル(x,y,z,h)を返す
示例#2
0
def draw_points(img, points):
    result_img = img.copy()

    for point in points:
        position = (int(point[0]), int(point[1]))
        cv.drawMarker(img=result_img,
                      position=position,
                      color=GREEN_COLOR,
                      markerType=cv.MARKER_TILTED_CROSS,
                      markerSize=20,
                      thickness=2,
                      line_type=cv.LINE_AA)

    return result_img
示例#3
0
文件: dss.py 项目: rusagent/TFT-DSS
def draw_rectangles_show_points_show_buttons_reset_counters(
    rgb_colours_list_,
    champions_list_for_ocr_,
    origin_champs_counters_to_buy_,
    reader_,
    champions_list_,
    tk_window,
    origin_champs_counters_,
    df_,
    origin_list_,
    origin_counters_,
    class_list_,
    class_counters_,
    mode="points",
    CARDS_TO_BUY_AMOUNT_=CARDS_TO_BUY_AMOUNT,
    LINE_TYPE_=LINE_TYPE,
    MARKER_TYPE_=MARKER_TYPE,
):
    """
    This function is making OCR detection on champion cards, and then draws by
    input mode like default points on screenshot.

    Parameters
    ----------
    rgb_colours_list_ : ["worst", "medium3", "medium2", "medium1", "best"]. list of RGB tuples.
    The default is rgb_colours_list.
    mode :  The default is "points". Also there are cross and rectangle.

    Returns
    -------
    None.

    """
    logging.debug(
        "Function draw_rectangles_show_points_show_buttons_reset_counters() called"
    )
    reset_counters_in_list(origin_champs_counters_to_buy_)
    (
        list_of_champs_to_buy_this_turn,
        index_list,
    ) = update_champions_to_buy_from_ocr_detection(
        champions_list_for_ocr_, origin_champs_counters_to_buy_, reader_)

    champions_to_buy_in_order_as_in_screen = list_of_champs_to_buy_this_turn
    champions_to_buy_points_and_position = show_nonzero_counters_with_points_from_ocr(
        tk_window,
        origin_champs_counters_,
        origin_champs_counters_to_buy_,
        champions_list_,
        df_,
        index_list,
        origin_list_,
        origin_counters_,
        class_list_,
        class_counters_,
    )

    champions_position_to_buy_ordered_by_screen = [
        champions_list_for_ocr_.index(i)
        for i in champions_to_buy_in_order_as_in_screen
    ]
    logging.info(
        "champions_position_to_buy_ordered_by_screen: %s",
        champions_position_to_buy_ordered_by_screen,
    )

    champions_to_buy_points = list(
        zip(*champions_to_buy_points_and_position))[0]
    champions_to_buy_position = list(
        zip(*champions_to_buy_points_and_position))[1]
    logging.info("Points (in alphabetical by champ name order?): %s",
                 champions_to_buy_points)
    logging.info(
        "Champions position (in alphabetical by champ name order?): %s",
        champions_to_buy_position,
    )
    sorted_champions_to_buy_points_and_position = sorted(
        champions_to_buy_points_and_position)
    logging.info(
        "Points and Champions position (in alphabetical by champ name order?): %s",
        sorted_champions_to_buy_points_and_position,
    )
    sorted_champions_to_buy_position = list(
        zip(*sorted_champions_to_buy_points_and_position))[1]
    logging.info(
        "sorted_champions_to_buy_position in alphabetical order?: %s",
        sorted_champions_to_buy_position,
    )
    values_by_points_indexes_order_by_position_on_screen = [
        sorted_champions_to_buy_position.index(i)
        for i in champions_position_to_buy_ordered_by_screen
    ]
    logging.info(
        "values_by_points_indexes_order_by_position_on_screen 0 worst 4 best card: %s",
        values_by_points_indexes_order_by_position_on_screen,
    )
    cards_rectangles = build_list_of_champion_cards_rectangles()
    screenshot = make_cropped_ss()[1]

    # at the end
    # values_by_points_indexes_order_by_position_on_screen contains champions
    # sorted by points from lowest(0) to highest(4)
    # and indexes represents champion placement on the screen

    if mode == "rectangle":
        for i in range(0, CARDS_TO_BUY_AMOUNT_):
            cv.rectangle(
                screenshot,
                cards_rectangles[i][0],
                cards_rectangles[i][1],
                color=rgb_colours_list_[
                    values_by_points_indexes_order_by_position_on_screen[i]],
                lineType=LINE_TYPE_,
                thickness=2,
            )
        cv.imshow("draw_rectangles_show_points_show_buttons_reset_counters()",
                  screenshot)
    elif mode == "cross":
        for i in range(0, CARDS_TO_BUY_AMOUNT_):
            # Draw the center point
            cv.drawMarker(
                screenshot,
                cards_rectangles[i][2],
                color=rgb_colours_list_[
                    values_by_points_indexes_order_by_position_on_screen[i]],
                markerType=MARKER_TYPE_,
                markerSize=40,
                thickness=2,
            )
        cv.imshow("draw_rectangles_show_points_show_buttons_reset_counters()",
                  screenshot)
    elif mode == "points":
        for i in range(0, CARDS_TO_BUY_AMOUNT_):
            # Draw the center point
            cv.putText(
                screenshot,
                "{:.3f}".format(sorted_champions_to_buy_points_and_position[
                    values_by_points_indexes_order_by_position_on_screen[i]]
                                [0]),
                cards_rectangles[i][2],
                cv.FONT_HERSHEY_SIMPLEX,
                0.6,
                rgb_colours_list_[
                    values_by_points_indexes_order_by_position_on_screen[i]],
                2,
            )
        cv.imshow("draw_rectangles_show_points_show_buttons_reset_counters()",
                  screenshot)

    logging.debug(
        "Function draw_rectangles_show_points_show_buttons_reset_counters() end"
    )
示例#4
0
 def mark_target(self, target: Tuple[int, int], frame) -> None:
     drawMarker(frame,
                target, (0, 0, 255),
                MARKER_TILTED_CROSS,
                thickness=2)
示例#5
0
    def draw_masks(self, img, fname):
        kernel = np.ones((5, 5), np.uint8)
        blank_image = np.zeros(img.shape, np.uint8)

        threshy = cv2.inRange(img, (0, 100, 100),
                              (10, 255, 255))  #Thresholds for values
        threshy = cv2.dilate(threshy, kernel, iterations=3)
        comy = self.getCoM(threshy)

        threshb = cv2.inRange(img, (100, 0, 0),
                              (255, 10, 10))  #Thresholds for values
        threshb = cv2.dilate(threshb, kernel, iterations=3)
        comb = self.getCoM(threshb)

        threshg = cv2.inRange(img, (0, 100, 0),
                              (10, 255, 10))  #Thresholds for values
        threshg = cv2.dilate(threshg, kernel, iterations=3)
        comg = self.getCoM(threshg)

        threshr = cv2.inRange(img, (0, 0, 100),
                              (10, 10, 255))  #Thresholds for values
        threshr = cv2.dilate(threshr, kernel, iterations=3)
        comr = self.getCoM(threshr)

        for i in range(len(blank_image)):
            for j in range(len(blank_image[0])):
                if threshy[i, j] != 0:
                    blank_image[i, j] = np.array([0, 200, 200])
                elif threshb[i, j] != 0:
                    blank_image[i, j] = np.array([255, 0, 0])
                elif threshg[i, j] != 0:
                    blank_image[i, j] = np.array([0, 255, 0])
                elif threshr[i, j] != 0:
                    blank_image[i, j] = np.array([0, 0, 255])

        blank_image = cv2.putText(blank_image, str(comy), (comy[0], comy[1]),
                                  cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                                  (255, 255, 255), 2, cv2.LINE_AA)
        blank_image = cv2.putText(blank_image, str(comb), (comb[0], comb[1]),
                                  cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                                  (255, 255, 255), 2, cv2.LINE_AA)
        blank_image = cv2.putText(blank_image, str(comg), (comg[0], comg[1]),
                                  cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                                  (255, 255, 255), 2, cv2.LINE_AA)
        blank_image = cv2.putText(blank_image, str(comr), (comr[0], comr[1]),
                                  cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                                  (255, 255, 255), 2, cv2.LINE_AA)
        blank_image = cv2.drawMarker(blank_image, (comy[0], comy[1]),
                                     (255, 255, 255),
                                     markerType=cv2.MARKER_STAR)
        blank_image = cv2.drawMarker(blank_image, (comb[0], comb[1]),
                                     (255, 255, 255),
                                     markerType=cv2.MARKER_STAR)
        blank_image = cv2.drawMarker(blank_image, (comg[0], comg[1]),
                                     (255, 255, 255),
                                     markerType=cv2.MARKER_STAR)
        blank_image = cv2.drawMarker(blank_image, (comr[0], comr[1]),
                                     (255, 255, 255),
                                     markerType=cv2.MARKER_STAR)

        return blank_image
示例#6
0
def draw_corners(original, corners):
    for corner in corners:
        cv2.drawMarker(original, tuple(corner), (0, 191, 255), 0, 20,
                       3)  # deben ser tuplas para poder dibujarlas