How to detect the text above lines using OpenCV in Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to detect the text above lines using OpenCV in Python (/thread-25865.html) |
How to detect the text above lines using OpenCV in Python - pframe - Apr-14-2020 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 :) |