Image Recognition using OpenCV and performing Image Analysis using Google Cloud Vision API
Image Recognition using OpenCV and performing Image Analysis using Google Cloud Vision API
Here is the code for image recognition using OpenCV and Google Cloud Vision API with input from webcam. OpenCV tracks faces and monitors for smiles, when a smile is detected a picture is saved locally on the computer, sent the image to Google Cloud Storage bucket, then Google Cloud Vision API is invoked to analyze that picture, and the results are sent back to console. We need a webcam to provide video input to the program.
$ python -m pip install google-cloud
$ sudo pip install --upgrade google-cloud-storage
$ pip install --upgrade google-cloud-vision
$ export GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_KEY_FILE
, https://cloud.google.com/speech/docs/auth#using_a_service_accountUbuntu 16.04 actually ships out-of-the-box with both Python 2.7 and Python 3.5 installed. The actual versions are:
Make sure to create virtual environment for Python 2 while installing OpenCV. Virtualenv is a tool to create isolated Python environments. Refer: http://pythonopencv.com/install-opencv-3-3-and-python2-7-3-5-bindings-on-ubuntu-16-04/, https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/
If you face isssues while installing OpenCV or running the program, try re-installing OpenCV ‘WITH_JPEG=OFF’ in CMAKE command this time.
Run following code in the terminal,
python imagerecog-opencv-cloudvision.py
https://cloud.google.com/vision/docs/
https://cloud.google.com/python/
https://cloud.google.com/vision/docs/reference/libraries
Enjoy, Have Fun!