EdjeElectronics / TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi

A tutorial showing how to train, convert, and run TensorFlow Lite object detection models on Android devices, the Raspberry Pi, and more!
Apache License 2.0
1.5k stars 683 forks source link

import cv2 ModuleNotFoundError: No module named 'cv2' #21

Closed hathemi closed 4 years ago

hathemi commented 4 years ago

(tensorflow-build) C:\tensorflow-build>python TFLite_detection_webcam.py --modeldir=C:\tensorflow\models\research\object_detection\coco_ssd_mobilenet_v1_1.0_quant_2018_06_29 Traceback (most recent call last): File "TFLite_detection_webcam.py", line 19, in import cv2 ModuleNotFoundError: No module named 'cv2'

i have installed tensorflow V1.13.2, but i always got this error !! how can i fix it ?

redfoo22 commented 4 years ago

I'm getting same error "No module named 'cv2" . I'm in the virtual env and I went to install opencv-python and i already have it installed. perhaps cv2 is the incorrect name for the import statement?

jasalazar commented 4 years ago

I am having the same error on an AIY Google Vision Kit, and I cannot even install opencv-python on my Raspberry Pi Zero WH.

lilithebowman commented 3 years ago

To get opencv to install, the name has changed to python3-opencv

lilithebowman commented 3 years ago

This was my fix for the install script

#!/bin/bash

# Get packages required for OpenCV

sudo apt-get -y install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get -y install libxvidcore-dev libx264-dev
sudo add-apt-repository ppa:gezakovacs/ppa && sudo apt update
sudo apt-get -y install qt4-dev-tools libatlas-base-dev
sudo apt-get install -y libjasper
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y libjasper-dev
sudo apt-get install -y libqtgui4
sudo apt-get install -y python3-pyqt5

# Need to get an older version of OpenCV because version 4 has errors
sudo apt install -y python3-opencv

# Get packages required for TensorFlow
# Using the tflite_runtime packages available at https://www.tensorflow.org/lite/guide/python
# Will change to just 'pip3 install tensorflow' once newer versions of TF are added to piwheels

#pip3 install tensorflow

version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')

if [ $version == "3.7" ]; then
pip3 install https://github.com/google-coral/pycoral/releases/download/release-frogfish/tflite_runtime-2.5.0-cp37-cp37m-linux_armv7l.whl
fi

if [ $version == "3.5" ]; then
pip3 install https://github.com/google-coral/pycoral/releases/download/release-frogfish/tflite_runtime-2.5.0-cp35-cp35m-linux_armv7l.whl
fi

Not positive this will work without the proper version set for opencv but you can just do that if it doesn't.