从python中的特定图像块读取文本
有没有办法从特定的固定位置读取图像中的文本从python中的特定图像块读取文本,python,django,image-processing,python-tesseract,Python,Django,Image Processing,Python Tesseract,有没有办法从特定的固定位置读取图像中的文本 def read_image_data(request): import cv2 import pytesseract pytesseract.pytesseract.tesseract_cmd = "C:/Program Files/Tesseract-OCR/tesseract.exe" img = cv2.imread("workcenter_dash.png") t
def read_image_data(request):
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = "C:/Program Files/Tesseract-OCR/tesseract.exe"
img = cv2.imread("workcenter_dash.png")
text = pytesseract.image_to_string(img)
print(text)
在上面的示例中,我使用“pytesseract”来读取图像文本,这对于读取文本来说很好,但在我的示例中,我希望从特定位置读取文本
例如:在上图中,我只想从红色矩形选中的位置读取文本
因此,请给我最好的解决方案。
提前感谢。我已经修复了这个问题,在读取数据之后,我会剪切图像 这对我很有用,有没有更好的解决方案,所以请建议我
def read_image_data(request):
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = "C:/Program Files/Tesseract-OCR/tesseract.exe"
img = cv2.imread("workcenter_dash.png")
height, width = img.shape[0:2]
startRow = int(height * 0.10)
startCol = int(width * 0.10)
endRow = int(height * 0.90)
endCol = int(width * 0.40)
croppedImage = img[startRow:endRow, startCol:endCol]
text = pytesseract.image_to_string(croppedImage)
print(text)