I am writing a function that finds and returns the center of any image given to the system (they are mostly circular objects.)
When running the findContours method using OpenCV3.10, the function throws an error in the vector class. Here is my code:
cv::Mat image = next_image(cam); cv::Mat gray; cv::Mat thresh; cv::Mat conv; cv::Mat canny_output; cv::Mat nImg; std::vector<std::vector<cv::Point>> contours; std::vector<cv::Vec4i> hierarchy; //threshold and contour the image cv::cvtColor(image, conv, cv::COLOR_GRAY2RGB); cv::cvtColor(conv, gray, CV_BGR2GRAY); cv::blur(gray, gray, cv::Size(5, 5)); cv::threshold(gray, thresh, 60, 355, cv::THRESH_BINARY); cv::findContours(thresh, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
Visual Studio throws the Exception Unhandled when it hits findContours (and specifically in the vector file that it uses) and the message says
Unhandled exception at 0x5825AF78 (opencv_core310.dll) in Laser_Tracking.exe: 0xC0000005: Access violation reading location 0xDDDDDDD9.
I am currently using Visual Studios 2019 to run OpenCV.
I tested and found your problem. This seems to be a problem with OpenCV configuration. My environment is also VS2019 and OpenCV 3.1.0
In the configuration of the Linker, I added opencv_world310.lib and opencv_world310d.lib. That is to say, I added the release and debug versions of the library, and I was running in debug mode, which may have no impact on other functions, but it is different for findContours() function, so I changed the order of the two libraries, or we can delete one of the libraries, which depends on your own mode.
This is a problem left when we configure Visual Studio. Since there is no error reported, the problem has not been found. In this case, we need to develop good configuration habits.
User contributions licensed under CC BY-SA 3.0