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.
cv::threshold(gray, thresh, 60, 355, cv::THRESH_BINARY)
, I guess355
is a typo and it should be255
!? As I said, seems like a stupid idea, but just for sanity, I would fix that and test again. Can't reproduce the error with OpenCV 3.4.0 (Debug), 4.0.0 or 4.1.0 (Debug/Release) by the way. – HansHirse