Is there a way to read the images from the "samples" folder if OpenCV was installed with pip?

Viewed 2176

Is there a way to read the images from the "samples" folder if OpenCV was installed with pip?

I am trying to use one of the images (e.g., box.png) from the samples folder of the OpenCV package with the following Python code

cv2.imread(cv2.samples.findFile('box.png'))

However, I am getting the following error

OpenCV samples: Can't find required data file: box.png in function 'findFile'

Why? And how can I solve it?

I am using the following versions of the packages (for reproducibility), which were installed with pip:

opencv-contrib-python         3.4.2.16
opencv-contrib-python-nonfree 4.1.1.1 
opencv-python                 3.4.2.16

And I am using Python 3.7.5.

Please, don't tell me to use another version of OpenCV or any other library.

2 Answers

here is the example of the code

cap = cv2.imread("C:/Users/user/Desktop/Program2/step3/box.png")

you can change this part C:/Users/user/Desktop/Program2/step3/ to the folder that include a picture

Related