You almost found the answer to your question. First of all, there is a difference between edge detection detection and . Essentially, detecting an edge leads to what you call (incorrectly) an โopen pathโ (that is, an edge) and a path, resulting in what you call a โclosed pathโ (i.e., Path).
Definition Canny edge is a popular border detection algorithm. Since you want to detect an edge as an array with coordinates (x, y) going from left to right of the image, detecting the Canny edge is a good idea.
The edge response, which is not in the desired format.
import numpy as np import matplotlib.pyplot as plt import cv2 img = cv2.imread('test.tif') edge = cv2.Canny(img, 100, 200) ans = [] for y in range(0, edge.shape[0]): for x in range(0, edge.shape[1]): if edge[y, x] != 0: ans = ans + [[x, y]] ans = np.array(ans) print(ans.shape) print(ans[0:10, :])
The ans array (a shape equal to (n, 2) ) stores the (x, y) -coordinates of the pixels n that make up the detected edge. This is the result you are looking for.
Here is the image in which I painted these n pixels in white:

Hope this helps you.
source share