如何解决红外图像上光伏模块的边缘检测
背景
我的目标是在无人机拍摄的红外图像数据集上检测 PV 模块。 我想改进边缘检测,以便我的算法性能更好。然后使用检测和标记的模块来训练神经网络。
数据集
我有数百张在不同时间和不同高度拍摄的图像。我猜他们的质量并不完美 - 环境条件可以更好,例如:
海拔 - 有时模块之间的边缘不是图像可以从较低的高度拍摄,因此边缘更清晰。
拍摄时间 - 有时背景(草)很热。这些图像很可能是在上午晚些时候/下午早些时候拍摄的。
但是,我必须坚持我所拥有的。
正如您有时看到的(例如 image_3
),“中间线”几乎不可见。
代码
下面的预处理基于我在 Github 上找到的项目。使用标准预处理和 Canny 边缘检测。
import cv2
import numpy as np
def detect_edges():
# image_path = "data/stackoverflow/TEMP_DJI_1_R (715).JPG"
# image_path = "data/stackoverflow/TEMP_DJI_6_R (720).JPG"
image_path = "data/stackoverflow/TEMP_DJI_5_R (657).JPG"
# read image
input_image = cv2.imread(image_path,cv2.IMREAD_COLOR)
cv2.imshow('input_image',input_image)
# scale image
image_scaling = 11.0
scaled_image_rgb = cv2.resize(src=input_image,dsize=(0,0),fx=image_scaling,fy=image_scaling)
cv2.imshow('scaled_image',scaled_image_rgb)
# blur image
gaussian_blur = 7
blurred_image = cv2.blur(scaled_image_rgb,(gaussian_blur,gaussian_blur))
cv2.imshow('blurred_image',blurred_image)
# gray image
grayed_image = cv2.cvtColor(scaled_image_rgb,cv2.COLOR_BGR2GRAY)
cv2.imshow('grayed_image',grayed_image)
# red threshold
red_threshold = 120
red_channel = scaled_image_rgb[:,:,2]
_,thresholded_image = cv2.threshold(red_channel,red_threshold,255,cv2.THRESH_BINARY)
# dilation and erosion
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(9,9))
closing = cv2.morphologyEx(thresholded_image,cv2.MORPH_CLOSE,kernel)
opening = cv2.morphologyEx(closing,cv2.MORPH_OPEN,kernel)
# min area
min_area = 250 * 200
contours,hierarchy = cv2.findContours(opening,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
areas = [cv2.contourArea(contour) for contour in contours]
discarded_contours = [area < min_area for area in areas]
contours = [contours[i] for i in range(len(contours)) if not discarded_contours[i]]
mask = np.zeros_like(grayed_image)
cv2.drawContours(mask,contours,-1,(255),cv2.FILLED)
mask = cv2.dilate(mask,kernel,iterations=5)
mask = cv2.blur(mask,(25,25))
mask = mask.astype(np.float) / 255.
preprocessed_image = (grayed_image * mask).astype(np.uint8)
cv2.imshow('preprocessed_image',preprocessed_image)
hysteresis_min_thresh = 25
hysteresis_max_thresh = 40
# canny edge
canny_image = cv2.Canny(image=preprocessed_image,threshold1=hysteresis_min_thresh,threshold2=hysteresis_max_thresh,apertureSize=3)
cv2.imshow('canny_image',canny_image)
cv2.waitKey()
结果
结果还不错,但在进一步处理之前必须改进。
哪种操作最能将面板与背景(草)区分开来?
对于几乎看不到“中间”线 (image_3
) 的图像,是否有机会找到“内部”边缘?也许对于这些图像,我应该只专注于寻找外边缘,并在中间画一条人工线将整个面板分成两部分?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。