发行Loop Tesseract和Opencv?

时间:2019-03-20 08:10:29

标签: python opencv tesseract

我正在尝试使tessract和opencv循环以识别操作。但是当运行一段时间后,opencv仍然会发出正常的图像,而tessract无法正常运行(输出不正确)。当我使用多张图像运行它时,确实发生了此问题
enter image description here

1 个答案:

答案 0 :(得分:0)

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

对此我感到很抱歉