A simple
cv::Mat element_cross=getStructuringElement(cv::MORPH_CROSS,cv::Size(3,3));
would give me a failed assertion
anchor.inside(Rect(0, 0, ksize.width, ksize.height))) in normalizeAnchor
I didn’t specify and anchor points, but it seem my anchor point isn’t in the rectangle.
the anchor should have been calculated automatically to be in the center… I can’t reproduce this.
check that you copied your code exactly. what else is going on in your code?
please prepare a minimal reproducible example.
Thanks for reply.
I managed to narrow it down to the usage of Boost
. If I add Boost in CMakeLists, it will have the said issue above. My Boost version is 1.75.0. Hope you can reproduce it by this example:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(cv_issue LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(cv_issue main.cpp)
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)
target_include_directories(cv_issue PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(cv_issue ${OpenCV_LIBS})
#below lines are causing trouble
find_package(Boost REQUIRED)
target_include_directories(cv_issue PRIVATE ${Boost_INCLUDE_DIRS})
main.cpp
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cv::Mat element_cross = getStructuringElement(cv::MORPH_CROSS, cv::Size(3,3));
cv::Mat element_rect = getStructuringElement(cv::MORPH_RECT, cv::Size(3,3));
return 0;
}
output:
Hello World!
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.5.5) Error: Assertion failed (anchor.inside(Rect(0, 0, ksize.width, ksize.height))) in normalizeAnchor, file C:\For_CMake\source\opencv-4.5.5\modules\imgproc\src\filterengine.hpp, line 367
1 Like
Update: Maybe I included to much stuff from Boost, while all I need is Boost::property_tree. It’s a header-only library so I just did this so recklessly.
So instead, I changed CMakeList a little bit, which only includes header-onlys, and the issue is gone:
find_package(Boost REQUIRED)
#target_include_directories(meteoroid-thread PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries( cv_issue Boost::boost)
(source: stackoverflow)
But anyway there might be something behind this.
fascinating. boost is a beast. perhaps it’s worth filing an issue on boost and/or opencv and have the experts investigate further.