Add image conversion backends
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from .image_conversion import ImageConversionBackend
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ghostscript
|
||||
|
||||
|
||||
class GhostscriptBackend(object):
|
||||
def convert(self, pdf_path, png_path, resolution=300):
|
||||
gs_args = [
|
||||
"gs",
|
||||
"-q",
|
||||
"-sDEVICE=png16m",
|
||||
"-o",
|
||||
png_path,
|
||||
f"-r{resolution}",
|
||||
pdf_path,
|
||||
]
|
||||
ghostscript.Ghostscript(*gs_args)
|
||||
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from .poppler_backend import PopplerBackend
|
||||
from .ghostscript_backend import GhostscriptBackend
|
||||
|
||||
backends = {"poppler": PopplerBackend, "ghostscript": GhostscriptBackend}
|
||||
|
||||
|
||||
class ImageConversionBackend(object):
|
||||
def __init__(self, backend="poppler"):
|
||||
self.backend = backend
|
||||
|
||||
def convert(self, pdf_path, png_path):
|
||||
converter = backends[self.backend]()
|
||||
converter.convert(pdf_path, png_path)
|
||||
@@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pdftopng import pdftopng
|
||||
|
||||
|
||||
class PopplerBackend(object):
|
||||
def convert(self, pdf_path, png_path):
|
||||
pdftopng.convert(pdf_path, png_path)
|
||||
@@ -29,6 +29,7 @@ from ..image_processing import (
|
||||
find_contours,
|
||||
find_joints,
|
||||
)
|
||||
from ..backends import ImageConversionBackend
|
||||
|
||||
|
||||
logger = logging.getLogger("camelot")
|
||||
@@ -111,7 +112,7 @@ class Lattice(BaseParser):
|
||||
threshold_constant=-2,
|
||||
iterations=0,
|
||||
resolution=300,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
):
|
||||
self.table_regions = table_regions
|
||||
self.table_areas = table_areas
|
||||
@@ -208,9 +209,8 @@ class Lattice(BaseParser):
|
||||
return t
|
||||
|
||||
def _generate_image(self):
|
||||
from pdftopng import pdftopng
|
||||
|
||||
pdftopng.convert(pdf_path=self.filename, png_path=self.imagename)
|
||||
converter = ImageConversionBackend()
|
||||
converter.convert(self.filename, self.imagename)
|
||||
|
||||
def _generate_table_bbox(self):
|
||||
def scale_areas(areas):
|
||||
|
||||
Reference in New Issue
Block a user