Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to upload and annotate multiple pdfs #1088

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cvat/apps/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 11 additions & 9 deletions cvat/apps/engine/media_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -89,17 +89,19 @@ 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))

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):
Expand Down Expand Up @@ -273,6 +275,6 @@ def _is_pdf(path):
'has_mime_type': _is_pdf,
'extractor': PDFExtractor,
'mode': 'annotation',
'unique': True,
'unique': False,
},
}