我正在尝试做一个循环tessract和opencv来识别一个操作。但是当运行一些时候,opencv仍然会给出正常的图像,而tessract不会正常运行(输出不正确)。这个问题在我使用多图像运行时真的发生了。
发布于 2019-03-22 04:26:35
with mss.mss() as sct:
# Grab the data
sct_img = sct.grab(monitor)
# Save to the picture file
mss.tools.to_png(sct_img.rgb, sct_img.size, output=path)
# load the image
ap = argparse.ArgumentParser(description='bot')
ap.add_argument("-i", "--image", required=False,default=path,help="path to input image to be OCR'd")
ap.add_argument("-p", "--preprocess", type=str, default="thresh", help="type of preprocessing to be done")
args = vars(ap.parse_args())
# load the image
image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
if args["preprocess"] == "thresh":
gray = cv2.threshold(gray, 0, 255,
cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
# make a check to see if median blurring should be done to remove
# noise
elif args["preprocess"] == "blur":
gray = cv2.medianBlur(gray, 3)
# write the grayscale image to disk as a temporary file so we can
# apply OCR to it
filename = ("Scripts/Screens/" +str(i) +".png").format(os.getpid())
cv2.imwrite(filename, gray)
cv2.waitKey(1)
text = pytesseract.image_to_string(Image.open(filename),config='--psm 7', lang ="eng+equ")我对此感到很抱歉
https://stackoverflow.com/questions/55256136
复制相似问题