From d58b39118cf53c119f3cb95eb1f77c242798b390 Mon Sep 17 00:00:00 2001 From: tanvi15 Date: Tue, 21 Jan 2020 17:24:13 +0530 Subject: [PATCH 1/2] fix multiple pdfs bug --- cvat/apps/annotation/annotation.py | 2 +- cvat/apps/engine/media_extractors.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cvat/apps/annotation/annotation.py b/cvat/apps/annotation/annotation.py index a592dd91b0e8..e8270c253d6e 100644 --- a/cvat/apps/annotation/annotation.py +++ b/cvat/apps/annotation/annotation.py @@ -305,7 +305,7 @@ def _get_frame(annotations, shape): frame = self._db_task.start_frame + shape["frame"] * self._db_task.get_frame_step() rpath = db_image['path'].split(os.path.sep) if len(rpath) != 1: - rpath = os.path.sep.join(rpath[rpath.index(".upload")+1:]) + rpath = os.path.sep.join(rpath[-1:]) else: rpath = rpath[0] if frame not in annotations: diff --git a/cvat/apps/engine/media_extractors.py b/cvat/apps/engine/media_extractors.py index 018671e1b173..bf44ce073e96 100644 --- a/cvat/apps/engine/media_extractors.py +++ b/cvat/apps/engine/media_extractors.py @@ -80,7 +80,7 @@ def __init__(self, source_path, dest_path, image_quality, step=1, start=0, stop= from pdf2image import convert_from_path self._temp_directory = tempfile.mkdtemp(prefix='cvat-') super().__init__( - source_path=source_path[0], + source_path=sorted(source_path), dest_path=dest_path, image_quality=image_quality, step=1, @@ -89,12 +89,14 @@ def __init__(self, source_path, dest_path, image_quality, step=1, start=0, stop= ) self._dimensions = [] - file_ = convert_from_path(self._source_path) - self._basename = os.path.splitext(os.path.basename(self._source_path))[0] - for page_num, page in enumerate(file_): - output = os.path.join(self._temp_directory, self._basename + str(page_num) + '.jpg') - self._dimensions.append(page.size) - page.save(output, 'JPEG') + count = 0 + for source in source_path: + pages = convert_from_path(source) + for page in pages: + output = os.path.join(self._temp_directory, str(count) + '.jpg') + count += 1 + self._dimensions.append(page.size) + page.save(output, 'JPEG') self._length = len(os.listdir(self._temp_directory)) From 89641268886592f763adcb93edd2a2804120bde5 Mon Sep 17 00:00:00 2001 From: Tanvi Anand Date: Thu, 23 Jan 2020 15:53:17 +0530 Subject: [PATCH 2/2] Update media_extractors.py --- cvat/apps/engine/media_extractors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cvat/apps/engine/media_extractors.py b/cvat/apps/engine/media_extractors.py index bf44ce073e96..2db177939e00 100644 --- a/cvat/apps/engine/media_extractors.py +++ b/cvat/apps/engine/media_extractors.py @@ -101,7 +101,7 @@ def __init__(self, source_path, dest_path, image_quality, step=1, start=0, stop= self._length = len(os.listdir(self._temp_directory)) def _get_imagepath(self, k): - img_path = os.path.join(self._temp_directory, self._basename + str(k) + '.jpg') + img_path = os.path.join(self._temp_directory, str(k) + '.jpg') return img_path def __iter__(self): @@ -275,6 +275,6 @@ def _is_pdf(path): 'has_mime_type': _is_pdf, 'extractor': PDFExtractor, 'mode': 'annotation', - 'unique': True, + 'unique': False, }, }