Occurs when I try to clear the memory of a vector. There is something similar , but I'm not sure how much this applies to my problem, since there was a conflict between the DLL and the template, but I have no templates (see below, it turned out that there is, namely Rect ).

And I connect opencv via .hpp files, although the linker has settings that I need .lib from opencv\build\x64\vc14\lib , and the .dll in the next folder. True, it is opencv_ffmpeg310_64.dll , opencv_world310.dll and opencv_world310d.dll .

 cv::Size size(40, 60); std::vector<cv::Rect> objects1, objects2; // достаём xml с каскадом Хаара для анфаса, ищем на кадре и записываем static_cast<cv::CascadeClassifier*>(repository->get(VisionFrontCascade))-> detectMultiScale(*gray, objects1, 1.3, 3, 0, size); // достаём xml с каскадом Хаара для профиля, ищем на кадре и записываем static_cast<cv::CascadeClassifier*>(repository->get(VisionProfileCascade))-> detectMultiScale(*gray, objects2, 1.3, 3, 0, size); if (!objects2.empty()) { objects1.insert(objects1.end(), objects2.begin(), objects2.end()); objects2.clear(); } objects2.shrink_to_fit(); // ошибка здесь // черчение прямоугольников вокруг найденных объектов Concurrency::parallel_for_each(objects1.begin(), objects1.end(), [&](cv::Rect collection) { auto x = collection.x, y = collection.y; rectangle(*frame, cv::Point(x * 2, y * 2), cv::Point((x + collection.width) * 2, (y + collection.height) * 2), cv::Scalar(0.0, 0.0, 255.0)); // скаляр работает в BGR }); objects1.clear(); objects1.shrink_to_fit(); // или здесь 

It turned out that the template is still there - in cv :: Rect .

But for cv::CascadeClassifier::detectMultiScale be sure to specify std::vector<cv::Rect> .

If you remove shrink_to_fit() , then the error occurs already in the destructor.

  • one
    And try cppcheck or some other static code analyzer . - PinkTux
  • Well, did you try to build with the / MDd flag? - goldstar_labs
  • @goldstar_labs, I have already specified /MDd for debug and /MD for release in the project settings. - brenoritvrezorkre
  • one
    @brenoritvrezorkre, and opencv than (and how) collected? The essence of the problem is what, in c ++, the one who allocated it should free the memory (otherwise there will be an error), in your case the memory is allocated to opencv, it means that opencv should release it. Usually this problem is solved by dynamically linking dll and exe to one version of CRT. However, if the crt versions are different, the error will persist. A dirty solution to the problem is to declare these vectors dynamically, i.e. std::vector<cv::Rect>* objects1 = new std::vector<cv::Rect>; and do not touch them until the end of time, it will be a memory leak, but you'll know about it). - goldstar_labs
  • one
    A good solution is to export / import the functions for allocating and freeing memory between modules. But it is cumbersome and not always feasible. To free up memory, you can also try to wedge into someone else's memory using the GetProcessHeap functions and release via HeapFree (but this is fraught with a shot through leg). But I think the problem is somewhere in the build configuration). - goldstar_labs

1 answer 1

Still, I realized what the hell. When I had VS2013 , everything worked fine. But then he broke down, did not want to recover, and I rolled the project on VS2015 . Thinking that the algorithm that worked well before, and now it works well, didn’t go there. When looked - a subject. So, now I have thrown all my code on a clean project, and everything works. Thank you all.