这是 Python/OpenCV 中的一个想法。
将图像缩小 25% 以强调暗带。然后沿每列平均。然后得到平均数据的轮廓。然后,您可以在轮廓上更准确地测量间距,然后乘以 4 以补偿 25% 的减少。
输入:

import cv2
import numpy as np
from matplotlib import pyplot as plt
# Read image
img = cv2.imread('weld_bead.jpg')
# convert to gray
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# scale image by 25%
img_small = cv2.resize(gray, (0,0), fx=0.25, fy=0.25, interpolation=cv2.INTER_AREA)
hh, ww = img_small.shape[:2]
# compute mean of each column
mean = np.mean(img_small, axis=0)
# scale the mean up vertically for viewing
mean_stretch = cv2.resize(mean, (hh,ww), fx=0, fy=0, interpolation=cv2.INTER_AREA).transpose()
# show results
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
plt.imshow(img_small, cmap='gray')
ax = plt.axes()
ax.xaxis.grid(color='black')
plt.title("Weld Bead Scaled By 25%")
plt.savefig('weld_bead_small.png')
plt.show()
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
plt.imshow(mean_stretch, cmap='gray')
ax = plt.axes()
ax.xaxis.grid(color='black')
plt.title("Weld Bead Average Stretched In Y")
plt.savefig('weld_bead_ave_stretch.png')
plt.show()
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
plt.plot(mean,color = 'black')
major_ticks = np.arange(0, ww, 50)
minor_ticks = np.arange(0, ww, 10)
ax.set_xticks(major_ticks)
ax.set_xticks(minor_ticks, minor=True)
ax.grid(which='minor', alpha=0.5)
ax.grid(which='major', alpha=1)
plt.grid(color='gray')
plt.title("Weld Bead Profile")
plt.savefig('weld_bead_plot.png')
plt.show()


