Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor core module for type-safety #12487

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar

# OpenCV build options
# ===================================================
OCV_OPTION(DISABLE_TYPE_SAFE_API "Disable enum-based type-safe API? If disabled, 'int' types will be utilized" OFF)
OCV_OPTION(DISABLE_TYPE_COMPATIBLE_API "Disable backwards compatibility with legacy API?" OFF IF NOT DISABLE_TYPE_SAFE_API)
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) )
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (MSVC OR (NOT IOS AND NOT CMAKE_CROSSCOMPILING) ) )
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
Expand Down Expand Up @@ -343,6 +345,10 @@ OCV_OPTION(CV_TRACE "Enable OpenCV code trace" ON)
OCV_OPTION(ENABLE_PYLINT "Add target with Pylint checks" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )
OCV_OPTION(ENABLE_FLAKE8 "Add target with Python flake8 checker" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) )

if(DISABLE_TYPE_SAFE_API)
ocv_assert(DISABLE_TYPE_COMPATIBLE_API)
endif()

if(ENABLE_IMPL_COLLECTION)
add_definitions(-DCV_COLLECT_IMPL_DATA)
endif()
Expand Down Expand Up @@ -1020,6 +1026,9 @@ else()
endif()
status(" ccache:" OPENCV_COMPILER_IS_CCACHE THEN YES ELSE NO)
status(" Precompiled headers:" PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS THEN YES ELSE NO)
status(" Type-safe API:" DISABLE_TYPE_SAFE_API THEN "NO" ELSE "YES")
status(" Compatible type API:" DISABLE_TYPE_COMPATIBLE_API THEN "NO" ELSE "YES")


# ========================== Dependencies ============================
ocv_get_all_libs(deps_modules deps_extra deps_3rdparty)
Expand Down
6 changes: 6 additions & 0 deletions cmake/OpenCVDetectCUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ if(CUDA_FOUND)
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-but-set-variable)
endif()

if(DISABLE_TYPE_SAFE_API)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -DCV_DISABLE_TYPE_SAFE_API=1)
elseif(DISABLE_TYPE_COMPATIBLE_API)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler -DCV_DISABLE_TYPE_COMPATIBLE_API=1)
endif()

CUDA_COMPILE(${VAR} ${ARGN})

foreach(var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
Expand Down
10 changes: 5 additions & 5 deletions modules/calib3d/src/fisheye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void cv::fisheye::initUndistortRectifyMap( InputArray K, InputArray D, InputArra

CV_Assert( m1type == CV_16SC2 || m1type == CV_32F || m1type <=0 );
map1.create( size, m1type <= 0 ? CV_16SC2 : m1type );
map2.create( size, map1.type() == CV_16SC2 ? CV_16UC1 : CV_32F );
map2.create( size, map1.type() == CV_16SC2 ? CV_16UC1 : CV_32FC1 );

CV_Assert((K.depth() == CV_32F || K.depth() == CV_64F) && (D.depth() == CV_32F || D.depth() == CV_64F));
CV_Assert((P.empty() || P.depth() == CV_32F || P.depth() == CV_64F) && (R.empty() || R.depth() == CV_32F || R.depth() == CV_64F));
Expand Down Expand Up @@ -664,9 +664,9 @@ void cv::fisheye::stereoRectify( InputArray K1, InputArray D1, InputArray K2, In

// apply to both views
Matx33d ri1 = wr * r_r.t();
Mat(ri1, false).convertTo(R1, R1.empty() ? CV_64F : R1.type());
Mat(ri1, false).convertTo(R1, R1.empty() ? CV_64F : R1.depth());
Matx33d ri2 = wr * r_r;
Mat(ri2, false).convertTo(R2, R2.empty() ? CV_64F : R2.type());
Mat(ri2, false).convertTo(R2, R2.empty() ? CV_64F : R2.depth());
Vec3d tnew = ri2 * tvec;

// calculate projection/camera matrices. these contain the relevant rectified image internal params (fx, fy=fx, cx, cy)
Expand All @@ -687,11 +687,11 @@ void cv::fisheye::stereoRectify( InputArray K1, InputArray D1, InputArray K2, In

Mat(Matx34d(fc_new, 0, cc_new[0].x, 0,
0, fc_new, cc_new[0].y, 0,
0, 0, 1, 0), false).convertTo(P1, P1.empty() ? CV_64F : P1.type());
0, 0, 1, 0), false).convertTo(P1, P1.empty() ? CV_64F : P1.depth());

Mat(Matx34d(fc_new, 0, cc_new[1].x, tnew[0]*fc_new, // baseline * focal length;,
0, fc_new, cc_new[1].y, 0,
0, 0, 1, 0), false).convertTo(P2, P2.empty() ? CV_64F : P2.type());
0, 0, 1, 0), false).convertTo(P2, P2.empty() ? CV_64F : P2.depth());

if (Q.needed())
Mat(Matx44d(1, 0, 0, -cc_new[0].x,
Expand Down
6 changes: 6 additions & 0 deletions modules/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ if(HAVE_CUDA)
ocv_target_compile_definitions(${the_module} PUBLIC OPENCV_TRAITS_ENABLE_DEPRECATED)
endif()

if(DISABLE_TYPE_SAFE_API)
ocv_target_compile_definitions(${the_module} PUBLIC CV_DISABLE_TYPE_SAFE_API=1)
elseif(DISABLE_TYPE_COMPATIBLE_API)
ocv_target_compile_definitions(${the_module} PUBLIC CV_DISABLE_TYPE_COMPATIBLE_API=1)
endif()

ocv_add_accuracy_tests()
ocv_add_perf_tests()

Expand Down