-1

I am using Visual Studio Code and try to 'import cv2', but I see an error.

import cv2
import numpy as np

def sketch(image):
    img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    img_gray_blur = cv2.GaussianBlur(img_gray, (5,5), 0)
    canny_edges = cv2.Canny(img_gray_blur, 10, 70)
    ret, mask = cv2.threshold(canny_edges, 70, 255, cv2.THRESH_BINARY_INV)
    return mask

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 1
    Which Python version are you using? – FLAK-ZOSO Jan 26 '22 at 06:34
  • It looks like you installed `opencv-python` but didn't install `numpy` yet. Since your shared code doesn't even use `numpy`, you could just remove the import line, or install numpy using `pip`, `conda` or whatever you use to install packages. – Grismar Jan 26 '22 at 06:46
  • Slightly different error message, but the canonical question for a related problem on Windows may be *[Error "Import Error: No module named numpy" on Windows](https://stackoverflow.com/questions/7818811/)* (2011, 40 answers and 300 votes). – Peter Mortensen Aug 22 '22 at 15:47

1 Answers1

2

You have to to your cmd.exe, or if you are not in windows you simply have to go to your command prompt.

pip install numpy

And after writing this in the prompt, try another time to run your Python file.

FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28