Ask Your Question
1

samples.findfile for loading photos

asked 2019-11-11 20:00:48 -0600

Tbot1000 gravatar image

updated 2019-11-12 02:13:22 -0600

berak gravatar image

Hello, I've downloaded openCV for python and am using it on Microsoft Visual Studio and am trying to use the tutorials. Often, they fetch a picture,

src2 = cv.imread(cv.samples.findFile('LinuxLogo.jpg'))

The program runs, but gives an error:

  Message=OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\core\src\utils\samples.cpp:62: error: (-2:Unspecified error) OpenCV samples: Can't find required data file: LinuxLogo.jpg in function 'cv::samples::findFile'

  Source=C:\Users\tiern\source\repos\OpenCV-Dilation\OpenCV_Dilation.py
  StackTrace:
  File "C:\Users\tiern\source\repos\OpenCV-Dilation\OpenCV_Dilation.py", line 48, in <module>
    src = cv.imread(cv.samples.findFile(args.input))

If you could explain how I could load in pictures, I would greatly appreciate it.

Thank you!

edit retag flag offensive close merge delete

Comments

i've downloaded openCV for python.

what exactly did you download and from where ? (does it even have samples / data folders ?)

it probably works great, if you run the sample code from a plain cmdline, not an ide, where you have no control over the startup path.

berak gravatar imageberak ( 2019-11-12 02:15:35 -0600 )edit
1

-I've downloaded it from pip. -It does have a sample folder, and it does have a data folder which contains all pictures specified.

I ran this from a command line and it worked much better. For the erosion and dilation demo it did sort of worked when I entered the code. It created two windows, and each of them had two sliders like in the demo, however, it did not load the picture that was supposed to be in the window.

Tbot1000 gravatar imageTbot1000 ( 2019-11-12 07:13:09 -0600 )edit
1

did you read the documentation

sturkmen gravatar imagesturkmen ( 2019-11-12 11:54:49 -0600 )edit

What do you mean?

Tbot1000 gravatar imageTbot1000 ( 2019-11-13 19:34:38 -0600 )edit

Are you using namespace import argparse?

supra56 gravatar imagesupra56 ( 2020-02-03 06:09:31 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2020-07-13 20:41:02 -0600

Christos M. gravatar image

tl;dr;

Try running cv.imread(args.input) instead of cv.imread(cv.samples.findFile(args.input)) or pass an image path with the parameter --input [SOME_IMAGE] and see if that works. If you get other errors than something with your project setup is wrong (see below).

Full answer:

There is a specific setup you have to do to get OpenCV up and running with python. And that doesn't guarantee that it will work properly. You have to get the right version of OpenCV, the equivalent python version and the right installation way. E.g. the wrapper packages of opencv for python (pip install opencv-python) are causing unexpected errors with python 3.

You probably executed a tutorial script that uses sample files from predefined sample directories (see also in documentation the environment variables).

In the tutorial they are using a sample file LinuxLogo.jpg that can't be found in your working directory / sample directory. Maybe because you probably haven't define a sample directory at all?

You might get further errors even when you fix this error (e.g. I get null window handler errors when running with pip install opencv-python package and AttributeError: module 'cv2' has no attribute 'samples'when running with apt install libopencv-dev python3-opencv). The latter error is easy to fix, just remove the cv.samples.findFile() and directly pass your args.input variable. The first however seems to be a version incompatibility that causes unexpected errors with window elements.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-11-11 20:00:48 -0600

Seen: 8,932 times

Last updated: Jul 13 '20