0
votes

So i'm trying to make opencv open a image i have saved on my computer and display it in a window. But my visual studio compiler keeps throwing this excpetion:

Exception thrown at 0x00007FF80A2012DB (vcruntime140.dll) in Pixel_analisys.exe: 0xC0000005: Access violation reading location 0x0000021037BD4000.

I have tried to change the file location, double checked the linker if the libraries was linked. However using the cv:haveImageReader() with the same file path it says it is not accesable/not permissions to access it, i have double checked the file location and checked if it is locked in any way and still cant figure this out.

#include <windows.h>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
cv::Mat a;

int main()
{
    a = cv::imread("C:\\Users\\simuls26\\Desktop\\dog.jpg");
    cv::imshow("dog", a);
    return 0;
}

This is my callstack:

vcruntime140.dll!memcpy_repmovs() Line 40 Unknown [Inline Frame] msvcp140.dll!std::_Char_traits<char,int>::copy(char * const) Line 64 C++ msvcp140.dll!std::basic_streambuf<char,std::char_traits>::xsputn(const char * _Ptr, __int64 _Count) Line 345 C++ opencv_world455.dll!std::_Insert_string<char,struct std::char_traits,unsigned __int64>(class std::basic_ostream<char,struct std::char_traits > &,char const * const,unsigned __int64) C++ opencv_world455.dll!std::allocator<struct cv::Ptr >::deallocate(struct cv::Ptr * const,unsigned __int64) C++ opencv_world455.dll!cv::imread(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,int) C++ opencv_world455.dll!cv::imread(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,int) C++ Pixel_analisys.exe!main() Line 14 C++ [External Code]

EDIT: I have fixed the .dll compiler issue by using the visual studio 2015 toolset instead of the 2022 toolset. However now my program wont open my picture. My code is still the same and i have trippled checked my file path. the console output i'm getting are as following

[ WARN:[email protected]] global C:\build\master_winpack-build-win64-vc15\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('

failed to open img.jpg

1
First of all, provide OpenCV version that you're having the problem with. Secondly, have you done anything else with this OpenCV version before? I'm just trying to be sure that whether it's cv::imread related or not. If you have not, be sure that there's no compiler version mismatch with the static and dynamic libraries. - Orkhan Aliyev
@OrkhanAliyev i'm using opencv 4.5.5. Also this is the first time i have used opencv since i just installed it and got it setup. How might i go about checking the compiler versions of them? - ZNOW
Which version of Visual Studio you're using? - Orkhan Aliyev
@OrkhanAliyev i'm using visual studio 2022. Figured out that it might have been because of the 2022 toolset so i installed the 2015 one and it stopped throwing the exception. However now my program still wont read the file - ZNOW
Please, don't forget to provide necessary information when you ask a question. As for your problem, can you share the current output? (Edit your question, since comment section is not a chatroom) - Orkhan Aliyev

1 Answers

0
votes

MSVC is a compiler that Microsoft Visual Studio IDE uses. Your output log clearly shows that there is a mismatch in the OpenCV library and MSVC version you are using. Make sure the library you have installed is compatible with your compiler. Microsoft Visual C++

As for OpenCV, if you don't build OpenCV yourself(It means, you'll use pre-built binaries), again, make sure that the libraries are inside the opencvdir/x64/vc16(vc16:The compiler packaged with Visual Studio 2019). If you are using a higher version of that library, the folder name will already lead you.