Python Forum
how to detect horizontal dotted lines in an image using OpenCV
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to detect horizontal dotted lines in an image using OpenCV
#1
Hi all,

I am learning techniques on how to detect horizontal lines. So far I know how to detect a continuous horizontal line. So I am trying to learn how to detect a broken (dotted) horizontal line.

The code that I use to detect continuous horizontal line is below.
import cv2
import functions
import numpy as np

# Load image, convert to grayscale, Otsu's threshold
image = cv2.imread('new.jpg')
no_horizontal = image.copy()
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]

# Detect horizontal lines
horizontal_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (40,1))
detect_horizontal = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, horizontal_kernel, iterations=2)
cnts = cv2.findContours(detect_horizontal, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(no_horizontal, [c], -1, (255,255,255), 3)

A test image I am using is below:
[url=https://pasteboard.co/J3YpAY6.jpg[/url]

I have tried HoughLinesP from OpenCV but I can't seem to get the parameters right.
Any direction/advice will be greatly appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using OpenCV and image path is invalid AudunNilsen 5 456 Mar-18-2024, 05:28 PM
Last Post: snippsat
  detect if two lines are crossing bast0s4 2 672 Aug-16-2023, 04:23 PM
Last Post: Gribouillis
  i need help for opencv apriltag detect bleulake 0 2,613 Dec-06-2020, 06:56 AM
Last Post: bleulake
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,705 Aug-10-2020, 11:01 PM
Last Post: medatib531
  Detect event by motion/image - Help Zarqua 0 1,500 May-12-2020, 10:41 AM
Last Post: Zarqua
  How to detect the text above lines using OpenCV in Python pframe 0 2,484 Apr-14-2020, 09:53 AM
Last Post: pframe
  Display the bottom image of the line and cut the upper image using Opencv jenkins43 1 3,194 May-27-2019, 06:56 AM
Last Post: heiner55
  circle node with horizontal line in python graphviz mandana 0 2,317 May-05-2019, 10:39 AM
Last Post: mandana
  Is there a way to detect the text font, size and color from an image in python? Maia07 2 8,579 Aug-23-2018, 01:16 PM
Last Post: Maia07
  OpenCV, segment image Standard_user 6 7,545 Jan-01-2017, 08:29 PM
Last Post: Standard_user

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020