【发布时间】:2020-10-07 00:10:40
【问题描述】:
我正在编写一个脚本,使用不同的 OpenCV 操作来处理屋顶太阳能电池板的图像。我的原图如下:
处理图像后,我得到面板的边缘如下:
可以看出图片中一些矩形是如何由于太阳的反射而被破坏的。
我想知道是否有可能修复那些破损的矩形,也许可以使用那些没有破损的矩形。
我的代码如下:
# Load image
color_image = cv2.imread("google6.jpg")
cv2.imshow("Original", color_image)
# Convert to gray
img = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY)
# Apply various filters
img = cv2.GaussianBlur(img, (5, 5), 0)
img = cv2.medianBlur(img, 5)
img = img & 0x88 # 0x88
img = cv2.fastNlMeansDenoising(img, h=10)
# Invert to binary
ret, thresh = cv2.threshold(img, 127, 255, 1)
# Perform morphological erosion
kernel = np.ones((5, 5),np.uint8)
erosion = cv2.morphologyEx(thresh, cv2.MORPH_ERODE, kernel, iterations=2)
# Invert image and blur it
ret, thresh1 = cv2.threshold(erosion, 127, 255, 1)
blur = cv2.blur(thresh1, (10, 10))
# Perform another threshold on blurred image to get the central portion of the edge
ret, thresh2 = cv2.threshold(blur, 145, 255, 0)
# Perform morphological erosion to thin the edge by ellipse structuring element
kernel1 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
contour = cv2.morphologyEx(thresh2, cv2.MORPH_ERODE, kernel1, iterations=2)
# Get edges
final = cv2.Canny(contour, 249, 250)
cv2.imshow("final", final)
我已尝试修改我正在使用的所有滤镜,以尽可能减少原始图片中太阳的影响,但这是我所能做到的。
总的来说,我对所有这些过滤器的结果感到满意(尽管欢迎任何建议),所以我想处理我展示的黑白图像,它已经足够平滑,可以进行后期处理我需要做。
谢谢!
【问题讨论】:
标签: python opencv image-processing imagefilter