1

Im using the following code to detect lines in my image.

import numpy as np
import cv2

gray = cv2.imread('img.png')
kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)

edges = cv2.Canny(blur_gray,50,150,apertureSize = 3)
cv2.imshow("edges",edges)
minLineLength=100
lines = cv2.HoughLinesP(image=edges,rho=1,theta=np.pi/180, threshold=100,lines=np.array([]), minLineLength=minLineLength,maxLineGap=80)

a,b,c = lines.shape
for i in range(a):
    cv2.line(gray, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 3, cv2.LINE_AA)

cv2.imshow("Gray",gray)
cv2.waitKey(0)

This code works perfectly. However I want to remove the lines detected by HoughLinesP. is there any such ways to do so?

This is my image

Image

  • Set them to the colour of your image background (if it has some). Can you post the image in question? – T A Dec 14 '18 at 08:11
  • I have attached the image. Please find the corresponding image. –  Dec 14 '18 at 08:16
  • 1
    Replace the line color in `cv2.line` from `(0, 0, 255)` to your background color using `(0, 0, 0)` color with 2 or 3 line thickness parameter – ZdaR Dec 14 '18 at 08:28
  • thank you. that works. Is it possible to access those pixels individually? I tried it but with no luck –  Dec 14 '18 at 08:34
  • If this is the real image, just erase everything ! For image processing questions, using synthetic images never makes sense. –  Dec 14 '18 at 09:26

0 Answers0