I am trying to detect edges on a welding image. On one side of the image i can easily detect the edge by using simple thresholding in open cv with the threshold value that matched in this area, but this threshold value is too low for the other side. Is it possible to distinguish between grayscale value and therefore use different threshold to detect the edges?
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
def region_of_interest(img, vertices):
mask = np.zeros_like(img)
#channel_count = img.shape[2] # for RGB image
match_mask_color = (255,) # * channel_count # only if you want RGB image
cv.fillPoly(mask, vertices, match_mask_color)
masked_img = cv.bitwise_and(img, mask)
return masked_img
path = "resources/weld_6.PNG"
img = cv.imread(path)
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
start_x = 615
end_x = 900
start_y = 510
end_y = 560
gray_img = cv.cvtColor(img, cv.COLOR_RGB2GRAY)
img_blur = cv.GaussianBlur(gray_img, (5, 5), 8)
roi_test = region_of_interest(img_blur,
np.array([region_of_interest_vertices], np.int32))
canny_img = cv.Canny(roi_test, 10, 35)
ret, img_binary1 = cv.threshold(roi_test, 225, 255, 0)
img_cropped = img_binary1[530:540, 625:890]
img_canny = cv.Canny(img_cropped, 150, 200)
# Sum down the columns
columnTotals = np.sum(img_canny, axis=0)
# Now look for non-zero (non-black) entries
nz = np.nonzero(columnTotals)
# Now get left and right edges of white parts of image
left, right = nz[0][0], nz[0][-1]
the last part gives me the leftmost white pixel and the rightmost one and with the difference I am be able to detect the distance between the edges.