Home > Enterprise >  Image processing after edge detect in opencv
Image processing after edge detect in opencv

Time:01-11

I use canny to detect edge.But, as the quality of image is bad, a lot of noise is as below: enter image description here

Origin image is this. enter image description here

I just want the rectangle edges. As the edge I want to detect is so regular(like bricks). I wonder if there were some image process algorithms that could help me?

Note that some edge in image is so week, use a GaussianBlur may make these edge hard to be detected.

Thanks for all reply.

CodePudding user response:

Hough Line Transform might be a good option after some processing and filtering, but you need to Tune the parameters to suit your needs and detect as many lines as possible. The parameters as you can see in the code down are:

  • Gaussian Filter Kernel.
  • Canny Edge Detection Parameters.
  • Hough Line Detection Parameters.
import cv2
import numpy as np
import matplotlib.pyplot as plt
import math

original = cv2.imread('input.png')

img = original.copy()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Histogram Equalization to eenhance contrast
equ = cv2.equalizeHist(gray)
# Noise Removal
blur = cv2.GaussianBlur(equ, (9,9), 0)
# Edge Detection
edges = cv2.Canny(blur,50,200)

# Lines Detection
lines  = cv2.HoughLines (edges, 1, np.pi / 180, 150, None, 10, 0)

if lines is not None:
    for i in range(0, len(lines)):
        rho = lines[i][0][0]
        theta = lines[i][0][1]
        a = math.cos(theta)
        b = math.sin(theta)
        x0 = a * rho
        y0 = b * rho
        pt1 = (int(x0   1000*(-b)), int(y0   1000*(a)))
        pt2 = (int(x0 - 1000*(-b)), int(y0 - 1000*(a)))
        cv2.line(img, pt1, pt2, (0,0,255), 1, cv2.LINE_AA)

plt.subplot(121)
plt.imshow(original, cmap='gray')
plt.title("Original")

plt.subplot(122)
plt.imshow(img, cmap='gray')
plt.title("Processed")

plt.show()

img

CodePudding user response:

Just a hint: it could be useful to strongly blur the image horizontally and vertically to obtain "clean" rows. From this you could reconstruct the grid and possibly inspect every cell.

enter image description here

enter image description here

  •  Tags:  
  • Related