Пример #1
0
def processPage(scan_id, ia_page_index):
    print 'processing', scan_id, ia_page_index

    img = getIAImage(scan_id, ia_page_index)

    result = processImage(img, scan_id, ia_page_index)

    del img

    return result
Пример #2
0
def processPage(scan_id, ia_page_index):
    print 'processing', scan_id, ia_page_index

    img = getIAImage(scan_id, ia_page_index)

    result = processImage(img, scan_id, ia_page_index)

    del img

    return result
Пример #3
0
def processPage(scan_id, ia_page_index):

    img = getIAImage(scan_id, ia_page_index)
    filesize = os.path.getsize('tmp/ia/%s/%s.jpeg' % (scan_id, ia_page_index))

    mode_to_bpp = {'1': 1, 'L': 8, 'P': 8, 'RGB': 24, 'RGBA': 32, 'CMYK': 32, 'YCbCr': 24, 'I': 32, 'F': 32}

    area = img.size[0] * img.size[1]

    return {
        'file_size': filesize,
        'bytes_per_pixel': float(filesize) / area,
        'pixel_depth': mode_to_bpp[img.mode],
        'compression': float(filesize) * 8 / (area * mode_to_bpp[img.mode])
    }
Пример #4
0
def renderBlocks(scan_id, ia_page_index, pblocks, output_width=500):

    img = getIAImage(scan_id, ia_page_index)

    if not os.path.exists('tmp/pictureblocks'):
        os.mkdir('tmp/pictureblocks')
    if not os.path.exists('tmp/pictureblocks/%s' % (scan_id)):
        os.mkdir('tmp/pictureblocks/%s' % (scan_id))

    output_file = 'tmp/pictureblocks/%s/%s_blocks_%s.png' % (scan_id, scan_id, ia_page_index)

    t0 = clock()

    size = img.size
    scale = float(output_width) / img.size[0]
    print 'Image size:', size, 'scale factor:', scale

    small = img.resize([output_width, int(img.size[1] * scale)])

    draw = ImageDraw.Draw(small)
    for block in pblocks:
        print block.attrib
        draw.rectangle([
                (float(block.attrib['l']) * scale, float(block.attrib['t']) * scale),
                (float(block.attrib['r']) * scale, float(block.attrib['b']) * scale)
            ],
            outline=(0, 255, 0)
        )
    del draw

    small.save(output_file)
    del img
    del small

    benchmarks['image_processing'].append(clock() - t0)

    return output_file
Пример #5
0
def renderBlocks(scan_id, ia_page_index, pblocks, output_width=500):

    img = getIAImage(scan_id, ia_page_index)

    if not os.path.exists('tmp/pictureblocks'):
        os.mkdir('tmp/pictureblocks')
    if not os.path.exists('tmp/pictureblocks/%s' % (scan_id)):
        os.mkdir('tmp/pictureblocks/%s' % (scan_id))

    output_file = 'tmp/pictureblocks/%s/%s_blocks_%s.png' % (scan_id, scan_id,
                                                             ia_page_index)

    t0 = clock()

    size = img.size
    scale = float(output_width) / img.size[0]
    print 'Image size:', size, 'scale factor:', scale

    small = img.resize([output_width, int(img.size[1] * scale)])

    draw = ImageDraw.Draw(small)
    for block in pblocks:
        print block.attrib
        draw.rectangle([(float(block.attrib['l']) * scale,
                         float(block.attrib['t']) * scale),
                        (float(block.attrib['r']) * scale,
                         float(block.attrib['b']) * scale)],
                       outline=(0, 255, 0))
    del draw

    small.save(output_file)
    del img
    del small

    benchmarks['image_processing'].append(clock() - t0)

    return output_file