how to show image after fetching from firebase - python

I am trying to fetch image from firebase storage using python into my raspberry pi 3.
import urllib.request
URL=urllib.request.urlretrieve("https://firebasestorage.googleapis.com/v0/b/cameraviewer-32936.appspot.com/o/images%2F49567?alt=media&token=1eded9d0-b9f0-48bf-b869-37756b31a94a")
URL object has a few key value pairs. One of them was 'str' with value of:
'C:\Users\DELL\AppData\Local\Temp\tmp4ki4w7we'
The above value represents the path of image fetched into my device But how can i open image. I don't know where to go or am I confused a lot.

It is pretty simple using Python Imaging Library (PIL). PIL is free and open-source library.
How to Install PIL
If you don't have PILLOW installed, first open a terminal ( CTRL + ALT + T ) and download it using command:
sudo pip install Pillow
Displaying an Image
After you successfully installed it, use the code below to show your downloaded image:
from PIL import Image
import urllib.request
URL=urllib.request.urlretrieve("https://firebasestorage.googleapis.com/v0/b/cameraviewer-32936.appspot.com/o/images%2F49567?alt=media&token=1eded9d0-b9f0-48bf-b869-37756b31a94a")
img = Image.open(URL[0])
img.show()

Related

How do I add and print a image in the console in python with visual studio?

I dont know what to import and how to do this. How do I print and add a image in python.
I have tried nothing im just looking for suggestions.
In the console it's impossible, but you can use OpenCV, PIL, or matplotlib to display images.
With OpenCV you can display the pixel value in the console:
If you are interested in image manipulation check out Pillow. It's an image manipulation/processing library.
You can install it with:
python -m pip install Pillow
To load an image and show it use this:
from PIL import Image
im = Image.open("image.png")
im.show()
For more examples and information check out the official documentation.

What is the Best Way to Get Text From Image with Python?

I want to get the text out of an image. I tried tesseract but I had issues installing it, so im wondering if I can get some help with that or another way to do it.
When I try to use tesseract it says I have no module names PIL? But I know I have pillow installed and i thought that was in reference to it.
I've provided a Colab solution since that will probably be useful to the most people.
Install tesseract in our Colab environment.
!sudo apt install tesseract-ocr
!pip install PyTesseract
Import libraries and mount our Drive
from google.colab import drive
from google.colab.patches import cv2_imshow
drive.mount('/content/drive/')
Set our pytesseract path, read in source image from our Drive, show our source image, then finally convert the image to text.
import cv2
import pytesseract
import numpy as np
pytesseract.pytesseract.terreract_cmd = {
r'/usr/bin/tesseract'
}
src = cv2.imread('/content/drive/MyDrive/Colab Notebooks/images/macbeth.png')
cv2_imshow(src)
output_txt = pytesseract.image_to_string(src)
print(type(output_txt))
print(output_txt)

Python OpenCV imshow fails

I installed opencv on my Ubuntu 14.04 system system with
pip install python-opencv
my Python version is 2.7.14
import cv2
cv2.__version__
tells me that I have the OpenCV version 3.4.0.
After that I wanted to follow the tutorial on the OpenCV website
import numpy as np
import cv2 as cv
img = cv.imread('messi5.jpg',0)
print img
It works fine until this point, but then I am supposed to enter
cv.imshow('image',img)
and I get the following error:
QObject::moveToThread: Current thread (0x233cdb0) is not the object's thread (0x2458430).
Cannot move to target thread (0x233cdb0)
QObject::moveToThread: Current thread (0x233cdb0) is not the object's thread (0x2458430).
Cannot move to target thread (0x233cdb0)
QPixmap: Must construct a QApplication before a QPaintDevice
Does anyone know what the problem is?
Try checking if the image you are reading is loading
image = cv2.imread(filepath,0) #0 for gray scale
if image is None:
print "Cant Load Image"
else:
cv2.imshow("Image", image)
cv2.waitKey(0)
Apparently
pip install python-opencv
is not working at all and should not be used. After I installed Opencv from their website it worked
seems hard to install opencv on ubuntu, I finally get it with a docker image
https://hub.docker.com/r/jjanzic/docker-python3-opencv/
or you can download sources and make install as described on
https://milq.github.io/install-opencv-ubuntu-debian/ using bash script

View Picture in Python and Save User Input about that Picture

Is there a way to have Python pull up a picture (that is stored locally) for a user to view and then have that user input information about that picture, which information is then stored locally?
I found some information about the Image library, but I can't get the Image library to work. When I use the following code, I get an error:
import Image
ImportError: No module named Image
from PIL import Image
ImportError: No module named PIL
I tried to install pillow using
pip install pillow
I'm not sure if it installed correctly. Any one else have this problem? I'm using Python 2.7. I know that I can eventually use the following code to view the picture:
Image.open('example.jpg').show()

To detect digits from an image using cv2 and python

I am trying to detect digits located inside a grid and to tell their positions in an image and don't know where to start. So any help is welcome. So far I have used GT Text software but it didn't solve the purpose. Any helper function, libraries, tutorials, links or anything is welcome.
You should check out the pytesseract module:
https://pypi.python.org/pypi/pytesseract/0.1
It has a one-liner for what you're trying to do:
try:
import Image
except ImportError:
from PIL import Image
import pytesseract as tes
results = tes.image_to_string(Image.open('test.png'),boxes=True)
This will give you results, which has each digit and the image coordinates of its bounding box.
You will need to install PIL (python image library, pip install PIL) and the tesseract c library (brew install tesseract if you have homebrew..) so it's not super trivial but once you have it working, this is the most straight forward OCR in python, and requires no training whatsoever.

Categories

Resources