I was able to install the pdftotext utility (comes with Linux I guess) to convert PDF's into text, and extract the images on a Mac:
# install poppler, xpdf, and imagemagick
brew install imagemagick
brew install poppler # not sure if this worked, had to install `xpdf` from online .dmg
pdftotext sample.pdf output.txt
pdfimages sample.pdf pdf-images
# then convert .ppm to .jpg
# one at a time:
# convert pdf-images-001.ppm pdf-images-001.jpg
# batch:
mogrify -format jpg *.ppm
So now I have an output.txt with the (impressively well formatted) text from the PDF, and a bunch of images which I had to convert from .ppm to .jpg with ImageMagick.
Question is, is there any way to now insert references to these images in the right places in the output.txt document? Or, is there a way to combine those two commands so it extracts both text and images and creates links in the text to the images, all at once? Wondering if I have to manually write the parsing code to insert images into the text myself.
Related
I'm trying to unzip a directory of 75,000 images for training a CNN. When unzipping using,
!unzip -uq "/content/BDD_gt_8045.zip" -d "/content/drive/My Drive/Ground_Truth"
not all images unzip. I have about 5,000 I believe. I tried doing it several times but then I have some duplicates. Is there a limit to the number of images I can unzip?
I'm currently stuck on how else I'm meant to get all files into my drive to train the model.
Colab's default 'unzip' binary doesn't work as expected. It seems to cancel the unzipping automatically after a few cycles. Run latest version of 7z and you are good to go.
# To extract with full paths
!7z x <filename.zip>
# To extract all the files in the same folder (ignore paths)
!7z e <filename.zip>
# To specify output directory, use '-o'
!7z x <filename.zip> -o '/content/drive/My Drive/Datasets/FashionMNIST'
I have to write a script in linux with the identify command to extract a date from an image file and add it to the image itself this has to be done for every file in the specified directory. Anyone who could help me? Thanks a lot! I'm now on to this:
for file in $picturemap
do
identify -verbose $file > date.txt
date= date.txt grep | "date:create:"
done
its everything i know
You can use imagemagick package to draw on image files, convert them to other formats and lots of other stuff. There are huge amount of switches that can be useful, just reffer to the documentation.
Install imagemagick
sudo apt-get install imagemagick
Use convert command with draw switch.
Example:
convert test1.jpg -weight 700 -pointsize 200 -draw "gravity north fill black text 0,100 'text' " test2.jpg
this will take test1.jpg annotate text with black color in your image and write it to test.jpg.
I want to create a PDF with selectable/searchable text..
I have source.png which has gone through some pre-processing before OCR, and then I have view.jpg which is a compressed version of source.png to reduce the output PDF file
How do I define the view.jpg in the syntax?
tesseract -l eng source.png out pdf
I'm not sure whether you can specify view.jpg in the command. The out.pdf already contains some sort of a compressed source.png.
I want to convert a powerpoint presentation to multiple images. I already installed LibreOffice on my server and converting docx to pdf is no problem. pptx to pdf conversion does not work. I used following command line:
libreoffice --headless --convert-to pdf filename.pptx
Is there es way to convert pptx to pngs immediately or do I have to convert it to pdf first and then use ghostscript or something?
And what about the quality settings? Is there a way to choose the resolution of the resulting images?
Thanks in advance!
EDIT:
According to this link I was able to convert a pdf to images with the simple command line:
convert <filename>.pdf <filename>.jpg
(I guess you need LibreOffice and ImageMagick for it but not sure about it - worked on my server)
But there are still the problems with the pptx-to-pdf convert.
Thanks to googling and Sebastian Heyn's help I was able to create some high quality images with this line:
convert -density 400 my_filename.pdf -resize 2000x1500 my_filename%d.jpg
Please be patient after using it - you still can type soemthing into the unix console but it's processing. Just wait a few minutes and the jpg files will be created.
For further information about the options check out this link
P.S.: The aspect ratio of a pptx file doesn't seem to be exactly 4:3 because the resulting image size is 1950x1500
After Installing unoconv and LibreOffice you can use:
unoconv --export Quality=100 filename.pptx filename.pdf
to convert your presentation to a pdf. For further options look here.
Afterwards you can - as already said above - use:
convert -density 400 my_filename.pdf -resize 2000x1500 my_filename%d.jpg
to receive the images.
Convertion PPTX to PNG/JPG
This solution requires LibreOffice ( soffice ) and Ghostscript ( gs )
sudo apt install libreoffice ghostscript
Then two steps:
PPTX -> PDF
soffice --headless --convert-to pdf prezentacja.pptx
PDF -> PNG/JPG
gs -sDEVICE=pngalpha -o slajd-%02d.png -r96 prezentacja.pdf
-o slajd-%02d.png - output to file, %02d slajd number, two digits
-r96 - resolution:
96 -> 1280x720
144 -> 1920x1080
Not sure about libreoffice, but afaik its the only program to deal with pptx files.
I found this http://ask.libreoffice.org/en/question/23851/converting-pptx-to-pdf-issue/
If you have pdfs you can use imagemagick to output any quality pictures
I have a script that takes tons of pictures and names them with a time-stamp. These Images are all put into one folder. I want to create a script that takes all the pictures in the folder, combines them into a 10fps video, saves this video as the date and time it started from to the time it ended, and deletes the original pictures. So far, I've seen some people use Ffmpeg or mencoder but I'm not sure how to use these or do what I want with them. Any help is appreciated! Thanks.
You can use the FFMpeg command line interface. You invoke it from the shell. Download the binary and run it by pointing it at the desired directory. %05d is simply string formatting for numbers. %05d just says pad with 4 leading zeros 0001.jpg or whatever.
# Create a directory and copy the original images there for manipulation:
mkdir temp
cp *.JPG temp/.
# Resize the images:
mogrify -resize 200x200 temp/*.JPG
# Create the morph images
convert temp/*.JPG -delay 10 -morph 5 temp/%05d.jpg
# Stitch them together into a video
ffmpeg -r 50 -qscale 2 -i temp/%05d.jpg output.mp4
from http://www.itforeveryone.co.uk/image-to-video.html