Python script to apply some basic knowledge regarding Tensorflow/Keras and OpenCV.
This script takes a picture using the webcam and then predicts the object with a simple neural network trained using the Fasion MNIST dataset.
Here you can find some successful results:
It is really recommended to use a virtual environment:
sudo apt update
sudo apt install python3-dev python3-pip
sudo pip3 install -U virtualenv # system-wide install
Then create a new virtual environment
virtualenv --system-site-packages -p python3 ./venv
And activate it
source ./venv/bin/activate # sh, bash, ksh, or zsh
Install the following packages
pip install --upgrade tensorflow
pip install matplotlib
sudo apt install python3-opencv
- Run
python webcam_fashion_mnist.py
. - The webcam will start running.
- If you want to quit, just press 'q'.
- Bring the picture that you want to predict.
- Once the object is in the right frame, press the key 's' to save a picture.
- After hitting 's' the program will show the image in a 28x28 resolution and its prediction.
- Press 'q' to close the result.
You can exit from the virtual environment using the command deactivate
.
- Steven Macías - webcam_fashion_mnist script - StevenMacias
- freeCodeCamp.org - AI Knowledge - TensorFlow 2.0 Full Tutorial - Python Neural Networks for Beginners
- kevinam99 - Webcam Script - capturing-images-from-webcam-using-opencv-python