Merged the trunk r8589:8653 - all changes related to build warnings
This commit is contained in:
parent
73c152abc4
commit
bd0e0b5800
27
3rdparty/libjasper/CMakeLists.txt
vendored
27
3rdparty/libjasper/CMakeLists.txt
vendored
@ -7,31 +7,24 @@ project(${JASPER_LIBRARY})
|
||||
|
||||
add_definitions(-DEXCLUDE_MIF_SUPPORT -DEXCLUDE_PNM_SUPPORT -DEXCLUDE_BMP_SUPPORT -DEXCLUDE_RAS_SUPPORT -DEXCLUDE_JPG_SUPPORT -DEXCLUDE_PGX_SUPPORT)
|
||||
|
||||
# List of C++ files:
|
||||
ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# The .cpp files:
|
||||
file(GLOB lib_srcs *.c)
|
||||
file(GLOB lib_hdrs *.h)
|
||||
file(GLOB lib_ext_hdrs jasper/*.h)
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# Define the library target:
|
||||
# Define the library target:
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
add_library(${JASPER_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs} ${lib_ext_hdrs})
|
||||
|
||||
if(MSVC)
|
||||
if(NOT ENABLE_NOISY_WARNINGS)
|
||||
string(REPLACE "/W3" "/W0" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
string(REPLACE "/W4" "/W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
add_definitions(-DJAS_WIN_MSVC_BUILD)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-uninitialized")
|
||||
endif()
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wno-implicit-function-declaration -Wno-uninitialized -Wmissing-prototypes -Wmissing-declarations -Wunused -Wshadow
|
||||
/wd4013 /wd4018 /wd4715 /wd4244 /wd4101 /wd4267)
|
||||
|
||||
if(UNIX)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
|
||||
@ -39,16 +32,12 @@ if(UNIX)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-implicit-function-declaration -Wno-unused")
|
||||
endif()
|
||||
|
||||
set_target_properties(${JASPER_LIBRARY}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME ${JASPER_LIBRARY}
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
PROPERTIES
|
||||
OUTPUT_NAME ${JASPER_LIBRARY}
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${JASPER_LIBRARY} PROPERTIES FOLDER "3rdparty")
|
||||
|
19
3rdparty/libjpeg/CMakeLists.txt
vendored
19
3rdparty/libjpeg/CMakeLists.txt
vendored
@ -4,24 +4,17 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
project(${JPEG_LIBRARY})
|
||||
|
||||
# List of C++ files:
|
||||
|
||||
ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# The .cpp files:
|
||||
file(GLOB lib_srcs *.c)
|
||||
file(GLOB lib_hdrs *.h)
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# Define the library target:
|
||||
# Define the library target:
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
add_library(${JPEG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
@ -32,11 +25,13 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set_source_files_properties(jcdctmgr.c PROPERTIES COMPILE_FLAGS "-O1")
|
||||
endif()
|
||||
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align -Wshadow)
|
||||
|
||||
set_target_properties(${JPEG_LIBRARY}
|
||||
PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY}
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}
|
||||
)
|
||||
PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY}
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}
|
||||
)
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${JPEG_LIBRARY} PROPERTIES FOLDER "3rdparty")
|
||||
|
18
3rdparty/libpng/CMakeLists.txt
vendored
18
3rdparty/libpng/CMakeLists.txt
vendored
@ -4,34 +4,30 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
project(${PNG_LIBRARY})
|
||||
|
||||
# List of C++ files:
|
||||
|
||||
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" ${ZLIB_INCLUDE_DIR})
|
||||
|
||||
file(GLOB lib_srcs *.c)
|
||||
file(GLOB lib_hdrs *.h)
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# Define the library target:
|
||||
# Define the library target:
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
add_library(${PNG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3")
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align)
|
||||
|
||||
set_target_properties(${PNG_LIBRARY}
|
||||
PROPERTIES OUTPUT_NAME ${PNG_LIBRARY}
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
PROPERTIES OUTPUT_NAME ${PNG_LIBRARY}
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${PNG_LIBRARY} PROPERTIES FOLDER "3rdparty")
|
||||
|
18
3rdparty/libtiff/CMakeLists.txt
vendored
18
3rdparty/libtiff/CMakeLists.txt
vendored
@ -26,7 +26,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmakein"
|
||||
|
||||
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" ${ZLIB_INCLUDE_DIR})
|
||||
|
||||
# List of C++ files:
|
||||
set(lib_srcs
|
||||
tif_aux.c
|
||||
tif_close.c
|
||||
@ -91,10 +90,9 @@ if(WIN32)
|
||||
list(APPEND lib_srcs tif_win32.c)
|
||||
endif(WIN32)
|
||||
|
||||
if(MSVC AND NOT ENABLE_NOISY_WARNINGS)
|
||||
string(REPLACE "/W4" "/W0" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
string(REPLACE "/W4" "/W0" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
endif()
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef
|
||||
-Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast)
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations /wd4100 /wd4244 /wd4706 /wd4127 /wd4701 /wd4018 /wd4267 /wd4306 /wd4305 /wd4312 /wd4311)
|
||||
|
||||
if(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR CV_ICC))
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
||||
@ -104,11 +102,11 @@ add_library(${TIFF_LIBRARY} STATIC ${lib_srcs})
|
||||
target_link_libraries(${TIFF_LIBRARY} ${ZLIB_LIBRARIES})
|
||||
|
||||
set_target_properties(${TIFF_LIBRARY}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME "${TIFF_LIBRARY}"
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
PROPERTIES
|
||||
OUTPUT_NAME "${TIFF_LIBRARY}"
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${TIFF_LIBRARY} PROPERTIES FOLDER "3rdparty")
|
||||
|
2
3rdparty/libtiff/tif_config.h.cmakein
vendored
2
3rdparty/libtiff/tif_config.h.cmakein
vendored
@ -143,7 +143,7 @@
|
||||
|
||||
/* Signed 64-bit type formatter */
|
||||
/* Unsigned 64-bit type formatter */
|
||||
#ifdef _MSC_VER
|
||||
#if defined _MSC_VER || defined __MINGW__ || defined __MINGW32__
|
||||
# define TIFF_UINT64_FORMAT "%I64u"
|
||||
# define TIFF_SSIZE_FORMAT "%Iu"
|
||||
#else
|
||||
|
13
3rdparty/tbb/CMakeLists.txt
vendored
13
3rdparty/tbb/CMakeLists.txt
vendored
@ -119,13 +119,16 @@ endif()
|
||||
add_library(tbb STATIC ${lib_srcs} ${lib_hdrs} "${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h" "${CMAKE_CURRENT_SOURCE_DIR}/${tbb_version_file}")
|
||||
target_link_libraries(tbb c m dl)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"")
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef -Wmissing-declarations)
|
||||
string(REPLACE "-Werror=non-virtual-dtor" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include \"${CMAKE_CURRENT_SOURCE_DIR}/android_additional.h\"")
|
||||
|
||||
set_target_properties(tbb
|
||||
PROPERTIES OUTPUT_NAME tbb
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
PROPERTIES OUTPUT_NAME tbb
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}"
|
||||
)
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(tbb PROPERTIES FOLDER "3rdparty")
|
||||
|
2
3rdparty/tbb/version_string.tmp
vendored
2
3rdparty/tbb/version_string.tmp
vendored
@ -6,4 +6,4 @@
|
||||
"TBB: BUILD_GLIBC Unknown" ENDL \
|
||||
"TBB: BUILD_LD Unknown" ENDL \
|
||||
"TBB: BUILD_TARGET Unknown" ENDL \
|
||||
"TBB: BUILD_COMMAND use cv::getBuildInformation() for details" ENDL \
|
||||
"TBB: BUILD_COMMAND use cv::getBuildInformation() for details" ENDL
|
||||
|
2
3rdparty/tbb/version_string.ver
vendored
2
3rdparty/tbb/version_string.ver
vendored
@ -6,4 +6,4 @@
|
||||
#N": BUILD_GLIBC Unknown" ENDL \
|
||||
#N": BUILD_LD Unknown" ENDL \
|
||||
#N": BUILD_TARGET Unknown" ENDL \
|
||||
#N": BUILD_COMMAND use cv::getBuildInformation() for details" ENDL \
|
||||
#N": BUILD_COMMAND use cv::getBuildInformation() for details" ENDL
|
||||
|
13
3rdparty/zlib/CMakeLists.txt
vendored
13
3rdparty/zlib/CMakeLists.txt
vendored
@ -5,19 +5,10 @@
|
||||
|
||||
project(${ZLIB_LIBRARY} C)
|
||||
|
||||
include(CheckTypeSize)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
#
|
||||
# Check to see if we have large file support
|
||||
#
|
||||
check_type_size(off64_t OFF64_T)
|
||||
if(HAVE_OFF64_T)
|
||||
add_definitions(-D_LARGEFILE64_SOURCE=1)
|
||||
endif()
|
||||
|
||||
#
|
||||
# Check for fseeko
|
||||
#
|
||||
@ -82,9 +73,7 @@ if(UNIX)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC AND NOT ENABLE_NOISY_WARNINGS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4013")
|
||||
endif()
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 -Wattributes -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations)
|
||||
|
||||
set_target_properties(${ZLIB_LIBRARY} PROPERTIES
|
||||
OUTPUT_NAME ${ZLIB_LIBRARY}
|
||||
|
10
3rdparty/zlib/zconf.h.cmakein
vendored
10
3rdparty/zlib/zconf.h.cmakein
vendored
@ -410,10 +410,18 @@ typedef uLong FAR uLongf;
|
||||
* both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
|
||||
* equivalently requesting no 64-bit operations
|
||||
*/
|
||||
#if -_LARGEFILE64_SOURCE - -1 == 1
|
||||
#if defined _LARGEFILE64_SOURCE && -_LARGEFILE64_SOURCE - -1 == 1
|
||||
# undef _LARGEFILE64_SOURCE
|
||||
#endif
|
||||
|
||||
#ifndef _LFS64_LARGEFILE
|
||||
# define _LFS64_LARGEFILE 0
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_OFFSET_BITS
|
||||
# define _FILE_OFFSET_BITS 0
|
||||
#endif
|
||||
|
||||
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
|
||||
# define Z_LARGE
|
||||
#endif
|
||||
|
@ -188,6 +188,8 @@ OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions"
|
||||
OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF )
|
||||
OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF )
|
||||
|
||||
OCV_OPTION(OPENCV_CAN_BREAK_BINARY_COMPATIBILITY "Allow changes breaking binary compatibility with OpenCV 2.4.0" OFF )
|
||||
|
||||
# uncategorized options
|
||||
# ===================================================
|
||||
OCV_OPTION(CMAKE_VERBOSE "Verbose mode" OFF )
|
||||
@ -286,13 +288,13 @@ endif()
|
||||
# ----------------------------------------------------------------------------
|
||||
# OpenCV compiler and linker options
|
||||
# ----------------------------------------------------------------------------
|
||||
include(cmake/OpenCVCompilerOptions.cmake REQUIRED)
|
||||
|
||||
# In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release:
|
||||
if(CMAKE_GENERATOR MATCHES "Makefiles|Ninja" AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
include(cmake/OpenCVCompilerOptions.cmake REQUIRED)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Use statically or dynamically linked CRT?
|
||||
@ -328,6 +330,15 @@ if(UNIX)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#
|
||||
# Check to see if we have large file support (needed by zlib)
|
||||
#
|
||||
include(CheckTypeSize)
|
||||
check_type_size(off64_t OFF64_T)
|
||||
if(HAVE_OFF64_T)
|
||||
add_definitions(-D_LARGEFILE64_SOURCE=1)
|
||||
endif()
|
||||
|
||||
include(cmake/OpenCVPCHSupport.cmake REQUIRED)
|
||||
include(cmake/OpenCVModule.cmake REQUIRED)
|
||||
|
||||
@ -471,6 +482,7 @@ else()
|
||||
status(" Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
|
||||
status(" Linker flags (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
|
||||
endif()
|
||||
status(" Precompiled headers:" PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS THEN YES ELSE NO)
|
||||
|
||||
# ========================== OpenCV modules ==========================
|
||||
status("")
|
||||
@ -560,7 +572,7 @@ if(WITH_TIFF)
|
||||
if(TIFF_VERSION_STRING AND TIFF_FOUND)
|
||||
status(" TIFF:" "${TIFF_LIBRARY} (ver ${TIFF_VERSION} - ${TIFF_VERSION_STRING})")
|
||||
else()
|
||||
status(" TIFF:" TIFF_FOUND THEN "${TIFF_LIBRARY} (ver ${TIFF_VERSION})" ELSE "build (ver ${TIFF_VERSION})")
|
||||
status(" TIFF:" TIFF_FOUND THEN "${TIFF_LIBRARY} (ver ${TIFF_VERSION})" ELSE "build (ver ${TIFF_VERSION} - ${TIFF_VERSION_STRING})")
|
||||
endif()
|
||||
else()
|
||||
status(" TIFF:" "NO")
|
||||
|
@ -42,6 +42,9 @@
|
||||
#ifndef __CVCOMMON_H_
|
||||
#define __CVCOMMON_H_
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "cxcore.h"
|
||||
#include "cv.h"
|
||||
#include "cxmisc.h"
|
||||
|
@ -80,11 +80,11 @@ typedef struct CvValArray
|
||||
( *( (float*) (aux->data + ((int) (idx1)) * aux->step ) ) < \
|
||||
*( (float*) (aux->data + ((int) (idx2)) * aux->step ) ) )
|
||||
|
||||
CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_16s, short, CMP_VALUES, CvValArray* )
|
||||
static CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_16s, short, CMP_VALUES, CvValArray* )
|
||||
|
||||
CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32s, int, CMP_VALUES, CvValArray* )
|
||||
static CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32s, int, CMP_VALUES, CvValArray* )
|
||||
|
||||
CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32f, float, CMP_VALUES, CvValArray* )
|
||||
static CV_IMPLEMENT_QSORT_EX( icvSortIndexedValArray_32f, float, CMP_VALUES, CvValArray* )
|
||||
|
||||
CV_BOOST_IMPL
|
||||
void cvGetSortedIndices( CvMat* val, CvMat* idx, int sortcols )
|
||||
@ -190,7 +190,7 @@ float cvEvalStumpClassifier( CvClassifier* classifier, CvMat* sample )
|
||||
}
|
||||
|
||||
#define ICV_DEF_FIND_STUMP_THRESHOLD( suffix, type, error ) \
|
||||
CV_BOOST_IMPL int icvFindStumpThreshold_##suffix( \
|
||||
static int icvFindStumpThreshold_##suffix( \
|
||||
uchar* data, size_t datastep, \
|
||||
uchar* wdata, size_t wstep, \
|
||||
uchar* ydata, size_t ystep, \
|
||||
@ -213,13 +213,10 @@ CV_BOOST_IMPL int icvFindStumpThreshold_##suffix(
|
||||
float* curval = NULL; \
|
||||
float curlerror = 0.0F; \
|
||||
float currerror = 0.0F; \
|
||||
float wposl; \
|
||||
float wposr; \
|
||||
\
|
||||
int i = 0; \
|
||||
int idx = 0; \
|
||||
\
|
||||
wposl = wposr = 0.0F; \
|
||||
if( *sumw == FLT_MAX ) \
|
||||
{ \
|
||||
/* calculate sums */ \
|
||||
@ -298,8 +295,8 @@ CV_BOOST_IMPL int icvFindStumpThreshold_##suffix(
|
||||
*/
|
||||
#define ICV_DEF_FIND_STUMP_THRESHOLD_MISC( suffix, type ) \
|
||||
ICV_DEF_FIND_STUMP_THRESHOLD( misc_##suffix, type, \
|
||||
wposl = 0.5F * ( wl + wyl ); \
|
||||
wposr = 0.5F * ( wr + wyr ); \
|
||||
float wposl = 0.5F * ( wl + wyl ); \
|
||||
float wposr = 0.5F * ( wr + wyr ); \
|
||||
curleft = 0.5F * ( 1.0F + curleft ); \
|
||||
curright = 0.5F * ( 1.0F + curright ); \
|
||||
curlerror = MIN( wposl, wl - wposl ); \
|
||||
@ -311,8 +308,8 @@ CV_BOOST_IMPL int icvFindStumpThreshold_##suffix(
|
||||
*/
|
||||
#define ICV_DEF_FIND_STUMP_THRESHOLD_GINI( suffix, type ) \
|
||||
ICV_DEF_FIND_STUMP_THRESHOLD( gini_##suffix, type, \
|
||||
wposl = 0.5F * ( wl + wyl ); \
|
||||
wposr = 0.5F * ( wr + wyr ); \
|
||||
float wposl = 0.5F * ( wl + wyl ); \
|
||||
float wposr = 0.5F * ( wr + wyr ); \
|
||||
curleft = 0.5F * ( 1.0F + curleft ); \
|
||||
curright = 0.5F * ( 1.0F + curright ); \
|
||||
curlerror = 2.0F * wposl * ( 1.0F - curleft ); \
|
||||
@ -326,8 +323,8 @@ CV_BOOST_IMPL int icvFindStumpThreshold_##suffix(
|
||||
*/
|
||||
#define ICV_DEF_FIND_STUMP_THRESHOLD_ENTROPY( suffix, type ) \
|
||||
ICV_DEF_FIND_STUMP_THRESHOLD( entropy_##suffix, type, \
|
||||
wposl = 0.5F * ( wl + wyl ); \
|
||||
wposr = 0.5F * ( wr + wyr ); \
|
||||
float wposl = 0.5F * ( wl + wyl ); \
|
||||
float wposr = 0.5F * ( wr + wyr ); \
|
||||
curleft = 0.5F * ( 1.0F + curleft ); \
|
||||
curright = 0.5F * ( 1.0F + curright ); \
|
||||
curlerror = currerror = 0.0F; \
|
||||
@ -1149,7 +1146,7 @@ float cvEvalCARTClassifier( CvClassifier* classifier, CvMat* sample )
|
||||
return ((CvCARTClassifier*) classifier)->val[-idx];
|
||||
}
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float cvEvalCARTClassifierIdx( CvClassifier* classifier, CvMat* sample )
|
||||
{
|
||||
CV_FUNCNAME( "cvEvalCARTClassifierIdx" );
|
||||
@ -1209,7 +1206,7 @@ void cvReleaseCARTClassifier( CvClassifier** classifier )
|
||||
*classifier = NULL;
|
||||
}
|
||||
|
||||
void CV_CDECL icvDefaultSplitIdx_R( int compidx, float threshold,
|
||||
static void CV_CDECL icvDefaultSplitIdx_R( int compidx, float threshold,
|
||||
CvMat* idx, CvMat** left, CvMat** right,
|
||||
void* userdata )
|
||||
{
|
||||
@ -1258,7 +1255,7 @@ void CV_CDECL icvDefaultSplitIdx_R( int compidx, float threshold,
|
||||
}
|
||||
}
|
||||
|
||||
void CV_CDECL icvDefaultSplitIdx_C( int compidx, float threshold,
|
||||
static void CV_CDECL icvDefaultSplitIdx_C( int compidx, float threshold,
|
||||
CvMat* idx, CvMat** left, CvMat** right,
|
||||
void* userdata )
|
||||
{
|
||||
@ -1529,7 +1526,7 @@ typedef struct CvBoostTrainer
|
||||
* using ANY appropriate weak classifier
|
||||
*/
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses,
|
||||
CvMat* weakTrainVals,
|
||||
CvMat* /*weights*/,
|
||||
@ -1560,7 +1557,7 @@ CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses,
|
||||
CV_MAT2VEC( *trainClasses, ydata, ystep, m );
|
||||
CV_MAT2VEC( *weakTrainVals, traindata, trainstep, trainnum );
|
||||
|
||||
assert( m == trainnum );
|
||||
CV_Assert( m == trainnum );
|
||||
|
||||
idxnum = 0;
|
||||
idxstep = 0;
|
||||
@ -1607,7 +1604,7 @@ CvBoostTrainer* icvBoostStartTraining( CvMat* trainClasses,
|
||||
* Discrete AdaBoost functions
|
||||
*
|
||||
*/
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float icvBoostNextWeakClassifierDAB( CvMat* weakEvalVals,
|
||||
CvMat* trainClasses,
|
||||
CvMat* /*weakTrainVals*/,
|
||||
@ -1640,8 +1637,8 @@ float icvBoostNextWeakClassifierDAB( CvMat* weakEvalVals,
|
||||
CV_MAT2VEC( *trainClasses, ydata, ystep, ynum );
|
||||
CV_MAT2VEC( *weights, wdata, wstep, wnum );
|
||||
|
||||
assert( m == ynum );
|
||||
assert( m == wnum );
|
||||
CV_Assert( m == ynum );
|
||||
CV_Assert( m == wnum );
|
||||
|
||||
sumw = 0.0F;
|
||||
err = 0.0F;
|
||||
@ -1681,7 +1678,7 @@ float icvBoostNextWeakClassifierDAB( CvMat* weakEvalVals,
|
||||
* Real AdaBoost functions
|
||||
*
|
||||
*/
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float icvBoostNextWeakClassifierRAB( CvMat* weakEvalVals,
|
||||
CvMat* trainClasses,
|
||||
CvMat* /*weakTrainVals*/,
|
||||
@ -1743,7 +1740,7 @@ float icvBoostNextWeakClassifierRAB( CvMat* weakEvalVals,
|
||||
#define CV_LB_PROB_THRESH 0.01F
|
||||
#define CV_LB_WEIGHT_THRESHOLD 0.0001F
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
void icvResponsesAndWeightsLB( int num, uchar* wdata, int wstep,
|
||||
uchar* ydata, int ystep,
|
||||
uchar* fdata, int fstep,
|
||||
@ -1772,7 +1769,7 @@ void icvResponsesAndWeightsLB( int num, uchar* wdata, int wstep,
|
||||
}
|
||||
}
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
CvBoostTrainer* icvBoostStartTrainingLB( CvMat* trainClasses,
|
||||
CvMat* weakTrainVals,
|
||||
CvMat* weights,
|
||||
@ -1808,8 +1805,8 @@ CvBoostTrainer* icvBoostStartTrainingLB( CvMat* trainClasses,
|
||||
CV_MAT2VEC( *weakTrainVals, traindata, trainstep, trainnum );
|
||||
CV_MAT2VEC( *weights, wdata, wstep, wnum );
|
||||
|
||||
assert( m == trainnum );
|
||||
assert( m == wnum );
|
||||
CV_Assert( m == trainnum );
|
||||
CV_Assert( m == wnum );
|
||||
|
||||
|
||||
idxnum = 0;
|
||||
@ -1854,7 +1851,7 @@ CvBoostTrainer* icvBoostStartTrainingLB( CvMat* trainClasses,
|
||||
return ptr;
|
||||
}
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float icvBoostNextWeakClassifierLB( CvMat* weakEvalVals,
|
||||
CvMat* trainClasses,
|
||||
CvMat* weakTrainVals,
|
||||
@ -1889,9 +1886,9 @@ float icvBoostNextWeakClassifierLB( CvMat* weakEvalVals,
|
||||
CV_MAT2VEC( *weakTrainVals, traindata, trainstep, trainnum );
|
||||
CV_MAT2VEC( *weights, wdata, wstep, wnum );
|
||||
|
||||
assert( m == ynum );
|
||||
assert( m == wnum );
|
||||
assert( m == trainnum );
|
||||
CV_Assert( m == ynum );
|
||||
CV_Assert( m == wnum );
|
||||
CV_Assert( m == trainnum );
|
||||
//assert( m == trainer->count );
|
||||
|
||||
for( i = 0; i < trainer->count; i++ )
|
||||
@ -1913,7 +1910,7 @@ float icvBoostNextWeakClassifierLB( CvMat* weakEvalVals,
|
||||
* Gentle AdaBoost
|
||||
*
|
||||
*/
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float icvBoostNextWeakClassifierGAB( CvMat* weakEvalVals,
|
||||
CvMat* trainClasses,
|
||||
CvMat* /*weakTrainVals*/,
|
||||
@ -1944,8 +1941,8 @@ float icvBoostNextWeakClassifierGAB( CvMat* weakEvalVals,
|
||||
CV_MAT2VEC( *trainClasses, ydata, ystep, ynum );
|
||||
CV_MAT2VEC( *weights, wdata, wstep, wnum );
|
||||
|
||||
assert( m == ynum );
|
||||
assert( m == wnum );
|
||||
CV_Assert( m == ynum );
|
||||
CV_Assert( m == wnum );
|
||||
|
||||
sumw = 0.0F;
|
||||
for( i = 0; i < trainer->count; i++ )
|
||||
@ -2071,7 +2068,7 @@ typedef struct CvBtTrainer
|
||||
typedef void (*CvZeroApproxFunc)( float* approx, CvBtTrainer* trainer );
|
||||
|
||||
/* Mean zero approximation */
|
||||
void icvZeroApproxMean( float* approx, CvBtTrainer* trainer )
|
||||
static void icvZeroApproxMean( float* approx, CvBtTrainer* trainer )
|
||||
{
|
||||
int i;
|
||||
int idx;
|
||||
@ -2088,7 +2085,7 @@ void icvZeroApproxMean( float* approx, CvBtTrainer* trainer )
|
||||
/*
|
||||
* Median zero approximation
|
||||
*/
|
||||
void icvZeroApproxMed( float* approx, CvBtTrainer* trainer )
|
||||
static void icvZeroApproxMed( float* approx, CvBtTrainer* trainer )
|
||||
{
|
||||
int i;
|
||||
int idx;
|
||||
@ -2106,7 +2103,7 @@ void icvZeroApproxMed( float* approx, CvBtTrainer* trainer )
|
||||
/*
|
||||
* 0.5 * log( mean(y) / (1 - mean(y)) ) where y in {0, 1}
|
||||
*/
|
||||
void icvZeroApproxLog( float* approx, CvBtTrainer* trainer )
|
||||
static void icvZeroApproxLog( float* approx, CvBtTrainer* trainer )
|
||||
{
|
||||
float y_mean;
|
||||
|
||||
@ -2117,7 +2114,7 @@ void icvZeroApproxLog( float* approx, CvBtTrainer* trainer )
|
||||
/*
|
||||
* 0 zero approximation
|
||||
*/
|
||||
void icvZeroApprox0( float* approx, CvBtTrainer* trainer )
|
||||
static void icvZeroApprox0( float* approx, CvBtTrainer* trainer )
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -2143,7 +2140,7 @@ static CvZeroApproxFunc icvZeroApproxFunc[] =
|
||||
CV_BOOST_IMPL
|
||||
void cvBtNext( CvCARTClassifier** trees, CvBtTrainer* trainer );
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
CvBtTrainer* cvBtStart( CvCARTClassifier** trees,
|
||||
CvMat* trainData,
|
||||
int flags,
|
||||
@ -2270,7 +2267,7 @@ CvBtTrainer* cvBtStart( CvCARTClassifier** trees,
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void icvBtNext_LSREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
static void icvBtNext_LSREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -2288,7 +2285,7 @@ void icvBtNext_LSREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
}
|
||||
|
||||
|
||||
void icvBtNext_LADREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
static void icvBtNext_LADREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
{
|
||||
CvCARTClassifier* ptr;
|
||||
int i, j;
|
||||
@ -2361,7 +2358,7 @@ void icvBtNext_LADREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
}
|
||||
|
||||
|
||||
void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
static void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
{
|
||||
CvCARTClassifier* ptr;
|
||||
int i, j;
|
||||
@ -2476,7 +2473,7 @@ void icvBtNext_MREG( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
|
||||
#define CV_LOG_VAL_MAX 18.0
|
||||
|
||||
void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
static void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
{
|
||||
CvCARTClassifier* ptr;
|
||||
int i, j;
|
||||
@ -2617,7 +2614,7 @@ void icvBtNext_L2CLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
trees[0] = ptr;
|
||||
}
|
||||
|
||||
void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
static void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
{
|
||||
int i, j, k, kk, num;
|
||||
CvMat sample;
|
||||
@ -2781,7 +2778,7 @@ void icvBtNext_LKCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
}
|
||||
|
||||
|
||||
void icvBtNext_XXBCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
static void icvBtNext_XXBCLASS( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
{
|
||||
float alpha;
|
||||
int i;
|
||||
@ -2898,7 +2895,7 @@ void cvBtNext( CvCARTClassifier** trees, CvBtTrainer* trainer )
|
||||
}
|
||||
}
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
void cvBtEnd( CvBtTrainer** trainer )
|
||||
{
|
||||
CV_FUNCNAME( "cvBtEnd" );
|
||||
@ -2931,7 +2928,7 @@ void cvBtEnd( CvBtTrainer** trainer )
|
||||
* Boosted tree model as a classifier *
|
||||
\****************************************************************************************/
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float cvEvalBtClassifier( CvClassifier* classifier, CvMat* sample )
|
||||
{
|
||||
float val;
|
||||
@ -2972,7 +2969,7 @@ float cvEvalBtClassifier( CvClassifier* classifier, CvMat* sample )
|
||||
return val;
|
||||
}
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float cvEvalBtClassifier2( CvClassifier* classifier, CvMat* sample )
|
||||
{
|
||||
float val;
|
||||
@ -2988,7 +2985,7 @@ float cvEvalBtClassifier2( CvClassifier* classifier, CvMat* sample )
|
||||
return (float) (val >= 0.0F);
|
||||
}
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
float cvEvalBtClassifierK( CvClassifier* classifier, CvMat* sample )
|
||||
{
|
||||
int cls = 0;
|
||||
@ -3072,7 +3069,7 @@ static CvEvalBtClassifier icvEvalBtClassifier[] =
|
||||
cvEvalBtClassifier
|
||||
};
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
int cvSaveBtClassifier( CvClassifier* classifier, const char* filename )
|
||||
{
|
||||
CV_FUNCNAME( "cvSaveBtClassifier" );
|
||||
@ -3137,7 +3134,7 @@ int cvSaveBtClassifier( CvClassifier* classifier, const char* filename )
|
||||
}
|
||||
|
||||
|
||||
CV_BOOST_IMPL
|
||||
static
|
||||
void cvReleaseBtClassifier( CvClassifier** ptr )
|
||||
{
|
||||
CV_FUNCNAME( "cvReleaseBtClassifier" );
|
||||
@ -3183,7 +3180,7 @@ void cvReleaseBtClassifier( CvClassifier** ptr )
|
||||
__END__;
|
||||
}
|
||||
|
||||
void cvTuneBtClassifier( CvClassifier* classifier, CvMat*, int flags,
|
||||
static void cvTuneBtClassifier( CvClassifier* classifier, CvMat*, int flags,
|
||||
CvMat*, CvMat* , CvMat*, CvMat*, CvMat* )
|
||||
{
|
||||
CV_FUNCNAME( "cvTuneBtClassifier" );
|
||||
@ -3244,7 +3241,7 @@ void cvTuneBtClassifier( CvClassifier* classifier, CvMat*, int flags,
|
||||
__END__;
|
||||
}
|
||||
|
||||
CvBtClassifier* icvAllocBtClassifier( CvBoostType type, int flags, int numclasses,
|
||||
static CvBtClassifier* icvAllocBtClassifier( CvBoostType type, int flags, int numclasses,
|
||||
int numiter )
|
||||
{
|
||||
CvBtClassifier* ptr;
|
||||
@ -3720,7 +3717,7 @@ void cvWriteTrainData( const char* filename, int flags,
|
||||
|
||||
|
||||
#define ICV_RAND_SHUFFLE( suffix, type ) \
|
||||
void icvRandShuffle_##suffix( uchar* data, size_t step, int num ) \
|
||||
static void icvRandShuffle_##suffix( uchar* data, size_t step, int num ) \
|
||||
{ \
|
||||
time_t seed; \
|
||||
type tmp; \
|
||||
|
@ -394,7 +394,7 @@ void icvSaveStageHaarClassifier( CvIntHaarClassifier* classifier, FILE* file )
|
||||
|
||||
|
||||
|
||||
CvIntHaarClassifier* icvLoadCARTStageHaarClassifierF( FILE* file, int step )
|
||||
static CvIntHaarClassifier* icvLoadCARTStageHaarClassifierF( FILE* file, int step )
|
||||
{
|
||||
CvStageHaarClassifier* ptr = NULL;
|
||||
|
||||
@ -525,9 +525,9 @@ float icvEvalTreeCascadeClassifierFilter( CvIntHaarClassifier* classifier, sum_t
|
||||
sum_type* tilted, float normfactor )
|
||||
{
|
||||
CvTreeCascadeNode* ptr;
|
||||
CvTreeCascadeClassifier* tree;
|
||||
//CvTreeCascadeClassifier* tree;
|
||||
|
||||
tree = (CvTreeCascadeClassifier*) classifier;
|
||||
//tree = (CvTreeCascadeClassifier*) classifier;
|
||||
|
||||
|
||||
|
||||
|
@ -169,10 +169,11 @@ CvIntHaarFeatures* icvCreateIntHaarFeatures( CvSize winsize,
|
||||
int dx = 0;
|
||||
int dy = 0;
|
||||
|
||||
#if 0
|
||||
float factor = 1.0F;
|
||||
|
||||
factor = ((float) winsize.width) * winsize.height / (24 * 24);
|
||||
#if 0
|
||||
|
||||
s0 = (int) (s0 * factor);
|
||||
s1 = (int) (s1 * factor);
|
||||
s2 = (int) (s2 * factor);
|
||||
@ -1257,11 +1258,11 @@ CvBackgroundData* icvCreateBackgroundData( const char* filename, CvSize winsize
|
||||
while( !feof( input ) )
|
||||
{
|
||||
*imgfilename = '\0';
|
||||
if( !fgets( imgfilename, PATH_MAX - (int)(imgfilename - full) - 1, input ))
|
||||
if( !fgets( imgfilename, PATH_MAX - (int)(imgfilename - full) - 1, input ))
|
||||
break;
|
||||
len = (int)strlen( imgfilename );
|
||||
if( len > 0 && imgfilename[len-1] == '\n' )
|
||||
imgfilename[len-1] = 0, len--;
|
||||
if( len > 0 && imgfilename[len-1] == '\n' )
|
||||
imgfilename[len-1] = 0, len--;
|
||||
if( len > 0 )
|
||||
{
|
||||
if( (*imgfilename) == '#' ) continue; /* comment */
|
||||
@ -1878,7 +1879,7 @@ int icvGetHaarTraininDataFromVecCallback( CvMat* img, void* userdata )
|
||||
return 1;
|
||||
}
|
||||
|
||||
int icvGetHaarTrainingDataFromBGCallback ( CvMat* img, void* /*userdata*/ )
|
||||
static int icvGetHaarTrainingDataFromBGCallback ( CvMat* img, void* /*userdata*/ )
|
||||
{
|
||||
if (! cvbgdata)
|
||||
return 0;
|
||||
@ -2190,15 +2191,15 @@ void cvCreateCascadeClassifier( const char* dirname,
|
||||
{
|
||||
char xml_path[1024];
|
||||
int len = (int)strlen(dirname);
|
||||
CvHaarClassifierCascade* cascade = 0;
|
||||
CvHaarClassifierCascade* cascade1 = 0;
|
||||
strcpy( xml_path, dirname );
|
||||
if( xml_path[len-1] == '\\' || xml_path[len-1] == '/' )
|
||||
len--;
|
||||
strcpy( xml_path + len, ".xml" );
|
||||
cascade = cvLoadHaarClassifierCascade( dirname, cvSize(winwidth,winheight) );
|
||||
if( cascade )
|
||||
cvSave( xml_path, cascade );
|
||||
cvReleaseHaarClassifierCascade( &cascade );
|
||||
cascade1 = cvLoadHaarClassifierCascade( dirname, cvSize(winwidth,winheight) );
|
||||
if( cascade1 )
|
||||
cvSave( xml_path, cascade1 );
|
||||
cvReleaseHaarClassifierCascade( &cascade1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -2215,7 +2216,7 @@ void cvCreateCascadeClassifier( const char* dirname,
|
||||
|
||||
/* tree cascade classifier */
|
||||
|
||||
int icvNumSplits( CvStageHaarClassifier* stage )
|
||||
static int icvNumSplits( CvStageHaarClassifier* stage )
|
||||
{
|
||||
int i;
|
||||
int num;
|
||||
@ -2229,7 +2230,7 @@ int icvNumSplits( CvStageHaarClassifier* stage )
|
||||
return num;
|
||||
}
|
||||
|
||||
void icvSetNumSamples( CvHaarTrainingData* training_data, int num )
|
||||
static void icvSetNumSamples( CvHaarTrainingData* training_data, int num )
|
||||
{
|
||||
assert( num <= training_data->maxnum );
|
||||
|
||||
@ -2238,7 +2239,7 @@ void icvSetNumSamples( CvHaarTrainingData* training_data, int num )
|
||||
training_data->cls.cols = training_data->weights.cols = num;
|
||||
}
|
||||
|
||||
void icvSetWeightsAndClasses( CvHaarTrainingData* training_data,
|
||||
static void icvSetWeightsAndClasses( CvHaarTrainingData* training_data,
|
||||
int num1, float weight1, float cls1,
|
||||
int num2, float weight2, float cls2 )
|
||||
{
|
||||
@ -2258,7 +2259,7 @@ void icvSetWeightsAndClasses( CvHaarTrainingData* training_data,
|
||||
}
|
||||
}
|
||||
|
||||
CvMat* icvGetUsedValues( CvHaarTrainingData* training_data,
|
||||
static CvMat* icvGetUsedValues( CvHaarTrainingData* training_data,
|
||||
int start, int num,
|
||||
CvIntHaarFeatures* haar_features,
|
||||
CvStageHaarClassifier* stage )
|
||||
@ -2501,7 +2502,6 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
|
||||
{
|
||||
CvTreeCascadeNode* single_cluster;
|
||||
CvTreeCascadeNode* multiple_clusters;
|
||||
CvSplit* cur_split;
|
||||
int single_num;
|
||||
|
||||
icvSetNumSamples( training_data, poscount + negcount );
|
||||
@ -2674,18 +2674,19 @@ void cvCreateTreeCascadeClassifier( const char* dirname,
|
||||
} /* try different number of clusters */
|
||||
cvReleaseMat( &vals );
|
||||
|
||||
CV_CALL( cur_split = (CvSplit*) cvAlloc( sizeof( *cur_split ) ) );
|
||||
CV_ZERO_OBJ( cur_split );
|
||||
CvSplit* curSplit;
|
||||
CV_CALL( curSplit = (CvSplit*) cvAlloc( sizeof( *curSplit ) ) );
|
||||
CV_ZERO_OBJ( curSplit );
|
||||
|
||||
if( last_split ) last_split->next = cur_split;
|
||||
else first_split = cur_split;
|
||||
last_split = cur_split;
|
||||
if( last_split ) last_split->next = curSplit;
|
||||
else first_split = curSplit;
|
||||
last_split = curSplit;
|
||||
|
||||
cur_split->single_cluster = single_cluster;
|
||||
cur_split->multiple_clusters = multiple_clusters;
|
||||
cur_split->num_clusters = best_clusters;
|
||||
cur_split->parent = parent;
|
||||
cur_split->single_multiple_ratio = (float) single_num / best_num;
|
||||
curSplit->single_cluster = single_cluster;
|
||||
curSplit->multiple_clusters = multiple_clusters;
|
||||
curSplit->num_clusters = best_clusters;
|
||||
curSplit->parent = parent;
|
||||
curSplit->single_multiple_ratio = (float) single_num / best_num;
|
||||
}
|
||||
|
||||
if( parent ) parent = parent->next_same_level;
|
||||
|
@ -83,7 +83,7 @@
|
||||
* cij - coeffs[i][j], coeffs[2][2] = 1
|
||||
* (ui, vi) - rectangle vertices
|
||||
*/
|
||||
void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
|
||||
static void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
|
||||
double coeffs[3][3] )
|
||||
{
|
||||
//CV_FUNCNAME( "cvWarpPerspective" );
|
||||
@ -130,7 +130,7 @@ void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
|
||||
}
|
||||
|
||||
/* Warps source into destination by a perspective transform */
|
||||
void cvWarpPerspective( CvArr* src, CvArr* dst, double quad[4][2] )
|
||||
static void cvWarpPerspective( CvArr* src, CvArr* dst, double quad[4][2] )
|
||||
{
|
||||
CV_FUNCNAME( "cvWarpPerspective" );
|
||||
|
||||
@ -323,8 +323,6 @@ void cvWarpPerspective( CvArr* src, CvArr* dst, double quad[4][2] )
|
||||
int i00, i10, i01, i11;
|
||||
i00 = i10 = i01 = i11 = (int) fill_value;
|
||||
|
||||
double i = fill_value;
|
||||
|
||||
/* linear interpolation using 2x2 neighborhood */
|
||||
if( isrc_x >= 0 && isrc_x <= src_size.width &&
|
||||
isrc_y >= 0 && isrc_y <= src_size.height )
|
||||
@ -349,9 +347,8 @@ void cvWarpPerspective( CvArr* src, CvArr* dst, double quad[4][2] )
|
||||
|
||||
double i0 = i00 + (i10 - i00)*delta_x;
|
||||
double i1 = i01 + (i11 - i01)*delta_x;
|
||||
i = i0 + (i1 - i0)*delta_y;
|
||||
|
||||
((uchar*)(dst_data + y * dst_step))[x] = (uchar) i;
|
||||
((uchar*)(dst_data + y * dst_step))[x] = (uchar) (i0 + (i1 - i0)*delta_y);
|
||||
}
|
||||
x_min += k_left;
|
||||
x_max += k_right;
|
||||
|
@ -44,6 +44,9 @@
|
||||
*
|
||||
* Measure performance of classifier
|
||||
*/
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "cv.h"
|
||||
#include "highgui.h"
|
||||
|
||||
@ -211,7 +214,7 @@ int main( int argc, char* argv[] )
|
||||
totaltime = 0.0;
|
||||
if( info != NULL )
|
||||
{
|
||||
int x, y, width, height;
|
||||
int x, y;
|
||||
IplImage* img;
|
||||
int hits, missed, falseAlarms;
|
||||
int totalHits, totalMissed, totalFalseAlarms;
|
||||
@ -246,11 +249,12 @@ int main( int argc, char* argv[] )
|
||||
ref = (ObjectPos*) cvAlloc( refcount * sizeof( *ref ) );
|
||||
for( i = 0; i < refcount; i++ )
|
||||
{
|
||||
error = (fscanf( info, "%d %d %d %d", &x, &y, &width, &height ) != 4);
|
||||
int w, h;
|
||||
error = (fscanf( info, "%d %d %d %d", &x, &y, &w, &h ) != 4);
|
||||
if( error ) break;
|
||||
ref[i].x = 0.5F * width + x;
|
||||
ref[i].y = 0.5F * height + y;
|
||||
ref[i].width = sqrtf( 0.5F * (width * width + height * height) );
|
||||
ref[i].x = 0.5F * w + x;
|
||||
ref[i].y = 0.5F * h + y;
|
||||
ref[i].width = sqrtf( 0.5F * (w * w + h * h) );
|
||||
ref[i].found = 0;
|
||||
ref[i].neghbors = 0;
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "HOGfeatures.h"
|
||||
#include "cascadeclassifier.h"
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "boost.h"
|
||||
#include "cascadeclassifier.h"
|
||||
#include <queue>
|
||||
@ -481,7 +484,7 @@ CvCascadeBoostTrainData::CvCascadeBoostTrainData( const CvFeatureEvaluator* _fea
|
||||
void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluator,
|
||||
int _numSamples,
|
||||
int _precalcValBufSize, int _precalcIdxBufSize,
|
||||
const CvDTreeParams& _params )
|
||||
const CvDTreeParams& _params )
|
||||
{
|
||||
int* idst = 0;
|
||||
unsigned short* udst = 0;
|
||||
@ -504,10 +507,10 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
|
||||
responses = &_resp;
|
||||
// TODO: check responses: elements must be 0 or 1
|
||||
|
||||
if( _precalcValBufSize < 0 || _precalcIdxBufSize < 0)
|
||||
if( _precalcValBufSize < 0 || _precalcIdxBufSize < 0)
|
||||
CV_Error( CV_StsOutOfRange, "_numPrecalcVal and _numPrecalcIdx must be positive or 0" );
|
||||
|
||||
var_count = var_all = featureEvaluator->getNumFeatures() * featureEvaluator->getFeatureSize();
|
||||
var_count = var_all = featureEvaluator->getNumFeatures() * featureEvaluator->getFeatureSize();
|
||||
sample_count = _numSamples;
|
||||
|
||||
is_buf_16u = false;
|
||||
@ -556,7 +559,7 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
|
||||
cat_count = cvCreateMat( 1, cat_var_count + 1, CV_32SC1 );
|
||||
|
||||
// precalculate valCache and set indices in buf
|
||||
precalculate();
|
||||
precalculate();
|
||||
|
||||
// now calculate the maximum size of split,
|
||||
// create memory storage that will keep nodes and splits of the decision tree
|
||||
@ -739,8 +742,8 @@ const int* CvCascadeBoostTrainData::get_cat_var_data( CvDTreeNode* n, int vi, in
|
||||
float CvCascadeBoostTrainData::getVarValue( int vi, int si )
|
||||
{
|
||||
if ( vi < numPrecalcVal && !valCache.empty() )
|
||||
return valCache.at<float>( vi, si );
|
||||
return (*featureEvaluator)( vi, si );
|
||||
return valCache.at<float>( vi, si );
|
||||
return (*featureEvaluator)( vi, si );
|
||||
}
|
||||
|
||||
|
||||
@ -1232,7 +1235,7 @@ void CvCascadeBoostTree::split_node_data( CvDTreeNode* node )
|
||||
data->free_node_data(node);
|
||||
}
|
||||
|
||||
void auxMarkFeaturesInMap( const CvDTreeNode* node, Mat& featureMap)
|
||||
static void auxMarkFeaturesInMap( const CvDTreeNode* node, Mat& featureMap)
|
||||
{
|
||||
if ( node && node->split )
|
||||
{
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "cascadeclassifier.h"
|
||||
#include <queue>
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "traincascade_features.h"
|
||||
#include "cascadeclassifier.h"
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "haarfeatures.h"
|
||||
#include "cascadeclassifier.h"
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "cv.h"
|
||||
#include "imagestorage.h"
|
||||
#include <stdio.h>
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "lbpfeatures.h"
|
||||
#include "cascadeclassifier.h"
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
|
||||
#include "cv.h"
|
||||
#include "cascadeclassifier.h"
|
||||
|
||||
|
@ -14,6 +14,8 @@ if(MINGW)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
string(REGEX REPLACE "^ *| * $" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
string(REGEX REPLACE "^ *| * $" "" CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT}")
|
||||
if(CMAKE_CXX_FLAGS STREQUAL CMAKE_CXX_FLAGS_INIT)
|
||||
# override cmake default exception handling option
|
||||
string(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
@ -21,73 +23,112 @@ if(MSVC)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(OPENCV_EXTRA_FLAGS "")
|
||||
set(OPENCV_EXTRA_C_FLAGS "")
|
||||
set(OPENCV_EXTRA_C_FLAGS_RELEASE "")
|
||||
set(OPENCV_EXTRA_C_FLAGS_DEBUG "")
|
||||
set(OPENCV_EXTRA_CXX_FLAGS "")
|
||||
set(OPENCV_EXTRA_FLAGS_RELEASE "")
|
||||
set(OPENCV_EXTRA_FLAGS_DEBUG "")
|
||||
set(OPENCV_EXTRA_EXE_LINKER_FLAGS "")
|
||||
set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "")
|
||||
set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "")
|
||||
|
||||
macro(add_extra_compiler_option option)
|
||||
if(CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
ocv_check_flag_support(CXX "${option}" _varname "${OPENCV_EXTRA_CXX_FLAGS} ${ARGN}")
|
||||
if(${_varname})
|
||||
set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS} ${option}")
|
||||
endif()
|
||||
|
||||
ocv_check_flag_support(C "${option}" _varname "${OPENCV_EXTRA_C_FLAGS} ${ARGN}")
|
||||
if(${_varname})
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} ${option}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
if(MINGW)
|
||||
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838
|
||||
# here we are trying to workaround the problem
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG(-mstackrealign HAVE_STACKREALIGN_FLAG)
|
||||
if(HAVE_STACKREALIGN_FLAG)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mstackrealign")
|
||||
else()
|
||||
CHECK_CXX_COMPILER_FLAG(-mpreferred-stack-boundary=2 HAVE_PREFERRED_STACKBOUNDARY_FLAG)
|
||||
if(HAVE_PREFERRED_STACKBOUNDARY_FLAG)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mstackrealign")
|
||||
endif()
|
||||
add_extra_compiler_option(-mstackrealign)
|
||||
if(NOT HAVE_CXX_MSTACKREALIGN)
|
||||
add_extra_compiler_option(-mpreferred-stack-boundary=2)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(OPENCV_CAN_BREAK_BINARY_COMPATIBILITY)
|
||||
add_definitions(-DOPENCV_CAN_BREAK_BINARY_COMPATIBILITY)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
# High level of warnings.
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wall")
|
||||
add_extra_compiler_option(-Wall)
|
||||
add_extra_compiler_option(-Werror=return-type)
|
||||
if(OPENCV_CAN_BREAK_BINARY_COMPATIBILITY)
|
||||
add_extra_compiler_option(-Werror=non-virtual-dtor)
|
||||
endif()
|
||||
add_extra_compiler_option(-Werror=address)
|
||||
add_extra_compiler_option(-Werror=sequence-point)
|
||||
add_extra_compiler_option(-Wformat)
|
||||
add_extra_compiler_option(-Werror=format-security -Wformat)
|
||||
add_extra_compiler_option(-Wmissing-declarations)
|
||||
add_extra_compiler_option(-Wmissing-prototypes)
|
||||
add_extra_compiler_option(-Wstrict-prototypes)
|
||||
add_extra_compiler_option(-Wundef)
|
||||
add_extra_compiler_option(-Winit-self)
|
||||
add_extra_compiler_option(-Wpointer-arith)
|
||||
add_extra_compiler_option(-Wshadow)
|
||||
|
||||
if(ENABLE_NOISY_WARNINGS)
|
||||
add_extra_compiler_option(-Wcast-align)
|
||||
add_extra_compiler_option(-Wstrict-aliasing=2)
|
||||
else()
|
||||
add_extra_compiler_option(-Wno-narrowing)
|
||||
add_extra_compiler_option(-Wno-delete-non-virtual-dtor)
|
||||
add_extra_compiler_option(-Wno-unnamed-type-template-args)
|
||||
endif()
|
||||
|
||||
# The -Wno-long-long is required in 64bit systems when including sytem headers.
|
||||
if(X86_64)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Wno-long-long")
|
||||
add_extra_compiler_option(-Wno-long-long)
|
||||
endif()
|
||||
|
||||
# We need pthread's
|
||||
if(UNIX AND NOT ANDROID)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -pthread")
|
||||
add_extra_compiler_option(-pthread)
|
||||
endif()
|
||||
|
||||
if(OPENCV_WARNINGS_ARE_ERRORS)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -Werror")
|
||||
add_extra_compiler_option(-Werror)
|
||||
endif()
|
||||
|
||||
if(X86 AND NOT MINGW64 AND NOT X86_64 AND NOT APPLE)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -march=i686")
|
||||
add_extra_compiler_option(-march=i686)
|
||||
endif()
|
||||
|
||||
# Other optimizations
|
||||
if(ENABLE_OMIT_FRAME_POINTER)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -fomit-frame-pointer")
|
||||
add_extra_compiler_option(-fomit-frame-pointer)
|
||||
else()
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -fno-omit-frame-pointer")
|
||||
add_extra_compiler_option(-fno-omit-frame-pointer)
|
||||
endif()
|
||||
if(ENABLE_FAST_MATH)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffast-math")
|
||||
add_extra_compiler_option(-ffast-math)
|
||||
endif()
|
||||
if(ENABLE_POWERPC)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mcpu=G3 -mtune=G5")
|
||||
add_extra_compiler_option("-mcpu=G3 -mtune=G5")
|
||||
endif()
|
||||
if(ENABLE_SSE)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -msse")
|
||||
add_extra_compiler_option(-msse)
|
||||
endif()
|
||||
if(ENABLE_SSE2)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -msse2")
|
||||
add_extra_compiler_option(-msse2)
|
||||
endif()
|
||||
|
||||
# SSE3 and further should be disabled under MingW because it generates compiler errors
|
||||
if(NOT MINGW)
|
||||
if(ENABLE_SSE3)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -msse3")
|
||||
add_extra_compiler_option(-msse3)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_OPENCV_GCC_VERSION_NUM} GREATER 402)
|
||||
@ -99,14 +140,14 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
if(HAVE_GCC42_OR_NEWER OR APPLE)
|
||||
if(ENABLE_SSSE3)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mssse3")
|
||||
add_extra_compiler_option(-mssse3)
|
||||
endif()
|
||||
if(HAVE_GCC43_OR_NEWER)
|
||||
if(ENABLE_SSE41)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -msse4.1")
|
||||
add_extra_compiler_option(-msse4.1)
|
||||
endif()
|
||||
if(ENABLE_SSE42)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -msse4.2")
|
||||
add_extra_compiler_option(-msse4.2)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -114,39 +155,40 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
if(X86 OR X86_64)
|
||||
if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
if(ENABLE_SSE2)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mfpmath=sse")# !! important - be on the same wave with x64 compilers
|
||||
else()
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -mfpmath=387")
|
||||
endif()
|
||||
if(ENABLE_SSE2)
|
||||
add_extra_compiler_option(-mfpmath=sse)# !! important - be on the same wave with x64 compilers
|
||||
else()
|
||||
add_extra_compiler_option(-mfpmath=387)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Profiling?
|
||||
if(ENABLE_PROFILING)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -pg -g")
|
||||
add_extra_compiler_option("-pg -g")
|
||||
# turn off incompatible options
|
||||
foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG OPENCV_EXTRA_C_FLAGS_RELEASE)
|
||||
foreach(flags CMAKE_CXX_FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_DEBUG
|
||||
OPENCV_EXTRA_FLAGS_RELEASE OPENCV_EXTRA_FLAGS_DEBUG OPENCV_EXTRA_C_FLAGS OPENCV_EXTRA_CXX_FLAGS)
|
||||
string(REPLACE "-fomit-frame-pointer" "" ${flags} "${${flags}}")
|
||||
string(REPLACE "-ffunction-sections" "" ${flags} "${${flags}}")
|
||||
endforeach()
|
||||
elseif(NOT APPLE AND NOT ANDROID)
|
||||
# Remove unreferenced functions: function level linking
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} -ffunction-sections")
|
||||
add_extra_compiler_option(-ffunction-sections)
|
||||
endif()
|
||||
|
||||
set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} -DNDEBUG")
|
||||
set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG")
|
||||
set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} -DNDEBUG")
|
||||
set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG")
|
||||
if(BUILD_WITH_DEBUG_INFO)
|
||||
set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG} -ggdb3")
|
||||
set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -ggdb3")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS")
|
||||
# 64-bit portability warnings, in MSVC80
|
||||
if(MSVC80)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Wp64")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /Wp64")
|
||||
endif()
|
||||
|
||||
if(BUILD_WITH_DEBUG_INFO)
|
||||
@ -154,38 +196,38 @@ if(MSVC)
|
||||
endif()
|
||||
|
||||
# Remove unreferenced functions: function level linking
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Gy")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /Gy")
|
||||
if(NOT MSVC_VERSION LESS 1400)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /bigobj")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /bigobj")
|
||||
endif()
|
||||
if(BUILD_WITH_DEBUG_INFO)
|
||||
set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE} /Zi")
|
||||
set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} /Zi")
|
||||
endif()
|
||||
|
||||
if(NOT MSVC64)
|
||||
# 64-bit MSVC compiler uses SSE/SSE2 by default
|
||||
if(ENABLE_SSE)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /arch:SSE")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /arch:SSE")
|
||||
endif()
|
||||
if(ENABLE_SSE2)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /arch:SSE2")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /arch:SSE2")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ENABLE_SSE3)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /arch:SSE3")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /arch:SSE3")
|
||||
endif()
|
||||
if(ENABLE_SSE4_1)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /arch:SSE4.1")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /arch:SSE4.1")
|
||||
endif()
|
||||
|
||||
if(ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /Oi")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /Oi")
|
||||
endif()
|
||||
|
||||
if(X86 OR X86_64)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND ENABLE_SSE2)
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS} /fp:fast")# !! important - be on the same wave with x64 compilers
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /fp:fast")# !! important - be on the same wave with x64 compilers
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -194,25 +236,27 @@ endif()
|
||||
if(NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX AND NOT ANDROID)
|
||||
# Android does not need these settings because they are already set by toolchain file
|
||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} stdc++)
|
||||
set(OPENCV_EXTRA_C_FLAGS "-fPIC ${OPENCV_EXTRA_C_FLAGS}")
|
||||
set(OPENCV_EXTRA_FLAGS "-fPIC ${OPENCV_EXTRA_FLAGS}")
|
||||
endif()
|
||||
|
||||
# Add user supplied extra options (optimization, etc...)
|
||||
# ==========================================================
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS}" CACHE INTERNAL "Extra compiler options")
|
||||
set(OPENCV_EXTRA_C_FLAGS_RELEASE "${OPENCV_EXTRA_C_FLAGS_RELEASE}" CACHE INTERNAL "Extra compiler options for Release build")
|
||||
set(OPENCV_EXTRA_C_FLAGS_DEBUG "${OPENCV_EXTRA_C_FLAGS_DEBUG}" CACHE INTERNAL "Extra compiler options for Debug build")
|
||||
set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS}" CACHE INTERNAL "Extra compiler options")
|
||||
set(OPENCV_EXTRA_C_FLAGS "${OPENCV_EXTRA_C_FLAGS}" CACHE INTERNAL "Extra compiler options for C sources")
|
||||
set(OPENCV_EXTRA_CXX_FLAGS "${OPENCV_EXTRA_CXX_FLAGS}" CACHE INTERNAL "Extra compiler options for C++ sources")
|
||||
set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE}" CACHE INTERNAL "Extra compiler options for Release build")
|
||||
set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG}" CACHE INTERNAL "Extra compiler options for Debug build")
|
||||
set(OPENCV_EXTRA_EXE_LINKER_FLAGS "${OPENCV_EXTRA_EXE_LINKER_FLAGS}" CACHE INTERNAL "Extra linker flags")
|
||||
set(OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE "${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}" CACHE INTERNAL "Extra linker flags for Release build")
|
||||
set(OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG "${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}" CACHE INTERNAL "Extra linker flags for Debug build")
|
||||
|
||||
#combine all "extra" options
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPENCV_EXTRA_C_FLAGS_RELEASE}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${OPENCV_EXTRA_C_FLAGS_DEBUG}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCV_EXTRA_FLAGS} ${OPENCV_EXTRA_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OPENCV_EXTRA_FLAGS_RELEASE}")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${OPENCV_EXTRA_FLAGS_RELEASE}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OPENCV_EXTRA_FLAGS_DEBUG}")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${OPENCV_EXTRA_FLAGS_DEBUG}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_EXTRA_EXE_LINKER_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_RELEASE}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${OPENCV_EXTRA_EXE_LINKER_FLAGS_DEBUG}")
|
||||
@ -226,6 +270,10 @@ if(MSVC)
|
||||
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
||||
string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
|
||||
if(NOT ENABLE_NOISY_WARNINGS AND MSVC_VERSION EQUAL 1400)
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4510 /wd4610 /wd4312 /wd4201 /wd4244 /wd4328 /wd4267)
|
||||
endif()
|
||||
|
||||
# allow extern "C" functions throw exceptions
|
||||
foreach(flags CMAKE_C_FLAGS CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_DEBUG)
|
||||
string(REPLACE "/EHsc-" "/EHs" ${flags} "${${flags}}")
|
||||
|
@ -44,6 +44,12 @@ if(MSVC AND CMAKE_C_COMPILER MATCHES "icc")
|
||||
set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR (UNIX AND CV_ICC))
|
||||
set(CV_COMPILER_IS_GNU TRUE)
|
||||
else()
|
||||
set(CV_COMPILER_IS_GNU FALSE)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Detect GNU version:
|
||||
# ----------------------------------------------------------------------------
|
||||
|
@ -1,6 +1,6 @@
|
||||
if(ANDROID)
|
||||
add_subdirectory("${OpenCV_SOURCE_DIR}/3rdparty/tbb")
|
||||
ocv_include_directories(${TBB_INCLUDE_DIRS})
|
||||
include_directories(SYSTEM ${TBB_INCLUDE_DIRS})
|
||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} tbb)
|
||||
add_definitions(-DTBB_USE_GCC_BUILTINS=1 -D__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1 -D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1)
|
||||
set(HAVE_TBB 1)
|
||||
|
@ -61,6 +61,16 @@ if(TIFF_BIGTIFF_VERSION AND NOT TIFF_VERSION_BIG)
|
||||
set(TIFF_VERSION_BIG ${TIFF_BIGTIFF_VERSION})
|
||||
endif()
|
||||
|
||||
if(NOT TIFF_VERSION_STRING AND TIFF_INCLUDE_DIR)
|
||||
list(GET TIFF_INCLUDE_DIR 0 _TIFF_INCLUDE_DIR)
|
||||
if(EXISTS "${_TIFF_INCLUDE_DIR}/tiffvers.h")
|
||||
file(STRINGS "${_TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*")
|
||||
string(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*" "\\1" TIFF_VERSION_STRING "${tiff_version_str}")
|
||||
unset(tiff_version_str)
|
||||
endif()
|
||||
unset(_TIFF_INCLUDE_DIR)
|
||||
endif()
|
||||
|
||||
# --- libjpeg (optional) ---
|
||||
if(WITH_JPEG)
|
||||
if(BUILD_JPEG)
|
||||
|
@ -18,7 +18,7 @@ if(WIN32)
|
||||
# Try to find the XIMEA API path in registry.
|
||||
GET_FILENAME_COMPONENT(XIMEA_PATH "[HKEY_CURRENT_USER\\Software\\XIMEA\\CamSupport\\API;Path]" ABSOLUTE)
|
||||
|
||||
if(XIMEA_PATH)
|
||||
if(EXISTS XIMEA_PATH)
|
||||
set(XIMEA_FOUND 1)
|
||||
|
||||
# set LIB folders
|
||||
|
@ -20,17 +20,17 @@ set(OPENCV_MOD_LIST ${OPENCV_MODULES_PUBLIC})
|
||||
ocv_list_sort(OPENCV_MOD_LIST)
|
||||
foreach(m ${OPENCV_MOD_LIST})
|
||||
string(TOUPPER "${m}" m)
|
||||
set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}#define HAVE_${m} 1\n")
|
||||
set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}#define HAVE_${m}\n")
|
||||
endforeach()
|
||||
|
||||
set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}\n")
|
||||
|
||||
set(OPENCV_MOD_LIST ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO})
|
||||
ocv_list_sort(OPENCV_MOD_LIST)
|
||||
foreach(m ${OPENCV_MOD_LIST})
|
||||
string(TOUPPER "${m}" m)
|
||||
set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}#undef HAVE_${m}\n")
|
||||
endforeach()
|
||||
#set(OPENCV_MOD_LIST ${OPENCV_MODULES_DISABLED_USER} ${OPENCV_MODULES_DISABLED_AUTO} ${OPENCV_MODULES_DISABLED_FORCE})
|
||||
#ocv_list_sort(OPENCV_MOD_LIST)
|
||||
#foreach(m ${OPENCV_MOD_LIST})
|
||||
# string(TOUPPER "${m}" m)
|
||||
# set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE}#undef HAVE_${m}\n")
|
||||
#endforeach()
|
||||
|
||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv_modules.hpp.in" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp")
|
||||
install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_PREFIX}/opencv2 COMPONENT main)
|
||||
|
@ -512,6 +512,8 @@ endmacro()
|
||||
macro(ocv_add_precompiled_headers the_target)
|
||||
if("${the_target}" MATCHES "^opencv_test_.*$")
|
||||
SET(pch_path "test/test_")
|
||||
elseif("${the_target}" MATCHES "opencv_perf_gpu_cpu")
|
||||
SET(pch_path "perf_cpu/perf_cpu_")
|
||||
elseif("${the_target}" MATCHES "^opencv_perf_.*$")
|
||||
SET(pch_path "perf/perf_")
|
||||
else()
|
||||
|
@ -24,10 +24,12 @@ IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
ENDIF()
|
||||
|
||||
SET(_PCH_include_prefix "-I")
|
||||
SET(_PCH_isystem_prefix "-isystem")
|
||||
|
||||
ELSEIF(WIN32)
|
||||
SET(PCHSupport_FOUND TRUE) # for experimental msvc support
|
||||
SET(_PCH_include_prefix "/I")
|
||||
SET(_PCH_isystem_prefix "/I")
|
||||
ELSE()
|
||||
SET(PCHSupport_FOUND FALSE)
|
||||
ENDIF()
|
||||
@ -50,7 +52,11 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
|
||||
|
||||
GET_DIRECTORY_PROPERTY(DIRINC INCLUDE_DIRECTORIES )
|
||||
FOREACH(item ${DIRINC})
|
||||
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
|
||||
if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/")
|
||||
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
|
||||
else()
|
||||
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
|
||||
endif()
|
||||
ENDFOREACH(item)
|
||||
|
||||
GET_DIRECTORY_PROPERTY(_directory_flags DEFINITIONS)
|
||||
@ -72,6 +78,7 @@ MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#include \\\"${_include_file}\\\"" > "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction();" >> "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction()" >> "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo " return 0;" >> "${${_dephelp}}"
|
||||
@ -82,6 +89,7 @@ MACRO(_PCH_WRITE_PCHDEP_CXX _targetName _include_file _dephelp)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "\\#include \\\"${_include_file}\\\"" > "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)\\;" >> "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "int testfunction\\(\\)" >> "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "{" >> "${${_dephelp}}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo " \\return 0\\;" >> "${${_dephelp}}"
|
||||
|
@ -19,7 +19,7 @@ function(ocv_include_directories)
|
||||
if("${__abs_dir}" MATCHES "^${OpenCV_SOURCE_DIR}" OR "${__abs_dir}" MATCHES "^${OpenCV_BINARY_DIR}")
|
||||
list(APPEND __add_before "${dir}")
|
||||
else()
|
||||
include_directories(AFTER "${dir}")
|
||||
include_directories(AFTER SYSTEM "${dir}")
|
||||
endif()
|
||||
endforeach()
|
||||
include_directories(BEFORE ${__add_before})
|
||||
@ -32,6 +32,125 @@ macro(ocv_clear_vars)
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
set(OCV_COMPILER_FAIL_REGEX
|
||||
"command line option .* is valid for .* but not for C\\+\\+" # GNU
|
||||
"unrecognized .*option" # GNU
|
||||
"unknown .*option" # Clang
|
||||
"ignoring unknown option" # MSVC
|
||||
"warning D9002" # MSVC, any lang
|
||||
"option .*not supported" # Intel
|
||||
"[Uu]nknown option" # HP
|
||||
"[Ww]arning: [Oo]ption" # SunPro
|
||||
"command option .* is not recognized" # XL
|
||||
"not supported in this configuration; ignored" # AIX
|
||||
"File with unknown suffix passed to linker" # PGI
|
||||
"WARNING: unknown flag:" # Open64
|
||||
)
|
||||
|
||||
MACRO(ocv_check_compiler_flag LANG FLAG RESULT)
|
||||
if(NOT DEFINED ${RESULT})
|
||||
if("_${LANG}_" MATCHES "_CXX_")
|
||||
set(_fname "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.cxx")
|
||||
if("${CMAKE_CXX_FLAGS} ${FLAG} " MATCHES "-Werror " OR "${CMAKE_CXX_FLAGS} ${FLAG} " MATCHES "-Werror=unknown-pragmas ")
|
||||
FILE(WRITE "${_fname}" "int main() { return 0; }\n")
|
||||
else()
|
||||
FILE(WRITE "${_fname}" "#pragma\nint main() { return 0; }\n")
|
||||
endif()
|
||||
elseif("_${LANG}_" MATCHES "_C_")
|
||||
set(_fname "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src.c")
|
||||
if("${CMAKE_C_FLAGS} ${FLAG} " MATCHES "-Werror " OR "${CMAKE_C_FLAGS} ${FLAG} " MATCHES "-Werror=unknown-pragmas ")
|
||||
FILE(WRITE "${_fname}" "int main(void) { return 0; }\n")
|
||||
else()
|
||||
FILE(WRITE "${_fname}" "#pragma\nint main(void) { return 0; }\n")
|
||||
endif()
|
||||
else()
|
||||
unset(_fname)
|
||||
endif()
|
||||
if(_fname)
|
||||
MESSAGE(STATUS "Performing Test ${RESULT}")
|
||||
TRY_COMPILE(${RESULT}
|
||||
${CMAKE_BINARY_DIR}
|
||||
"${_fname}"
|
||||
COMPILE_DEFINITIONS "${FLAG}"
|
||||
OUTPUT_VARIABLE OUTPUT)
|
||||
|
||||
FOREACH(_regex ${OCV_COMPILER_FAIL_REGEX})
|
||||
IF("${OUTPUT}" MATCHES "${_regex}")
|
||||
SET(${RESULT} 0)
|
||||
break()
|
||||
ENDIF()
|
||||
ENDFOREACH()
|
||||
|
||||
IF(${RESULT})
|
||||
SET(${RESULT} 1 CACHE INTERNAL "Test ${RESULT}")
|
||||
MESSAGE(STATUS "Performing Test ${RESULT} - Success")
|
||||
ELSE(${RESULT})
|
||||
MESSAGE(STATUS "Performing Test ${RESULT} - Failed")
|
||||
SET(${RESULT} "" CACHE INTERNAL "Test ${RESULT}")
|
||||
ENDIF(${RESULT})
|
||||
else()
|
||||
SET(${RESULT} 0)
|
||||
endif()
|
||||
endif()
|
||||
ENDMACRO()
|
||||
|
||||
macro(ocv_check_flag_support lang flag varname)
|
||||
if("_${lang}_" MATCHES "_CXX_")
|
||||
set(_lang CXX)
|
||||
elseif("_${lang}_" MATCHES "_C_")
|
||||
set(_lang C)
|
||||
else()
|
||||
set(_lang ${lang})
|
||||
endif()
|
||||
|
||||
string(TOUPPER "${flag}" ${varname})
|
||||
string(REGEX REPLACE "^(/|-)" "HAVE_${_lang}_" ${varname} "${${varname}}")
|
||||
string(REGEX REPLACE " -|-|=| |\\." "_" ${varname} "${${varname}}")
|
||||
|
||||
ocv_check_compiler_flag("${_lang}" "${ARGN} ${flag}" ${${varname}})
|
||||
endmacro()
|
||||
|
||||
# turns off warnings
|
||||
macro(ocv_warnings_disable)
|
||||
if(NOT ENABLE_NOISY_WARNINGS)
|
||||
set(_flag_vars "")
|
||||
set(_msvc_warnings "")
|
||||
set(_gxx_warnings "")
|
||||
foreach(arg ${ARGN})
|
||||
if(arg MATCHES "^CMAKE_")
|
||||
list(APPEND _flag_vars ${arg})
|
||||
elseif(arg MATCHES "^/wd")
|
||||
list(APPEND _msvc_warnings ${arg})
|
||||
elseif(arg MATCHES "^-W")
|
||||
list(APPEND _gxx_warnings ${arg})
|
||||
endif()
|
||||
endforeach()
|
||||
if(MSVC AND _msvc_warnings AND _flag_vars)
|
||||
foreach(var ${_flag_vars})
|
||||
foreach(warning ${_msvc_warnings})
|
||||
set(${var} "${${var}} ${warning}")
|
||||
endforeach()
|
||||
endforeach()
|
||||
elseif(CV_COMPILER_IS_GNU AND _gxx_warnings AND _flag_vars)
|
||||
foreach(var ${_flag_vars})
|
||||
foreach(warning ${_gxx_warnings})
|
||||
if(NOT warning MATCHES "^-Wno-")
|
||||
string(REPLACE "${warning}" "" ${var} "${${var}}")
|
||||
string(REPLACE "-W" "-Wno-" warning "${warning}")
|
||||
endif()
|
||||
ocv_check_flag_support(${var} "${warning}" _varname)
|
||||
if(${_varname})
|
||||
set(${var} "${${var}} ${warning}")
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif()
|
||||
unset(_flag_vars)
|
||||
unset(_msvc_warnings)
|
||||
unset(_gxx_warnings)
|
||||
endif(NOT ENABLE_NOISY_WARNINGS)
|
||||
endmacro()
|
||||
|
||||
# Provides an option that the user can optionally select.
|
||||
# Can accept condition to control when option is available for user.
|
||||
# Usage:
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
||||
#endif
|
||||
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__
|
||||
#define __OPENCV_PERF_PRECOMP_HPP__
|
||||
|
||||
@ -6,7 +10,7 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
@ -255,7 +255,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
|
||||
IplImage _img;
|
||||
int check_chessboard_result;
|
||||
int quad_count = 0, group_idx = 0, i = 0, dilations = 0;
|
||||
int quad_count = 0, group_idx = 0, dilations = 0;
|
||||
|
||||
img = cvGetMat( img, &stub );
|
||||
//debug_img = img;
|
||||
@ -316,7 +316,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
for( dilations = min_dilations; dilations <= max_dilations; dilations++ )
|
||||
{
|
||||
if (found)
|
||||
break; // already found it
|
||||
break; // already found it
|
||||
|
||||
cvFree(&quads);
|
||||
cvFree(&corners);
|
||||
@ -378,7 +378,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
cvCopy(dbg_img, dbg1_img);
|
||||
cvNamedWindow("all_quads", 1);
|
||||
// copy corners to temp array
|
||||
for( i = 0; i < quad_count; i++ )
|
||||
for(int i = 0; i < quad_count; i++ )
|
||||
{
|
||||
for (int k=0; k<4; k++)
|
||||
{
|
||||
@ -432,7 +432,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
cvCopy(dbg_img,dbg2_img);
|
||||
cvNamedWindow("connected_group", 1);
|
||||
// copy corners to temp array
|
||||
for( i = 0; i < quad_count; i++ )
|
||||
for(int i = 0; i < quad_count; i++ )
|
||||
{
|
||||
if (quads[i].group_idx == group_idx)
|
||||
for (int k=0; k<4; k++)
|
||||
@ -455,7 +455,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
#endif
|
||||
|
||||
if (count == 0)
|
||||
continue; // haven't found inner quads
|
||||
continue; // haven't found inner quads
|
||||
|
||||
|
||||
// If count is more than it should be, this will remove those quads
|
||||
@ -472,7 +472,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
float sum_dist = 0;
|
||||
int total = 0;
|
||||
|
||||
for( i = 0; i < n; i++ )
|
||||
for(int i = 0; i < n; i++ )
|
||||
{
|
||||
int ni = 0;
|
||||
float avgi = corner_group[i]->meanDist(&ni);
|
||||
@ -484,7 +484,7 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
if( count > 0 || (out_corner_count && -count > *out_corner_count) )
|
||||
{
|
||||
// copy corners to output array
|
||||
for( i = 0; i < n; i++ )
|
||||
for(int i = 0; i < n; i++ )
|
||||
out_corners[i] = corner_group[i]->pt;
|
||||
|
||||
if( out_corner_count )
|
||||
@ -505,19 +505,19 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
if( found )
|
||||
found = icvCheckBoardMonotony( out_corners, pattern_size );
|
||||
|
||||
// check that none of the found corners is too close to the image boundary
|
||||
// check that none of the found corners is too close to the image boundary
|
||||
if( found )
|
||||
{
|
||||
const int BORDER = 8;
|
||||
for( k = 0; k < pattern_size.width*pattern_size.height; k++ )
|
||||
{
|
||||
if( out_corners[k].x <= BORDER || out_corners[k].x > img->cols - BORDER ||
|
||||
out_corners[k].y <= BORDER || out_corners[k].y > img->rows - BORDER )
|
||||
break;
|
||||
}
|
||||
{
|
||||
const int BORDER = 8;
|
||||
for( k = 0; k < pattern_size.width*pattern_size.height; k++ )
|
||||
{
|
||||
if( out_corners[k].x <= BORDER || out_corners[k].x > img->cols - BORDER ||
|
||||
out_corners[k].y <= BORDER || out_corners[k].y > img->rows - BORDER )
|
||||
break;
|
||||
}
|
||||
|
||||
found = k == pattern_size.width*pattern_size.height;
|
||||
}
|
||||
found = k == pattern_size.width*pattern_size.height;
|
||||
}
|
||||
|
||||
if( found && pattern_size.height % 2 == 0 && pattern_size.width % 2 == 0 )
|
||||
{
|
||||
@ -525,8 +525,8 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||
double dy0 = out_corners[last_row].y - out_corners[0].y;
|
||||
if( dy0 < 0 )
|
||||
{
|
||||
int i, n = pattern_size.width*pattern_size.height;
|
||||
for( i = 0; i < n/2; i++ )
|
||||
int n = pattern_size.width*pattern_size.height;
|
||||
for(int i = 0; i < n/2; i++ )
|
||||
{
|
||||
CvPoint2D32f temp;
|
||||
CV_SWAP(out_corners[i], out_corners[n-i-1], temp);
|
||||
@ -627,11 +627,10 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
{
|
||||
cv::Ptr<CvMemStorage> temp_storage = cvCreateChildMemStorage( storage );
|
||||
CvSeq* stack = cvCreateSeq( 0, sizeof(*stack), sizeof(void*), temp_storage );
|
||||
int i;
|
||||
|
||||
// first find an interior quad
|
||||
CvCBQuad *start = NULL;
|
||||
for (i=0; i<quad_count; i++)
|
||||
for (int i=0; i<quad_count; i++)
|
||||
{
|
||||
if (quads[i]->count == 4)
|
||||
{
|
||||
@ -682,7 +681,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
case 1:
|
||||
col += 2; break;
|
||||
case 2:
|
||||
row += 2; break;
|
||||
row += 2; break;
|
||||
case 3:
|
||||
col -= 2; break;
|
||||
}
|
||||
@ -700,7 +699,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
}
|
||||
}
|
||||
|
||||
for (i=col_min; i<=col_max; i++)
|
||||
for (int i=col_min; i<=col_max; i++)
|
||||
PRINTF("HIST[%d] = %d\n", i, col_hist[i]);
|
||||
|
||||
// analyze inner quad structure
|
||||
@ -763,7 +762,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
// if there is an outer quad missing, fill it in
|
||||
// first order all inner quads
|
||||
int found = 0;
|
||||
for (i=0; i<quad_count; i++)
|
||||
for (int i=0; i<quad_count; i++)
|
||||
{
|
||||
if (quads[i]->count == 4)
|
||||
{ // ok, look at neighbors
|
||||
@ -778,7 +777,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
case 1:
|
||||
col += 2; break;
|
||||
case 2:
|
||||
row += 2; break;
|
||||
row += 2; break;
|
||||
case 3:
|
||||
col -= 2; break;
|
||||
}
|
||||
@ -817,7 +816,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
|
||||
|
||||
// final trimming of outer quads
|
||||
if (dcol == w && drow == h) // found correct inner quads
|
||||
if (dcol == w && drow == h) // found correct inner quads
|
||||
{
|
||||
PRINTF("Inner bounds ok, check outer quads\n");
|
||||
int rcount = quad_count;
|
||||
@ -832,7 +831,7 @@ icvOrderFoundConnectedQuads( int quad_count, CvCBQuad **quads,
|
||||
if (quads[i]->neighbors[j] && quads[i]->neighbors[j]->ordered)
|
||||
outer = true;
|
||||
}
|
||||
if (!outer) // not an outer quad, eliminate
|
||||
if (!outer) // not an outer quad, eliminate
|
||||
{
|
||||
PRINTF("Removing quad %d\n", i);
|
||||
icvRemoveQuadFromGroup(quads,rcount,quads[i]);
|
||||
@ -876,7 +875,7 @@ icvAddOuterQuad( CvCBQuad *quad, CvCBQuad **quads, int quad_count,
|
||||
quad->count += 1;
|
||||
q->neighbors[j] = quad;
|
||||
q->group_idx = quad->group_idx;
|
||||
q->count = 1; // number of neighbors
|
||||
q->count = 1; // number of neighbors
|
||||
q->ordered = false;
|
||||
q->edge_len = quad->edge_len;
|
||||
|
||||
@ -2006,17 +2005,17 @@ bool cv::findCirclesGrid( InputArray _image, Size patternSize,
|
||||
#endif
|
||||
if (isFound)
|
||||
{
|
||||
switch(parameters.gridType)
|
||||
{
|
||||
switch(parameters.gridType)
|
||||
{
|
||||
case CirclesGridFinderParameters::SYMMETRIC_GRID:
|
||||
boxFinder.getHoles(centers);
|
||||
break;
|
||||
case CirclesGridFinderParameters::ASYMMETRIC_GRID:
|
||||
boxFinder.getAsymmetricHoles(centers);
|
||||
break;
|
||||
boxFinder.getAsymmetricHoles(centers);
|
||||
break;
|
||||
default:
|
||||
CV_Error(CV_StsBadArg, "Unkown pattern type");
|
||||
}
|
||||
}
|
||||
|
||||
if (i != 0)
|
||||
{
|
||||
|
@ -1153,7 +1153,7 @@ CV_IMPL void cvFindExtrinsicCameraParams2( const CvMat* objectPoints,
|
||||
int useExtrinsicGuess )
|
||||
{
|
||||
const int max_iter = 20;
|
||||
Ptr<CvMat> matM, _Mxy, _m, _mn, matL, matJ;
|
||||
Ptr<CvMat> matM, _Mxy, _m, _mn, matL;
|
||||
|
||||
int i, count;
|
||||
double a[9], ar[9]={1,0,0,0,1,0,0,0,1}, R[9];
|
||||
|
@ -55,7 +55,7 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector<std::pair<float, int> >& quads, int class_id)
|
||||
static void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector<std::pair<float, int> >& quads, int class_id)
|
||||
{
|
||||
const float min_aspect_ratio = 0.3f;
|
||||
const float max_aspect_ratio = 3.0f;
|
||||
@ -80,7 +80,7 @@ void icvGetQuadrangleHypotheses(CvSeq* contours, std::vector<std::pair<float, in
|
||||
}
|
||||
}
|
||||
|
||||
void countClasses(const std::vector<std::pair<float, int> >& pairs, size_t idx1, size_t idx2, std::vector<int>& counts)
|
||||
static void countClasses(const std::vector<std::pair<float, int> >& pairs, size_t idx1, size_t idx2, std::vector<int>& counts)
|
||||
{
|
||||
counts.assign(2, 0);
|
||||
for(size_t i = idx1; i != idx2; i++)
|
||||
@ -89,7 +89,7 @@ void countClasses(const std::vector<std::pair<float, int> >& pairs, size_t idx1,
|
||||
}
|
||||
}
|
||||
|
||||
bool less_pred(const std::pair<float, int>& p1, const std::pair<float, int>& p2)
|
||||
inline bool less_pred(const std::pair<float, int>& p1, const std::pair<float, int>& p2)
|
||||
{
|
||||
return p1.first < p2.first;
|
||||
}
|
||||
|
@ -65,14 +65,14 @@ void drawPoints(const vector<Point2f> &points, Mat &outImage, int radius = 2, S
|
||||
}
|
||||
#endif
|
||||
|
||||
void CirclesGridClusterFinder::hierarchicalClustering(const vector<Point2f> points, const Size &patternSize, vector<Point2f> &patternPoints)
|
||||
void CirclesGridClusterFinder::hierarchicalClustering(const vector<Point2f> points, const Size &patternSz, vector<Point2f> &patternPoints)
|
||||
{
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
if(tegra::hierarchicalClustering(points, patternSize, patternPoints))
|
||||
if(tegra::hierarchicalClustering(points, patternSz, patternPoints))
|
||||
return;
|
||||
#endif
|
||||
int i, j, n = (int)points.size();
|
||||
size_t pn = static_cast<size_t>(patternSize.area());
|
||||
int j, n = (int)points.size();
|
||||
size_t pn = static_cast<size_t>(patternSz.area());
|
||||
|
||||
patternPoints.clear();
|
||||
if (pn >= points.size())
|
||||
@ -84,7 +84,7 @@ void CirclesGridClusterFinder::hierarchicalClustering(const vector<Point2f> poin
|
||||
|
||||
Mat dists(n, n, CV_32FC1, Scalar(0));
|
||||
Mat distsMask(dists.size(), CV_8UC1, Scalar(0));
|
||||
for(i = 0; i < n; i++)
|
||||
for(int i = 0; i < n; i++)
|
||||
{
|
||||
for(j = i+1; j < n; j++)
|
||||
{
|
||||
@ -122,7 +122,7 @@ void CirclesGridClusterFinder::hierarchicalClustering(const vector<Point2f> poin
|
||||
}
|
||||
|
||||
//the largest cluster can have more than pn points -- we need to filter out such situations
|
||||
if(clusters[patternClusterIdx].size() != static_cast<size_t>(patternSize.area()))
|
||||
if(clusters[patternClusterIdx].size() != static_cast<size_t>(patternSz.area()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -505,11 +505,11 @@ void Graph::floydWarshall(cv::Mat &distanceMatrix, int infinity) const
|
||||
{
|
||||
for (Vertices::const_iterator it3 = vertices.begin(); it3 != vertices.end(); it3++)
|
||||
{
|
||||
int i1 = (int)it1->first, i2 = (int)it2->first, i3 = (int)it3->first;
|
||||
int i1 = (int)it1->first, i2 = (int)it2->first, i3 = (int)it3->first;
|
||||
int val1 = distanceMatrix.at<int> (i2, i3);
|
||||
int val2;
|
||||
if (distanceMatrix.at<int> (i2, i1) == infinity ||
|
||||
distanceMatrix.at<int> (i1, i3) == infinity)
|
||||
distanceMatrix.at<int> (i1, i3) == infinity)
|
||||
val2 = val1;
|
||||
else
|
||||
{
|
||||
@ -1223,7 +1223,7 @@ void computePredecessorMatrix(const Mat &dm, int verticesCount, Mat &predecessor
|
||||
}
|
||||
}
|
||||
|
||||
void computeShortestPath(Mat &predecessorMatrix, size_t v1, size_t v2, vector<size_t> &path)
|
||||
static void computeShortestPath(Mat &predecessorMatrix, size_t v1, size_t v2, vector<size_t> &path)
|
||||
{
|
||||
if (predecessorMatrix.at<int> ((int)v1, (int)v2) < 0)
|
||||
{
|
||||
@ -1403,7 +1403,7 @@ void CirclesGridFinder::getHoles(vector<Point2f> &outHoles) const
|
||||
}
|
||||
}
|
||||
|
||||
bool areIndicesCorrect(Point pos, vector<vector<size_t> > *points)
|
||||
static bool areIndicesCorrect(Point pos, vector<vector<size_t> > *points)
|
||||
{
|
||||
if (pos.y < 0 || pos.x < 0)
|
||||
return false;
|
||||
|
@ -8,7 +8,7 @@ epnp::epnp(const cv::Mat& cameraMatrix, const cv::Mat& opoints, const cv::Mat& i
|
||||
if (cameraMatrix.depth() == CV_32F)
|
||||
init_camera_parameters<float>(cameraMatrix);
|
||||
else
|
||||
init_camera_parameters<double>(cameraMatrix);
|
||||
init_camera_parameters<double>(cameraMatrix);
|
||||
|
||||
number_of_correspondences = std::max(opoints.checkVector(3, CV_32F), opoints.checkVector(3, CV_64F));
|
||||
|
||||
@ -17,15 +17,15 @@ epnp::epnp(const cv::Mat& cameraMatrix, const cv::Mat& opoints, const cv::Mat& i
|
||||
|
||||
if (opoints.depth() == ipoints.depth())
|
||||
{
|
||||
if (opoints.depth() == CV_32F)
|
||||
init_points<cv::Point3f,cv::Point2f>(opoints, ipoints);
|
||||
else
|
||||
init_points<cv::Point3d,cv::Point2d>(opoints, ipoints);
|
||||
if (opoints.depth() == CV_32F)
|
||||
init_points<cv::Point3f,cv::Point2f>(opoints, ipoints);
|
||||
else
|
||||
init_points<cv::Point3d,cv::Point2d>(opoints, ipoints);
|
||||
}
|
||||
else if (opoints.depth() == CV_32F)
|
||||
init_points<cv::Point3f,cv::Point2d>(opoints, ipoints);
|
||||
init_points<cv::Point3f,cv::Point2d>(opoints, ipoints);
|
||||
else
|
||||
init_points<cv::Point3d,cv::Point2f>(opoints, ipoints);
|
||||
init_points<cv::Point3d,cv::Point2f>(opoints, ipoints);
|
||||
|
||||
alphas.resize(4 * number_of_correspondences);
|
||||
pcs.resize(3 * number_of_correspondences);
|
||||
@ -97,15 +97,15 @@ void epnp::compute_barycentric_coordinates(void)
|
||||
|
||||
for(int j = 0; j < 3; j++)
|
||||
a[1 + j] =
|
||||
ci[3 * j ] * (pi[0] - cws[0][0]) +
|
||||
ci[3 * j + 1] * (pi[1] - cws[0][1]) +
|
||||
ci[3 * j + 2] * (pi[2] - cws[0][2]);
|
||||
ci[3 * j ] * (pi[0] - cws[0][0]) +
|
||||
ci[3 * j + 1] * (pi[1] - cws[0][1]) +
|
||||
ci[3 * j + 2] * (pi[2] - cws[0][2]);
|
||||
a[0] = 1.0f - a[1] - a[2] - a[3];
|
||||
}
|
||||
}
|
||||
|
||||
void epnp::fill_M(CvMat * M,
|
||||
const int row, const double * as, const double u, const double v)
|
||||
const int row, const double * as, const double u, const double v)
|
||||
{
|
||||
double * M1 = M->data.db + row * 12;
|
||||
double * M2 = M1 + 12;
|
||||
@ -130,7 +130,7 @@ void epnp::compute_ccs(const double * betas, const double * ut)
|
||||
const double * v = ut + 12 * (11 - i);
|
||||
for(int j = 0; j < 4; j++)
|
||||
for(int k = 0; k < 3; k++)
|
||||
ccs[j][k] += betas[i] * v[3 * j + k];
|
||||
ccs[j][k] += betas[i] * v[3 * j + k];
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ void epnp::compute_pose(cv::Mat& R, cv::Mat& t)
|
||||
}
|
||||
|
||||
void epnp::copy_R_and_t(const double R_src[3][3], const double t_src[3],
|
||||
double R_dst[3][3], double t_dst[3])
|
||||
double R_dst[3][3], double t_dst[3])
|
||||
{
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++)
|
||||
@ -282,7 +282,7 @@ void epnp::solve_for_sign(void)
|
||||
if (pcs[2] < 0.0) {
|
||||
for(int i = 0; i < 4; i++)
|
||||
for(int j = 0; j < 3; j++)
|
||||
ccs[i][j] = -ccs[i][j];
|
||||
ccs[i][j] = -ccs[i][j];
|
||||
|
||||
for(int i = 0; i < number_of_correspondences; i++) {
|
||||
pcs[3 * i ] = -pcs[3 * i];
|
||||
@ -293,7 +293,7 @@ void epnp::solve_for_sign(void)
|
||||
}
|
||||
|
||||
double epnp::compute_R_and_t(const double * ut, const double * betas,
|
||||
double R[3][3], double t[3])
|
||||
double R[3][3], double t[3])
|
||||
{
|
||||
compute_ccs(betas, ut);
|
||||
compute_pcs();
|
||||
@ -328,7 +328,7 @@ double epnp::reprojection_error(const double R[3][3], const double t[3])
|
||||
// betas_approx_1 = [B11 B12 B13 B14]
|
||||
|
||||
void epnp::find_betas_approx_1(const CvMat * L_6x10, const CvMat * Rho,
|
||||
double * betas)
|
||||
double * betas)
|
||||
{
|
||||
double l_6x4[6 * 4], b4[4];
|
||||
CvMat L_6x4 = cvMat(6, 4, CV_64F, l_6x4);
|
||||
@ -360,7 +360,7 @@ void epnp::find_betas_approx_1(const CvMat * L_6x10, const CvMat * Rho,
|
||||
// betas_approx_2 = [B11 B12 B22 ]
|
||||
|
||||
void epnp::find_betas_approx_2(const CvMat * L_6x10, const CvMat * Rho,
|
||||
double * betas)
|
||||
double * betas)
|
||||
{
|
||||
double l_6x3[6 * 3], b3[3];
|
||||
CvMat L_6x3 = cvMat(6, 3, CV_64F, l_6x3);
|
||||
@ -392,7 +392,7 @@ void epnp::find_betas_approx_2(const CvMat * L_6x10, const CvMat * Rho,
|
||||
// betas_approx_3 = [B11 B12 B22 B13 B23 ]
|
||||
|
||||
void epnp::find_betas_approx_3(const CvMat * L_6x10, const CvMat * Rho,
|
||||
double * betas)
|
||||
double * betas)
|
||||
{
|
||||
double l_6x5[6 * 5], b5[5];
|
||||
CvMat L_6x5 = cvMat(6, 5, CV_64F, l_6x5);
|
||||
@ -440,8 +440,8 @@ void epnp::compute_L_6x10(const double * ut, double * l_6x10)
|
||||
|
||||
b++;
|
||||
if (b > 3) {
|
||||
a++;
|
||||
b = a + 1;
|
||||
a++;
|
||||
b = a + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -473,7 +473,7 @@ void epnp::compute_rho(double * rho)
|
||||
}
|
||||
|
||||
void epnp::compute_A_and_b_gauss_newton(const double * l_6x10, const double * rho,
|
||||
const double betas[4], CvMat * A, CvMat * b)
|
||||
const double betas[4], CvMat * A, CvMat * b)
|
||||
{
|
||||
for(int i = 0; i < 6; i++) {
|
||||
const double * rowL = l_6x10 + i * 10;
|
||||
@ -485,23 +485,22 @@ void epnp::compute_A_and_b_gauss_newton(const double * l_6x10, const double * rh
|
||||
rowA[3] = rowL[6] * betas[0] + rowL[7] * betas[1] + rowL[8] * betas[2] + 2 * rowL[9] * betas[3];
|
||||
|
||||
cvmSet(b, i, 0, rho[i] -
|
||||
(
|
||||
rowL[0] * betas[0] * betas[0] +
|
||||
rowL[1] * betas[0] * betas[1] +
|
||||
rowL[2] * betas[1] * betas[1] +
|
||||
rowL[3] * betas[0] * betas[2] +
|
||||
rowL[4] * betas[1] * betas[2] +
|
||||
rowL[5] * betas[2] * betas[2] +
|
||||
rowL[6] * betas[0] * betas[3] +
|
||||
rowL[7] * betas[1] * betas[3] +
|
||||
rowL[8] * betas[2] * betas[3] +
|
||||
rowL[9] * betas[3] * betas[3]
|
||||
));
|
||||
(
|
||||
rowL[0] * betas[0] * betas[0] +
|
||||
rowL[1] * betas[0] * betas[1] +
|
||||
rowL[2] * betas[1] * betas[1] +
|
||||
rowL[3] * betas[0] * betas[2] +
|
||||
rowL[4] * betas[1] * betas[2] +
|
||||
rowL[5] * betas[2] * betas[2] +
|
||||
rowL[6] * betas[0] * betas[3] +
|
||||
rowL[7] * betas[1] * betas[3] +
|
||||
rowL[8] * betas[2] * betas[3] +
|
||||
rowL[9] * betas[3] * betas[3]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void epnp::gauss_newton(const CvMat * L_6x10, const CvMat * Rho,
|
||||
double betas[4])
|
||||
void epnp::gauss_newton(const CvMat * L_6x10, const CvMat * Rho, double betas[4])
|
||||
{
|
||||
const int iterations_number = 5;
|
||||
|
||||
@ -510,12 +509,13 @@ void epnp::gauss_newton(const CvMat * L_6x10, const CvMat * Rho,
|
||||
CvMat B = cvMat(6, 1, CV_64F, b);
|
||||
CvMat X = cvMat(4, 1, CV_64F, x);
|
||||
|
||||
for(int k = 0; k < iterations_number; k++) {
|
||||
for(int k = 0; k < iterations_number; k++)
|
||||
{
|
||||
compute_A_and_b_gauss_newton(L_6x10->data.db, Rho->data.db,
|
||||
betas, &A, &B);
|
||||
betas, &A, &B);
|
||||
qr_solve(&A, &B, &X);
|
||||
for(int i = 0; i < 4; i++)
|
||||
betas[i] += x[i];
|
||||
betas[i] += x[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -524,53 +524,64 @@ void epnp::qr_solve(CvMat * A, CvMat * b, CvMat * X)
|
||||
const int nr = A->rows;
|
||||
const int nc = A->cols;
|
||||
|
||||
if (max_nr != 0 && max_nr < nr) {
|
||||
if (max_nr != 0 && max_nr < nr)
|
||||
{
|
||||
delete [] A1;
|
||||
delete [] A2;
|
||||
}
|
||||
if (max_nr < nr) {
|
||||
if (max_nr < nr)
|
||||
{
|
||||
max_nr = nr;
|
||||
A1 = new double[nr];
|
||||
A2 = new double[nr];
|
||||
}
|
||||
|
||||
double * pA = A->data.db, * ppAkk = pA;
|
||||
for(int k = 0; k < nc; k++) {
|
||||
double * ppAik = ppAkk, eta = fabs(*ppAik);
|
||||
for(int i = k + 1; i < nr; i++) {
|
||||
double elt = fabs(*ppAik);
|
||||
for(int k = 0; k < nc; k++)
|
||||
{
|
||||
double * ppAik1 = ppAkk, eta = fabs(*ppAik1);
|
||||
for(int i = k + 1; i < nr; i++)
|
||||
{
|
||||
double elt = fabs(*ppAik1);
|
||||
if (eta < elt) eta = elt;
|
||||
ppAik += nc;
|
||||
ppAik1 += nc;
|
||||
}
|
||||
if (eta == 0) {
|
||||
if (eta == 0)
|
||||
{
|
||||
A1[k] = A2[k] = 0.0;
|
||||
//cerr << "God damnit, A is singular, this shouldn't happen." << endl;
|
||||
return;
|
||||
} else {
|
||||
double * ppAik = ppAkk, sum = 0.0, inv_eta = 1. / eta;
|
||||
for(int i = k; i < nr; i++) {
|
||||
*ppAik *= inv_eta;
|
||||
sum += *ppAik * *ppAik;
|
||||
ppAik += nc;
|
||||
}
|
||||
else
|
||||
{
|
||||
double * ppAik2 = ppAkk, sum2 = 0.0, inv_eta = 1. / eta;
|
||||
for(int i = k; i < nr; i++)
|
||||
{
|
||||
*ppAik2 *= inv_eta;
|
||||
sum2 += *ppAik2 * *ppAik2;
|
||||
ppAik2 += nc;
|
||||
}
|
||||
double sigma = sqrt(sum);
|
||||
double sigma = sqrt(sum2);
|
||||
if (*ppAkk < 0)
|
||||
sigma = -sigma;
|
||||
sigma = -sigma;
|
||||
*ppAkk += sigma;
|
||||
A1[k] = sigma * *ppAkk;
|
||||
A2[k] = -eta * sigma;
|
||||
for(int j = k + 1; j < nc; j++) {
|
||||
double * ppAik = ppAkk, sum = 0;
|
||||
for(int i = k; i < nr; i++) {
|
||||
sum += *ppAik * ppAik[j - k];
|
||||
ppAik += nc;
|
||||
}
|
||||
double tau = sum / A1[k];
|
||||
ppAik = ppAkk;
|
||||
for(int i = k; i < nr; i++) {
|
||||
ppAik[j - k] -= tau * *ppAik;
|
||||
ppAik += nc;
|
||||
}
|
||||
for(int j = k + 1; j < nc; j++)
|
||||
{
|
||||
double * ppAik = ppAkk, sum = 0;
|
||||
for(int i = k; i < nr; i++)
|
||||
{
|
||||
sum += *ppAik * ppAik[j - k];
|
||||
ppAik += nc;
|
||||
}
|
||||
double tau = sum / A1[k];
|
||||
ppAik = ppAkk;
|
||||
for(int i = k; i < nr; i++)
|
||||
{
|
||||
ppAik[j - k] -= tau * *ppAik;
|
||||
ppAik += nc;
|
||||
}
|
||||
}
|
||||
}
|
||||
ppAkk += nc + 1;
|
||||
@ -578,15 +589,18 @@ void epnp::qr_solve(CvMat * A, CvMat * b, CvMat * X)
|
||||
|
||||
// b <- Qt b
|
||||
double * ppAjj = pA, * pb = b->data.db;
|
||||
for(int j = 0; j < nc; j++) {
|
||||
for(int j = 0; j < nc; j++)
|
||||
{
|
||||
double * ppAij = ppAjj, tau = 0;
|
||||
for(int i = j; i < nr; i++) {
|
||||
for(int i = j; i < nr; i++)
|
||||
{
|
||||
tau += *ppAij * pb[i];
|
||||
ppAij += nc;
|
||||
}
|
||||
tau /= A1[j];
|
||||
ppAij = ppAjj;
|
||||
for(int i = j; i < nr; i++) {
|
||||
for(int i = j; i < nr; i++)
|
||||
{
|
||||
pb[i] -= tau * *ppAij;
|
||||
ppAij += nc;
|
||||
}
|
||||
@ -596,10 +610,12 @@ void epnp::qr_solve(CvMat * A, CvMat * b, CvMat * X)
|
||||
// X = R-1 b
|
||||
double * pX = X->data.db;
|
||||
pX[nc - 1] = pb[nc - 1] / A2[nc - 1];
|
||||
for(int i = nc - 2; i >= 0; i--) {
|
||||
for(int i = nc - 2; i >= 0; i--)
|
||||
{
|
||||
double * ppAij = pA + i * nc + (i + 1), sum = 0;
|
||||
|
||||
for(int j = i + 1; j < nc; j++) {
|
||||
for(int j = i + 1; j < nc; j++)
|
||||
{
|
||||
sum += *ppAij * pX[j];
|
||||
ppAij++;
|
||||
}
|
||||
|
@ -9,151 +9,151 @@ using namespace std;
|
||||
|
||||
void p3p::init_inverse_parameters()
|
||||
{
|
||||
inv_fx = 1. / fx;
|
||||
inv_fy = 1. / fy;
|
||||
cx_fx = cx / fx;
|
||||
cy_fy = cy / fy;
|
||||
inv_fx = 1. / fx;
|
||||
inv_fy = 1. / fy;
|
||||
cx_fx = cx / fx;
|
||||
cy_fy = cy / fy;
|
||||
}
|
||||
|
||||
p3p::p3p(cv::Mat cameraMatrix)
|
||||
{
|
||||
if (cameraMatrix.depth() == CV_32F)
|
||||
init_camera_parameters<float>(cameraMatrix);
|
||||
else
|
||||
init_camera_parameters<double>(cameraMatrix);
|
||||
init_inverse_parameters();
|
||||
if (cameraMatrix.depth() == CV_32F)
|
||||
init_camera_parameters<float>(cameraMatrix);
|
||||
else
|
||||
init_camera_parameters<double>(cameraMatrix);
|
||||
init_inverse_parameters();
|
||||
}
|
||||
|
||||
p3p::p3p(double _fx, double _fy, double _cx, double _cy)
|
||||
{
|
||||
fx = _fx;
|
||||
fy = _fy;
|
||||
cx = _cx;
|
||||
cy = _cy;
|
||||
init_inverse_parameters();
|
||||
fx = _fx;
|
||||
fy = _fy;
|
||||
cx = _cx;
|
||||
cy = _cy;
|
||||
init_inverse_parameters();
|
||||
}
|
||||
|
||||
bool p3p::solve(cv::Mat& R, cv::Mat& tvec, const cv::Mat& opoints, const cv::Mat& ipoints)
|
||||
{
|
||||
double rotation_matrix[3][3], translation[3];
|
||||
std::vector<double> points;
|
||||
if (opoints.depth() == ipoints.depth())
|
||||
{
|
||||
if (opoints.depth() == CV_32F)
|
||||
extract_points<cv::Point3f,cv::Point2f>(opoints, ipoints, points);
|
||||
else
|
||||
extract_points<cv::Point3d,cv::Point2d>(opoints, ipoints, points);
|
||||
}
|
||||
else if (opoints.depth() == CV_32F)
|
||||
extract_points<cv::Point3f,cv::Point2d>(opoints, ipoints, points);
|
||||
else
|
||||
extract_points<cv::Point3d,cv::Point2f>(opoints, ipoints, points);
|
||||
double rotation_matrix[3][3], translation[3];
|
||||
std::vector<double> points;
|
||||
if (opoints.depth() == ipoints.depth())
|
||||
{
|
||||
if (opoints.depth() == CV_32F)
|
||||
extract_points<cv::Point3f,cv::Point2f>(opoints, ipoints, points);
|
||||
else
|
||||
extract_points<cv::Point3d,cv::Point2d>(opoints, ipoints, points);
|
||||
}
|
||||
else if (opoints.depth() == CV_32F)
|
||||
extract_points<cv::Point3f,cv::Point2d>(opoints, ipoints, points);
|
||||
else
|
||||
extract_points<cv::Point3d,cv::Point2f>(opoints, ipoints, points);
|
||||
|
||||
bool result = solve(rotation_matrix, translation, points[0], points[1], points[2], points[3], points[4], points[5],
|
||||
points[6], points[7], points[8], points[9], points[10], points[11], points[12], points[13], points[14],
|
||||
points[15], points[16], points[17], points[18], points[19]);
|
||||
cv::Mat(3, 1, CV_64F, translation).copyTo(tvec);
|
||||
bool result = solve(rotation_matrix, translation, points[0], points[1], points[2], points[3], points[4], points[5],
|
||||
points[6], points[7], points[8], points[9], points[10], points[11], points[12], points[13], points[14],
|
||||
points[15], points[16], points[17], points[18], points[19]);
|
||||
cv::Mat(3, 1, CV_64F, translation).copyTo(tvec);
|
||||
cv::Mat(3, 3, CV_64F, rotation_matrix).copyTo(R);
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool p3p::solve(double R[3][3], double t[3],
|
||||
double mu0, double mv0, double X0, double Y0, double Z0,
|
||||
double mu1, double mv1, double X1, double Y1, double Z1,
|
||||
double mu2, double mv2, double X2, double Y2, double Z2,
|
||||
double mu3, double mv3, double X3, double Y3, double Z3)
|
||||
double mu0, double mv0, double X0, double Y0, double Z0,
|
||||
double mu1, double mv1, double X1, double Y1, double Z1,
|
||||
double mu2, double mv2, double X2, double Y2, double Z2,
|
||||
double mu3, double mv3, double X3, double Y3, double Z3)
|
||||
{
|
||||
double Rs[4][3][3], ts[4][3];
|
||||
double Rs[4][3][3], ts[4][3];
|
||||
|
||||
int n = solve(Rs, ts, mu0, mv0, X0, Y0, Z0, mu1, mv1, X1, Y1, Z1, mu2, mv2, X2, Y2, Z2);
|
||||
int n = solve(Rs, ts, mu0, mv0, X0, Y0, Z0, mu1, mv1, X1, Y1, Z1, mu2, mv2, X2, Y2, Z2);
|
||||
|
||||
if (n == 0)
|
||||
return false;
|
||||
if (n == 0)
|
||||
return false;
|
||||
|
||||
int ns = 0;
|
||||
double min_reproj = 0;
|
||||
for(int i = 0; i < n; i++) {
|
||||
double X3p = Rs[i][0][0] * X3 + Rs[i][0][1] * Y3 + Rs[i][0][2] * Z3 + ts[i][0];
|
||||
double Y3p = Rs[i][1][0] * X3 + Rs[i][1][1] * Y3 + Rs[i][1][2] * Z3 + ts[i][1];
|
||||
double Z3p = Rs[i][2][0] * X3 + Rs[i][2][1] * Y3 + Rs[i][2][2] * Z3 + ts[i][2];
|
||||
double mu3p = cx + fx * X3p / Z3p;
|
||||
double mv3p = cy + fy * Y3p / Z3p;
|
||||
double reproj = (mu3p - mu3) * (mu3p - mu3) + (mv3p - mv3) * (mv3p - mv3);
|
||||
if (i == 0 || min_reproj > reproj) {
|
||||
ns = i;
|
||||
min_reproj = reproj;
|
||||
}
|
||||
}
|
||||
int ns = 0;
|
||||
double min_reproj = 0;
|
||||
for(int i = 0; i < n; i++) {
|
||||
double X3p = Rs[i][0][0] * X3 + Rs[i][0][1] * Y3 + Rs[i][0][2] * Z3 + ts[i][0];
|
||||
double Y3p = Rs[i][1][0] * X3 + Rs[i][1][1] * Y3 + Rs[i][1][2] * Z3 + ts[i][1];
|
||||
double Z3p = Rs[i][2][0] * X3 + Rs[i][2][1] * Y3 + Rs[i][2][2] * Z3 + ts[i][2];
|
||||
double mu3p = cx + fx * X3p / Z3p;
|
||||
double mv3p = cy + fy * Y3p / Z3p;
|
||||
double reproj = (mu3p - mu3) * (mu3p - mu3) + (mv3p - mv3) * (mv3p - mv3);
|
||||
if (i == 0 || min_reproj > reproj) {
|
||||
ns = i;
|
||||
min_reproj = reproj;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++)
|
||||
R[i][j] = Rs[ns][i][j];
|
||||
t[i] = ts[ns][i];
|
||||
}
|
||||
for(int i = 0; i < 3; i++) {
|
||||
for(int j = 0; j < 3; j++)
|
||||
R[i][j] = Rs[ns][i][j];
|
||||
t[i] = ts[ns][i];
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int p3p::solve(double R[4][3][3], double t[4][3],
|
||||
double mu0, double mv0, double X0, double Y0, double Z0,
|
||||
double mu1, double mv1, double X1, double Y1, double Z1,
|
||||
double mu2, double mv2, double X2, double Y2, double Z2)
|
||||
double mu0, double mv0, double X0, double Y0, double Z0,
|
||||
double mu1, double mv1, double X1, double Y1, double Z1,
|
||||
double mu2, double mv2, double X2, double Y2, double Z2)
|
||||
{
|
||||
double mk0, mk1, mk2;
|
||||
double norm;
|
||||
double mk0, mk1, mk2;
|
||||
double norm;
|
||||
|
||||
mu0 = inv_fx * mu0 - cx_fx;
|
||||
mv0 = inv_fy * mv0 - cy_fy;
|
||||
norm = sqrt(mu0 * mu0 + mv0 * mv0 + 1);
|
||||
mk0 = 1. / norm; mu0 *= mk0; mv0 *= mk0;
|
||||
mu0 = inv_fx * mu0 - cx_fx;
|
||||
mv0 = inv_fy * mv0 - cy_fy;
|
||||
norm = sqrt(mu0 * mu0 + mv0 * mv0 + 1);
|
||||
mk0 = 1. / norm; mu0 *= mk0; mv0 *= mk0;
|
||||
|
||||
mu1 = inv_fx * mu1 - cx_fx;
|
||||
mv1 = inv_fy * mv1 - cy_fy;
|
||||
norm = sqrt(mu1 * mu1 + mv1 * mv1 + 1);
|
||||
mk1 = 1. / norm; mu1 *= mk1; mv1 *= mk1;
|
||||
mu1 = inv_fx * mu1 - cx_fx;
|
||||
mv1 = inv_fy * mv1 - cy_fy;
|
||||
norm = sqrt(mu1 * mu1 + mv1 * mv1 + 1);
|
||||
mk1 = 1. / norm; mu1 *= mk1; mv1 *= mk1;
|
||||
|
||||
mu2 = inv_fx * mu2 - cx_fx;
|
||||
mv2 = inv_fy * mv2 - cy_fy;
|
||||
norm = sqrt(mu2 * mu2 + mv2 * mv2 + 1);
|
||||
mk2 = 1. / norm; mu2 *= mk2; mv2 *= mk2;
|
||||
mu2 = inv_fx * mu2 - cx_fx;
|
||||
mv2 = inv_fy * mv2 - cy_fy;
|
||||
norm = sqrt(mu2 * mu2 + mv2 * mv2 + 1);
|
||||
mk2 = 1. / norm; mu2 *= mk2; mv2 *= mk2;
|
||||
|
||||
double distances[3];
|
||||
distances[0] = sqrt( (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2) + (Z1 - Z2) * (Z1 - Z2) );
|
||||
distances[1] = sqrt( (X0 - X2) * (X0 - X2) + (Y0 - Y2) * (Y0 - Y2) + (Z0 - Z2) * (Z0 - Z2) );
|
||||
distances[2] = sqrt( (X0 - X1) * (X0 - X1) + (Y0 - Y1) * (Y0 - Y1) + (Z0 - Z1) * (Z0 - Z1) );
|
||||
double distances[3];
|
||||
distances[0] = sqrt( (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2) + (Z1 - Z2) * (Z1 - Z2) );
|
||||
distances[1] = sqrt( (X0 - X2) * (X0 - X2) + (Y0 - Y2) * (Y0 - Y2) + (Z0 - Z2) * (Z0 - Z2) );
|
||||
distances[2] = sqrt( (X0 - X1) * (X0 - X1) + (Y0 - Y1) * (Y0 - Y1) + (Z0 - Z1) * (Z0 - Z1) );
|
||||
|
||||
// Calculate angles
|
||||
double cosines[3];
|
||||
cosines[0] = mu1 * mu2 + mv1 * mv2 + mk1 * mk2;
|
||||
cosines[1] = mu0 * mu2 + mv0 * mv2 + mk0 * mk2;
|
||||
cosines[2] = mu0 * mu1 + mv0 * mv1 + mk0 * mk1;
|
||||
// Calculate angles
|
||||
double cosines[3];
|
||||
cosines[0] = mu1 * mu2 + mv1 * mv2 + mk1 * mk2;
|
||||
cosines[1] = mu0 * mu2 + mv0 * mv2 + mk0 * mk2;
|
||||
cosines[2] = mu0 * mu1 + mv0 * mv1 + mk0 * mk1;
|
||||
|
||||
double lengths[4][3];
|
||||
int n = solve_for_lengths(lengths, distances, cosines);
|
||||
double lengths[4][3];
|
||||
int n = solve_for_lengths(lengths, distances, cosines);
|
||||
|
||||
int nb_solutions = 0;
|
||||
for(int i = 0; i < n; i++) {
|
||||
double M_orig[3][3];
|
||||
int nb_solutions = 0;
|
||||
for(int i = 0; i < n; i++) {
|
||||
double M_orig[3][3];
|
||||
|
||||
M_orig[0][0] = lengths[i][0] * mu0;
|
||||
M_orig[0][1] = lengths[i][0] * mv0;
|
||||
M_orig[0][2] = lengths[i][0] * mk0;
|
||||
M_orig[0][0] = lengths[i][0] * mu0;
|
||||
M_orig[0][1] = lengths[i][0] * mv0;
|
||||
M_orig[0][2] = lengths[i][0] * mk0;
|
||||
|
||||
M_orig[1][0] = lengths[i][1] * mu1;
|
||||
M_orig[1][1] = lengths[i][1] * mv1;
|
||||
M_orig[1][2] = lengths[i][1] * mk1;
|
||||
M_orig[1][0] = lengths[i][1] * mu1;
|
||||
M_orig[1][1] = lengths[i][1] * mv1;
|
||||
M_orig[1][2] = lengths[i][1] * mk1;
|
||||
|
||||
M_orig[2][0] = lengths[i][2] * mu2;
|
||||
M_orig[2][1] = lengths[i][2] * mv2;
|
||||
M_orig[2][2] = lengths[i][2] * mk2;
|
||||
M_orig[2][0] = lengths[i][2] * mu2;
|
||||
M_orig[2][1] = lengths[i][2] * mv2;
|
||||
M_orig[2][2] = lengths[i][2] * mk2;
|
||||
|
||||
if (!align(M_orig, X0, Y0, Z0, X1, Y1, Z1, X2, Y2, Z2, R[nb_solutions], t[nb_solutions]))
|
||||
continue;
|
||||
if (!align(M_orig, X0, Y0, Z0, X1, Y1, Z1, X2, Y2, Z2, R[nb_solutions], t[nb_solutions]))
|
||||
continue;
|
||||
|
||||
nb_solutions++;
|
||||
}
|
||||
nb_solutions++;
|
||||
}
|
||||
|
||||
return nb_solutions;
|
||||
return nb_solutions;
|
||||
}
|
||||
|
||||
/// Given 3D distances between three points and cosines of 3 angles at the apex, calculates
|
||||
@ -170,247 +170,247 @@ int p3p::solve(double R[4][3][3], double t[4][3],
|
||||
|
||||
int p3p::solve_for_lengths(double lengths[4][3], double distances[3], double cosines[3])
|
||||
{
|
||||
double p = cosines[0] * 2;
|
||||
double q = cosines[1] * 2;
|
||||
double r = cosines[2] * 2;
|
||||
double p = cosines[0] * 2;
|
||||
double q = cosines[1] * 2;
|
||||
double r = cosines[2] * 2;
|
||||
|
||||
double inv_d22 = 1. / (distances[2] * distances[2]);
|
||||
double a = inv_d22 * (distances[0] * distances[0]);
|
||||
double b = inv_d22 * (distances[1] * distances[1]);
|
||||
double inv_d22 = 1. / (distances[2] * distances[2]);
|
||||
double a = inv_d22 * (distances[0] * distances[0]);
|
||||
double b = inv_d22 * (distances[1] * distances[1]);
|
||||
|
||||
double a2 = a * a, b2 = b * b, p2 = p * p, q2 = q * q, r2 = r * r;
|
||||
double pr = p * r, pqr = q * pr;
|
||||
double a2 = a * a, b2 = b * b, p2 = p * p, q2 = q * q, r2 = r * r;
|
||||
double pr = p * r, pqr = q * pr;
|
||||
|
||||
// Check reality condition (the four points should not be coplanar)
|
||||
if (p2 + q2 + r2 - pqr - 1 == 0)
|
||||
return 0;
|
||||
// Check reality condition (the four points should not be coplanar)
|
||||
if (p2 + q2 + r2 - pqr - 1 == 0)
|
||||
return 0;
|
||||
|
||||
double ab = a * b, a_2 = 2*a;
|
||||
double ab = a * b, a_2 = 2*a;
|
||||
|
||||
double A = -2 * b + b2 + a2 + 1 + ab*(2 - r2) - a_2;
|
||||
double A = -2 * b + b2 + a2 + 1 + ab*(2 - r2) - a_2;
|
||||
|
||||
// Check reality condition
|
||||
if (A == 0) return 0;
|
||||
// Check reality condition
|
||||
if (A == 0) return 0;
|
||||
|
||||
double a_4 = 4*a;
|
||||
double a_4 = 4*a;
|
||||
|
||||
double B = q*(-2*(ab + a2 + 1 - b) + r2*ab + a_4) + pr*(b - b2 + ab);
|
||||
double C = q2 + b2*(r2 + p2 - 2) - b*(p2 + pqr) - ab*(r2 + pqr) + (a2 - a_2)*(2 + q2) + 2;
|
||||
double D = pr*(ab-b2+b) + q*((p2-2)*b + 2 * (ab - a2) + a_4 - 2);
|
||||
double E = 1 + 2*(b - a - ab) + b2 - b*p2 + a2;
|
||||
double B = q*(-2*(ab + a2 + 1 - b) + r2*ab + a_4) + pr*(b - b2 + ab);
|
||||
double C = q2 + b2*(r2 + p2 - 2) - b*(p2 + pqr) - ab*(r2 + pqr) + (a2 - a_2)*(2 + q2) + 2;
|
||||
double D = pr*(ab-b2+b) + q*((p2-2)*b + 2 * (ab - a2) + a_4 - 2);
|
||||
double E = 1 + 2*(b - a - ab) + b2 - b*p2 + a2;
|
||||
|
||||
double temp = (p2*(a-1+b) + r2*(a-1-b) + pqr - a*pqr);
|
||||
double b0 = b * temp * temp;
|
||||
// Check reality condition
|
||||
if (b0 == 0)
|
||||
return 0;
|
||||
double temp = (p2*(a-1+b) + r2*(a-1-b) + pqr - a*pqr);
|
||||
double b0 = b * temp * temp;
|
||||
// Check reality condition
|
||||
if (b0 == 0)
|
||||
return 0;
|
||||
|
||||
double real_roots[4];
|
||||
int n = solve_deg4(A, B, C, D, E, real_roots[0], real_roots[1], real_roots[2], real_roots[3]);
|
||||
double real_roots[4];
|
||||
int n = solve_deg4(A, B, C, D, E, real_roots[0], real_roots[1], real_roots[2], real_roots[3]);
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
int nb_solutions = 0;
|
||||
double r3 = r2*r, pr2 = p*r2, r3q = r3 * q;
|
||||
double inv_b0 = 1. / b0;
|
||||
int nb_solutions = 0;
|
||||
double r3 = r2*r, pr2 = p*r2, r3q = r3 * q;
|
||||
double inv_b0 = 1. / b0;
|
||||
|
||||
// For each solution of x
|
||||
for(int i = 0; i < n; i++) {
|
||||
double x = real_roots[i];
|
||||
// For each solution of x
|
||||
for(int i = 0; i < n; i++) {
|
||||
double x = real_roots[i];
|
||||
|
||||
// Check reality condition
|
||||
if (x <= 0)
|
||||
continue;
|
||||
// Check reality condition
|
||||
if (x <= 0)
|
||||
continue;
|
||||
|
||||
double x2 = x*x;
|
||||
double x2 = x*x;
|
||||
|
||||
double b1 =
|
||||
((1-a-b)*x2 + (q*a-q)*x + 1 - a + b) *
|
||||
(((r3*(a2 + ab*(2 - r2) - a_2 + b2 - 2*b + 1)) * x +
|
||||
double b1 =
|
||||
((1-a-b)*x2 + (q*a-q)*x + 1 - a + b) *
|
||||
(((r3*(a2 + ab*(2 - r2) - a_2 + b2 - 2*b + 1)) * x +
|
||||
|
||||
(r3q*(2*(b-a2) + a_4 + ab*(r2 - 2) - 2) + pr2*(1 + a2 + 2*(ab-a-b) + r2*(b - b2) + b2))) * x2 +
|
||||
(r3q*(2*(b-a2) + a_4 + ab*(r2 - 2) - 2) + pr2*(1 + a2 + 2*(ab-a-b) + r2*(b - b2) + b2))) * x2 +
|
||||
|
||||
(r3*(q2*(1-2*a+a2) + r2*(b2-ab) - a_4 + 2*(a2 - b2) + 2) + r*p2*(b2 + 2*(ab - b - a) + 1 + a2) + pr2*q*(a_4 + 2*(b - ab - a2) - 2 - r2*b)) * x +
|
||||
(r3*(q2*(1-2*a+a2) + r2*(b2-ab) - a_4 + 2*(a2 - b2) + 2) + r*p2*(b2 + 2*(ab - b - a) + 1 + a2) + pr2*q*(a_4 + 2*(b - ab - a2) - 2 - r2*b)) * x +
|
||||
|
||||
2*r3q*(a_2 - b - a2 + ab - 1) + pr2*(q2 - a_4 + 2*(a2 - b2) + r2*b + q2*(a2 - a_2) + 2) +
|
||||
p2*(p*(2*(ab - a - b) + a2 + b2 + 1) + 2*q*r*(b + a_2 - a2 - ab - 1)));
|
||||
2*r3q*(a_2 - b - a2 + ab - 1) + pr2*(q2 - a_4 + 2*(a2 - b2) + r2*b + q2*(a2 - a_2) + 2) +
|
||||
p2*(p*(2*(ab - a - b) + a2 + b2 + 1) + 2*q*r*(b + a_2 - a2 - ab - 1)));
|
||||
|
||||
// Check reality condition
|
||||
if (b1 <= 0)
|
||||
continue;
|
||||
// Check reality condition
|
||||
if (b1 <= 0)
|
||||
continue;
|
||||
|
||||
double y = inv_b0 * b1;
|
||||
double v = x2 + y*y - x*y*r;
|
||||
double y = inv_b0 * b1;
|
||||
double v = x2 + y*y - x*y*r;
|
||||
|
||||
if (v <= 0)
|
||||
continue;
|
||||
if (v <= 0)
|
||||
continue;
|
||||
|
||||
double Z = distances[2] / sqrt(v);
|
||||
double X = x * Z;
|
||||
double Y = y * Z;
|
||||
double Z = distances[2] / sqrt(v);
|
||||
double X = x * Z;
|
||||
double Y = y * Z;
|
||||
|
||||
lengths[nb_solutions][0] = X;
|
||||
lengths[nb_solutions][1] = Y;
|
||||
lengths[nb_solutions][2] = Z;
|
||||
lengths[nb_solutions][0] = X;
|
||||
lengths[nb_solutions][1] = Y;
|
||||
lengths[nb_solutions][2] = Z;
|
||||
|
||||
nb_solutions++;
|
||||
}
|
||||
nb_solutions++;
|
||||
}
|
||||
|
||||
return nb_solutions;
|
||||
return nb_solutions;
|
||||
}
|
||||
|
||||
bool p3p::align(double M_end[3][3],
|
||||
double X0, double Y0, double Z0,
|
||||
double X1, double Y1, double Z1,
|
||||
double X2, double Y2, double Z2,
|
||||
double R[3][3], double T[3])
|
||||
double X0, double Y0, double Z0,
|
||||
double X1, double Y1, double Z1,
|
||||
double X2, double Y2, double Z2,
|
||||
double R[3][3], double T[3])
|
||||
{
|
||||
// Centroids:
|
||||
double C_start[3], C_end[3];
|
||||
for(int i = 0; i < 3; i++) C_end[i] = (M_end[0][i] + M_end[1][i] + M_end[2][i]) / 3;
|
||||
C_start[0] = (X0 + X1 + X2) / 3;
|
||||
C_start[1] = (Y0 + Y1 + Y2) / 3;
|
||||
C_start[2] = (Z0 + Z1 + Z2) / 3;
|
||||
// Centroids:
|
||||
double C_start[3], C_end[3];
|
||||
for(int i = 0; i < 3; i++) C_end[i] = (M_end[0][i] + M_end[1][i] + M_end[2][i]) / 3;
|
||||
C_start[0] = (X0 + X1 + X2) / 3;
|
||||
C_start[1] = (Y0 + Y1 + Y2) / 3;
|
||||
C_start[2] = (Z0 + Z1 + Z2) / 3;
|
||||
|
||||
// Covariance matrix s:
|
||||
double s[3 * 3];
|
||||
for(int j = 0; j < 3; j++) {
|
||||
s[0 * 3 + j] = (X0 * M_end[0][j] + X1 * M_end[1][j] + X2 * M_end[2][j]) / 3 - C_end[j] * C_start[0];
|
||||
s[1 * 3 + j] = (Y0 * M_end[0][j] + Y1 * M_end[1][j] + Y2 * M_end[2][j]) / 3 - C_end[j] * C_start[1];
|
||||
s[2 * 3 + j] = (Z0 * M_end[0][j] + Z1 * M_end[1][j] + Z2 * M_end[2][j]) / 3 - C_end[j] * C_start[2];
|
||||
}
|
||||
// Covariance matrix s:
|
||||
double s[3 * 3];
|
||||
for(int j = 0; j < 3; j++) {
|
||||
s[0 * 3 + j] = (X0 * M_end[0][j] + X1 * M_end[1][j] + X2 * M_end[2][j]) / 3 - C_end[j] * C_start[0];
|
||||
s[1 * 3 + j] = (Y0 * M_end[0][j] + Y1 * M_end[1][j] + Y2 * M_end[2][j]) / 3 - C_end[j] * C_start[1];
|
||||
s[2 * 3 + j] = (Z0 * M_end[0][j] + Z1 * M_end[1][j] + Z2 * M_end[2][j]) / 3 - C_end[j] * C_start[2];
|
||||
}
|
||||
|
||||
double Qs[16], evs[4], U[16];
|
||||
double Qs[16], evs[4], U[16];
|
||||
|
||||
Qs[0 * 4 + 0] = s[0 * 3 + 0] + s[1 * 3 + 1] + s[2 * 3 + 2];
|
||||
Qs[1 * 4 + 1] = s[0 * 3 + 0] - s[1 * 3 + 1] - s[2 * 3 + 2];
|
||||
Qs[2 * 4 + 2] = s[1 * 3 + 1] - s[2 * 3 + 2] - s[0 * 3 + 0];
|
||||
Qs[3 * 4 + 3] = s[2 * 3 + 2] - s[0 * 3 + 0] - s[1 * 3 + 1];
|
||||
Qs[0 * 4 + 0] = s[0 * 3 + 0] + s[1 * 3 + 1] + s[2 * 3 + 2];
|
||||
Qs[1 * 4 + 1] = s[0 * 3 + 0] - s[1 * 3 + 1] - s[2 * 3 + 2];
|
||||
Qs[2 * 4 + 2] = s[1 * 3 + 1] - s[2 * 3 + 2] - s[0 * 3 + 0];
|
||||
Qs[3 * 4 + 3] = s[2 * 3 + 2] - s[0 * 3 + 0] - s[1 * 3 + 1];
|
||||
|
||||
Qs[1 * 4 + 0] = Qs[0 * 4 + 1] = s[1 * 3 + 2] - s[2 * 3 + 1];
|
||||
Qs[2 * 4 + 0] = Qs[0 * 4 + 2] = s[2 * 3 + 0] - s[0 * 3 + 2];
|
||||
Qs[3 * 4 + 0] = Qs[0 * 4 + 3] = s[0 * 3 + 1] - s[1 * 3 + 0];
|
||||
Qs[2 * 4 + 1] = Qs[1 * 4 + 2] = s[1 * 3 + 0] + s[0 * 3 + 1];
|
||||
Qs[3 * 4 + 1] = Qs[1 * 4 + 3] = s[2 * 3 + 0] + s[0 * 3 + 2];
|
||||
Qs[3 * 4 + 2] = Qs[2 * 4 + 3] = s[2 * 3 + 1] + s[1 * 3 + 2];
|
||||
Qs[1 * 4 + 0] = Qs[0 * 4 + 1] = s[1 * 3 + 2] - s[2 * 3 + 1];
|
||||
Qs[2 * 4 + 0] = Qs[0 * 4 + 2] = s[2 * 3 + 0] - s[0 * 3 + 2];
|
||||
Qs[3 * 4 + 0] = Qs[0 * 4 + 3] = s[0 * 3 + 1] - s[1 * 3 + 0];
|
||||
Qs[2 * 4 + 1] = Qs[1 * 4 + 2] = s[1 * 3 + 0] + s[0 * 3 + 1];
|
||||
Qs[3 * 4 + 1] = Qs[1 * 4 + 3] = s[2 * 3 + 0] + s[0 * 3 + 2];
|
||||
Qs[3 * 4 + 2] = Qs[2 * 4 + 3] = s[2 * 3 + 1] + s[1 * 3 + 2];
|
||||
|
||||
jacobi_4x4(Qs, evs, U);
|
||||
jacobi_4x4(Qs, evs, U);
|
||||
|
||||
// Looking for the largest eigen value:
|
||||
int i_ev = 0;
|
||||
double ev_max = evs[i_ev];
|
||||
for(int i = 1; i < 4; i++)
|
||||
if (evs[i] > ev_max)
|
||||
ev_max = evs[i_ev = i];
|
||||
// Looking for the largest eigen value:
|
||||
int i_ev = 0;
|
||||
double ev_max = evs[i_ev];
|
||||
for(int i = 1; i < 4; i++)
|
||||
if (evs[i] > ev_max)
|
||||
ev_max = evs[i_ev = i];
|
||||
|
||||
// Quaternion:
|
||||
double q[4];
|
||||
for(int i = 0; i < 4; i++)
|
||||
q[i] = U[i * 4 + i_ev];
|
||||
// Quaternion:
|
||||
double q[4];
|
||||
for(int i = 0; i < 4; i++)
|
||||
q[i] = U[i * 4 + i_ev];
|
||||
|
||||
double q02 = q[0] * q[0], q12 = q[1] * q[1], q22 = q[2] * q[2], q32 = q[3] * q[3];
|
||||
double q0_1 = q[0] * q[1], q0_2 = q[0] * q[2], q0_3 = q[0] * q[3];
|
||||
double q1_2 = q[1] * q[2], q1_3 = q[1] * q[3];
|
||||
double q2_3 = q[2] * q[3];
|
||||
double q02 = q[0] * q[0], q12 = q[1] * q[1], q22 = q[2] * q[2], q32 = q[3] * q[3];
|
||||
double q0_1 = q[0] * q[1], q0_2 = q[0] * q[2], q0_3 = q[0] * q[3];
|
||||
double q1_2 = q[1] * q[2], q1_3 = q[1] * q[3];
|
||||
double q2_3 = q[2] * q[3];
|
||||
|
||||
R[0][0] = q02 + q12 - q22 - q32;
|
||||
R[0][1] = 2. * (q1_2 - q0_3);
|
||||
R[0][2] = 2. * (q1_3 + q0_2);
|
||||
R[0][0] = q02 + q12 - q22 - q32;
|
||||
R[0][1] = 2. * (q1_2 - q0_3);
|
||||
R[0][2] = 2. * (q1_3 + q0_2);
|
||||
|
||||
R[1][0] = 2. * (q1_2 + q0_3);
|
||||
R[1][1] = q02 + q22 - q12 - q32;
|
||||
R[1][2] = 2. * (q2_3 - q0_1);
|
||||
R[1][0] = 2. * (q1_2 + q0_3);
|
||||
R[1][1] = q02 + q22 - q12 - q32;
|
||||
R[1][2] = 2. * (q2_3 - q0_1);
|
||||
|
||||
R[2][0] = 2. * (q1_3 - q0_2);
|
||||
R[2][1] = 2. * (q2_3 + q0_1);
|
||||
R[2][2] = q02 + q32 - q12 - q22;
|
||||
R[2][0] = 2. * (q1_3 - q0_2);
|
||||
R[2][1] = 2. * (q2_3 + q0_1);
|
||||
R[2][2] = q02 + q32 - q12 - q22;
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
T[i] = C_end[i] - (R[i][0] * C_start[0] + R[i][1] * C_start[1] + R[i][2] * C_start[2]);
|
||||
for(int i = 0; i < 3; i++)
|
||||
T[i] = C_end[i] - (R[i][0] * C_start[0] + R[i][1] * C_start[1] + R[i][2] * C_start[2]);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3p::jacobi_4x4(double * A, double * D, double * U)
|
||||
{
|
||||
double B[4], Z[4];
|
||||
double Id[16] = {1., 0., 0., 0.,
|
||||
0., 1., 0., 0.,
|
||||
0., 0., 1., 0.,
|
||||
0., 0., 0., 1.};
|
||||
double B[4], Z[4];
|
||||
double Id[16] = {1., 0., 0., 0.,
|
||||
0., 1., 0., 0.,
|
||||
0., 0., 1., 0.,
|
||||
0., 0., 0., 1.};
|
||||
|
||||
memcpy(U, Id, 16 * sizeof(double));
|
||||
memcpy(U, Id, 16 * sizeof(double));
|
||||
|
||||
B[0] = A[0]; B[1] = A[5]; B[2] = A[10]; B[3] = A[15];
|
||||
memcpy(D, B, 4 * sizeof(double));
|
||||
memset(Z, 0, 4 * sizeof(double));
|
||||
B[0] = A[0]; B[1] = A[5]; B[2] = A[10]; B[3] = A[15];
|
||||
memcpy(D, B, 4 * sizeof(double));
|
||||
memset(Z, 0, 4 * sizeof(double));
|
||||
|
||||
for(int iter = 0; iter < 50; iter++) {
|
||||
double sum = fabs(A[1]) + fabs(A[2]) + fabs(A[3]) + fabs(A[6]) + fabs(A[7]) + fabs(A[11]);
|
||||
for(int iter = 0; iter < 50; iter++) {
|
||||
double sum = fabs(A[1]) + fabs(A[2]) + fabs(A[3]) + fabs(A[6]) + fabs(A[7]) + fabs(A[11]);
|
||||
|
||||
if (sum == 0.0)
|
||||
return true;
|
||||
if (sum == 0.0)
|
||||
return true;
|
||||
|
||||
double tresh = (iter < 3) ? 0.2 * sum / 16. : 0.0;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
double * pAij = A + 5 * i + 1;
|
||||
for(int j = i + 1 ; j < 4; j++) {
|
||||
double Aij = *pAij;
|
||||
double eps_machine = 100.0 * fabs(Aij);
|
||||
double tresh = (iter < 3) ? 0.2 * sum / 16. : 0.0;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
double * pAij = A + 5 * i + 1;
|
||||
for(int j = i + 1 ; j < 4; j++) {
|
||||
double Aij = *pAij;
|
||||
double eps_machine = 100.0 * fabs(Aij);
|
||||
|
||||
if ( iter > 3 && fabs(D[i]) + eps_machine == fabs(D[i]) && fabs(D[j]) + eps_machine == fabs(D[j]) )
|
||||
*pAij = 0.0;
|
||||
else if (fabs(Aij) > tresh) {
|
||||
double h = D[j] - D[i], t;
|
||||
if (fabs(h) + eps_machine == fabs(h))
|
||||
t = Aij / h;
|
||||
else {
|
||||
double theta = 0.5 * h / Aij;
|
||||
t = 1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
|
||||
if (theta < 0.0) t = -t;
|
||||
}
|
||||
if ( iter > 3 && fabs(D[i]) + eps_machine == fabs(D[i]) && fabs(D[j]) + eps_machine == fabs(D[j]) )
|
||||
*pAij = 0.0;
|
||||
else if (fabs(Aij) > tresh) {
|
||||
double hh = D[j] - D[i], t;
|
||||
if (fabs(hh) + eps_machine == fabs(hh))
|
||||
t = Aij / hh;
|
||||
else {
|
||||
double theta = 0.5 * hh / Aij;
|
||||
t = 1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
|
||||
if (theta < 0.0) t = -t;
|
||||
}
|
||||
|
||||
h = t * Aij;
|
||||
Z[i] -= h;
|
||||
Z[j] += h;
|
||||
D[i] -= h;
|
||||
D[j] += h;
|
||||
*pAij = 0.0;
|
||||
hh = t * Aij;
|
||||
Z[i] -= hh;
|
||||
Z[j] += hh;
|
||||
D[i] -= hh;
|
||||
D[j] += hh;
|
||||
*pAij = 0.0;
|
||||
|
||||
double c = 1.0 / sqrt(1 + t * t);
|
||||
double s = t * c;
|
||||
double tau = s / (1.0 + c);
|
||||
for(int k = 0; k <= i - 1; k++) {
|
||||
double g = A[k * 4 + i], h = A[k * 4 + j];
|
||||
A[k * 4 + i] = g - s * (h + g * tau);
|
||||
A[k * 4 + j] = h + s * (g - h * tau);
|
||||
}
|
||||
for(int k = i + 1; k <= j - 1; k++) {
|
||||
double g = A[i * 4 + k], h = A[k * 4 + j];
|
||||
A[i * 4 + k] = g - s * (h + g * tau);
|
||||
A[k * 4 + j] = h + s * (g - h * tau);
|
||||
}
|
||||
for(int k = j + 1; k < 4; k++) {
|
||||
double g = A[i * 4 + k], h = A[j * 4 + k];
|
||||
A[i * 4 + k] = g - s * (h + g * tau);
|
||||
A[j * 4 + k] = h + s * (g - h * tau);
|
||||
}
|
||||
for(int k = 0; k < 4; k++) {
|
||||
double g = U[k * 4 + i], h = U[k * 4 + j];
|
||||
U[k * 4 + i] = g - s * (h + g * tau);
|
||||
U[k * 4 + j] = h + s * (g - h * tau);
|
||||
}
|
||||
}
|
||||
pAij++;
|
||||
}
|
||||
}
|
||||
double c = 1.0 / sqrt(1 + t * t);
|
||||
double s = t * c;
|
||||
double tau = s / (1.0 + c);
|
||||
for(int k = 0; k <= i - 1; k++) {
|
||||
double g = A[k * 4 + i], h = A[k * 4 + j];
|
||||
A[k * 4 + i] = g - s * (h + g * tau);
|
||||
A[k * 4 + j] = h + s * (g - h * tau);
|
||||
}
|
||||
for(int k = i + 1; k <= j - 1; k++) {
|
||||
double g = A[i * 4 + k], h = A[k * 4 + j];
|
||||
A[i * 4 + k] = g - s * (h + g * tau);
|
||||
A[k * 4 + j] = h + s * (g - h * tau);
|
||||
}
|
||||
for(int k = j + 1; k < 4; k++) {
|
||||
double g = A[i * 4 + k], h = A[j * 4 + k];
|
||||
A[i * 4 + k] = g - s * (h + g * tau);
|
||||
A[j * 4 + k] = h + s * (g - h * tau);
|
||||
}
|
||||
for(int k = 0; k < 4; k++) {
|
||||
double g = U[k * 4 + i], h = U[k * 4 + j];
|
||||
U[k * 4 + i] = g - s * (h + g * tau);
|
||||
U[k * 4 + j] = h + s * (g - h * tau);
|
||||
}
|
||||
}
|
||||
pAij++;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++) B[i] += Z[i];
|
||||
memcpy(D, B, 4 * sizeof(double));
|
||||
memset(Z, 0, 4 * sizeof(double));
|
||||
}
|
||||
for(int i = 0; i < 4; i++) B[i] += Z[i];
|
||||
memcpy(D, B, 4 * sizeof(double));
|
||||
memset(Z, 0, 4 * sizeof(double));
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -42,10 +42,6 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
@ -54,39 +54,39 @@
|
||||
namespace cv {
|
||||
|
||||
|
||||
void drawCircles(Mat& img, const vector<Point2f>& corners, const vector<float>& radius)
|
||||
{
|
||||
for(size_t i = 0; i < corners.size(); i++)
|
||||
{
|
||||
circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0));
|
||||
}
|
||||
}
|
||||
// static void drawCircles(Mat& img, const vector<Point2f>& corners, const vector<float>& radius)
|
||||
// {
|
||||
// for(size_t i = 0; i < corners.size(); i++)
|
||||
// {
|
||||
// circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0));
|
||||
// }
|
||||
// }
|
||||
|
||||
int histQuantile(const Mat& hist, float quantile)
|
||||
{
|
||||
if(hist.dims > 1) return -1; // works for 1D histograms only
|
||||
// static int histQuantile(const Mat& hist, float quantile)
|
||||
// {
|
||||
// if(hist.dims > 1) return -1; // works for 1D histograms only
|
||||
|
||||
float cur_sum = 0;
|
||||
float total_sum = (float)sum(hist).val[0];
|
||||
float quantile_sum = total_sum*quantile;
|
||||
for(int j = 0; j < hist.size[0]; j++)
|
||||
{
|
||||
cur_sum += (float)hist.at<float>(j);
|
||||
if(cur_sum > quantile_sum)
|
||||
{
|
||||
return j;
|
||||
}
|
||||
}
|
||||
// float cur_sum = 0;
|
||||
// float total_sum = (float)sum(hist).val[0];
|
||||
// float quantile_sum = total_sum*quantile;
|
||||
// for(int j = 0; j < hist.size[0]; j++)
|
||||
// {
|
||||
// cur_sum += (float)hist.at<float>(j);
|
||||
// if(cur_sum > quantile_sum)
|
||||
// {
|
||||
// return j;
|
||||
// }
|
||||
// }
|
||||
|
||||
return hist.size[0] - 1;
|
||||
}
|
||||
// return hist.size[0] - 1;
|
||||
// }
|
||||
|
||||
bool is_smaller(const std::pair<int, float>& p1, const std::pair<int, float>& p2)
|
||||
inline bool is_smaller(const std::pair<int, float>& p1, const std::pair<int, float>& p2)
|
||||
{
|
||||
return p1.second < p2.second;
|
||||
}
|
||||
|
||||
void orderContours(const vector<vector<Point> >& contours, Point2f point, vector<std::pair<int, float> >& order)
|
||||
static void orderContours(const vector<vector<Point> >& contours, Point2f point, vector<std::pair<int, float> >& order)
|
||||
{
|
||||
order.clear();
|
||||
size_t i, j, n = contours.size();
|
||||
@ -106,16 +106,16 @@ void orderContours(const vector<vector<Point> >& contours, Point2f point, vector
|
||||
}
|
||||
|
||||
// fit second order curve to a set of 2D points
|
||||
void fitCurve2Order(const vector<Point2f>& /*points*/, vector<float>& /*curve*/)
|
||||
inline void fitCurve2Order(const vector<Point2f>& /*points*/, vector<float>& /*curve*/)
|
||||
{
|
||||
// TBD
|
||||
}
|
||||
|
||||
void findCurvesCross(const vector<float>& /*curve1*/, const vector<float>& /*curve2*/, Point2f& /*cross_point*/)
|
||||
inline void findCurvesCross(const vector<float>& /*curve1*/, const vector<float>& /*curve2*/, Point2f& /*cross_point*/)
|
||||
{
|
||||
}
|
||||
|
||||
void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, Point2f dir2, Point2f& cross_point)
|
||||
static void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, Point2f dir2, Point2f& cross_point)
|
||||
{
|
||||
float det = dir2.x*dir1.y - dir2.y*dir1.x;
|
||||
Point2f offset = origin2 - origin1;
|
||||
@ -124,30 +124,30 @@ void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, Point2f
|
||||
cross_point = origin1 + dir1*alpha;
|
||||
}
|
||||
|
||||
void findCorner(const vector<Point>& contour, Point2f point, Point2f& corner)
|
||||
{
|
||||
// find the nearest point
|
||||
double min_dist = std::numeric_limits<double>::max();
|
||||
int min_idx = -1;
|
||||
// static void findCorner(const vector<Point>& contour, Point2f point, Point2f& corner)
|
||||
// {
|
||||
// // find the nearest point
|
||||
// double min_dist = std::numeric_limits<double>::max();
|
||||
// int min_idx = -1;
|
||||
|
||||
// find corner idx
|
||||
for(size_t i = 0; i < contour.size(); i++)
|
||||
{
|
||||
double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point);
|
||||
if(dist < min_dist)
|
||||
{
|
||||
min_dist = dist;
|
||||
min_idx = (int)i;
|
||||
}
|
||||
}
|
||||
assert(min_idx >= 0);
|
||||
// // find corner idx
|
||||
// for(size_t i = 0; i < contour.size(); i++)
|
||||
// {
|
||||
// double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point);
|
||||
// if(dist < min_dist)
|
||||
// {
|
||||
// min_dist = dist;
|
||||
// min_idx = (int)i;
|
||||
// }
|
||||
// }
|
||||
// assert(min_idx >= 0);
|
||||
|
||||
// temporary solution, have to make something more precise
|
||||
corner = contour[min_idx];
|
||||
return;
|
||||
}
|
||||
// // temporary solution, have to make something more precise
|
||||
// corner = contour[min_idx];
|
||||
// return;
|
||||
// }
|
||||
|
||||
void findCorner(const vector<Point2f>& contour, Point2f point, Point2f& corner)
|
||||
static void findCorner(const vector<Point2f>& contour, Point2f point, Point2f& corner)
|
||||
{
|
||||
// find the nearest point
|
||||
double min_dist = std::numeric_limits<double>::max();
|
||||
@ -170,7 +170,7 @@ void findCorner(const vector<Point2f>& contour, Point2f point, Point2f& corner)
|
||||
return;
|
||||
}
|
||||
|
||||
int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
static int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh)
|
||||
{
|
||||
Mat bw;
|
||||
//const double max_bell_width = 20; // we expect two bells with width bounded above
|
||||
@ -252,7 +252,7 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size
|
||||
int black_thresh = histQuantile(hist, 0.45f);
|
||||
int white_thresh = histQuantile(hist, 0.55f);
|
||||
#else
|
||||
int black_thresh, white_thresh;
|
||||
int black_thresh = 0, white_thresh = 0;
|
||||
segment_hist_max(hist, black_thresh, white_thresh);
|
||||
#endif
|
||||
|
||||
|
@ -59,41 +59,41 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
|
||||
|
||||
if (flags == CV_EPNP)
|
||||
{
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
epnp PnP(cameraMatrix, opoints, undistortedPoints);
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
epnp PnP(cameraMatrix, opoints, undistortedPoints);
|
||||
|
||||
cv::Mat R, rvec = _rvec.getMat(), tvec = _tvec.getMat();
|
||||
PnP.compute_pose(R, tvec);
|
||||
cv::Rodrigues(R, rvec);
|
||||
return true;
|
||||
}
|
||||
else if (flags == CV_P3P)
|
||||
{
|
||||
CV_Assert( npoints == 4);
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
p3p P3Psolver(cameraMatrix);
|
||||
return true;
|
||||
}
|
||||
else if (flags == CV_P3P)
|
||||
{
|
||||
CV_Assert( npoints == 4);
|
||||
cv::Mat undistortedPoints;
|
||||
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
|
||||
p3p P3Psolver(cameraMatrix);
|
||||
|
||||
cv::Mat R, rvec = _rvec.getMat(), tvec = _tvec.getMat();
|
||||
bool result = P3Psolver.solve(R, tvec, opoints, undistortedPoints);
|
||||
if (result)
|
||||
cv::Rodrigues(R, rvec);
|
||||
return result;
|
||||
}
|
||||
else if (flags == CV_ITERATIVE)
|
||||
{
|
||||
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
|
||||
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
|
||||
CvMat c_rvec = _rvec.getMat(), c_tvec = _tvec.getMat();
|
||||
cvFindExtrinsicCameraParams2(&c_objectPoints, &c_imagePoints, &c_cameraMatrix,
|
||||
c_distCoeffs.rows*c_distCoeffs.cols ? &c_distCoeffs : 0,
|
||||
&c_rvec, &c_tvec, useExtrinsicGuess );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
cv::Rodrigues(R, rvec);
|
||||
return result;
|
||||
}
|
||||
else if (flags == CV_ITERATIVE)
|
||||
{
|
||||
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
|
||||
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
|
||||
CvMat c_rvec = _rvec.getMat(), c_tvec = _tvec.getMat();
|
||||
cvFindExtrinsicCameraParams2(&c_objectPoints, &c_imagePoints, &c_cameraMatrix,
|
||||
c_distCoeffs.rows*c_distCoeffs.cols ? &c_distCoeffs : 0,
|
||||
&c_rvec, &c_tvec, useExtrinsicGuess );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
CV_Error(CV_StsBadArg, "The flags argument must be one of CV_ITERATIVE or CV_EPNP");
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace cv
|
||||
@ -102,7 +102,7 @@ namespace cv
|
||||
{
|
||||
const int MIN_POINTS_COUNT = 4;
|
||||
|
||||
void project3dPoints(const Mat& points, const Mat& rvec, const Mat& tvec, Mat& modif_points)
|
||||
static void project3dPoints(const Mat& points, const Mat& rvec, const Mat& tvec, Mat& modif_points)
|
||||
{
|
||||
modif_points.create(1, points.cols, CV_32FC3);
|
||||
Mat R(3, 3, CV_64FC1);
|
||||
@ -119,11 +119,11 @@ namespace cv
|
||||
{
|
||||
public:
|
||||
Mutex() {
|
||||
}
|
||||
}
|
||||
void lock()
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
resultsMutex.lock();
|
||||
resultsMutex.lock();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -158,11 +158,11 @@ namespace cv
|
||||
float reprojectionError;
|
||||
int minInliersCount;
|
||||
bool useExtrinsicGuess;
|
||||
int flags;
|
||||
int flags;
|
||||
CameraParameters camera;
|
||||
};
|
||||
|
||||
void pnpTask(const vector<char>& pointsMask, const Mat& objectPoints, const Mat& imagePoints,
|
||||
static void pnpTask(const vector<char>& pointsMask, const Mat& objectPoints, const Mat& imagePoints,
|
||||
const Parameters& params, vector<int>& inliers, Mat& rvec, Mat& tvec,
|
||||
const Mat& rvecInit, const Mat& tvecInit, Mutex& resultsMutex)
|
||||
{
|
||||
@ -195,8 +195,8 @@ namespace cv
|
||||
rvecInit.copyTo(localRvec);
|
||||
tvecInit.copyTo(localTvec);
|
||||
|
||||
solvePnP(modelObjectPoints, modelImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec,
|
||||
params.useExtrinsicGuess, params.flags);
|
||||
solvePnP(modelObjectPoints, modelImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec,
|
||||
params.useExtrinsicGuess, params.flags);
|
||||
|
||||
|
||||
vector<Point2f> projected_points;
|
||||
@ -253,16 +253,16 @@ namespace cv
|
||||
}
|
||||
}
|
||||
}
|
||||
PnPSolver(const Mat& objectPoints, const Mat& imagePoints, const Parameters& parameters,
|
||||
Mat& rvec, Mat& tvec, vector<int>& inliers):
|
||||
objectPoints(objectPoints), imagePoints(imagePoints), parameters(parameters),
|
||||
rvec(rvec), tvec(tvec), inliers(inliers)
|
||||
PnPSolver(const Mat& _objectPoints, const Mat& _imagePoints, const Parameters& _parameters,
|
||||
Mat& _rvec, Mat& _tvec, vector<int>& _inliers):
|
||||
objectPoints(_objectPoints), imagePoints(_imagePoints), parameters(_parameters),
|
||||
rvec(_rvec), tvec(_tvec), inliers(_inliers)
|
||||
{
|
||||
rvec.copyTo(initRvec);
|
||||
tvec.copyTo(initTvec);
|
||||
}
|
||||
private:
|
||||
PnPSolver& operator=(const PnPSolver&);
|
||||
PnPSolver& operator=(const PnPSolver&);
|
||||
|
||||
const Mat& objectPoints;
|
||||
const Mat& imagePoints;
|
||||
@ -325,7 +325,7 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
|
||||
params.reprojectionError = reprojectionError;
|
||||
params.useExtrinsicGuess = useExtrinsicGuess;
|
||||
params.camera.init(cameraMatrix, distCoeffs);
|
||||
params.flags = flags;
|
||||
params.flags = flags;
|
||||
|
||||
vector<int> localInliers;
|
||||
Mat localRvec, localTvec;
|
||||
@ -340,21 +340,21 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
|
||||
|
||||
if (localInliers.size() >= (size_t)pnpransac::MIN_POINTS_COUNT)
|
||||
{
|
||||
if (flags != CV_P3P)
|
||||
{
|
||||
int i, pointsCount = (int)localInliers.size();
|
||||
Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2);
|
||||
for (i = 0; i < pointsCount; i++)
|
||||
{
|
||||
int index = localInliers[i];
|
||||
Mat colInlierImagePoints = inlierImagePoints(Rect(i, 0, 1, 1));
|
||||
imagePoints.col(index).copyTo(colInlierImagePoints);
|
||||
Mat colInlierObjectPoints = inlierObjectPoints(Rect(i, 0, 1, 1));
|
||||
objectPoints.col(index).copyTo(colInlierObjectPoints);
|
||||
}
|
||||
solvePnP(inlierObjectPoints, inlierImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, true, flags);
|
||||
}
|
||||
localRvec.copyTo(rvec);
|
||||
if (flags != CV_P3P)
|
||||
{
|
||||
int i, pointsCount = (int)localInliers.size();
|
||||
Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2);
|
||||
for (i = 0; i < pointsCount; i++)
|
||||
{
|
||||
int index = localInliers[i];
|
||||
Mat colInlierImagePoints = inlierImagePoints(Rect(i, 0, 1, 1));
|
||||
imagePoints.col(index).copyTo(colInlierImagePoints);
|
||||
Mat colInlierObjectPoints = inlierObjectPoints(Rect(i, 0, 1, 1));
|
||||
objectPoints.col(index).copyTo(colInlierObjectPoints);
|
||||
}
|
||||
solvePnP(inlierObjectPoints, inlierImagePoints, params.camera.intrinsics, params.camera.distortion, localRvec, localTvec, true, flags);
|
||||
}
|
||||
localRvec.copyTo(rvec);
|
||||
localTvec.copyTo(tvec);
|
||||
if (_inliers.needed())
|
||||
Mat(localInliers).copyTo(_inliers);
|
||||
|
@ -336,7 +336,7 @@ static void findStereoCorrespondenceBM_SSE2( const Mat& left, const Mat& right,
|
||||
short* costptr = cost.data ? (short*)cost.data + lofs + x : &costbuf;
|
||||
int x0 = x - wsz2 - 1, x1 = x + wsz2;
|
||||
const uchar* cbuf_sub = cbuf0 + ((x0 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
|
||||
uchar* cbuf = cbuf0 + ((x1 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
|
||||
cbuf = cbuf0 + ((x1 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
|
||||
hsad = hsad0 - dy0*ndisp;
|
||||
lptr_sub = lptr0 + MIN(MAX(x0, -lofs), width-1-lofs) - dy0*sstep;
|
||||
lptr = lptr0 + MIN(MAX(x1, -lofs), width-1-lofs) - dy0*sstep;
|
||||
@ -463,7 +463,8 @@ static void findStereoCorrespondenceBM_SSE2( const Mat& left, const Mat& right,
|
||||
int thresh = minsad + ((minsad * uniquenessRatio) >> 8);
|
||||
__m128i thresh8 = _mm_set1_epi16((short)(thresh + 1));
|
||||
__m128i d1 = _mm_set1_epi16((short)(mind-1)), d2 = _mm_set1_epi16((short)(mind+1));
|
||||
__m128i dd_16 = _mm_add_epi16(dd_8, dd_8), d8 = _mm_sub_epi16(d0_8, dd_16);
|
||||
__m128i dd_16 = _mm_add_epi16(dd_8, dd_8);
|
||||
d8 = _mm_sub_epi16(d0_8, dd_16);
|
||||
|
||||
for( d = 0; d < ndisp; d += 16 )
|
||||
{
|
||||
@ -492,7 +493,8 @@ static void findStereoCorrespondenceBM_SSE2( const Mat& left, const Mat& right,
|
||||
|
||||
if( 0 < mind && mind < ndisp - 1 )
|
||||
{
|
||||
int p = sad[mind+1], n = sad[mind-1], d = p + n - 2*sad[mind] + std::abs(p - n);
|
||||
int p = sad[mind+1], n = sad[mind-1];
|
||||
d = p + n - 2*sad[mind] + std::abs(p - n);
|
||||
dptr[y*dstep] = (short)(((ndisp - mind - 1 + mindisp)*256 + (d != 0 ? (p-n)*256/d : 0) + 15) >> 4);
|
||||
}
|
||||
else
|
||||
@ -583,7 +585,7 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right,
|
||||
int* costptr = cost.data ? (int*)cost.data + lofs + x : &costbuf;
|
||||
int x0 = x - wsz2 - 1, x1 = x + wsz2;
|
||||
const uchar* cbuf_sub = cbuf0 + ((x0 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
|
||||
uchar* cbuf = cbuf0 + ((x1 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
|
||||
cbuf = cbuf0 + ((x1 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
|
||||
hsad = hsad0 - dy0*ndisp;
|
||||
lptr_sub = lptr0 + MIN(MAX(x0, -lofs), width-1-lofs) - dy0*sstep;
|
||||
lptr = lptr0 + MIN(MAX(x1, -lofs), width-1-lofs) - dy0*sstep;
|
||||
@ -662,7 +664,8 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right,
|
||||
{
|
||||
sad[-1] = sad[1];
|
||||
sad[ndisp] = sad[ndisp-2];
|
||||
int p = sad[mind+1], n = sad[mind-1], d = p + n - 2*sad[mind] + std::abs(p - n);
|
||||
int p = sad[mind+1], n = sad[mind-1];
|
||||
d = p + n - 2*sad[mind] + std::abs(p - n);
|
||||
dptr[y*dstep] = (short)(((ndisp - mind - 1 + mindisp)*256 + (d != 0 ? (p-n)*256/d : 0) + 15) >> 4);
|
||||
costptr[y*coststep] = sad[mind];
|
||||
}
|
||||
|
@ -773,11 +773,11 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
if( d < D )
|
||||
continue;
|
||||
d = bestDisp;
|
||||
int x2 = x + minX1 - d - minD;
|
||||
if( disp2cost[x2] > minS )
|
||||
int _x2 = x + minX1 - d - minD;
|
||||
if( disp2cost[_x2] > minS )
|
||||
{
|
||||
disp2cost[x2] = (CostType)minS;
|
||||
disp2ptr[x2] = (DispType)(d + minD);
|
||||
disp2cost[_x2] = (CostType)minS;
|
||||
disp2ptr[_x2] = (DispType)(d + minD);
|
||||
}
|
||||
|
||||
if( 0 < d && d < D-1 )
|
||||
@ -798,11 +798,11 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2,
|
||||
// we round the computed disparity both towards -inf and +inf and check
|
||||
// if either of the corresponding disparities in disp2 is consistent.
|
||||
// This is to give the computed disparity a chance to look valid if it is.
|
||||
int d = disp1ptr[x];
|
||||
if( d == INVALID_DISP_SCALED )
|
||||
int d1 = disp1ptr[x];
|
||||
if( d1 == INVALID_DISP_SCALED )
|
||||
continue;
|
||||
int _d = d >> DISP_SHIFT;
|
||||
int d_ = (d + DISP_SCALE-1) >> DISP_SHIFT;
|
||||
int _d = d1 >> DISP_SHIFT;
|
||||
int d_ = (d1 + DISP_SCALE-1) >> DISP_SHIFT;
|
||||
int _x = x - _d, x_ = x - d_;
|
||||
if( 0 <= _x && _x < width && disp2ptr[_x] >= minD && std::abs(disp2ptr[_x] - _d) > disp12MaxDiff &&
|
||||
0 <= x_ && x_ < width && disp2ptr[x_] >= minD && std::abs(disp2ptr[x_] - d_) > disp12MaxDiff )
|
||||
@ -890,9 +890,9 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi
|
||||
|
||||
for( j = 0; j < width; j++ )
|
||||
{
|
||||
if( ds[j] != newVal ) // not a bad disparity
|
||||
if( ds[j] != newVal ) // not a bad disparity
|
||||
{
|
||||
if( ls[j] ) // has a label, check for bad label
|
||||
if( ls[j] ) // has a label, check for bad label
|
||||
{
|
||||
if( rtype[ls[j]] ) // small region, zero out disparity
|
||||
ds[j] = (short)newVal;
|
||||
@ -900,10 +900,10 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi
|
||||
// no label, assign and propagate
|
||||
else
|
||||
{
|
||||
Point2s* ws = wbuf; // initialize wavefront
|
||||
Point2s p((short)j, (short)i); // current pixel
|
||||
curlabel++; // next label
|
||||
int count = 0; // current region size
|
||||
Point2s* ws = wbuf; // initialize wavefront
|
||||
Point2s p((short)j, (short)i); // current pixel
|
||||
curlabel++; // next label
|
||||
int count = 0; // current region size
|
||||
ls[j] = curlabel;
|
||||
|
||||
// wavefront propagation
|
||||
@ -945,13 +945,13 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi
|
||||
}
|
||||
|
||||
// assign label type
|
||||
if( count <= maxSpeckleSize ) // speckle region
|
||||
if( count <= maxSpeckleSize ) // speckle region
|
||||
{
|
||||
rtype[ls[j]] = 1; // small region label
|
||||
rtype[ls[j]] = 1; // small region label
|
||||
ds[j] = (short)newVal;
|
||||
}
|
||||
else
|
||||
rtype[ls[j]] = 0; // large region label
|
||||
rtype[ls[j]] = 0; // large region label
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -221,19 +221,19 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
double reprojectErrorWithoutIntrinsics(const vector<Point3f>& cb3d, const vector<Mat>& rvecs_exp, const vector<Mat>& tvecs_exp,
|
||||
double reprojectErrorWithoutIntrinsics(const vector<Point3f>& cb3d, const vector<Mat>& _rvecs_exp, const vector<Mat>& _tvecs_exp,
|
||||
const vector<Mat>& rvecs_est, const vector<Mat>& tvecs_est)
|
||||
{
|
||||
const static Mat eye33 = Mat::eye(3, 3, CV_64F);
|
||||
const static Mat zero15 = Mat::zeros(1, 5, CV_64F);
|
||||
Mat chessboard3D(cb3d);
|
||||
Mat _chessboard3D(cb3d);
|
||||
vector<Point2f> uv_exp, uv_est;
|
||||
double res = 0;
|
||||
|
||||
for(size_t i = 0; i < rvecs_exp.size(); ++i)
|
||||
{
|
||||
projectPoints(chessboard3D, rvecs_exp[i], tvecs_exp[i], eye33, zero15, uv_exp);
|
||||
projectPoints(chessboard3D, rvecs_est[i], tvecs_est[i], eye33, zero15, uv_est);
|
||||
projectPoints(_chessboard3D, _rvecs_exp[i], _tvecs_exp[i], eye33, zero15, uv_exp);
|
||||
projectPoints(_chessboard3D, rvecs_est[i], tvecs_est[i], eye33, zero15, uv_est);
|
||||
for(size_t j = 0; j < cb3d.size(); ++j)
|
||||
res += norm(uv_exp[i] - uv_est[i]);
|
||||
}
|
||||
|
@ -137,8 +137,7 @@ const double precise_success_error_level = 2;
|
||||
/* ///////////////////// chess_corner_test ///////////////////////// */
|
||||
void CV_ChessboardDetectorTest::run( int /*start_from */)
|
||||
{
|
||||
cvtest::TS& ts = *this->ts;
|
||||
ts.set_failed_test_info( cvtest::TS::OK );
|
||||
ts->set_failed_test_info( cvtest::TS::OK );
|
||||
|
||||
/*if (!checkByGenerator())
|
||||
return;*/
|
||||
@ -146,19 +145,19 @@ void CV_ChessboardDetectorTest::run( int /*start_from */)
|
||||
{
|
||||
case CHESSBOARD:
|
||||
checkByGenerator();
|
||||
if (ts.get_err_code() != cvtest::TS::OK)
|
||||
if (ts->get_err_code() != cvtest::TS::OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
run_batch("negative_list.dat");
|
||||
if (ts.get_err_code() != cvtest::TS::OK)
|
||||
if (ts->get_err_code() != cvtest::TS::OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
run_batch("chessboard_list.dat");
|
||||
if (ts.get_err_code() != cvtest::TS::OK)
|
||||
if (ts->get_err_code() != cvtest::TS::OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -176,9 +175,7 @@ void CV_ChessboardDetectorTest::run( int /*start_from */)
|
||||
|
||||
void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
{
|
||||
cvtest::TS& ts = *this->ts;
|
||||
|
||||
ts.printf(cvtest::TS::LOG, "\nRunning batch %s\n", filename.c_str());
|
||||
ts->printf(cvtest::TS::LOG, "\nRunning batch %s\n", filename.c_str());
|
||||
//#define WRITE_POINTS 1
|
||||
#ifndef WRITE_POINTS
|
||||
double max_rough_error = 0, max_precise_error = 0;
|
||||
@ -187,13 +184,13 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
switch( pattern )
|
||||
{
|
||||
case CHESSBOARD:
|
||||
folder = string(ts.get_data_path()) + "cameracalibration/";
|
||||
folder = string(ts->get_data_path()) + "cameracalibration/";
|
||||
break;
|
||||
case CIRCLES_GRID:
|
||||
folder = string(ts.get_data_path()) + "cameracalibration/circles/";
|
||||
folder = string(ts->get_data_path()) + "cameracalibration/circles/";
|
||||
break;
|
||||
case ASYMMETRIC_CIRCLES_GRID:
|
||||
folder = string(ts.get_data_path()) + "cameracalibration/asymmetric_circles/";
|
||||
folder = string(ts->get_data_path()) + "cameracalibration/asymmetric_circles/";
|
||||
break;
|
||||
}
|
||||
|
||||
@ -202,10 +199,10 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
|
||||
if( !fs.isOpened() || board_list.empty() || !board_list.isSeq() || board_list.size() % 2 != 0 )
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "%s can not be readed or is not valid\n", (folder + filename).c_str() );
|
||||
ts.printf( cvtest::TS::LOG, "fs.isOpened=%d, board_list.empty=%d, board_list.isSeq=%d,board_list.size()%2=%d\n",
|
||||
ts->printf( cvtest::TS::LOG, "%s can not be readed or is not valid\n", (folder + filename).c_str() );
|
||||
ts->printf( cvtest::TS::LOG, "fs.isOpened=%d, board_list.empty=%d, board_list.isSeq=%d,board_list.size()%2=%d\n",
|
||||
fs.isOpened(), (int)board_list.empty(), board_list.isSeq(), board_list.size()%2);
|
||||
ts.set_failed_test_info( cvtest::TS::FAIL_MISSING_TEST_DATA );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISSING_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -216,7 +213,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
|
||||
for(int idx = 0; idx < max_idx; ++idx )
|
||||
{
|
||||
ts.update_context( this, idx, true );
|
||||
ts->update_context( this, idx, true );
|
||||
|
||||
/* read the image */
|
||||
string img_file = board_list[idx * 2];
|
||||
@ -224,19 +221,19 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
|
||||
if( gray.empty() )
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", img_file.c_str() );
|
||||
ts.set_failed_test_info( cvtest::TS::FAIL_MISSING_TEST_DATA );
|
||||
ts->printf( cvtest::TS::LOG, "one of chessboard images can't be read: %s\n", img_file.c_str() );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISSING_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
string filename = folder + (string)board_list[idx * 2 + 1];
|
||||
string _filename = folder + (string)board_list[idx * 2 + 1];
|
||||
bool doesContatinChessboard;
|
||||
Mat expected;
|
||||
{
|
||||
FileStorage fs(filename, FileStorage::READ);
|
||||
fs["corners"] >> expected;
|
||||
fs["isFound"] >> doesContatinChessboard;
|
||||
fs.release();
|
||||
FileStorage fs1(_filename, FileStorage::READ);
|
||||
fs1["corners"] >> expected;
|
||||
fs1["isFound"] >> doesContatinChessboard;
|
||||
fs1.release();
|
||||
}
|
||||
size_t count_exp = static_cast<size_t>(expected.cols * expected.rows);
|
||||
Size pattern_size = expected.size();
|
||||
@ -259,8 +256,8 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
|
||||
if( result ^ doesContatinChessboard || v.size() != count_exp )
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "chessboard is detected incorrectly in %s\n", img_file.c_str() );
|
||||
ts.set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
|
||||
ts->printf( cvtest::TS::LOG, "chessboard is detected incorrectly in %s\n", img_file.c_str() );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -291,19 +288,19 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
#if 1
|
||||
if( err > precise_success_error_level )
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "Image %s: bad accuracy of adjusted corners %f\n", img_file.c_str(), err );
|
||||
ts.set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
ts->printf( cvtest::TS::LOG, "Image %s: bad accuracy of adjusted corners %f\n", img_file.c_str(), err );
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY );
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
ts.printf(cvtest::TS::LOG, "Error on %s is %f\n", img_file.c_str(), err);
|
||||
ts->printf(cvtest::TS::LOG, "Error on %s is %f\n", img_file.c_str(), err);
|
||||
max_precise_error = MAX( max_precise_error, err );
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WRITE_POINTS
|
||||
Mat mat_v(pattern_size, CV_32FC2, (void*)&v[0]);
|
||||
FileStorage fs(filename, FileStorage::WRITE);
|
||||
FileStorage fs(_filename, FileStorage::WRITE);
|
||||
fs << "isFound" << result;
|
||||
fs << "corners" << mat_v;
|
||||
fs.release();
|
||||
@ -312,7 +309,7 @@ void CV_ChessboardDetectorTest::run_batch( const string& filename )
|
||||
}
|
||||
|
||||
sum_error /= count;
|
||||
ts.printf(cvtest::TS::LOG, "Average error is %f\n", sum_error);
|
||||
ts->printf(cvtest::TS::LOG, "Average error is %f\n", sum_error);
|
||||
}
|
||||
|
||||
double calcErrorMinError(const Size& cornSz, const vector<Point2f>& corners_found, const vector<Point2f>& corners_generated)
|
||||
|
@ -139,8 +139,7 @@ protected:
|
||||
|
||||
void run(int)
|
||||
{
|
||||
cvtest::TS& ts = *this->ts;
|
||||
ts.set_failed_test_info(cvtest::TS::OK);
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
|
||||
Mat_<double> rvec1(3, 1), tvec1(3, 1), rvec2(3, 1), tvec2(3, 1);
|
||||
|
||||
@ -164,7 +163,7 @@ protected:
|
||||
|
||||
const double thres = 1e-5;
|
||||
if (norm(rvec3_exp, rvec3) > thres || norm(tvec3_exp, tvec3) > thres)
|
||||
ts.set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
|
||||
const double eps = 1e-3;
|
||||
Differential diff(eps, rvec1, tvec1, rvec2, tvec2);
|
||||
@ -179,8 +178,8 @@ protected:
|
||||
|
||||
if (norm(dr3_dr1, dr3dr1) > thres || norm(dt3_dr1, dt3dr1) > thres)
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "Invalid derivates by r1\n" );
|
||||
ts.set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
ts->printf( cvtest::TS::LOG, "Invalid derivates by r1\n" );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
Mat_<double> dr3_dr2, dt3_dr2;
|
||||
@ -188,8 +187,8 @@ protected:
|
||||
|
||||
if (norm(dr3_dr2, dr3dr2) > thres || norm(dt3_dr2, dt3dr2) > thres)
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "Invalid derivates by r2\n" );
|
||||
ts.set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
ts->printf( cvtest::TS::LOG, "Invalid derivates by r2\n" );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
Mat_<double> dr3_dt1, dt3_dt1;
|
||||
@ -197,8 +196,8 @@ protected:
|
||||
|
||||
if (norm(dr3_dt1, dr3dt1) > thres || norm(dt3_dt1, dt3dt1) > thres)
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "Invalid derivates by t1\n" );
|
||||
ts.set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
ts->printf( cvtest::TS::LOG, "Invalid derivates by t1\n" );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
|
||||
Mat_<double> dr3_dt2, dt3_dt2;
|
||||
@ -206,8 +205,8 @@ protected:
|
||||
|
||||
if (norm(dr3_dt2, dr3dt2) > thres || norm(dt3_dt2, dt3dt2) > thres)
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "Invalid derivates by t2\n" );
|
||||
ts.set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
ts->printf( cvtest::TS::LOG, "Invalid derivates by t2\n" );
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -86,20 +86,20 @@ protected:
|
||||
double sigma;
|
||||
|
||||
private:
|
||||
float max_diff, max_2diff;
|
||||
bool check_matrix_size(const cv::Mat& H);
|
||||
bool check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff);
|
||||
float max_diff, max_2diff;
|
||||
bool check_matrix_size(const cv::Mat& H);
|
||||
bool check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff);
|
||||
int check_ransac_mask_1(const Mat& src, const Mat& mask);
|
||||
int check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask);
|
||||
int check_ransac_mask_2(const Mat& original_mask, const Mat& found_mask);
|
||||
|
||||
void print_information_1(int j, int N, int method, const Mat& H);
|
||||
void print_information_2(int j, int N, int method, const Mat& H, const Mat& H_res, int k, double diff);
|
||||
void print_information_3(int j, int N, const Mat& mask);
|
||||
void print_information_4(int method, int j, int N, int k, int l, double diff);
|
||||
void print_information_5(int method, int j, int N, int l, double diff);
|
||||
void print_information_6(int j, int N, int k, double diff, bool value);
|
||||
void print_information_7(int j, int N, int k, double diff, bool original_value, bool found_value);
|
||||
void print_information_8(int j, int N, int k, int l, double diff);
|
||||
void print_information_1(int j, int N, int method, const Mat& H);
|
||||
void print_information_2(int j, int N, int method, const Mat& H, const Mat& H_res, int k, double diff);
|
||||
void print_information_3(int j, int N, const Mat& mask);
|
||||
void print_information_4(int method, int j, int N, int k, int l, double diff);
|
||||
void print_information_5(int method, int j, int N, int l, double diff);
|
||||
void print_information_6(int j, int N, int k, double diff, bool value);
|
||||
void print_information_7(int j, int N, int k, double diff, bool original_value, bool found_value);
|
||||
void print_information_8(int j, int N, int k, int l, double diff);
|
||||
};
|
||||
|
||||
CV_HomographyTest::CV_HomographyTest() : max_diff(1e-2f), max_2diff(2e-2f)
|
||||
@ -138,25 +138,25 @@ int CV_HomographyTest::check_ransac_mask_2(const Mat& original_mask, const Mat&
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_1(int j, int N, int method, const Mat& H)
|
||||
void CV_HomographyTest::print_information_1(int j, int N, int _method, const Mat& H)
|
||||
{
|
||||
cout << endl; cout << "Checking for homography matrix sizes..." << endl; cout << endl;
|
||||
cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";
|
||||
cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;
|
||||
cout << "Count of points: " << N << endl; cout << endl;
|
||||
cout << "Method: "; if (method == 0) cout << 0; else if (method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;
|
||||
cout << "Method: "; if (_method == 0) cout << 0; else if (_method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;
|
||||
cout << "Homography matrix:" << endl; cout << endl;
|
||||
cout << H << endl; cout << endl;
|
||||
cout << "Number of rows: " << H.rows << " Number of cols: " << H.cols << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_2(int j, int N, int method, const Mat& H, const Mat& H_res, int k, double diff)
|
||||
void CV_HomographyTest::print_information_2(int j, int N, int _method, const Mat& H, const Mat& H_res, int k, double diff)
|
||||
{
|
||||
cout << endl; cout << "Checking for accuracy of homography matrix computing..." << endl; cout << endl;
|
||||
cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";
|
||||
cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;
|
||||
cout << "Count of points: " << N << endl; cout << endl;
|
||||
cout << "Method: "; if (method == 0) cout << 0; else if (method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;
|
||||
cout << "Method: "; if (_method == 0) cout << 0; else if (_method == 8) cout << "RANSAC"; else cout << "LMEDS"; cout << endl;
|
||||
cout << "Original matrix:" << endl; cout << endl;
|
||||
cout << H << endl; cout << endl;
|
||||
cout << "Found matrix:" << endl; cout << endl;
|
||||
@ -178,10 +178,10 @@ void CV_HomographyTest::print_information_3(int j, int N, const Mat& mask)
|
||||
cout << "Number of rows: " << mask.rows << " Number of cols: " << mask.cols << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_4(int method, int j, int N, int k, int l, double diff)
|
||||
void CV_HomographyTest::print_information_4(int _method, int j, int N, int k, int l, double diff)
|
||||
{
|
||||
cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;
|
||||
cout << "Method: "; if (method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;
|
||||
cout << "Method: "; if (_method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;
|
||||
cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";
|
||||
cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;
|
||||
cout << "Sigma of normal noise: " << sigma << endl;
|
||||
@ -192,10 +192,10 @@ void CV_HomographyTest::print_information_4(int method, int j, int N, int k, int
|
||||
cout << "Maxumum allowed difference: " << max_2diff << endl; cout << endl;
|
||||
}
|
||||
|
||||
void CV_HomographyTest::print_information_5(int method, int j, int N, int l, double diff)
|
||||
void CV_HomographyTest::print_information_5(int _method, int j, int N, int l, double diff)
|
||||
{
|
||||
cout << endl; cout << "Checking for accuracy of reprojection error computing..." << endl; cout << endl;
|
||||
cout << "Method: "; if (method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;
|
||||
cout << "Method: "; if (_method == 0) cout << 0 << endl; else cout << "CV_LMEDS" << endl;
|
||||
cout << "Type of srcPoints: "; if ((j>-1) && (j<2)) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>";
|
||||
cout << " Type of dstPoints: "; if (j % 2 == 0) cout << "Mat of CV_32FC2"; else cout << "vector <Point2f>"; cout << endl;
|
||||
cout << "Sigma of normal noise: " << sigma << endl;
|
||||
@ -412,7 +412,7 @@ void CV_HomographyTest::run(int)
|
||||
{
|
||||
case 0:
|
||||
case CV_LMEDS:
|
||||
{
|
||||
{
|
||||
Mat H_res_64 [4] = { cv::findHomography(src_mat_2f, dst_mat_2f),
|
||||
cv::findHomography(src_mat_2f, dst_vec),
|
||||
cv::findHomography(src_vec, dst_mat_2f),
|
||||
@ -465,7 +465,7 @@ void CV_HomographyTest::run(int)
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
case CV_RANSAC:
|
||||
{
|
||||
cv::Mat mask_res [4];
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
||||
#endif
|
||||
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
|
@ -106,7 +106,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool runTest(RNG& rng, int mode, int method, const vector<Point3f>& points, const double* eps, double& maxError)
|
||||
virtual bool runTest(RNG& rng, int mode, int method, const vector<Point3f>& points, const double* epsilon, double& maxError)
|
||||
{
|
||||
Mat rvec, tvec;
|
||||
vector<int> inliers;
|
||||
@ -136,7 +136,7 @@ protected:
|
||||
bool isTestSuccess = inliers.size() >= points.size()*0.95;
|
||||
|
||||
double rvecDiff = norm(rvec-trueRvec), tvecDiff = norm(tvec-trueTvec);
|
||||
isTestSuccess = isTestSuccess && rvecDiff < eps[method] && tvecDiff < eps[method];
|
||||
isTestSuccess = isTestSuccess && rvecDiff < epsilon[method] && tvecDiff < epsilon[method];
|
||||
double error = rvecDiff > tvecDiff ? rvecDiff : tvecDiff;
|
||||
//cout << error << " " << inliers.size() << " " << eps[method] << endl;
|
||||
if (error > maxError)
|
||||
@ -147,8 +147,7 @@ protected:
|
||||
|
||||
void run(int)
|
||||
{
|
||||
cvtest::TS& ts = *this->ts;
|
||||
ts.set_failed_test_info(cvtest::TS::OK);
|
||||
ts->set_failed_test_info(cvtest::TS::OK);
|
||||
|
||||
vector<Point3f> points;
|
||||
const int pointsCount = 500;
|
||||
@ -157,7 +156,7 @@ protected:
|
||||
|
||||
|
||||
const int methodsCount = 3;
|
||||
RNG rng = ts.get_rng();
|
||||
RNG rng = ts->get_rng();
|
||||
|
||||
|
||||
for (int mode = 0; mode < 2; mode++)
|
||||
@ -174,9 +173,9 @@ protected:
|
||||
//cout << maxError << " " << successfulTestsCount << endl;
|
||||
if (successfulTestsCount < 0.7*totalTestsCount)
|
||||
{
|
||||
ts.printf( cvtest::TS::LOG, "Invalid accuracy for method %d, failed %d tests from %d, maximum error equals %f, distortion mode equals %d\n",
|
||||
ts->printf( cvtest::TS::LOG, "Invalid accuracy for method %d, failed %d tests from %d, maximum error equals %f, distortion mode equals %d\n",
|
||||
method, totalTestsCount - successfulTestsCount, totalTestsCount, maxError, mode);
|
||||
ts.set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,7 +197,7 @@ public:
|
||||
|
||||
~CV_solvePnP_Test() {}
|
||||
protected:
|
||||
virtual bool runTest(RNG& rng, int mode, int method, const vector<Point3f>& points, const double* eps, double& maxError)
|
||||
virtual bool runTest(RNG& rng, int mode, int method, const vector<Point3f>& points, const double* epsilon, double& maxError)
|
||||
{
|
||||
Mat rvec, tvec;
|
||||
Mat trueRvec, trueTvec;
|
||||
@ -226,7 +225,7 @@ protected:
|
||||
false, method);
|
||||
|
||||
double rvecDiff = norm(rvec-trueRvec), tvecDiff = norm(tvec-trueTvec);
|
||||
bool isTestSuccess = rvecDiff < eps[method] && tvecDiff < eps[method];
|
||||
bool isTestSuccess = rvecDiff < epsilon[method] && tvecDiff < epsilon[method];
|
||||
|
||||
double error = rvecDiff > tvecDiff ? rvecDiff : tvecDiff;
|
||||
if (error > maxError)
|
||||
|
@ -593,11 +593,11 @@ int CV_StereoMatchingTest::readDatasetsParams( FileStorage& fs )
|
||||
assert(fn.isSeq());
|
||||
for( int i = 0; i < (int)fn.size(); i+=3 )
|
||||
{
|
||||
string name = fn[i];
|
||||
string _name = fn[i];
|
||||
DatasetParams params;
|
||||
string sf = fn[i+1]; params.dispScaleFactor = atoi(sf.c_str());
|
||||
string uv = fn[i+2]; params.dispUnknVal = atoi(uv.c_str());
|
||||
datasetsParams[name] = params;
|
||||
datasetsParams[_name] = params;
|
||||
}
|
||||
return cvtest::TS::OK;
|
||||
}
|
||||
|
@ -585,34 +585,34 @@ namespace cv
|
||||
//! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair
|
||||
CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, Mat& disp);
|
||||
|
||||
CV_PROP_RW int levels;
|
||||
CV_PROP_RW double pyrScale;
|
||||
CV_PROP_RW int nIt;
|
||||
CV_PROP_RW int minDisp;
|
||||
CV_PROP_RW int maxDisp;
|
||||
CV_PROP_RW int poly_n;
|
||||
CV_PROP_RW double poly_sigma;
|
||||
CV_PROP_RW float fi;
|
||||
CV_PROP_RW float lambda;
|
||||
CV_PROP_RW int penalization;
|
||||
CV_PROP_RW int cycle;
|
||||
CV_PROP_RW int flags;
|
||||
CV_PROP_RW int levels;
|
||||
CV_PROP_RW double pyrScale;
|
||||
CV_PROP_RW int nIt;
|
||||
CV_PROP_RW int minDisp;
|
||||
CV_PROP_RW int maxDisp;
|
||||
CV_PROP_RW int poly_n;
|
||||
CV_PROP_RW double poly_sigma;
|
||||
CV_PROP_RW float fi;
|
||||
CV_PROP_RW float lambda;
|
||||
CV_PROP_RW int penalization;
|
||||
CV_PROP_RW int cycle;
|
||||
CV_PROP_RW int flags;
|
||||
|
||||
private:
|
||||
void autoParams();
|
||||
void FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level);
|
||||
void FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level);
|
||||
void VCycle_MyFAS(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level);
|
||||
void VariationalSolver(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level);
|
||||
};
|
||||
|
||||
CV_EXPORTS void polyfit(const Mat& srcx, const Mat& srcy, Mat& dst, int order);
|
||||
|
||||
class CV_EXPORTS Directory
|
||||
class CV_EXPORTS Directory
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> GetListFiles ( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
static std::vector<std::string> GetListFilesR ( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
static std::vector<std::string> GetListFolders( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
public:
|
||||
static std::vector<std::string> GetListFiles ( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
static std::vector<std::string> GetListFilesR ( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
static std::vector<std::string> GetListFolders( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -86,10 +86,10 @@ struct CV_EXPORTS CvMeanShiftTrackerParams
|
||||
struct CV_EXPORTS CvFeatureTrackerParams
|
||||
{
|
||||
enum { SIFT = 0, SURF = 1, OPTICAL_FLOW = 2 };
|
||||
CvFeatureTrackerParams(int feature_type = 0, int window_size = 0)
|
||||
CvFeatureTrackerParams(int featureType = 0, int windowSize = 0)
|
||||
{
|
||||
feature_type = 0;
|
||||
window_size = 0;
|
||||
featureType = 0;
|
||||
windowSize = 0;
|
||||
}
|
||||
|
||||
int feature_type; // Feature type to use
|
||||
|
@ -58,26 +58,26 @@ LevMarqSparse::~LevMarqSparse() {
|
||||
}
|
||||
|
||||
LevMarqSparse::LevMarqSparse(int npoints, // number of points
|
||||
int ncameras, // number of cameras
|
||||
int nPointParams, // number of params per one point (3 in case of 3D points)
|
||||
int nCameraParams, // number of parameters per one camera
|
||||
int nErrParams, // number of parameters in measurement vector
|
||||
// for 1 point at one camera (2 in case of 2D projections)
|
||||
Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras
|
||||
// 1 - point is visible for the camera, 0 - invisible
|
||||
Mat& P0, // starting vector of parameters, first cameras then points
|
||||
Mat& X_, // measurements, in order of visibility. non visible cases are skipped
|
||||
TermCriteria criteria, // termination criteria
|
||||
int ncameras, // number of cameras
|
||||
int nPointParams, // number of params per one point (3 in case of 3D points)
|
||||
int nCameraParams, // number of parameters per one camera
|
||||
int nErrParams, // number of parameters in measurement vector
|
||||
// for 1 point at one camera (2 in case of 2D projections)
|
||||
Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras
|
||||
// 1 - point is visible for the camera, 0 - invisible
|
||||
Mat& P0, // starting vector of parameters, first cameras then points
|
||||
Mat& X_, // measurements, in order of visibility. non visible cases are skipped
|
||||
TermCriteria _criteria, // termination criteria
|
||||
|
||||
// callback for estimation of Jacobian matrices
|
||||
void (CV_CDECL * fjac)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& A, Mat& B, void* data),
|
||||
// callback for estimation of backprojection errors
|
||||
void (CV_CDECL * func)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& estim, void* data),
|
||||
void* data, // user-specific data passed to the callbacks
|
||||
BundleAdjustCallback _cb, void* _user_data
|
||||
) {
|
||||
// callback for estimation of Jacobian matrices
|
||||
void (CV_CDECL * _fjac)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& A, Mat& B, void* data),
|
||||
// callback for estimation of backprojection errors
|
||||
void (CV_CDECL * _func)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& estim, void* data),
|
||||
void* _data, // user-specific data passed to the callbacks
|
||||
BundleAdjustCallback _cb, void* _user_data
|
||||
) {
|
||||
Vis_index = X = prevP = P = deltaP = err = JtJ_diag = S = hX = NULL;
|
||||
U = ea = V = inv_V_star = eb = Yj = NULL;
|
||||
A = B = W = NULL;
|
||||
@ -86,7 +86,7 @@ LevMarqSparse::LevMarqSparse(int npoints, // number of points
|
||||
user_data = _user_data;
|
||||
|
||||
run(npoints, ncameras, nPointParams, nCameraParams, nErrParams, visibility,
|
||||
P0, X_, criteria, fjac, func, data);
|
||||
P0, X_, _criteria, _fjac, _func, _data);
|
||||
}
|
||||
|
||||
void LevMarqSparse::clear() {
|
||||
@ -95,17 +95,17 @@ void LevMarqSparse::clear() {
|
||||
//CvMat* tmp = ((CvMat**)(A->data.ptr + i * A->step))[j];
|
||||
CvMat* tmp = A[j+i*num_cams];
|
||||
if (tmp)
|
||||
cvReleaseMat( &tmp );
|
||||
cvReleaseMat( &tmp );
|
||||
|
||||
//tmp = ((CvMat**)(B->data.ptr + i * B->step))[j];
|
||||
tmp = B[j+i*num_cams];
|
||||
if (tmp)
|
||||
cvReleaseMat( &tmp );
|
||||
cvReleaseMat( &tmp );
|
||||
|
||||
//tmp = ((CvMat**)(W->data.ptr + j * W->step))[i];
|
||||
tmp = W[j+i*num_cams];
|
||||
if (tmp)
|
||||
cvReleaseMat( &tmp );
|
||||
cvReleaseMat( &tmp );
|
||||
}
|
||||
}
|
||||
delete A; //cvReleaseMat(&A);
|
||||
@ -165,19 +165,19 @@ void LevMarqSparse::clear() {
|
||||
//num_errors - number of measurements.
|
||||
|
||||
void LevMarqSparse::run( int num_points_, //number of points
|
||||
int num_cams_, //number of cameras
|
||||
int num_point_param_, //number of params per one point (3 in case of 3D points)
|
||||
int num_cam_param_, //number of parameters per one camera
|
||||
int num_err_param_, //number of parameters in measurement vector for 1 point at one camera (2 in case of 2D projections)
|
||||
Mat& visibility, //visibility matrix . rows correspond to points, columns correspond to cameras
|
||||
// 0 - point is visible for the camera, 0 - invisible
|
||||
Mat& P0, //starting vector of parameters, first cameras then points
|
||||
Mat& X_init, //measurements, in order of visibility. non visible cases are skipped
|
||||
TermCriteria criteria_init,
|
||||
void (*fjac_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data),
|
||||
void (*func_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data),
|
||||
void* data_
|
||||
) { //termination criteria
|
||||
int num_cams_, //number of cameras
|
||||
int num_point_param_, //number of params per one point (3 in case of 3D points)
|
||||
int num_cam_param_, //number of parameters per one camera
|
||||
int num_err_param_, //number of parameters in measurement vector for 1 point at one camera (2 in case of 2D projections)
|
||||
Mat& visibility, //visibility matrix . rows correspond to points, columns correspond to cameras
|
||||
// 0 - point is visible for the camera, 0 - invisible
|
||||
Mat& P0, //starting vector of parameters, first cameras then points
|
||||
Mat& X_init, //measurements, in order of visibility. non visible cases are skipped
|
||||
TermCriteria criteria_init,
|
||||
void (*fjac_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data),
|
||||
void (*func_)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data),
|
||||
void* data_
|
||||
) { //termination criteria
|
||||
//clear();
|
||||
|
||||
func = func_; //assign evaluation function
|
||||
@ -228,28 +228,28 @@ void LevMarqSparse::run( int num_points_, //number of points
|
||||
for (int i = 0; i < num_points; i++ ) {
|
||||
for (int j = 0; j < num_cams; j++ ) {
|
||||
if (((int*)(_vis.data.ptr+ i * _vis.step))[j] ) {
|
||||
((int*)(Vis_index->data.ptr + i * Vis_index->step))[j] = index;
|
||||
index += num_err_param;
|
||||
((int*)(Vis_index->data.ptr + i * Vis_index->step))[j] = index;
|
||||
index += num_err_param;
|
||||
|
||||
//create matrices Aij, Bij
|
||||
CvMat* tmp = cvCreateMat(Aij_height, Aij_width, CV_64F );
|
||||
//((CvMat**)(A->data.ptr + i * A->step))[j] = tmp;
|
||||
cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0));
|
||||
A[j+i*num_cams] = tmp;
|
||||
//create matrices Aij, Bij
|
||||
CvMat* tmp = cvCreateMat(Aij_height, Aij_width, CV_64F );
|
||||
//((CvMat**)(A->data.ptr + i * A->step))[j] = tmp;
|
||||
cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0));
|
||||
A[j+i*num_cams] = tmp;
|
||||
|
||||
tmp = cvCreateMat( Bij_height, Bij_width, CV_64F );
|
||||
//((CvMat**)(B->data.ptr + i * B->step))[j] = tmp;
|
||||
cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0));
|
||||
B[j+i*num_cams] = tmp;
|
||||
tmp = cvCreateMat( Bij_height, Bij_width, CV_64F );
|
||||
//((CvMat**)(B->data.ptr + i * B->step))[j] = tmp;
|
||||
cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0));
|
||||
B[j+i*num_cams] = tmp;
|
||||
|
||||
tmp = cvCreateMat( Wij_height, Wij_width, CV_64F );
|
||||
//((CvMat**)(W->data.ptr + j * W->step))[i] = tmp; //note indices i and j swapped
|
||||
cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0));
|
||||
W[j+i*num_cams] = tmp;
|
||||
tmp = cvCreateMat( Wij_height, Wij_width, CV_64F );
|
||||
//((CvMat**)(W->data.ptr + j * W->step))[i] = tmp; //note indices i and j swapped
|
||||
cvSet(tmp,cvScalar(1.0,1.0,1.0,1.0));
|
||||
W[j+i*num_cams] = tmp;
|
||||
} else{
|
||||
A[j+i*num_cams] = NULL;
|
||||
B[j+i*num_cams] = NULL;
|
||||
W[j+i*num_cams] = NULL;
|
||||
A[j+i*num_cams] = NULL;
|
||||
B[j+i*num_cams] = NULL;
|
||||
W[j+i*num_cams] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -423,29 +423,31 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
cvSetZero(ea[j]);
|
||||
//summ by i (number of points)
|
||||
for (int i = 0; i < num_points; i++ ) {
|
||||
//get Aij
|
||||
//CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j];
|
||||
CvMat* Aij = A[j+i*num_cams];
|
||||
if (Aij ) {
|
||||
//Uj+= AijT*Aij
|
||||
cvGEMM( Aij, Aij, 1, U[j], 1, U[j], CV_GEMM_A_T );
|
||||
//ea_j += AijT * e_ij
|
||||
CvMat eij;
|
||||
//get Aij
|
||||
//CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j];
|
||||
CvMat* Aij = A[j+i*num_cams];
|
||||
if (Aij ) {
|
||||
//Uj+= AijT*Aij
|
||||
cvGEMM( Aij, Aij, 1, U[j], 1, U[j], CV_GEMM_A_T );
|
||||
//ea_j += AijT * e_ij
|
||||
CvMat eij;
|
||||
|
||||
int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j];
|
||||
int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j];
|
||||
|
||||
cvGetSubRect( err, &eij, cvRect( 0, index, 1, Aij->height ) ); //width of transposed Aij
|
||||
cvGEMM( Aij, &eij, 1, ea[j], 1, ea[j], CV_GEMM_A_T );
|
||||
}
|
||||
else
|
||||
invisible_count++;
|
||||
cvGetSubRect( err, &eij, cvRect( 0, index, 1, Aij->height ) ); //width of transposed Aij
|
||||
cvGEMM( Aij, &eij, 1, ea[j], 1, ea[j], CV_GEMM_A_T );
|
||||
}
|
||||
else
|
||||
invisible_count++;
|
||||
}
|
||||
} //U_j and ea_j computed for all j
|
||||
|
||||
// if (!(iters%100))
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = prevErrNorm*prevErrNorm, e2n = e2 / nviz;
|
||||
std::cerr<<"Iteration: "<<iters<<", normError: "<<e2<<" ("<<e2n<<")"<<std::endl;
|
||||
{
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = prevErrNorm*prevErrNorm, e2n = e2 / nviz;
|
||||
std::cerr<<"Iteration: "<<iters<<", normError: "<<e2<<" ("<<e2n<<")"<<std::endl;
|
||||
}
|
||||
if (cb)
|
||||
cb(iters, prevErrNorm, user_data);
|
||||
//compute V_i and eb_i
|
||||
@ -455,37 +457,37 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
|
||||
//summ by i (number of points)
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
//get Bij
|
||||
//CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j];
|
||||
CvMat* Bij = B[j+i*num_cams];
|
||||
if (Bij ) {
|
||||
//Vi+= BijT*Bij
|
||||
cvGEMM( Bij, Bij, 1, V[i], 1, V[i], CV_GEMM_A_T );
|
||||
//get Bij
|
||||
//CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j];
|
||||
CvMat* Bij = B[j+i*num_cams];
|
||||
if (Bij ) {
|
||||
//Vi+= BijT*Bij
|
||||
cvGEMM( Bij, Bij, 1, V[i], 1, V[i], CV_GEMM_A_T );
|
||||
|
||||
//eb_i += BijT * e_ij
|
||||
int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j];
|
||||
//eb_i += BijT * e_ij
|
||||
int index = ((int*)(Vis_index->data.ptr + i * Vis_index->step))[j];
|
||||
|
||||
CvMat eij;
|
||||
cvGetSubRect( err, &eij, cvRect( 0, index, 1, Bij->height ) ); //width of transposed Bij
|
||||
cvGEMM( Bij, &eij, 1, eb[i], 1, eb[i], CV_GEMM_A_T );
|
||||
}
|
||||
CvMat eij;
|
||||
cvGetSubRect( err, &eij, cvRect( 0, index, 1, Bij->height ) ); //width of transposed Bij
|
||||
cvGEMM( Bij, &eij, 1, eb[i], 1, eb[i], CV_GEMM_A_T );
|
||||
}
|
||||
}
|
||||
} //V_i and eb_i computed for all i
|
||||
|
||||
//compute W_ij
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
//CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j];
|
||||
CvMat* Aij = A[j+i*num_cams];
|
||||
if( Aij ) { //visible
|
||||
//CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j];
|
||||
CvMat* Bij = B[j+i*num_cams];
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
//CvMat* Aij = ((CvMat**)(A->data.ptr + A->step * i))[j];
|
||||
CvMat* Aij = A[j+i*num_cams];
|
||||
if( Aij ) { //visible
|
||||
//CvMat* Bij = ((CvMat**)(B->data.ptr + B->step * i))[j];
|
||||
CvMat* Bij = B[j+i*num_cams];
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
|
||||
//multiply
|
||||
cvGEMM( Aij, Bij, 1, NULL, 0, Wij, CV_GEMM_A_T );
|
||||
}
|
||||
//multiply
|
||||
cvGEMM( Aij, Bij, 1, NULL, 0, Wij, CV_GEMM_A_T );
|
||||
}
|
||||
}
|
||||
} //Wij computed
|
||||
|
||||
@ -494,16 +496,16 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
CvMat dia;
|
||||
CvMat subr;
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
cvGetDiag(U[j], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, j*num_cam_param, 1, num_cam_param ));
|
||||
cvCopy( &dia, &subr );
|
||||
cvGetDiag(U[j], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, j*num_cam_param, 1, num_cam_param ));
|
||||
cvCopy( &dia, &subr );
|
||||
}
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
cvGetDiag(V[i], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, num_cams*num_cam_param + i * num_point_param, 1, num_point_param ));
|
||||
cvCopy( &dia, &subr );
|
||||
cvGetDiag(V[i], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, num_cams*num_cam_param + i * num_point_param, 1, num_point_param ));
|
||||
cvCopy( &dia, &subr );
|
||||
}
|
||||
}
|
||||
|
||||
@ -511,10 +513,10 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
//initialize lambda. It is set to 1e-3 * average diagonal element in JtJ
|
||||
double average_diag = 0;
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
average_diag += cvTrace( U[j] ).val[0];
|
||||
average_diag += cvTrace( U[j] ).val[0];
|
||||
}
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
average_diag += cvTrace( V[i] ).val[0];
|
||||
average_diag += cvTrace( V[i] ).val[0];
|
||||
}
|
||||
average_diag /= (num_cams*num_cam_param + num_points * num_point_param );
|
||||
|
||||
@ -527,187 +529,189 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
for(;;) {
|
||||
//augmentation of diagonal
|
||||
for(int j = 0; j < num_cams; j++ ) {
|
||||
CvMat diag;
|
||||
cvGetDiag( U[j], &diag );
|
||||
CvMat diag;
|
||||
cvGetDiag( U[j], &diag );
|
||||
#if 1
|
||||
cvAddS( &diag, cvScalar( lambda ), &diag );
|
||||
cvAddS( &diag, cvScalar( lambda ), &diag );
|
||||
#else
|
||||
cvScale( &diag, &diag, 1 + lambda );
|
||||
cvScale( &diag, &diag, 1 + lambda );
|
||||
#endif
|
||||
}
|
||||
for(int i = 0; i < num_points; i++ ) {
|
||||
CvMat diag;
|
||||
cvGetDiag( V[i], &diag );
|
||||
CvMat diag;
|
||||
cvGetDiag( V[i], &diag );
|
||||
#if 1
|
||||
cvAddS( &diag, cvScalar( lambda ), &diag );
|
||||
cvAddS( &diag, cvScalar( lambda ), &diag );
|
||||
#else
|
||||
cvScale( &diag, &diag, 1 + lambda );
|
||||
cvScale( &diag, &diag, 1 + lambda );
|
||||
#endif
|
||||
}
|
||||
bool error = false;
|
||||
//compute inv(V*)
|
||||
bool inverted_ok = true;
|
||||
for(int i = 0; i < num_points; i++ ) {
|
||||
double det = cvInvert( V[i], inv_V_star[i] );
|
||||
double det = cvInvert( V[i], inv_V_star[i] );
|
||||
|
||||
if( fabs(det) <= FLT_EPSILON ) {
|
||||
inverted_ok = false;
|
||||
std::cerr<<"V["<<i<<"] failed"<<std::endl;
|
||||
break;
|
||||
} //means we did wrong augmentation, try to choose different lambda
|
||||
if( fabs(det) <= FLT_EPSILON ) {
|
||||
inverted_ok = false;
|
||||
std::cerr<<"V["<<i<<"] failed"<<std::endl;
|
||||
break;
|
||||
} //means we did wrong augmentation, try to choose different lambda
|
||||
}
|
||||
|
||||
if( inverted_ok ) {
|
||||
cvSetZero( E );
|
||||
//loop through cameras, compute upper diagonal blocks of matrix S
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
//compute Yij = Wij (V*_i)^-1 for all i (if Wij exists/nonzero)
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
//
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
if( Wij ) {
|
||||
cvMatMul( Wij, inv_V_star[i], Yj[i] );
|
||||
}
|
||||
}
|
||||
cvSetZero( E );
|
||||
//loop through cameras, compute upper diagonal blocks of matrix S
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
//compute Yij = Wij (V*_i)^-1 for all i (if Wij exists/nonzero)
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
//
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
if( Wij ) {
|
||||
cvMatMul( Wij, inv_V_star[i], Yj[i] );
|
||||
}
|
||||
}
|
||||
|
||||
//compute Sjk for k>=j (because Sjk = Skj)
|
||||
for( int k = j; k < num_cams; k++ ) {
|
||||
cvSetZero( YWt );
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
//check that both Wij and Wik exist
|
||||
// CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
//CvMat* Wik = ((CvMat**)(W->data.ptr + W->step * k))[i];
|
||||
CvMat* Wik = W[k+i*num_cams];
|
||||
//compute Sjk for k>=j (because Sjk = Skj)
|
||||
for( int k = j; k < num_cams; k++ ) {
|
||||
cvSetZero( YWt );
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
//check that both Wij and Wik exist
|
||||
// CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
//CvMat* Wik = ((CvMat**)(W->data.ptr + W->step * k))[i];
|
||||
CvMat* Wik = W[k+i*num_cams];
|
||||
|
||||
if( Wij && Wik ) {
|
||||
//multiply YWt += Yj[i]*Wik'
|
||||
cvGEMM( Yj[i], Wik, 1, YWt, 1, YWt, CV_GEMM_B_T ); ///*transpose Wik
|
||||
}
|
||||
}
|
||||
if( Wij && Wik ) {
|
||||
//multiply YWt += Yj[i]*Wik'
|
||||
cvGEMM( Yj[i], Wik, 1, YWt, 1, YWt, CV_GEMM_B_T ); ///*transpose Wik
|
||||
}
|
||||
}
|
||||
|
||||
//copy result to matrix S
|
||||
//copy result to matrix S
|
||||
|
||||
CvMat Sjk;
|
||||
//extract submat
|
||||
cvGetSubRect( S, &Sjk, cvRect( k * num_cam_param, j * num_cam_param, num_cam_param, num_cam_param ));
|
||||
CvMat Sjk;
|
||||
//extract submat
|
||||
cvGetSubRect( S, &Sjk, cvRect( k * num_cam_param, j * num_cam_param, num_cam_param, num_cam_param ));
|
||||
|
||||
|
||||
//if j==k, add diagonal
|
||||
if( j != k ) {
|
||||
//just copy with minus
|
||||
cvScale( YWt, &Sjk, -1 ); //if we set initial S to zero then we can use cvSub( Sjk, YWt, Sjk);
|
||||
} else {
|
||||
//add diagonal value
|
||||
|
||||
//subtract YWt from augmented Uj
|
||||
cvSub( U[j], YWt, &Sjk );
|
||||
}
|
||||
}
|
||||
|
||||
//compute right part of equation involving matrix S
|
||||
// e_j=ea_j - \sum_i Y_ij eb_i
|
||||
{
|
||||
CvMat e_j;
|
||||
|
||||
//select submat
|
||||
cvGetSubRect( E, &e_j, cvRect( 0, j * num_cam_param, 1, num_cam_param ) );
|
||||
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
if( Wij )
|
||||
cvMatMulAdd( Yj[i], eb[i], &e_j, &e_j );
|
||||
}
|
||||
|
||||
cvSub( ea[j], &e_j, &e_j );
|
||||
}
|
||||
|
||||
}
|
||||
//fill below diagonal elements of matrix S
|
||||
cvCompleteSymm( S, 0 ); ///*from upper to low //operation may be done by nonzero blocks or during upper diagonal computation
|
||||
|
||||
//Solve linear system S * deltaP_a = E
|
||||
CvMat dpa;
|
||||
cvGetSubRect( deltaP, &dpa, cvRect(0, 0, 1, S->width ) );
|
||||
int res = cvSolve( S, E, &dpa, CV_CHOLESKY );
|
||||
|
||||
if( res ) { //system solved ok
|
||||
//compute db_i
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
CvMat dbi;
|
||||
cvGetSubRect( deltaP, &dbi, cvRect( 0, dpa.height + i * num_point_param, 1, num_point_param ) );
|
||||
|
||||
// compute \sum_j W_ij^T da_j
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
//get Wij
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
if( Wij ) {
|
||||
//get da_j
|
||||
CvMat daj;
|
||||
cvGetSubRect( &dpa, &daj, cvRect( 0, j * num_cam_param, 1, num_cam_param ));
|
||||
cvGEMM( Wij, &daj, 1, &dbi, 1, &dbi, CV_GEMM_A_T ); ///* transpose Wij
|
||||
}
|
||||
}
|
||||
//finalize dbi
|
||||
cvSub( eb[i], &dbi, &dbi );
|
||||
cvMatMul(inv_V_star[i], &dbi, &dbi ); //here we get final dbi
|
||||
} //now we computed whole deltaP
|
||||
|
||||
//add deltaP to delta
|
||||
cvAdd( prevP, deltaP, P );
|
||||
|
||||
//evaluate function with new parameters
|
||||
ask_for_proj(_vis); // func( P, hX );
|
||||
|
||||
//compute error
|
||||
errNorm = cvNorm( X, hX, CV_L2 );
|
||||
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
//if j==k, add diagonal
|
||||
if( j != k ) {
|
||||
//just copy with minus
|
||||
cvScale( YWt, &Sjk, -1 ); //if we set initial S to zero then we can use cvSub( Sjk, YWt, Sjk);
|
||||
} else {
|
||||
error = true;
|
||||
//add diagonal value
|
||||
|
||||
//subtract YWt from augmented Uj
|
||||
cvSub( U[j], YWt, &Sjk );
|
||||
}
|
||||
}
|
||||
|
||||
//compute right part of equation involving matrix S
|
||||
// e_j=ea_j - \sum_i Y_ij eb_i
|
||||
{
|
||||
CvMat e_j;
|
||||
|
||||
//select submat
|
||||
cvGetSubRect( E, &e_j, cvRect( 0, j * num_cam_param, 1, num_cam_param ) );
|
||||
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
if( Wij )
|
||||
cvMatMulAdd( Yj[i], eb[i], &e_j, &e_j );
|
||||
}
|
||||
|
||||
cvSub( ea[j], &e_j, &e_j );
|
||||
}
|
||||
|
||||
}
|
||||
//fill below diagonal elements of matrix S
|
||||
cvCompleteSymm( S, 0 ); ///*from upper to low //operation may be done by nonzero blocks or during upper diagonal computation
|
||||
|
||||
//Solve linear system S * deltaP_a = E
|
||||
CvMat dpa;
|
||||
cvGetSubRect( deltaP, &dpa, cvRect(0, 0, 1, S->width ) );
|
||||
int res = cvSolve( S, E, &dpa, CV_CHOLESKY );
|
||||
|
||||
if( res ) { //system solved ok
|
||||
//compute db_i
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
CvMat dbi;
|
||||
cvGetSubRect( deltaP, &dbi, cvRect( 0, dpa.height + i * num_point_param, 1, num_point_param ) );
|
||||
|
||||
// compute \sum_j W_ij^T da_j
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
//get Wij
|
||||
//CvMat* Wij = ((CvMat**)(W->data.ptr + W->step * j))[i];
|
||||
CvMat* Wij = W[j+i*num_cams];
|
||||
if( Wij ) {
|
||||
//get da_j
|
||||
CvMat daj;
|
||||
cvGetSubRect( &dpa, &daj, cvRect( 0, j * num_cam_param, 1, num_cam_param ));
|
||||
cvGEMM( Wij, &daj, 1, &dbi, 1, &dbi, CV_GEMM_A_T ); ///* transpose Wij
|
||||
}
|
||||
}
|
||||
//finalize dbi
|
||||
cvSub( eb[i], &dbi, &dbi );
|
||||
cvMatMul(inv_V_star[i], &dbi, &dbi ); //here we get final dbi
|
||||
} //now we computed whole deltaP
|
||||
|
||||
//add deltaP to delta
|
||||
cvAdd( prevP, deltaP, P );
|
||||
|
||||
//evaluate function with new parameters
|
||||
ask_for_proj(_vis); // func( P, hX );
|
||||
|
||||
//compute error
|
||||
errNorm = cvNorm( X, hX, CV_L2 );
|
||||
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
} else {
|
||||
error = true;
|
||||
}
|
||||
//check solution
|
||||
if( error || ///* singularities somewhere
|
||||
errNorm > prevErrNorm ) { //step was not accepted
|
||||
//increase lambda and reject change
|
||||
lambda *= 10;
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = errNorm*errNorm, e2_prev = prevErrNorm*prevErrNorm;
|
||||
double e2n = e2/nviz, e2n_prev = e2_prev/nviz;
|
||||
std::cerr<<"move failed: lambda = "<<lambda<<", e2 = "<<e2<<" ("<<e2n<<") > "<<e2_prev<<" ("<<e2n_prev<<")"<<std::endl;
|
||||
errNorm > prevErrNorm ) { //step was not accepted
|
||||
//increase lambda and reject change
|
||||
lambda *= 10;
|
||||
{
|
||||
int nviz = X->rows / num_err_param;
|
||||
double e2 = errNorm*errNorm, e2_prev = prevErrNorm*prevErrNorm;
|
||||
double e2n = e2/nviz, e2n_prev = e2_prev/nviz;
|
||||
std::cerr<<"move failed: lambda = "<<lambda<<", e2 = "<<e2<<" ("<<e2n<<") > "<<e2_prev<<" ("<<e2n_prev<<")"<<std::endl;
|
||||
}
|
||||
|
||||
//restore diagonal from backup
|
||||
{
|
||||
CvMat dia;
|
||||
CvMat subr;
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
cvGetDiag(U[j], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, j*num_cam_param, 1, num_cam_param ));
|
||||
cvCopy( &subr, &dia );
|
||||
}
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
cvGetDiag(V[i], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, num_cams*num_cam_param + i * num_point_param, 1, num_point_param ));
|
||||
cvCopy( &subr, &dia );
|
||||
}
|
||||
}
|
||||
//restore diagonal from backup
|
||||
{
|
||||
CvMat dia;
|
||||
CvMat subr;
|
||||
for( int j = 0; j < num_cams; j++ ) {
|
||||
cvGetDiag(U[j], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, j*num_cam_param, 1, num_cam_param ));
|
||||
cvCopy( &subr, &dia );
|
||||
}
|
||||
for( int i = 0; i < num_points; i++ ) {
|
||||
cvGetDiag(V[i], &dia);
|
||||
cvGetSubRect(JtJ_diag, &subr,
|
||||
cvRect(0, num_cams*num_cam_param + i * num_point_param, 1, num_point_param ));
|
||||
cvCopy( &subr, &dia );
|
||||
}
|
||||
}
|
||||
} else { //all is ok
|
||||
//accept change and decrease lambda
|
||||
lambda /= 10;
|
||||
lambda = MAX(lambda, 1e-16);
|
||||
std::cerr<<"decreasing lambda to "<<lambda<<std::endl;
|
||||
prevErrNorm = errNorm;
|
||||
//accept change and decrease lambda
|
||||
lambda /= 10;
|
||||
lambda = MAX(lambda, 1e-16);
|
||||
std::cerr<<"decreasing lambda to "<<lambda<<std::endl;
|
||||
prevErrNorm = errNorm;
|
||||
|
||||
//compute new projection error vector
|
||||
cvSub( X, hX, err );
|
||||
break;
|
||||
//compute new projection error vector
|
||||
cvSub( X, hX, err );
|
||||
break;
|
||||
}
|
||||
}
|
||||
iters++;
|
||||
@ -715,7 +719,7 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
double param_change_norm = cvNorm(P, prevP, CV_RELATIVE_L2);
|
||||
//check termination criteria
|
||||
if( (criteria.type&CV_TERMCRIT_ITER && iters > criteria.max_iter ) ||
|
||||
(criteria.type&CV_TERMCRIT_EPS && param_change_norm < criteria.epsilon) ) {
|
||||
(criteria.type&CV_TERMCRIT_EPS && param_change_norm < criteria.epsilon) ) {
|
||||
// std::cerr<<"relative norm change "<<param_change_norm<<" lower than eps "<<criteria.epsilon<<", stopping"<<std::endl;
|
||||
done = true;
|
||||
break;
|
||||
@ -730,7 +734,7 @@ void LevMarqSparse::optimize(CvMat &_vis) { //main function that runs minimizati
|
||||
|
||||
//Utilities
|
||||
|
||||
void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A, CvMat* B, void* /*data*/) {
|
||||
static void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A, CvMat* B, void* /*data*/) {
|
||||
//compute jacobian per camera parameters (i.e. Aij)
|
||||
//take i-th point 3D current coordinates
|
||||
|
||||
@ -766,7 +770,7 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A
|
||||
cvGetCols( A, &_dpdk, 10, A->width );
|
||||
}
|
||||
cvProjectPoints2(&_Mi, &_ri, &_ti, &_A, have_dk ? &_k : NULL, _mp, &_dpdr, &_dpdt,
|
||||
&_dpdf, &_dpdc, have_dk ? &_dpdk : NULL, 0);
|
||||
&_dpdf, &_dpdc, have_dk ? &_dpdk : NULL, 0);
|
||||
|
||||
cvReleaseMat( &_mp );
|
||||
|
||||
@ -843,7 +847,7 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A
|
||||
// dy'/dX dy'/dY dy'/dZ
|
||||
|
||||
double coeff[6] = { z, 0, -x,
|
||||
0, z, -y };
|
||||
0, z, -y };
|
||||
CvMat coeffmat = cvMat( 2, 3, CV_64F, coeff );
|
||||
|
||||
CvMat* dstrike_dbig = cvCreateMat(2,3,CV_64F);
|
||||
@ -884,11 +888,11 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A
|
||||
CvMat* dstrike2_dbig = cvCreateMat( 2, 3, CV_64F );
|
||||
|
||||
double c[4] = { g+2*p1*y_strike+4*p2*x_strike, 2*p1*x_strike,
|
||||
2*p2*y_strike, g+2*p2*x_strike + 4*p1*y_strike };
|
||||
2*p2*y_strike, g+2*p2*x_strike + 4*p1*y_strike };
|
||||
|
||||
CvMat coeffmat = cvMat(2,2,CV_64F, c );
|
||||
CvMat coeffmat2 = cvMat(2,2,CV_64F, c );
|
||||
|
||||
cvMatMul(&coeffmat, dstrike_dbig, dstrike2_dbig );
|
||||
cvMatMul(&coeffmat2, dstrike_dbig, dstrike2_dbig );
|
||||
|
||||
cvGEMM( &strike, dg_dbig, 1, NULL, 0, tmp, CV_GEMM_A_T );
|
||||
cvAdd( dstrike2_dbig, tmp, dstrike2_dbig );
|
||||
@ -935,7 +939,7 @@ void fjac(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* A
|
||||
#endif
|
||||
|
||||
};
|
||||
void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* estim, void* /*data*/) {
|
||||
static void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* estim, void* /*data*/) {
|
||||
//just do projections
|
||||
CvMat _Mi;
|
||||
cvReshape( point_params, &_Mi, 3, 1 );
|
||||
@ -965,7 +969,7 @@ void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* e
|
||||
cvGetRows( cam_params, &_k, 10, cam_params->height );
|
||||
}
|
||||
cvProjectPoints2( &_Mi, &_ri, &_ti, &_A, have_dk ? &_k : NULL, _mp, NULL, NULL,
|
||||
NULL, NULL, NULL, 0);
|
||||
NULL, NULL, NULL, 0);
|
||||
// std::cerr<<"_mp = "<<_mp->data.db[0]<<","<<_mp->data.db[1]<<std::endl;
|
||||
//
|
||||
_mp2->data.db[0] = _mp->data.db[0];
|
||||
@ -975,34 +979,34 @@ void func(int /*i*/, int /*j*/, CvMat *point_params, CvMat* cam_params, CvMat* e
|
||||
cvReleaseMat( &_mp2 );
|
||||
};
|
||||
|
||||
void fjac_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data) {
|
||||
static void fjac_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data) {
|
||||
CvMat _point_params = point_params, _cam_params = cam_params, _Al = A, _Bl = B;
|
||||
fjac(i,j, &_point_params, &_cam_params, &_Al, &_Bl, data);
|
||||
};
|
||||
|
||||
void func_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data) {
|
||||
static void func_new(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data) {
|
||||
CvMat _point_params = point_params, _cam_params = cam_params, _estim = estim;
|
||||
func(i,j,&_point_params,&_cam_params,&_estim,data);
|
||||
};
|
||||
|
||||
void LevMarqSparse::bundleAdjust( vector<Point3d>& points, //positions of points in global coordinate system (input and output)
|
||||
const vector<vector<Point2d> >& imagePoints, //projections of 3d points for every camera
|
||||
const vector<vector<int> >& visibility, //visibility of 3d points for every camera
|
||||
vector<Mat>& cameraMatrix, //intrinsic matrices of all cameras (input and output)
|
||||
vector<Mat>& R, //rotation matrices of all cameras (input and output)
|
||||
vector<Mat>& T, //translation vector of all cameras (input and output)
|
||||
vector<Mat>& distCoeffs, //distortion coefficients of all cameras (input and output)
|
||||
const TermCriteria& criteria,
|
||||
BundleAdjustCallback cb, void* user_data) {
|
||||
const vector<vector<Point2d> >& imagePoints, //projections of 3d points for every camera
|
||||
const vector<vector<int> >& visibility, //visibility of 3d points for every camera
|
||||
vector<Mat>& cameraMatrix, //intrinsic matrices of all cameras (input and output)
|
||||
vector<Mat>& R, //rotation matrices of all cameras (input and output)
|
||||
vector<Mat>& T, //translation vector of all cameras (input and output)
|
||||
vector<Mat>& distCoeffs, //distortion coefficients of all cameras (input and output)
|
||||
const TermCriteria& criteria,
|
||||
BundleAdjustCallback cb, void* user_data) {
|
||||
//,enum{MOTION_AND_STRUCTURE,MOTION,STRUCTURE})
|
||||
int num_points = (int)points.size();
|
||||
int num_cameras = (int)cameraMatrix.size();
|
||||
|
||||
CV_Assert( imagePoints.size() == (size_t)num_cameras &&
|
||||
visibility.size() == (size_t)num_cameras &&
|
||||
R.size() == (size_t)num_cameras &&
|
||||
T.size() == (size_t)num_cameras &&
|
||||
(distCoeffs.size() == (size_t)num_cameras || distCoeffs.size() == 0) );
|
||||
visibility.size() == (size_t)num_cameras &&
|
||||
R.size() == (size_t)num_cameras &&
|
||||
T.size() == (size_t)num_cameras &&
|
||||
(distCoeffs.size() == (size_t)num_cameras || distCoeffs.size() == 0) );
|
||||
|
||||
int numdist = distCoeffs.size() ? (distCoeffs[0].rows * distCoeffs[0].cols) : 0;
|
||||
|
||||
@ -1066,19 +1070,19 @@ void LevMarqSparse::bundleAdjust( vector<Point3d>& points, //positions of points
|
||||
for(int j = 0; j < num_cameras; j++ ) {
|
||||
//check visibility
|
||||
if( visibility[j][i] ) {
|
||||
//extract point and put tu vector
|
||||
Point2d p = imagePoints[j][i];
|
||||
((double*)(X.data))[counter] = p.x;
|
||||
((double*)(X.data))[counter+1] = p.y;
|
||||
assert(p.x != -1 || p.y != -1);
|
||||
counter+=2;
|
||||
//extract point and put tu vector
|
||||
Point2d p = imagePoints[j][i];
|
||||
((double*)(X.data))[counter] = p.x;
|
||||
((double*)(X.data))[counter+1] = p.y;
|
||||
assert(p.x != -1 || p.y != -1);
|
||||
counter+=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LevMarqSparse levmar( num_points, num_cameras, num_point_param, num_cam_param, 2, vismat, params, X,
|
||||
TermCriteria(criteria), fjac_new, func_new, NULL,
|
||||
cb, user_data);
|
||||
TermCriteria(criteria), fjac_new, func_new, NULL,
|
||||
cb, user_data);
|
||||
//extract results
|
||||
//fill point params
|
||||
/*Mat final_points(num_points, 1, CV_64FC3,
|
||||
|
@ -180,13 +180,13 @@ void BasicRetinaFilter::setLPfilterParameters(const float beta, const float tau,
|
||||
}
|
||||
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float _a = _filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[1+tableOffset]=(1.0f-_a)*(1.0f-_a)*(1.0f-_a)*(1.0f-_a)/(1.0f+_beta);
|
||||
float a = _filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[1+tableOffset]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[2+tableOffset] =tau;
|
||||
|
||||
//std::cout<<"BasicRetinaFilter::normal:"<<(1.0-_a)*(1.0-_a)*(1.0-_a)*(1.0-_a)/(1.0+_beta)<<" -> old:"<<(1-_a)*(1-_a)*(1-_a)*(1-_a)/(1+_beta)<<std::endl;
|
||||
//std::cout<<"BasicRetinaFilter::normal:"<<(1.0-a)*(1.0-a)*(1.0-a)*(1.0-a)/(1.0+_beta)<<" -> old:"<<(1-a)*(1-a)*(1-a)*(1-a)/(1+_beta)<<std::endl;
|
||||
|
||||
//std::cout<<"BasicRetinaFilter::_a="<<_a<<", gain="<<_filteringCoeficientsTable[1+tableOffset]<<", tau="<<tau<<std::endl;
|
||||
//std::cout<<"BasicRetinaFilter::a="<<a<<", gain="<<_filteringCoeficientsTable[1+tableOffset]<<", tau="<<tau<<std::endl;
|
||||
}
|
||||
|
||||
void BasicRetinaFilter::setProgressiveFilterConstants_CentredAccuracy(const float beta, const float tau, const float alpha0, const unsigned int filterIndex)
|
||||
@ -210,8 +210,8 @@ void BasicRetinaFilter::setProgressiveFilterConstants_CentredAccuracy(const floa
|
||||
|
||||
float _alpha=0.8f;
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float _a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-_a)*(1.0f-_a)*(1.0f-_a)*(1.0f-_a)/(1.0f+_beta);
|
||||
float a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[tableOffset+2] =tau;
|
||||
|
||||
float commonFactor=alpha0/(float)sqrt(_halfNBcolumns*_halfNBcolumns+_halfNBrows*_halfNBrows+1.0f);
|
||||
@ -266,8 +266,8 @@ void BasicRetinaFilter::setProgressiveFilterConstants_CustomAccuracy(const float
|
||||
}
|
||||
unsigned int tableOffset=filterIndex*3;
|
||||
float _temp = (1.0f+_beta)/(2.0f*_mu*_alpha);
|
||||
float _a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-_a)*(1.0f-_a)*(1.0f-_a)*(1.0f-_a)/(1.0f+_beta);
|
||||
float a=_filteringCoeficientsTable[tableOffset] = 1.0f + _temp - (float)sqrt( (1.0f+_temp)*(1.0f+_temp) - 1.0f);
|
||||
_filteringCoeficientsTable[tableOffset+1]=(1.0f-a)*(1.0f-a)*(1.0f-a)*(1.0f-a)/(1.0f+_beta);
|
||||
_filteringCoeficientsTable[tableOffset+2] =tau;
|
||||
|
||||
//memset(_progressiveSpatialConstant, 255, _filterOutput.getNBpixels());
|
||||
@ -335,7 +335,7 @@ void BasicRetinaFilter::_localLuminanceAdaptation(const float *inputFrame, const
|
||||
{
|
||||
float X0=*(localLuminancePTR++)*_localLuminanceFactor+_localLuminanceAddon;
|
||||
// TODO : the following line can lead to a divide by zero ! A small offset is added, take care if the offset is too large in case of High Dynamic Range images which can use very small values...
|
||||
*(outputFramePTR++) = (_maxInputValue+X0)**inputFramePTR/(*inputFramePTR +X0+0.00000000001);
|
||||
*(outputFramePTR++) = (_maxInputValue+X0)**inputFramePTR/(*inputFramePTR +X0+0.00000000001f);
|
||||
//std::cout<<"BasicRetinaFilter::inputFrame[IDpixel]=%f, X0=%f, outputFrame[IDpixel]=%f\n", inputFrame[IDpixel], X0, outputFrame[IDpixel]);
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,7 @@ private:
|
||||
{
|
||||
public:
|
||||
virtual ImageIterator* iterator() const = 0;
|
||||
virtual ~ImageRange() {}
|
||||
};
|
||||
|
||||
// Sliding window
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "precomp.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1400
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( disable: 4305 )
|
||||
#endif
|
||||
|
||||
@ -60,7 +60,7 @@ static Mat sortMatrixRowsByIndices(InputArray src, InputArray indices)
|
||||
}
|
||||
|
||||
|
||||
Mat argsort(InputArray _src, bool ascending=true)
|
||||
static Mat argsort(InputArray _src, bool ascending=true)
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
if (src.rows != 1 && src.cols != 1)
|
||||
|
@ -68,10 +68,10 @@ void CvMeanShiftTracker::newTrackingWindow(Mat image, Rect selection)
|
||||
mixChannels(&hsv, 1, &hue, 1, channels, 2);
|
||||
|
||||
Mat roi(hue, selection);
|
||||
Mat maskroi(mask, selection);
|
||||
Mat mskroi(mask, selection);
|
||||
int ch[] = {0, 1};
|
||||
int chsize[] = {32, 32};
|
||||
calcHist(&roi, 1, ch, maskroi, hist, 1, chsize, ranges);
|
||||
calcHist(&roi, 1, ch, mskroi, hist, 1, chsize, ranges);
|
||||
normalize(hist, hist, 0, 255, CV_MINMAX);
|
||||
|
||||
prev_trackwindow = selection;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#define DEBUGLOGS 1
|
||||
|
||||
#if ANDROID
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "OBJECT_DETECTOR"
|
||||
#define LOGD0(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
|
||||
|
@ -100,15 +100,15 @@ public:
|
||||
using FaceRecognizer::load;
|
||||
|
||||
// Initializes an empty Eigenfaces model.
|
||||
Eigenfaces(int num_components = 0) :
|
||||
_num_components(num_components) { }
|
||||
Eigenfaces(int numComponents = 0) :
|
||||
_num_components(numComponents) { }
|
||||
|
||||
// Initializes and computes an Eigenfaces model with images in src and
|
||||
// corresponding labels in labels. num_components will be kept for
|
||||
// classification.
|
||||
Eigenfaces(InputArray src, InputArray labels,
|
||||
int num_components = 0) :
|
||||
_num_components(num_components) {
|
||||
int numComponents = 0) :
|
||||
_num_components(numComponents) {
|
||||
train(src, labels);
|
||||
}
|
||||
|
||||
@ -157,16 +157,16 @@ public:
|
||||
using FaceRecognizer::load;
|
||||
|
||||
// Initializes an empty Fisherfaces model.
|
||||
Fisherfaces(int num_components = 0) :
|
||||
_num_components(num_components) {}
|
||||
Fisherfaces(int numComponents = 0) :
|
||||
_num_components(numComponents) {}
|
||||
|
||||
// Initializes and computes a Fisherfaces model with images in src and
|
||||
// corresponding labels in labels. num_components will be kept for
|
||||
// classification.
|
||||
Fisherfaces(InputArray src,
|
||||
InputArray labels,
|
||||
int num_components = 0) :
|
||||
_num_components(num_components) {
|
||||
int numComponents = 0) :
|
||||
_num_components(numComponents) {
|
||||
train(src, labels);
|
||||
}
|
||||
|
||||
@ -228,11 +228,11 @@ public:
|
||||
//
|
||||
// radius, neighbors are used in the local binary patterns creation.
|
||||
// grid_x, grid_y control the grid size of the spatial histograms.
|
||||
LBPH(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8) :
|
||||
_grid_x(grid_x),
|
||||
_grid_y(grid_y),
|
||||
_radius(radius),
|
||||
_neighbors(neighbors) {}
|
||||
LBPH(int radius_=1, int neighbors_=8, int grid_x_=8, int grid_y_=8) :
|
||||
_grid_x(grid_x_),
|
||||
_grid_y(grid_y_),
|
||||
_radius(radius_),
|
||||
_neighbors(neighbors_) {}
|
||||
|
||||
// Initializes and computes this LBPH Model. The current implementation is
|
||||
// rather fixed as it uses the Extended Local Binary Patterns per default.
|
||||
@ -241,12 +241,12 @@ public:
|
||||
// (grid_x=8), (grid_y=8) controls the grid size of the spatial histograms.
|
||||
LBPH(InputArray src,
|
||||
InputArray labels,
|
||||
int radius=1, int neighbors=8,
|
||||
int grid_x=8, int grid_y=8) :
|
||||
_grid_x(grid_x),
|
||||
_grid_y(grid_y),
|
||||
_radius(radius),
|
||||
_neighbors(neighbors) {
|
||||
int radius_=1, int neighbors_=8,
|
||||
int grid_x_=8, int grid_y_=8) :
|
||||
_grid_x(grid_x_),
|
||||
_grid_y(grid_y_),
|
||||
_radius(radius_),
|
||||
_neighbors(neighbors_) {
|
||||
train(src, labels);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
using namespace cv;
|
||||
|
||||
void downsamplePoints( const Mat& src, Mat& dst, size_t count )
|
||||
static void downsamplePoints( const Mat& src, Mat& dst, size_t count )
|
||||
{
|
||||
CV_Assert( count >= 2 );
|
||||
CV_Assert( src.cols == 1 || src.rows == 1 );
|
||||
|
@ -46,36 +46,54 @@ inline vector<_Tp> remove_dups(const vector<_Tp>& src) {
|
||||
static Mat argsort(InputArray _src, bool ascending=true)
|
||||
{
|
||||
Mat src = _src.getMat();
|
||||
if (src.rows != 1 && src.cols != 1)
|
||||
CV_Error(CV_StsBadArg, "cv::argsort only sorts 1D matrices.");
|
||||
if (src.rows != 1 && src.cols != 1) {
|
||||
string error_message = "Wrong shape of input matrix! Expected a matrix with one row or column.";
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
int flags = CV_SORT_EVERY_ROW+(ascending ? CV_SORT_ASCENDING : CV_SORT_DESCENDING);
|
||||
Mat sorted_indices;
|
||||
sortIdx(src.reshape(1,1),sorted_indices,flags);
|
||||
return sorted_indices;
|
||||
}
|
||||
|
||||
static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double beta=0)
|
||||
{
|
||||
static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double beta=0) {
|
||||
// make sure the input data is a vector of matrices or vector of vector
|
||||
if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) {
|
||||
string error_message = "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).";
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// number of samples
|
||||
int n = (int) src.total();
|
||||
// return empty matrix if no data given
|
||||
size_t n = src.total();
|
||||
// return empty matrix if no matrices given
|
||||
if(n == 0)
|
||||
return Mat();
|
||||
// dimensionality of samples
|
||||
int d = (int)src.getMat(0).total();
|
||||
// dimensionality of (reshaped) samples
|
||||
size_t d = src.getMat(0).total();
|
||||
// create data matrix
|
||||
Mat data(n, d, rtype);
|
||||
// copy data
|
||||
for(int i = 0; i < n; i++) {
|
||||
Mat data((int)n, (int)d, rtype);
|
||||
// now copy data
|
||||
for(int i = 0; i < (int)n; i++) {
|
||||
// make sure data can be reshaped, throw exception if not!
|
||||
if(src.getMat(i).total() != d) {
|
||||
string error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, (int)d, (int)src.getMat(i).total());
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// get a hold of the current row
|
||||
Mat xi = data.row(i);
|
||||
src.getMat(i).reshape(1, 1).convertTo(xi, rtype, alpha, beta);
|
||||
// make reshape happy by cloning for non-continuous matrices
|
||||
if(src.getMat(i).isContinuous()) {
|
||||
src.getMat(i).reshape(1, 1).convertTo(xi, rtype, alpha, beta);
|
||||
} else {
|
||||
src.getMat(i).clone().reshape(1, 1).convertTo(xi, rtype, alpha, beta);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) {
|
||||
if(_indices.getMat().type() != CV_32SC1)
|
||||
static void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) {
|
||||
if(_indices.getMat().type() != CV_32SC1) {
|
||||
CV_Error(CV_StsUnsupportedFormat, "cv::sortColumnsByIndices only works on integer indices!");
|
||||
}
|
||||
Mat src = _src.getMat();
|
||||
vector<int> indices = _indices.getMat();
|
||||
_dst.create(src.rows, src.cols, src.type());
|
||||
@ -87,7 +105,7 @@ void sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArra
|
||||
}
|
||||
}
|
||||
|
||||
Mat sortMatrixColumnsByIndices(InputArray src, InputArray indices) {
|
||||
static Mat sortMatrixColumnsByIndices(InputArray src, InputArray indices) {
|
||||
Mat dst;
|
||||
sortMatrixColumnsByIndices(src, indices, dst);
|
||||
return dst;
|
||||
@ -153,31 +171,44 @@ static bool isSymmetric(InputArray src, double eps=1e-16)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// subspace::project
|
||||
// cv::subspaceProject
|
||||
//------------------------------------------------------------------------------
|
||||
Mat subspaceProject(InputArray _W, InputArray _mean, InputArray _src)
|
||||
{
|
||||
Mat subspaceProject(InputArray _W, InputArray _mean, InputArray _src) {
|
||||
// get data matrices
|
||||
Mat W = _W.getMat();
|
||||
Mat mean = _mean.getMat();
|
||||
Mat src = _src.getMat();
|
||||
// get number of samples and dimension
|
||||
int n = src.rows;
|
||||
int d = src.cols;
|
||||
// make sure the data has the correct shape
|
||||
if(W.rows != d) {
|
||||
string error_message = format("Wrong shapes for given matrices. Was size(src) = (%d,%d), size(W) = (%d,%d).", src.rows, src.cols, W.rows, W.cols);
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// make sure mean is correct if not empty
|
||||
if(!mean.empty() && (mean.total() != (size_t) d)) {
|
||||
string error_message = format("Wrong mean shape for the given data matrix. Expected %d, but was %d.", d, mean.total());
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// create temporary matrices
|
||||
Mat X, Y;
|
||||
// copy data & make sure we are using the correct type
|
||||
// make sure you operate on correct type
|
||||
src.convertTo(X, W.type());
|
||||
// get number of samples and dimension
|
||||
int n = X.rows;
|
||||
int d = X.cols;
|
||||
// center the data if correct aligned sample mean is given
|
||||
if(mean.total() == (size_t)d)
|
||||
subtract(X, repeat(mean.reshape(1,1), n, 1), X);
|
||||
// safe to do, because of above assertion
|
||||
if(!mean.empty()) {
|
||||
for(int i=0; i<n; i++) {
|
||||
Mat r_i = X.row(i);
|
||||
subtract(r_i, mean.reshape(1,1), r_i);
|
||||
}
|
||||
}
|
||||
// finally calculate projection as Y = (X-mean)*W
|
||||
gemm(X, W, 1.0, Mat(), 0.0, Y);
|
||||
return Y;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// subspace::reconstruct
|
||||
// cv::subspaceReconstruct
|
||||
//------------------------------------------------------------------------------
|
||||
Mat subspaceReconstruct(InputArray _W, InputArray _mean, InputArray _src)
|
||||
{
|
||||
@ -185,16 +216,32 @@ Mat subspaceReconstruct(InputArray _W, InputArray _mean, InputArray _src)
|
||||
Mat W = _W.getMat();
|
||||
Mat mean = _mean.getMat();
|
||||
Mat src = _src.getMat();
|
||||
// get number of samples
|
||||
// get number of samples and dimension
|
||||
int n = src.rows;
|
||||
int d = src.cols;
|
||||
// make sure the data has the correct shape
|
||||
if(W.cols != d) {
|
||||
string error_message = format("Wrong shapes for given matrices. Was size(src) = (%d,%d), size(W) = (%d,%d).", src.rows, src.cols, W.rows, W.cols);
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// make sure mean is correct if not empty
|
||||
if(!mean.empty() && (mean.total() != (size_t) W.rows)) {
|
||||
string error_message = format("Wrong mean shape for the given eigenvector matrix. Expected %d, but was %d.", W.cols, mean.total());
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// initalize temporary matrices
|
||||
Mat X, Y;
|
||||
// copy data & make sure we are using the correct type
|
||||
src.convertTo(Y, W.type());
|
||||
// calculate the reconstruction
|
||||
gemm(Y, W, 1.0, Mat(), 0.0, X, GEMM_2_T);
|
||||
if(mean.total() == (size_t) X.cols)
|
||||
add(X, repeat(mean.reshape(1,1), n, 1), X);
|
||||
// safe to do because of above assertion
|
||||
if(!mean.empty()) {
|
||||
for(int i=0; i<n; i++) {
|
||||
Mat r_i = X.row(i);
|
||||
add(r_i, mean.reshape(1,1), r_i);
|
||||
}
|
||||
}
|
||||
return X;
|
||||
}
|
||||
|
||||
@ -235,19 +282,19 @@ private:
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp **alloc_2d(int m, int n) {
|
||||
_Tp **alloc_2d(int m, int _n) {
|
||||
_Tp **arr = new _Tp*[m];
|
||||
for (int i = 0; i < m; i++)
|
||||
arr[i] = new _Tp[n];
|
||||
arr[i] = new _Tp[_n];
|
||||
return arr;
|
||||
}
|
||||
|
||||
// Allocates memory.
|
||||
template<typename _Tp>
|
||||
_Tp **alloc_2d(int m, int n, _Tp val) {
|
||||
_Tp **arr = alloc_2d<_Tp> (m, n);
|
||||
_Tp **alloc_2d(int m, int _n, _Tp val) {
|
||||
_Tp **arr = alloc_2d<_Tp> (m, _n);
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
for (int j = 0; j < _n; j++) {
|
||||
arr[i][j] = val;
|
||||
}
|
||||
}
|
||||
@ -255,17 +302,17 @@ private:
|
||||
}
|
||||
|
||||
void cdiv(double xr, double xi, double yr, double yi) {
|
||||
double r, d;
|
||||
double r, dv;
|
||||
if (std::abs(yr) > std::abs(yi)) {
|
||||
r = yi / yr;
|
||||
d = yr + r * yi;
|
||||
cdivr = (xr + r * xi) / d;
|
||||
cdivi = (xi - r * xr) / d;
|
||||
dv = yr + r * yi;
|
||||
cdivr = (xr + r * xi) / dv;
|
||||
cdivi = (xi - r * xr) / dv;
|
||||
} else {
|
||||
r = yr / yi;
|
||||
d = yi + r * yr;
|
||||
cdivr = (r * xr + xi) / d;
|
||||
cdivi = (r * xi - xr) / d;
|
||||
dv = yi + r * yr;
|
||||
cdivr = (r * xr + xi) / dv;
|
||||
cdivi = (r * xi - xr) / dv;
|
||||
}
|
||||
}
|
||||
|
||||
@ -280,7 +327,7 @@ private:
|
||||
|
||||
// Initialize
|
||||
int nn = this->n;
|
||||
int n = nn - 1;
|
||||
int n1 = nn - 1;
|
||||
int low = 0;
|
||||
int high = nn - 1;
|
||||
double eps = pow(2.0, -52.0);
|
||||
@ -302,10 +349,10 @@ private:
|
||||
|
||||
// Outer loop over eigenvalue index
|
||||
int iter = 0;
|
||||
while (n >= low) {
|
||||
while (n1 >= low) {
|
||||
|
||||
// Look for single small sub-diagonal element
|
||||
int l = n;
|
||||
int l = n1;
|
||||
while (l > low) {
|
||||
s = std::abs(H[l - 1][l - 1]) + std::abs(H[l][l]);
|
||||
if (s == 0.0) {
|
||||
@ -320,23 +367,23 @@ private:
|
||||
// Check for convergence
|
||||
// One root found
|
||||
|
||||
if (l == n) {
|
||||
H[n][n] = H[n][n] + exshift;
|
||||
d[n] = H[n][n];
|
||||
e[n] = 0.0;
|
||||
n--;
|
||||
if (l == n1) {
|
||||
H[n1][n1] = H[n1][n1] + exshift;
|
||||
d[n1] = H[n1][n1];
|
||||
e[n1] = 0.0;
|
||||
n1--;
|
||||
iter = 0;
|
||||
|
||||
// Two roots found
|
||||
|
||||
} else if (l == n - 1) {
|
||||
w = H[n][n - 1] * H[n - 1][n];
|
||||
p = (H[n - 1][n - 1] - H[n][n]) / 2.0;
|
||||
} else if (l == n1 - 1) {
|
||||
w = H[n1][n1 - 1] * H[n1 - 1][n1];
|
||||
p = (H[n1 - 1][n1 - 1] - H[n1][n1]) / 2.0;
|
||||
q = p * p + w;
|
||||
z = sqrt(std::abs(q));
|
||||
H[n][n] = H[n][n] + exshift;
|
||||
H[n - 1][n - 1] = H[n - 1][n - 1] + exshift;
|
||||
x = H[n][n];
|
||||
H[n1][n1] = H[n1][n1] + exshift;
|
||||
H[n1 - 1][n1 - 1] = H[n1 - 1][n1 - 1] + exshift;
|
||||
x = H[n1][n1];
|
||||
|
||||
// Real pair
|
||||
|
||||
@ -346,14 +393,14 @@ private:
|
||||
} else {
|
||||
z = p - z;
|
||||
}
|
||||
d[n - 1] = x + z;
|
||||
d[n] = d[n - 1];
|
||||
d[n1 - 1] = x + z;
|
||||
d[n1] = d[n1 - 1];
|
||||
if (z != 0.0) {
|
||||
d[n] = x - w / z;
|
||||
d[n1] = x - w / z;
|
||||
}
|
||||
e[n - 1] = 0.0;
|
||||
e[n] = 0.0;
|
||||
x = H[n][n - 1];
|
||||
e[n1 - 1] = 0.0;
|
||||
e[n1] = 0.0;
|
||||
x = H[n1][n1 - 1];
|
||||
s = std::abs(x) + std::abs(z);
|
||||
p = x / s;
|
||||
q = z / s;
|
||||
@ -363,37 +410,37 @@ private:
|
||||
|
||||
// Row modification
|
||||
|
||||
for (int j = n - 1; j < nn; j++) {
|
||||
z = H[n - 1][j];
|
||||
H[n - 1][j] = q * z + p * H[n][j];
|
||||
H[n][j] = q * H[n][j] - p * z;
|
||||
for (int j = n1 - 1; j < nn; j++) {
|
||||
z = H[n1 - 1][j];
|
||||
H[n1 - 1][j] = q * z + p * H[n1][j];
|
||||
H[n1][j] = q * H[n1][j] - p * z;
|
||||
}
|
||||
|
||||
// Column modification
|
||||
|
||||
for (int i = 0; i <= n; i++) {
|
||||
z = H[i][n - 1];
|
||||
H[i][n - 1] = q * z + p * H[i][n];
|
||||
H[i][n] = q * H[i][n] - p * z;
|
||||
for (int i = 0; i <= n1; i++) {
|
||||
z = H[i][n1 - 1];
|
||||
H[i][n1 - 1] = q * z + p * H[i][n1];
|
||||
H[i][n1] = q * H[i][n1] - p * z;
|
||||
}
|
||||
|
||||
// Accumulate transformations
|
||||
|
||||
for (int i = low; i <= high; i++) {
|
||||
z = V[i][n - 1];
|
||||
V[i][n - 1] = q * z + p * V[i][n];
|
||||
V[i][n] = q * V[i][n] - p * z;
|
||||
z = V[i][n1 - 1];
|
||||
V[i][n1 - 1] = q * z + p * V[i][n1];
|
||||
V[i][n1] = q * V[i][n1] - p * z;
|
||||
}
|
||||
|
||||
// Complex pair
|
||||
|
||||
} else {
|
||||
d[n - 1] = x + p;
|
||||
d[n] = x + p;
|
||||
e[n - 1] = z;
|
||||
e[n] = -z;
|
||||
d[n1 - 1] = x + p;
|
||||
d[n1] = x + p;
|
||||
e[n1 - 1] = z;
|
||||
e[n1] = -z;
|
||||
}
|
||||
n = n - 2;
|
||||
n1 = n1 - 2;
|
||||
iter = 0;
|
||||
|
||||
// No convergence yet
|
||||
@ -402,22 +449,22 @@ private:
|
||||
|
||||
// Form shift
|
||||
|
||||
x = H[n][n];
|
||||
x = H[n1][n1];
|
||||
y = 0.0;
|
||||
w = 0.0;
|
||||
if (l < n) {
|
||||
y = H[n - 1][n - 1];
|
||||
w = H[n][n - 1] * H[n - 1][n];
|
||||
if (l < n1) {
|
||||
y = H[n1 - 1][n1 - 1];
|
||||
w = H[n1][n1 - 1] * H[n1 - 1][n1];
|
||||
}
|
||||
|
||||
// Wilkinson's original ad hoc shift
|
||||
|
||||
if (iter == 10) {
|
||||
exshift += x;
|
||||
for (int i = low; i <= n; i++) {
|
||||
for (int i = low; i <= n1; i++) {
|
||||
H[i][i] -= x;
|
||||
}
|
||||
s = std::abs(H[n][n - 1]) + std::abs(H[n - 1][n - 2]);
|
||||
s = std::abs(H[n1][n1 - 1]) + std::abs(H[n1 - 1][n1 - 2]);
|
||||
x = y = 0.75 * s;
|
||||
w = -0.4375 * s * s;
|
||||
}
|
||||
@ -433,7 +480,7 @@ private:
|
||||
s = -s;
|
||||
}
|
||||
s = x - w / ((y - x) / 2.0 + s);
|
||||
for (int i = low; i <= n; i++) {
|
||||
for (int i = low; i <= n1; i++) {
|
||||
H[i][i] -= s;
|
||||
}
|
||||
exshift += s;
|
||||
@ -444,7 +491,7 @@ private:
|
||||
iter = iter + 1; // (Could check iteration count here.)
|
||||
|
||||
// Look for two consecutive small sub-diagonal elements
|
||||
int m = n - 2;
|
||||
int m = n1 - 2;
|
||||
while (m >= l) {
|
||||
z = H[m][m];
|
||||
r = x - z;
|
||||
@ -467,7 +514,7 @@ private:
|
||||
m--;
|
||||
}
|
||||
|
||||
for (int i = m + 2; i <= n; i++) {
|
||||
for (int i = m + 2; i <= n1; i++) {
|
||||
H[i][i - 2] = 0.0;
|
||||
if (i > m + 2) {
|
||||
H[i][i - 3] = 0.0;
|
||||
@ -476,8 +523,8 @@ private:
|
||||
|
||||
// Double QR step involving rows l:n and columns m:n
|
||||
|
||||
for (int k = m; k <= n - 1; k++) {
|
||||
bool notlast = (k != n - 1);
|
||||
for (int k = m; k <= n1 - 1; k++) {
|
||||
bool notlast = (k != n1 - 1);
|
||||
if (k != m) {
|
||||
p = H[k][k - 1];
|
||||
q = H[k + 1][k - 1];
|
||||
@ -523,7 +570,7 @@ private:
|
||||
|
||||
// Column modification
|
||||
|
||||
for (int i = 0; i <= min(n, k + 3); i++) {
|
||||
for (int i = 0; i <= min(n1, k + 3); i++) {
|
||||
p = x * H[i][k] + y * H[i][k + 1];
|
||||
if (notlast) {
|
||||
p = p + z * H[i][k + 2];
|
||||
@ -547,7 +594,7 @@ private:
|
||||
} // (s != 0)
|
||||
} // k loop
|
||||
} // check convergence
|
||||
} // while (n >= low)
|
||||
} // while (n1 >= low)
|
||||
|
||||
// Backsubstitute to find vectors of upper triangular form
|
||||
|
||||
@ -555,20 +602,20 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
for (n = nn - 1; n >= 0; n--) {
|
||||
p = d[n];
|
||||
q = e[n];
|
||||
for (n1 = nn - 1; n1 >= 0; n1--) {
|
||||
p = d[n1];
|
||||
q = e[n1];
|
||||
|
||||
// Real vector
|
||||
|
||||
if (q == 0) {
|
||||
int l = n;
|
||||
H[n][n] = 1.0;
|
||||
for (int i = n - 1; i >= 0; i--) {
|
||||
int l = n1;
|
||||
H[n1][n1] = 1.0;
|
||||
for (int i = n1 - 1; i >= 0; i--) {
|
||||
w = H[i][i] - p;
|
||||
r = 0.0;
|
||||
for (int j = l; j <= n; j++) {
|
||||
r = r + H[i][j] * H[j][n];
|
||||
for (int j = l; j <= n1; j++) {
|
||||
r = r + H[i][j] * H[j][n1];
|
||||
}
|
||||
if (e[i] < 0.0) {
|
||||
z = w;
|
||||
@ -577,9 +624,9 @@ private:
|
||||
l = i;
|
||||
if (e[i] == 0.0) {
|
||||
if (w != 0.0) {
|
||||
H[i][n] = -r / w;
|
||||
H[i][n1] = -r / w;
|
||||
} else {
|
||||
H[i][n] = -r / (eps * norm);
|
||||
H[i][n1] = -r / (eps * norm);
|
||||
}
|
||||
|
||||
// Solve real equations
|
||||
@ -589,49 +636,47 @@ private:
|
||||
y = H[i + 1][i];
|
||||
q = (d[i] - p) * (d[i] - p) + e[i] * e[i];
|
||||
t = (x * s - z * r) / q;
|
||||
H[i][n] = t;
|
||||
H[i][n1] = t;
|
||||
if (std::abs(x) > std::abs(z)) {
|
||||
H[i + 1][n] = (-r - w * t) / x;
|
||||
H[i + 1][n1] = (-r - w * t) / x;
|
||||
} else {
|
||||
H[i + 1][n] = (-s - y * t) / z;
|
||||
H[i + 1][n1] = (-s - y * t) / z;
|
||||
}
|
||||
}
|
||||
|
||||
// Overflow control
|
||||
|
||||
t = std::abs(H[i][n]);
|
||||
t = std::abs(H[i][n1]);
|
||||
if ((eps * t) * t > 1) {
|
||||
for (int j = i; j <= n; j++) {
|
||||
H[j][n] = H[j][n] / t;
|
||||
for (int j = i; j <= n1; j++) {
|
||||
H[j][n1] = H[j][n1] / t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Complex vector
|
||||
|
||||
} else if (q < 0) {
|
||||
int l = n - 1;
|
||||
int l = n1 - 1;
|
||||
|
||||
// Last vector component imaginary so matrix is triangular
|
||||
|
||||
if (std::abs(H[n][n - 1]) > std::abs(H[n - 1][n])) {
|
||||
H[n - 1][n - 1] = q / H[n][n - 1];
|
||||
H[n - 1][n] = -(H[n][n] - p) / H[n][n - 1];
|
||||
if (std::abs(H[n1][n1 - 1]) > std::abs(H[n1 - 1][n1])) {
|
||||
H[n1 - 1][n1 - 1] = q / H[n1][n1 - 1];
|
||||
H[n1 - 1][n1] = -(H[n1][n1] - p) / H[n1][n1 - 1];
|
||||
} else {
|
||||
cdiv(0.0, -H[n - 1][n], H[n - 1][n - 1] - p, q);
|
||||
H[n - 1][n - 1] = cdivr;
|
||||
H[n - 1][n] = cdivi;
|
||||
cdiv(0.0, -H[n1 - 1][n1], H[n1 - 1][n1 - 1] - p, q);
|
||||
H[n1 - 1][n1 - 1] = cdivr;
|
||||
H[n1 - 1][n1] = cdivi;
|
||||
}
|
||||
H[n][n - 1] = 0.0;
|
||||
H[n][n] = 1.0;
|
||||
for (int i = n - 2; i >= 0; i--) {
|
||||
H[n1][n1 - 1] = 0.0;
|
||||
H[n1][n1] = 1.0;
|
||||
for (int i = n1 - 2; i >= 0; i--) {
|
||||
double ra, sa, vr, vi;
|
||||
ra = 0.0;
|
||||
sa = 0.0;
|
||||
for (int j = l; j <= n; j++) {
|
||||
ra = ra + H[i][j] * H[j][n - 1];
|
||||
sa = sa + H[i][j] * H[j][n];
|
||||
for (int j = l; j <= n1; j++) {
|
||||
ra = ra + H[i][j] * H[j][n1 - 1];
|
||||
sa = sa + H[i][j] * H[j][n1];
|
||||
}
|
||||
w = H[i][i] - p;
|
||||
|
||||
@ -643,8 +688,8 @@ private:
|
||||
l = i;
|
||||
if (e[i] == 0) {
|
||||
cdiv(-ra, -sa, w, q);
|
||||
H[i][n - 1] = cdivr;
|
||||
H[i][n] = cdivi;
|
||||
H[i][n1 - 1] = cdivr;
|
||||
H[i][n1] = cdivi;
|
||||
} else {
|
||||
|
||||
// Solve complex equations
|
||||
@ -659,28 +704,28 @@ private:
|
||||
}
|
||||
cdiv(x * r - z * ra + q * sa,
|
||||
x * s - z * sa - q * ra, vr, vi);
|
||||
H[i][n - 1] = cdivr;
|
||||
H[i][n] = cdivi;
|
||||
H[i][n1 - 1] = cdivr;
|
||||
H[i][n1] = cdivi;
|
||||
if (std::abs(x) > (std::abs(z) + std::abs(q))) {
|
||||
H[i + 1][n - 1] = (-ra - w * H[i][n - 1] + q
|
||||
* H[i][n]) / x;
|
||||
H[i + 1][n] = (-sa - w * H[i][n] - q * H[i][n
|
||||
H[i + 1][n1 - 1] = (-ra - w * H[i][n1 - 1] + q
|
||||
* H[i][n1]) / x;
|
||||
H[i + 1][n1] = (-sa - w * H[i][n1] - q * H[i][n1
|
||||
- 1]) / x;
|
||||
} else {
|
||||
cdiv(-r - y * H[i][n - 1], -s - y * H[i][n], z,
|
||||
cdiv(-r - y * H[i][n1 - 1], -s - y * H[i][n1], z,
|
||||
q);
|
||||
H[i + 1][n - 1] = cdivr;
|
||||
H[i + 1][n] = cdivi;
|
||||
H[i + 1][n1 - 1] = cdivr;
|
||||
H[i + 1][n1] = cdivi;
|
||||
}
|
||||
}
|
||||
|
||||
// Overflow control
|
||||
|
||||
t = max(std::abs(H[i][n - 1]), std::abs(H[i][n]));
|
||||
t = max(std::abs(H[i][n1 - 1]), std::abs(H[i][n1]));
|
||||
if ((eps * t) * t > 1) {
|
||||
for (int j = i; j <= n; j++) {
|
||||
H[j][n - 1] = H[j][n - 1] / t;
|
||||
H[j][n] = H[j][n] / t;
|
||||
for (int j = i; j <= n1; j++) {
|
||||
H[j][n1 - 1] = H[j][n1 - 1] / t;
|
||||
H[j][n1] = H[j][n1] / t;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -898,8 +943,9 @@ public:
|
||||
//------------------------------------------------------------------------------
|
||||
void LDA::save(const string& filename) const {
|
||||
FileStorage fs(filename, FileStorage::WRITE);
|
||||
if (!fs.isOpened())
|
||||
if (!fs.isOpened()) {
|
||||
CV_Error(CV_StsError, "File can't be opened for writing!");
|
||||
}
|
||||
this->save(fs);
|
||||
fs.release();
|
||||
}
|
||||
@ -941,8 +987,8 @@ void LDA::lda(InputArray _src, InputArray _lbls) {
|
||||
vector<int> mapped_labels(labels.size());
|
||||
vector<int> num2label = remove_dups(labels);
|
||||
map<int, int> label2num;
|
||||
for (size_t i = 0; i < num2label.size(); i++)
|
||||
label2num[num2label[i]] = (int)i;
|
||||
for (int i = 0; i < (int)num2label.size(); i++)
|
||||
label2num[num2label[i]] = i;
|
||||
for (size_t i = 0; i < labels.size(); i++)
|
||||
mapped_labels[i] = label2num[labels[i]];
|
||||
// get sample size, dimension
|
||||
@ -950,17 +996,27 @@ void LDA::lda(InputArray _src, InputArray _lbls) {
|
||||
int D = data.cols;
|
||||
// number of unique labels
|
||||
int C = (int)num2label.size();
|
||||
// we can't do a LDA on one class, what do you
|
||||
// want to separate from each other then?
|
||||
if(C == 1) {
|
||||
string error_message = "At least two classes are needed to perform a LDA. Reason: Only one class was given!";
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// throw error if less labels, than samples
|
||||
if (labels.size() != (size_t)N)
|
||||
CV_Error(CV_StsBadArg, "Error: The number of samples must equal the number of labels.");
|
||||
if (labels.size() != static_cast<size_t>(N)) {
|
||||
string error_message = format("The number of samples must equal the number of labels. Given %d labels, %d samples. ", labels.size(), N);
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
}
|
||||
// warn if within-classes scatter matrix becomes singular
|
||||
if (N < D)
|
||||
if (N < D) {
|
||||
cout << "Warning: Less observations than feature dimension given!"
|
||||
<< "Computation will probably fail."
|
||||
<< endl;
|
||||
<< "Computation will probably fail."
|
||||
<< endl;
|
||||
}
|
||||
// clip number of components to be a valid number
|
||||
if ((_num_components <= 0) || (_num_components > (C - 1)))
|
||||
if ((_num_components <= 0) || (_num_components > (C - 1))) {
|
||||
_num_components = (C - 1);
|
||||
}
|
||||
// holds the mean over all classes
|
||||
Mat meanTotal = Mat::zeros(1, D, data.type());
|
||||
// holds the mean for each class
|
||||
@ -979,12 +1035,12 @@ void LDA::lda(InputArray _src, InputArray _lbls) {
|
||||
add(meanClass[classIdx], instance, meanClass[classIdx]);
|
||||
numClass[classIdx]++;
|
||||
}
|
||||
// calculate means
|
||||
meanTotal.convertTo(meanTotal, meanTotal.type(),
|
||||
1.0 / static_cast<double> (N));
|
||||
for (int i = 0; i < C; i++)
|
||||
meanClass[i].convertTo(meanClass[i], meanClass[i].type(),
|
||||
1.0 / static_cast<double> (numClass[i]));
|
||||
// calculate total mean
|
||||
meanTotal.convertTo(meanTotal, meanTotal.type(), 1.0 / static_cast<double> (N));
|
||||
// calculate class means
|
||||
for (int i = 0; i < C; i++) {
|
||||
meanClass[i].convertTo(meanClass[i], meanClass[i].type(), 1.0 / static_cast<double> (numClass[i]));
|
||||
}
|
||||
// subtract class means
|
||||
for (int i = 0; i < N; i++) {
|
||||
int classIdx = mapped_labels[i];
|
||||
@ -1031,7 +1087,8 @@ void LDA::compute(InputArray _src, InputArray _lbls) {
|
||||
lda(_src.getMat(), _lbls);
|
||||
break;
|
||||
default:
|
||||
CV_Error(CV_StsNotImplemented, "This data type is not supported by subspace::LDA::compute.");
|
||||
string error_message= format("InputArray Datatype %d is not supported.", _src.kind());
|
||||
CV_Error(CV_StsBadArg, error_message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ namespace cv
|
||||
{
|
||||
|
||||
//------------------------------------interp-------------------------------------------
|
||||
LogPolar_Interp::LogPolar_Interp(int w, int h, Point2i center, int R, double ro0, int interp, int full, int S, int sp)
|
||||
LogPolar_Interp::LogPolar_Interp(int w, int h, Point2i center, int _R, double _ro0, int _interp, int full, int _s, int sp)
|
||||
{
|
||||
if ( (center.x!=w/2 || center.y!=h/2) && full==0) full=1;
|
||||
|
||||
@ -97,23 +97,23 @@ LogPolar_Interp::LogPolar_Interp(int w, int h, Point2i center, int R, double ro0
|
||||
|
||||
if (sp){
|
||||
int jc=M/2-1, ic=N/2-1;
|
||||
int romax=min(ic, jc);
|
||||
double a=exp(log((double)(romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(a-1)+0.5);
|
||||
int _romax=min(ic, jc);
|
||||
double _a=exp(log((double)(_romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(_a-1)+0.5);
|
||||
}
|
||||
|
||||
this->interp=interp;
|
||||
interp=_interp;
|
||||
|
||||
create_map(M, N, R, S, ro0);
|
||||
create_map(M, N, _R, _s, _ro0);
|
||||
}
|
||||
|
||||
void LogPolar_Interp::create_map(int M, int N, int R, int S, double ro0)
|
||||
void LogPolar_Interp::create_map(int _M, int _n, int _R, int _s, double _ro0)
|
||||
{
|
||||
this->M=M;
|
||||
this->N=N;
|
||||
this->R=R;
|
||||
this->S=S;
|
||||
this->ro0=ro0;
|
||||
M=_M;
|
||||
N=_n;
|
||||
R=_R;
|
||||
S=_s;
|
||||
ro0=_ro0;
|
||||
|
||||
int jc=N/2-1, ic=M/2-1;
|
||||
romax=min(ic, jc);
|
||||
@ -208,7 +208,7 @@ LogPolar_Interp::~LogPolar_Interp()
|
||||
|
||||
//------------------------------------overlapping----------------------------------
|
||||
|
||||
LogPolar_Overlapping::LogPolar_Overlapping(int w, int h, Point2i center, int R, double ro0, int full, int S, int sp)
|
||||
LogPolar_Overlapping::LogPolar_Overlapping(int w, int h, Point2i center, int _R, double _ro0, int full, int _s, int sp)
|
||||
{
|
||||
if ( (center.x!=w/2 || center.y!=h/2) && full==0) full=1;
|
||||
|
||||
@ -244,21 +244,21 @@ LogPolar_Overlapping::LogPolar_Overlapping(int w, int h, Point2i center, int R,
|
||||
|
||||
if (sp){
|
||||
int jc=M/2-1, ic=N/2-1;
|
||||
int romax=min(ic, jc);
|
||||
double a=exp(log((double)(romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(a-1)+0.5);
|
||||
int _romax=min(ic, jc);
|
||||
double _a=exp(log((double)(_romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(_a-1)+0.5);
|
||||
}
|
||||
|
||||
create_map(M, N, R, S, ro0);
|
||||
create_map(M, N, _R, _s, _ro0);
|
||||
}
|
||||
|
||||
void LogPolar_Overlapping::create_map(int M, int N, int R, int S, double ro0)
|
||||
void LogPolar_Overlapping::create_map(int _M, int _n, int _R, int _s, double _ro0)
|
||||
{
|
||||
this->M=M;
|
||||
this->N=N;
|
||||
this->R=R;
|
||||
this->S=S;
|
||||
this->ro0=ro0;
|
||||
M=_M;
|
||||
N=_n;
|
||||
R=_R;
|
||||
S=_s;
|
||||
ro0=_ro0;
|
||||
|
||||
int jc=N/2-1, ic=M/2-1;
|
||||
romax=min(ic, jc);
|
||||
@ -433,7 +433,7 @@ LogPolar_Overlapping::~LogPolar_Overlapping()
|
||||
|
||||
//----------------------------------------adjacent---------------------------------------
|
||||
|
||||
LogPolar_Adjacent::LogPolar_Adjacent(int w, int h, Point2i center, int R, double ro0, double smin, int full, int S, int sp)
|
||||
LogPolar_Adjacent::LogPolar_Adjacent(int w, int h, Point2i center, int _R, double _ro0, double smin, int full, int _s, int sp)
|
||||
{
|
||||
if ( (center.x!=w/2 || center.y!=h/2) && full==0) full=1;
|
||||
|
||||
@ -468,22 +468,22 @@ LogPolar_Adjacent::LogPolar_Adjacent(int w, int h, Point2i center, int R, double
|
||||
|
||||
if (sp){
|
||||
int jc=M/2-1, ic=N/2-1;
|
||||
int romax=min(ic, jc);
|
||||
double a=exp(log((double)(romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(a-1)+0.5);
|
||||
int _romax=min(ic, jc);
|
||||
double _a=exp(log((double)(_romax/2-1)/(double)ro0)/(double)R);
|
||||
S=(int) floor(2*CV_PI/(_a-1)+0.5);
|
||||
}
|
||||
|
||||
create_map(M, N, R, S, ro0, smin);
|
||||
create_map(M, N, _R, _s, _ro0, smin);
|
||||
}
|
||||
|
||||
|
||||
void LogPolar_Adjacent::create_map(int M, int N, int R, int S, double ro0, double smin)
|
||||
void LogPolar_Adjacent::create_map(int _M, int _n, int _R, int _s, double _ro0, double smin)
|
||||
{
|
||||
LogPolar_Adjacent::M=M;
|
||||
LogPolar_Adjacent::N=N;
|
||||
LogPolar_Adjacent::R=R;
|
||||
LogPolar_Adjacent::S=S;
|
||||
LogPolar_Adjacent::ro0=ro0;
|
||||
M=_M;
|
||||
N=_n;
|
||||
R=_R;
|
||||
S=_s;
|
||||
ro0=_ro0;
|
||||
romax=min(M/2.0, N/2.0);
|
||||
|
||||
a=exp(log(romax/ro0)/(double)R);
|
||||
|
@ -43,8 +43,9 @@
|
||||
#include "precomp.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace cv
|
||||
namespace
|
||||
{
|
||||
using namespace cv;
|
||||
const size_t MAX_STACK_SIZE = 255;
|
||||
const size_t MAX_LEAFS = 8;
|
||||
|
||||
@ -159,17 +160,20 @@ namespace cv
|
||||
child.x_min = parent.x_min;
|
||||
}
|
||||
|
||||
}//namespace
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////// Octree //////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace cv
|
||||
{
|
||||
Octree::Octree()
|
||||
{
|
||||
}
|
||||
|
||||
Octree::Octree(const vector<Point3f>& points3d, int maxLevels, int minPoints)
|
||||
Octree::Octree(const vector<Point3f>& points3d, int maxLevels, int _minPoints)
|
||||
{
|
||||
buildTree(points3d, maxLevels, minPoints);
|
||||
buildTree(points3d, maxLevels, _minPoints);
|
||||
}
|
||||
|
||||
Octree::~Octree()
|
||||
@ -252,12 +256,12 @@ namespace cv
|
||||
}
|
||||
}
|
||||
|
||||
void Octree::buildTree(const vector<Point3f>& points3d, int maxLevels, int minPoints)
|
||||
void Octree::buildTree(const vector<Point3f>& points3d, int maxLevels, int _minPoints)
|
||||
{
|
||||
assert((size_t)maxLevels * 8 < MAX_STACK_SIZE);
|
||||
points.resize(points3d.size());
|
||||
std::copy(points3d.begin(), points3d.end(), points.begin());
|
||||
this->minPoints = minPoints;
|
||||
minPoints = _minPoints;
|
||||
|
||||
nodes.clear();
|
||||
nodes.push_back(Node());
|
||||
@ -271,7 +275,7 @@ namespace cv
|
||||
for (size_t i = 0; i < MAX_LEAFS; i++)
|
||||
root.children[i] = 0;
|
||||
|
||||
if (maxLevels != 1 && (root.end - root.begin) > minPoints)
|
||||
if (maxLevels != 1 && (root.end - root.begin) > _minPoints)
|
||||
{
|
||||
root.isLeaf = false;
|
||||
buildNext(0);
|
||||
|
@ -43,10 +43,6 @@
|
||||
#ifndef __OPENCV_PRECOMP_H__
|
||||
#define __OPENCV_PRECOMP_H__
|
||||
|
||||
#if _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4251 4710 4711 4514 4996 )
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
|
@ -75,16 +75,16 @@
|
||||
namespace cv
|
||||
{
|
||||
|
||||
Retina::Retina(const cv::Size inputSize)
|
||||
Retina::Retina(const cv::Size inputSz)
|
||||
{
|
||||
_retinaFilter = 0;
|
||||
_init(inputSize, true, RETINA_COLOR_BAYER, false);
|
||||
_init(inputSz, true, RETINA_COLOR_BAYER, false);
|
||||
}
|
||||
|
||||
Retina::Retina(const cv::Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
Retina::Retina(const cv::Size inputSz, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
_retinaFilter = 0;
|
||||
_init(inputSize, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
_init(inputSz, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
};
|
||||
|
||||
Retina::~Retina()
|
||||
@ -106,7 +106,7 @@ Size Retina::outputSize(){return cv::Size(_retinaFilter->getOutputNBcolumns(), _
|
||||
|
||||
void Retina::setColorSaturation(const bool saturateColors, const float colorSaturationValue)
|
||||
{
|
||||
_retinaFilter->setColorSaturation(saturateColors, colorSaturationValue);
|
||||
_retinaFilter->setColorSaturation(saturateColors, colorSaturationValue);
|
||||
}
|
||||
|
||||
struct Retina::RetinaParameters Retina::getParameters(){return _retinaParameters;}
|
||||
@ -121,71 +121,71 @@ void Retina::setup(std::string retinaParameterFile, const bool applyDefaultSetup
|
||||
setup(fs, applyDefaultSetupOnFailure);
|
||||
}catch(Exception &e)
|
||||
{
|
||||
std::cout<<"Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>"<<e.what()<<std::endl;
|
||||
if (applyDefaultSetupOnFailure)
|
||||
{
|
||||
std::cout<<"Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>"<<e.what()<<std::endl;
|
||||
if (applyDefaultSetupOnFailure)
|
||||
{
|
||||
std::cout<<"Retina::setup: resetting retina with default parameters"<<std::endl;
|
||||
setupOPLandIPLParvoChannel();
|
||||
setupIPLMagnoChannel();
|
||||
}
|
||||
setupOPLandIPLParvoChannel();
|
||||
setupIPLMagnoChannel();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout<<"=> keeping current parameters"<<std::endl;
|
||||
std::cout<<"=> keeping current parameters"<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Retina::setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure)
|
||||
{
|
||||
try
|
||||
{
|
||||
// read parameters file if it exists or apply default setup if asked for
|
||||
if (!fs.isOpened())
|
||||
{
|
||||
std::cout<<"Retina::setup: provided parameters file could not be open... skeeping configuration"<<std::endl;
|
||||
return;
|
||||
// implicit else case : retinaParameterFile could be open (it exists at least)
|
||||
}
|
||||
try
|
||||
{
|
||||
// read parameters file if it exists or apply default setup if asked for
|
||||
if (!fs.isOpened())
|
||||
{
|
||||
std::cout<<"Retina::setup: provided parameters file could not be open... skeeping configuration"<<std::endl;
|
||||
return;
|
||||
// implicit else case : retinaParameterFile could be open (it exists at least)
|
||||
}
|
||||
// OPL and Parvo init first... update at the same time the parameters structure and the retina core
|
||||
cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"];
|
||||
currFn["colorMode"]>>_retinaParameters.OPLandIplParvo.colorMode;
|
||||
currFn["normaliseOutput"]>>_retinaParameters.OPLandIplParvo.normaliseOutput;
|
||||
currFn["photoreceptorsLocalAdaptationSensitivity"]>>_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity;
|
||||
currFn["photoreceptorsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant;
|
||||
currFn["photoreceptorsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant;
|
||||
currFn["horizontalCellsGain"]>>_retinaParameters.OPLandIplParvo.horizontalCellsGain;
|
||||
currFn["hcellsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.hcellsTemporalConstant;
|
||||
currFn["hcellsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.hcellsSpatialConstant;
|
||||
currFn["ganglionCellsSensitivity"]>>_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity;
|
||||
setupOPLandIPLParvoChannel(_retinaParameters.OPLandIplParvo.colorMode, _retinaParameters.OPLandIplParvo.normaliseOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant, _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant, _retinaParameters.OPLandIplParvo.horizontalCellsGain, _retinaParameters.OPLandIplParvo.hcellsTemporalConstant, _retinaParameters.OPLandIplParvo.hcellsSpatialConstant, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity);
|
||||
cv::FileNode rootFn = fs.root(), currFn=rootFn["OPLandIPLparvo"];
|
||||
currFn["colorMode"]>>_retinaParameters.OPLandIplParvo.colorMode;
|
||||
currFn["normaliseOutput"]>>_retinaParameters.OPLandIplParvo.normaliseOutput;
|
||||
currFn["photoreceptorsLocalAdaptationSensitivity"]>>_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity;
|
||||
currFn["photoreceptorsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant;
|
||||
currFn["photoreceptorsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant;
|
||||
currFn["horizontalCellsGain"]>>_retinaParameters.OPLandIplParvo.horizontalCellsGain;
|
||||
currFn["hcellsTemporalConstant"]>>_retinaParameters.OPLandIplParvo.hcellsTemporalConstant;
|
||||
currFn["hcellsSpatialConstant"]>>_retinaParameters.OPLandIplParvo.hcellsSpatialConstant;
|
||||
currFn["ganglionCellsSensitivity"]>>_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity;
|
||||
setupOPLandIPLParvoChannel(_retinaParameters.OPLandIplParvo.colorMode, _retinaParameters.OPLandIplParvo.normaliseOutput, _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity, _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant, _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant, _retinaParameters.OPLandIplParvo.horizontalCellsGain, _retinaParameters.OPLandIplParvo.hcellsTemporalConstant, _retinaParameters.OPLandIplParvo.hcellsSpatialConstant, _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity);
|
||||
|
||||
// init retina IPL magno setup... update at the same time the parameters structure and the retina core
|
||||
currFn=rootFn["IPLmagno"];
|
||||
currFn["normaliseOutput"]>>_retinaParameters.IplMagno.normaliseOutput;
|
||||
currFn["parasolCells_beta"]>>_retinaParameters.IplMagno.parasolCells_beta;
|
||||
currFn["parasolCells_tau"]>>_retinaParameters.IplMagno.parasolCells_tau;
|
||||
currFn["parasolCells_k"]>>_retinaParameters.IplMagno.parasolCells_k;
|
||||
currFn["amacrinCellsTemporalCutFrequency"]>>_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency;
|
||||
currFn["V0CompressionParameter"]>>_retinaParameters.IplMagno.V0CompressionParameter;
|
||||
currFn["localAdaptintegration_tau"]>>_retinaParameters.IplMagno.localAdaptintegration_tau;
|
||||
currFn["localAdaptintegration_k"]>>_retinaParameters.IplMagno.localAdaptintegration_k;
|
||||
// init retina IPL magno setup... update at the same time the parameters structure and the retina core
|
||||
currFn=rootFn["IPLmagno"];
|
||||
currFn["normaliseOutput"]>>_retinaParameters.IplMagno.normaliseOutput;
|
||||
currFn["parasolCells_beta"]>>_retinaParameters.IplMagno.parasolCells_beta;
|
||||
currFn["parasolCells_tau"]>>_retinaParameters.IplMagno.parasolCells_tau;
|
||||
currFn["parasolCells_k"]>>_retinaParameters.IplMagno.parasolCells_k;
|
||||
currFn["amacrinCellsTemporalCutFrequency"]>>_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency;
|
||||
currFn["V0CompressionParameter"]>>_retinaParameters.IplMagno.V0CompressionParameter;
|
||||
currFn["localAdaptintegration_tau"]>>_retinaParameters.IplMagno.localAdaptintegration_tau;
|
||||
currFn["localAdaptintegration_k"]>>_retinaParameters.IplMagno.localAdaptintegration_k;
|
||||
|
||||
setupIPLMagnoChannel(_retinaParameters.IplMagno.normaliseOutput, _retinaParameters.IplMagno.parasolCells_beta, _retinaParameters.IplMagno.parasolCells_tau, _retinaParameters.IplMagno.parasolCells_k, _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency,_retinaParameters.IplMagno.V0CompressionParameter, _retinaParameters.IplMagno.localAdaptintegration_tau, _retinaParameters.IplMagno.localAdaptintegration_k);
|
||||
setupIPLMagnoChannel(_retinaParameters.IplMagno.normaliseOutput, _retinaParameters.IplMagno.parasolCells_beta, _retinaParameters.IplMagno.parasolCells_tau, _retinaParameters.IplMagno.parasolCells_k, _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency,_retinaParameters.IplMagno.V0CompressionParameter, _retinaParameters.IplMagno.localAdaptintegration_tau, _retinaParameters.IplMagno.localAdaptintegration_k);
|
||||
|
||||
}catch(Exception &e)
|
||||
{
|
||||
std::cout<<"Retina::setup: resetting retina with default parameters"<<std::endl;
|
||||
if (applyDefaultSetupOnFailure)
|
||||
{
|
||||
setupOPLandIPLParvoChannel();
|
||||
setupIPLMagnoChannel();
|
||||
}
|
||||
std::cout<<"Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>"<<e.what()<<std::endl;
|
||||
std::cout<<"=> keeping current parameters"<<std::endl;
|
||||
}
|
||||
}catch(Exception &e)
|
||||
{
|
||||
std::cout<<"Retina::setup: resetting retina with default parameters"<<std::endl;
|
||||
if (applyDefaultSetupOnFailure)
|
||||
{
|
||||
setupOPLandIPLParvoChannel();
|
||||
setupIPLMagnoChannel();
|
||||
}
|
||||
std::cout<<"Retina::setup: wrong/unappropriate xml parameter file : error report :`n=>"<<e.what()<<std::endl;
|
||||
std::cout<<"=> keeping current parameters"<<std::endl;
|
||||
}
|
||||
|
||||
// report current configuration
|
||||
std::cout<<printSetup()<<std::endl;
|
||||
// report current configuration
|
||||
std::cout<<printSetup()<<std::endl;
|
||||
}
|
||||
|
||||
void Retina::setup(cv::Retina::RetinaParameters newConfiguration)
|
||||
@ -201,35 +201,35 @@ void Retina::setup(cv::Retina::RetinaParameters newConfiguration)
|
||||
|
||||
const std::string Retina::printSetup()
|
||||
{
|
||||
std::stringstream outmessage;
|
||||
std::stringstream outmessage;
|
||||
|
||||
// displaying OPL and IPL parvo setup
|
||||
outmessage<<"Current Retina instance setup :"
|
||||
<<"\nOPLandIPLparvo"<<"{"
|
||||
<< "\n==> colorMode : " << _retinaParameters.OPLandIplParvo.colorMode
|
||||
<< "\n==> normalizeParvoOutput :" << _retinaParameters.OPLandIplParvo.normaliseOutput
|
||||
<< "\n==> photoreceptorsLocalAdaptationSensitivity : " << _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity
|
||||
<< "\n==> photoreceptorsTemporalConstant : " << _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant
|
||||
<< "\n==> photoreceptorsSpatialConstant : " << _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant
|
||||
<< "\n==> horizontalCellsGain : " << _retinaParameters.OPLandIplParvo.horizontalCellsGain
|
||||
<< "\n==> hcellsTemporalConstant : " << _retinaParameters.OPLandIplParvo.hcellsTemporalConstant
|
||||
<< "\n==> hcellsSpatialConstant : " << _retinaParameters.OPLandIplParvo.hcellsSpatialConstant
|
||||
<< "\n==> parvoGanglionCellsSensitivity : " << _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity
|
||||
<<"}\n";
|
||||
// displaying OPL and IPL parvo setup
|
||||
outmessage<<"Current Retina instance setup :"
|
||||
<<"\nOPLandIPLparvo"<<"{"
|
||||
<< "\n==> colorMode : " << _retinaParameters.OPLandIplParvo.colorMode
|
||||
<< "\n==> normalizeParvoOutput :" << _retinaParameters.OPLandIplParvo.normaliseOutput
|
||||
<< "\n==> photoreceptorsLocalAdaptationSensitivity : " << _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity
|
||||
<< "\n==> photoreceptorsTemporalConstant : " << _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant
|
||||
<< "\n==> photoreceptorsSpatialConstant : " << _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant
|
||||
<< "\n==> horizontalCellsGain : " << _retinaParameters.OPLandIplParvo.horizontalCellsGain
|
||||
<< "\n==> hcellsTemporalConstant : " << _retinaParameters.OPLandIplParvo.hcellsTemporalConstant
|
||||
<< "\n==> hcellsSpatialConstant : " << _retinaParameters.OPLandIplParvo.hcellsSpatialConstant
|
||||
<< "\n==> parvoGanglionCellsSensitivity : " << _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity
|
||||
<<"}\n";
|
||||
|
||||
// displaying IPL magno setup
|
||||
outmessage<<"Current Retina instance setup :"
|
||||
<<"\nIPLmagno"<<"{"
|
||||
<< "\n==> normaliseOutput : " << _retinaParameters.IplMagno.normaliseOutput
|
||||
<< "\n==> parasolCells_beta : " << _retinaParameters.IplMagno.parasolCells_beta
|
||||
<< "\n==> parasolCells_tau : " << _retinaParameters.IplMagno.parasolCells_tau
|
||||
<< "\n==> parasolCells_k : " << _retinaParameters.IplMagno.parasolCells_k
|
||||
<< "\n==> amacrinCellsTemporalCutFrequency : " << _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency
|
||||
<< "\n==> V0CompressionParameter : " << _retinaParameters.IplMagno.V0CompressionParameter
|
||||
<< "\n==> localAdaptintegration_tau : " << _retinaParameters.IplMagno.localAdaptintegration_tau
|
||||
<< "\n==> localAdaptintegration_k : " << _retinaParameters.IplMagno.localAdaptintegration_k
|
||||
<<"}";
|
||||
return outmessage.str();
|
||||
// displaying IPL magno setup
|
||||
outmessage<<"Current Retina instance setup :"
|
||||
<<"\nIPLmagno"<<"{"
|
||||
<< "\n==> normaliseOutput : " << _retinaParameters.IplMagno.normaliseOutput
|
||||
<< "\n==> parasolCells_beta : " << _retinaParameters.IplMagno.parasolCells_beta
|
||||
<< "\n==> parasolCells_tau : " << _retinaParameters.IplMagno.parasolCells_tau
|
||||
<< "\n==> parasolCells_k : " << _retinaParameters.IplMagno.parasolCells_k
|
||||
<< "\n==> amacrinCellsTemporalCutFrequency : " << _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency
|
||||
<< "\n==> V0CompressionParameter : " << _retinaParameters.IplMagno.V0CompressionParameter
|
||||
<< "\n==> localAdaptintegration_tau : " << _retinaParameters.IplMagno.localAdaptintegration_tau
|
||||
<< "\n==> localAdaptintegration_k : " << _retinaParameters.IplMagno.localAdaptintegration_k
|
||||
<<"}";
|
||||
return outmessage.str();
|
||||
}
|
||||
|
||||
void Retina::write( std::string fs ) const
|
||||
@ -240,98 +240,98 @@ void Retina::write( std::string fs ) const
|
||||
|
||||
void Retina::write( FileStorage& fs ) const
|
||||
{
|
||||
if (!fs.isOpened())
|
||||
return; // basic error case
|
||||
fs<<"OPLandIPLparvo"<<"{";
|
||||
fs << "colorMode" << _retinaParameters.OPLandIplParvo.colorMode;
|
||||
fs << "normaliseOutput" << _retinaParameters.OPLandIplParvo.normaliseOutput;
|
||||
fs << "photoreceptorsLocalAdaptationSensitivity" << _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity;
|
||||
fs << "photoreceptorsTemporalConstant" << _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant;
|
||||
fs << "photoreceptorsSpatialConstant" << _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant;
|
||||
fs << "horizontalCellsGain" << _retinaParameters.OPLandIplParvo.horizontalCellsGain;
|
||||
fs << "hcellsTemporalConstant" << _retinaParameters.OPLandIplParvo.hcellsTemporalConstant;
|
||||
fs << "hcellsSpatialConstant" << _retinaParameters.OPLandIplParvo.hcellsSpatialConstant;
|
||||
fs << "ganglionCellsSensitivity" << _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity;
|
||||
fs << "}";
|
||||
fs<<"IPLmagno"<<"{";
|
||||
fs << "normaliseOutput" << _retinaParameters.IplMagno.normaliseOutput;
|
||||
fs << "parasolCells_beta" << _retinaParameters.IplMagno.parasolCells_beta;
|
||||
fs << "parasolCells_tau" << _retinaParameters.IplMagno.parasolCells_tau;
|
||||
fs << "parasolCells_k" << _retinaParameters.IplMagno.parasolCells_k;
|
||||
fs << "amacrinCellsTemporalCutFrequency" << _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency;
|
||||
fs << "V0CompressionParameter" << _retinaParameters.IplMagno.V0CompressionParameter;
|
||||
fs << "localAdaptintegration_tau" << _retinaParameters.IplMagno.localAdaptintegration_tau;
|
||||
fs << "localAdaptintegration_k" << _retinaParameters.IplMagno.localAdaptintegration_k;
|
||||
fs<<"}";
|
||||
if (!fs.isOpened())
|
||||
return; // basic error case
|
||||
fs<<"OPLandIPLparvo"<<"{";
|
||||
fs << "colorMode" << _retinaParameters.OPLandIplParvo.colorMode;
|
||||
fs << "normaliseOutput" << _retinaParameters.OPLandIplParvo.normaliseOutput;
|
||||
fs << "photoreceptorsLocalAdaptationSensitivity" << _retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity;
|
||||
fs << "photoreceptorsTemporalConstant" << _retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant;
|
||||
fs << "photoreceptorsSpatialConstant" << _retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant;
|
||||
fs << "horizontalCellsGain" << _retinaParameters.OPLandIplParvo.horizontalCellsGain;
|
||||
fs << "hcellsTemporalConstant" << _retinaParameters.OPLandIplParvo.hcellsTemporalConstant;
|
||||
fs << "hcellsSpatialConstant" << _retinaParameters.OPLandIplParvo.hcellsSpatialConstant;
|
||||
fs << "ganglionCellsSensitivity" << _retinaParameters.OPLandIplParvo.ganglionCellsSensitivity;
|
||||
fs << "}";
|
||||
fs<<"IPLmagno"<<"{";
|
||||
fs << "normaliseOutput" << _retinaParameters.IplMagno.normaliseOutput;
|
||||
fs << "parasolCells_beta" << _retinaParameters.IplMagno.parasolCells_beta;
|
||||
fs << "parasolCells_tau" << _retinaParameters.IplMagno.parasolCells_tau;
|
||||
fs << "parasolCells_k" << _retinaParameters.IplMagno.parasolCells_k;
|
||||
fs << "amacrinCellsTemporalCutFrequency" << _retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency;
|
||||
fs << "V0CompressionParameter" << _retinaParameters.IplMagno.V0CompressionParameter;
|
||||
fs << "localAdaptintegration_tau" << _retinaParameters.IplMagno.localAdaptintegration_tau;
|
||||
fs << "localAdaptintegration_k" << _retinaParameters.IplMagno.localAdaptintegration_k;
|
||||
fs<<"}";
|
||||
}
|
||||
|
||||
void Retina::setupOPLandIPLParvoChannel(const bool colorMode, const bool normaliseOutput, const float photoreceptorsLocalAdaptationSensitivity, const float photoreceptorsTemporalConstant, const float photoreceptorsSpatialConstant, const float horizontalCellsGain, const float HcellsTemporalConstant, const float HcellsSpatialConstant, const float ganglionCellsSensitivity)
|
||||
{
|
||||
// retina core parameters setup
|
||||
_retinaFilter->setColorMode(colorMode);
|
||||
_retinaFilter->setPhotoreceptorsLocalAdaptationSensitivity(photoreceptorsLocalAdaptationSensitivity);
|
||||
_retinaFilter->setOPLandParvoParameters(0, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, HcellsTemporalConstant, HcellsSpatialConstant, ganglionCellsSensitivity);
|
||||
_retinaFilter->setParvoGanglionCellsLocalAdaptationSensitivity(ganglionCellsSensitivity);
|
||||
_retinaFilter->activateNormalizeParvoOutput_0_maxOutputValue(normaliseOutput);
|
||||
// retina core parameters setup
|
||||
_retinaFilter->setColorMode(colorMode);
|
||||
_retinaFilter->setPhotoreceptorsLocalAdaptationSensitivity(photoreceptorsLocalAdaptationSensitivity);
|
||||
_retinaFilter->setOPLandParvoParameters(0, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, HcellsTemporalConstant, HcellsSpatialConstant, ganglionCellsSensitivity);
|
||||
_retinaFilter->setParvoGanglionCellsLocalAdaptationSensitivity(ganglionCellsSensitivity);
|
||||
_retinaFilter->activateNormalizeParvoOutput_0_maxOutputValue(normaliseOutput);
|
||||
|
||||
// update parameters struture
|
||||
|
||||
_retinaParameters.OPLandIplParvo.colorMode = colorMode;
|
||||
_retinaParameters.OPLandIplParvo.normaliseOutput = normaliseOutput;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity = photoreceptorsLocalAdaptationSensitivity;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant = photoreceptorsTemporalConstant;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant = photoreceptorsSpatialConstant;
|
||||
_retinaParameters.OPLandIplParvo.horizontalCellsGain = horizontalCellsGain;
|
||||
_retinaParameters.OPLandIplParvo.hcellsTemporalConstant = HcellsTemporalConstant;
|
||||
_retinaParameters.OPLandIplParvo.hcellsSpatialConstant = HcellsSpatialConstant;
|
||||
_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity = ganglionCellsSensitivity;
|
||||
_retinaParameters.OPLandIplParvo.colorMode = colorMode;
|
||||
_retinaParameters.OPLandIplParvo.normaliseOutput = normaliseOutput;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsLocalAdaptationSensitivity = photoreceptorsLocalAdaptationSensitivity;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsTemporalConstant = photoreceptorsTemporalConstant;
|
||||
_retinaParameters.OPLandIplParvo.photoreceptorsSpatialConstant = photoreceptorsSpatialConstant;
|
||||
_retinaParameters.OPLandIplParvo.horizontalCellsGain = horizontalCellsGain;
|
||||
_retinaParameters.OPLandIplParvo.hcellsTemporalConstant = HcellsTemporalConstant;
|
||||
_retinaParameters.OPLandIplParvo.hcellsSpatialConstant = HcellsSpatialConstant;
|
||||
_retinaParameters.OPLandIplParvo.ganglionCellsSensitivity = ganglionCellsSensitivity;
|
||||
|
||||
}
|
||||
|
||||
void Retina::setupIPLMagnoChannel(const bool normaliseOutput, const float parasolCells_beta, const float parasolCells_tau, const float parasolCells_k, const float amacrinCellsTemporalCutFrequency, const float V0CompressionParameter, const float localAdaptintegration_tau, const float localAdaptintegration_k)
|
||||
{
|
||||
|
||||
_retinaFilter->setMagnoCoefficientsTable(parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k);
|
||||
_retinaFilter->activateNormalizeMagnoOutput_0_maxOutputValue(normaliseOutput);
|
||||
_retinaFilter->setMagnoCoefficientsTable(parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k);
|
||||
_retinaFilter->activateNormalizeMagnoOutput_0_maxOutputValue(normaliseOutput);
|
||||
|
||||
// update parameters struture
|
||||
_retinaParameters.IplMagno.normaliseOutput = normaliseOutput;
|
||||
_retinaParameters.IplMagno.parasolCells_beta = parasolCells_beta;
|
||||
_retinaParameters.IplMagno.parasolCells_tau = parasolCells_tau;
|
||||
_retinaParameters.IplMagno.parasolCells_k = parasolCells_k;
|
||||
_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency = amacrinCellsTemporalCutFrequency;
|
||||
_retinaParameters.IplMagno.V0CompressionParameter = V0CompressionParameter;
|
||||
_retinaParameters.IplMagno.localAdaptintegration_tau = localAdaptintegration_tau;
|
||||
_retinaParameters.IplMagno.localAdaptintegration_k = localAdaptintegration_k;
|
||||
_retinaParameters.IplMagno.normaliseOutput = normaliseOutput;
|
||||
_retinaParameters.IplMagno.parasolCells_beta = parasolCells_beta;
|
||||
_retinaParameters.IplMagno.parasolCells_tau = parasolCells_tau;
|
||||
_retinaParameters.IplMagno.parasolCells_k = parasolCells_k;
|
||||
_retinaParameters.IplMagno.amacrinCellsTemporalCutFrequency = amacrinCellsTemporalCutFrequency;
|
||||
_retinaParameters.IplMagno.V0CompressionParameter = V0CompressionParameter;
|
||||
_retinaParameters.IplMagno.localAdaptintegration_tau = localAdaptintegration_tau;
|
||||
_retinaParameters.IplMagno.localAdaptintegration_k = localAdaptintegration_k;
|
||||
}
|
||||
|
||||
void Retina::run(const cv::Mat &inputMatToConvert)
|
||||
{
|
||||
// first convert input image to the compatible format : std::valarray<float>
|
||||
const bool colorMode = _convertCvMat2ValarrayBuffer(inputMatToConvert, _inputBuffer);
|
||||
// process the retina
|
||||
if (!_retinaFilter->runFilter(_inputBuffer, colorMode, false, _retinaParameters.OPLandIplParvo.colorMode && colorMode, false))
|
||||
throw cv::Exception(-1, "Retina cannot be applied, wrong input buffer size", "Retina::run", "Retina.h", 0);
|
||||
// first convert input image to the compatible format : std::valarray<float>
|
||||
const bool colorMode = _convertCvMat2ValarrayBuffer(inputMatToConvert, _inputBuffer);
|
||||
// process the retina
|
||||
if (!_retinaFilter->runFilter(_inputBuffer, colorMode, false, _retinaParameters.OPLandIplParvo.colorMode && colorMode, false))
|
||||
throw cv::Exception(-1, "Retina cannot be applied, wrong input buffer size", "Retina::run", "Retina.h", 0);
|
||||
}
|
||||
|
||||
void Retina::getParvo(cv::Mat &retinaOutput_parvo)
|
||||
{
|
||||
if (_retinaFilter->getColorMode())
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getColorOutput(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), true, retinaOutput_parvo);
|
||||
}else
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getContours(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), false, retinaOutput_parvo);
|
||||
}
|
||||
//retinaOutput_parvo/=255.0;
|
||||
if (_retinaFilter->getColorMode())
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getColorOutput(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), true, retinaOutput_parvo);
|
||||
}else
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getContours(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), false, retinaOutput_parvo);
|
||||
}
|
||||
//retinaOutput_parvo/=255.0;
|
||||
}
|
||||
void Retina::getMagno(cv::Mat &retinaOutput_magno)
|
||||
{
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getMovingContours(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), false, retinaOutput_magno);
|
||||
//retinaOutput_magno/=255.0;
|
||||
// reallocate output buffer (if necessary)
|
||||
_convertValarrayBuffer2cvMat(_retinaFilter->getMovingContours(), _retinaFilter->getOutputNBrows(), _retinaFilter->getOutputNBcolumns(), false, retinaOutput_magno);
|
||||
//retinaOutput_magno/=255.0;
|
||||
}
|
||||
|
||||
// original API level data accessors : copy buffers if size matches
|
||||
@ -342,109 +342,111 @@ const std::valarray<float> & Retina::getMagno() const {return _retinaFilter->get
|
||||
const std::valarray<float> & Retina::getParvo() const {if (_retinaFilter->getColorMode())return _retinaFilter->getColorOutput(); /* implicite else */return _retinaFilter->getContours();}
|
||||
|
||||
// private method called by constructirs
|
||||
void Retina::_init(const cv::Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
void Retina::_init(const cv::Size inputSz, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod, const bool useRetinaLogSampling, const double reductionFactor, const double samplingStrenght)
|
||||
{
|
||||
// basic error check
|
||||
if (inputSize.height*inputSize.width <= 0)
|
||||
throw cv::Exception(-1, "Bad retina size setup : size height and with must be superior to zero", "Retina::setup", "Retina.h", 0);
|
||||
// basic error check
|
||||
if (inputSz.height*inputSz.width <= 0)
|
||||
throw cv::Exception(-1, "Bad retina size setup : size height and with must be superior to zero", "Retina::setup", "Retina.h", 0);
|
||||
|
||||
unsigned int nbPixels=inputSize.height*inputSize.width;
|
||||
// resize buffers if size does not match
|
||||
_inputBuffer.resize(nbPixels*3); // buffer supports gray images but also 3 channels color buffers... (larger is better...)
|
||||
unsigned int nbPixels=inputSz.height*inputSz.width;
|
||||
// resize buffers if size does not match
|
||||
_inputBuffer.resize(nbPixels*3); // buffer supports gray images but also 3 channels color buffers... (larger is better...)
|
||||
|
||||
// allocate the retina model
|
||||
// allocate the retina model
|
||||
if (_retinaFilter)
|
||||
delete _retinaFilter;
|
||||
_retinaFilter = new RetinaFilter(inputSize.height, inputSize.width, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
_retinaFilter = new RetinaFilter(inputSz.height, inputSz.width, colorMode, colorSamplingMethod, useRetinaLogSampling, reductionFactor, samplingStrenght);
|
||||
|
||||
// prepare the default parameter XML file with default setup
|
||||
// prepare the default parameter XML file with default setup
|
||||
setup(_retinaParameters);
|
||||
|
||||
// init retina
|
||||
_retinaFilter->clearAllBuffers();
|
||||
// init retina
|
||||
_retinaFilter->clearAllBuffers();
|
||||
|
||||
// report current configuration
|
||||
std::cout<<printSetup()<<std::endl;
|
||||
// report current configuration
|
||||
std::cout<<printSetup()<<std::endl;
|
||||
}
|
||||
|
||||
void Retina::_convertValarrayBuffer2cvMat(const std::valarray<float> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, const bool colorMode, cv::Mat &outBuffer)
|
||||
{
|
||||
// fill output buffer with the valarray buffer
|
||||
const float *valarrayPTR=get_data(grayMatrixToConvert);
|
||||
if (!colorMode)
|
||||
{
|
||||
outBuffer.create(cv::Size(nbColumns, nbRows), CV_8U);
|
||||
for (unsigned int i=0;i<nbRows;++i)
|
||||
{
|
||||
for (unsigned int j=0;j<nbColumns;++j)
|
||||
{
|
||||
cv::Point2d pixel(j,i);
|
||||
outBuffer.at<unsigned char>(pixel)=(unsigned char)*(valarrayPTR++);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
const unsigned int doubleNBpixels=_retinaFilter->getOutputNBpixels()*2;
|
||||
outBuffer.create(cv::Size(nbColumns, nbRows), CV_8UC3);
|
||||
for (unsigned int i=0;i<nbRows;++i)
|
||||
{
|
||||
for (unsigned int j=0;j<nbColumns;++j,++valarrayPTR)
|
||||
{
|
||||
cv::Point2d pixel(j,i);
|
||||
cv::Vec3b pixelValues;
|
||||
pixelValues[2]=(unsigned char)*(valarrayPTR);
|
||||
pixelValues[1]=(unsigned char)*(valarrayPTR+_retinaFilter->getOutputNBpixels());
|
||||
pixelValues[0]=(unsigned char)*(valarrayPTR+doubleNBpixels);
|
||||
// fill output buffer with the valarray buffer
|
||||
const float *valarrayPTR=get_data(grayMatrixToConvert);
|
||||
if (!colorMode)
|
||||
{
|
||||
outBuffer.create(cv::Size(nbColumns, nbRows), CV_8U);
|
||||
for (unsigned int i=0;i<nbRows;++i)
|
||||
{
|
||||
for (unsigned int j=0;j<nbColumns;++j)
|
||||
{
|
||||
cv::Point2d pixel(j,i);
|
||||
outBuffer.at<unsigned char>(pixel)=(unsigned char)*(valarrayPTR++);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
const unsigned int doubleNBpixels=_retinaFilter->getOutputNBpixels()*2;
|
||||
outBuffer.create(cv::Size(nbColumns, nbRows), CV_8UC3);
|
||||
for (unsigned int i=0;i<nbRows;++i)
|
||||
{
|
||||
for (unsigned int j=0;j<nbColumns;++j,++valarrayPTR)
|
||||
{
|
||||
cv::Point2d pixel(j,i);
|
||||
cv::Vec3b pixelValues;
|
||||
pixelValues[2]=(unsigned char)*(valarrayPTR);
|
||||
pixelValues[1]=(unsigned char)*(valarrayPTR+_retinaFilter->getOutputNBpixels());
|
||||
pixelValues[0]=(unsigned char)*(valarrayPTR+doubleNBpixels);
|
||||
|
||||
outBuffer.at<cv::Vec3b>(pixel)=pixelValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
outBuffer.at<cv::Vec3b>(pixel)=pixelValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Retina::_convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, std::valarray<float> &outputValarrayMatrix)
|
||||
{
|
||||
// first check input consistency
|
||||
if (inputMatToConvert.empty())
|
||||
throw cv::Exception(-1, "Retina cannot be applied, input buffer is empty", "Retina::run", "Retina.h", 0);
|
||||
// first check input consistency
|
||||
if (inputMatToConvert.empty())
|
||||
throw cv::Exception(-1, "Retina cannot be applied, input buffer is empty", "Retina::run", "Retina.h", 0);
|
||||
|
||||
// retreive color mode from image input
|
||||
int imageNumberOfChannels = inputMatToConvert.channels();
|
||||
// retreive color mode from image input
|
||||
int imageNumberOfChannels = inputMatToConvert.channels();
|
||||
|
||||
// convert to float AND fill the valarray buffer
|
||||
typedef float T; // define here the target pixel format, here, float
|
||||
typedef float T; // define here the target pixel format, here, float
|
||||
const int dsttype = DataType<T>::depth; // output buffer is float format
|
||||
|
||||
|
||||
if(imageNumberOfChannels==4)
|
||||
if(imageNumberOfChannels==4)
|
||||
{
|
||||
// create a cv::Mat table (for RGBA planes)
|
||||
cv::Mat planes[4] =
|
||||
{
|
||||
// create a cv::Mat table (for RGBA planes)
|
||||
cv::Mat planes[] =
|
||||
{
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()*2]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype) // last channel (alpha) does not point on the valarray (not usefull in our case)
|
||||
};
|
||||
// split color cv::Mat in 4 planes... it fills valarray directely
|
||||
cv::split(cv::Mat_<Vec<T, 4> >(inputMatToConvert), planes);
|
||||
}else if (imageNumberOfChannels==3)
|
||||
{
|
||||
// create a cv::Mat table (for RGB planes)
|
||||
cv::Mat planes[] =
|
||||
{
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()*2]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0])
|
||||
};
|
||||
// split color cv::Mat in 3 planes... it fills valarray directely
|
||||
cv::split(cv::Mat_<Vec<T, 3> >(inputMatToConvert), planes);
|
||||
}else if(imageNumberOfChannels==1)
|
||||
{
|
||||
// create a cv::Mat header for the valarray
|
||||
cv::Mat dst(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0]);
|
||||
inputMatToConvert.convertTo(dst, dsttype);
|
||||
}
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()*2]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0])
|
||||
};
|
||||
planes[3] = cv::Mat(inputMatToConvert.size(), dsttype); // last channel (alpha) does not point on the valarray (not usefull in our case)
|
||||
// split color cv::Mat in 4 planes... it fills valarray directely
|
||||
cv::split(cv::Mat_<Vec<T, 4> >(inputMatToConvert), planes);
|
||||
}
|
||||
else if (imageNumberOfChannels==3)
|
||||
{
|
||||
// create a cv::Mat table (for RGB planes)
|
||||
cv::Mat planes[] =
|
||||
{
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()*2]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[_retinaFilter->getInputNBpixels()]),
|
||||
cv::Mat(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0])
|
||||
};
|
||||
// split color cv::Mat in 3 planes... it fills valarray directely
|
||||
cv::split(cv::Mat_<Vec<T, 3> >(inputMatToConvert), planes);
|
||||
}
|
||||
else if(imageNumberOfChannels==1)
|
||||
{
|
||||
// create a cv::Mat header for the valarray
|
||||
cv::Mat dst(inputMatToConvert.size(), dsttype, &outputValarrayMatrix[0]);
|
||||
inputMatToConvert.convertTo(dst, dsttype);
|
||||
}
|
||||
else
|
||||
CV_Error(CV_StsUnsupportedFormat, "input image must be single channel (gray levels), bgr format (color) or bgra (color with transparency which won't be considered");
|
||||
|
||||
|
@ -325,15 +325,15 @@ void RetinaColor::runColorDemultiplexing(const std::valarray<float> &multiplexed
|
||||
|
||||
}else
|
||||
{
|
||||
register const float *multiplexedColorFramePTR= get_data(multiplexedColorFrame);
|
||||
for (unsigned int indexc=0; indexc<_filterOutput.getNBpixels() ; ++indexc, ++chrominancePTR, ++colorLocalDensityPTR, ++luminance, ++multiplexedColorFramePTR)
|
||||
register const float *multiplexedColorFramePTR1= get_data(multiplexedColorFrame);
|
||||
for (unsigned int indexc=0; indexc<_filterOutput.getNBpixels() ; ++indexc, ++chrominancePTR, ++colorLocalDensityPTR, ++luminance, ++multiplexedColorFramePTR1)
|
||||
{
|
||||
// normalize by photoreceptors density
|
||||
float Cr=*(chrominancePTR)*_colorLocalDensity[indexc];
|
||||
float Cg=*(chrominancePTR+_filterOutput.getNBpixels())*_colorLocalDensity[indexc+_filterOutput.getNBpixels()];
|
||||
float Cb=*(chrominancePTR+_filterOutput.getDoubleNBpixels())*_colorLocalDensity[indexc+_filterOutput.getDoubleNBpixels()];
|
||||
*luminance=(Cr+Cg+Cb)*_pG;
|
||||
_demultiplexedTempBuffer[_colorSampling[indexc]] = *multiplexedColorFramePTR - *luminance;
|
||||
_demultiplexedTempBuffer[_colorSampling[indexc]] = *multiplexedColorFramePTR1 - *luminance;
|
||||
|
||||
}
|
||||
|
||||
|
@ -336,18 +336,18 @@ void computeSpinImages( const Octree& Octree, const vector<Point3f>& points, con
|
||||
__m128 f1f2 = _mm_mul_ps(f1, f2); // f1 * f2
|
||||
__m128 omf1omf2 = _mm_add_ps(_mm_sub_ps(_mm_sub_ps(one4f, f2), f1), f1f2); // (1-f1) * (1-f2)
|
||||
|
||||
__m128i mask = _mm_and_si128(
|
||||
__m128i _mask = _mm_and_si128(
|
||||
_mm_andnot_si128(_mm_cmpgt_epi32(zero4, n1), _mm_cmpgt_epi32(height4m1, n1)),
|
||||
_mm_andnot_si128(_mm_cmpgt_epi32(zero4, n2), _mm_cmpgt_epi32(width4m1, n2)));
|
||||
|
||||
__m128 maskf = _mm_cmpneq_ps(_mm_cvtepi32_ps(mask), zero4f);
|
||||
__m128 maskf = _mm_cmpneq_ps(_mm_cvtepi32_ps(_mask), zero4f);
|
||||
|
||||
__m128 v00 = _mm_and_ps( omf1omf2 , maskf); // a00 b00 c00 d00
|
||||
__m128 v01 = _mm_and_ps( _mm_sub_ps( f2, f1f2 ), maskf); // a01 b01 c01 d01
|
||||
__m128 v10 = _mm_and_ps( _mm_sub_ps( f1, f1f2 ), maskf); // a10 b10 c10 d10
|
||||
__m128 v11 = _mm_and_ps( f1f2 , maskf); // a11 b11 c11 d11
|
||||
|
||||
__m128i ofs4 = _mm_and_si128(_mm_add_epi32(_mm_mullo_epi32_emul(n1, step4), n2), mask);
|
||||
__m128i ofs4 = _mm_and_si128(_mm_add_epi32(_mm_mullo_epi32_emul(n1, step4), n2), _mask);
|
||||
_mm_store_si128((__m128i*)o, ofs4);
|
||||
|
||||
__m128 t0 = _mm_unpacklo_ps(v00, v01); // a00 a01 b00 b01
|
||||
@ -504,16 +504,16 @@ void cv::Mesh3D::writeAsVrml(const String& file, const vector<Scalar>& _colors)
|
||||
ofstream ofs(file.c_str());
|
||||
|
||||
ofs << "#VRML V2.0 utf8" << endl;
|
||||
ofs << "Shape" << std::endl << "{" << endl;
|
||||
ofs << "geometry PointSet" << endl << "{" << endl;
|
||||
ofs << "coord Coordinate" << endl << "{" << endl;
|
||||
ofs << "point[" << endl;
|
||||
ofs << "Shape" << std::endl << "{" << endl;
|
||||
ofs << "geometry PointSet" << endl << "{" << endl;
|
||||
ofs << "coord Coordinate" << endl << "{" << endl;
|
||||
ofs << "point[" << endl;
|
||||
|
||||
for(size_t i = 0; i < vtx.size(); ++i)
|
||||
ofs << vtx[i].x << " " << vtx[i].y << " " << vtx[i].z << endl;
|
||||
|
||||
ofs << "]" << endl; //point[
|
||||
ofs << "}" << endl; //Coordinate{
|
||||
ofs << "]" << endl; //point[
|
||||
ofs << "}" << endl; //Coordinate{
|
||||
|
||||
if (vtx.size() == _colors.size())
|
||||
{
|
||||
@ -524,11 +524,11 @@ void cv::Mesh3D::writeAsVrml(const String& file, const vector<Scalar>& _colors)
|
||||
ofs << (float)_colors[i][2] << " " << (float)_colors[i][1] << " " << (float)_colors[i][0] << endl;
|
||||
|
||||
ofs << "]" << endl; //color[
|
||||
ofs << "}" << endl; //color Color{
|
||||
ofs << "}" << endl; //color Color{
|
||||
}
|
||||
|
||||
ofs << "}" << endl; //PointSet{
|
||||
ofs << "}" << endl; //Shape{
|
||||
ofs << "}" << endl; //PointSet{
|
||||
ofs << "}" << endl; //Shape{
|
||||
}
|
||||
|
||||
|
||||
@ -808,7 +808,7 @@ void cv::SpinImageModel::selectRandomSubset(float ratio)
|
||||
subset.resize(setSize);
|
||||
for(size_t i = 0; i < setSize; ++i)
|
||||
{
|
||||
int pos = rnd.next() % left.size();
|
||||
int pos = rnd.next() % (int)left.size();
|
||||
subset[i] = (int)left[pos];
|
||||
|
||||
left[pos] = left.back();
|
||||
@ -823,21 +823,21 @@ void cv::SpinImageModel::setSubset(const vector<int>& ss)
|
||||
subset = ss;
|
||||
}
|
||||
|
||||
void cv::SpinImageModel::repackSpinImages(const vector<uchar>& mask, Mat& spinImages, bool reAlloc) const
|
||||
void cv::SpinImageModel::repackSpinImages(const vector<uchar>& mask, Mat& _spinImages, bool reAlloc) const
|
||||
{
|
||||
if (reAlloc)
|
||||
{
|
||||
size_t spinCount = mask.size() - count(mask.begin(), mask.end(), (uchar)0);
|
||||
Mat newImgs((int)spinCount, spinImages.cols, spinImages.type());
|
||||
Mat newImgs((int)spinCount, _spinImages.cols, _spinImages.type());
|
||||
|
||||
int pos = 0;
|
||||
for(size_t t = 0; t < mask.size(); ++t)
|
||||
if (mask[t])
|
||||
{
|
||||
Mat row = newImgs.row(pos++);
|
||||
spinImages.row((int)t).copyTo(row);
|
||||
_spinImages.row((int)t).copyTo(row);
|
||||
}
|
||||
spinImages = newImgs;
|
||||
_spinImages = newImgs;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -849,13 +849,13 @@ void cv::SpinImageModel::repackSpinImages(const vector<uchar>& mask, Mat& spinIm
|
||||
|
||||
int first = dest + 1;
|
||||
for (; first != last; ++first)
|
||||
if (mask[first] != 0)
|
||||
if (mask[first] != 0)
|
||||
{
|
||||
Mat row = spinImages.row(dest);
|
||||
spinImages.row(first).copyTo(row);
|
||||
Mat row = _spinImages.row(dest);
|
||||
_spinImages.row(first).copyTo(row);
|
||||
++dest;
|
||||
}
|
||||
spinImages = spinImages.rowRange(0, dest);
|
||||
_spinImages = _spinImages.rowRange(0, dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,9 +67,9 @@ StereoVar::~StereoVar()
|
||||
|
||||
static Mat diffX(Mat &src)
|
||||
{
|
||||
register int x, y, cols = src.cols - 1;
|
||||
Mat dst(src.size(), src.type());
|
||||
for(y = 0; y < src.rows; y++){
|
||||
register int x, y, cols = src.cols - 1;
|
||||
Mat dst(src.size(), src.type());
|
||||
for(y = 0; y < src.rows; y++){
|
||||
const float* pSrc = src.ptr<float>(y);
|
||||
float* pDst = dst.ptr<float>(y);
|
||||
#if CV_SSE2
|
||||
@ -92,319 +92,319 @@ static Mat diffX(Mat &src)
|
||||
|
||||
static Mat getGradient(Mat &src)
|
||||
{
|
||||
register int x, y;
|
||||
Mat dst(src.size(), src.type());
|
||||
dst.setTo(0);
|
||||
for (y = 0; y < src.rows - 1; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pSrcF = src.ptr<float>(y + 1);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (x = 0; x < src.cols - 1; x++)
|
||||
pDst[x] = fabs(pSrc[x + 1] - pSrc[x]) + fabs(pSrcF[x] - pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
register int x, y;
|
||||
Mat dst(src.size(), src.type());
|
||||
dst.setTo(0);
|
||||
for (y = 0; y < src.rows - 1; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pSrcF = src.ptr<float>(y + 1);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (x = 0; x < src.cols - 1; x++)
|
||||
pDst[x] = fabs(pSrc[x + 1] - pSrc[x]) + fabs(pSrcF[x] - pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static Mat getG_c(Mat &src, float l)
|
||||
{
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l / sqrtf(l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l / sqrtf(l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static Mat getG_p(Mat &src, float l)
|
||||
{
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l*l / (l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
Mat dst(src.size(), src.type());
|
||||
for (register int y = 0; y < src.rows; y++) {
|
||||
float *pSrc = src.ptr<float>(y);
|
||||
float *pDst = dst.ptr<float>(y);
|
||||
for (register int x = 0; x < src.cols; x++)
|
||||
pDst[x] = 0.5f*l*l / (l*l + pSrc[x]*pSrc[x]);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
void StereoVar::VariationalSolver(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level)
|
||||
{
|
||||
register int n, x, y;
|
||||
float gl = 1, gr = 1, gu = 1, gd = 1, gc = 4;
|
||||
Mat g_c, g_p;
|
||||
Mat U;
|
||||
u.copyTo(U);
|
||||
register int n, x, y;
|
||||
float gl = 1, gr = 1, gu = 1, gd = 1, gc = 4;
|
||||
Mat g_c, g_p;
|
||||
Mat U;
|
||||
u.copyTo(U);
|
||||
|
||||
int N = nIt;
|
||||
float l = lambda;
|
||||
float Fi = fi;
|
||||
int N = nIt;
|
||||
float l = lambda;
|
||||
float Fi = fi;
|
||||
|
||||
|
||||
if (flags & USE_SMART_ID) {
|
||||
double scale = pow(pyrScale, (double) level) * (1 + pyrScale);
|
||||
N = (int) (N / scale);
|
||||
}
|
||||
if (flags & USE_SMART_ID) {
|
||||
double scale = pow(pyrScale, (double) level) * (1 + pyrScale);
|
||||
N = (int) (N / scale);
|
||||
}
|
||||
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
Fi /= (float) scale;
|
||||
l *= (float) scale;
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
Fi /= (float) scale;
|
||||
l *= (float) scale;
|
||||
|
||||
int width = u.cols - 1;
|
||||
int height = u.rows - 1;
|
||||
for (n = 0; n < N; n++) {
|
||||
if (penalization != PENALIZATION_TICHONOV) {
|
||||
Mat gradient = getGradient(U);
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER: g_c = getG_c(gradient, l); break;
|
||||
case PENALIZATION_PERONA_MALIK: g_p = getG_p(gradient, l); break;
|
||||
}
|
||||
gradient.release();
|
||||
}
|
||||
for (y = 1 ; y < height; y++) {
|
||||
float *pU = U.ptr<float>(y);
|
||||
float *pUu = U.ptr<float>(y + 1);
|
||||
float *pUd = U.ptr<float>(y - 1);
|
||||
float *pu = u.ptr<float>(y);
|
||||
float *pI1 = I1.ptr<float>(y);
|
||||
float *pI2 = I2.ptr<float>(y);
|
||||
float *pI2x = I2x.ptr<float>(y);
|
||||
float *pG_c = NULL, *pG_cu = NULL, *pG_cd = NULL;
|
||||
float *pG_p = NULL, *pG_pu = NULL, *pG_pd = NULL;
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
pG_c = g_c.ptr<float>(y);
|
||||
pG_cu = g_c.ptr<float>(y + 1);
|
||||
pG_cd = g_c.ptr<float>(y - 1);
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
pG_p = g_p.ptr<float>(y);
|
||||
pG_pu = g_p.ptr<float>(y + 1);
|
||||
pG_pd = g_p.ptr<float>(y - 1);
|
||||
break;
|
||||
}
|
||||
for (x = 1; x < width; x++) {
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
gc = pG_c[x];
|
||||
gl = gc + pG_c[x - 1];
|
||||
gr = gc + pG_c[x + 1];
|
||||
gu = gc + pG_cu[x];
|
||||
gd = gc + pG_cd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
gc = pG_p[x];
|
||||
gl = gc + pG_p[x - 1];
|
||||
gr = gc + pG_p[x + 1];
|
||||
gu = gc + pG_pu[x];
|
||||
gd = gc + pG_pd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
}
|
||||
int width = u.cols - 1;
|
||||
int height = u.rows - 1;
|
||||
for (n = 0; n < N; n++) {
|
||||
if (penalization != PENALIZATION_TICHONOV) {
|
||||
Mat gradient = getGradient(U);
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER: g_c = getG_c(gradient, l); break;
|
||||
case PENALIZATION_PERONA_MALIK: g_p = getG_p(gradient, l); break;
|
||||
}
|
||||
gradient.release();
|
||||
}
|
||||
for (y = 1 ; y < height; y++) {
|
||||
float *pU = U.ptr<float>(y);
|
||||
float *pUu = U.ptr<float>(y + 1);
|
||||
float *pUd = U.ptr<float>(y - 1);
|
||||
float *pu = u.ptr<float>(y);
|
||||
float *pI1 = I1.ptr<float>(y);
|
||||
float *pI2 = I2.ptr<float>(y);
|
||||
float *pI2x = I2x.ptr<float>(y);
|
||||
float *pG_c = NULL, *pG_cu = NULL, *pG_cd = NULL;
|
||||
float *pG_p = NULL, *pG_pu = NULL, *pG_pd = NULL;
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
pG_c = g_c.ptr<float>(y);
|
||||
pG_cu = g_c.ptr<float>(y + 1);
|
||||
pG_cd = g_c.ptr<float>(y - 1);
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
pG_p = g_p.ptr<float>(y);
|
||||
pG_pu = g_p.ptr<float>(y + 1);
|
||||
pG_pd = g_p.ptr<float>(y - 1);
|
||||
break;
|
||||
}
|
||||
for (x = 1; x < width; x++) {
|
||||
switch (penalization) {
|
||||
case PENALIZATION_CHARBONNIER:
|
||||
gc = pG_c[x];
|
||||
gl = gc + pG_c[x - 1];
|
||||
gr = gc + pG_c[x + 1];
|
||||
gu = gc + pG_cu[x];
|
||||
gd = gc + pG_cd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
case PENALIZATION_PERONA_MALIK:
|
||||
gc = pG_p[x];
|
||||
gl = gc + pG_p[x - 1];
|
||||
gr = gc + pG_p[x + 1];
|
||||
gu = gc + pG_pu[x];
|
||||
gd = gc + pG_pd[x];
|
||||
gc = gl + gr + gu + gd;
|
||||
break;
|
||||
}
|
||||
|
||||
float fi = Fi;
|
||||
if (maxDisp > minDisp) {
|
||||
if (pU[x] > maxDisp * scale) {fi *= 1000; pU[x] = static_cast<float>(maxDisp * scale);}
|
||||
if (pU[x] < minDisp * scale) {fi *= 1000; pU[x] = static_cast<float>(minDisp * scale);}
|
||||
}
|
||||
float _fi = Fi;
|
||||
if (maxDisp > minDisp) {
|
||||
if (pU[x] > maxDisp * scale) {_fi *= 1000; pU[x] = static_cast<float>(maxDisp * scale);}
|
||||
if (pU[x] < minDisp * scale) {_fi *= 1000; pU[x] = static_cast<float>(minDisp * scale);}
|
||||
}
|
||||
|
||||
int A = static_cast<int>(pU[x]);
|
||||
int neg = 0; if (pU[x] <= 0) neg = -1;
|
||||
int A = static_cast<int>(pU[x]);
|
||||
int neg = 0; if (pU[x] <= 0) neg = -1;
|
||||
|
||||
if (x + A > width)
|
||||
pu[x] = pU[width - A];
|
||||
else if (x + A + neg < 0)
|
||||
pu[x] = pU[- A + 2];
|
||||
else {
|
||||
pu[x] = A + (pI2x[x + A + neg] * (pI1[x] - pI2[x + A])
|
||||
+ fi * (gr * pU[x + 1] + gl * pU[x - 1] + gu * pUu[x] + gd * pUd[x] - gc * A))
|
||||
/ (pI2x[x + A + neg] * pI2x[x + A + neg] + gc * fi) ;
|
||||
}
|
||||
}// x
|
||||
pu[0] = pu[1];
|
||||
pu[width] = pu[width - 1];
|
||||
}// y
|
||||
for (x = 0; x <= width; x++) {
|
||||
u.at<float>(0, x) = u.at<float>(1, x);
|
||||
u.at<float>(height, x) = u.at<float>(height - 1, x);
|
||||
}
|
||||
u.copyTo(U);
|
||||
if (!g_c.empty()) g_c.release();
|
||||
if (!g_p.empty()) g_p.release();
|
||||
}//n
|
||||
if (x + A > width)
|
||||
pu[x] = pU[width - A];
|
||||
else if (x + A + neg < 0)
|
||||
pu[x] = pU[- A + 2];
|
||||
else {
|
||||
pu[x] = A + (pI2x[x + A + neg] * (pI1[x] - pI2[x + A])
|
||||
+ _fi * (gr * pU[x + 1] + gl * pU[x - 1] + gu * pUu[x] + gd * pUd[x] - gc * A))
|
||||
/ (pI2x[x + A + neg] * pI2x[x + A + neg] + gc * _fi) ;
|
||||
}
|
||||
}// x
|
||||
pu[0] = pu[1];
|
||||
pu[width] = pu[width - 1];
|
||||
}// y
|
||||
for (x = 0; x <= width; x++) {
|
||||
u.at<float>(0, x) = u.at<float>(1, x);
|
||||
u.at<float>(height, x) = u.at<float>(height - 1, x);
|
||||
}
|
||||
u.copyTo(U);
|
||||
if (!g_c.empty()) g_c.release();
|
||||
if (!g_p.empty()) g_p.release();
|
||||
}//n
|
||||
}
|
||||
|
||||
void StereoVar::VCycle_MyFAS(Mat &I1, Mat &I2, Mat &I2x, Mat &_u, int level)
|
||||
{
|
||||
CvSize imgSize = _u.size();
|
||||
CvSize frmSize = cvSize((int) (imgSize.width * pyrScale + 0.5), (int) (imgSize.height * pyrScale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h, U, U_h;
|
||||
CvSize imgSize = _u.size();
|
||||
CvSize frmSize = cvSize((int) (imgSize.width * pyrScale + 0.5), (int) (imgSize.height * pyrScale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h, U, U_h;
|
||||
|
||||
//PRE relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level);
|
||||
//PRE relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level);
|
||||
|
||||
if (level >= levels - 1) return;
|
||||
level ++;
|
||||
if (level >= levels - 1) return;
|
||||
level ++;
|
||||
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(_u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), pyrScale);
|
||||
I2x_h = diffX(I2_h);
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(_u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), pyrScale);
|
||||
I2x_h = diffX(I2_h);
|
||||
|
||||
//Next level
|
||||
U_h = u_h.clone();
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, U_h, level);
|
||||
//Next level
|
||||
U_h = u_h.clone();
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, U_h, level);
|
||||
|
||||
subtract(U_h, u_h, U_h);
|
||||
U_h.convertTo(U_h, U_h.type(), 1.0 / pyrScale);
|
||||
subtract(U_h, u_h, U_h);
|
||||
U_h.convertTo(U_h, U_h.type(), 1.0 / pyrScale);
|
||||
|
||||
//scaling UP
|
||||
resize(U_h, U, imgSize);
|
||||
//scaling UP
|
||||
resize(U_h, U, imgSize);
|
||||
|
||||
//correcting the solution
|
||||
add(_u, U, _u);
|
||||
//correcting the solution
|
||||
add(_u, U, _u);
|
||||
|
||||
//POST relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level - 1);
|
||||
//POST relaxation
|
||||
VariationalSolver(I1, I2, I2x, _u, level - 1);
|
||||
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(_u, _u, 3);
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(_u, _u, 3);
|
||||
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
U.release();
|
||||
U_h.release();
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
U.release();
|
||||
U_h.release();
|
||||
}
|
||||
|
||||
void StereoVar::FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level)
|
||||
{
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
CvSize frmSize = cvSize((int) (u.cols * scale + 0.5), (int) (u.rows * scale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h;
|
||||
double scale = pow(pyrScale, (double) level);
|
||||
CvSize frmSize = cvSize((int) (u.cols * scale + 0.5), (int) (u.rows * scale + 0.5));
|
||||
Mat I1_h, I2_h, I2x_h, u_h;
|
||||
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), scale);
|
||||
I2x_h = diffX(I2_h);
|
||||
//scaling DOWN
|
||||
resize(I1, I1_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(I2, I2_h, frmSize, 0, 0, INTER_AREA);
|
||||
resize(u, u_h, frmSize, 0, 0, INTER_AREA);
|
||||
u_h.convertTo(u_h, u_h.type(), scale);
|
||||
I2x_h = diffX(I2_h);
|
||||
|
||||
switch (cycle) {
|
||||
case CYCLE_O:
|
||||
VariationalSolver(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
case CYCLE_V:
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
}
|
||||
switch (cycle) {
|
||||
case CYCLE_O:
|
||||
VariationalSolver(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
case CYCLE_V:
|
||||
VCycle_MyFAS(I1_h, I2_h, I2x_h, u_h, level);
|
||||
break;
|
||||
}
|
||||
|
||||
u_h.convertTo(u_h, u_h.type(), 1.0 / scale);
|
||||
u_h.convertTo(u_h, u_h.type(), 1.0 / scale);
|
||||
|
||||
//scaling UP
|
||||
resize(u_h, u, u.size(), 0, 0, INTER_CUBIC);
|
||||
//scaling UP
|
||||
resize(u_h, u, u.size(), 0, 0, INTER_CUBIC);
|
||||
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
I1_h.release();
|
||||
I2_h.release();
|
||||
I2x_h.release();
|
||||
u_h.release();
|
||||
|
||||
level--;
|
||||
if ((flags & USE_AUTO_PARAMS) && (level < levels / 3)) {
|
||||
penalization = PENALIZATION_PERONA_MALIK;
|
||||
fi *= 100;
|
||||
flags -= USE_AUTO_PARAMS;
|
||||
autoParams();
|
||||
}
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(u, u, 3);
|
||||
if (level >= 0) FMG(I1, I2, I2x, u, level);
|
||||
level--;
|
||||
if ((flags & USE_AUTO_PARAMS) && (level < levels / 3)) {
|
||||
penalization = PENALIZATION_PERONA_MALIK;
|
||||
fi *= 100;
|
||||
flags -= USE_AUTO_PARAMS;
|
||||
autoParams();
|
||||
}
|
||||
if (flags & USE_MEDIAN_FILTERING) medianBlur(u, u, 3);
|
||||
if (level >= 0) FMG(I1, I2, I2x, u, level);
|
||||
}
|
||||
|
||||
void StereoVar::autoParams()
|
||||
{
|
||||
int maxD = MAX(labs(maxDisp), labs(minDisp));
|
||||
int maxD = MAX(labs(maxDisp), labs(minDisp));
|
||||
|
||||
if (!maxD) pyrScale = 0.85;
|
||||
else if (maxD < 8) pyrScale = 0.5;
|
||||
else if (maxD < 64) pyrScale = 0.5 + static_cast<double>(maxD - 8) * 0.00625;
|
||||
else pyrScale = 0.85;
|
||||
if (!maxD) pyrScale = 0.85;
|
||||
else if (maxD < 8) pyrScale = 0.5;
|
||||
else if (maxD < 64) pyrScale = 0.5 + static_cast<double>(maxD - 8) * 0.00625;
|
||||
else pyrScale = 0.85;
|
||||
|
||||
if (maxD) {
|
||||
levels = 0;
|
||||
while ( pow(pyrScale, levels) * maxD > 1.5) levels ++;
|
||||
levels++;
|
||||
}
|
||||
if (maxD) {
|
||||
levels = 0;
|
||||
while ( pow(pyrScale, levels) * maxD > 1.5) levels ++;
|
||||
levels++;
|
||||
}
|
||||
|
||||
switch(penalization) {
|
||||
case PENALIZATION_TICHONOV: cycle = CYCLE_V; break;
|
||||
case PENALIZATION_CHARBONNIER: cycle = CYCLE_O; break;
|
||||
case PENALIZATION_PERONA_MALIK: cycle = CYCLE_O; break;
|
||||
}
|
||||
switch(penalization) {
|
||||
case PENALIZATION_TICHONOV: cycle = CYCLE_V; break;
|
||||
case PENALIZATION_CHARBONNIER: cycle = CYCLE_O; break;
|
||||
case PENALIZATION_PERONA_MALIK: cycle = CYCLE_O; break;
|
||||
}
|
||||
}
|
||||
|
||||
void StereoVar::operator ()( const Mat& left, const Mat& right, Mat& disp )
|
||||
{
|
||||
CV_Assert(left.size() == right.size() && left.type() == right.type());
|
||||
CvSize imgSize = left.size();
|
||||
int MaxD = MAX(labs(minDisp), labs(maxDisp));
|
||||
int SignD = 1; if (MIN(minDisp, maxDisp) < 0) SignD = -1;
|
||||
if (minDisp >= maxDisp) {MaxD = 256; SignD = 1;}
|
||||
CV_Assert(left.size() == right.size() && left.type() == right.type());
|
||||
CvSize imgSize = left.size();
|
||||
int MaxD = MAX(labs(minDisp), labs(maxDisp));
|
||||
int SignD = 1; if (MIN(minDisp, maxDisp) < 0) SignD = -1;
|
||||
if (minDisp >= maxDisp) {MaxD = 256; SignD = 1;}
|
||||
|
||||
Mat u;
|
||||
if ((flags & USE_INITIAL_DISPARITY) && (!disp.empty())) {
|
||||
CV_Assert(disp.size() == left.size() && disp.type() == CV_8UC1);
|
||||
disp.convertTo(u, CV_32FC1, static_cast<double>(SignD * MaxD) / 256);
|
||||
} else {
|
||||
u.create(imgSize, CV_32FC1);
|
||||
u.setTo(0);
|
||||
}
|
||||
Mat u;
|
||||
if ((flags & USE_INITIAL_DISPARITY) && (!disp.empty())) {
|
||||
CV_Assert(disp.size() == left.size() && disp.type() == CV_8UC1);
|
||||
disp.convertTo(u, CV_32FC1, static_cast<double>(SignD * MaxD) / 256);
|
||||
} else {
|
||||
u.create(imgSize, CV_32FC1);
|
||||
u.setTo(0);
|
||||
}
|
||||
|
||||
// Preprocessing
|
||||
Mat leftgray, rightgray;
|
||||
if (left.type() != CV_8UC1) {
|
||||
cvtColor(left, leftgray, CV_BGR2GRAY);
|
||||
cvtColor(right, rightgray, CV_BGR2GRAY);
|
||||
} else {
|
||||
left.copyTo(leftgray);
|
||||
right.copyTo(rightgray);
|
||||
}
|
||||
if (flags & USE_EQUALIZE_HIST) {
|
||||
equalizeHist(leftgray, leftgray);
|
||||
equalizeHist(rightgray, rightgray);
|
||||
}
|
||||
if (poly_sigma > 0.0001) {
|
||||
GaussianBlur(leftgray, leftgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
GaussianBlur(rightgray, rightgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
}
|
||||
// Preprocessing
|
||||
Mat leftgray, rightgray;
|
||||
if (left.type() != CV_8UC1) {
|
||||
cvtColor(left, leftgray, CV_BGR2GRAY);
|
||||
cvtColor(right, rightgray, CV_BGR2GRAY);
|
||||
} else {
|
||||
left.copyTo(leftgray);
|
||||
right.copyTo(rightgray);
|
||||
}
|
||||
if (flags & USE_EQUALIZE_HIST) {
|
||||
equalizeHist(leftgray, leftgray);
|
||||
equalizeHist(rightgray, rightgray);
|
||||
}
|
||||
if (poly_sigma > 0.0001) {
|
||||
GaussianBlur(leftgray, leftgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
GaussianBlur(rightgray, rightgray, cvSize(poly_n, poly_n), poly_sigma);
|
||||
}
|
||||
|
||||
if (flags & USE_AUTO_PARAMS) {
|
||||
penalization = PENALIZATION_TICHONOV;
|
||||
autoParams();
|
||||
}
|
||||
if (flags & USE_AUTO_PARAMS) {
|
||||
penalization = PENALIZATION_TICHONOV;
|
||||
autoParams();
|
||||
}
|
||||
|
||||
Mat I1, I2;
|
||||
leftgray.convertTo(I1, CV_32FC1);
|
||||
rightgray.convertTo(I2, CV_32FC1);
|
||||
leftgray.release();
|
||||
rightgray.release();
|
||||
Mat I1, I2;
|
||||
leftgray.convertTo(I1, CV_32FC1);
|
||||
rightgray.convertTo(I2, CV_32FC1);
|
||||
leftgray.release();
|
||||
rightgray.release();
|
||||
|
||||
Mat I2x = diffX(I2);
|
||||
Mat I2x = diffX(I2);
|
||||
|
||||
FMG(I1, I2, I2x, u, levels - 1);
|
||||
FMG(I1, I2, I2x, u, levels - 1);
|
||||
|
||||
I1.release();
|
||||
I2.release();
|
||||
I2x.release();
|
||||
I1.release();
|
||||
I2.release();
|
||||
I2x.release();
|
||||
|
||||
|
||||
disp.create( left.size(), CV_8UC1 );
|
||||
u = abs(u);
|
||||
u.convertTo(disp, disp.type(), 256 / MaxD, 0);
|
||||
disp.create( left.size(), CV_8UC1 );
|
||||
u = abs(u);
|
||||
u.convertTo(disp, disp.type(), 256 / MaxD, 0);
|
||||
|
||||
u.release();
|
||||
u.release();
|
||||
}
|
||||
} // namespace
|
@ -1,3 +1,7 @@
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
||||
#endif
|
||||
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
||||
#define __OPENCV_TEST_PRECOMP_HPP__
|
||||
|
||||
|
@ -6,8 +6,9 @@ if(HAVE_CUDA)
|
||||
file(GLOB lib_cuda "src/cuda/*.cu")
|
||||
source_group("Cuda" FILES "${lib_cuda}")
|
||||
|
||||
ocv_include_directories(${CUDA_INCLUDE_DIRS} "${OpenCV_SOURCE_DIR}/modules/gpu/src" "${OpenCV_SOURCE_DIR}/modules/gpu/src/cuda")
|
||||
OCV_CUDA_COMPILE(cuda_objs ${lib_cuda})
|
||||
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/src" "${OpenCV_SOURCE_DIR}/modules/gpu/src/cuda" ${CUDA_INCLUDE_DIRS})
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
|
||||
ocv_cuda_compile(cuda_objs ${lib_cuda})
|
||||
|
||||
set(cuda_link_libs ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
|
||||
else()
|
||||
|
@ -1299,6 +1299,7 @@ public:
|
||||
GPU_MAT = 9 << KIND_SHIFT
|
||||
};
|
||||
_InputArray();
|
||||
|
||||
_InputArray(const Mat& m);
|
||||
_InputArray(const MatExpr& expr);
|
||||
template<typename _Tp> _InputArray(const _Tp* vec, int n);
|
||||
@ -1328,6 +1329,10 @@ public:
|
||||
virtual int channels(int i=-1) const;
|
||||
virtual bool empty() const;
|
||||
|
||||
#ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
|
||||
virtual ~_InputArray();
|
||||
#endif
|
||||
|
||||
int flags;
|
||||
void* obj;
|
||||
Size sz;
|
||||
@ -1384,6 +1389,10 @@ public:
|
||||
virtual void create(int dims, const int* size, int type, int i=-1, bool allowTransposed=false, int fixedDepthMask=0) const;
|
||||
virtual void release() const;
|
||||
virtual void clear() const;
|
||||
|
||||
#ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
|
||||
virtual ~_OutputArray();
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef const _InputArray& InputArray;
|
||||
|
@ -666,7 +666,7 @@ CVAPI(int) cvSolveCubic( const CvMat* coeffs, CvMat* roots );
|
||||
|
||||
/* Finds all real and complex roots of a polynomial equation */
|
||||
CVAPI(void) cvSolvePoly(const CvMat* coeffs, CvMat *roots2,
|
||||
int maxiter CV_DEFAULT(20), int fig CV_DEFAULT(100));
|
||||
int maxiter CV_DEFAULT(20), int fig CV_DEFAULT(100));
|
||||
|
||||
/****************************************************************************************\
|
||||
* Matrix operations *
|
||||
@ -1127,9 +1127,9 @@ CVAPI(void) cvSetRemove( CvSet* set_header, int index );
|
||||
|
||||
/* Returns a set element by index. If the element doesn't belong to the set,
|
||||
NULL is returned */
|
||||
CV_INLINE CvSetElem* cvGetSetElem( const CvSet* set_header, int index )
|
||||
CV_INLINE CvSetElem* cvGetSetElem( const CvSet* set_header, int idx )
|
||||
{
|
||||
CvSetElem* elem = (CvSetElem*)cvGetSeqElem( (CvSeq*)set_header, index );
|
||||
CvSetElem* elem = (CvSetElem*)cvGetSeqElem( (CvSeq*)set_header, idx );
|
||||
return elem && CV_IS_SET_ELEM( elem ) ? elem : 0;
|
||||
}
|
||||
|
||||
@ -1374,17 +1374,17 @@ CVAPI(int) cvInitLineIterator( const CvArr* image, CvPoint pt1, CvPoint pt2,
|
||||
/* Font structure */
|
||||
typedef struct CvFont
|
||||
{
|
||||
const char* nameFont; //Qt:nameFont
|
||||
CvScalar color; //Qt:ColorFont -> cvScalar(blue_component, green_component, red\_component[, alpha_component])
|
||||
int font_face; //Qt: bool italic /* =CV_FONT_* */
|
||||
const int* ascii; /* font data and metrics */
|
||||
const char* nameFont; //Qt:nameFont
|
||||
CvScalar color; //Qt:ColorFont -> cvScalar(blue_component, green_component, red\_component[, alpha_component])
|
||||
int font_face; //Qt: bool italic /* =CV_FONT_* */
|
||||
const int* ascii; /* font data and metrics */
|
||||
const int* greek;
|
||||
const int* cyrillic;
|
||||
float hscale, vscale;
|
||||
float shear; /* slope coefficient: 0 - normal, >0 - italic */
|
||||
int thickness; //Qt: weight /* letters thickness */
|
||||
float dx; /* horizontal interval between letters */
|
||||
int line_type; //Qt: PointSize
|
||||
float shear; /* slope coefficient: 0 - normal, >0 - italic */
|
||||
int thickness; //Qt: weight /* letters thickness */
|
||||
float dx; /* horizontal interval between letters */
|
||||
int line_type; //Qt: PointSize
|
||||
}
|
||||
CvFont;
|
||||
|
||||
|
@ -48,6 +48,11 @@
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4714 ) //__forceinline is not inlined
|
||||
#pragma warning( disable: 4127 ) //conditional expression is constant
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
|
@ -366,12 +366,12 @@ namespace cv { namespace gpu
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void GpuMat::assignTo(GpuMat& m, int type) const
|
||||
inline void GpuMat::assignTo(GpuMat& m, int _type) const
|
||||
{
|
||||
if (type < 0)
|
||||
if (_type < 0)
|
||||
m = *this;
|
||||
else
|
||||
convertTo(m, type);
|
||||
convertTo(m, _type);
|
||||
}
|
||||
|
||||
inline size_t GpuMat::step1() const
|
||||
@ -434,9 +434,9 @@ namespace cv { namespace gpu
|
||||
create(size_.height, size_.width, type_);
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::operator()(Range rowRange, Range colRange) const
|
||||
inline GpuMat GpuMat::operator()(Range _rowRange, Range _colRange) const
|
||||
{
|
||||
return GpuMat(*this, rowRange, colRange);
|
||||
return GpuMat(*this, _rowRange, _colRange);
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::operator()(Rect roi) const
|
||||
|
@ -60,34 +60,34 @@
|
||||
#endif
|
||||
|
||||
#if defined WIN32 || defined WINCE
|
||||
#ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?)
|
||||
#define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#undef small
|
||||
#undef min
|
||||
#undef max
|
||||
# ifndef _WIN32_WINNT // This is needed for the declaration of TryEnterCriticalSection in winbase.h with Visual Studio 2005 (and older?)
|
||||
# define _WIN32_WINNT 0x0400 // http://msdn.microsoft.com/en-us/library/ms686857(VS.85).aspx
|
||||
# endif
|
||||
# include <windows.h>
|
||||
# undef small
|
||||
# undef min
|
||||
# undef max
|
||||
#else
|
||||
#include <pthread.h>
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#ifndef WIN32
|
||||
#define WIN32
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#define _WIN32
|
||||
#endif
|
||||
#define CV_DLL
|
||||
#undef _CV_ALWAYS_PROFILE_
|
||||
#define _CV_ALWAYS_NO_PROFILE_
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
# ifndef _WIN32
|
||||
# define _WIN32
|
||||
# endif
|
||||
# define CV_DLL
|
||||
# undef _CV_ALWAYS_PROFILE_
|
||||
# define _CV_ALWAYS_NO_PROFILE_
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
# define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
# define TRUE 1
|
||||
#endif
|
||||
|
||||
#define __BEGIN__ __CV_BEGIN__
|
||||
@ -95,7 +95,7 @@
|
||||
#define EXIT __CV_EXIT__
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
#include "ipp.h"
|
||||
# include "ipp.h"
|
||||
|
||||
CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
{
|
||||
@ -104,137 +104,132 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined __SSE2__ || _MSC_VER >= 1300
|
||||
#include "emmintrin.h"
|
||||
#define CV_SSE 1
|
||||
#define CV_SSE2 1
|
||||
#if defined __SSE3__ || _MSC_VER >= 1500
|
||||
#include "pmmintrin.h"
|
||||
#define CV_SSE3 1
|
||||
#endif
|
||||
#if defined __SSSE3__
|
||||
#include "tmmintrin.h"
|
||||
#define CV_SSSE3 1
|
||||
#endif
|
||||
#if defined __SSE2__ || (defined _MSC_VER && _MSC_VER >= 1300)
|
||||
# include "emmintrin.h"
|
||||
# define CV_SSE 1
|
||||
# define CV_SSE2 1
|
||||
# if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include "pmmintrin.h"
|
||||
# define CV_SSE3 1
|
||||
# else
|
||||
# define CV_SSE3 0
|
||||
# endif
|
||||
# if defined __SSSE3__
|
||||
# include "tmmintrin.h"
|
||||
# define CV_SSSE3 1
|
||||
# else
|
||||
# define CV_SSSE3 0
|
||||
# endif
|
||||
#else
|
||||
#define CV_SSE 0
|
||||
#define CV_SSE2 0
|
||||
#define CV_SSE3 0
|
||||
#define CV_SSSE3 0
|
||||
# define CV_SSE 0
|
||||
# define CV_SSE2 0
|
||||
# define CV_SSE3 0
|
||||
# define CV_SSSE3 0
|
||||
#endif
|
||||
|
||||
#if defined ANDROID && defined __ARM_NEON__ && defined __GNUC__
|
||||
#include "arm_neon.h"
|
||||
#define CV_NEON 1
|
||||
#if defined ANDROID && defined __ARM_NEON__
|
||||
# include "arm_neon.h"
|
||||
# define CV_NEON 1
|
||||
|
||||
#define CPU_HAS_NEON_FEATURE (true)
|
||||
# define CPU_HAS_NEON_FEATURE (true)
|
||||
//TODO: make real check using stuff from "cpu-features.h"
|
||||
//((bool)android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON)
|
||||
#else
|
||||
#define CV_NEON 0
|
||||
#define CPU_HAS_NEON_FEATURE (false)
|
||||
#endif
|
||||
|
||||
#ifdef CV_ICC
|
||||
#define CV_ENABLE_UNROLLED 0
|
||||
#else
|
||||
#define CV_ENABLE_UNROLLED 1
|
||||
# define CV_NEON 0
|
||||
# define CPU_HAS_NEON_FEATURE (false)
|
||||
#endif
|
||||
|
||||
#ifndef IPPI_CALL
|
||||
#define IPPI_CALL(func) CV_Assert((func) >= 0)
|
||||
# define IPPI_CALL(func) CV_Assert((func) >= 0)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
#include "tbb/tbb_stddef.h"
|
||||
#if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
|
||||
#include "tbb/tbb.h"
|
||||
#include "tbb/task.h"
|
||||
#undef min
|
||||
#undef max
|
||||
#else
|
||||
#undef HAVE_TBB
|
||||
#endif
|
||||
# include "tbb/tbb_stddef.h"
|
||||
# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
|
||||
# include "tbb/tbb.h"
|
||||
# include "tbb/task.h"
|
||||
# undef min
|
||||
# undef max
|
||||
# else
|
||||
# undef HAVE_TBB
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
#include <Eigen/Core>
|
||||
#include "opencv2/core/eigen.hpp"
|
||||
# include <Eigen/Core>
|
||||
# include "opencv2/core/eigen.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace cv
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
namespace cv
|
||||
|
||||
typedef tbb::blocked_range<int> BlockedRange;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
typedef tbb::blocked_range<int> BlockedRange;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
tbb::parallel_for(range, body);
|
||||
}
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
tbb::parallel_do(first, last, body);
|
||||
}
|
||||
|
||||
typedef tbb::split Split;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
tbb::parallel_reduce(range, body);
|
||||
}
|
||||
|
||||
typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
|
||||
typedef tbb::concurrent_vector<double> ConcurrentDoubleVector;
|
||||
tbb::parallel_for(range, body);
|
||||
}
|
||||
#else
|
||||
namespace cv
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
class BlockedRange
|
||||
{
|
||||
public:
|
||||
BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
|
||||
BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
|
||||
int begin() const { return _begin; }
|
||||
int end() const { return _end; }
|
||||
int grainsize() const { return _grainsize; }
|
||||
tbb::parallel_do(first, last, body);
|
||||
}
|
||||
|
||||
protected:
|
||||
int _begin, _end, _grainsize;
|
||||
};
|
||||
typedef tbb::split Split;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
typedef std::vector<Rect> ConcurrentRectVector;
|
||||
typedef std::vector<double> ConcurrentDoubleVector;
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
tbb::parallel_reduce(range, body);
|
||||
}
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
for( ; first != last; ++first )
|
||||
body(*first);
|
||||
}
|
||||
typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
|
||||
typedef tbb::concurrent_vector<double> ConcurrentDoubleVector;
|
||||
#else
|
||||
class BlockedRange
|
||||
{
|
||||
public:
|
||||
BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
|
||||
BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
|
||||
int begin() const { return _begin; }
|
||||
int end() const { return _end; }
|
||||
int grainsize() const { return _grainsize; }
|
||||
|
||||
class Split {};
|
||||
protected:
|
||||
int _begin, _end, _grainsize;
|
||||
};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
typedef std::vector<Rect> ConcurrentRectVector;
|
||||
typedef std::vector<double> ConcurrentDoubleVector;
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
for( ; first != last; ++first )
|
||||
body(*first);
|
||||
}
|
||||
|
||||
class Split {};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
#endif
|
||||
} //namespace cv
|
||||
|
||||
#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
|
||||
#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
|
||||
static Algorithm* create##classname() \
|
||||
{ \
|
||||
return new classname; \
|
||||
@ -261,7 +256,7 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
return &classname##_info(); \
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif //__cplusplus
|
||||
|
||||
/* maximal size of vector to run matrix operations on it inline (i.e. w/o ipp calls) */
|
||||
#define CV_MAX_INLINE_MAT_OP_SIZE 10
|
||||
@ -305,9 +300,9 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
#define CV_MAX_STRLEN 1024
|
||||
|
||||
#if 0 /*def CV_CHECK_FOR_NANS*/
|
||||
#define CV_CHECK_NANS( arr ) cvCheckArray((arr))
|
||||
# define CV_CHECK_NANS( arr ) cvCheckArray((arr))
|
||||
#else
|
||||
#define CV_CHECK_NANS( arr )
|
||||
# define CV_CHECK_NANS( arr )
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
@ -316,38 +311,38 @@ CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
|
||||
/* get alloca declaration */
|
||||
#ifdef __GNUC__
|
||||
#undef alloca
|
||||
#define alloca __builtin_alloca
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# undef alloca
|
||||
# define alloca __builtin_alloca
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#elif defined WIN32 || defined _WIN32 || \
|
||||
defined WINCE || defined _MSC_VER || defined __BORLANDC__
|
||||
#include <malloc.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# include <malloc.h>
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#elif defined HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# include <alloca.h>
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#elif defined HAVE_ALLOCA
|
||||
#include <stdlib.h>
|
||||
#define CV_HAVE_ALLOCA 1
|
||||
# include <stdlib.h>
|
||||
# define CV_HAVE_ALLOCA 1
|
||||
#else
|
||||
#undef CV_HAVE_ALLOCA
|
||||
# undef CV_HAVE_ALLOCA
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
|
||||
# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
|
||||
#elif defined _MSC_VER
|
||||
#define CV_DECL_ALIGNED(x) __declspec(align(x))
|
||||
# define CV_DECL_ALIGNED(x) __declspec(align(x))
|
||||
#else
|
||||
#define CV_DECL_ALIGNED(x)
|
||||
# define CV_DECL_ALIGNED(x)
|
||||
#endif
|
||||
|
||||
#if CV_HAVE_ALLOCA
|
||||
/* ! DO NOT make it an inline function */
|
||||
#define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN )
|
||||
# define cvStackAlloc(size) cvAlignPtr( alloca((size) + CV_MALLOC_ALIGN), CV_MALLOC_ALIGN )
|
||||
#endif
|
||||
|
||||
#ifndef CV_IMPL
|
||||
#define CV_IMPL CV_EXTERN_C
|
||||
# define CV_IMPL CV_EXTERN_C
|
||||
#endif
|
||||
|
||||
#define CV_DBG_BREAK() { volatile int* crashMe = 0; *crashMe = 0; }
|
||||
@ -687,25 +682,25 @@ typedef enum CvStatus
|
||||
CV_UNSUPPORTED_DEPTH_ERR = -101,
|
||||
CV_UNSUPPORTED_FORMAT_ERR = -100,
|
||||
|
||||
CV_BADARG_ERR = -49, //ipp comp
|
||||
CV_NOTDEFINED_ERR = -48, //ipp comp
|
||||
CV_BADARG_ERR = -49, //ipp comp
|
||||
CV_NOTDEFINED_ERR = -48, //ipp comp
|
||||
|
||||
CV_BADCHANNELS_ERR = -47, //ipp comp
|
||||
CV_BADRANGE_ERR = -44, //ipp comp
|
||||
CV_BADSTEP_ERR = -29, //ipp comp
|
||||
CV_BADCHANNELS_ERR = -47, //ipp comp
|
||||
CV_BADRANGE_ERR = -44, //ipp comp
|
||||
CV_BADSTEP_ERR = -29, //ipp comp
|
||||
|
||||
CV_BADFLAG_ERR = -12,
|
||||
CV_DIV_BY_ZERO_ERR = -11, //ipp comp
|
||||
CV_BADCOEF_ERR = -10,
|
||||
CV_BADFLAG_ERR = -12,
|
||||
CV_DIV_BY_ZERO_ERR = -11, //ipp comp
|
||||
CV_BADCOEF_ERR = -10,
|
||||
|
||||
CV_BADFACTOR_ERR = -7,
|
||||
CV_BADPOINT_ERR = -6,
|
||||
CV_BADSCALE_ERR = -4,
|
||||
CV_OUTOFMEM_ERR = -3,
|
||||
CV_NULLPTR_ERR = -2,
|
||||
CV_BADSIZE_ERR = -1,
|
||||
CV_NO_ERR = 0,
|
||||
CV_OK = CV_NO_ERR
|
||||
CV_BADFACTOR_ERR = -7,
|
||||
CV_BADPOINT_ERR = -6,
|
||||
CV_BADSCALE_ERR = -4,
|
||||
CV_OUTOFMEM_ERR = -3,
|
||||
CV_NULLPTR_ERR = -2,
|
||||
CV_BADSIZE_ERR = -1,
|
||||
CV_NO_ERR = 0,
|
||||
CV_OK = CV_NO_ERR
|
||||
}
|
||||
CvStatus;
|
||||
|
||||
@ -720,8 +715,7 @@ CvFuncTable;
|
||||
typedef struct CvBigFuncTable
|
||||
{
|
||||
void* fn_2d[CV_DEPTH_MAX*4];
|
||||
}
|
||||
CvBigFuncTable;
|
||||
} CvBigFuncTable;
|
||||
|
||||
#define CV_INIT_FUNC_TAB( tab, FUNCNAME, FLAG ) \
|
||||
(tab).fn_2d[CV_8U] = (void*)FUNCNAME##_8u##FLAG; \
|
||||
@ -732,6 +726,7 @@ CvBigFuncTable;
|
||||
(tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \
|
||||
(tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG
|
||||
|
||||
#ifdef __cplusplus
|
||||
//! OpenGL extension table
|
||||
class CV_EXPORTS CvOpenGlFuncTab
|
||||
{
|
||||
@ -764,4 +759,6 @@ CV_EXPORTS bool icvCheckGlError(const char* file, const int line, const char* fu
|
||||
#define CV_CheckGlError() CV_DbgAssert( (::icvCheckGlError(__FILE__, __LINE__)) )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif //__cplusplus
|
||||
|
||||
#endif // __OPENCV_CORE_INTERNAL_HPP__
|
||||
|
@ -336,12 +336,12 @@ inline Mat Mat::clone() const
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void Mat::assignTo( Mat& m, int type ) const
|
||||
inline void Mat::assignTo( Mat& m, int _type ) const
|
||||
{
|
||||
if( type < 0 )
|
||||
if( _type < 0 )
|
||||
m = *this;
|
||||
else
|
||||
convertTo(m, type);
|
||||
convertTo(m, _type);
|
||||
}
|
||||
|
||||
inline void Mat::create(int _rows, int _cols, int _type)
|
||||
@ -370,9 +370,9 @@ inline void Mat::release()
|
||||
refcount = 0;
|
||||
}
|
||||
|
||||
inline Mat Mat::operator()( Range rowRange, Range colRange ) const
|
||||
inline Mat Mat::operator()( Range _rowRange, Range _colRange ) const
|
||||
{
|
||||
return Mat(*this, rowRange, colRange);
|
||||
return Mat(*this, _rowRange, _colRange);
|
||||
}
|
||||
|
||||
inline Mat Mat::operator()( const Rect& roi ) const
|
||||
@ -682,11 +682,11 @@ template<typename _Tp, int m, int n> inline Mat::operator Matx<_Tp, m, n>() cons
|
||||
template<typename _Tp> inline void Mat::push_back(const _Tp& elem)
|
||||
{
|
||||
if( !data )
|
||||
{
|
||||
*this = Mat(1, 1, DataType<_Tp>::type, (void*)&elem).clone();
|
||||
return;
|
||||
}
|
||||
CV_Assert(DataType<_Tp>::type == type() && cols == 1
|
||||
{
|
||||
*this = Mat(1, 1, DataType<_Tp>::type, (void*)&elem).clone();
|
||||
return;
|
||||
}
|
||||
CV_Assert(DataType<_Tp>::type == type() && cols == 1
|
||||
/* && dims == 2 (cols == 1 implies dims == 2) */);
|
||||
uchar* tmp = dataend + step[0];
|
||||
if( !isSubmatrix() && isContinuous() && tmp <= datalimit )
|
||||
@ -829,8 +829,8 @@ template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m)
|
||||
template<typename _Tp> inline Mat_<_Tp>::Mat_(int _rows, int _cols, _Tp* _data, size_t steps)
|
||||
: Mat(_rows, _cols, DataType<_Tp>::type, _data, steps) {}
|
||||
|
||||
template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m, const Range& rowRange, const Range& colRange)
|
||||
: Mat(m, rowRange, colRange) {}
|
||||
template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m, const Range& _rowRange, const Range& _colRange)
|
||||
: Mat(m, _rowRange, _colRange) {}
|
||||
|
||||
template<typename _Tp> inline Mat_<_Tp>::Mat_(const Mat_& m, const Rect& roi)
|
||||
: Mat(m, roi) {}
|
||||
@ -967,8 +967,8 @@ template<typename _Tp> inline size_t Mat_<_Tp>::step1(int i) const { return step
|
||||
template<typename _Tp> inline Mat_<_Tp>& Mat_<_Tp>::adjustROI( int dtop, int dbottom, int dleft, int dright )
|
||||
{ return (Mat_<_Tp>&)(Mat::adjustROI(dtop, dbottom, dleft, dright)); }
|
||||
|
||||
template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Range& rowRange, const Range& colRange ) const
|
||||
{ return Mat_<_Tp>(*this, rowRange, colRange); }
|
||||
template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Range& _rowRange, const Range& _colRange ) const
|
||||
{ return Mat_<_Tp>(*this, _rowRange, _colRange); }
|
||||
|
||||
template<typename _Tp> inline Mat_<_Tp> Mat_<_Tp>::operator()( const Rect& roi ) const
|
||||
{ return Mat_<_Tp>(*this, roi); }
|
||||
@ -2123,12 +2123,12 @@ inline SparseMat SparseMat::clone() const
|
||||
}
|
||||
|
||||
|
||||
inline void SparseMat::assignTo( SparseMat& m, int type ) const
|
||||
inline void SparseMat::assignTo( SparseMat& m, int _type ) const
|
||||
{
|
||||
if( type < 0 )
|
||||
if( _type < 0 )
|
||||
m = *this;
|
||||
else
|
||||
convertTo(m, type);
|
||||
convertTo(m, _type);
|
||||
}
|
||||
|
||||
inline void SparseMat::addref()
|
||||
|
@ -49,280 +49,285 @@
|
||||
|
||||
namespace cv
|
||||
{
|
||||
//! Smart pointer for OpenGL buffer memory with reference counting.
|
||||
class CV_EXPORTS GlBuffer
|
||||
//! Smart pointer for OpenGL buffer memory with reference counting.
|
||||
class CV_EXPORTS GlBuffer
|
||||
{
|
||||
public:
|
||||
enum Usage
|
||||
{
|
||||
public:
|
||||
enum Usage
|
||||
{
|
||||
ARRAY_BUFFER = 0x8892, // buffer will use for OpenGL arrays (vertices, colors, normals, etc)
|
||||
TEXTURE_BUFFER = 0x88EC // buffer will ise for OpenGL textures
|
||||
};
|
||||
|
||||
//! create empty buffer
|
||||
explicit GlBuffer(Usage usage);
|
||||
|
||||
//! create buffer
|
||||
GlBuffer(int rows, int cols, int type, Usage usage);
|
||||
GlBuffer(Size size, int type, Usage usage);
|
||||
|
||||
//! copy from host/device memory
|
||||
GlBuffer(InputArray mat, Usage usage);
|
||||
|
||||
void create(int rows, int cols, int type, Usage usage);
|
||||
inline void create(Size size, int type, Usage usage) { create(size.height, size.width, type, usage); }
|
||||
inline void create(int rows, int cols, int type) { create(rows, cols, type, usage()); }
|
||||
inline void create(Size size, int type) { create(size.height, size.width, type, usage()); }
|
||||
|
||||
void release();
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray mat);
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
//! map to host memory
|
||||
Mat mapHost();
|
||||
void unmapHost();
|
||||
|
||||
//! map to device memory
|
||||
gpu::GpuMat mapDevice();
|
||||
void unmapDevice();
|
||||
|
||||
inline int rows() const { return rows_; }
|
||||
inline int cols() const { return cols_; }
|
||||
inline Size size() const { return Size(cols_, rows_); }
|
||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
inline int type() const { return type_; }
|
||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
||||
inline int channels() const { return CV_MAT_CN(type_); }
|
||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||
|
||||
inline Usage usage() const { return usage_; }
|
||||
|
||||
class Impl;
|
||||
private:
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
Usage usage_;
|
||||
|
||||
Ptr<Impl> impl_;
|
||||
ARRAY_BUFFER = 0x8892, // buffer will use for OpenGL arrays (vertices, colors, normals, etc)
|
||||
TEXTURE_BUFFER = 0x88EC // buffer will ise for OpenGL textures
|
||||
};
|
||||
|
||||
template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj();
|
||||
//! create empty buffer
|
||||
explicit GlBuffer(Usage usage);
|
||||
|
||||
//! Smart pointer for OpenGL 2d texture memory with reference counting.
|
||||
class CV_EXPORTS GlTexture
|
||||
//! create buffer
|
||||
GlBuffer(int rows, int cols, int type, Usage usage);
|
||||
GlBuffer(Size size, int type, Usage usage);
|
||||
|
||||
//! copy from host/device memory
|
||||
GlBuffer(InputArray mat, Usage usage);
|
||||
|
||||
void create(int rows, int cols, int type, Usage usage);
|
||||
void create(Size size, int type, Usage usage);
|
||||
void create(int rows, int cols, int type);
|
||||
void create(Size size, int type);
|
||||
|
||||
void release();
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray mat);
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
//! map to host memory
|
||||
Mat mapHost();
|
||||
void unmapHost();
|
||||
|
||||
//! map to device memory
|
||||
gpu::GpuMat mapDevice();
|
||||
void unmapDevice();
|
||||
|
||||
inline int rows() const { return rows_; }
|
||||
inline int cols() const { return cols_; }
|
||||
inline Size size() const { return Size(cols_, rows_); }
|
||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
inline int type() const { return type_; }
|
||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
||||
inline int channels() const { return CV_MAT_CN(type_); }
|
||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||
|
||||
inline Usage usage() const { return usage_; }
|
||||
|
||||
class Impl;
|
||||
private:
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
Usage usage_;
|
||||
|
||||
Ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj();
|
||||
|
||||
//! Smart pointer for OpenGL 2d texture memory with reference counting.
|
||||
class CV_EXPORTS GlTexture
|
||||
{
|
||||
public:
|
||||
//! create empty texture
|
||||
GlTexture();
|
||||
|
||||
//! create texture
|
||||
GlTexture(int rows, int cols, int type);
|
||||
GlTexture(Size size, int type);
|
||||
|
||||
//! copy from host/device memory
|
||||
explicit GlTexture(InputArray mat, bool bgra = true);
|
||||
|
||||
void create(int rows, int cols, int type);
|
||||
void create(Size size, int type);
|
||||
void release();
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray mat, bool bgra = true);
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
inline int rows() const { return rows_; }
|
||||
inline int cols() const { return cols_; }
|
||||
inline Size size() const { return Size(cols_, rows_); }
|
||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
inline int type() const { return type_; }
|
||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
||||
inline int channels() const { return CV_MAT_CN(type_); }
|
||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||
|
||||
class Impl;
|
||||
private:
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
|
||||
Ptr<Impl> impl_;
|
||||
GlBuffer buf_;
|
||||
};
|
||||
|
||||
template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
|
||||
|
||||
//! OpenGL Arrays
|
||||
class CV_EXPORTS GlArrays
|
||||
{
|
||||
public:
|
||||
inline GlArrays()
|
||||
: vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER)
|
||||
{
|
||||
public:
|
||||
//! create empty texture
|
||||
GlTexture();
|
||||
|
||||
//! create texture
|
||||
GlTexture(int rows, int cols, int type);
|
||||
GlTexture(Size size, int type);
|
||||
|
||||
//! copy from host/device memory
|
||||
explicit GlTexture(InputArray mat, bool bgra = true);
|
||||
|
||||
void create(int rows, int cols, int type);
|
||||
inline void create(Size size, int type) { create(size.height, size.width, type); }
|
||||
void release();
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray mat, bool bgra = true);
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
inline int rows() const { return rows_; }
|
||||
inline int cols() const { return cols_; }
|
||||
inline Size size() const { return Size(cols_, rows_); }
|
||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
inline int type() const { return type_; }
|
||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
||||
inline int channels() const { return CV_MAT_CN(type_); }
|
||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||
|
||||
class Impl;
|
||||
private:
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
|
||||
Ptr<Impl> impl_;
|
||||
GlBuffer buf_;
|
||||
};
|
||||
|
||||
template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
|
||||
|
||||
//! OpenGL Arrays
|
||||
class CV_EXPORTS GlArrays
|
||||
{
|
||||
public:
|
||||
inline GlArrays()
|
||||
: vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER)
|
||||
{
|
||||
}
|
||||
|
||||
void setVertexArray(InputArray vertex);
|
||||
inline void resetVertexArray() { vertex_.release(); }
|
||||
|
||||
void setColorArray(InputArray color, bool bgra = true);
|
||||
inline void resetColorArray() { color_.release(); }
|
||||
|
||||
void setNormalArray(InputArray normal);
|
||||
inline void resetNormalArray() { normal_.release(); }
|
||||
|
||||
void setTexCoordArray(InputArray texCoord);
|
||||
inline void resetTexCoordArray() { texCoord_.release(); }
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
inline int rows() const { return vertex_.rows(); }
|
||||
inline int cols() const { return vertex_.cols(); }
|
||||
inline Size size() const { return vertex_.size(); }
|
||||
inline bool empty() const { return vertex_.empty(); }
|
||||
|
||||
private:
|
||||
GlBuffer vertex_;
|
||||
GlBuffer color_;
|
||||
bool bgra_;
|
||||
GlBuffer normal_;
|
||||
GlBuffer texCoord_;
|
||||
};
|
||||
|
||||
//! OpenGL Font
|
||||
class CV_EXPORTS GlFont
|
||||
{
|
||||
public:
|
||||
enum Weight
|
||||
{
|
||||
WEIGHT_LIGHT = 300,
|
||||
WEIGHT_NORMAL = 400,
|
||||
WEIGHT_SEMIBOLD = 600,
|
||||
WEIGHT_BOLD = 700,
|
||||
WEIGHT_BLACK = 900
|
||||
};
|
||||
|
||||
enum Style
|
||||
{
|
||||
STYLE_NORMAL = 0,
|
||||
STYLE_ITALIC = 1,
|
||||
STYLE_UNDERLINE = 2
|
||||
};
|
||||
|
||||
static Ptr<GlFont> get(const std::string& family, int height = 12, Weight weight = WEIGHT_NORMAL, Style style = STYLE_NORMAL);
|
||||
|
||||
void draw(const char* str, int len) const;
|
||||
|
||||
inline const std::string& family() const { return family_; }
|
||||
inline int height() const { return height_; }
|
||||
inline Weight weight() const { return weight_; }
|
||||
inline Style style() const { return style_; }
|
||||
|
||||
private:
|
||||
GlFont(const std::string& family, int height, Weight weight, Style style);
|
||||
|
||||
std::string family_;
|
||||
int height_;
|
||||
Weight weight_;
|
||||
Style style_;
|
||||
|
||||
unsigned int base_;
|
||||
|
||||
GlFont(const GlFont&);
|
||||
GlFont& operator =(const GlFont&);
|
||||
};
|
||||
|
||||
//! render functions
|
||||
|
||||
//! render texture rectangle in window
|
||||
CV_EXPORTS void render(const GlTexture& tex,
|
||||
Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
|
||||
Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
|
||||
|
||||
//! render mode
|
||||
namespace RenderMode {
|
||||
enum {
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006,
|
||||
QUADS = 0x0007,
|
||||
QUAD_STRIP = 0x0008,
|
||||
POLYGON = 0x0009
|
||||
};
|
||||
}
|
||||
|
||||
//! render OpenGL arrays
|
||||
CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
|
||||
void setVertexArray(InputArray vertex);
|
||||
inline void resetVertexArray() { vertex_.release(); }
|
||||
|
||||
CV_EXPORTS void render(const std::string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos);
|
||||
void setColorArray(InputArray color, bool bgra = true);
|
||||
inline void resetColorArray() { color_.release(); }
|
||||
|
||||
//! OpenGL camera
|
||||
class CV_EXPORTS GlCamera
|
||||
void setNormalArray(InputArray normal);
|
||||
inline void resetNormalArray() { normal_.release(); }
|
||||
|
||||
void setTexCoordArray(InputArray texCoord);
|
||||
inline void resetTexCoordArray() { texCoord_.release(); }
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
inline int rows() const { return vertex_.rows(); }
|
||||
inline int cols() const { return vertex_.cols(); }
|
||||
inline Size size() const { return vertex_.size(); }
|
||||
inline bool empty() const { return vertex_.empty(); }
|
||||
|
||||
private:
|
||||
GlBuffer vertex_;
|
||||
GlBuffer color_;
|
||||
bool bgra_;
|
||||
GlBuffer normal_;
|
||||
GlBuffer texCoord_;
|
||||
};
|
||||
|
||||
//! OpenGL Font
|
||||
class CV_EXPORTS GlFont
|
||||
{
|
||||
public:
|
||||
enum Weight
|
||||
{
|
||||
public:
|
||||
GlCamera();
|
||||
|
||||
void lookAt(Point3d eye, Point3d center, Point3d up);
|
||||
void setCameraPos(Point3d pos, double yaw, double pitch, double roll);
|
||||
|
||||
void setScale(Point3d scale);
|
||||
|
||||
void setProjectionMatrix(const Mat& projectionMatrix, bool transpose = true);
|
||||
void setPerspectiveProjection(double fov, double aspect, double zNear, double zFar);
|
||||
void setOrthoProjection(double left, double right, double bottom, double top, double zNear, double zFar);
|
||||
|
||||
void setupProjectionMatrix() const;
|
||||
void setupModelViewMatrix() const;
|
||||
|
||||
private:
|
||||
Point3d eye_;
|
||||
Point3d center_;
|
||||
Point3d up_;
|
||||
|
||||
Point3d pos_;
|
||||
double yaw_;
|
||||
double pitch_;
|
||||
double roll_;
|
||||
|
||||
bool useLookAtParams_;
|
||||
|
||||
Point3d scale_;
|
||||
|
||||
Mat projectionMatrix_;
|
||||
|
||||
double fov_;
|
||||
double aspect_;
|
||||
|
||||
double left_;
|
||||
double right_;
|
||||
double bottom_;
|
||||
double top_;
|
||||
|
||||
double zNear_;
|
||||
double zFar_;
|
||||
|
||||
bool perspectiveProjection_;
|
||||
WEIGHT_LIGHT = 300,
|
||||
WEIGHT_NORMAL = 400,
|
||||
WEIGHT_SEMIBOLD = 600,
|
||||
WEIGHT_BOLD = 700,
|
||||
WEIGHT_BLACK = 900
|
||||
};
|
||||
|
||||
namespace gpu
|
||||
enum Style
|
||||
{
|
||||
//! set a CUDA device to use OpenGL interoperability
|
||||
CV_EXPORTS void setGlDevice(int device = 0);
|
||||
}
|
||||
STYLE_NORMAL = 0,
|
||||
STYLE_ITALIC = 1,
|
||||
STYLE_UNDERLINE = 2
|
||||
};
|
||||
|
||||
static Ptr<GlFont> get(const std::string& family, int height = 12, Weight weight = WEIGHT_NORMAL, Style style = STYLE_NORMAL);
|
||||
|
||||
void draw(const char* str, int len) const;
|
||||
|
||||
inline const std::string& family() const { return family_; }
|
||||
inline int height() const { return height_; }
|
||||
inline Weight weight() const { return weight_; }
|
||||
inline Style style() const { return style_; }
|
||||
|
||||
private:
|
||||
GlFont(const std::string& family, int height, Weight weight, Style style);
|
||||
|
||||
std::string family_;
|
||||
int height_;
|
||||
Weight weight_;
|
||||
Style style_;
|
||||
|
||||
unsigned int base_;
|
||||
|
||||
GlFont(const GlFont&);
|
||||
GlFont& operator =(const GlFont&);
|
||||
};
|
||||
|
||||
//! render functions
|
||||
|
||||
//! render texture rectangle in window
|
||||
CV_EXPORTS void render(const GlTexture& tex,
|
||||
Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
|
||||
Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
|
||||
|
||||
//! render mode
|
||||
namespace RenderMode {
|
||||
enum {
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006,
|
||||
QUADS = 0x0007,
|
||||
QUAD_STRIP = 0x0008,
|
||||
POLYGON = 0x0009
|
||||
};
|
||||
}
|
||||
|
||||
//! render OpenGL arrays
|
||||
CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
|
||||
|
||||
CV_EXPORTS void render(const std::string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos);
|
||||
|
||||
//! OpenGL camera
|
||||
class CV_EXPORTS GlCamera
|
||||
{
|
||||
public:
|
||||
GlCamera();
|
||||
|
||||
void lookAt(Point3d eye, Point3d center, Point3d up);
|
||||
void setCameraPos(Point3d pos, double yaw, double pitch, double roll);
|
||||
|
||||
void setScale(Point3d scale);
|
||||
|
||||
void setProjectionMatrix(const Mat& projectionMatrix, bool transpose = true);
|
||||
void setPerspectiveProjection(double fov, double aspect, double zNear, double zFar);
|
||||
void setOrthoProjection(double left, double right, double bottom, double top, double zNear, double zFar);
|
||||
|
||||
void setupProjectionMatrix() const;
|
||||
void setupModelViewMatrix() const;
|
||||
|
||||
private:
|
||||
Point3d eye_;
|
||||
Point3d center_;
|
||||
Point3d up_;
|
||||
|
||||
Point3d pos_;
|
||||
double yaw_;
|
||||
double pitch_;
|
||||
double roll_;
|
||||
|
||||
bool useLookAtParams_;
|
||||
|
||||
Point3d scale_;
|
||||
|
||||
Mat projectionMatrix_;
|
||||
|
||||
double fov_;
|
||||
double aspect_;
|
||||
|
||||
double left_;
|
||||
double right_;
|
||||
double bottom_;
|
||||
double top_;
|
||||
|
||||
double zNear_;
|
||||
double zFar_;
|
||||
|
||||
bool perspectiveProjection_;
|
||||
};
|
||||
|
||||
inline void GlBuffer::create(Size _size, int _type, Usage _usage) { create(_size.height, _size.width, _type, _usage); }
|
||||
inline void GlBuffer::create(int _rows, int _cols, int _type) { create(_rows, _cols, _type, usage()); }
|
||||
inline void GlBuffer::create(Size _size, int _type) { create(_size.height, _size.width, _type, usage()); }
|
||||
inline void GlTexture::create(Size _size, int _type) { create(_size.height, _size.width, _type); }
|
||||
|
||||
namespace gpu
|
||||
{
|
||||
//! set a CUDA device to use OpenGL interoperability
|
||||
CV_EXPORTS void setGlDevice(int device = 0);
|
||||
}
|
||||
} // namespace cv
|
||||
|
||||
#endif // __cplusplus
|
||||
|
@ -984,13 +984,13 @@ _AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n)
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= n - 4; i += 4 )
|
||||
{
|
||||
_AccTp v0 = a[i] - b[i], v1 = a[i+1] - b[i+1], v2 = a[i+2] - b[i+2], v3 = a[i+3] - b[i+3];
|
||||
_AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
|
||||
s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
|
||||
}
|
||||
#endif
|
||||
for( ; i < n; i++ )
|
||||
{
|
||||
_AccTp v = (_AccTp)(a[i] - b[i]);
|
||||
_AccTp v = _AccTp(a[i] - b[i]);
|
||||
s += v*v;
|
||||
}
|
||||
return s;
|
||||
@ -1024,13 +1024,13 @@ _AccTp normL1(const _Tp* a, const _Tp* b, int n)
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= n - 4; i += 4 )
|
||||
{
|
||||
_AccTp v0 = a[i] - b[i], v1 = a[i+1] - b[i+1], v2 = a[i+2] - b[i+2], v3 = a[i+3] - b[i+3];
|
||||
_AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
|
||||
s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3);
|
||||
}
|
||||
#endif
|
||||
for( ; i < n; i++ )
|
||||
{
|
||||
_AccTp v = (_AccTp)(a[i] - b[i]);
|
||||
_AccTp v = _AccTp(a[i] - b[i]);
|
||||
s += std::abs(v);
|
||||
}
|
||||
return s;
|
||||
@ -2616,20 +2616,20 @@ template<typename _Tp> inline void Ptr<_Tp>::delete_obj()
|
||||
|
||||
template<typename _Tp> inline Ptr<_Tp>::~Ptr() { release(); }
|
||||
|
||||
template<typename _Tp> inline Ptr<_Tp>::Ptr(const Ptr<_Tp>& ptr)
|
||||
template<typename _Tp> inline Ptr<_Tp>::Ptr(const Ptr<_Tp>& _ptr)
|
||||
{
|
||||
obj = ptr.obj;
|
||||
refcount = ptr.refcount;
|
||||
obj = _ptr.obj;
|
||||
refcount = _ptr.refcount;
|
||||
addref();
|
||||
}
|
||||
|
||||
template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& ptr)
|
||||
template<typename _Tp> inline Ptr<_Tp>& Ptr<_Tp>::operator = (const Ptr<_Tp>& _ptr)
|
||||
{
|
||||
int* _refcount = ptr.refcount;
|
||||
int* _refcount = _ptr.refcount;
|
||||
if( _refcount )
|
||||
CV_XADD(_refcount, 1);
|
||||
release();
|
||||
obj = ptr.obj;
|
||||
obj = _ptr.obj;
|
||||
refcount = _refcount;
|
||||
return *this;
|
||||
}
|
||||
@ -3593,10 +3593,10 @@ template<typename _Tp> inline Seq<_Tp>::operator vector<_Tp>() const
|
||||
template<typename _Tp> inline SeqIterator<_Tp>::SeqIterator()
|
||||
{ memset(this, 0, sizeof(*this)); }
|
||||
|
||||
template<typename _Tp> inline SeqIterator<_Tp>::SeqIterator(const Seq<_Tp>& seq, bool seekEnd)
|
||||
template<typename _Tp> inline SeqIterator<_Tp>::SeqIterator(const Seq<_Tp>& _seq, bool seekEnd)
|
||||
{
|
||||
cvStartReadSeq(seq.seq, this);
|
||||
index = seekEnd ? seq.seq->total : 0;
|
||||
cvStartReadSeq(_seq.seq, this);
|
||||
index = seekEnd ? _seq.seq->total : 0;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline void SeqIterator<_Tp>::seek(size_t pos)
|
||||
@ -3842,17 +3842,17 @@ template<typename _Tp> inline Ptr<_Tp> Algorithm::create(const string& name)
|
||||
return _create(name).ptr<_Tp>();
|
||||
}
|
||||
|
||||
template<typename _Tp> inline typename ParamType<_Tp>::member_type Algorithm::get(const string& name) const
|
||||
template<typename _Tp> inline typename ParamType<_Tp>::member_type Algorithm::get(const string& _name) const
|
||||
{
|
||||
typename ParamType<_Tp>::member_type value;
|
||||
info()->get(this, name.c_str(), ParamType<_Tp>::type, &value);
|
||||
info()->get(this, _name.c_str(), ParamType<_Tp>::type, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline typename ParamType<_Tp>::member_type Algorithm::get(const char* name) const
|
||||
template<typename _Tp> inline typename ParamType<_Tp>::member_type Algorithm::get(const char* _name) const
|
||||
{
|
||||
typename ParamType<_Tp>::member_type value;
|
||||
info()->get(this, name, ParamType<_Tp>::type, &value);
|
||||
info()->get(this, _name, ParamType<_Tp>::type, &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -43,122 +43,132 @@
|
||||
#ifndef __OPENCV_CORE_TYPES_H__
|
||||
#define __OPENCV_CORE_TYPES_H__
|
||||
|
||||
#if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
|
||||
#define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
|
||||
#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER
|
||||
# if _MSC_VER > 1300
|
||||
# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SKIP_INCLUDES
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
|
||||
#if !defined _MSC_VER && !defined __BORLANDC__
|
||||
#include <stdint.h>
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined __ICL
|
||||
#define CV_ICC __ICL
|
||||
#elif defined __ICC
|
||||
#define CV_ICC __ICC
|
||||
#elif defined __ECL
|
||||
#define CV_ICC __ECL
|
||||
#elif defined __ECC
|
||||
#define CV_ICC __ECC
|
||||
#elif defined __INTEL_COMPILER
|
||||
#define CV_ICC __INTEL_COMPILER
|
||||
#endif
|
||||
#if defined __ICL
|
||||
# define CV_ICC __ICL
|
||||
#elif defined __ICC
|
||||
# define CV_ICC __ICC
|
||||
#elif defined __ECL
|
||||
# define CV_ICC __ECL
|
||||
#elif defined __ECC
|
||||
# define CV_ICC __ECC
|
||||
#elif defined __INTEL_COMPILER
|
||||
# define CV_ICC __INTEL_COMPILER
|
||||
#endif
|
||||
|
||||
#if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__)
|
||||
#if defined WIN32
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
#if __SSE2__ || !defined __GNUC__
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
#endif
|
||||
#if defined CV_ICC && !defined CV_ENABLE_UNROLLED
|
||||
# define CV_ENABLE_UNROLLED 0
|
||||
#else
|
||||
# define CV_ENABLE_UNROLLED 1
|
||||
#endif
|
||||
|
||||
#if defined __BORLANDC__
|
||||
#include <fastmath.h>
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
#if (defined _M_X64 && defined _MSC_VER && _MSC_VER >= 1400) || (__GNUC__ >= 4 && defined __x86_64__)
|
||||
# if defined WIN32
|
||||
# include <intrin.h>
|
||||
# endif
|
||||
# if __SSE2__ || !defined __GNUC__
|
||||
# include <emmintrin.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined __BORLANDC__
|
||||
# include <fastmath.h>
|
||||
#else
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IPL
|
||||
# ifndef __IPL_H__
|
||||
# if defined WIN32 || defined _WIN32
|
||||
# include <ipl.h>
|
||||
# else
|
||||
# include <ipl/ipl.h>
|
||||
# endif
|
||||
# endif
|
||||
#elif defined __IPL_H__
|
||||
# define HAVE_IPL
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IPL
|
||||
#ifndef __IPL_H__
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#include <ipl.h>
|
||||
#else
|
||||
#include <ipl/ipl.h>
|
||||
#endif
|
||||
#endif
|
||||
#elif defined __IPL_H__
|
||||
#define HAVE_IPL
|
||||
#endif
|
||||
#endif // SKIP_INCLUDES
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
#define CV_CDECL __cdecl
|
||||
#define CV_STDCALL __stdcall
|
||||
# define CV_CDECL __cdecl
|
||||
# define CV_STDCALL __stdcall
|
||||
#else
|
||||
#define CV_CDECL
|
||||
#define CV_STDCALL
|
||||
# define CV_CDECL
|
||||
# define CV_STDCALL
|
||||
#endif
|
||||
|
||||
#ifndef CV_EXTERN_C
|
||||
#ifdef __cplusplus
|
||||
#define CV_EXTERN_C extern "C"
|
||||
#define CV_DEFAULT(val) = val
|
||||
#else
|
||||
#define CV_EXTERN_C
|
||||
#define CV_DEFAULT(val)
|
||||
#endif
|
||||
# ifdef __cplusplus
|
||||
# define CV_EXTERN_C extern "C"
|
||||
# define CV_DEFAULT(val) = val
|
||||
# else
|
||||
# define CV_EXTERN_C
|
||||
# define CV_DEFAULT(val)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CV_EXTERN_C_FUNCPTR
|
||||
#ifdef __cplusplus
|
||||
#define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
|
||||
#else
|
||||
#define CV_EXTERN_C_FUNCPTR(x) typedef x
|
||||
#endif
|
||||
# ifdef __cplusplus
|
||||
# define CV_EXTERN_C_FUNCPTR(x) extern "C" { typedef x; }
|
||||
# else
|
||||
# define CV_EXTERN_C_FUNCPTR(x) typedef x
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CV_INLINE
|
||||
#if defined __cplusplus
|
||||
#define CV_INLINE inline
|
||||
#elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__
|
||||
#define CV_INLINE __inline
|
||||
#else
|
||||
#define CV_INLINE static
|
||||
#endif
|
||||
# if defined __cplusplus
|
||||
# define CV_INLINE inline
|
||||
# elif (defined WIN32 || defined _WIN32 || defined WINCE) && !defined __GNUC__
|
||||
# define CV_INLINE __inline
|
||||
# else
|
||||
# define CV_INLINE static
|
||||
# endif
|
||||
#endif /* CV_INLINE */
|
||||
|
||||
#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined CVAPI_EXPORTS
|
||||
#define CV_EXPORTS __declspec(dllexport)
|
||||
# define CV_EXPORTS __declspec(dllexport)
|
||||
#else
|
||||
#define CV_EXPORTS
|
||||
# define CV_EXPORTS
|
||||
#endif
|
||||
|
||||
#ifndef CVAPI
|
||||
#define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
|
||||
# define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER || defined __BORLANDC__
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
#define CV_BIG_INT(n) n##I64
|
||||
#define CV_BIG_UINT(n) n##UI64
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
# define CV_BIG_INT(n) n##I64
|
||||
# define CV_BIG_UINT(n) n##UI64
|
||||
#else
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
#define CV_BIG_INT(n) n##LL
|
||||
#define CV_BIG_UINT(n) n##ULL
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
# define CV_BIG_INT(n) n##LL
|
||||
# define CV_BIG_UINT(n) n##ULL
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_IPL
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
#endif
|
||||
|
||||
typedef signed char schar;
|
||||
@ -262,7 +272,7 @@ enum {
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
# include "tegra_round.hpp"
|
||||
# include "tegra_round.hpp"
|
||||
#endif
|
||||
|
||||
#define CV_PI 3.1415926535897932384626433832795
|
||||
@ -271,11 +281,11 @@ enum {
|
||||
#define CV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
# define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
# define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
/* min & max without jumps */
|
||||
@ -285,9 +295,9 @@ enum {
|
||||
|
||||
/* absolute value without jumps */
|
||||
#ifndef __cplusplus
|
||||
#define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
|
||||
# define CV_IABS(a) (((a) ^ ((a) < 0 ? -1 : 0)) - ((a) < 0 ? -1 : 0))
|
||||
#else
|
||||
#define CV_IABS(a) abs(a)
|
||||
# define CV_IABS(a) abs(a)
|
||||
#endif
|
||||
#define CV_CMP(a,b) (((a) > (b)) - ((a) < (b)))
|
||||
#define CV_SIGN(a) CV_CMP((a),0)
|
||||
@ -306,11 +316,11 @@ CV_INLINE int cvRound( double value )
|
||||
}
|
||||
return t;
|
||||
#elif defined HAVE_LRINT || defined CV_ICC || defined __GNUC__
|
||||
# ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
# ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
TEGRA_ROUND(value);
|
||||
# else
|
||||
# else
|
||||
return (int)lrint(value);
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
// while this is not IEEE754-compliant rounding, it's usually a good enough approximation
|
||||
return (int)(value + (value >= 0 ? 0.5 : -0.5));
|
||||
@ -318,7 +328,7 @@ CV_INLINE int cvRound( double value )
|
||||
}
|
||||
|
||||
#if defined __SSE2__ || (defined _M_IX86_FP && 2 == _M_IX86_FP)
|
||||
#include "emmintrin.h"
|
||||
# include "emmintrin.h"
|
||||
#endif
|
||||
|
||||
CV_INLINE int cvFloor( double value )
|
||||
@ -1886,6 +1896,6 @@ typedef struct CvModuleInfo
|
||||
}
|
||||
CvModuleInfo;
|
||||
|
||||
#endif /*_CXCORE_TYPES_H_*/
|
||||
#endif /*__OPENCV_CORE_TYPES_H__*/
|
||||
|
||||
/* End of file. */
|
||||
|
@ -1,9 +1,13 @@
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
||||
#endif
|
||||
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__
|
||||
#define __OPENCV_PERF_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts/ts.hpp"
|
||||
|
||||
#if GTEST_CREATE_SHARED_LIBRARY
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
|
@ -181,124 +181,124 @@ string Algorithm::name() const
|
||||
return info()->name();
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, int value)
|
||||
void Algorithm::set(const string& parameter, int value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<int>::type, &value);
|
||||
info()->set(this, parameter.c_str(), ParamType<int>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, double value)
|
||||
void Algorithm::set(const string& parameter, double value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<double>::type, &value);
|
||||
info()->set(this, parameter.c_str(), ParamType<double>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, bool value)
|
||||
void Algorithm::set(const string& parameter, bool value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<bool>::type, &value);
|
||||
info()->set(this, parameter.c_str(), ParamType<bool>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, const string& value)
|
||||
void Algorithm::set(const string& parameter, const string& value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<string>::type, &value);
|
||||
info()->set(this, parameter.c_str(), ParamType<string>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, const Mat& value)
|
||||
void Algorithm::set(const string& parameter, const Mat& value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<Mat>::type, &value);
|
||||
info()->set(this, parameter.c_str(), ParamType<Mat>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, const vector<Mat>& value)
|
||||
void Algorithm::set(const string& parameter, const vector<Mat>& value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<vector<Mat> >::type, &value);
|
||||
info()->set(this, parameter.c_str(), ParamType<vector<Mat> >::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const string& name, const Ptr<Algorithm>& value)
|
||||
void Algorithm::set(const string& parameter, const Ptr<Algorithm>& value)
|
||||
{
|
||||
info()->set(this, name.c_str(), ParamType<Algorithm>::type, &value);
|
||||
info()->set(this, parameter.c_str(), ParamType<Algorithm>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, int value)
|
||||
void Algorithm::set(const char* parameter, int value)
|
||||
{
|
||||
info()->set(this, name, ParamType<int>::type, &value);
|
||||
info()->set(this, parameter, ParamType<int>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, double value)
|
||||
void Algorithm::set(const char* parameter, double value)
|
||||
{
|
||||
info()->set(this, name, ParamType<double>::type, &value);
|
||||
info()->set(this, parameter, ParamType<double>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, bool value)
|
||||
void Algorithm::set(const char* parameter, bool value)
|
||||
{
|
||||
info()->set(this, name, ParamType<bool>::type, &value);
|
||||
info()->set(this, parameter, ParamType<bool>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, const string& value)
|
||||
void Algorithm::set(const char* parameter, const string& value)
|
||||
{
|
||||
info()->set(this, name, ParamType<string>::type, &value);
|
||||
info()->set(this, parameter, ParamType<string>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, const Mat& value)
|
||||
void Algorithm::set(const char* parameter, const Mat& value)
|
||||
{
|
||||
info()->set(this, name, ParamType<Mat>::type, &value);
|
||||
info()->set(this, parameter, ParamType<Mat>::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, const vector<Mat>& value)
|
||||
void Algorithm::set(const char* parameter, const vector<Mat>& value)
|
||||
{
|
||||
info()->set(this, name, ParamType<vector<Mat> >::type, &value);
|
||||
info()->set(this, parameter, ParamType<vector<Mat> >::type, &value);
|
||||
}
|
||||
|
||||
void Algorithm::set(const char* name, const Ptr<Algorithm>& value)
|
||||
void Algorithm::set(const char* parameter, const Ptr<Algorithm>& value)
|
||||
{
|
||||
info()->set(this, name, ParamType<Algorithm>::type, &value);
|
||||
info()->set(this, parameter, ParamType<Algorithm>::type, &value);
|
||||
}
|
||||
|
||||
int Algorithm::getInt(const string& name) const
|
||||
int Algorithm::getInt(const string& parameter) const
|
||||
{
|
||||
return get<int>(name);
|
||||
return get<int>(parameter);
|
||||
}
|
||||
|
||||
double Algorithm::getDouble(const string& name) const
|
||||
double Algorithm::getDouble(const string& parameter) const
|
||||
{
|
||||
return get<double>(name);
|
||||
return get<double>(parameter);
|
||||
}
|
||||
|
||||
bool Algorithm::getBool(const string& name) const
|
||||
bool Algorithm::getBool(const string& parameter) const
|
||||
{
|
||||
return get<bool>(name);
|
||||
return get<bool>(parameter);
|
||||
}
|
||||
|
||||
string Algorithm::getString(const string& name) const
|
||||
string Algorithm::getString(const string& parameter) const
|
||||
{
|
||||
return get<string>(name);
|
||||
return get<string>(parameter);
|
||||
}
|
||||
|
||||
Mat Algorithm::getMat(const string& name) const
|
||||
Mat Algorithm::getMat(const string& parameter) const
|
||||
{
|
||||
return get<Mat>(name);
|
||||
return get<Mat>(parameter);
|
||||
}
|
||||
|
||||
vector<Mat> Algorithm::getMatVector(const string& name) const
|
||||
vector<Mat> Algorithm::getMatVector(const string& parameter) const
|
||||
{
|
||||
return get<vector<Mat> >(name);
|
||||
return get<vector<Mat> >(parameter);
|
||||
}
|
||||
|
||||
Ptr<Algorithm> Algorithm::getAlgorithm(const string& name) const
|
||||
Ptr<Algorithm> Algorithm::getAlgorithm(const string& parameter) const
|
||||
{
|
||||
return get<Algorithm>(name);
|
||||
return get<Algorithm>(parameter);
|
||||
}
|
||||
|
||||
string Algorithm::paramHelp(const string& name) const
|
||||
string Algorithm::paramHelp(const string& parameter) const
|
||||
{
|
||||
return info()->paramHelp(name.c_str());
|
||||
return info()->paramHelp(parameter.c_str());
|
||||
}
|
||||
|
||||
int Algorithm::paramType(const string& name) const
|
||||
int Algorithm::paramType(const string& parameter) const
|
||||
{
|
||||
return info()->paramType(name.c_str());
|
||||
return info()->paramType(parameter.c_str());
|
||||
}
|
||||
|
||||
int Algorithm::paramType(const char* name) const
|
||||
int Algorithm::paramType(const char* parameter) const
|
||||
{
|
||||
return info()->paramType(name);
|
||||
return info()->paramType(parameter);
|
||||
}
|
||||
|
||||
void Algorithm::getParams(vector<string>& names) const
|
||||
@ -440,15 +440,15 @@ union GetSetParam
|
||||
void (Algorithm::*set_algo)(const Ptr<Algorithm>&);
|
||||
};
|
||||
|
||||
void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const void* value, bool force) const
|
||||
void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, const void* value, bool force) const
|
||||
{
|
||||
const Param* p = findstr(data->params, name);
|
||||
const Param* p = findstr(data->params, parameter);
|
||||
|
||||
if( !p )
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", name ? name : "<NULL>") );
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
||||
|
||||
if( !force && p->readonly )
|
||||
CV_Error_( CV_StsError, ("Parameter '%s' is readonly", name));
|
||||
CV_Error_( CV_StsError, ("Parameter '%s' is readonly", parameter));
|
||||
|
||||
GetSetParam f;
|
||||
f.set_int = p->setter;
|
||||
@ -532,11 +532,11 @@ void AlgorithmInfo::set(Algorithm* algo, const char* name, int argType, const vo
|
||||
CV_Error(CV_StsBadArg, "Unknown/unsupported parameter type");
|
||||
}
|
||||
|
||||
void AlgorithmInfo::get(const Algorithm* algo, const char* name, int argType, void* value) const
|
||||
void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argType, void* value) const
|
||||
{
|
||||
const Param* p = findstr(data->params, name);
|
||||
const Param* p = findstr(data->params, parameter);
|
||||
if( !p )
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", name ? name : "<NULL>") );
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
||||
|
||||
GetSetParam f;
|
||||
f.get_int = p->getter;
|
||||
@ -606,20 +606,20 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* name, int argType, vo
|
||||
}
|
||||
|
||||
|
||||
int AlgorithmInfo::paramType(const char* name) const
|
||||
int AlgorithmInfo::paramType(const char* parameter) const
|
||||
{
|
||||
const Param* p = findstr(data->params, name);
|
||||
const Param* p = findstr(data->params, parameter);
|
||||
if( !p )
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", name ? name : "<NULL>") );
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
||||
return p->type;
|
||||
}
|
||||
|
||||
|
||||
string AlgorithmInfo::paramHelp(const char* name) const
|
||||
string AlgorithmInfo::paramHelp(const char* parameter) const
|
||||
{
|
||||
const Param* p = findstr(data->params, name);
|
||||
const Param* p = findstr(data->params, parameter);
|
||||
if( !p )
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", name ? name : "<NULL>") );
|
||||
CV_Error_( CV_StsBadArg, ("No parameter '%s' is found", parameter ? parameter : "<NULL>") );
|
||||
return p->help;
|
||||
}
|
||||
|
||||
@ -630,7 +630,7 @@ void AlgorithmInfo::getParams(vector<string>& names) const
|
||||
}
|
||||
|
||||
|
||||
void AlgorithmInfo::addParam_(Algorithm& algo, const char* name, int argType,
|
||||
void AlgorithmInfo::addParam_(Algorithm& algo, const char* parameter, int argType,
|
||||
void* value, bool readOnly,
|
||||
Algorithm::Getter getter, Algorithm::Setter setter,
|
||||
const string& help)
|
||||
@ -639,79 +639,79 @@ void AlgorithmInfo::addParam_(Algorithm& algo, const char* name, int argType,
|
||||
argType == Param::REAL || argType == Param::STRING ||
|
||||
argType == Param::MAT || argType == Param::MAT_VECTOR ||
|
||||
argType == Param::ALGORITHM );
|
||||
data->params.add(string(name), Param(argType, readOnly,
|
||||
data->params.add(string(parameter), Param(argType, readOnly,
|
||||
(int)((size_t)value - (size_t)(void*)&algo),
|
||||
getter, setter, help));
|
||||
}
|
||||
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
||||
int& value, bool readOnly,
|
||||
int (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(int),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<int>::type, &value, readOnly,
|
||||
addParam_(algo, parameter, ParamType<int>::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
||||
bool& value, bool readOnly,
|
||||
int (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(int),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<bool>::type, &value, readOnly,
|
||||
addParam_(algo, parameter, ParamType<bool>::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
||||
double& value, bool readOnly,
|
||||
double (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(double),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<double>::type, &value, readOnly,
|
||||
addParam_(algo, parameter, ParamType<double>::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
||||
string& value, bool readOnly,
|
||||
string (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(const string&),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<string>::type, &value, readOnly,
|
||||
addParam_(algo, parameter, ParamType<string>::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
||||
Mat& value, bool readOnly,
|
||||
Mat (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(const Mat&),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<Mat>::type, &value, readOnly,
|
||||
addParam_(algo, parameter, ParamType<Mat>::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
||||
vector<Mat>& value, bool readOnly,
|
||||
vector<Mat> (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(const vector<Mat>&),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<vector<Mat> >::type, &value, readOnly,
|
||||
addParam_(algo, parameter, ParamType<vector<Mat> >::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
|
||||
void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
|
||||
Ptr<Algorithm>& value, bool readOnly,
|
||||
Ptr<Algorithm> (Algorithm::*getter)(),
|
||||
void (Algorithm::*setter)(const Ptr<Algorithm>&),
|
||||
const string& help)
|
||||
{
|
||||
addParam_(algo, name, ParamType<Algorithm>::type, &value, readOnly,
|
||||
addParam_(algo, parameter, ParamType<Algorithm>::type, &value, readOnly,
|
||||
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,9 @@ static void* OutOfMemoryError(size_t size)
|
||||
|
||||
#if CV_USE_SYSTEM_MALLOC
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
void deleteThreadAllocData() {}
|
||||
#endif
|
||||
|
||||
void* fastMalloc( size_t size )
|
||||
{
|
||||
@ -388,7 +390,7 @@ struct ThreadData
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef WINCE
|
||||
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
|
||||
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
|
||||
#endif //WINCE
|
||||
|
||||
static DWORD tlsKey;
|
||||
|
@ -974,7 +974,7 @@ void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t bl
|
||||
scbuf[i] = scbuf[i - esz];
|
||||
}
|
||||
|
||||
void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
static void binary_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
InputArray _mask, const BinaryFunc* tab, bool bitwise)
|
||||
{
|
||||
int kind1 = _src1.kind(), kind2 = _src2.kind();
|
||||
@ -1216,7 +1216,7 @@ void cv::min(const Mat& src1, double src2, Mat& dst)
|
||||
namespace cv
|
||||
{
|
||||
|
||||
void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
InputArray _mask, int dtype, BinaryFunc* tab, bool muldiv=false, void* usrdata=0)
|
||||
{
|
||||
int kind1 = _src1.kind(), kind2 = _src2.kind();
|
||||
|
@ -6,6 +6,7 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace {
|
||||
void helpParser()
|
||||
{
|
||||
printf("\nThe CommandLineParser class is designed for command line arguments parsing\n"
|
||||
@ -89,6 +90,8 @@ string del_space(string name)
|
||||
return name;
|
||||
}
|
||||
|
||||
}//namespace
|
||||
|
||||
CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys)
|
||||
{
|
||||
std::string keys_buffer;
|
||||
|
@ -328,8 +328,8 @@ void cv::merge(const Mat* mv, size_t n, OutputArray _dst)
|
||||
if( j + blocksize < total )
|
||||
{
|
||||
ptrs[0] += bsz*esz;
|
||||
for( int k = 0; k < cn; k++ )
|
||||
ptrs[k+1] += bsz*esz1;
|
||||
for( int t = 0; t < cn; t++ )
|
||||
ptrs[t+1] += bsz*esz1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -480,12 +480,12 @@ void cv::mixChannels( const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts, cons
|
||||
dsts[k] = ptrs[tab[k*4+2]] + tab[k*4+3];
|
||||
}
|
||||
|
||||
for( int j = 0; j < total; j += blocksize )
|
||||
for( int t = 0; t < total; t += blocksize )
|
||||
{
|
||||
int bsz = std::min(total - j, blocksize);
|
||||
int bsz = std::min(total - t, blocksize);
|
||||
func( srcs, sdelta, dsts, ddelta, bsz, (int)npairs );
|
||||
|
||||
if( j + blocksize < total )
|
||||
if( t + blocksize < total )
|
||||
for( k = 0; k < npairs; k++ )
|
||||
{
|
||||
srcs[k] += blocksize*sdelta[k]*esz1;
|
||||
|
@ -59,7 +59,7 @@ copyMask_(const uchar* _src, size_t sstep, const uchar* mask, size_t mstep, ucha
|
||||
const T* src = (const T*)_src;
|
||||
T* dst = (T*)_dst;
|
||||
int x = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; x <= size.width - 4; x += 4 )
|
||||
{
|
||||
if( mask[x] )
|
||||
@ -193,10 +193,10 @@ void Mat::copyTo( OutputArray _dst ) const
|
||||
const Mat* arrays[] = { this, &dst };
|
||||
uchar* ptrs[2];
|
||||
NAryMatIterator it(arrays, ptrs, 2);
|
||||
size_t size = it.size*elemSize();
|
||||
size_t sz = it.size*elemSize();
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
memcpy(ptrs[1], ptrs[0], size);
|
||||
memcpy(ptrs[1], ptrs[0], sz);
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,14 +242,14 @@ void Mat::copyTo( OutputArray _dst, InputArray _mask ) const
|
||||
Mat& Mat::operator = (const Scalar& s)
|
||||
{
|
||||
const Mat* arrays[] = { this };
|
||||
uchar* ptr;
|
||||
NAryMatIterator it(arrays, &ptr, 1);
|
||||
size_t size = it.size*elemSize();
|
||||
uchar* dptr;
|
||||
NAryMatIterator it(arrays, &dptr, 1);
|
||||
size_t elsize = it.size*elemSize();
|
||||
|
||||
if( s[0] == 0 && s[1] == 0 && s[2] == 0 && s[3] == 0 )
|
||||
{
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
memset( ptr, 0, size );
|
||||
memset( dptr, 0, elsize );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -259,17 +259,17 @@ Mat& Mat::operator = (const Scalar& s)
|
||||
scalarToRawData(s, scalar, type(), 12);
|
||||
size_t blockSize = 12*elemSize1();
|
||||
|
||||
for( size_t j = 0; j < size; j += blockSize )
|
||||
for( size_t j = 0; j < elsize; j += blockSize )
|
||||
{
|
||||
size_t sz = MIN(blockSize, size - j);
|
||||
memcpy( ptr + j, scalar, sz );
|
||||
size_t sz = MIN(blockSize, elsize - j);
|
||||
memcpy( dptr + j, scalar, sz );
|
||||
}
|
||||
}
|
||||
|
||||
for( size_t i = 1; i < it.nplanes; i++ )
|
||||
{
|
||||
++it;
|
||||
memcpy( ptr, data, size );
|
||||
memcpy( dptr, data, elsize );
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
@ -292,16 +292,16 @@ Mat& Mat::setTo(InputArray _value, InputArray _mask)
|
||||
const Mat* arrays[] = { this, !mask.empty() ? &mask : 0, 0 };
|
||||
uchar* ptrs[2]={0,0};
|
||||
NAryMatIterator it(arrays, ptrs);
|
||||
int total = (int)it.size, blockSize0 = std::min(total, (int)((BLOCK_SIZE + esz-1)/esz));
|
||||
int totalsz = (int)it.size, blockSize0 = std::min(totalsz, (int)((BLOCK_SIZE + esz-1)/esz));
|
||||
AutoBuffer<uchar> _scbuf(blockSize0*esz + 32);
|
||||
uchar* scbuf = alignPtr((uchar*)_scbuf, (int)sizeof(double));
|
||||
convertAndUnrollScalar( value, type(), scbuf, blockSize0 );
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
for( int j = 0; j < total; j += blockSize0 )
|
||||
for( int j = 0; j < totalsz; j += blockSize0 )
|
||||
{
|
||||
Size sz(std::min(blockSize0, total - j), 1);
|
||||
Size sz(std::min(blockSize0, totalsz - j), 1);
|
||||
size_t blockSize = sz.width*esz;
|
||||
if( ptrs[1] )
|
||||
{
|
||||
|
@ -3653,7 +3653,7 @@ void KDTree::build(InputArray __points, InputArray __labels, bool _copyData)
|
||||
points.create(_points.size(), _points.type());
|
||||
}
|
||||
|
||||
int i, j, n = _points.rows, dims = _points.cols, top = 0;
|
||||
int i, j, n = _points.rows, ptdims = _points.cols, top = 0;
|
||||
const float* data = _points.ptr<float>(0);
|
||||
float* dstdata = points.ptr<float>(0);
|
||||
size_t step = _points.step1();
|
||||
@ -3669,7 +3669,7 @@ void KDTree::build(InputArray __points, InputArray __labels, bool _copyData)
|
||||
_labels_data = (const int*)_labels.data;
|
||||
}
|
||||
|
||||
Mat sumstack(MAX_TREE_DEPTH*2, dims*2, CV_64F);
|
||||
Mat sumstack(MAX_TREE_DEPTH*2, ptdims*2, CV_64F);
|
||||
SubTree stack[MAX_TREE_DEPTH*2];
|
||||
|
||||
vector<size_t> _ptofs(n);
|
||||
@ -3700,7 +3700,7 @@ void KDTree::build(InputArray __points, InputArray __labels, bool _copyData)
|
||||
{
|
||||
const float* src = data + ptofs[first];
|
||||
float* dst = dstdata + idx*dstep;
|
||||
for( j = 0; j < dims; j++ )
|
||||
for( j = 0; j < ptdims; j++ )
|
||||
dst[j] = src[j];
|
||||
}
|
||||
labels[idx] = _labels_data ? _labels_data[idx0] : idx0;
|
||||
@ -3709,7 +3709,7 @@ void KDTree::build(InputArray __points, InputArray __labels, bool _copyData)
|
||||
}
|
||||
|
||||
// find the dimensionality with the biggest variance
|
||||
for( j = 0; j < dims; j++ )
|
||||
for( j = 0; j < ptdims; j++ )
|
||||
{
|
||||
double m = sums[j*2]*invCount;
|
||||
double varj = sums[j*2+1]*invCount - m*m;
|
||||
@ -3729,9 +3729,9 @@ void KDTree::build(InputArray __points, InputArray __labels, bool _copyData)
|
||||
nodes[nidx].boundary = medianPartition(ptofs, first, last, data + dim);
|
||||
|
||||
int middle = (first + last)/2;
|
||||
double *lsums = (double*)sums, *rsums = lsums + dims*2;
|
||||
double *lsums = (double*)sums, *rsums = lsums + ptdims*2;
|
||||
computeSums(points, ptofs, middle+1, last, rsums);
|
||||
for( j = 0; j < dims*2; j++ )
|
||||
for( j = 0; j < ptdims*2; j++ )
|
||||
lsums[j] = sums[j] - rsums[j];
|
||||
stack[top++] = SubTree(first, middle, left, depth+1);
|
||||
stack[top++] = SubTree(middle+1, last, right, depth+1);
|
||||
@ -3758,7 +3758,7 @@ int KDTree::findNearest(InputArray _vec, int K, int emax,
|
||||
CV_Assert( vecmat.isContinuous() && vecmat.type() == CV_32F && vecmat.total() == (size_t)points.cols );
|
||||
const float* vec = vecmat.ptr<float>();
|
||||
K = std::min(K, points.rows);
|
||||
int dims = points.cols;
|
||||
int ptdims = points.cols;
|
||||
|
||||
CV_Assert(K > 0 && (normType == NORM_L2 || normType == NORM_L1));
|
||||
|
||||
@ -3819,13 +3819,13 @@ int KDTree::findNearest(InputArray _vec, int K, int emax,
|
||||
i = ~n.idx;
|
||||
const float* row = points.ptr<float>(i);
|
||||
if( normType == NORM_L2 )
|
||||
for( j = 0, d = 0.f; j < dims; j++ )
|
||||
for( j = 0, d = 0.f; j < ptdims; j++ )
|
||||
{
|
||||
float t = vec[j] - row[j];
|
||||
d += t*t;
|
||||
}
|
||||
else
|
||||
for( j = 0, d = 0.f; j < dims; j++ )
|
||||
for( j = 0, d = 0.f; j < ptdims; j++ )
|
||||
d += std::abs(vec[j] - row[j]);
|
||||
|
||||
dist[ncount] = d;
|
||||
@ -3898,14 +3898,14 @@ void KDTree::findOrthoRange(InputArray _lowerBound,
|
||||
OutputArray _neighbors,
|
||||
OutputArray _labels ) const
|
||||
{
|
||||
int dims = points.cols;
|
||||
int ptdims = points.cols;
|
||||
Mat lowerBound = _lowerBound.getMat(), upperBound = _upperBound.getMat();
|
||||
CV_Assert( lowerBound.size == upperBound.size &&
|
||||
lowerBound.isContinuous() &&
|
||||
upperBound.isContinuous() &&
|
||||
lowerBound.type() == upperBound.type() &&
|
||||
lowerBound.type() == CV_32F &&
|
||||
lowerBound.total() == (size_t)dims );
|
||||
lowerBound.total() == (size_t)ptdims );
|
||||
const float* L = lowerBound.ptr<float>();
|
||||
const float* R = upperBound.ptr<float>();
|
||||
|
||||
@ -3926,10 +3926,10 @@ void KDTree::findOrthoRange(InputArray _lowerBound,
|
||||
{
|
||||
int j, i = ~n.idx;
|
||||
const float* row = points.ptr<float>(i);
|
||||
for( j = 0; j < dims; j++ )
|
||||
for( j = 0; j < ptdims; j++ )
|
||||
if( row[j] < L[j] || row[j] >= R[j] )
|
||||
break;
|
||||
if( j == dims )
|
||||
if( j == ptdims )
|
||||
idx.push_back(i);
|
||||
continue;
|
||||
}
|
||||
@ -3957,7 +3957,7 @@ void KDTree::getPoints(InputArray _idx, OutputArray _pts, OutputArray _labels) c
|
||||
const int* idx = idxmat.ptr<int>();
|
||||
int* dstlabels = 0;
|
||||
|
||||
int dims = points.cols;
|
||||
int ptdims = points.cols;
|
||||
int i, nidx = (int)idxmat.total();
|
||||
if( nidx == 0 )
|
||||
{
|
||||
@ -3968,7 +3968,7 @@ void KDTree::getPoints(InputArray _idx, OutputArray _pts, OutputArray _labels) c
|
||||
|
||||
if( _pts.needed() )
|
||||
{
|
||||
_pts.create( nidx, dims, points.type());
|
||||
_pts.create( nidx, ptdims, points.type());
|
||||
pts = _pts.getMat();
|
||||
}
|
||||
|
||||
@ -3987,7 +3987,7 @@ void KDTree::getPoints(InputArray _idx, OutputArray _pts, OutputArray _labels) c
|
||||
CV_Assert( (unsigned)k < (unsigned)points.rows );
|
||||
const float* src = points.ptr<float>(k);
|
||||
if( pts.data )
|
||||
std::copy(src, src + dims, pts.ptr<float>(i));
|
||||
std::copy(src, src + ptdims, pts.ptr<float>(i));
|
||||
if( dstlabels )
|
||||
dstlabels[i] = srclabels ? srclabels[k] : k;
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2,
|
||||
}
|
||||
|
||||
int bt_pix0 = (int)img.elemSize(), bt_pix = bt_pix0;
|
||||
size_t step = img.step;
|
||||
size_t istep = img.step;
|
||||
|
||||
int dx = pt2.x - pt1.x;
|
||||
int dy = pt2.y - pt1.y;
|
||||
@ -188,11 +188,11 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2,
|
||||
bt_pix = (bt_pix ^ s) - s;
|
||||
}
|
||||
|
||||
ptr = (uchar*)(img.data + pt1.y * step + pt1.x * bt_pix0);
|
||||
ptr = (uchar*)(img.data + pt1.y * istep + pt1.x * bt_pix0);
|
||||
|
||||
s = dy < 0 ? -1 : 0;
|
||||
dy = (dy ^ s) - s;
|
||||
step = (step ^ s) - s;
|
||||
istep = (istep ^ s) - s;
|
||||
|
||||
s = dy > dx ? -1 : 0;
|
||||
|
||||
@ -201,9 +201,9 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2,
|
||||
dy ^= dx & s;
|
||||
dx ^= dy & s;
|
||||
|
||||
bt_pix ^= step & s;
|
||||
step ^= bt_pix & s;
|
||||
bt_pix ^= step & s;
|
||||
bt_pix ^= istep & s;
|
||||
istep ^= bt_pix & s;
|
||||
bt_pix ^= istep & s;
|
||||
|
||||
if( connectivity == 8 )
|
||||
{
|
||||
@ -212,7 +212,7 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2,
|
||||
err = dx - (dy + dy);
|
||||
plusDelta = dx + dx;
|
||||
minusDelta = -(dy + dy);
|
||||
plusStep = (int)step;
|
||||
plusStep = (int)istep;
|
||||
minusStep = bt_pix;
|
||||
count = dx + 1;
|
||||
}
|
||||
@ -223,7 +223,7 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2,
|
||||
err = 0;
|
||||
plusDelta = (dx + dx) + (dy + dy);
|
||||
minusDelta = -(dy + dy);
|
||||
plusStep = (int)step - bt_pix;
|
||||
plusStep = (int)istep - bt_pix;
|
||||
minusStep = bt_pix;
|
||||
count = dx + dy + 1;
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ namespace cv
|
||||
|
||||
// On Win64 optimized versions of DFT and DCT fail the tests (fixed in VS2010)
|
||||
#if defined _MSC_VER && !defined CV_ICC && defined _M_X64 && _MSC_VER < 1600
|
||||
#pragma optimize("", off)
|
||||
#pragma warning( disable : 4748 )
|
||||
# pragma optimize("", off)
|
||||
# pragma warning(disable: 4748)
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
|
@ -524,30 +524,30 @@ cv::gpu::GpuMat::GpuMat(Size size_, int type_, void* data_, size_t step_) :
|
||||
dataend += step * (rows - 1) + minstep;
|
||||
}
|
||||
|
||||
cv::gpu::GpuMat::GpuMat(const GpuMat& m, Range rowRange, Range colRange)
|
||||
cv::gpu::GpuMat::GpuMat(const GpuMat& m, Range _rowRange, Range _colRange)
|
||||
{
|
||||
flags = m.flags;
|
||||
step = m.step; refcount = m.refcount;
|
||||
data = m.data; datastart = m.datastart; dataend = m.dataend;
|
||||
|
||||
if (rowRange == Range::all())
|
||||
if (_rowRange == Range::all())
|
||||
rows = m.rows;
|
||||
else
|
||||
{
|
||||
CV_Assert(0 <= rowRange.start && rowRange.start <= rowRange.end && rowRange.end <= m.rows);
|
||||
CV_Assert(0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows);
|
||||
|
||||
rows = rowRange.size();
|
||||
data += step*rowRange.start;
|
||||
rows = _rowRange.size();
|
||||
data += step*_rowRange.start;
|
||||
}
|
||||
|
||||
if (colRange == Range::all())
|
||||
if (_colRange == Range::all())
|
||||
cols = m.cols;
|
||||
else
|
||||
{
|
||||
CV_Assert(0 <= colRange.start && colRange.start <= colRange.end && colRange.end <= m.cols);
|
||||
CV_Assert(0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols);
|
||||
|
||||
cols = colRange.size();
|
||||
data += colRange.start*elemSize();
|
||||
cols = _colRange.size();
|
||||
data += _colRange.start*elemSize();
|
||||
flags &= cols < m.cols ? ~Mat::CONTINUOUS_FLAG : -1;
|
||||
}
|
||||
|
||||
|
@ -1845,37 +1845,37 @@ iPow_( const T* src, T* dst, int len, int power )
|
||||
}
|
||||
|
||||
|
||||
void iPow8u(const uchar* src, uchar* dst, int len, int power)
|
||||
static void iPow8u(const uchar* src, uchar* dst, int len, int power)
|
||||
{
|
||||
iPow_<uchar, int>(src, dst, len, power);
|
||||
}
|
||||
|
||||
void iPow8s(const schar* src, schar* dst, int len, int power)
|
||||
static void iPow8s(const schar* src, schar* dst, int len, int power)
|
||||
{
|
||||
iPow_<schar, int>(src, dst, len, power);
|
||||
}
|
||||
|
||||
void iPow16u(const ushort* src, ushort* dst, int len, int power)
|
||||
static void iPow16u(const ushort* src, ushort* dst, int len, int power)
|
||||
{
|
||||
iPow_<ushort, int>(src, dst, len, power);
|
||||
}
|
||||
|
||||
void iPow16s(const short* src, short* dst, int len, int power)
|
||||
static void iPow16s(const short* src, short* dst, int len, int power)
|
||||
{
|
||||
iPow_<short, int>(src, dst, len, power);
|
||||
}
|
||||
|
||||
void iPow32s(const int* src, int* dst, int len, int power)
|
||||
static void iPow32s(const int* src, int* dst, int len, int power)
|
||||
{
|
||||
iPow_<int, int>(src, dst, len, power);
|
||||
}
|
||||
|
||||
void iPow32f(const float* src, float* dst, int len, int power)
|
||||
static void iPow32f(const float* src, float* dst, int len, int power)
|
||||
{
|
||||
iPow_<float, float>(src, dst, len, power);
|
||||
}
|
||||
|
||||
void iPow64f(const double* src, double* dst, int len, int power)
|
||||
static void iPow64f(const double* src, double* dst, int len, int power)
|
||||
{
|
||||
iPow_<double, double>(src, dst, len, power);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ GEMM_CopyBlock( const uchar* src, size_t src_step,
|
||||
|
||||
for( ; size.height--; src += src_step, dst += dst_step )
|
||||
{
|
||||
j=0;
|
||||
j=0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; j <= size.width - 4; j += 4 )
|
||||
{
|
||||
@ -345,7 +345,7 @@ GEMMSingleMul( const T* a_data, size_t a_step,
|
||||
for( k = 0; k < n; k++, b_data += b_step )
|
||||
{
|
||||
WT al(a_data[k]);
|
||||
j=0;
|
||||
j=0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; j <= m - 4; j += 4 )
|
||||
{
|
||||
@ -513,8 +513,8 @@ GEMMStore( const T* c_data, size_t c_step,
|
||||
if( _c_data )
|
||||
{
|
||||
c_data = _c_data;
|
||||
j=0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
j=0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; j <= d_size.width - 4; j += 4, c_data += 4*c_step1 )
|
||||
{
|
||||
WT t0 = alpha*d_buf[j];
|
||||
@ -539,8 +539,8 @@ GEMMStore( const T* c_data, size_t c_step,
|
||||
}
|
||||
else
|
||||
{
|
||||
j = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
j = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; j <= d_size.width - 4; j += 4 )
|
||||
{
|
||||
WT t0 = alpha*d_buf[j];
|
||||
@ -552,7 +552,7 @@ GEMMStore( const T* c_data, size_t c_step,
|
||||
d_data[j+2] = T(t0);
|
||||
d_data[j+3] = T(t1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
for( ; j < d_size.width; j++ )
|
||||
d_data[j] = T(alpha*d_buf[j]);
|
||||
}
|
||||
@ -696,7 +696,7 @@ static void GEMMStore_64fc( const Complexd* c_data, size_t c_step,
|
||||
}
|
||||
|
||||
void cv::gemm( InputArray matA, InputArray matB, double alpha,
|
||||
InputArray matC, double beta, OutputArray matD, int flags )
|
||||
InputArray matC, double beta, OutputArray _matD, int flags )
|
||||
{
|
||||
const int block_lin_size = 128;
|
||||
const int block_size = block_lin_size * block_lin_size;
|
||||
@ -741,8 +741,8 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha,
|
||||
((flags&GEMM_3_T) != 0 && C.rows == d_size.width && C.cols == d_size.height)));
|
||||
}
|
||||
|
||||
matD.create( d_size.height, d_size.width, type );
|
||||
Mat D = matD.getMat();
|
||||
_matD.create( d_size.height, d_size.width, type );
|
||||
Mat D = _matD.getMat();
|
||||
if( (flags & GEMM_3_T) != 0 && C.data == D.data )
|
||||
{
|
||||
transpose( C, C );
|
||||
@ -2008,7 +2008,7 @@ static void scaleAdd_32f(const float* src1, const float* src2, float* dst,
|
||||
t1 = src1[i+3]*alpha + src2[i+3];
|
||||
dst[i+2] = t0; dst[i+3] = t1;
|
||||
}
|
||||
for(; i < len; i++ )
|
||||
for(; i < len; i++ )
|
||||
dst[i] = src1[i]*alpha + src2[i];
|
||||
}
|
||||
|
||||
@ -2046,7 +2046,7 @@ static void scaleAdd_64f(const double* src1, const double* src2, double* dst,
|
||||
t1 = src1[i+3]*alpha + src2[i+3];
|
||||
dst[i+2] = t0; dst[i+3] = t1;
|
||||
}
|
||||
for(; i < len; i++ )
|
||||
for(; i < len; i++ )
|
||||
dst[i] = src1[i]*alpha + src2[i];
|
||||
}
|
||||
|
||||
@ -2134,12 +2134,12 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean,
|
||||
_mean = mean.reshape(1, size.height);
|
||||
}
|
||||
|
||||
void cv::calcCovarMatrix( InputArray _data, OutputArray _covar, InputOutputArray _mean, int flags, int ctype )
|
||||
void cv::calcCovarMatrix( InputArray _src, OutputArray _covar, InputOutputArray _mean, int flags, int ctype )
|
||||
{
|
||||
if(_data.kind() == _InputArray::STD_VECTOR_MAT)
|
||||
if(_src.kind() == _InputArray::STD_VECTOR_MAT)
|
||||
{
|
||||
std::vector<cv::Mat> src;
|
||||
_data.getMatVector(src);
|
||||
_src.getMatVector(src);
|
||||
|
||||
CV_Assert( src.size() > 0 );
|
||||
|
||||
@ -2185,7 +2185,7 @@ void cv::calcCovarMatrix( InputArray _data, OutputArray _covar, InputOutputArray
|
||||
return;
|
||||
}
|
||||
|
||||
Mat data = _data.getMat(), mean;
|
||||
Mat data = _src.getMat(), mean;
|
||||
CV_Assert( ((flags & CV_COVAR_ROWS) != 0) ^ ((flags & CV_COVAR_COLS) != 0) );
|
||||
bool takeRows = (flags & CV_COVAR_ROWS) != 0;
|
||||
int type = data.type();
|
||||
@ -2209,7 +2209,7 @@ void cv::calcCovarMatrix( InputArray _data, OutputArray _covar, InputOutputArray
|
||||
else
|
||||
{
|
||||
ctype = std::max(CV_MAT_DEPTH(ctype >= 0 ? ctype : type), CV_32F);
|
||||
reduce( _data, _mean, takeRows ? 0 : 1, CV_REDUCE_AVG, ctype );
|
||||
reduce( _src, _mean, takeRows ? 0 : 1, CV_REDUCE_AVG, ctype );
|
||||
mean = _mean.getMat();
|
||||
}
|
||||
|
||||
@ -2261,7 +2261,7 @@ double cv::Mahalanobis( InputArray _v1, InputArray _v2, InputArray _icovar )
|
||||
{
|
||||
double row_sum = 0;
|
||||
j = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; j <= len - 4; j += 4 )
|
||||
row_sum += diff[j]*mat[j] + diff[j+1]*mat[j+1] +
|
||||
diff[j+2]*mat[j+2] + diff[j+3]*mat[j+3];
|
||||
@ -2292,7 +2292,7 @@ double cv::Mahalanobis( InputArray _v1, InputArray _v2, InputArray _icovar )
|
||||
{
|
||||
double row_sum = 0;
|
||||
j = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; j <= len - 4; j += 4 )
|
||||
row_sum += diff[j]*mat[j] + diff[j+1]*mat[j+1] +
|
||||
diff[j+2]*mat[j+2] + diff[j+3]*mat[j+3];
|
||||
@ -2642,7 +2642,7 @@ dotProd_(const T* src1, const T* src2, int len)
|
||||
{
|
||||
int i = 0;
|
||||
double result = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= len - 4; i += 4 )
|
||||
result += (double)src1[i]*src2[i] + (double)src1[i+1]*src2[i+1] +
|
||||
(double)src1[i+2]*src2[i+2] + (double)src1[i+3]*src2[i+3];
|
||||
@ -2674,7 +2674,7 @@ static double dotProd_8u(const uchar* src1, const uchar* src2, int len)
|
||||
{
|
||||
blockSize = std::min(len0 - i, blockSize0);
|
||||
__m128i s = _mm_setzero_si128();
|
||||
j = 0;
|
||||
j = 0;
|
||||
for( ; j <= blockSize - 16; j += 16 )
|
||||
{
|
||||
__m128i b0 = _mm_loadu_si128((const __m128i*)(src1 + j));
|
||||
@ -2806,9 +2806,9 @@ double Mat::dot(InputArray _mat) const
|
||||
|
||||
PCA::PCA() {}
|
||||
|
||||
PCA::PCA(InputArray data, InputArray mean, int flags, int maxComponents)
|
||||
PCA::PCA(InputArray data, InputArray _mean, int flags, int maxComponents)
|
||||
{
|
||||
operator()(data, mean, flags, maxComponents);
|
||||
operator()(data, _mean, flags, maxComponents);
|
||||
}
|
||||
|
||||
PCA& PCA::operator()(InputArray _data, InputArray __mean, int flags, int maxComponents)
|
||||
|
@ -1181,14 +1181,14 @@ int MatExpr::type() const
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_Identity::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_Identity::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
if( type == -1 || type == e.a.type() )
|
||||
if( _type == -1 || _type == e.a.type() )
|
||||
m = e.a;
|
||||
else
|
||||
{
|
||||
CV_Assert( CV_MAT_CN(type) == e.a.channels() );
|
||||
e.a.convertTo(m, type);
|
||||
CV_Assert( CV_MAT_CN(_type) == e.a.channels() );
|
||||
e.a.convertTo(m, _type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1199,9 +1199,9 @@ inline void MatOp_Identity::makeExpr(MatExpr& res, const Mat& m)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_AddEx::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_AddEx::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
Mat temp, &dst = type == -1 || e.a.type() == type ? m : temp;
|
||||
Mat temp, &dst = _type == -1 || e.a.type() == _type ? m : temp;
|
||||
if( e.b.data )
|
||||
{
|
||||
if( e.s == Scalar() || !e.s.isReal() )
|
||||
@ -1233,7 +1233,7 @@ void MatOp_AddEx::assign(const MatExpr& e, Mat& m, int type) const
|
||||
}
|
||||
else if( e.s.isReal() && (dst.data != m.data || fabs(e.alpha) != 1))
|
||||
{
|
||||
e.a.convertTo(m, type, e.alpha, e.s[0]);
|
||||
e.a.convertTo(m, _type, e.alpha, e.s[0]);
|
||||
return;
|
||||
}
|
||||
else if( e.alpha == 1 )
|
||||
@ -1308,9 +1308,9 @@ inline void MatOp_AddEx::makeExpr(MatExpr& res, const Mat& a, const Mat& b, doub
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_Bin::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_Bin::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
Mat temp, &dst = type == -1 || e.a.type() == type ? m : temp;
|
||||
Mat temp, &dst = _type == -1 || e.a.type() == _type ? m : temp;
|
||||
|
||||
if( e.flags == '*' )
|
||||
cv::multiply(e.a, e.b, dst, e.alpha);
|
||||
@ -1348,7 +1348,7 @@ void MatOp_Bin::assign(const MatExpr& e, Mat& m, int type) const
|
||||
CV_Error(CV_StsError, "Unknown operation");
|
||||
|
||||
if( dst.data != m.data )
|
||||
dst.convertTo(m, type);
|
||||
dst.convertTo(m, _type);
|
||||
}
|
||||
|
||||
void MatOp_Bin::multiply(const MatExpr& e, double s, MatExpr& res) const
|
||||
@ -1382,9 +1382,9 @@ inline void MatOp_Bin::makeExpr(MatExpr& res, char op, const Mat& a, const Scala
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_Cmp::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_Cmp::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
Mat temp, &dst = type == -1 || type == CV_8U ? m : temp;
|
||||
Mat temp, &dst = _type == -1 || _type == CV_8U ? m : temp;
|
||||
|
||||
if( e.b.data )
|
||||
cv::compare(e.a, e.b, dst, e.flags);
|
||||
@ -1392,7 +1392,7 @@ void MatOp_Cmp::assign(const MatExpr& e, Mat& m, int type) const
|
||||
cv::compare(e.a, e.alpha, dst, e.flags);
|
||||
|
||||
if( dst.data != m.data )
|
||||
dst.convertTo(m, type);
|
||||
dst.convertTo(m, _type);
|
||||
}
|
||||
|
||||
inline void MatOp_Cmp::makeExpr(MatExpr& res, int cmpop, const Mat& a, const Mat& b)
|
||||
@ -1407,14 +1407,14 @@ inline void MatOp_Cmp::makeExpr(MatExpr& res, int cmpop, const Mat& a, double al
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_T::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_T::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
Mat temp, &dst = type == -1 || type == e.a.type() ? m : temp;
|
||||
Mat temp, &dst = _type == -1 || _type == e.a.type() ? m : temp;
|
||||
|
||||
cv::transpose(e.a, dst);
|
||||
|
||||
if( dst.data != m.data || e.alpha != 1 )
|
||||
dst.convertTo(m, type, e.alpha);
|
||||
dst.convertTo(m, _type, e.alpha);
|
||||
}
|
||||
|
||||
void MatOp_T::multiply(const MatExpr& e, double s, MatExpr& res) const
|
||||
@ -1438,13 +1438,13 @@ inline void MatOp_T::makeExpr(MatExpr& res, const Mat& a, double alpha)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_GEMM::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_GEMM::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
Mat temp, &dst = type == -1 || type == e.a.type() ? m : temp;
|
||||
Mat temp, &dst = _type == -1 || _type == e.a.type() ? m : temp;
|
||||
|
||||
cv::gemm(e.a, e.b, e.alpha, e.c, e.beta, dst, e.flags);
|
||||
if( dst.data != m.data )
|
||||
dst.convertTo(m, type);
|
||||
dst.convertTo(m, _type);
|
||||
}
|
||||
|
||||
void MatOp_GEMM::add(const MatExpr& e1, const MatExpr& e2, MatExpr& res) const
|
||||
@ -1503,13 +1503,13 @@ inline void MatOp_GEMM::makeExpr(MatExpr& res, int flags, const Mat& a, const Ma
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_Invert::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_Invert::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
Mat temp, &dst = type == -1 || type == e.a.type() ? m : temp;
|
||||
Mat temp, &dst = _type == -1 || _type == e.a.type() ? m : temp;
|
||||
|
||||
cv::invert(e.a, dst, e.flags);
|
||||
if( dst.data != m.data )
|
||||
dst.convertTo(m, type);
|
||||
dst.convertTo(m, _type);
|
||||
}
|
||||
|
||||
void MatOp_Invert::matmul(const MatExpr& e1, const MatExpr& e2, MatExpr& res) const
|
||||
@ -1529,13 +1529,13 @@ inline void MatOp_Invert::makeExpr(MatExpr& res, int method, const Mat& m)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_Solve::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_Solve::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
Mat temp, &dst = type == -1 || type == e.a.type() ? m : temp;
|
||||
Mat temp, &dst = _type == -1 || _type == e.a.type() ? m : temp;
|
||||
|
||||
cv::solve(e.a, e.b, dst, e.flags);
|
||||
if( dst.data != m.data )
|
||||
dst.convertTo(m, type);
|
||||
dst.convertTo(m, _type);
|
||||
}
|
||||
|
||||
inline void MatOp_Solve::makeExpr(MatExpr& res, int method, const Mat& a, const Mat& b)
|
||||
@ -1545,11 +1545,11 @@ inline void MatOp_Solve::makeExpr(MatExpr& res, int method, const Mat& a, const
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void MatOp_Initializer::assign(const MatExpr& e, Mat& m, int type) const
|
||||
void MatOp_Initializer::assign(const MatExpr& e, Mat& m, int _type) const
|
||||
{
|
||||
if( type == -1 )
|
||||
type = e.a.type();
|
||||
m.create(e.a.size(), type);
|
||||
if( _type == -1 )
|
||||
_type = e.a.type();
|
||||
m.create(e.a.size(), _type);
|
||||
if( e.flags == 'I' )
|
||||
setIdentity(m, Scalar(e.alpha));
|
||||
else if( e.flags == '0' )
|
||||
|
@ -210,9 +210,9 @@ void Mat::create(int d, const int* _sizes, int _type)
|
||||
#endif
|
||||
if( !allocator )
|
||||
{
|
||||
size_t total = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
|
||||
data = datastart = (uchar*)fastMalloc(total + (int)sizeof(*refcount));
|
||||
refcount = (int*)(data + total);
|
||||
size_t totalsize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
|
||||
data = datastart = (uchar*)fastMalloc(totalsize + (int)sizeof(*refcount));
|
||||
refcount = (int*)(data + totalsize);
|
||||
*refcount = 1;
|
||||
}
|
||||
else
|
||||
@ -225,9 +225,9 @@ void Mat::create(int d, const int* _sizes, int _type)
|
||||
}catch(...)
|
||||
{
|
||||
allocator = 0;
|
||||
size_t total = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
|
||||
data = datastart = (uchar*)fastMalloc(total + (int)sizeof(*refcount));
|
||||
refcount = (int*)(data + total);
|
||||
size_t totalSize = alignSize(step.p[0]*size.p[0], (int)sizeof(*refcount));
|
||||
data = datastart = (uchar*)fastMalloc(totalSize + (int)sizeof(*refcount));
|
||||
refcount = (int*)(data + totalSize);
|
||||
*refcount = 1;
|
||||
}
|
||||
#else
|
||||
@ -262,15 +262,15 @@ void Mat::deallocate()
|
||||
}
|
||||
|
||||
|
||||
Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&rows)
|
||||
Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) : size(&rows)
|
||||
{
|
||||
initEmpty();
|
||||
CV_Assert( m.dims >= 2 );
|
||||
if( m.dims > 2 )
|
||||
{
|
||||
AutoBuffer<Range> rs(m.dims);
|
||||
rs[0] = rowRange;
|
||||
rs[1] = colRange;
|
||||
rs[0] = _rowRange;
|
||||
rs[1] = _colRange;
|
||||
for( int i = 2; i < m.dims; i++ )
|
||||
rs[i] = Range::all();
|
||||
*this = m(rs);
|
||||
@ -278,19 +278,19 @@ Mat::Mat(const Mat& m, const Range& rowRange, const Range& colRange) : size(&row
|
||||
}
|
||||
|
||||
*this = m;
|
||||
if( rowRange != Range::all() && rowRange != Range(0,rows) )
|
||||
if( _rowRange != Range::all() && _rowRange != Range(0,rows) )
|
||||
{
|
||||
CV_Assert( 0 <= rowRange.start && rowRange.start <= rowRange.end && rowRange.end <= m.rows );
|
||||
rows = rowRange.size();
|
||||
data += step*rowRange.start;
|
||||
CV_Assert( 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows );
|
||||
rows = _rowRange.size();
|
||||
data += step*_rowRange.start;
|
||||
flags |= SUBMATRIX_FLAG;
|
||||
}
|
||||
|
||||
if( colRange != Range::all() && colRange != Range(0,cols) )
|
||||
if( _colRange != Range::all() && _colRange != Range(0,cols) )
|
||||
{
|
||||
CV_Assert( 0 <= colRange.start && colRange.start <= colRange.end && colRange.end <= m.cols );
|
||||
cols = colRange.size();
|
||||
data += colRange.start*elemSize();
|
||||
CV_Assert( 0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols );
|
||||
cols = _colRange.size();
|
||||
data += _colRange.start*elemSize();
|
||||
flags &= cols < m.cols ? ~CONTINUOUS_FLAG : -1;
|
||||
flags |= SUBMATRIX_FLAG;
|
||||
}
|
||||
@ -473,14 +473,14 @@ Mat::Mat(const IplImage* img, bool copyData) : size(&rows)
|
||||
dims = 2;
|
||||
CV_DbgAssert(CV_IS_IMAGE(img) && img->imageData != 0);
|
||||
|
||||
int depth = IPL2CV_DEPTH(img->depth);
|
||||
int imgdepth = IPL2CV_DEPTH(img->depth);
|
||||
size_t esz;
|
||||
step[0] = img->widthStep;
|
||||
|
||||
if(!img->roi)
|
||||
{
|
||||
CV_Assert(img->dataOrder == IPL_DATA_ORDER_PIXEL);
|
||||
flags = MAGIC_VAL + CV_MAKETYPE(depth, img->nChannels);
|
||||
flags = MAGIC_VAL + CV_MAKETYPE(imgdepth, img->nChannels);
|
||||
rows = img->height; cols = img->width;
|
||||
datastart = data = (uchar*)img->imageData;
|
||||
esz = CV_ELEM_SIZE(flags);
|
||||
@ -489,12 +489,12 @@ Mat::Mat(const IplImage* img, bool copyData) : size(&rows)
|
||||
{
|
||||
CV_Assert(img->dataOrder == IPL_DATA_ORDER_PIXEL || img->roi->coi != 0);
|
||||
bool selectedPlane = img->roi->coi && img->dataOrder == IPL_DATA_ORDER_PLANE;
|
||||
flags = MAGIC_VAL + CV_MAKETYPE(depth, selectedPlane ? 1 : img->nChannels);
|
||||
flags = MAGIC_VAL + CV_MAKETYPE(imgdepth, selectedPlane ? 1 : img->nChannels);
|
||||
rows = img->roi->height; cols = img->roi->width;
|
||||
esz = CV_ELEM_SIZE(flags);
|
||||
data = datastart = (uchar*)img->imageData +
|
||||
(selectedPlane ? (img->roi->coi - 1)*step*img->height : 0) +
|
||||
img->roi->yOffset*step[0] + img->roi->xOffset*esz;
|
||||
(selectedPlane ? (img->roi->coi - 1)*step*img->height : 0) +
|
||||
img->roi->yOffset*step[0] + img->roi->xOffset*esz;
|
||||
}
|
||||
datalimit = datastart + step.p[0]*rows;
|
||||
dataend = datastart + step.p[0]*(rows-1) + esz*cols;
|
||||
@ -636,11 +636,11 @@ void Mat::push_back(const Mat& elems)
|
||||
push_back(tmp);
|
||||
return;
|
||||
}
|
||||
if( !data )
|
||||
{
|
||||
*this = elems.clone();
|
||||
return;
|
||||
}
|
||||
if( !data )
|
||||
{
|
||||
*this = elems.clone();
|
||||
return;
|
||||
}
|
||||
|
||||
size.p[0] = elems.size.p[0];
|
||||
bool eq = size == elems.size;
|
||||
@ -917,6 +917,9 @@ void scalarToRawData(const Scalar& s, void* _buf, int type, int unroll_to)
|
||||
\*************************************************************************************************/
|
||||
|
||||
_InputArray::_InputArray() : flags(0), obj(0) {}
|
||||
#ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
|
||||
_InputArray::~_InputArray() {}
|
||||
#endif
|
||||
_InputArray::_InputArray(const Mat& m) : flags(MAT), obj((void*)&m) {}
|
||||
_InputArray::_InputArray(const vector<Mat>& vec) : flags(STD_VECTOR_MAT), obj((void*)&vec) {}
|
||||
_InputArray::_InputArray(const double& val) : flags(FIXED_TYPE + FIXED_SIZE + MATX + CV_64F), obj((void*)&val), sz(Size(1,1)) {}
|
||||
@ -1280,6 +1283,9 @@ bool _InputArray::empty() const
|
||||
|
||||
|
||||
_OutputArray::_OutputArray() {}
|
||||
#ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
|
||||
_OutputArray::~_OutputArray() {}
|
||||
#endif
|
||||
_OutputArray::_OutputArray(Mat& m) : _InputArray(m) {}
|
||||
_OutputArray::_OutputArray(vector<Mat>& vec) : _InputArray(vec) {}
|
||||
|
||||
@ -1297,38 +1303,38 @@ bool _OutputArray::fixedType() const
|
||||
return (flags & FIXED_TYPE) == FIXED_TYPE;
|
||||
}
|
||||
|
||||
void _OutputArray::create(Size _sz, int type, int i, bool allowTransposed, int fixedDepthMask) const
|
||||
void _OutputArray::create(Size _sz, int mtype, int i, bool allowTransposed, int fixedDepthMask) const
|
||||
{
|
||||
int k = kind();
|
||||
if( k == MAT && i < 0 && !allowTransposed && fixedDepthMask == 0 )
|
||||
{
|
||||
CV_Assert(!fixedSize() || ((Mat*)obj)->size.operator()() == _sz);
|
||||
CV_Assert(!fixedType() || ((Mat*)obj)->type() == type);
|
||||
((Mat*)obj)->create(_sz, type);
|
||||
CV_Assert(!fixedType() || ((Mat*)obj)->type() == mtype);
|
||||
((Mat*)obj)->create(_sz, mtype);
|
||||
return;
|
||||
}
|
||||
int sz[] = {_sz.height, _sz.width};
|
||||
create(2, sz, type, i, allowTransposed, fixedDepthMask);
|
||||
int sizes[] = {_sz.height, _sz.width};
|
||||
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
|
||||
}
|
||||
|
||||
void _OutputArray::create(int rows, int cols, int type, int i, bool allowTransposed, int fixedDepthMask) const
|
||||
void _OutputArray::create(int rows, int cols, int mtype, int i, bool allowTransposed, int fixedDepthMask) const
|
||||
{
|
||||
int k = kind();
|
||||
if( k == MAT && i < 0 && !allowTransposed && fixedDepthMask == 0 )
|
||||
{
|
||||
CV_Assert(!fixedSize() || ((Mat*)obj)->size.operator()() == Size(cols, rows));
|
||||
CV_Assert(!fixedType() || ((Mat*)obj)->type() == type);
|
||||
((Mat*)obj)->create(rows, cols, type);
|
||||
CV_Assert(!fixedType() || ((Mat*)obj)->type() == mtype);
|
||||
((Mat*)obj)->create(rows, cols, mtype);
|
||||
return;
|
||||
}
|
||||
int sz[] = {rows, cols};
|
||||
create(2, sz, type, i, allowTransposed, fixedDepthMask);
|
||||
int sizes[] = {rows, cols};
|
||||
create(2, sizes, mtype, i, allowTransposed, fixedDepthMask);
|
||||
}
|
||||
|
||||
void _OutputArray::create(int dims, const int* size, int type, int i, bool allowTransposed, int fixedDepthMask) const
|
||||
void _OutputArray::create(int dims, const int* sizes, int mtype, int i, bool allowTransposed, int fixedDepthMask) const
|
||||
{
|
||||
int k = kind();
|
||||
type = CV_MAT_TYPE(type);
|
||||
mtype = CV_MAT_TYPE(mtype);
|
||||
|
||||
if( k == MAT )
|
||||
{
|
||||
@ -1343,24 +1349,24 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow
|
||||
}
|
||||
|
||||
if( dims == 2 && m.dims == 2 && m.data &&
|
||||
m.type() == type && m.rows == size[1] && m.cols == size[0] )
|
||||
m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] )
|
||||
return;
|
||||
}
|
||||
|
||||
if(fixedType())
|
||||
{
|
||||
if(CV_MAT_CN(type) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
|
||||
type = m.type();
|
||||
if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
|
||||
mtype = m.type();
|
||||
else
|
||||
CV_Assert(CV_MAT_TYPE(type) == m.type());
|
||||
CV_Assert(CV_MAT_TYPE(mtype) == m.type());
|
||||
}
|
||||
if(fixedSize())
|
||||
{
|
||||
CV_Assert(m.dims == dims);
|
||||
for(int j = 0; j < dims; ++j)
|
||||
CV_Assert(m.size[j] == size[j]);
|
||||
CV_Assert(m.size[j] == sizes[j]);
|
||||
}
|
||||
m.create(dims, size, type);
|
||||
m.create(dims, sizes, mtype);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1368,16 +1374,16 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow
|
||||
{
|
||||
CV_Assert( i < 0 );
|
||||
int type0 = CV_MAT_TYPE(flags);
|
||||
CV_Assert( type == type0 || (CV_MAT_CN(type) == 1 && ((1 << type0) & fixedDepthMask) != 0) );
|
||||
CV_Assert( dims == 2 && ((size[0] == sz.height && size[1] == sz.width) ||
|
||||
(allowTransposed && size[0] == sz.width && size[1] == sz.height)));
|
||||
CV_Assert( mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0) );
|
||||
CV_Assert( dims == 2 && ((sizes[0] == sz.height && sizes[1] == sz.width) ||
|
||||
(allowTransposed && sizes[0] == sz.width && sizes[1] == sz.height)));
|
||||
return;
|
||||
}
|
||||
|
||||
if( k == STD_VECTOR || k == STD_VECTOR_VECTOR )
|
||||
{
|
||||
CV_Assert( dims == 2 && (size[0] == 1 || size[1] == 1 || size[0]*size[1] == 0) );
|
||||
size_t len = size[0]*size[1] > 0 ? size[0] + size[1] - 1 : 0;
|
||||
CV_Assert( dims == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0) );
|
||||
size_t len = sizes[0]*sizes[1] > 0 ? sizes[0] + sizes[1] - 1 : 0;
|
||||
vector<uchar>* v = (vector<uchar>*)obj;
|
||||
|
||||
if( k == STD_VECTOR_VECTOR )
|
||||
@ -1396,7 +1402,7 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow
|
||||
CV_Assert( i < 0 );
|
||||
|
||||
int type0 = CV_MAT_TYPE(flags);
|
||||
CV_Assert( type == type0 || (CV_MAT_CN(type) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0) );
|
||||
CV_Assert( mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0) );
|
||||
|
||||
int esz = CV_ELEM_SIZE(type0);
|
||||
CV_Assert(!fixedSize() || len == ((vector<uchar>*)v)->size() / esz);
|
||||
@ -1469,20 +1475,20 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow
|
||||
|
||||
if( i < 0 )
|
||||
{
|
||||
CV_Assert( dims == 2 && (size[0] == 1 || size[1] == 1 || size[0]*size[1] == 0) );
|
||||
size_t len = size[0]*size[1] > 0 ? size[0] + size[1] - 1 : 0, len0 = v.size();
|
||||
CV_Assert( dims == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0) );
|
||||
size_t len = sizes[0]*sizes[1] > 0 ? sizes[0] + sizes[1] - 1 : 0, len0 = v.size();
|
||||
|
||||
CV_Assert(!fixedSize() || len == len0);
|
||||
v.resize(len);
|
||||
if( fixedType() )
|
||||
{
|
||||
int type = CV_MAT_TYPE(flags);
|
||||
int _type = CV_MAT_TYPE(flags);
|
||||
for( size_t j = len0; j < len; j++ )
|
||||
{
|
||||
if( v[i].type() == type )
|
||||
if( v[i].type() == _type )
|
||||
continue;
|
||||
CV_Assert( v[i].empty() );
|
||||
v[i].flags = (v[i].flags & ~CV_MAT_TYPE_MASK) | type;
|
||||
v[i].flags = (v[i].flags & ~CV_MAT_TYPE_MASK) | _type;
|
||||
}
|
||||
}
|
||||
return;
|
||||
@ -1500,25 +1506,25 @@ void _OutputArray::create(int dims, const int* size, int type, int i, bool allow
|
||||
}
|
||||
|
||||
if( dims == 2 && m.dims == 2 && m.data &&
|
||||
m.type() == type && m.rows == size[1] && m.cols == size[0] )
|
||||
m.type() == mtype && m.rows == sizes[1] && m.cols == sizes[0] )
|
||||
return;
|
||||
}
|
||||
|
||||
if(fixedType())
|
||||
{
|
||||
if(CV_MAT_CN(type) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
|
||||
type = m.type();
|
||||
if(CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0 )
|
||||
mtype = m.type();
|
||||
else
|
||||
CV_Assert(!fixedType() || (CV_MAT_CN(type) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0));
|
||||
CV_Assert(!fixedType() || (CV_MAT_CN(mtype) == m.channels() && ((1 << CV_MAT_TYPE(flags)) & fixedDepthMask) != 0));
|
||||
}
|
||||
if(fixedSize())
|
||||
{
|
||||
CV_Assert(m.dims == dims);
|
||||
for(int j = 0; j < dims; ++j)
|
||||
CV_Assert(m.size[j] == size[j]);
|
||||
CV_Assert(m.size[j] == sizes[j]);
|
||||
}
|
||||
|
||||
m.create(dims, size, type);
|
||||
m.create(dims, sizes, mtype);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1763,7 +1769,7 @@ transpose_( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size sz )
|
||||
{
|
||||
int i=0, j, m = sz.width, n = sz.height;
|
||||
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= m - 4; i += 4 )
|
||||
{
|
||||
T* d0 = (T*)(dst + dstep*i);
|
||||
@ -1795,7 +1801,7 @@ transpose_( const uchar* src, size_t sstep, uchar* dst, size_t dstep, Size sz )
|
||||
{
|
||||
T* d0 = (T*)(dst + dstep*i);
|
||||
j = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; j <= n - 4; j += 4 )
|
||||
{
|
||||
const T* s0 = (const T*)(src + i*sizeof(T) + sstep*j);
|
||||
@ -1927,10 +1933,10 @@ void cv::completeSymm( InputOutputArray _m, bool LtoR )
|
||||
cv::Mat cv::Mat::cross(InputArray _m) const
|
||||
{
|
||||
Mat m = _m.getMat();
|
||||
int t = type(), d = CV_MAT_DEPTH(t);
|
||||
CV_Assert( dims <= 2 && m.dims <= 2 && size() == m.size() && t == m.type() &&
|
||||
int tp = type(), d = CV_MAT_DEPTH(tp);
|
||||
CV_Assert( dims <= 2 && m.dims <= 2 && size() == m.size() && tp == m.type() &&
|
||||
((rows == 3 && cols == 1) || (cols*channels() == 3 && rows == 1)));
|
||||
Mat result(rows, cols, t);
|
||||
Mat result(rows, cols, tp);
|
||||
|
||||
if( d == CV_32F )
|
||||
{
|
||||
@ -1985,7 +1991,7 @@ reduceR_( const Mat& srcmat, Mat& dstmat )
|
||||
{
|
||||
src += srcstep;
|
||||
i = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= size.width - 4; i += 4 )
|
||||
{
|
||||
WT s0, s1;
|
||||
@ -2044,7 +2050,7 @@ reduceC_( const Mat& srcmat, Mat& dstmat )
|
||||
dst[k] = (ST)a0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef void (*ReduceFunc)( const Mat& src, Mat& dst );
|
||||
@ -2577,8 +2583,8 @@ double cv::kmeans( InputArray _data, int K,
|
||||
sample = data.ptr<float>(i);
|
||||
k = labels[i];
|
||||
float* center = centers.ptr<float>(k);
|
||||
j=0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
j=0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; j <= dims - 4; j += 4 )
|
||||
{
|
||||
float t0 = center[j] + sample[j];
|
||||
@ -2843,7 +2849,7 @@ cvRange( CvArr* arr, double start, double end )
|
||||
CV_IMPL void
|
||||
cvSort( const CvArr* _src, CvArr* _dst, CvArr* _idx, int flags )
|
||||
{
|
||||
cv::Mat src = cv::cvarrToMat(_src), dst, idx;
|
||||
cv::Mat src = cv::cvarrToMat(_src);
|
||||
|
||||
if( _idx )
|
||||
{
|
||||
@ -3260,7 +3266,7 @@ convertScaleData_(const void* _from, void* _to, int cn, double alpha, double bet
|
||||
to[i] = saturate_cast<T2>(from[i]*alpha + beta);
|
||||
}
|
||||
|
||||
ConvertData getConvertData(int fromType, int toType)
|
||||
static ConvertData getConvertData(int fromType, int toType)
|
||||
{
|
||||
static ConvertData tab[][8] =
|
||||
{{ convertData_<uchar, uchar>, convertData_<uchar, schar>,
|
||||
@ -3305,7 +3311,7 @@ ConvertData getConvertData(int fromType, int toType)
|
||||
return func;
|
||||
}
|
||||
|
||||
ConvertScaleData getConvertScaleData(int fromType, int toType)
|
||||
static ConvertScaleData getConvertScaleData(int fromType, int toType)
|
||||
{
|
||||
static ConvertScaleData tab[][8] =
|
||||
{{ convertScaleData_<uchar, uchar>, convertScaleData_<uchar, schar>,
|
||||
@ -3408,22 +3414,22 @@ SparseMat::SparseMat(const Mat& m)
|
||||
|
||||
int i, idx[CV_MAX_DIM] = {0}, d = m.dims, lastSize = m.size[d - 1];
|
||||
size_t esz = m.elemSize();
|
||||
uchar* ptr = m.data;
|
||||
uchar* dptr = m.data;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
for( i = 0; i < lastSize; i++, ptr += esz )
|
||||
for( i = 0; i < lastSize; i++, dptr += esz )
|
||||
{
|
||||
if( isZeroElem(ptr, esz) )
|
||||
if( isZeroElem(dptr, esz) )
|
||||
continue;
|
||||
idx[d-1] = i;
|
||||
uchar* to = newNode(idx, hash(idx));
|
||||
copyElem( ptr, to, esz );
|
||||
copyElem( dptr, to, esz );
|
||||
}
|
||||
|
||||
for( i = d - 2; i >= 0; i-- )
|
||||
{
|
||||
ptr += m.step[i] - m.size[i+1]*m.step[i+1];
|
||||
dptr += m.step[i] - m.size[i+1]*m.step[i+1];
|
||||
if( ++idx[i] < m.size[i] )
|
||||
break;
|
||||
idx[i] = 0;
|
||||
|
@ -163,11 +163,11 @@ void icvSetOpenGlFuncTab(const CvOpenGlFuncTab* tab)
|
||||
void cv::gpu::setGlDevice(int device)
|
||||
{
|
||||
#ifndef HAVE_CUDA
|
||||
(void)device;
|
||||
(void)device;
|
||||
throw_nocuda;
|
||||
#else
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)device;
|
||||
(void)device;
|
||||
throw_nogl;
|
||||
#else
|
||||
if (!glFuncTab()->isGlContextInitialized())
|
||||
@ -484,57 +484,57 @@ inline void cv::GlBuffer::Impl::unmapDevice(cudaStream_t stream)
|
||||
|
||||
#endif // HAVE_OPENGL
|
||||
|
||||
cv::GlBuffer::GlBuffer(Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage)
|
||||
cv::GlBuffer::GlBuffer(Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)usage;
|
||||
(void)_usage;
|
||||
throw_nogl;
|
||||
#else
|
||||
impl_ = Impl::empty();
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlBuffer::GlBuffer(int rows, int cols, int type, Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage)
|
||||
cv::GlBuffer::GlBuffer(int _rows, int _cols, int _type, Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)rows;
|
||||
(void)cols;
|
||||
(void)type;
|
||||
(void)usage;
|
||||
(void)_rows;
|
||||
(void)_cols;
|
||||
(void)_type;
|
||||
(void)_usage;
|
||||
throw_nogl;
|
||||
#else
|
||||
impl_ = new Impl(rows, cols, type, usage);
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
type_ = type;
|
||||
impl_ = new Impl(_rows, _cols, _type, _usage);
|
||||
rows_ = _rows;
|
||||
cols_ = _cols;
|
||||
type_ = _type;
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlBuffer::GlBuffer(Size size, int type, Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage)
|
||||
cv::GlBuffer::GlBuffer(Size _size, int _type, Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)size;
|
||||
(void)type;
|
||||
(void)usage;
|
||||
(void)_size;
|
||||
(void)_type;
|
||||
(void)_usage;
|
||||
throw_nogl;
|
||||
#else
|
||||
impl_ = new Impl(size.height, size.width, type, usage);
|
||||
rows_ = size.height;
|
||||
cols_ = size.width;
|
||||
type_ = type;
|
||||
impl_ = new Impl(_size.height, _size.width, _type, _usage);
|
||||
rows_ = _size.height;
|
||||
cols_ = _size.width;
|
||||
type_ = _type;
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlBuffer::GlBuffer(InputArray mat_, Usage usage) : rows_(0), cols_(0), type_(0), usage_(usage)
|
||||
cv::GlBuffer::GlBuffer(InputArray mat_, Usage _usage) : rows_(0), cols_(0), type_(0), usage_(_usage)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)mat_;
|
||||
(void)usage;
|
||||
(void)mat_;
|
||||
(void)_usage;
|
||||
throw_nogl;
|
||||
#else
|
||||
int kind = mat_.kind();
|
||||
Size size = mat_.size();
|
||||
int type = mat_.type();
|
||||
Size _size = mat_.size();
|
||||
int _type = mat_.type();
|
||||
|
||||
if (kind == _InputArray::GPU_MAT)
|
||||
{
|
||||
@ -542,38 +542,38 @@ cv::GlBuffer::GlBuffer(InputArray mat_, Usage usage) : rows_(0), cols_(0), type_
|
||||
throw_nocuda;
|
||||
#else
|
||||
GpuMat d_mat = mat_.getGpuMat();
|
||||
impl_ = new Impl(d_mat.rows, d_mat.cols, d_mat.type(), usage);
|
||||
impl_ = new Impl(d_mat.rows, d_mat.cols, d_mat.type(), _usage);
|
||||
impl_->copyFrom(d_mat);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat mat = mat_.getMat();
|
||||
impl_ = new Impl(mat, usage);
|
||||
impl_ = new Impl(mat, _usage);
|
||||
}
|
||||
|
||||
rows_ = size.height;
|
||||
cols_ = size.width;
|
||||
type_ = type;
|
||||
rows_ = _size.height;
|
||||
cols_ = _size.width;
|
||||
type_ = _type;
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::GlBuffer::create(int rows, int cols, int type, Usage usage)
|
||||
void cv::GlBuffer::create(int _rows, int _cols, int _type, Usage _usage)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)rows;
|
||||
(void)cols;
|
||||
(void)type;
|
||||
(void)usage;
|
||||
(void)_rows;
|
||||
(void)_cols;
|
||||
(void)_type;
|
||||
(void)_usage;
|
||||
throw_nogl;
|
||||
#else
|
||||
if (rows_ != rows || cols_ != cols || type_ != type || usage_ != usage)
|
||||
if (rows_ != _rows || cols_ != _cols || type_ != _type || usage_ != _usage)
|
||||
{
|
||||
impl_ = new Impl(rows, cols, type, usage);
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
type_ = type;
|
||||
usage_ = usage;
|
||||
impl_ = new Impl(_rows, _cols, _type, _usage);
|
||||
rows_ = _rows;
|
||||
cols_ = _cols;
|
||||
type_ = _type;
|
||||
usage_ = _usage;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -590,14 +590,14 @@ void cv::GlBuffer::release()
|
||||
void cv::GlBuffer::copyFrom(InputArray mat_)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)mat_;
|
||||
(void)mat_;
|
||||
throw_nogl;
|
||||
#else
|
||||
int kind = mat_.kind();
|
||||
Size size = mat_.size();
|
||||
int type = mat_.type();
|
||||
Size _size = mat_.size();
|
||||
int _type = mat_.type();
|
||||
|
||||
create(size, type);
|
||||
create(_size, _type);
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
@ -926,45 +926,45 @@ cv::GlTexture::GlTexture() : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTUR
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlTexture::GlTexture(int rows, int cols, int type) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER)
|
||||
cv::GlTexture::GlTexture(int _rows, int _cols, int _type) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)rows;
|
||||
(void)cols;
|
||||
(void)type;
|
||||
(void)_rows;
|
||||
(void)_cols;
|
||||
(void)_type;
|
||||
throw_nogl;
|
||||
#else
|
||||
impl_ = new Impl(rows, cols, type);
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
type_ = type;
|
||||
impl_ = new Impl(_rows, _cols, _type);
|
||||
rows_ = _rows;
|
||||
cols_ = _cols;
|
||||
type_ = _type;
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlTexture::GlTexture(Size size, int type) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER)
|
||||
cv::GlTexture::GlTexture(Size _size, int _type) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)size;
|
||||
(void)type;
|
||||
(void)_size;
|
||||
(void)_type;
|
||||
throw_nogl;
|
||||
#else
|
||||
impl_ = new Impl(size.height, size.width, type);
|
||||
rows_ = size.height;
|
||||
cols_ = size.width;
|
||||
type_ = type;
|
||||
impl_ = new Impl(_size.height, _size.width, _type);
|
||||
rows_ = _size.height;
|
||||
cols_ = _size.width;
|
||||
type_ = _type;
|
||||
#endif
|
||||
}
|
||||
|
||||
cv::GlTexture::GlTexture(InputArray mat_, bool bgra) : rows_(0), cols_(0), type_(0), buf_(GlBuffer::TEXTURE_BUFFER)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)mat_;
|
||||
(void)bgra;
|
||||
(void)mat_;
|
||||
(void)bgra;
|
||||
throw_nogl;
|
||||
#else
|
||||
int kind = mat_.kind();
|
||||
Size size = mat_.size();
|
||||
int type = mat_.type();
|
||||
Size _size = mat_.size();
|
||||
int _type = mat_.type();
|
||||
|
||||
switch (kind)
|
||||
{
|
||||
@ -994,26 +994,26 @@ cv::GlTexture::GlTexture(InputArray mat_, bool bgra) : rows_(0), cols_(0), type_
|
||||
}
|
||||
}
|
||||
|
||||
rows_ = size.height;
|
||||
cols_ = size.width;
|
||||
type_ = type;
|
||||
rows_ = _size.height;
|
||||
cols_ = _size.width;
|
||||
type_ = _type;
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::GlTexture::create(int rows, int cols, int type)
|
||||
void cv::GlTexture::create(int _rows, int _cols, int _type)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)rows;
|
||||
(void)cols;
|
||||
(void)type;
|
||||
(void)_rows;
|
||||
(void)_cols;
|
||||
(void)_type;
|
||||
throw_nogl;
|
||||
#else
|
||||
if (rows_ != rows || cols_ != cols || type_ != type)
|
||||
if (rows_ != _rows || cols_ != _cols || type_ != _type)
|
||||
{
|
||||
impl_ = new Impl(rows, cols, type);
|
||||
rows_ = rows;
|
||||
cols_ = cols;
|
||||
type_ = type;
|
||||
impl_ = new Impl(_rows, _cols, _type);
|
||||
rows_ = _rows;
|
||||
cols_ = _cols;
|
||||
type_ = _type;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1030,15 +1030,15 @@ void cv::GlTexture::release()
|
||||
void cv::GlTexture::copyFrom(InputArray mat_, bool bgra)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)mat_;
|
||||
(void)bgra;
|
||||
(void)mat_;
|
||||
(void)bgra;
|
||||
throw_nogl;
|
||||
#else
|
||||
int kind = mat_.kind();
|
||||
Size size = mat_.size();
|
||||
int type = mat_.type();
|
||||
Size _size = mat_.size();
|
||||
int _type = mat_.type();
|
||||
|
||||
create(size, type);
|
||||
create(_size, _type);
|
||||
|
||||
switch(kind)
|
||||
{
|
||||
@ -1244,8 +1244,8 @@ void cv::GlArrays::unbind() const
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// GlFont
|
||||
|
||||
cv::GlFont::GlFont(const string& family, int height, Weight weight, Style style)
|
||||
: family_(family), height_(height), weight_(weight), style_(style), base_(0)
|
||||
cv::GlFont::GlFont(const string& _family, int _height, Weight _weight, Style _style)
|
||||
: family_(_family), height_(_height), weight_(_weight), style_(_style), base_(0)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
throw_nogl;
|
||||
@ -1253,7 +1253,7 @@ cv::GlFont::GlFont(const string& family, int height, Weight weight, Style style)
|
||||
base_ = glGenLists(256);
|
||||
CV_CheckGlError();
|
||||
|
||||
glFuncTab()->generateBitmapFont(family, height, weight, (style & STYLE_ITALIC) != 0, (style & STYLE_UNDERLINE) != 0, 0, 256, base_);
|
||||
glFuncTab()->generateBitmapFont(family_, height_, weight_, (style_ & STYLE_ITALIC) != 0, (style_ & STYLE_UNDERLINE) != 0, 0, 256, base_);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1304,10 +1304,10 @@ namespace
|
||||
Ptr<GlFont> cv::GlFont::get(const std::string& family, int height, Weight weight, Style style)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)family;
|
||||
(void)height;
|
||||
(void)weight;
|
||||
(void)style;
|
||||
(void)family;
|
||||
(void)height;
|
||||
(void)weight;
|
||||
(void)style;
|
||||
throw_nogl;
|
||||
return Ptr<GlFont>();
|
||||
#else
|
||||
@ -1333,9 +1333,9 @@ Ptr<GlFont> cv::GlFont::get(const std::string& family, int height, Weight weight
|
||||
void cv::render(const GlTexture& tex, Rect_<double> wndRect, Rect_<double> texRect)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)tex;
|
||||
(void)wndRect;
|
||||
(void)texRect;
|
||||
(void)tex;
|
||||
(void)wndRect;
|
||||
(void)texRect;
|
||||
throw_nogl;
|
||||
#else
|
||||
if (!tex.empty())
|
||||
@ -1368,9 +1368,9 @@ void cv::render(const GlTexture& tex, Rect_<double> wndRect, Rect_<double> texRe
|
||||
void cv::render(const GlArrays& arr, int mode, Scalar color)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)arr;
|
||||
(void)mode;
|
||||
(void)color;
|
||||
(void)arr;
|
||||
(void)mode;
|
||||
(void)color;
|
||||
throw_nogl;
|
||||
#else
|
||||
glColor3d(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0);
|
||||
@ -1386,10 +1386,10 @@ void cv::render(const GlArrays& arr, int mode, Scalar color)
|
||||
void cv::render(const string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)str;
|
||||
(void)font;
|
||||
(void)color;
|
||||
(void)pos;
|
||||
(void)str;
|
||||
(void)font;
|
||||
(void)color;
|
||||
(void)pos;
|
||||
throw_nogl;
|
||||
#else
|
||||
glPushAttrib(GL_DEPTH_BUFFER_BIT);
|
||||
@ -1544,9 +1544,9 @@ void cv::GlCamera::setupModelViewMatrix() const
|
||||
bool icvCheckGlError(const char* file, const int line, const char* func)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
(void)file;
|
||||
(void)line;
|
||||
(void)func;
|
||||
(void)file;
|
||||
(void)line;
|
||||
(void)func;
|
||||
return true;
|
||||
#else
|
||||
GLenum err = glGetError();
|
||||
|
@ -243,7 +243,7 @@ static CFormatter cFormatter;
|
||||
static const Formatter* g_defaultFormatter0 = &matlabFormatter;
|
||||
static const Formatter* g_defaultFormatter = &matlabFormatter;
|
||||
|
||||
bool my_streq(const char* a, const char* b)
|
||||
static bool my_streq(const char* a, const char* b)
|
||||
{
|
||||
size_t i, alen = strlen(a), blen = strlen(b);
|
||||
if( alen != blen )
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user