光伏组件边缘检测矩形

问题描述

目标

我的目标是在红外图像数据集上检测光伏组件。在预处理阶段之后,主要是去除嘈杂的背景,我想找到边缘,以便它们可以用于进一步处理(houghlinesp 等)。我已经得到了非常令人满意的结果,但是,我想验证我的方法并寻求提示

注意图片(经过预处理、去除背景)

preprocessed_1

preprocessed_2

preprocessed_3

然后我增加对比度(这给了我更好的结果)

然后应用带有一些腐蚀和膨胀的 Canny Edge 检测。

最终结果

canny_1

canny_2

canny_3

我想改进对与第三张图像相似的图像的检测 - 在两个矩形的左侧和右侧都未检测到边缘(中间很好)。我试图增加对比度,它在那个特定的图像上工作得很好,但它也导致在我的数据集中的其他图像上检测到更多的错误边缘。有没有更好的办法?

代码

如果我的方法有意义,那就是我的代码

import cv2
import numpy as np


def increase_contrast(input_image):
   bgr_image = cv2.cvtColor(input_image,cv2.COLOR_GRAY2BGR)
   lab = cv2.cvtColor(bgr_image,cv2.COLOR_BGR2LAB)

   l,a,b = cv2.split(lab)
   clahe = cv2.createCLAHE(clipLimit=2.0,tileGridSize=(8,8))
   cl = clahe.apply(l)

   limg = cv2.merge((cl,b))

   increased_contrast_image = cv2.cvtColor(limg,cv2.COLOR_LAB2BGR)
   return increased_contrast_image


def detect_edges(input_image):
   hysteresis_min_thresh = 35
   hysteresis_max_thresh = 45

   canny_image = cv2.Canny(image=input_image,threshold1=hysteresis_min_thresh,threshold2=hysteresis_max_thresh,apertureSize=3)

   kernel_size = (7,7)
   kernel_shape = cv2.MORPH_CROSS
   kernel = cv2.getStructuringElement(kernel_shape,kernel_size)

   dilation_steps = 4
   dilated = cv2.dilate(canny_image,(3,3),iterations=dilation_steps)

   size = np.size(dilated)
   skel = np.zeros(dilated.shape,np.uint8)

   img = dilated
   done = False

   while not done:
       eroded = cv2.erode(img,kernel)
       temp = cv2.dilate(eroded,kernel)
       temp = cv2.subtract(img,temp)
       skel = cv2.bitwise_or(skel,temp)
       img = eroded.copy()

       zeros = size - cv2.countNonZero(img)
       if zeros == size:
           done = True

   return skel


def process_image(img_path):
   input_image = cv2.imread(img_path)
   input_image = cv2.cvtColor(input_image,cv2.COLOR_BGR2GRAY)
   increased_contrast_image = increase_contrast(input_image)

   cv2.imshow('increased_contrast_image',increased_contrast_image)

   image_scaling = 3
   scaled_image = cv2.resize(src=increased_contrast_image,dsize=(0,0),fx=image_scaling,fy=image_scaling)
   gaussian_blur = 7
   blurred_image = cv2.blur(scaled_image,(gaussian_blur,gaussian_blur))

   canny_image = detect_edges(blurred_image)
   cv2.imshow('canny_image',canny_image)
   cv2.waitKey()


# DON'T FORGET TO VERIFY THIS PATH
img_path = "data/plasma_results/background/9.JPG"
process_image(img_path)

问题

我的方法 (Canny) 对这种情况是否有效和合理?

如何改进我的算法,使其在模块之间边缘不明显的图像上效果更好?

编辑

原始图片

根据评论中的要求,这些是等离子调色板中未经处理的红外图像。

plasma_1

plasma_2

plasma_3

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)