1

hello I had imported OpenCV into my C++ project but for some reason my code gives me this error.

CODE:

#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

int main()
{
    std::string path = "Resources/test.png";
    cv::Mat img = cv::imread(path);
    imshow("Image", img);
    cv::waitKey(0);

    return 0;
}

error:

enter image description here

I think it might be because of my paths but I'm not sure I think I got them right.

enter image description here

enter image description here

enter image description here

Edit: I reinstalled the setup and installed openCV in a new path and now I do have .dll files but it keeps giving me an error here are new screenshots enter image description here enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

LAYTOR
  • 381
  • 4
  • 12
  • None of the pictures show the existence of the dll file that your OS says it did not find. The required dlls should be placed in one of the folders of the `PATH` environment variable or the same folder as your executable. This Microsoft document describes how and where the OS will search for the dlls: [https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-desktop-applications](https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-desktop-applications) – drescherjm Nov 13 '21 at 16:47
  • Avoid putting dlls in the OS system folders. – drescherjm Nov 13 '21 at 16:51
  • Your bottom picture is `pdb` files. They are synbol files that can be used to help debug the opencv code (if you want to look inside the code when you are debugging your code) but these are not what the OS needs to run your program. It needs the `.dll` files. – drescherjm Nov 13 '21 at 17:04
  • The problem is that even with a reinstall it doesn't download `.dll` files – LAYTOR Nov 13 '21 at 17:19
  • You may want to check the install folder for the dlls. Perhaps the installation did not add the folder containing the dlls to your OS `PATH` environment variable requiring you to do that yourself. – drescherjm Nov 13 '21 at 18:55
  • I did add `PATH` manually. – LAYTOR Nov 13 '21 at 19:44
  • If you logged out and back in after adjusting the `PATH` environment variable and verified that the dlls are in the folder that you added to the `PATH` my guess is you made some type of typing mistake. Also note that `opencv_world454.dll` is a different dll from the one in the picture. `opencv_world454.dll` is the release version of the dll `opencv_world454d.dll` is the debug version. You need debug dlls to run your debug configuration and release dlls to run your release application. – drescherjm Nov 13 '21 at 20:02
  • it looks like I don't have `.dll` installed for some reason does anyone know where I can get them and where should I put them? – LAYTOR Nov 14 '21 at 13:41
  • You can compile opencv yourself if you build from source. Or you can use vcpkg to build it for you. Both options require installing CMake. The simpler option would be to use vcpkg as everything is automatic after you get vcpkg setup. – drescherjm Nov 14 '21 at 13:46
  • Related to vcpkg building: [https://eximia.co/hello-opencv-with-c-using-visual-studio-2017-and-vcpkg/](https://eximia.co/hello-opencv-with-c-using-visual-studio-2017-and-vcpkg/) note that all of the commands that start with a . should be .\ instead of . I assume the web formatting lost the \ for some reason – drescherjm Nov 14 '21 at 13:51
  • I just downloaded [https://sourceforge.net/projects/opencvlibrary/files/4.5.4/opencv-4.5.4-vc14_vc15.exe/download](https://sourceforge.net/projects/opencvlibrary/files/4.5.4/opencv-4.5.4-vc14_vc15.exe/download) and ran the installer and it has the required dlls in the `opencv\build\x64\vc14\bin` or `opencv\build\x64\vc15\bin` folder. If you are using this same download perhaps your problem is your antivirus deleting the dlls. – drescherjm Nov 14 '21 at 14:08
  • Here is an image of the folder contents: [https://pasteboard.co/ma8BExBDHZcB.png](https://pasteboard.co/ma8BExBDHZcB.png) – drescherjm Nov 14 '21 at 14:16
  • okay I reinstalled a setup and installed it in a new path I do have `.dll` files but it still gives me an error give me a min I would edit a post – LAYTOR Nov 14 '21 at 14:31
  • I don't think you are setting the PATH correctly. Related: [https://stackoverflow.com/questions/428085/how-do-i-set-a-path-in-visual-studio/2916103#2916103](https://stackoverflow.com/questions/428085/how-do-i-set-a-path-in-visual-studio/2916103#2916103) – drescherjm Nov 14 '21 at 14:49

2 Answers2

4

Maybe it will help someone Instructions:

  1. Open Project->Property
  2. Configuration Properties->Debugging->Environment
  3. PATH=C:\opencv\build\x64\vc15\bin;

You need your path to the folder

  • I am still facing this issue with visual studio 2022. I have added "include path" in the C/C++.And additional libraries and additional dependencies path in linker setting. – Muhammad Muneeb Ur Rahman Apr 07 '23 at 17:17
1

The solution was to install a new setup and install OpenCV into another path not sure why it helped but still thank you to everyone who helped.

LAYTOR
  • 381
  • 4
  • 12