久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 Pytesseract 提取圖像中的小數點

How to extract decimal in image with Pytesseract(如何使用 Pytesseract 提取圖像中的小數點)
本文介紹了如何使用 Pytesseract 提取圖像中的小數點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

上面是圖片,我已經嘗試了從 SO 或 google 獲得的一切,似乎沒有任何效果.我無法在圖像中得到確切的值,我應該得到 2.10,而不是總是得到 210.

并且不僅限于此圖像,只有在數字 1 tesseract 之前具有小數的任何圖像都會忽略十進制值.

 def returnAllowedAmount(self,imgpath):th = 127最大值 = 255img = cv2.imread(imgpath,0) #在內存中加載圖片img = cv2.resize(img, None, fx=2.5, fy=2.5, interpolation=cv2.INTER_CUBIC) #rescale Imageimg = cv2.medianBlur(img, 1)ret , img = cv2.threshold(img,th,max_val,cv2.THRESH_TOZERO)self.showImage(img)returnData = pytesseract.image_to_string(img,lang='eng',config='-psm 13' )returnData = ''.join(p for p in returnData if p.isnumeric() or p == ".") # REMOVE $ SIGN

解決方案

在將圖像放入 Pytesseract 之前,一些預處理以清理/平滑圖像會有所幫助.這是一個簡單的方法

  • 將圖像轉換為灰度并放大圖像
  • 門檻
  • 執行形態學操作以清潔圖像
  • 反轉圖像
<小時>

首先我們將圖像轉換為灰度,使用

現在我們執行

現在我們為 Pytesseract 反轉圖像并添加高斯模糊

我們使用 --psm 10 配置標志,因為我們希望將圖像視為單個字符.以下是一些可能有用的額外配置標志

結果

<塊引用>

2.10 美元

過濾后

<塊引用>

2.10

導入 cv2導入 pytesseract導入 imutilspytesseract.pytesseract.tesseract_cmd = r"C:Program FilesTesseract-OCR	esseract.exe"圖像 = cv2.imread('1.png',0)圖像 = imutils.resize(圖像,寬度 = 300)thresh = cv2.threshold(圖像, 150, 255, cv2.THRESH_BINARY_INV)[1]內核 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))關閉 = cv2.morphologyEx(閾值,cv2.MORPH_CLOSE,內核)結果 = 255 - 關閉結果 = cv2.GaussianBlur(結果, (5,5), 0)數據 = pytesseract.image_to_string(結果,lang='eng',config='--psm 10')processes_data = ''.join(char for char in data if char.isnumeric() or char == '.')打印(數據)打印(已處理數據)cv2.imshow('thresh', thresh)cv2.imshow('關閉',關閉)cv2.imshow('結果', 結果)cv2.waitKey()

Above is the image ,I have tried everything I could get from SO or google ,nothing seems to work. I can not get the exact value in image , I should get 2.10 , Instead it always get 210.

And it is not limited to this image only any image which have a decimal before number 1 tesseract ignores the decimal value.

 def returnAllowedAmount(self,imgpath):
        th = 127
        max_val = 255
        img = cv2.imread(imgpath,0) #Load Image in Memory
        img = cv2.resize(img, None, fx=2.5, fy=2.5, interpolation=cv2.INTER_CUBIC) #rescale Image
        img = cv2.medianBlur(img, 1)
        ret , img = cv2.threshold(img,th,max_val,cv2.THRESH_TOZERO)
        self.showImage(img)

        returnData = pytesseract.image_to_string(img,lang='eng',config='-psm 13 ' )
        returnData = ''.join(p for p in returnData if p.isnumeric() or p == ".") # REMOVE $ SIGN

解決方案

Before throwing the image into Pytesseract, some preprocessing to clean/smooth the image helps. Here's a simple approach

  • Convert image to grayscale and enlarge image
  • Threshold
  • Perform morphological operations to clean image
  • Invert image

First we convert the image to grayscale, resize using the imutils library then threshold to obtain a binary image

Now we perform morphological transformations to smooth the image

Now we invert the image for Pytesseract and add a Gaussian blur

We use the --psm 10 config flag since we want to treat the image as a single character. Here's some additional configuration flags that could be useful

Results

$2.10

After filtering

2.10

import cv2
import pytesseract
import imutils

pytesseract.pytesseract.tesseract_cmd = r"C:Program FilesTesseract-OCR	esseract.exe"

image = cv2.imread('1.png',0)
image = imutils.resize(image, width=300)
thresh = cv2.threshold(image, 150, 255, cv2.THRESH_BINARY_INV)[1]

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
close = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)

result = 255 - close 
result = cv2.GaussianBlur(result, (5,5), 0)

data = pytesseract.image_to_string(result, lang='eng',config='--psm 10 ')
processed_data = ''.join(char for char in data if char.isnumeric() or char == '.')
print(data)
print(processed_data)

cv2.imshow('thresh', thresh)
cv2.imshow('close', close)
cv2.imshow('result', result)
cv2.waitKey()

這篇關于如何使用 Pytesseract 提取圖像中的小數點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 精品国产伦一区二区三区观看方式 | 午夜视频在线视频 | av网站免费在线观看 | 美国av毛片 | 国产乱肥老妇国产一区二 | 国产精品自拍视频 | 精品久久久久久久久久久久 | 国产精品午夜电影 | 天天看天天爽 | 国产一区二区三区在线看 | 麻豆视频在线免费看 | 成人不卡 | 日本免费视频在线观看 | 免费黄色日本 | 欧洲精品一区 | 精品久久久久久亚洲精品 | 最新av中文字幕 | 波多野结衣在线观看一区二区三区 | 嫩呦国产一区二区三区av | 午夜电影网站 | 伊人免费在线观看 | 99免费| 成人视屏在线观看 | 欧美一区二区在线视频 | 伊人网在线综合 | 日本不卡一区 | 国产精品视频网址 | 亚洲视频二区 | 国产精品久久久久久久久久免费 | 手机看片在线播放 | 一区欧美 | 亚洲欧美bt | 日韩欧美高清dvd碟片 | 成av人电影在线 | 国色天香综合网 | 国产亚洲精品久久久久久豆腐 | 天天操网 | 九九久久精品 | 亚洲精品一区二区在线观看 | 国产欧美精品在线 | 在线国产一区 |