Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何仅保留pdf文本或其图像的注释部分?_Python 3.x_Image Processing - Fatal编程技术网

Python 3.x 如何仅保留pdf文本或其图像的注释部分?

Python 3.x 如何仅保留pdf文本或其图像的注释部分?,python-3.x,image-processing,Python 3.x,Image Processing,我已经构建了将pdf文本转换为图像的程序,我只想保留括号之间的文本部分: 例如,我想保留的文本的第一部分是: 我知道我可以从PIL使用Image,然后使用.crop(左、上、右、下)功能,但我不知道如何让它知道我想要文本中有[的部分 我知道即使我们按颜色提取图像也很有用。事实上,他们会找到轮廓并进行迭代。如果他们找到4个角点,他们会做另一件事来提取文本。这里我们有2个角点 以下是我从pdf格式的图像中获取文本的部分代码: for file_name in file_names: #

我已经构建了将pdf文本转换为图像的程序,我只想保留括号之间的文本部分:

例如,我想保留的文本的第一部分是:

我知道我可以从
PIL
使用
Image
,然后使用
.crop(左、上、右、下)
功能,但我不知道如何让它知道我想要文本中有
[
的部分

我知道即使我们按颜色提取图像也很有用。事实上,他们会找到轮廓并进行迭代。如果他们找到4个角点,他们会做另一件事来提取文本。这里我们有2个角点

以下是我从pdf格式的图像中获取文本的部分代码:

for file_name in file_names:
    # load the image and convert it to grayscale
    image = cv2.imread(file_name)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # check to see if we should apply thresholding to preprocess the
    # image
    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 = "{}.png".format(os.getpid())
    cv2.imwrite(filename, gray)

    # load the image as a PIL/Pillow image, apply OCR, and then delete
    # the temporary file
    text = pytesseract.image_to_string(Image.open(filename))
    os.remove(filename)
    #print(text)

    with open('resume.txt', 'a+') as f:
        print('***:', text, file=f)  
使用cv2(pip安装opencv python)进行模板匹配或块检测