def main():
    compute_and_render([
        AABBoxParams(get_image_path('mercedesspritesheets.png'), 132, 236),
        AABBoxParams(get_image_path('trump_run.png'), 230, 290),
        AABBoxParams(
            get_image_path('volt_sprite_sheet_by_kwelfury-d5hx008.png'),
            632, 676)
    ])
Ejemplo n.º 2
0
def main():
    im = cv2.imread(str(get_image_path('balls.png')))
    imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    cv2.imshow("imgray", imgray)

    # bug: marrant la valeur de threshold est sensible ...
    # surement lie a la compression ou format de l'image
    minThreshold = 121  # valeur dans le tuto = 127
    maxThreshold = 255
    ret, thresh = cv2.threshold(imgray, minThreshold, maxThreshold, 0)
    cv2.imshow("thresh", thresh)

    contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_SIMPLE)

    logger.info(f"len(contours): {len(contours)}")
    # coef_approx = 0.0  # suit exactement les contours detectes
    coef_approx = 0.01  # suit (presque) les contours detectes
    # coef_approx = 0.10  # affiche un rectanble englobant
    for h, cnt in enumerate(contours):
        approx = cv2.approxPolyDP(cnt, coef_approx * cv2.arcLength(cnt, True),
                                  True)
        logger.info(f"len(approx): {len(approx)}")
        cv2.drawContours(im, [approx], -1, (0, 255, 0), 3)

    cv2.imshow("approx", im)

    while True:
        k = cv2.waitKey(1) & 0xFF
        if k == 27:
            break
Ejemplo n.º 3
0
def main():
    im = cv2.imread(str(get_image_path('test.jpg')))
    imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(imgray, 127, 255, 0)
    contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_SIMPLE)

    logger.info(f"nombre de contours: {len(contours)}")
    cnt = contours[0]
    logger.info(f"nombre de points dans le contour 1: {len(cnt)}")

    cv2.drawContours(im, contours, -1, (0, 255, 0), 3)
    cv2.imshow("contours - borders", im)

    cv2.drawContours(im, contours, -1, (0, 0, 255), -1)
    cv2.imshow("contours - fill", im)

    while True:
        k = cv2.waitKey(1) & 0xFF
        if k == 27:
            break
Ejemplo n.º 4
0
def main():
    im = cv2.imread(str(get_image_path('balls.png')))
    imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    cv2.imshow("imgray", imgray)

    # bug: marrant la valeur de threshold est sensible ...
    # surement lie a la compression ou format de l'image
    minThreshold = 121  # valeur dans le tuto = 127
    maxThreshold = 255
    ret, thresh = cv2.threshold(imgray, minThreshold, maxThreshold, 0)
    cv2.imshow("thresh", thresh)

    contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_SIMPLE)

    logger.info(f"len(contours): {len(contours)}")

    for h, cnt in enumerate(contours):
        mask = np.zeros(imgray.shape, np.uint8)
        cv2.drawContours(mask, [cnt], 0, 255, -1)
        cv2.mean(im, mask=mask)
        cv2.imshow("Masks", mask)
        cv2.waitKey(0)
Ejemplo n.º 5
0
def main():
    im = cv2.imread(str(get_image_path('balls.png')))
    imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    cv2.imshow("imgray", imgray)

    # bug: marrant la valeur de threshold est sensible ...
    # surement lie a la compression ou format de l'image
    min_threshold = 121  # valeur dans le tuto = 127
    max_threshold = 255
    ret, thresh = cv2.threshold(imgray, min_threshold, max_threshold, 0)
    cv2.imshow("thresh", thresh)

    contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                           cv2.CHAIN_APPROX_SIMPLE)

    logger.info(f"len(contours): {len(contours)}")
    # coef_approx = 0.0  # suit exactement les contours detectes
    coef_approx = 0.01  # suit (presque) les contours detectes
    # coef_approx = 0.10  # affiche un rectanble englobant
    for h, cnt in enumerate(contours):
        approx = cv2.approxPolyDP(cnt, coef_approx * cv2.arcLength(cnt, True),
                                  True)
        print(f"len(approx): {len(approx)}")
        cv2.drawContours(im, [approx], -1, (0, 255, 0), 3)

    cv2.imshow("approx", im)

    # url: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_gui/py_trackbar/py_trackbar.html
    def nothing(_x):
        pass

    # height, width = im.shape[:2]

    # Create a black image, a window
    cv2.namedWindow('image')

    # create trackbars for color change
    cv2.createTrackbar('minThreshold', 'image', 1, 255, nothing)
    cv2.createTrackbar('maxThreshold', 'image', 1, 255, nothing)

    # create switch for ON/OFF functionality
    switch = '0 : OFF \n1 : ON'
    cv2.createTrackbar(switch, 'image', 0, 1, nothing)

    while True:
        k = cv2.waitKey(1) & 0xFF
        if k == 27:
            break

        # get current positions of four trackbars
        min_threshold = cv2.getTrackbarPos('minThreshold', 'image')
        max_threshold = cv2.getTrackbarPos('maxThreshold', 'image')
        s = cv2.getTrackbarPos(switch, 'image')

        if s == 0:
            img = imgray
        else:
            logger.info(
                f"minThreshold={min_threshold}, maxThreshold={max_threshold}")
            ret, thresh = cv2.threshold(imgray, min_threshold, max_threshold, 0)
            img = thresh

        cv2.imshow('image', img)

    cv2.destroyAllWindows()