<commit_before>import numpy as np
import cv2

def get_largest_contour_centroid(img):
    img2,cnts_start,heirarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 
    if len(cnts_start) == 0:
        return None
    start_cnt = cnts_start[0]
    M = cv2.moments(start_cnt)
    if M['m00'] != 0:
        return (int(M['m10'] / M['m00']), int(M['m01'] / M['m00']))
    return None

#thin all lines to 1 pixel wide
def skeletonize(img):
    size = np.size(img)
    kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,5))
    ret = np.zeros(img.shape, np.uint8)
    while True:
        eroded = cv2.erode(img, kernel)
        temp = cv2.dilate(eroded, kernel)
        temp = cv2.subtract(img, temp)
        ret = cv2.bitwise_or(ret, temp)
        img = eroded.copy()

        zeros = size - cv2.countNonZero(img)
        if zeros == size:
            break

    return ret

def read_maze(img):
    img2 = img.copy()

    #find the starting and ending locations
    b,g,r = cv2.split(img)
    h,s,v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))

    thresh_s = cv2.threshold(s, 100, 255, cv2.THRESH_BINARY)[1]
    thresh_r = cv2.bitwise_and(cv2.threshold(r, 200, 255, cv2.THRESH_BINARY)[1], thresh_s)
    thresh_g = cv2.bitwise_and(cv2.threshold(g, 200, 255, cv2.THRESH_BINARY)[1], thresh_s)

    start = get_largest_contour_centroid(thresh_r)
    if start == None:
        print("Unable to find start location")
        return None
    cv2.circle(img2, start, 25, (0, 0, 0), 1, cv2.LINE_AA)

    end = get_largest_contour_centroid(thresh_g)
    if end == None:
        print("Unable to find end location")
        return None
    cv2.circle(img2, end, 25, (0, 0, 0), 1, cv2.LINE_AA)

    thresh_v = cv2.bitwise_and(cv2.threshold(v, 254, 255, cv2.THRESH_BINARY)[1], cv2.bitwise_not(cv2.bitwise_or(thresh_r, thresh_g)))  
    #thresh_v =  cv2.GaussianBlur(thresh_v,(5,5),0)
    #thresh_v = cv2.bitwise_and(cv2.threshold(v, 254, 255, cv2.THRESH_BINARY)[1], cv2.bitwise_not(cv2.bitwise_or(thresh_r, thresh_g))) 
    
    thresh_v_eroded = cv2.erode(thresh_v, np.ones((3,3), np.uint8))
    thresh_v_skeleton = skeletonize(thresh_v)
    cv2.imshow("thresh_v", thresh_v)
    cv2.imshow("lines", cv2.bitwise_or(thresh_v_skeleton, cv2.bitwise_not(thresh_v)))
    #.imshow("lines", thresh_v_skeleton)
    corners = cv2.goodFeaturesToTrack(thresh_v_skeleton, 0, 0.1, 10)
    final_corners = []
    for corner in corners:
        if thresh_v_eroded[corner[0][1]][corner[0][0]] != 0:
            final_corners.append((corner[0][0], corner[0][1]))
            cv2.circle(img2, (corner[0][0], corner[0][1]), 3, (255, 0, 0), -1, cv2.LINE_AA)
    print("Found {} corners".format(len(final_corners)))

    return img2

if __name__ == "__main__":
    img = cv2.imread("circular_maze1.png")
    ret = read_maze(img)
    if ret != None:
        img2 = ret
        cv2.imshow("image", img2)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
<commit_msg>Fixed Kernel<commit_after>import numpy as np
import cv2

def get_largest_contour_centroid(img):
    img2,cnts_start,heirarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 
    if len(cnts_start) == 0:
        return None
    start_cnt = cnts_start[0]
    M = cv2.moments(start_cnt)
    if M['m00'] != 0:
        return (int(M['m10'] / M['m00']), int(M['m01'] / M['m00']))
    return None

#thin all lines to 1 pixel wide
def skeletonize(img):
    size = np.size(img)
    kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,3))
    ret = np.zeros(img.shape, np.uint8)
    while True:
        eroded = cv2.erode(img, kernel)
        temp = cv2.dilate(eroded, kernel)
        temp = cv2.subtract(img, temp)
        ret = cv2.bitwise_or(ret, temp)
        img = eroded.copy()

        zeros = size - cv2.countNonZero(img)
        if zeros == size:
            break

    return ret

def read_maze(img):
    img2 = img.copy()

    #find the starting and ending locations
    b,g,r = cv2.split(img)
    h,s,v = cv2.split(cv2.cvtColor(img, cv2.COLOR_BGR2HSV))

    thresh_s = cv2.threshold(s, 100, 255, cv2.THRESH_BINARY)[1]
    thresh_r = cv2.bitwise_and(cv2.threshold(r, 200, 255, cv2.THRESH_BINARY)[1], thresh_s)
    thresh_g = cv2.bitwise_and(cv2.threshold(g, 200, 255, cv2.THRESH_BINARY)[1], thresh_s)

    start = get_largest_contour_centroid(thresh_r)
    if start == None:
        print("Unable to find start location")
        return None
    cv2.circle(img2, start, 25, (0, 0, 0), 1, cv2.LINE_AA)

    end = get_largest_contour_centroid(thresh_g)
    if end == None:
        print("Unable to find end location")
        return None
    cv2.circle(img2, end, 25, (0, 0, 0), 1, cv2.LINE_AA)

    thresh_v = cv2.bitwise_and(cv2.threshold(v, 254, 255, cv2.THRESH_BINARY)[1], cv2.bitwise_not(cv2.bitwise_or(thresh_r, thresh_g)))  
    
    thresh_v_eroded = cv2.erode(thresh_v, np.ones((3,3), np.uint8))
    thresh_v_skeleton = skeletonize(thresh_v)
    cv2.imshow("thresh_v", thresh_v)
    cv2.imshow("lines", cv2.bitwise_or(thresh_v_skeleton, cv2.bitwise_not(thresh_v)))
    #.imshow("lines", thresh_v_skeleton)
    corners = cv2.goodFeaturesToTrack(thresh_v_skeleton, 0, 0.1, 10)
    final_corners = []
    for corner in corners:
        if thresh_v_eroded[corner[0][1]][corner[0][0]] != 0:
            final_corners.append((corner[0][0], corner[0][1]))
            cv2.circle(img2, (corner[0][0], corner[0][1]), 3, (255, 0, 0), -1, cv2.LINE_AA)
    print("Found {} corners".format(len(final_corners)))

    return img2

if __name__ == "__main__":
    img = cv2.imread("circular_maze1.png")
    ret = read_maze(img)
    if ret != None:
        img2 = ret
        cv2.imshow("image", img2)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

{'fraction_non_alphanumeric': 0.14432989690721648, 'fraction_numerical': 0.05207059234667133, 'mean_word_length': 3.2243542435424355, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2073990', 'n_tokens_mistral': 2477, 'n_tokens_neox': 2316, 'n_words': 428}