<jupyter_start><jupyter_text>Creating Pixel objects for all white pixels<jupyter_code>pixMtrx = [[Pixel(r, c) if img[r][c] == 1 else None for c in range(width)] for r in range(height)]
start = pixMtrx[227][11] # start point
start.dist = 0
end = pixMtrx[211][163] # end point<jupyter_output><empty_output><jupyter_text>Checking for neighbours and connecting the graph<jupyter_code>for r in range(height - 1):
    for c in range(width - 1):
        if img[r, c] == 1: # if white
            if img[r, c + 1] == 1: # if right pixel is white 
                pixMtrx[r][c].neighbours.append((r, c + 1))
                pixMtrx[r][c + 1].neighbours.append((r, c)) # left of right pixel is white too
            if img[r + 1, c] == 1: # if bottom pixel is white 
                pixMtrx[r][c].neighbours.append((r + 1, c))
                pixMtrx[r + 1][c].neighbours.append((r, c)) # top of bottom pixel is white too
for c in range(width - 1): # bottom most row
    if img[height - 1, c] == 1 and img[height - 1, c + 1] == 1: # if right pixel is white 
        pixMtrx[height - 1][c].neighbours.append((height - 1, c + 1))
        pixMtrx[height - 1][c + 1].neighbours.append((height - 1, c)) # left of right pixel is white too            
for r in range(height - 1): # left most column
    if img[r, width - 1] == 1 and img[r + 1, width - 1] == 1: # if bottom pixel is white 
        pixMtrx[r][width - 1].neighbours.append((r + 1, width - 1))
        pixMtrx[r + 1][width - 1].neighbours.append((r, width - 1)) # top of bottom pixel is white too<jupyter_output><empty_output><jupyter_text>DIJKSTRA'S ALGORITHM<jupyter_code>prQ = PriorityQueue(pixMtrx)

while (prQ.length > 0):
    toVisit = prQ.dequeue()
    toVisit.visited = True

    for neBor in toVisit.neighbours:
        if not pixMtrx[neBor[0]][neBor[1]].visited:
            newDist = toVisit.dist + 1
            if pixMtrx[neBor[0]][neBor[1]].dist > newDist:
                pixMtrx[neBor[0]][neBor[1]].dist = newDist
                pixMtrx[neBor[0]][neBor[1]].parent_row = toVisit.row
                pixMtrx[neBor[0]][neBor[1]].parent_col = toVisit.col

    prQ.buildHeap(prQ.length//2 - 1) # rebuilding the heap manually<jupyter_output><empty_output><jupyter_text>Getting path<jupyter_code>path = []
temp = end
while (temp != start):
    path.append((temp.row, temp.col))
    temp = pixMtrx[temp.parent_row][temp.parent_col]
path.append((start.row, start.col))<jupyter_output><empty_output><jupyter_text>Visualising the path in OpenCV<jupyter_code>pic = cv2.imread(location)
for coord in path:
    pic = cv2.circle(pic, (coord[1], coord[0]), 2, (0, 0, 255), -1)

cv2.imshow("Solution", pic)
cv2.waitKey(0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.145985401459854, 'fraction_numerical': 0.027737226277372264, 'mean_word_length': 2.9495677233429394, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '619278', 'license': 'MIT', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1011, 'n_words': 248, 'path': 'src/find_path_algo/path_find.ipynb', 'repo_name': 'tushdon2/TAKSHAK_ISHANA_2021_RoboVision', 'size': '2740'}