I am having trouble identifying what causes this problem. Basically, I am working on a jupyter notebook that runs on a conda environment. I have created a file "Myutils.py" which has some helper function for later use. the file is saved in the same folder as the notebook. Giving that I have made the necessary imports in the notebook as well as in the Myutils file, I still got a name error:
In notebook:
first cell:
import cv2
import pytesseract
import numpy as np
import os
import matplotlib.pyplot as plt
from MyUtils import *
%matplotlib inline
then:
img = cv2.imread('./yolov5/runs/detect/exp/crops/address/422.jpg')
plt.imshow(remove_noise(img))
produces this error message:
NameError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17892/550149434.py in <module>
1 img = cv2.imread('./yolov5/runs/detect/exp/crops/address/422.jpg')
----> 2 plt.imshow(remove_noise(img))
~\Documents\Machine Learning\Projects\CIN OCR\MyUtils.py in remove_noise(image)
5 def get_grayscale(image):
6 return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
----> 7
8 # noise removal
9 def remove_noise(image):
NameError: name 'cv2' is not defined
And, in the Myutils.py, we have:
import cv2
import numpy as np
# get grayscale image
def get_grayscale(image):
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)