python - python add_argument 参数定义
问题描述
我有一个示例 OCR 程序来从名片中提取数字。我不确定我是否理解“-i”、“-d”、“--image”、“--digits”的用法。还有什么是第 22 行和第 27 行中的“选项”。在此先感谢这里是代码:
# USAGE
# python ocr_digits.py --image apple_support.png
# python ocr_digits.py --image apple_support.png --digits 0
# import the necessary packages
import pytesseract
import argparse
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input image to be OCR'd")
ap.add_argument("-d", "--digits", type=int, default=1,
help="whether or not *digits only* OCR will be performed")
args = vars(ap.parse_args())
# load the input image, convert it from BGR to RGB channel ordering,
# and initialize our Tesseract OCR options as an empty string
image = cv2.imread(args["image"])
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
options = ""
# check to see if *digit only* OCR should be performed, and if so,
# update our Tesseract OCR options
if args["digits"] > 0:
options = "outputbase digits"
# OCR the input image using Tesseract
text = pytesseract.image_to_string(rgb, config=options)
print(text)
解决方案
推荐阅读
- python - 如何使用for循环在pandas df中逐一添加列
- scala - Spark RDD 到数据框
- java - BasicDataSource 被 UrlDecodingDataSource 类型的不兼容 bean 实例覆盖
- git - Git - 查找上次跨多个存储库修改文件的时间?
- angular - 我正在尝试从 component.ts 文件中关闭 html boostrap 模态
- garbage-collection - 如何使用 jmx 知道 Java 堆中每一代的大小
- docker - 如何在 AWS EKS 建立的 kubernetes 中部署 elasticsearch
- powershell - 比较两个字符串变量,判断是否相同
- cordova - 带有 Spring Boot 的 Ionic 3 中的 CORS 问题
- javascript - 当应用程序出错时,NodeJS Forever 的重启功能不起作用