In the official opencv tutorial: https://docs.opencv.org/4.x/db/deb/tutorial_display_image.html
In, when running the sample code, we will encounter the following error reports:
error: (-2:Unspecified error) OpenCV samples: Can’t find required data file: starry_night.jpg in function ‘findFile’
After checking [opencv installation path] / opencv / modules / core / SRC / utils / samples After the CPP code, we know that the reason for the error is that the environment variable is not set:
So let’s set the environment variable:
sudo vi ~/.bashrc
export OPENCV_ SAMPLES_ DATA_ Path = [opencv installation path] / opencv / samples
So we can run the sample code normally.