How to find longest uninterrupted edge using canny?

750 views Asked by At

I have a problem with canny edge detection in python. my starting picture is a normal picture of a bill like I have added in the post. I detect the edges with canny without any problems but I want to know where the longest detected edges are in the picture.

Here is the input image and here is the output image.

Now I want to know the longest edge in the output image to cut of the unnecessary parts of the picture, but I do not know how...

My Code:

# Read reference image
#refFilename = RefRefFileCalculation(row)
refFilename = "C:\\Maturaprojekt\\Test 1\\30Zeilen.JPG"
print("Reading reference image : ", refFilename)
imReference = cv2.imread(refFilename, cv2.IMREAD_COLOR)

# Read image to be aligned
imFilename = save_path
print("Reading image to align : ", imFilename);
im = cv2.imread(imFilename, cv2.IMREAD_COLOR)
print("Aligning images ...")

# Registered image will be resotred in imReg.
# The estimated homography will be stored in h.
imReg, h = alignImages(im, imReference)

# Write aligned image to disk.

outFilename = "C:\\Maturaprojekt\\Test 1\\gedreht\\" + sample_names[i]
print("Saving aligned image : ", outFilename);
cv2.imwrite(outFilename, imReg)

# Load the image file
image = cv2.imread(save_path)

# Check if image was loaded improperly and exit if so
if image is None:
  sys.exit('Failed to load image')

# Detect edges in the image. The parameters control the thresholds
edges = cv2.Canny(image, 100, 700, apertureSize=5)

# Display the output in a window
cv2.imwrite("C:\\Maturaprojekt\\Edge Detection Test 1\\cropped\\" + sample_names[i], edges)
i = i+1
0

There are 0 answers