Python Forum
How to detect the text above lines using OpenCV in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to detect the text above lines using OpenCV in Python
#1
I am having trouble looping through an image with lines and extract region of interest(roi) above those lines.
My code :
import cv2
import numpy as np

img=cv2.imread('test3.jpg')
#img=cv2.resize(img,(500,500))
imgGray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
imgEdges=cv2.Canny(imgGray,100,250)
imgLines= cv2.HoughLinesP(imgEdges,1,np.pi/180,230, minLineLength = 700, maxLineGap = 100)
imgLinesList= list(imgLines)

a,b,c=imgLines.shape
line_coords_list = []
for i in range(a):
    line_coords_list.append([int(imgLines[i][0][0]), int(imgLines[i][0][1]), int(imgLines[i][0][2]), int(imgLines[i][0][3])])

print(line_coords_list)#[[85, 523, 964, 523], [85, 115, 964, 115], [85, 360, 964, 360], [85, 441, 964, 441], [85, 278, 964, 278], [85, 197, 964, 197]]


roi= img[int(line_coords_list[0][1]-82): int(line_coords_list[0][-1]), int(line_coords_list[0][0]) : int(line_coords_list[0][2])]
print(roi) 
cv2.imshow('Roi NEW',roi) 
My test image: https://i.stack.imgur.com/nSYTD.jpg

The thing I don't understand is how do i loop through my line_coords_list and extract unique roi for each line detected.

For example I had to manually extract this
 roi= img[int(line_coords_list[0][1]-82): int(line_coords_list[0][-1]), int(line_coords_list[0][0]) : int(line_coords_list[0][2])] 
I just want to be able to generalise it.


Any help/advice will be greatly appreciated.

Thank you :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with using opencv in python Raunak1023984765 21 1,648 Feb-21-2024, 04:25 PM
Last Post: Pedroski55
  When does Python detect Errors? stamp1t 1 439 Oct-21-2023, 05:53 PM
Last Post: deanhystad
  detect if two lines are crossing bast0s4 2 708 Aug-16-2023, 04:23 PM
Last Post: Gribouillis
  How to detect abnormal data in big database python vanphuht91 5 1,128 Jun-27-2023, 11:22 PM
Last Post: Skaperen
  What are these python lines for? What are tey doing? Led_Zeppelin 7 1,612 Feb-13-2023, 03:08 PM
Last Post: deanhystad
  Editing text between two string from different lines Paqqno 1 1,311 Apr-06-2022, 10:34 PM
Last Post: BashBedlam
  Extracting Specific Lines from text file based on content. jokerfmj 8 2,952 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Help for the shortest way to install a suitable version of Python, Numpy, and OpenCV. Ezzat 2 2,277 Dec-23-2021, 12:34 PM
Last Post: snippsat
  raspberry use scrolling text two lines together fishbone 0 1,447 Sep-06-2021, 03:24 AM
Last Post: fishbone
  python seems to be skipping lines of code alansandbucket 1 4,149 Jun-22-2021, 01:18 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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