moved gtest to modules; added some gtest-based tests
This commit is contained in:
parent
ba32833c3f
commit
97d9a672cc
4
3rdparty/CMakeLists.txt
vendored
4
3rdparty/CMakeLists.txt
vendored
@ -16,7 +16,3 @@ endif()
|
|||||||
if(WITH_TIFF AND NOT TIFF_FOUND)
|
if(WITH_TIFF AND NOT TIFF_FOUND)
|
||||||
add_subdirectory(libtiff)
|
add_subdirectory(libtiff)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(0)
|
|
||||||
add_subdirectory(gtest)
|
|
||||||
endif()
|
|
||||||
|
29
3rdparty/gtest/CMakeLists.txt
vendored
29
3rdparty/gtest/CMakeLists.txt
vendored
@ -1,29 +0,0 @@
|
|||||||
project(opencv_gtest)
|
|
||||||
|
|
||||||
# List of C++ files:
|
|
||||||
|
|
||||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/..")
|
|
||||||
|
|
||||||
# The .cpp files:
|
|
||||||
file(GLOB lib_srcs *.cpp)
|
|
||||||
file(GLOB lib_hdrs *.h)
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------------
|
|
||||||
# Define the library target:
|
|
||||||
# ----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
set(the_target "opencv_gtest")
|
|
||||||
|
|
||||||
add_library(${the_target} STATIC ${lib_srcs} ${lib_hdrs})
|
|
||||||
|
|
||||||
if(UNIX)
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set_target_properties(${the_target}
|
|
||||||
PROPERTIES OUTPUT_NAME "${the_target}"
|
|
||||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
|
||||||
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/3rdparty/lib
|
|
||||||
)
|
|
@ -1,85 +1,203 @@
|
|||||||
# this is template for a OpenCV module
|
# this is template for a OpenCV module
|
||||||
macro(define_opencv_module name)
|
macro(define_opencv_module name)
|
||||||
|
|
||||||
project(opencv_${name})
|
project(opencv_${name})
|
||||||
add_definitions(-DCVAPI_EXPORTS)
|
add_definitions(-DCVAPI_EXPORTS)
|
||||||
|
|
||||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}")
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
|
||||||
foreach(d ${ARGN})
|
foreach(d ${ARGN})
|
||||||
if(${d} MATCHES "opencv_")
|
if(${d} MATCHES "opencv_")
|
||||||
if(${d} MATCHES "opencv_lapack")
|
if(${d} MATCHES "opencv_lapack")
|
||||||
else()
|
else()
|
||||||
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
|
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
|
||||||
include_directories("${d_dir}/include")
|
include_directories("${d_dir}/include")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
file(GLOB lib_srcs "src/*.cpp")
|
file(GLOB lib_srcs "src/*.cpp")
|
||||||
file(GLOB lib_int_hdrs "src/*.h*")
|
file(GLOB lib_int_hdrs "src/*.h*")
|
||||||
source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
|
source_group("Src" FILES ${lib_srcs} ${lib_int_hdrs})
|
||||||
|
|
||||||
file(GLOB lib_hdrs "include/opencv2/${name}/*.h*")
|
file(GLOB lib_hdrs "include/opencv2/${name}/*.h*")
|
||||||
source_group("Include" FILES ${lib_hdrs})
|
source_group("Include" FILES ${lib_hdrs})
|
||||||
|
|
||||||
set(the_target "opencv_${name}")
|
set(the_target "opencv_${name}")
|
||||||
|
|
||||||
add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})
|
add_library(${the_target} ${lib_srcs} ${lib_hdrs} ${lib_int_hdrs})
|
||||||
|
|
||||||
if(PCHSupport_FOUND)
|
if(PCHSupport_FOUND)
|
||||||
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp)
|
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/src/precomp.hpp)
|
||||||
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
|
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
|
||||||
if(${CMAKE_GENERATOR} MATCHES "Visual*")
|
if(${CMAKE_GENERATOR} MATCHES "Visual*")
|
||||||
set(${the_target}_pch "src/precomp.cpp")
|
set(${the_target}_pch "src/precomp.cpp")
|
||||||
endif()
|
endif()
|
||||||
add_native_precompiled_header(${the_target} ${pch_header})
|
add_native_precompiled_header(${the_target} ${pch_header})
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
|
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
|
||||||
add_precompiled_header(${the_target} ${pch_header})
|
add_precompiled_header(${the_target} ${pch_header})
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# For dynamic link numbering convenions
|
# For dynamic link numbering convenions
|
||||||
set_target_properties(${the_target} PROPERTIES
|
set_target_properties(${the_target} PROPERTIES
|
||||||
VERSION ${OPENCV_VERSION}
|
VERSION ${OPENCV_VERSION}
|
||||||
SOVERSION ${OPENCV_SOVERSION}
|
SOVERSION ${OPENCV_SOVERSION}
|
||||||
OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}"
|
OUTPUT_NAME "${the_target}${OPENCV_DLLVERSION}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Additional target properties
|
# Additional target properties
|
||||||
set_target_properties(${the_target} PROPERTIES
|
set_target_properties(${the_target} PROPERTIES
|
||||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||||
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/"
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/"
|
||||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
||||||
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
|
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add the required libraries for linking:
|
# Add the required libraries for linking:
|
||||||
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
|
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
if(CMAKE_CROSSCOMPILING)
|
if(CMAKE_CROSSCOMPILING)
|
||||||
set_target_properties(${the_target} PROPERTIES
|
set_target_properties(${the_target} PROPERTIES
|
||||||
LINK_FLAGS "/NODEFAULTLIB:secchk"
|
LINK_FLAGS "/NODEFAULTLIB:secchk"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
set_target_properties(${the_target} PROPERTIES
|
set_target_properties(${the_target} PROPERTIES
|
||||||
LINK_FLAGS "/NODEFAULTLIB:libc"
|
LINK_FLAGS "/NODEFAULTLIB:libc"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Dependencies of this target:
|
# Dependencies of this target:
|
||||||
add_dependencies(${the_target} ${ARGN})
|
add_dependencies(${the_target} ${ARGN})
|
||||||
|
|
||||||
install(TARGETS ${the_target}
|
install(TARGETS ${the_target}
|
||||||
RUNTIME DESTINATION bin COMPONENT main
|
RUNTIME DESTINATION bin COMPONENT main
|
||||||
LIBRARY DESTINATION lib COMPONENT main
|
LIBRARY DESTINATION lib COMPONENT main
|
||||||
ARCHIVE DESTINATION lib COMPONENT main)
|
ARCHIVE DESTINATION lib COMPONENT main)
|
||||||
|
|
||||||
install(FILES ${lib_hdrs}
|
install(FILES ${lib_hdrs}
|
||||||
DESTINATION include/opencv2/${name}
|
DESTINATION include/opencv2/${name}
|
||||||
COMPONENT main)
|
COMPONENT main)
|
||||||
|
|
||||||
|
if(BUILD_TESTS AND NOT ANDROID AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||||
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
"${CMAKE_SOURCE_DIR}/modules/gtest/include")
|
||||||
|
|
||||||
|
foreach(d ${ARGN})
|
||||||
|
if(${d} MATCHES "opencv_")
|
||||||
|
if(${d} MATCHES "opencv_lapack")
|
||||||
|
else()
|
||||||
|
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
|
||||||
|
include_directories("${d_dir}/include")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
file(GLOB test_srcs "test/*.cpp")
|
||||||
|
file(GLOB test_hdrs "test/*.h*")
|
||||||
|
|
||||||
|
set(the_target "opencv_gtest_${name}")
|
||||||
|
|
||||||
|
add_executable(${the_target} ${test_srcs} ${test_hdrs})
|
||||||
|
|
||||||
|
if(PCHSupport_FOUND)
|
||||||
|
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/test/precomp.hpp)
|
||||||
|
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
|
||||||
|
if(${CMAKE_GENERATOR} MATCHES "Visual*")
|
||||||
|
set(${the_target}_pch "test/precomp.cpp")
|
||||||
|
endif()
|
||||||
|
add_native_precompiled_header(${the_target} ${pch_header})
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
|
||||||
|
add_precompiled_header(${the_target} ${pch_header})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Additional target properties
|
||||||
|
set_target_properties(${the_target} PROPERTIES
|
||||||
|
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_dependencies(${the_target} ${ARGN} opencv_gtest)
|
||||||
|
|
||||||
|
# Add the required libraries for linking:
|
||||||
|
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${ARGN} opencv_gtest)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
get_target_property(LOC ${the_target} LOCATION)
|
||||||
|
add_test(${the_target} "${LOC}")
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
|
if(0)
|
||||||
|
macro(define_opencv_test name)
|
||||||
|
|
||||||
|
if(BUILD_TESTS AND NOT ANDROID AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||||
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
"${CMAKE_SOURCE_DIR}/modules/gtest/include")
|
||||||
|
|
||||||
|
foreach(d ${ARGN})
|
||||||
|
if(${d} MATCHES "opencv_")
|
||||||
|
if(${d} MATCHES "opencv_lapack")
|
||||||
|
else()
|
||||||
|
string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../" d_dir ${d})
|
||||||
|
include_directories("${d_dir}/include")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
file(GLOB test_srcs "test/*.cpp")
|
||||||
|
file(GLOB test_hdrs "test/*.h*")
|
||||||
|
|
||||||
|
set(the_target "opencv_gtest_${name}")
|
||||||
|
|
||||||
|
add_executable(${the_target} ${test_srcs} ${test_hdrs})
|
||||||
|
|
||||||
|
if(PCHSupport_FOUND)
|
||||||
|
set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/test/precomp.hpp)
|
||||||
|
if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")
|
||||||
|
if(${CMAKE_GENERATOR} MATCHES "Visual*")
|
||||||
|
set(${the_target}_pch "test/precomp.cpp")
|
||||||
|
endif()
|
||||||
|
add_native_precompiled_header(${the_target} ${pch_header})
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")
|
||||||
|
add_precompiled_header(${the_target} ${pch_header})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Additional target properties
|
||||||
|
set_target_properties(${the_target} PROPERTIES
|
||||||
|
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_dependencies(${the_target} ${ARGN} opencv_gtest)
|
||||||
|
|
||||||
|
# Add the required libraries for linking:
|
||||||
|
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${ARGN} opencv_gtest)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
get_target_property(LOC ${the_target} LOCATION)
|
||||||
|
add_test(${the_target} "${LOC}")
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endmacro()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ if(MSVC OR MINGW)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(gtest)
|
||||||
add_subdirectory(highgui)
|
add_subdirectory(highgui)
|
||||||
add_subdirectory(imgproc)
|
add_subdirectory(imgproc)
|
||||||
add_subdirectory(legacy)
|
add_subdirectory(legacy)
|
||||||
|
1
modules/core/test/precomp.cpp
Normal file
1
modules/core/test/precomp.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "precomp.hpp"
|
2
modules/core/test/precomp.hpp
Normal file
2
modules/core/test/precomp.hpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "opencv2/gtest/gtestcv.hpp"
|
||||||
|
#include "opencv2/core/core.hpp"
|
25
modules/core/test/test_arithm.cpp
Normal file
25
modules/core/test/test_arithm.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "precomp.hpp"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
TEST(ArithmTest, add)
|
||||||
|
{
|
||||||
|
typedef uchar _Tp;
|
||||||
|
|
||||||
|
Mat A(30,30,DataType<_Tp>::type), B(A.size(), A.type()), C0, C;
|
||||||
|
RNG rng(-1);
|
||||||
|
rng.fill(A, RNG::UNIFORM, Scalar::all(0), Scalar::all(256));
|
||||||
|
rng.fill(B, RNG::UNIFORM, Scalar::all(0), Scalar::all(256));
|
||||||
|
C0.create(A.size(), A.type());
|
||||||
|
int i, j, cols = A.cols*A.channels();
|
||||||
|
for(i = 0; i < A.rows; i++)
|
||||||
|
{
|
||||||
|
const _Tp* aptr = A.ptr<_Tp>(i);
|
||||||
|
const _Tp* bptr = B.ptr<_Tp>(i);
|
||||||
|
_Tp* cptr = C0.ptr<_Tp>(i);
|
||||||
|
for(j = 0; j < cols; j++)
|
||||||
|
cptr[j] = saturate_cast<_Tp>(aptr[j] + bptr[j]);
|
||||||
|
}
|
||||||
|
add(A, B, C);
|
||||||
|
EXPECT_EQ(norm(C, C0, NORM_INF), 0);
|
||||||
|
}
|
2
modules/core/test/test_main.cpp
Normal file
2
modules/core/test/test_main.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "precomp.hpp"
|
||||||
|
#include "opencv2/gtest/gtest_main.hpp"
|
4
modules/gtest/CMakeLists.txt
Normal file
4
modules/gtest/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
if(BUILD_SHARED_LIBS)
|
||||||
|
add_definitions(-DGTEST_CREATE_SHARED_LIBRARY=1)
|
||||||
|
endif()
|
||||||
|
define_opencv_module(gtest opencv_core)
|
@ -1,3 +1,8 @@
|
|||||||
|
The new OpenCV test engine is based
|
||||||
|
on the Google C++ Testing Framework (GTest).
|
||||||
|
Below is the original GTest README.
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
Google C++ Testing Framework
|
Google C++ Testing Framework
|
||||||
============================
|
============================
|
||||||
|
|
5
modules/gtest/include/opencv2/gtest/gtest_main.hpp
Normal file
5
modules/gtest/include/opencv2/gtest/gtest_main.hpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
60
modules/gtest/include/opencv2/gtest/gtestcv.hpp
Normal file
60
modules/gtest/include/opencv2/gtest/gtestcv.hpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#ifndef __OPENCV_GTESTCV_HPP__
|
||||||
|
#define __OPENCV_GTESTCV_HPP__
|
||||||
|
|
||||||
|
#include "opencv2/gtest/gtest.h"
|
||||||
|
#include "opencv2/core/core.hpp"
|
||||||
|
|
||||||
|
namespace cvtest
|
||||||
|
{
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
using cv::RNG;
|
||||||
|
using cv::Mat;
|
||||||
|
using cv::Scalar;
|
||||||
|
using cv::Size;
|
||||||
|
using cv::Point;
|
||||||
|
using cv::Rect;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
TYPE_MASK_8U = 1 << CV_8U,
|
||||||
|
TYPE_MASK_8S = 1 << CV_8S,
|
||||||
|
TYPE_MASK_16U = 1 << CV_16U,
|
||||||
|
TYPE_MASK_16S = 1 << CV_16S,
|
||||||
|
TYPE_MASK_32S = 1 << CV_32S,
|
||||||
|
TYPE_MASK_32F = 1 << CV_32F,
|
||||||
|
TYPE_MASK_64F = 1 << CV_64F,
|
||||||
|
TYPE_MASK_ALL = (TYPE_MASK_64F<<1)-1,
|
||||||
|
TYPE_MASK_ALL_BUT_8S = TYPE_MASK_ALL & ~TYPE_MASK_8S
|
||||||
|
};
|
||||||
|
|
||||||
|
CV_EXPORTS Size randomSize(RNG& rng, double maxSizeLog);
|
||||||
|
CV_EXPORTS void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector<int>& sz);
|
||||||
|
CV_EXPORTS int randomType(RNG& rng, int typeMask, int minChannels, int maxChannels);
|
||||||
|
CV_EXPORTS Mat randomMat(RNG& rng, Size size, int type, bool useRoi);
|
||||||
|
CV_EXPORTS Mat randomMat(RNG& rng, const vector<int>& size, int type, bool useRoi);
|
||||||
|
CV_EXPORTS Mat add(const Mat& a, double alpha, const Mat& b, double beta,
|
||||||
|
Scalar gamma, Mat& c, int ctype, bool calcAbs);
|
||||||
|
CV_EXPORTS void convert(const Mat& src, Mat& dst, int dtype, double alpha, double beta);
|
||||||
|
CV_EXPORTS void copy(const Mat& src, Mat& dst, const Mat& mask=Mat());
|
||||||
|
CV_EXPORTS void set(Mat& dst, const Scalar& gamma, const Mat& mask=Mat());
|
||||||
|
CV_EXPORTS void minMaxFilter(const Mat& a, Mat& maxresult, const Mat& minresult, const Mat& kernel, Point anchor);
|
||||||
|
CV_EXPORTS void filter2D(const Mat& src, Mat& dst, int ddepth, const Mat& kernel, Point anchor, double delta, int borderType);
|
||||||
|
CV_EXPORTS void copyMakeBorder(const Mat& src, Mat& dst, int top, int bottom, int left, int right, int borderType, Scalar borderValue);
|
||||||
|
CV_EXPORTS void minMaxLoc(const Mat& src, double* maxval, double* minval,
|
||||||
|
vector<int>* maxloc, vector<int>* minloc, const Mat& mask=Mat());
|
||||||
|
CV_EXPORTS double norm(const Mat& src, int normType, const Mat& mask=Mat());
|
||||||
|
CV_EXPORTS double norm(const Mat& src1, const Mat& src2, int normType, const Mat& mask=Mat());
|
||||||
|
CV_EXPORTS bool cmpEps(const Mat& src1, const Mat& src2, double maxDiff, vector<int>* loc);
|
||||||
|
CV_EXPORTS void logicOp(const Mat& src1, const Mat& src2, Mat& dst, char c);
|
||||||
|
CV_EXPORTS void logicOp(const Mat& src, const Scalar& s, Mat& dst, char c);
|
||||||
|
CV_EXPORTS void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop);
|
||||||
|
CV_EXPORTS void compare(const Mat& src, const Scalar& s, Mat& dst, int cmpop);
|
||||||
|
CV_EXPORTS void gemm(const Mat& src1, const Mat& src2, double alpha,
|
||||||
|
const Mat& src3, double beta, Mat& dst, int flags);
|
||||||
|
CV_EXPORTS void crosscorr(const Mat& src1, const Mat& src2, Mat& dst, int dtype);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
// This line ensures that gtest.h can be compiled on its own, even
|
// This line ensures that gtest.h can be compiled on its own, even
|
||||||
// when it's fused.
|
// when it's fused.
|
||||||
#include <gtest/gtest.h>
|
#include "precomp.hpp"
|
||||||
|
|
||||||
// The following lines pull in the real gtest *.cc files.
|
// The following lines pull in the real gtest *.cc files.
|
||||||
// Copyright 2005, Google Inc.
|
// Copyright 2005, Google Inc.
|
319
modules/gtest/src/gtestcv.cpp
Normal file
319
modules/gtest/src/gtestcv.cpp
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
#include "precomp.hpp"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
namespace cvtest
|
||||||
|
{
|
||||||
|
|
||||||
|
Size randomSize(RNG& rng, double maxSizeLog)
|
||||||
|
{
|
||||||
|
double width_log = rng.uniform(0., maxSizeLog);
|
||||||
|
double height_log = rng.uniform(0., maxSizeLog - width_log);
|
||||||
|
if( (unsigned)rng % 2 != 0 )
|
||||||
|
std::swap(width_log, height_log);
|
||||||
|
Size sz;
|
||||||
|
sz.width = cvRound(exp(width_log));
|
||||||
|
sz.height = cvRound(exp(height_log));
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
|
|
||||||
|
void randomSize(RNG& rng, int minDims, int maxDims, double maxSizeLog, vector<int>& sz)
|
||||||
|
{
|
||||||
|
int i, dims = rng.uniform(minDims, maxDims+1);
|
||||||
|
sz.resize(dims);
|
||||||
|
for( i = 0; i < dims; i++ )
|
||||||
|
{
|
||||||
|
double v = rng.uniform(0., maxSizeLog);
|
||||||
|
maxSizeLog -= v;
|
||||||
|
sz[i] = cvRound(exp(v));
|
||||||
|
}
|
||||||
|
for( i = 0; i < dims; i++ )
|
||||||
|
{
|
||||||
|
int j = rng.uniform(0, dims);
|
||||||
|
int k = rng.uniform(0, dims);
|
||||||
|
std::swap(sz[j], sz[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int randomType(RNG& rng, int typeMask, int minChannels, int maxChannels)
|
||||||
|
{
|
||||||
|
int channels = rng.uniform(minChannels, maxChannels+1);
|
||||||
|
int depth = 0;
|
||||||
|
CV_Assert((typeMask & TYPE_MASK_ALL) != 0);
|
||||||
|
for(;;)
|
||||||
|
{
|
||||||
|
depth = rng.uniform(CV_8U, CV_64F+1);
|
||||||
|
if( ((1 << depth) & typeMask) != 0 )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return CV_MAKETYPE(depth, channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat randomMat(RNG& rng, Size size, int type, bool useRoi)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat randomMat(RNG& rng, const vector<int>& size, int type, bool useRoi)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat add(const Mat& _a, double alpha, const Mat& _b, double beta,
|
||||||
|
Scalar gamma, Mat& c, int ctype, bool calcAbs)
|
||||||
|
{
|
||||||
|
Mat a = _a, b = _b;
|
||||||
|
if( a.empty() || alpha == 0 )
|
||||||
|
{
|
||||||
|
// both alpha and beta can be 0, but at least one of a and b must be non-empty array,
|
||||||
|
// otherwise we do not know the size of the output (and may be type of the output, when ctype<0)
|
||||||
|
CV_Assert( !a.empty() || !b.empty() );
|
||||||
|
if( !b.empty() )
|
||||||
|
{
|
||||||
|
a = b;
|
||||||
|
alpha = beta;
|
||||||
|
b = Mat();
|
||||||
|
beta = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( b.empty() || beta == 0 )
|
||||||
|
{
|
||||||
|
b = Mat();
|
||||||
|
beta = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CV_Assert(a.size == b.size);
|
||||||
|
|
||||||
|
if( ctype < 0 )
|
||||||
|
ctype = a.depth();
|
||||||
|
ctype = CV_MAKETYPE(CV_MAT_DEPTH(ctype), a.channels());
|
||||||
|
c.create(a.dims, &a.size[0], ctype);
|
||||||
|
const Mat *arrays[3];
|
||||||
|
Mat planes[3], buf[3];
|
||||||
|
arrays[0] = &a;
|
||||||
|
arrays[1] = b.empty() ? 0 : &b;
|
||||||
|
arrays[2] = &c;
|
||||||
|
|
||||||
|
NAryMatIterator it(arrays, planes, 3);
|
||||||
|
int i, nplanes = it.nplanes, cn=a.channels();
|
||||||
|
size_t total = planes[0].total(), maxsize = min(12*12*max(12/cn, 1), total);
|
||||||
|
|
||||||
|
CV_Assert(planes[0].rows == 1);
|
||||||
|
buf[0].create(1, (int)maxsize, CV_64FC(cn));
|
||||||
|
if(!b.empty())
|
||||||
|
buf[1].create(1, maxsize, CV_64FC(cn));
|
||||||
|
buf[2].create(1, maxsize, CV_64FC(cn));
|
||||||
|
scalarToRawData(gamma, buf[2].data, CV_64FC(cn), (int)(maxsize*cn));
|
||||||
|
|
||||||
|
for( i = 0; i < nplanes; i++, ++it)
|
||||||
|
{
|
||||||
|
for( size_t j = 0; j < total; j += maxsize )
|
||||||
|
{
|
||||||
|
size_t j2 = min(j + maxsize, total);
|
||||||
|
Mat apart0 = planes[0].colRange((int)j, (int)j2);
|
||||||
|
Mat cpart0 = planes[2].colRange((int)j, (int)j2);
|
||||||
|
Mat apart = buf[0].colRange(0, (int)(j2 - j));
|
||||||
|
|
||||||
|
apart0.convertTo(apart, apart.type(), alpha);
|
||||||
|
size_t k, n = (j2 - j)*cn;
|
||||||
|
double* aptr = (double*)apart.data;
|
||||||
|
const double* gptr = (const double*)buf[2].data;
|
||||||
|
|
||||||
|
if( b.empty() )
|
||||||
|
{
|
||||||
|
for( k = 0; k < n; k++ )
|
||||||
|
aptr[k] += gptr[k];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Mat bpart0 = planes[1].colRange((int)j, (int)j2);
|
||||||
|
Mat bpart = buf[1].colRange(0, (int)(j2 - j));
|
||||||
|
bpart0.convertTo(bpart, bpart.type(), beta);
|
||||||
|
const double* bptr = (const double*)bpart.data;
|
||||||
|
|
||||||
|
for( k = 0; k < n; k++ )
|
||||||
|
aptr[k] += bptr[k] + gptr[k];
|
||||||
|
}
|
||||||
|
if( calcAbs )
|
||||||
|
for( k = 0; k < n; k++ )
|
||||||
|
aptr[k] = fabs(aptr[k]);
|
||||||
|
apart.convertTo(cpart0, cpart0.type(), 1, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static template<typename _Tp1, typename _Tp2> inline void
|
||||||
|
convert(const _Tp1* src, _Tp2* dst, size_t total, double alpha, double beta)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
if( alpha == 1 && beta == 0 )
|
||||||
|
for( i = 0; i < total; i++ )
|
||||||
|
dst[i] = saturate_cast<_Tp2>(src[i]);
|
||||||
|
else if( beta == 0 )
|
||||||
|
for( i = 0; i < total; i++ )
|
||||||
|
dst[i] = saturate_cast<_Tp2>(src[i]*alpha);
|
||||||
|
else
|
||||||
|
for( i = 0; i < total; i++ )
|
||||||
|
dst[i] = saturate_cast<_Tp2>(src[i]*alpha + beta);
|
||||||
|
}
|
||||||
|
|
||||||
|
void convert(const Mat& src, Mat& dst, int dtype, double alpha, double beta)
|
||||||
|
{
|
||||||
|
dtype = CV_MAKETYPE(CV_MAT_DEPTH(dtype), src.channels());
|
||||||
|
dst.create(src.dims, &src.size[0], dtype);
|
||||||
|
if( alpha == 0 )
|
||||||
|
{
|
||||||
|
set( dst, Scalar::all(beta) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if( dtype == src.type() && alpha == 1 && beta == 0 )
|
||||||
|
{
|
||||||
|
copy( src, dst );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Mat *arrays[]={&src, &dst};
|
||||||
|
Mat planes[2];
|
||||||
|
|
||||||
|
NAryMatIterator it(arrays, planes, 2);
|
||||||
|
size_t j, total = total = planes[0].total()*planes[0].channels();
|
||||||
|
int i, nplanes = it.nplanes;
|
||||||
|
|
||||||
|
for( i = 0; i < nplanes; i++, ++it)
|
||||||
|
{
|
||||||
|
const uchar* sptr = planes[0].data;
|
||||||
|
uchar* dptr = planes[1].data;
|
||||||
|
|
||||||
|
switch( src.depth() )
|
||||||
|
{
|
||||||
|
case
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for( j = 0; j < total; j++, sptr += elemSize, dptr += elemSize )
|
||||||
|
{
|
||||||
|
if( mptr[j] )
|
||||||
|
for( k = 0; k < elemSize; k++ )
|
||||||
|
dptr[k] = sptr[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void copy(const Mat& src, Mat& dst, const Mat& mask)
|
||||||
|
{
|
||||||
|
dst.create(src.dims, &src.size[0], src.type());
|
||||||
|
|
||||||
|
if(mask.empty())
|
||||||
|
{
|
||||||
|
const Mat* arrays[] = {&src, &dst};
|
||||||
|
Mat planes[2];
|
||||||
|
NAryMatIterator it(arrays, planes, 2);
|
||||||
|
int i, nplanes = it.nplanes;
|
||||||
|
size_t planeSize = planes[0].total()*src.elemSize();
|
||||||
|
|
||||||
|
for( i = 0; i < nplanes; i++, ++it )
|
||||||
|
memcpy(planes[1].data, planes[0].data, planeSize);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_Assert( src.size == mask.size && mask.type() == CV_8U );
|
||||||
|
|
||||||
|
const Mat *arrays[3]={&src, &dst, &mask};
|
||||||
|
Mat planes[3];
|
||||||
|
|
||||||
|
NAryMatIterator it(arrays, planes, 3);
|
||||||
|
size_t j, k, elemSize = src.elemSize(), total = planes[0].total();
|
||||||
|
int i, nplanes = it.nplanes;
|
||||||
|
|
||||||
|
for( i = 0; i < nplanes; i++, ++it)
|
||||||
|
{
|
||||||
|
const uchar* sptr = planes[0].data;
|
||||||
|
uchar* dptr = planes[1].data;
|
||||||
|
const uchar* mptr = planes[2].data;
|
||||||
|
|
||||||
|
for( j = 0; j < total; j++, sptr += elemSize, dptr += elemSize )
|
||||||
|
{
|
||||||
|
if( mptr[j] )
|
||||||
|
for( k = 0; k < elemSize; k++ )
|
||||||
|
dptr[k] = sptr[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void set(Mat& dst, const Scalar& gamma, const Mat& mask)
|
||||||
|
{
|
||||||
|
double buf[12];
|
||||||
|
scalarToRawData(gama, &buf, dst.type(), dst.channels());
|
||||||
|
const uchar* gptr = (const uchar*)&buf[0];
|
||||||
|
|
||||||
|
if(mask.empty())
|
||||||
|
{
|
||||||
|
const Mat* arrays[] = {&dst};
|
||||||
|
Mat plane;
|
||||||
|
NAryMatIterator it(arrays, &plane, 1);
|
||||||
|
int i, nplanes = it.nplanes;
|
||||||
|
size_t j, k, elemSize = dst.elemSize(), planeSize = planes[0].total()*elemSize;
|
||||||
|
|
||||||
|
for( k = 1; k < elemSize; k++ )
|
||||||
|
if( gptr[k] != gptr[0] )
|
||||||
|
break;
|
||||||
|
bool uniform = k >= elemSize;
|
||||||
|
|
||||||
|
for( i = 0; i < nplanes; i++, ++it )
|
||||||
|
{
|
||||||
|
uchar* dptr = plane.data;
|
||||||
|
if( uniform )
|
||||||
|
memset( dptr, gptr[0], planeSize );
|
||||||
|
else if( i == 0 )
|
||||||
|
{
|
||||||
|
for( j = 0; j < planeSize; j += elemSize, dptr += elemSize )
|
||||||
|
for( k = 0; k < elemSize; k++ )
|
||||||
|
dptr[k] = gptr[k];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
memcpy(dtr, dst.data, planeSize);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_Assert( dst.size == mask.size && mask.type() == CV_8U );
|
||||||
|
|
||||||
|
const Mat *arrays[2]={&dst, &mask};
|
||||||
|
Mat planes[2];
|
||||||
|
|
||||||
|
NAryMatIterator it(arrays, planes, 2);
|
||||||
|
size_t j, k, elemSize = src.elemSize(), total = planes[0].total();
|
||||||
|
int i, nplanes = it.nplanes;
|
||||||
|
|
||||||
|
for( i = 0; i < nplanes; i++, ++it)
|
||||||
|
{
|
||||||
|
uchar* dptr = planes[0].data;
|
||||||
|
const uchar* mptr = planes[1].data;
|
||||||
|
|
||||||
|
for( j = 0; j < total; j++, dptr += elemSize )
|
||||||
|
{
|
||||||
|
if( mptr[j] )
|
||||||
|
for( k = 0; k < elemSize; k++ )
|
||||||
|
dptr[k] = gptr[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void minMaxFilter(const Mat& a, Mat& maxresult, const Mat& minresult, const Mat& kernel, Point anchor);
|
||||||
|
void filter2D(const Mat& src, Mat& dst, int ddepth, const Mat& kernel, Point anchor, double delta, int borderType);
|
||||||
|
void copyMakeBorder(const Mat& src, Mat& dst, int top, int bottom, int left, int right, int borderType, Scalar borderValue);
|
||||||
|
void minMaxLoc(const Mat& src, double* maxval, double* minval,
|
||||||
|
vector<int>* maxloc, vector<int>* minloc, const Mat& mask=Mat());
|
||||||
|
double norm(const Mat& src, int normType, const Mat& mask=Mat());
|
||||||
|
double norm(const Mat& src1, const Mat& src2, int normType, const Mat& mask=Mat());
|
||||||
|
bool cmpEps(const Mat& src1, const Mat& src2, int int_maxdiff, int flt_maxulp, vector<int>* loc);
|
||||||
|
void logicOp(const Mat& src1, const Mat& src2, Mat& dst, char c);
|
||||||
|
void logicOp(const Mat& src, const Scalar& s, Mat& dst, char c);
|
||||||
|
void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop);
|
||||||
|
void compare(const Mat& src, const Scalar& s, Mat& dst, int cmpop);
|
||||||
|
|
||||||
|
}
|
1
modules/gtest/src/precomp.cpp
Normal file
1
modules/gtest/src/precomp.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "precomp.hpp"
|
1
modules/gtest/src/precomp.hpp
Normal file
1
modules/gtest/src/precomp.hpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "opencv2/gtest/gtestcv.hpp"
|
Loading…
x
Reference in New Issue
Block a user