Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从python中的特定图像块读取文本_Python_Django_Image Processing_Python Tesseract - Fatal编程技术网

从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)