Exporting Google colab output as a screenshot and save to my mounted drive - python-3.x

I have written a google colab py3 script which shows some colorful table as output:
I just want to export the output as a PNG image and save it to my google drive.
Any idea how can I do it?

Related

Github isn't displaying my embedded images in my Jupiter Notebook

I uploaded a Jupyter notebook to GitHub with some screenshots that I embedded into markdown cells using the following format:
![Step1](Images/Step1.png)
However, when trying to view the notebook on GitHub, none of the embedded images appear. Is there something I can do to mend this?
I do not want users to have to run a Python code block to display the image. They are screenshots of different steps in a "getting started" guide I made, so I want them to appear in Markdown cells.
This is just a shot in the dark, but does your relative filepath need to point to the root directory? Like this:
![Step1](./Images/Step1.png)
That's my best guess.
If the images are posted on Github, open the image in a new tab, and copy the URL like so (Put in the actual link; I just added ellipses to redact the repository name):
![Step1](https://raw.githubusercontent.com/ ... /main/images/Step1.png)

How can I take high-quality screenshots of a PDF without ImageMagick using Python?

I would like to automate the process of taking screenshots of a PDF file's pages. I want to be able to specify the zoom (optional) so that the overall image size can be controlled. I would also like to be able to specify the dpi of the screenshots being saved.
Sample PDF file can be found at this link.
I have already tried opening the file with selenium web driver (Firefox), but the scrolling is not supported for rendered PDF files, apparently.
Is there a way to render this PDF file and then use any image processing module like Pillow or Open-CV to take the screenshots, or any module that does it directly?

How do I write files to my local drive when using Google Colab?

I have a set of data I want to write to an Excel file. I'm using Google Colab, and while I successfully use the following snippet to import files into my notebook...
from google.colab import files
uploaded = files.upload()
...I can't seem to figure out how to write files to my local drive. I'm using the xlwt library to write the data to an Excel file, as follows:
wb.save('Washington_1791.xls')
It completes the task without throwing an error, but I'm not sure of the save location, and I need to get it to save to my local drive. Google gives me lots of suggestions on how to import from the local drive, but not how to save.
Any files written by your Python code will be on the disk of the virtual machine on which the code is running: if you want to get the files to your local disk, you will have to download them explicitly.
To do this, go to the Files tab in the left pane (click the (>) in the upper left to open the pane). Within that file viewer you can right-click any file and choose "Download".

How to save python pptx on colab

Is there a way to save the Python pptx file on Google drive or desktop?
I tried Prs.save() to save the pptx file, but it doesn't work.
Your presentation will be saving to the Files panel on the left of Colab:
From here you can download the saved presentation file.
If you want to save to Google Drive you need to mount the drive (icon is at the top of the Files panel) and then simply append the relevant path to your file name when saving:
prs.save("/content/drive/My Drive/.../presentation.pptx")

Image preprocessing in Python for OCR

I'm doing pre-processing of images for OCR in python. I converted the pdf to binary images. The output I get is like this
I want the ouput to be something like this
Any idea how to go about this?
You have to use Tesseract library for extracting text from given image.
I am using window system so I downloaded it from location https://sourceforge.net/projects/tesseract-ocr-alt/files/.
Suppose you have installed it at location "E:\w\Tesseract-OCR"
Then put your image at the same location. Lets call your image question.png
Now go to command prompt and give command,
E:\w\Tesseract-OCR>tesseract.exe question.png answer.txt
Where answer.txt is text file which Tesseract will create you can give any other name instead of answer.txt and question.txt is your file.
Once command is successfully executed check output in answer.txt.
In case of your image I got following output.
Investment Type: Customer Owned
System Information
Fire III
Video I]
So in this case it is recognizing only text correctly.

Resources