试图用python脚本裁剪tiff图像

时间:2018-05-28 07:08:31

标签: python image numpy opencv

我正在使用github中的script裁剪图像,只留下文本块。 我试图将我的图像保存为tiff文件以获得最高质量,因为我将进行OCR。

现在我遇到的问题是它只适用于jpg - > png,如果我在字符串末尾将值更改为tiff,我会收到类似

的错误
newOCR10.tiff image has wrong mode

关于如何解决这个问题的任何想法?

以下是我更改的代码:

if __name__ == '__main__':
    if len(sys.argv) == 2 and '*' in sys.argv[1]:
        files = glob.glob(sys.argv[1])
        random.shuffle(files)
    else:
        files = sys.argv[1:]

    for path in files:
        out_path = path.replace('.jpg', '.crop.png') //'.tiff' '.crop.tiff'
        if os.path.exists(out_path): continue
        try:
            process_image(path, out_path)
        except Exception as e:
            print '%s %s' % (path, e)

tiffinfo newOCR6.tiff返回此信息:

TIFF Directory at offset 0xca90b8 (13275320)
  Image Width: 2316 Image Length: 2866
  Resolution: 300, 300 (unitless)
  Bits/Sample: 16
  Compression Scheme: None
  Photometric Interpretation: min-is-black
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 1
  Planar Configuration: single image plane
  Page Number: 0-1
  White Point: 0.3127-0.329
  PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000

0 个答案:

没有答案