-
Notifications
You must be signed in to change notification settings - Fork 3k
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
CVAT does not work when annotating PDFs #915
Comments
@philippschw , thanks for the report. It looks like a bug. |
I can't speak to the dumper errors. As far as the rationale behind only being able to load a single PDF, I submitted this while working a job for a client. All the client needed was the ability to upload a single PDF per task. And I had many, many other responsibilities :) . The upload code can easily be extended to account for your use case. You would need to wrap lines 92 - 97 in a I think the The relevant section of Below is a take on my comments from above. # Note: The following code would replace the existing code starting at:
# https://github.com/opencv/cvat/blob/1ec89b5f6a445aaa86854356cb73deb7e070d346/cvat/apps/engine/media_extractors.py#L91
self._dimensions = []
count = 0
for source in source_path:
for root, _, files in os.walk(source):
paths = os.path.join(root, f) for f in files]
paths = filter(lambda x: get_mime(x) == 'pdf')
for path in paths:
pages = convert_from_path(path)
for page in pages:
# Note: There's probably a better way to assign a name than using `count`
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))
# Note: you would need to redefine the below method for `PDFExtractor`
def _get_imagepath(self, k):
img_path = os.path.join(self._temp_directory, str(k) + '.jpg')
return img_path
# Note: You would need to change `unique` to be `False` in the following line:
# https://github.com/opencv/cvat/blob/1ec89b5f6a445aaa86854356cb73deb7e070d346/cvat/apps/engine/media_extractors.py#L276 But I don't have any way to test the above code currently. |
Thanks for your detailed Response: Unfortunately, the code fails silently. Though it says task has been created, the task is not there in the overview ready for the annotation. The following output from the logs, shows that not frames have been created for the task.
What is more, in the data folder no .jpg file is getting saved when I upload pdfs (projectid 1) but when I upload images (projectid 2) , it works as expected: django@2e82356a9f21:~/data$ ls 1/data/
django@2e82356a9f21:~/data$ ls 2/data/0/0/
0.jpg 1.jpg
django@2e82356a9f21:~/data$ I use your code only minimally adapted: self._dimensions = []
count = 0
for source in source_path:
for root, _, files in os.walk(source):
paths = [os.path.join(root, f) for f in files]
paths = filter(lambda x: get_mime(x) == 'pdf')
for path in paths:
pages = convert_from_path(path)
for page in pages:
# Note: There's probably a better way to assign a name than using `count`
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, str(k) + '.jpg')
return img_path Complete Code: |
I'm sorry about that! I think you need to change the constructor as well. In the class I think the constructor needs to look like the ImageListExtractor. Instead of grabbing the 0 index, they apply the Have you thought about submitting a pull request to CVAT? You could start the title of the pull request with [WIP] to show that you're still iterating on it. |
I think the for loop needs to be tweaked some. Added too many steps. 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') I think the above code should replace the loop starting at this line: |
I will close the issue as outdated. I was able to create a task with a book in pdf format. |
Hi,
I am trying to annotate pdf documents instead of images with cvat and noticed a number of problems that I am not able to resolve alone. I am using the develop branch, because on the master branch the Docker image of cvat does not build successfully.
I am only able to upload a single pdf document (with many pages) but not several pdf documents. The error Code explains that I can only upload a single pdf but it would be helpful to understand the rational for this:
ValueError: Only one video, archive, pdf or many image, directory can be used simultaneously, but 0 image(s), 0 video(s), 0 archive(s), 2 pdf(s), 0 directory(s) found.
The conversion from pdf to image with pdf2image is not working, because poppler is missing from the Dockerfile. I fixed it by adding it to the Dockerfile:
The text was updated successfully, but these errors were encountered: