I'm currently working on a Python project which is a very simple image classifier that uses the kNN approach. I'm required to use Python version 3.8, so I'm using an Anaconda virtual environment for this.
I'm having trouble with the cv2 module, as I keep getting the following error:
Traceback (most recent call last): File "", line 6, in import cv2 ModuleNotFoundError: No module named 'cv2'
Here are all of my imports:
import argparse
import csv
import distutils.util
import os
import Dummy
import cv2
import numpy as np
from scipy.spatial.distance import hamming, cityblock
import math
from operator import itemgetter
Here is how I'm using the cv2 module:
def readAndResize(image_path, width=60, height=30):
image = []
resize = (width, height)
#checking if image_path is a valid path
if os.path.isfile(image_path):
#IF TRUE: reading the image and storing in variable "readImage", resizing readImage and appending it to image list
readImage = cv2.imread(image_path)
resizedImage = cv2.resize(readImage, resize)
image.append(resizedImage)
return image
#IF FALSE: return empty image list
else:
return image
I really don't understand what could be causing this error.
Here's what I've tried so far:
pip installing opencv-Python
pip uninstalling and reinstalling opencv-python
Checking which directories Python is searching for installed packages, as well as the directory where the packages are being installed. Everything seems to check out.
I even tried deleting my old venv and creating a brand new one, installing all of the packages again, and still can't seem to solve or even figure out what is causing this error
I would really appreciate it if anyone can point me to any solutions or suggestions on how I can fix this issue. Any help would be greatly appreciated. Thank you!