Python:将过程脚本转换为类和对象(oop)样式
我仍在学习用python编写代码,我正在努力用面向对象的方式编写代码。我已经使用pytessarct库编写了一个代码,并使用提取的单词尝试通过使用关键字作为过滤器来制作一个简单的检测器。我想严格按照类和对象格式重做,作为一个学习练习。如果有人能提供帮助,我将不胜感激。多谢各位Python:将过程脚本转换为类和对象(oop)样式,python,oop,Python,Oop,我仍在学习用python编写代码,我正在努力用面向对象的方式编写代码。我已经使用pytessarct库编写了一个代码,并使用提取的单词尝试通过使用关键字作为过滤器来制作一个简单的检测器。我想严格按照类和对象格式重做,作为一个学习练习。如果有人能提供帮助,我将不胜感激。多谢各位 import pytesseract pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe' i
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
import os
import cv2
from PIL import Image
import matplotlib.pyplot as plt
from PIL import ImageFilter
import re
img_path = 'C:/Users/RAJ/realtest/'
for i in os.listdir(img_path):
images=Image.open(img_path+'//'+i)
plt.imshow(images)
plt.show()
images_new=images.convert('LA')
im_SHARPEN2 = images_new.filter(filter=ImageFilter.SHARPEN)
extract = pytesseract.image_to_string(im_SHARPEN2, lang = 'eng')
extract2 = pytesseract.image_to_string(images_new,lang = 'eng')
final= extract+extract2
x = re.search(r"INCOME|TAX|Account|GOVT.", final,re.M|re.I)
y = re.search(r"GOVERNMENT|DOB|Male|Female.", final,re.M|re.I)
if x == None and y== None:
print('Not a pan card or adhaar card')
elif type(x)== re.Match:
print('This is a pan card')
else:
print('adhaar card detected')
这个问题可能更适合:如果您希望代码缩进保持干净,请复制粘贴代码,选择它并按ctrl+K。这很好,非常感谢:)
import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
import os
import cv2
from PIL import Image
import matplotlib.pyplot as plt
from PIL import ImageFilter
import re
class is_pan_card():
def __init__(self,path):
self.img_path = path
for i in os.listdir(self.img_path):
images=Image.open(self.img_path+'//'+i)
plt.imshow(images)
plt.show()
images_new=images.convert('LA')
im_SHARPEN2 = images_new.filter(filter=ImageFilter.SHARPEN)
extract = pytesseract.image_to_string(im_SHARPEN2, lang = 'eng')
extract2 = pytesseract.image_to_string(images_new,lang = 'eng')
final= extract+extract2
x = re.search(r"INCOME|TAX|Account|GOVT.", final,re.M|re.I)
y = re.search(r"GOVERNMENT|DOB|Male|Female.", final,re.M|re.I)
if x == None and y== None:
print('Not a pan card or adhaar card')
elif type(x)== re.Match:
print('This is a pan card')
else:
print('adhaar card detected')
is_pan =is_pan_card('C:/Users/RAJ/realtest/')