1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00

Compare commits

...

82 Commits

Author SHA1 Message Date
Alexander Alekhin fb4c2ba64d OpenCV version++
2.4.13.4
2017-10-12 14:32:33 +03:00
Alexander Alekhin e53f1b2532 Merge pull request #9808 from alalek:backport_fixes
(2.4) backport fixes
2017-10-10 13:13:23 +03:00
Yaron Inger 621a1d3b09 videoio: remove AssetsLibrary dependency.
The entire AssetsLibrary framework is deprecated since iOS 8.0. The code
used in the camera example code can use UIKit to save videos to the
camera instead, which allows to avoid linking with PhotoKit instead to
prevent increasing the iOS deployment target.
2017-10-09 15:14:25 +03:00
berak 14b686cdc7 imgcodecs: fix 4 reading channel bmp images 2017-10-09 15:11:28 +03:00
blendin 0202e52747 Fix out of bounds write 2017-10-09 15:10:03 +03:00
Benoit Blanchon 7997e7aee9 cmake: map RelWithDebInfo and MinSizeRel configuration to Release 2017-10-09 15:08:16 +03:00
Guillaume Jacob b43e5e2d21 CMakeLists.txt: fix a typo in a message 2017-10-09 15:04:40 +03:00
KUANG Fangjun c92ecc7f96 Improve the documentation. 2017-10-09 15:03:10 +03:00
Alexander Alekhin ae52d94ceb Merge pull request #9776 from IgWod:matrix-memory-leak-fix
Fix memory leak in the matrix copying constructor
2017-10-06 21:35:32 +03:00
Igor Wodiany 37d4e24806 Fix a memory leak in the Mat copying constructor
Exception may be rasied inside the body of a copying constructor after
refcount has been increased, and beacause in the case of the exception
destrcutor is never called what causes memory leak. This commit adds a
workaround that calls the release() function before the exception is
thrown outside the contructor.
2017-10-05 22:24:43 +01:00
Alexander Alekhin 7b861cac9f Merge pull request #9662 from alalek:backport_9448_9504
(2.4) imgcodecs: backport 9448 9504
2017-09-20 12:45:15 +00:00
Alexander Alekhin da9395b592 imgcodecs: fix regression 9376 2017-09-19 13:05:34 +03:00
Alexander Alekhin df1a026329 imgcodesc: fix code problems with integer overflow / address arithmetic / UB 2017-09-19 12:39:32 +03:00
Alexander Alekhin dd9bf1ba1d Merge pull request #9435 from alalek:fix_numpy_warning_2.4
(2.4) python: eliminate -Wundef warning about NPY_INTERNAL_BUILD
2017-09-15 18:26:26 +00:00
Alexander Alekhin 30f7576029 Merge pull request #9383 from alalek:imgcodecs_refactoring_2.4 2017-08-22 16:36:18 +00:00
Alexander Alekhin f548d660ba Merge pull request #9432 from alalek:cmake_deprecated_policies_2.4
(2.4) cmake deprecated policies (backport 9415)
2017-08-22 14:13:49 +00:00
Alexander Alekhin 8a2bbc57e4 python: eliminate -Wundef warning about NPY_INTERNAL_BUILD
numpy 1.13.0+
2017-08-22 11:59:54 +03:00
Alexander Alekhin e575b5ff9a cmake: remove INSTALL_NAME_DIR 2017-08-21 19:17:52 +03:00
Alexander Alekhin 355553b0a6 cmake: CMP0026 NEW 2017-08-21 18:48:17 +03:00
Alexander Alekhin d25b04149a cmake: CMP0022 NEW 2017-08-21 18:26:57 +03:00
Alexander Alekhin 268d17e086 cmake: drop CMP0017 2017-08-21 18:26:57 +03:00
Alexander Alekhin d567a79581 cmake: use CMAKE_CXX_COMPILER_VERSION (CMake 2.8.8+)
- PVAPI library detection was changed
2017-08-21 18:26:57 +03:00
Alexander Alekhin 3ba7c16670 cmake: bump minimal version 2017-08-21 16:33:05 +03:00
Alexander Alekhin f7d99f3f6a Merge pull request #9408 from alalek:backport_9228
(2.4) Update OpenCVCompilerOptions.cmake (backport 9228)
2017-08-18 16:04:16 +00:00
neok-m4700 126de0cd95 Update OpenCVCompilerOptions.cmake
misplaced else
2017-08-18 18:48:03 +03:00
Alexander Alekhin 72d29259ca imgcodecs: refactoring, improve code quality 2017-08-16 18:25:09 +00:00
Alexander Alekhin c9488c661f Merge pull request #9380 from StevenPuttemans:fix_doc_9359_2.4
backport of PR 9367
2017-08-16 10:58:14 +00:00
Steven Puttemans 4852f017fa backport of PR 9367 2017-08-16 10:57:20 +02:00
Alexander Alekhin b398b572cc OpenCV version++
2.4.13.3
2017-07-31 15:57:29 +03:00
Alexander Alekhin a0520bef42 Merge pull request #9266 from alalek:backport_9238
(2.4) backport #9238
2017-07-30 14:38:06 +00:00
Alexander Alekhin 7dceebbc4e flann: fix out of buffer access 2017-07-30 14:14:08 +03:00
Alexander Alekhin 0312df4812 cmake: fix compiler flags 2017-07-30 14:11:10 +03:00
Alexander Alekhin d19147bc78 Merge pull request #9218 from alalek:backport_2.4
(2.4) Backport changes from master
2017-07-24 11:40:51 +00:00
Alexander Alekhin fc2a71dbab build: enable __STDC_FORMAT_MACROS macro 2017-07-21 17:38:23 +03:00
kvaghel1 6bafc2c598 Fix frame timestamp in VideoCapture::get 2017-07-21 17:35:20 +03:00
Alexander Alekhin 777a0080cb cmake: disallow in-source builds 2017-07-21 17:33:01 +03:00
Christof Kaufmann 572c86176a cmake: Avoid adding default path as system directory for GCC 6.x
This is a completion for PR #7390 and fixes #6517 and #815.
2017-07-21 17:29:50 +03:00
Alexander Alekhin 8736ece97d Merge pull request #9116 from alalek:backport_9110_2.4
(2.4) Added detection of MSVC1911
2017-07-10 08:07:48 +00:00
Patrik Huber ebd961585e Added detection of MSVC1911
This is VS2017 Preview. It makes sure the version is detected properly and the INSTALL target then correctly installs to x64/vc15 (the same as MSVC1910).
2017-07-07 14:46:56 +03:00
Alexander Alekhin 2e343ef631 Merge pull request #9102 from varunagrawal:2.4-vector
gpu.hpp vector scope fix
2017-07-06 16:11:07 +00:00
Varun Agrawal af3c544483 All vector definitions have correct namespace scopes 2017-07-05 19:02:27 -04:00
Alexander Alekhin 3dedd62f54 Merge pull request #8970 from alalek:fix_libname_2.4
(2.4) cmake: fix libname for pkg-config configuration
2017-06-25 14:16:46 +03:00
Alexander Alekhin 07b7c03efc Merge pull request #8980 from alalek:fix_typo_8979_2.4
(2.4) highgui(macos): fix video file reading via AVFoundation
2017-06-24 11:38:32 +03:00
Alexander Alekhin aae7621243 highgui(macos): fix video file reading via AVFoundation 2017-06-24 11:01:33 +03:00
Alexander Alekhin fa36e769cf Merge pull request #8979 from sabzo:issue/8305_unhandled_objective_c_exception_video_avi_playback
Unhandled Objective-C exception when playing video
2017-06-24 10:56:25 +03:00
Sabelo f71bf21aaf Unhandled Objective-C exception when playing video 2017-06-23 19:54:56 -04:00
Alexander Alekhin 70489b1e22 cmake: fix libname for pkg-config configuration 2017-06-22 19:34:50 +03:00
Alexander Alekhin e397794ae2 Merge pull request #8959 from alalek:gitignore_cache_2.4 2017-06-22 12:29:23 +03:00
Alexander Alekhin 3d4e1bd641 .gitignore: add .cache directory (to be consistent with master branch) 2017-06-21 19:25:36 +03:00
Alexander Alekhin 3649ee3cd3 Merge pull request #8887 from krishraghuram:gpu_reduce_doc
Modified doc for gpu::reduce(fixes issue 8628)
2017-06-10 22:27:17 +02:00
Raghuram Krishnaswami d0f3a14456 Modified doc for gpu::reduce(fixes issue 8628) 2017-06-10 18:36:39 +05:30
krishraghuram 01e34b6a91 correct bug in fastmeans (ref #7899) (#8757) 2017-05-23 12:40:49 +03:00
Alexander Alekhin df5c090f2e Merge pull request #8761 from kvaghel1:Issue-8760
Correct findChessboardCorners flags naming in calib3d doc. (#8761)
2017-05-22 16:46:59 +03:00
kvaghel1 27213a845f Correct findChessboardCorners flags naming in calib3d doc. 2017-05-21 21:12:19 -04:00
Alexander Alekhin 91a6940930 Merge pull request #8574 from elmewo:fix-affine-constructor
fix creation homogeneous affine matrix when constructing from 4x3 cv::Mat
2017-04-25 19:04:51 +03:00
Alexander Alekhin 7577f1420d Merge pull request #8592 from tomoaki0705:fixTypoCalib3d24
calib3d: fix typo
2017-04-17 17:22:29 +03:00
Tomoaki Teshima c72a191145 fix typo 2017-04-17 22:13:10 +09:00
André Mewes 34d7b96bfc create homogeneous affine matrix when constructing from 4x3 cv::Mat 2017-04-13 14:39:10 +02:00
Alexander Alekhin 160f26192c Merge pull request #8562 from alalek:fix_ffmpeg_check_2.4
(2.4) ffmpeg: add __STDC_CONSTANT_MACROS to check code
2017-04-11 16:27:25 +03:00
Alexander Alekhin 9e76ba5ccd ffmpeg: add __STDC_CONSTANT_MACROS to check code 2017-04-11 12:45:10 +03:00
Alexander Alekhin ec784331fb Merge pull request #8353 from lpetre:backport_3593
backport of PR #3593
2017-03-13 10:01:07 +00:00
Adam Borowski 61936eb1a4 Get rid of sysctl includes on Linux.
The 'sysctl' syscall has been strongly deprecated on Linux for ages.
Currently, on old architectures it will spam syslog whenever used, and on
newer ones it's missing from the headers altogether.  Opencv has migrated
away on Linux already, but #includes were left lingering.  This commit
removes them on non-__APPLE__, unbreaking x32 (and probably others).
2017-03-10 16:40:29 +00:00
Alexander Alekhin d856604a4a Merge pull request #8322 from StevenPuttemans:backport_8207
backport of PR #8207
2017-03-06 16:07:27 +00:00
StevenPuttemans ab806b63a7 backport of PR #8207 2017-03-06 14:03:26 +01:00
Alexander Alekhin 0051744fa0 Merge pull request #8267 from umbraclet16:fixCalibSample
Solve issue #8264
2017-02-28 11:47:37 +00:00
umbraclet16 b8d99e1ffb Solve issue #8264
Fix bug in camera_calibration.cpp that the program tries to
parse input of type VIDEO_FILE as IMAGE_LIST which causes the
program to crash.
2017-02-25 16:16:23 +08:00
Alexander Alekhin 54f65a4672 Merge pull request #8002 from alalek:c_defines_2.4
(2.4) cmake: add defines to enable useful macroses
2017-02-14 19:09:17 +03:00
Alexander Alekhin d103c116db Merge pull request #8031 from terfendail:shortline_fix_2.4
Backport of PR #7161 fix for drawing beyond 32768 range
2017-02-14 19:08:09 +03:00
Alexander Alekhin e304795622 cmake: add defines to enable useful macroses 2017-02-13 15:01:23 +03:00
Alexander Alekhin ebae963884 drawing: workaround MSVC2010 32-bit compiler bug 2017-02-02 21:01:28 +03:00
Vadim Pisarevsky 19e4c7727b Merge pull request #7546 from savuor:fix2.4/yuv_channel_order 2017-01-31 16:12:12 +00:00
Alexander Alekhin f2a59b3d94 Merge pull request #7913 from DabeDotCom:CoreImage-pre_Xcode_7 2017-01-19 16:18:40 +00:00
Dabrien 'Dabe' Murphy 88bc0f7838 Fix 7606 "ld: framework not found CoreImage" Bug
This affects OpenCV 2.4 on older Macs with Xcode versions
before 7.0 (i.e., Mac OS X versions older than 10.11 El Capitan)
2017-01-19 17:07:01 +03:00
Vitaly Tuzov 2346ba7ea2 Backport of PR #7161 fix for drawing beyond 32768 range 2017-01-18 17:02:52 +03:00
parismita f5db748312 Update linux_install.rst (#7776)
* Update linux_install.rst

whitespace between -D and \<option\> removed

* Update linux_install.rst

* Update linux_install.rst

* Update linux_install.rst

* Update linux_install.rst

* Update linux_install.rst

* Update linux_install.rst

* Update linux_install.rst

* Update linux_install.rst

* Update linux_install.rst
2017-01-10 15:13:41 +03:00
Alexander Alekhin 3e66654963 Merge pull request #7973 from sturkmen72:patch-2 2017-01-06 11:07:23 +00:00
Suleyman TURKMEN f108795e2c Update sift.cpp 2017-01-05 19:47:34 +02:00
Alexander Alekhin 6ed571b3c6 Merge pull request #7893 from alalek:fix_ffmpeg_check_2.4 2016-12-19 14:32:42 +00:00
Alexander Alekhin 9d45f15627 cmake: fix ffmpeg check code 2016-12-19 00:22:16 +03:00
Alexander Alekhin d7504ecaed OpenCV version++ 2016-12-16 16:19:56 +03:00
Rostislav Vasilikhin d23190dc3e fixed channel order from YVU to YUV 2016-11-03 17:37:22 +03:00
Rostislav Vasilikhin e3070ed553 fixed YUV channel equivalence 2016-10-25 16:32:04 +03:00
60 changed files with 1011 additions and 568 deletions
+1
View File
@@ -7,3 +7,4 @@
.sw[a-z] .sw[a-z]
tags tags
tegra/ tegra/
.cache
+1 -1
View File
@@ -187,7 +187,7 @@ if (HAVE_LIBPTHREAD)
add_definitions(-DUSE_PTHREAD) #required for Unix add_definitions(-DUSE_PTHREAD) #required for Unix
endif() endif()
if (CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_COMPILER_IS_CLANGCXX)
add_definitions(-DTBB_USE_GCC_BUILTINS=1) #required for ARM GCC add_definitions(-DTBB_USE_GCC_BUILTINS=1) #required for ARM GCC
endif() endif()
+16 -31
View File
@@ -4,11 +4,16 @@
# From the off-tree build directory, invoke: # From the off-tree build directory, invoke:
# $ cmake <PATH_TO_OPENCV_ROOT> # $ cmake <PATH_TO_OPENCV_ROOT>
# #
#
# - OCT-2008: Initial version <joseluisblancoc@gmail.com>
#
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Disable in-source builds to prevent source tree corruption.
if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
message(FATAL_ERROR "
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
")
endif()
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
# Following block can broke build in case of cross-compilng # Following block can broke build in case of cross-compilng
@@ -32,24 +37,15 @@ endif(NOT CMAKE_TOOLCHAIN_FILE)
# Top level OpenCV project # Top level OpenCV project
# -------------------------------------------------------------- # --------------------------------------------------------------
if(CMAKE_GENERATOR MATCHES Xcode AND XCODE_VERSION VERSION_GREATER 4.3) if(CMAKE_GENERATOR MATCHES Xcode AND XCODE_VERSION VERSION_GREATER 4.3)
cmake_minimum_required(VERSION 2.8.8) cmake_minimum_required(VERSION 3.0)
elseif(IOS) elseif(IOS)
cmake_minimum_required(VERSION 2.8.0) cmake_minimum_required(VERSION 3.0)
else() else()
cmake_minimum_required(VERSION 2.6.3) cmake_minimum_required(VERSION 2.8.12.2)
endif()
if(POLICY CMP0017)
cmake_policy(SET CMP0017 NEW)
endif()
if(POLICY CMP0022)
cmake_policy(SET CMP0022 OLD)
endif() endif()
if(POLICY CMP0026) if(POLICY CMP0026)
# silence cmake 3.0+ warnings about reading LOCATION attribute cmake_policy(SET CMP0026 NEW)
cmake_policy(SET CMP0026 OLD)
endif() endif()
if (POLICY CMP0042) if (POLICY CMP0042)
@@ -81,8 +77,8 @@ ocv_clear_vars(OpenCVModules_TARGETS)
# Break in case of popular CMake configuration mistakes # Break in case of popular CMake configuration mistakes
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
if(NOT CMAKE_SIZEOF_VOID_P GREATER 0) if(NOT CMAKE_SIZEOF_VOID_P GREATER 0)
message(FATAL_ERROR "CMake fails to deterimine the bitness of target platform. message(FATAL_ERROR "CMake fails to determine the bitness of the target platform.
Please check your CMake and compiler installation. If you are crosscompiling then ensure that your CMake toolchain file correctly sets the compiler details.") Please check your CMake and compiler installation. If you are cross-compiling then ensure that your CMake toolchain file correctly sets the compiler details.")
endif() endif()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
@@ -193,7 +189,7 @@ OCV_OPTION(BUILD_PACKAGE "Enables 'make package_source' command"
OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" ON IF (NOT IOS) ) OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" ON IF (NOT IOS) )
OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS) ) OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS) )
OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON ) OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON )
OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT for staticaly linked OpenCV" ON IF MSVC ) OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of statically linked CRT for staticaly linked OpenCV" ON IF MSVC )
OCV_OPTION(BUILD_FAT_JAVA_LIB "Create fat java wrapper containing the whole OpenCV library" ON IF NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX ) OCV_OPTION(BUILD_FAT_JAVA_LIB "Create fat java wrapper containing the whole OpenCV library" ON IF NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX )
OCV_OPTION(BUILD_ANDROID_SERVICE "Build OpenCV Manager for Google Play" OFF IF ANDROID AND ANDROID_SOURCE_TREE ) OCV_OPTION(BUILD_ANDROID_SERVICE "Build OpenCV Manager for Google Play" OFF IF ANDROID AND ANDROID_SOURCE_TREE )
OCV_OPTION(BUILD_ANDROID_PACKAGE "Build platform-specific package for Google Play" OFF IF ANDROID ) OCV_OPTION(BUILD_ANDROID_PACKAGE "Build platform-specific package for Google Play" OFF IF ANDROID )
@@ -707,10 +703,6 @@ endif()
# ========================== C/C++ options ========================== # ========================== C/C++ options ==========================
if(CMAKE_CXX_COMPILER_VERSION) if(CMAKE_CXX_COMPILER_VERSION)
set(OPENCV_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} (ver ${CMAKE_CXX_COMPILER_VERSION})") set(OPENCV_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} (ver ${CMAKE_CXX_COMPILER_VERSION})")
elseif(CMAKE_COMPILER_IS_CLANGCXX)
set(OPENCV_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} (ver ${CMAKE_CLANG_REGEX_VERSION})")
elseif(CMAKE_COMPILER_IS_GNUCXX)
set(OPENCV_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} (ver ${CMAKE_GCC_REGEX_VERSION})")
else() else()
set(OPENCV_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}") set(OPENCV_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
endif() endif()
@@ -1024,7 +1016,7 @@ if(HAVE_OPENCL)
set(__libs "") set(__libs "")
foreach(l ${OPENCL_LIBRARIES}) foreach(l ${OPENCL_LIBRARIES})
if(TARGET ${l}) if(TARGET ${l})
get_target_property(p ${l} LOCATION) get_target_property(p ${l} IMPORTED_LOCATION)
if(p MATCHES NOTFOUND) if(p MATCHES NOTFOUND)
list(APPEND __libs "${l}") list(APPEND __libs "${l}")
else() else()
@@ -1094,13 +1086,6 @@ status("")
ocv_finalize_status() ocv_finalize_status()
# ----------------------------------------------------------------------------
# Warn in the case of in-source build
# ----------------------------------------------------------------------------
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree")
endif()
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# CPack stuff # CPack stuff
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
+2 -2
View File
@@ -140,7 +140,7 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
double acceptanceRatioBreakValue) double acceptanceRatioBreakValue)
{ {
// Start recording clock ticks for training time output // Start recording clock ticks for training time output
const clock_t begin_time = clock(); double time = (double)getTickCount();
if( _cascadeDirName.empty() || _posFilename.empty() || _negFilename.empty() ) if( _cascadeDirName.empty() || _posFilename.empty() || _negFilename.empty() )
CV_Error( CV_StsBadArg, "_cascadeDirName or _bgfileName or _vecFileName is NULL" ); CV_Error( CV_StsBadArg, "_cascadeDirName or _bgfileName or _vecFileName is NULL" );
@@ -268,7 +268,7 @@ bool CvCascadeClassifier::train( const string _cascadeDirName,
fs << "}"; fs << "}";
// Output training time up till now // Output training time up till now
float seconds = float( clock () - begin_time ) / CLOCKS_PER_SEC; double seconds = ( (double)getTickCount() - time)/ getTickFrequency();
int days = int(seconds) / 60 / 60 / 24; int days = int(seconds) / 60 / 60 / 24;
int hours = (int(seconds) / 60 / 60) % 24; int hours = (int(seconds) / 60 / 60) % 24;
int minutes = (int(seconds) / 60) % 60; int minutes = (int(seconds) / 60) % 60;
+6 -6
View File
@@ -1553,7 +1553,7 @@ macro(CUDA_ADD_LIBRARY cuda_target)
# variable will have been defined. # variable will have been defined.
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
target_link_libraries(${cuda_target} target_link_libraries(${cuda_target} LINK_PRIVATE
${CUDA_LIBRARIES} ${CUDA_LIBRARIES}
) )
@@ -1597,7 +1597,7 @@ macro(CUDA_ADD_EXECUTABLE cuda_target)
# variable will have been defined. # variable will have been defined.
CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}")
target_link_libraries(${cuda_target} target_link_libraries(${cuda_target} LINK_PRIVATE
${CUDA_LIBRARIES} ${CUDA_LIBRARIES}
) )
@@ -1672,9 +1672,9 @@ endmacro()
############################################################################### ###############################################################################
macro(CUDA_ADD_CUFFT_TO_TARGET target) macro(CUDA_ADD_CUFFT_TO_TARGET target)
if (CUDA_BUILD_EMULATION) if (CUDA_BUILD_EMULATION)
target_link_libraries(${target} ${CUDA_cufftemu_LIBRARY}) target_link_libraries(${target} LINK_PRIVATE ${CUDA_cufftemu_LIBRARY})
else() else()
target_link_libraries(${target} ${CUDA_cufft_LIBRARY}) target_link_libraries(${target} LINK_PRIVATE ${CUDA_cufft_LIBRARY})
endif() endif()
endmacro() endmacro()
@@ -1685,9 +1685,9 @@ endmacro()
############################################################################### ###############################################################################
macro(CUDA_ADD_CUBLAS_TO_TARGET target) macro(CUDA_ADD_CUBLAS_TO_TARGET target)
if (CUDA_BUILD_EMULATION) if (CUDA_BUILD_EMULATION)
target_link_libraries(${target} ${CUDA_cublasemu_LIBRARY}) target_link_libraries(${target} LINK_PRIVATE ${CUDA_cublasemu_LIBRARY})
else() else()
target_link_libraries(${target} ${CUDA_cublas_LIBRARY}) target_link_libraries(${target} LINK_PRIVATE ${CUDA_cublas_LIBRARY})
endif() endif()
endmacro() endmacro()
+6 -3
View File
@@ -18,9 +18,9 @@ if(ENABLE_CCACHE AND NOT CMAKE_COMPILER_IS_CCACHE)
message(STATUS "Unable to compile program with enabled ccache, reverting...") message(STATUS "Unable to compile program with enabled ccache, reverting...")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${__OLD_RULE_LAUNCH_COMPILE}") set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${__OLD_RULE_LAUNCH_COMPILE}")
endif() endif()
else()
message(STATUS "Looking for ccache - not found")
endif() endif()
else()
message(STATUS "Looking for ccache - not found")
endif() endif()
endif() endif()
@@ -246,7 +246,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif() endif()
set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} -DNDEBUG") set(OPENCV_EXTRA_FLAGS_RELEASE "${OPENCV_EXTRA_FLAGS_RELEASE} -DNDEBUG")
set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -O0 -DDEBUG -D_DEBUG") if(NOT " ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG} " MATCHES "-O")
set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -O0")
endif()
set(OPENCV_EXTRA_FLAGS_DEBUG "${OPENCV_EXTRA_FLAGS_DEBUG} -DDEBUG -D_DEBUG")
endif() endif()
if(MSVC) if(MSVC)
+1 -1
View File
@@ -81,7 +81,7 @@ if(MSVC)
set(OpenCV_RUNTIME vc12) set(OpenCV_RUNTIME vc12)
elseif(MSVC_VERSION EQUAL 1900) elseif(MSVC_VERSION EQUAL 1900)
set(OpenCV_RUNTIME vc14) set(OpenCV_RUNTIME vc14)
elseif(MSVC_VERSION EQUAL 1910) elseif(MSVC_VERSION EQUAL 1910 OR MSVC_VERSION EQUAL 1911)
set(OpenCV_RUNTIME vc15) set(OpenCV_RUNTIME vc15)
endif() endif()
elseif(MINGW) elseif(MINGW)
+2 -3
View File
@@ -302,16 +302,15 @@ macro(add_android_project target path)
endif() endif()
add_library(${JNI_LIB_NAME} SHARED ${android_proj_jni_files}) add_library(${JNI_LIB_NAME} SHARED ${android_proj_jni_files})
target_link_libraries(${JNI_LIB_NAME} ${OPENCV_LINKER_LIBS} ${android_proj_NATIVE_DEPS}) target_link_libraries(${JNI_LIB_NAME} LINK_PRIVATE ${OPENCV_LINKER_LIBS} ${android_proj_NATIVE_DEPS})
set_target_properties(${JNI_LIB_NAME} PROPERTIES set_target_properties(${JNI_LIB_NAME} PROPERTIES
OUTPUT_NAME "${JNI_LIB_NAME}" OUTPUT_NAME "${JNI_LIB_NAME}"
LIBRARY_OUTPUT_DIRECTORY "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}" LIBRARY_OUTPUT_DIRECTORY "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}"
) )
get_target_property(android_proj_jni_location "${JNI_LIB_NAME}" LOCATION)
if (NOT (CMAKE_BUILD_TYPE MATCHES "debug")) if (NOT (CMAKE_BUILD_TYPE MATCHES "debug"))
add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${android_proj_jni_location}") add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$<TARGET_FILE:${JNI_LIB_NAME}>")
endif() endif()
endif() endif()
+1 -1
View File
@@ -212,7 +212,7 @@ if(CUDA_FOUND)
endif() endif()
# disabled because of multiple warnings during building nvcc auto generated files # disabled because of multiple warnings during building nvcc auto generated files
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_GCC_REGEX_VERSION VERSION_GREATER "4.6.0") if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.6.0")
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-but-set-variable) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-but-set-variable)
endif() endif()
+5 -43
View File
@@ -42,49 +42,11 @@ if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS) set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
endif() endif()
# ---------------------------------------------------------------------------- if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION)
# Detect GNU version: message(WARNING "Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set")
# ---------------------------------------------------------------------------- endif()
if(CMAKE_COMPILER_IS_CLANGCXX)
set(CMAKE_GCC_REGEX_VERSION "4.2.1")
set(CMAKE_OPENCV_GCC_VERSION_MAJOR 4)
set(CMAKE_OPENCV_GCC_VERSION_MINOR 2)
set(CMAKE_OPENCV_GCC_VERSION 42)
set(CMAKE_OPENCV_GCC_VERSION_NUM 402)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
ERROR_VARIABLE CMAKE_OPENCV_CLANG_VERSION_FULL
ERROR_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "version.*$" CMAKE_OPENCV_CLANG_VERSION_FULL "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_CLANG_REGEX_VERSION "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
elseif(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
# Look for the version number
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
if(NOT CMAKE_GCC_REGEX_VERSION)
string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
endif()
# Split the three parts:
string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")
list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")
if(CMAKE_COMPILER_IS_GNUCXX)
if(WIN32) if(WIN32)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
@@ -138,7 +100,7 @@ if(MSVC)
set(OpenCV_RUNTIME vc12) set(OpenCV_RUNTIME vc12)
elseif(MSVC_VERSION EQUAL 1900) elseif(MSVC_VERSION EQUAL 1900)
set(OpenCV_RUNTIME vc14) set(OpenCV_RUNTIME vc14)
elseif(MSVC_VERSION EQUAL 1910) elseif(MSVC_VERSION EQUAL 1910 OR MSVC_VERSION EQUAL 1911)
set(OpenCV_RUNTIME vc15) set(OpenCV_RUNTIME vc15)
endif() endif()
elseif(MINGW) elseif(MINGW)
+10 -16
View File
@@ -84,23 +84,16 @@ if(WITH_PVAPI)
set(PVAPI_SDK_SUBDIR arm) set(PVAPI_SDK_SUBDIR arm)
endif() endif()
get_filename_component(_PVAPI_LIBRARY "${PVAPI_INCLUDE_PATH}/../lib-pc" ABSOLUTE) get_filename_component(_PVAPI_LIBRARY_HINT "${PVAPI_INCLUDE_PATH}/../lib-pc" ABSOLUTE)
if(PVAPI_SDK_SUBDIR)
set(_PVAPI_LIBRARY "${_PVAPI_LIBRARY}/${PVAPI_SDK_SUBDIR}")
endif()
if(NOT WIN32 AND CMAKE_COMPILER_IS_GNUCXX)
set(_PVAPI_LIBRARY "${_PVAPI_LIBRARY}/${CMAKE_OPENCV_GCC_VERSION_MAJOR}.${CMAKE_OPENCV_GCC_VERSION_MINOR}")
endif()
if(WIN32) find_library(PVAPI_LIBRARY NAMES "PvAPI" PATHS "${_PVAPI_LIBRARY_HINT}")
if(MINGW)
set(PVAPI_DEFINITIONS "-DPVDECL=__stdcall") if(PVAPI_LIBRARY)
endif(MINGW) if(WIN32)
set(PVAPI_LIBRARY "${_PVAPI_LIBRARY}/PvAPI.lib" CACHE PATH "The PvAPI library") if(MINGW)
else(WIN32) set(PVAPI_DEFINITIONS "-DPVDECL=__stdcall")
set(PVAPI_LIBRARY "${_PVAPI_LIBRARY}/${CMAKE_STATIC_LIBRARY_PREFIX}PvAPI${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE PATH "The PvAPI library") endif(MINGW)
endif(WIN32) endif()
if(EXISTS "${PVAPI_LIBRARY}")
set(HAVE_PVAPI TRUE) set(HAVE_PVAPI TRUE)
endif() endif()
endif(PVAPI_INCLUDE_PATH) endif(PVAPI_INCLUDE_PATH)
@@ -213,6 +206,7 @@ if(WITH_FFMPEG)
if(NOT __VALID_FFMPEG) if(NOT __VALID_FFMPEG)
#message(FATAL_ERROR "FFMPEG: test check build log:\n${TRY_OUT}") #message(FATAL_ERROR "FFMPEG: test check build log:\n${TRY_OUT}")
message(STATUS "WARNING: Can't build ffmpeg test code") message(STATUS "WARNING: Can't build ffmpeg test code")
set(HAVE_FFMPEG FALSE)
else() else()
ocv_append_build_options(HIGHGUI FFMPEG) ocv_append_build_options(HIGHGUI FFMPEG)
endif() endif()
+11 -11
View File
@@ -46,16 +46,16 @@ endif()
set(OpenCV_LIB_COMPONENTS_) set(OpenCV_LIB_COMPONENTS_)
foreach(CVLib ${OpenCV_LIB_COMPONENTS}) foreach(CVLib ${OpenCV_LIB_COMPONENTS})
get_target_property(libloc ${CVLib} LOCATION_${CMAKE_BUILD_TYPE}) get_target_property(libname ${CVLib} OUTPUT_NAME_${CMAKE_BUILD_TYPE})
if(libloc MATCHES "3rdparty") if(NOT libname)
set(libpath "\${exec_prefix}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}") get_target_property(libname ${CVLib} OUTPUT_NAME)
else() endif()
set(libpath "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}") if(NOT libname)
set(libname "${CVLib}")
endif() endif()
list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libpath}")
get_filename_component(libname ${CVLib} NAME_WE) set(libpath "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}")
string(REGEX REPLACE "^lib" "" libname "${libname}") list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libpath}")
list(APPEND OpenCV_LIB_COMPONENTS_ "-l${libname}") list(APPEND OpenCV_LIB_COMPONENTS_ "-l${libname}")
endforeach() endforeach()
@@ -66,7 +66,7 @@ if(OpenCV_EXTRA_COMPONENTS)
if(TARGET "${extra_component}") if(TARGET "${extra_component}")
get_target_property(extra_component_is_imported "${extra_component}" IMPORTED) get_target_property(extra_component_is_imported "${extra_component}" IMPORTED)
if(extra_component_is_imported) if(extra_component_is_imported)
get_target_property(extra_component "${extra_component}" LOCATION) get_target_property(extra_component "${extra_component}" IMPORTED_LOCATION)
endif() endif()
endif() endif()
@@ -74,8 +74,8 @@ if(OpenCV_EXTRA_COMPONENTS)
list(APPEND OpenCV_LIB_COMPONENTS_ "${extra_component}") list(APPEND OpenCV_LIB_COMPONENTS_ "${extra_component}")
elseif(extra_component MATCHES "[\\/]") elseif(extra_component MATCHES "[\\/]")
get_filename_component(libdir "${extra_component}" PATH) get_filename_component(libdir "${extra_component}" PATH)
get_filename_component(libname "${extra_component}" NAME_WE) get_filename_component(libname "${extra_component}" NAME)
string(REGEX REPLACE "^lib" "" libname "${libname}") ocv_get_libname(libname "${libname}")
list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libdir}" "-l${libname}") list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libdir}" "-l${libname}")
else() else()
list(APPEND OpenCV_LIB_COMPONENTS_ "-l${extra_component}") list(APPEND OpenCV_LIB_COMPONENTS_ "-l${extra_component}")
+8 -4
View File
@@ -170,6 +170,10 @@ macro(ocv_add_module _name)
return() # extra protection from redefinition return() # extra protection from redefinition
endif() endif()
project(${the_module}) project(${the_module})
add_definitions(
-D_USE_MATH_DEFINES # M_PI constant in MSVS
-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS # to use C libraries from C++ code (ffmpeg)
)
endif(OPENCV_INITIAL_PASS) endif(OPENCV_INITIAL_PASS)
endmacro() endmacro()
@@ -574,12 +578,12 @@ macro(ocv_create_module)
${${the_module}_pch}) ${${the_module}_pch})
if(NOT "${ARGN}" STREQUAL "SKIP_LINK") if(NOT "${ARGN}" STREQUAL "SKIP_LINK")
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS}) target_link_libraries(${the_module} LINK_PUBLIC ${OPENCV_MODULE_${the_module}_DEPS})
target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${OPENCV_MODULE_${the_module}_DEPS}) target_link_libraries(${the_module} LINK_PUBLIC ${OPENCV_MODULE_${the_module}_DEPS})
set(extra_deps ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN}) set(extra_deps ${OPENCV_MODULE_${the_module}_DEPS_EXT} ${OPENCV_LINKER_LIBS} ${IPP_LIBS} ${ARGN})
ocv_extract_simple_libs(extra_deps _simple_deps _other_deps) ocv_extract_simple_libs(extra_deps _simple_deps _other_deps)
target_link_libraries(${the_module} LINK_INTERFACE_LIBRARIES ${_simple_deps}) # this list goes to "export" target_link_libraries(${the_module} LINK_PRIVATE ${_simple_deps}) # this list goes to "export"
target_link_libraries(${the_module} ${extra_deps}) target_link_libraries(${the_module} LINK_PRIVATE ${extra_deps})
endif() endif()
add_dependencies(opencv_modules ${the_module}) add_dependencies(opencv_modules ${the_module})
+6
View File
@@ -69,6 +69,9 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
FOREACH(item ${DIRINC}) FOREACH(item ${DIRINC})
if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/") if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/")
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"") LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
elseif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND
item MATCHES "/usr/include$")
# workaround for GCC 6.x bug
else() else()
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"") LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
endif() endif()
@@ -78,6 +81,9 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
FOREACH(item ${DIRINC}) FOREACH(item ${DIRINC})
if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/") if(item MATCHES "^${OpenCV_SOURCE_DIR}/modules/")
LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"") LIST(APPEND ${_out_compile_flags} "${_PCH_include_prefix}\"${item}\"")
elseif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0" AND
item MATCHES "/usr/include$")
# workaround for GCC 6.x bug
else() else()
LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"") LIST(APPEND ${_out_compile_flags} "${_PCH_isystem_prefix}\"${item}\"")
endif() endif()
+1 -1
View File
@@ -124,7 +124,7 @@ set(STD_OPENCV_DEV libopencv-dev)
set(ABI_VERSION_SUFFIX "") set(ABI_VERSION_SUFFIX "")
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
if(${CMAKE_OPENCV_GCC_VERSION_MAJOR} EQUAL 5) if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6)
set(ABI_VERSION_SUFFIX "v5") set(ABI_VERSION_SUFFIX "v5")
endif() endif()
endif() endif()
+11 -5
View File
@@ -5,8 +5,8 @@ if(UNIX)
find_package(PkgConfig) find_package(PkgConfig)
endif() endif()
# Search packages for host system instead of packages for target system # Search packages for the host system instead of packages for target system
# in case of cross compilation thess macro should be defined by toolchain file # in case of cross compilation these macros should be defined by the toolchain file
if(NOT COMMAND find_host_package) if(NOT COMMAND find_host_package)
macro(find_host_package) macro(find_host_package)
find_package(${ARGN}) find_package(${ARGN})
@@ -82,7 +82,7 @@ macro(ocv_check_environment_variables)
endforeach() endforeach()
endmacro() endmacro()
# adds include directories in such way that directories from the OpenCV source tree go first # adds include directories in such a way that directories from the OpenCV source tree go first
function(ocv_include_directories) function(ocv_include_directories)
set(__add_before "") set(__add_before "")
foreach(dir ${ARGN}) foreach(dir ${ARGN})
@@ -337,7 +337,7 @@ macro(ocv_check_modules define)
endmacro() endmacro()
# Macros that checks if module have been installed. # Macro that checks if module has been installed.
# After it adds module to build and define # After it adds module to build and define
# constants passed as second arg # constants passed as second arg
macro(CHECK_MODULE module_name define) macro(CHECK_MODULE module_name define)
@@ -526,7 +526,7 @@ macro(ocv_list_add_suffix LST SUFFIX)
endmacro() endmacro()
# gets and removes the first element from list # gets and removes the first element from the list
macro(ocv_list_pop_front LST VAR) macro(ocv_list_pop_front LST VAR)
if(${LST}) if(${LST})
list(GET ${LST} 0 ${VAR}) list(GET ${LST} 0 ${VAR})
@@ -749,6 +749,12 @@ function(ocv_source_group group)
source_group(${group} FILES ${srcs}) source_group(${group} FILES ${srcs})
endfunction() endfunction()
macro(ocv_get_libname var_name)
get_filename_component(__libname "${ARGN}" NAME)
string(REGEX REPLACE "^lib(.+).(a|so)(.[.0-9]+)?$" "\\1" __libname "${__libname}")
set(${var_name} "${__libname}")
endmacro()
# build the list of simple dependencies, that links via "-l" # build the list of simple dependencies, that links via "-l"
# _all_libs - name of variable with input list # _all_libs - name of variable with input list
# _simple - name of variable with output list of simple libs # _simple - name of variable with output list of simple libs
+2 -2
View File
@@ -14,6 +14,6 @@ endif()
set(OPENCV_SOVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}") set(OPENCV_SOVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}")
set(OPENCV_LIBVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}") set(OPENCV_LIBVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}")
# create a dependency on version file # create a dependency on the version file
# we never use output of the following command but cmake will rerun automatically if the version file changes # we never use the output of the following command but cmake will rerun automatically if the version file changes
configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY) configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY)
+2
View File
@@ -1,3 +1,5 @@
#define __STDC_CONSTANT_MACROS
#include <stdlib.h> #include <stdlib.h>
extern "C" { extern "C" {
+8
View File
@@ -219,6 +219,14 @@ foreach(__cvcomponent ${OpenCV_FIND_COMPONENTS})
string(TOUPPER "${__cvcomponent}" __cvcomponent) string(TOUPPER "${__cvcomponent}" __cvcomponent)
set(${__cvcomponent}_FOUND 1) set(${__cvcomponent}_FOUND 1)
endif() endif()
# OpenCV supports Debug and Release only.
# RelWithDebInfo and MinSizeRel are mapped to Release
if(TARGET ${__cvcomponent})
set_target_properties(${__cvcomponent} PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL "Release"
MAP_IMPORTED_CONFIG_RELWITHDEBINFO "Release"
)
endif()
endforeach() endforeach()
set(OpenCV_FIND_COMPONENTS ${OpenCV_FIND_COMPONENTS_}) set(OpenCV_FIND_COMPONENTS ${OpenCV_FIND_COMPONENTS_})
@@ -111,7 +111,7 @@ Then the PSNR is expressed as:
PSNR = 10 \cdot \log_{10} \left( \frac{MAX_I^2}{MSE} \right) PSNR = 10 \cdot \log_{10} \left( \frac{MAX_I^2}{MSE} \right)
Here the :math:`MAX_I^2` is the maximum valid value for a pixel. In case of the simple single byte image per pixel per channel this is 255. When two images are the same the MSE will give zero, resulting in an invalid divide by zero operation in the PSNR formula. In this case the PSNR is undefined and as we'll need to handle this case separately. The transition to a logarithmic scale is made because the pixel values have a very wide dynamic range. All this translated to OpenCV and a C++ function looks like: Here the :math:`MAX_I` is the maximum valid value for a pixel. In case of the simple single byte image per pixel per channel this is 255. When two images are the same the MSE will give zero, resulting in an invalid divide by zero operation in the PSNR formula. In this case the PSNR is undefined and as we'll need to handle this case separately. The transition to a logarithmic scale is made because the pixel values have a very wide dynamic range. All this translated to OpenCV and a C++ function looks like:
.. code-block:: cpp .. code-block:: cpp
@@ -81,4 +81,6 @@ Building OpenCV from Source Using CMake, Using the Command Line
.. note:: .. note::
Use ``cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local ..`` , without spaces after -D if step 2 do not work.
If the size of the created library is a critical issue (like in case of an Android build) you can use the ``install/strip`` command to get the smallest size as possible. The *stripped* version appears to be twice as small. However, we do not recommend using this unless those extra megabytes do really matter. If the size of the created library is a critical issue (like in case of an Android build) you can use the ``install/strip`` command to get the smallest size as possible. The *stripped* version appears to be twice as small. However, we do not recommend using this unless those extra megabytes do really matter.
@@ -483,11 +483,11 @@ Finds the positions of internal corners of the chessboard.
:param flags: Various operation flags that can be zero or a combination of the following values: :param flags: Various operation flags that can be zero or a combination of the following values:
* **CV_CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness). * **CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness).
* **CV_CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with :ocv:func:`equalizeHist` before applying fixed or adaptive thresholding. * **CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with :ocv:func:`equalizeHist` before applying fixed or adaptive thresholding.
* **CV_CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads extracted at the contour retrieval stage. * **CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads extracted at the contour retrieval stage.
* **CALIB_CB_FAST_CHECK** Run a fast check on the image that looks for chessboard corners, and shortcut the call if none is found. This can drastically speed up the call in the degenerate condition when no chessboard is observed. * **CALIB_CB_FAST_CHECK** Run a fast check on the image that looks for chessboard corners, and shortcut the call if none is found. This can drastically speed up the call in the degenerate condition when no chessboard is observed.
+1 -1
View File
@@ -329,7 +329,7 @@ TEST_F(fisheyeTest, Homography)
EXPECT_MAT_NEAR(std_err, correct_std_err, 1e-12); EXPECT_MAT_NEAR(std_err, correct_std_err, 1e-12);
} }
TEST_F(fisheyeTest, EtimateUncertainties) TEST_F(fisheyeTest, EstimateUncertainties)
{ {
const int n_images = 34; const int n_images = 34;
@@ -31,7 +31,7 @@ Aligns a buffer size to the specified number of bytes.
:param n: Alignment size that must be a power of two. :param n: Alignment size that must be a power of two.
The function returns the minimum number that is greater or equal to ``sz`` and is divisible by ``n`` : The function returns the minimum number that is greater than or equal to ``sz`` and is divisible by ``n`` :
.. math:: .. math::
@@ -363,7 +363,7 @@ Always returns 0 if called outside of parallel region.
.. ocv:function:: int getThreadNum() .. ocv:function:: int getThreadNum()
The exact meaning of return value depends on the threading framework used by OpenCV library: The exact meaning of the return value depends on the threading framework used by OpenCV library:
* **TBB** Unsupported with current 4.1 TBB release. May be will be supported in future. * **TBB** Unsupported with current 4.1 TBB release. May be will be supported in future.
* **OpenMP** The thread number, within the current team, of the calling thread. * **OpenMP** The thread number, within the current team, of the calling thread.
@@ -450,7 +450,7 @@ This operation is used in the simplest or most complex image processing function
setNumThreads setNumThreads
----------------- -----------------
OpenCV will try to set the number of threads for the next parallel region. OpenCV will try to set the number of threads for the next parallel region.
If ``threads == 0``, OpenCV will disable threading optimizations and run all it's If ``threads == 0``, OpenCV will disable threading optimizations and run all its
functions sequentially. Passing ``threads < 0`` will reset threads number to system default. functions sequentially. Passing ``threads < 0`` will reset threads number to system default.
This function must be called outside of parallel region. This function must be called outside of parallel region.
@@ -458,14 +458,14 @@ This function must be called outside of parallel region.
:param nthreads: Number of threads used by OpenCV. :param nthreads: Number of threads used by OpenCV.
OpenCV will try to run it's functions with specified threads number, but OpenCV will try to run its functions with specified threads number, but
some behaviour differs from framework: some behaviour differs from framework:
* **TBB** User-defined parallel constructions will run with the same threads number, * **TBB** User-defined parallel constructions will run with the same threads number,
if another does not specified. If late on user creates own scheduler, OpenCV will be use it. if another is not specified. If late on user creates his own scheduler, OpenCV will be use it.
* **OpenMP** No special defined behaviour. * **OpenMP** No special defined behaviour.
* **Concurrency** If ``threads == 1``, OpenCV will disable threading optimizations * **Concurrency** If ``threads == 1``, OpenCV will disable threading optimizations
and run it's functions sequentially. and run its functions sequentially.
* **GCD** Supports only values <= 0. * **GCD** Supports only values <= 0.
* **C=** No special defined behaviour. * **C=** No special defined behaviour.
+5 -3
View File
@@ -203,11 +203,13 @@ cv::Affine3<T>::Affine3(const cv::Mat& data, const Vec3& t)
{ {
rotation(data(Rect(0, 0, 3, 3))); rotation(data(Rect(0, 0, 3, 3)));
translation(data(Rect(3, 0, 1, 3))); translation(data(Rect(3, 0, 1, 3)));
return; }
else
{
rotation(data);
translation(t);
} }
rotation(data);
translation(t);
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0; matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
matrix.val[15] = 1; matrix.val[15] = 1;
} }
+10 -1
View File
@@ -407,7 +407,7 @@ public:
The class is specialized for each fundamental numerical data type supported by OpenCV. The class is specialized for each fundamental numerical data type supported by OpenCV.
It provides DataDepth<T>::value constant. It provides DataDepth<T>::value constant.
*/ */
template<typename _Tp> class DataDepth {}; template<typename _Tp> class DataDepth { public: enum { value = -1, fmt = 0 }; };
template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; }; template<> class DataDepth<bool> { public: enum { value = CV_8U, fmt=(int)'u' }; };
template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; }; template<> class DataDepth<uchar> { public: enum { value = CV_8U, fmt=(int)'u' }; };
@@ -880,8 +880,10 @@ public:
typedef Point_<int> Point2i; typedef Point_<int> Point2i;
typedef Point_<int64> Point2l;
typedef Point2i Point; typedef Point2i Point;
typedef Size_<int> Size2i; typedef Size_<int> Size2i;
typedef Size_<int64> Size2l;
typedef Size_<double> Size2d; typedef Size_<double> Size2d;
typedef Size2i Size; typedef Size2i Size;
typedef Rect_<int> Rect; typedef Rect_<int> Rect;
@@ -2711,6 +2713,7 @@ CV_EXPORTS_W void polylines(InputOutputArray img, InputArrayOfArrays pts,
//! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height) //! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height)
CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2); CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);
CV_EXPORTS bool clipLine(Size2l imgSize, CV_IN_OUT Point2l& pt1, CV_IN_OUT Point2l& pt2);
//! clips the line segment by the rectangle imgRect //! clips the line segment by the rectangle imgRect
CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2); CV_EXPORTS_W bool clipLine(Rect imgRect, CV_OUT CV_IN_OUT Point& pt1, CV_OUT CV_IN_OUT Point& pt2);
@@ -2748,6 +2751,9 @@ public:
CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle, CV_EXPORTS_W void ellipse2Poly( Point center, Size axes, int angle,
int arcStart, int arcEnd, int delta, int arcStart, int arcEnd, int delta,
CV_OUT vector<Point>& pts ); CV_OUT vector<Point>& pts );
CV_EXPORTS void ellipse2Poly( Point2d center, Size2d axes, int angle,
int arcStart, int arcEnd, int delta,
CV_OUT vector<Point2d>& pts );
enum enum
{ {
@@ -3242,6 +3248,9 @@ public:
//! returns read-only pointer to the real buffer, stack-allocated or head-allocated //! returns read-only pointer to the real buffer, stack-allocated or head-allocated
operator const _Tp* () const; operator const _Tp* () const;
//! returns number of allocated elements
size_t getSize() const;
protected: protected:
//! pointer to the real buffer, can point to buf if the buffer is small enough //! pointer to the real buffer, can point to buf if the buffer is small enough
_Tp* ptr; _Tp* ptr;
@@ -2581,6 +2581,9 @@ template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::op
template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const
{ return ptr; } { return ptr; }
template<typename _Tp, size_t fixed_size> inline size_t AutoBuffer<_Tp, fixed_size>::getSize() const
{ return size; }
/////////////////////////////////// Ptr //////////////////////////////////////// /////////////////////////////////// Ptr ////////////////////////////////////////
@@ -50,7 +50,7 @@
#define CV_VERSION_EPOCH 2 #define CV_VERSION_EPOCH 2
#define CV_VERSION_MAJOR 4 #define CV_VERSION_MAJOR 4
#define CV_VERSION_MINOR 13 #define CV_VERSION_MINOR 13
#define CV_VERSION_REVISION 1 #define CV_VERSION_REVISION 4
#define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR_EXP(__A) #__A
#define CVAUX_STR(__A) CVAUX_STR_EXP(__A) #define CVAUX_STR(__A) CVAUX_STR_EXP(__A)
+222 -154
View File
@@ -51,12 +51,12 @@ struct PolyEdge
//PolyEdge(int _y0, int _y1, int _x, int _dx) : y0(_y0), y1(_y1), x(_x), dx(_dx) {} //PolyEdge(int _y0, int _y1, int _x, int _dx) : y0(_y0), y1(_y1), x(_x), dx(_dx) {}
int y0, y1; int y0, y1;
int x, dx; int64 x, dx;
PolyEdge *next; PolyEdge *next;
}; };
static void static void
CollectPolyEdges( Mat& img, const Point* v, int npts, CollectPolyEdges( Mat& img, const Point2l* v, int npts,
vector<PolyEdge>& edges, const void* color, int line_type, vector<PolyEdge>& edges, const void* color, int line_type,
int shift, Point offset=Point() ); int shift, Point offset=Point() );
@@ -64,11 +64,11 @@ static void
FillEdgeCollection( Mat& img, vector<PolyEdge>& edges, const void* color ); FillEdgeCollection( Mat& img, vector<PolyEdge>& edges, const void* color );
static void static void
PolyLine( Mat& img, const Point* v, int npts, bool closed, PolyLine( Mat& img, const Point2l* v, int npts, bool closed,
const void* color, int thickness, int line_type, int shift ); const void* color, int thickness, int line_type, int shift );
static void static void
FillConvexPoly( Mat& img, const Point* v, int npts, FillConvexPoly( Mat& img, const Point2l* v, int npts,
const void* color, int line_type, int shift ); const void* color, int line_type, int shift );
/****************************************************************************************\ /****************************************************************************************\
@@ -77,14 +77,25 @@ FillConvexPoly( Mat& img, const Point* v, int npts,
bool clipLine( Size img_size, Point& pt1, Point& pt2 ) bool clipLine( Size img_size, Point& pt1, Point& pt2 )
{ {
int64 x1, y1, x2, y2; Point2l p1(pt1.x, pt1.y);
Point2l p2(pt2.x, pt2.y);
bool inside = clipLine(Size2l(img_size.width, img_size.height), p1, p2);
pt1.x = (int)p1.x;
pt1.y = (int)p1.y;
pt2.x = (int)p2.x;
pt2.y = (int)p2.y;
return inside;
}
bool clipLine( Size2l img_size, Point2l& pt1, Point2l& pt2 )
{
int c1, c2; int c1, c2;
int64 right = img_size.width-1, bottom = img_size.height-1; int64 right = img_size.width-1, bottom = img_size.height-1;
if( img_size.width <= 0 || img_size.height <= 0 ) if( img_size.width <= 0 || img_size.height <= 0 )
return false; return false;
x1 = pt1.x; y1 = pt1.y; x2 = pt2.x; y2 = pt2.y; int64 &x1 = pt1.x, &y1 = pt1.y, &x2 = pt2.x, &y2 = pt2.y;
c1 = (x1 < 0) + (x1 > right) * 2 + (y1 < 0) * 4 + (y1 > bottom) * 8; c1 = (x1 < 0) + (x1 > right) * 2 + (y1 < 0) * 4 + (y1 > bottom) * 8;
c2 = (x2 < 0) + (x2 > right) * 2 + (y2 < 0) * 4 + (y2 > bottom) * 8; c2 = (x2 < 0) + (x2 > right) * 2 + (y2 < 0) * 4 + (y2 > bottom) * 8;
@@ -124,11 +135,6 @@ bool clipLine( Size img_size, Point& pt1, Point& pt2 )
} }
assert( (c1 & c2) != 0 || (x1 | y1 | x2 | y2) >= 0 ); assert( (c1 & c2) != 0 || (x1 | y1 | x2 | y2) >= 0 );
pt1.x = (int)x1;
pt1.y = (int)y1;
pt2.x = (int)x2;
pt2.y = (int)y2;
} }
return (c1 | c2) == 0; return (c1 | c2) == 0;
@@ -279,25 +285,25 @@ static const int FilterTable[] = {
}; };
static void static void
LineAA( Mat& img, Point pt1, Point pt2, const void* color ) LineAA( Mat& img, Point2l pt1, Point2l pt2, const void* color )
{ {
int dx, dy; int64 dx, dy;
int ecount, scount = 0; int ecount, scount = 0;
int slope; int slope;
int ax, ay; int64 ax, ay;
int x_step, y_step; int64 x_step, y_step;
int i, j; int64 i, j;
int ep_table[9]; int ep_table[9];
int cb = ((uchar*)color)[0], cg = ((uchar*)color)[1], cr = ((uchar*)color)[2], ca = ((uchar*)color)[3]; int cb = ((uchar*)color)[0], cg = ((uchar*)color)[1], cr = ((uchar*)color)[2], ca = ((uchar*)color)[3];
int _cb, _cg, _cr, _ca; int _cb, _cg, _cr, _ca;
int nch = img.channels(); int nch = img.channels();
uchar* ptr = img.data; uchar* ptr = img.data;
size_t step = img.step; size_t step = img.step;
Size size = img.size(); Size2l size(img.cols, img.rows);
if( !((nch == 1 || nch == 3 || nch == 4) && img.depth() == CV_8U) ) if( !((nch == 1 || nch == 3 || nch == 4) && img.depth() == CV_8U) )
{ {
Line(img, pt1, pt2, color); Line(img, Point((int)(pt1.x<<XY_SHIFT), (int)(pt1.y<<XY_SHIFT)), Point((int)(pt2.x<<XY_SHIFT), (int)(pt2.y<<XY_SHIFT)), color);
return; return;
} }
@@ -333,11 +339,11 @@ LineAA( Mat& img, Point pt1, Point pt2, const void* color )
pt1.y ^= pt2.y & j; pt1.y ^= pt2.y & j;
x_step = XY_ONE; x_step = XY_ONE;
y_step = (int) (((int64) dy << XY_SHIFT) / (ax | 1)); y_step = (dy << XY_SHIFT) / (ax | 1);
pt2.x += XY_ONE; pt2.x += XY_ONE;
ecount = (pt2.x >> XY_SHIFT) - (pt1.x >> XY_SHIFT); ecount = (int)((pt2.x >> XY_SHIFT) - (pt1.x >> XY_SHIFT));
j = -(pt1.x & (XY_ONE - 1)); j = -(pt1.x & (XY_ONE - 1));
pt1.y += (int) ((((int64) y_step) * j) >> XY_SHIFT) + (XY_ONE >> 1); pt1.y += ((y_step * j) >> XY_SHIFT) + (XY_ONE >> 1);
slope = (y_step >> (XY_SHIFT - 5)) & 0x3f; slope = (y_step >> (XY_SHIFT - 5)) & 0x3f;
slope ^= (y_step < 0 ? 0x3f : 0); slope ^= (y_step < 0 ? 0x3f : 0);
@@ -356,12 +362,12 @@ LineAA( Mat& img, Point pt1, Point pt2, const void* color )
pt2.y ^= pt1.y & i; pt2.y ^= pt1.y & i;
pt1.y ^= pt2.y & i; pt1.y ^= pt2.y & i;
x_step = (int) (((int64) dx << XY_SHIFT) / (ay | 1)); x_step = (dx << XY_SHIFT) / (ay | 1);
y_step = XY_ONE; y_step = XY_ONE;
pt2.y += XY_ONE; pt2.y += XY_ONE;
ecount = (pt2.y >> XY_SHIFT) - (pt1.y >> XY_SHIFT); ecount = (int)((pt2.y >> XY_SHIFT) - (pt1.y >> XY_SHIFT));
j = -(pt1.y & (XY_ONE - 1)); j = -(pt1.y & (XY_ONE - 1));
pt1.x += (int) ((((int64) x_step) * j) >> XY_SHIFT) + (XY_ONE >> 1); pt1.x += ((x_step * j) >> XY_SHIFT) + (XY_ONE >> 1);
slope = (x_step >> (XY_SHIFT - 5)) & 0x3f; slope = (x_step >> (XY_SHIFT - 5)) & 0x3f;
slope ^= (x_step < 0 ? 0x3f : 0); slope ^= (x_step < 0 ? 0x3f : 0);
@@ -375,8 +381,8 @@ LineAA( Mat& img, Point pt1, Point pt2, const void* color )
/* Calc end point correction table */ /* Calc end point correction table */
{ {
int t0 = slope << 7; int t0 = slope << 7;
int t1 = ((0x78 - i) | 4) * slope; int t1 = ((0x78 - (int)i) | 4) * slope;
int t2 = (j | 4) * slope; int t2 = ((int)j | 4) * slope;
ep_table[0] = 0; ep_table[0] = 0;
ep_table[8] = slope; ep_table[8] = slope;
@@ -630,23 +636,25 @@ LineAA( Mat& img, Point pt1, Point pt2, const void* color )
static void static void
Line2( Mat& img, Point pt1, Point pt2, const void* color ) Line2( Mat& img, Point2l pt1, Point2l pt2, const void* color)
{ {
int dx, dy; int64 dx, dy;
int ecount; int ecount;
int ax, ay; int64 ax, ay;
int i, j, x, y; int64 i, j;
int x_step, y_step; int x, y;
int64 x_step, y_step;
int cb = ((uchar*)color)[0]; int cb = ((uchar*)color)[0];
int cg = ((uchar*)color)[1]; int cg = ((uchar*)color)[1];
int cr = ((uchar*)color)[2]; int cr = ((uchar*)color)[2];
int pix_size = (int)img.elemSize(); int pix_size = (int)img.elemSize();
uchar *ptr = img.data, *tptr; uchar *ptr = img.data, *tptr;
size_t step = img.step; size_t step = img.step;
Size size = img.size(), sizeScaled(size.width*XY_ONE, size.height*XY_ONE); Size size = img.size();
//assert( img && (nch == 1 || nch == 3) && img.depth() == CV_8U ); //assert( img && (nch == 1 || nch == 3) && img.depth() == CV_8U );
Size2l sizeScaled(((int64)size.width) << XY_SHIFT, ((int64)size.height) << XY_SHIFT);
if( !clipLine( sizeScaled, pt1, pt2 )) if( !clipLine( sizeScaled, pt1, pt2 ))
return; return;
@@ -670,8 +678,8 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
pt1.y ^= pt2.y & j; pt1.y ^= pt2.y & j;
x_step = XY_ONE; x_step = XY_ONE;
y_step = (int) (((int64) dy << XY_SHIFT) / (ax | 1)); y_step = (dy << XY_SHIFT) / (ax | 1);
ecount = (pt2.x - pt1.x) >> XY_SHIFT; ecount = (int)((pt2.x - pt1.x) >> XY_SHIFT);
} }
else else
{ {
@@ -684,9 +692,9 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
pt2.y ^= pt1.y & i; pt2.y ^= pt1.y & i;
pt1.y ^= pt2.y & i; pt1.y ^= pt2.y & i;
x_step = (int) (((int64) dx << XY_SHIFT) / (ay | 1)); x_step = (dx << XY_SHIFT) / (ay | 1);
y_step = XY_ONE; y_step = XY_ONE;
ecount = (pt2.y - pt1.y) >> XY_SHIFT; ecount = (int)((pt2.y - pt1.y) >> XY_SHIFT);
} }
pt1.x += (XY_ONE >> 1); pt1.x += (XY_ONE >> 1);
@@ -705,8 +713,8 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
tptr[2] = (uchar)cr; \ tptr[2] = (uchar)cr; \
} }
ICV_PUT_POINT((pt2.x + (XY_ONE >> 1)) >> XY_SHIFT, ICV_PUT_POINT((int)((pt2.x + (XY_ONE >> 1)) >> XY_SHIFT),
(pt2.y + (XY_ONE >> 1)) >> XY_SHIFT); (int)((pt2.y + (XY_ONE >> 1)) >> XY_SHIFT));
if( ax > ay ) if( ax > ay )
{ {
@@ -714,7 +722,7 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
while( ecount >= 0 ) while( ecount >= 0 )
{ {
ICV_PUT_POINT(pt1.x, pt1.y >> XY_SHIFT); ICV_PUT_POINT((int)(pt1.x), (int)(pt1.y >> XY_SHIFT));
pt1.x++; pt1.x++;
pt1.y += y_step; pt1.y += y_step;
ecount--; ecount--;
@@ -726,7 +734,7 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
while( ecount >= 0 ) while( ecount >= 0 )
{ {
ICV_PUT_POINT(pt1.x >> XY_SHIFT, pt1.y); ICV_PUT_POINT((int)(pt1.x >> XY_SHIFT), (int)(pt1.y));
pt1.x += x_step; pt1.x += x_step;
pt1.y++; pt1.y++;
ecount--; ecount--;
@@ -746,8 +754,8 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
tptr[0] = (uchar)cb; \ tptr[0] = (uchar)cb; \
} }
ICV_PUT_POINT((pt2.x + (XY_ONE >> 1)) >> XY_SHIFT, ICV_PUT_POINT((int)((pt2.x + (XY_ONE >> 1)) >> XY_SHIFT),
(pt2.y + (XY_ONE >> 1)) >> XY_SHIFT); (int)((pt2.y + (XY_ONE >> 1)) >> XY_SHIFT));
if( ax > ay ) if( ax > ay )
{ {
@@ -755,7 +763,7 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
while( ecount >= 0 ) while( ecount >= 0 )
{ {
ICV_PUT_POINT(pt1.x, pt1.y >> XY_SHIFT); ICV_PUT_POINT((int)(pt1.x), (int)(pt1.y >> XY_SHIFT));
pt1.x++; pt1.x++;
pt1.y += y_step; pt1.y += y_step;
ecount--; ecount--;
@@ -767,7 +775,7 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
while( ecount >= 0 ) while( ecount >= 0 )
{ {
ICV_PUT_POINT(pt1.x >> XY_SHIFT, pt1.y); ICV_PUT_POINT((int)(pt1.x >> XY_SHIFT), (int)(pt1.y));
pt1.x += x_step; pt1.x += x_step;
pt1.y++; pt1.y++;
ecount--; ecount--;
@@ -788,8 +796,8 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
tptr[j] = ((uchar*)color)[j]; \ tptr[j] = ((uchar*)color)[j]; \
} }
ICV_PUT_POINT((pt2.x + (XY_ONE >> 1)) >> XY_SHIFT, ICV_PUT_POINT((int)((pt2.x + (XY_ONE >> 1)) >> XY_SHIFT),
(pt2.y + (XY_ONE >> 1)) >> XY_SHIFT); (int)((pt2.y + (XY_ONE >> 1)) >> XY_SHIFT));
if( ax > ay ) if( ax > ay )
{ {
@@ -797,7 +805,7 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
while( ecount >= 0 ) while( ecount >= 0 )
{ {
ICV_PUT_POINT(pt1.x, pt1.y >> XY_SHIFT); ICV_PUT_POINT((int)(pt1.x), (int)(pt1.y >> XY_SHIFT));
pt1.x++; pt1.x++;
pt1.y += y_step; pt1.y += y_step;
ecount--; ecount--;
@@ -809,7 +817,7 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color )
while( ecount >= 0 ) while( ecount >= 0 )
{ {
ICV_PUT_POINT(pt1.x >> XY_SHIFT, pt1.y); ICV_PUT_POINT((int)(pt1.x >> XY_SHIFT), (int)(pt1.y));
pt1.x += x_step; pt1.x += x_step;
pt1.y++; pt1.y++;
ecount--; ecount--;
@@ -917,13 +925,35 @@ sincos( int angle, float& cosval, float& sinval )
constructs polygon that represents elliptic arc. constructs polygon that represents elliptic arc.
*/ */
void ellipse2Poly( Point center, Size axes, int angle, void ellipse2Poly( Point center, Size axes, int angle,
int arcStart, int arcEnd,
int delta, CV_OUT std::vector<Point>& pts )
{
vector<Point2d> _pts;
ellipse2Poly(Point2d(center.x, center.y), Size2d(axes.width, axes.height), angle,
arcStart, arcEnd, delta, _pts);
Point prevPt(INT_MIN, INT_MIN);
pts.resize(0);
for (unsigned int i = 0; i < _pts.size(); ++i)
{
Point pt;
pt.x = cvRound(_pts[i].x);
pt.y = cvRound(_pts[i].y);
if (pt != prevPt) {
pts.push_back(pt);
prevPt = pt;
}
}
// If there are no points, it's a zero-size polygon
if( pts.size() == 1 )
pts.push_back(pts[0]);
}
void ellipse2Poly( Point2d center, Size2d axes, int angle,
int arc_start, int arc_end, int arc_start, int arc_end,
int delta, vector<Point>& pts ) int delta, vector<Point2d>& pts )
{ {
float alpha, beta; float alpha, beta;
double size_a = axes.width, size_b = axes.height;
double cx = center.x, cy = center.y;
Point prevPt(INT_MIN,INT_MIN);
int i; int i;
while( angle < 0 ) while( angle < 0 )
@@ -964,15 +994,12 @@ void ellipse2Poly( Point center, Size axes, int angle,
if( angle < 0 ) if( angle < 0 )
angle += 360; angle += 360;
x = size_a * SinTable[450-angle]; x = axes.width * SinTable[450-angle];
y = size_b * SinTable[angle]; y = axes.height * SinTable[angle];
Point pt; Point2d pt;
pt.x = cvRound( cx + x * alpha - y * beta ); pt.x = center.x + x * alpha - y * beta;
pt.y = cvRound( cy + x * beta + y * alpha ); pt.y = center.y + x * beta + y * alpha;
if( pt != prevPt ){ pts.push_back(pt);
pts.push_back(pt);
prevPt = pt;
}
} }
if( pts.size() == 1 ) if( pts.size() == 1 )
@@ -981,16 +1008,37 @@ void ellipse2Poly( Point center, Size axes, int angle,
static void static void
EllipseEx( Mat& img, Point center, Size axes, EllipseEx( Mat& img, Point2l center, Size2l axes,
int angle, int arc_start, int arc_end, int angle, int arc_start, int arc_end,
const void* color, int thickness, int line_type ) const void* color, int thickness, int line_type )
{ {
axes.width = std::abs(axes.width), axes.height = std::abs(axes.height); axes.width = std::abs(axes.width), axes.height = std::abs(axes.height);
int delta = (std::max(axes.width,axes.height)+(XY_ONE>>1))>>XY_SHIFT; int delta = (int)((std::max(axes.width,axes.height)+(XY_ONE>>1))>>XY_SHIFT);
delta = delta < 3 ? 90 : delta < 10 ? 30 : delta < 15 ? 18 : 5; delta = delta < 3 ? 90 : delta < 10 ? 30 : delta < 15 ? 18 : 5;
vector<Point> v; vector<Point2d> _v;
ellipse2Poly( center, axes, angle, arc_start, arc_end, delta, v ); ellipse2Poly( Point2d((double)center.x, (double)center.y), Size2d((double)axes.width, (double)axes.height), angle, arc_start, arc_end, delta, _v );
vector<Point2l> v;
Point2l prevPt(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF);
v.resize(0);
for (unsigned int i = 0; i < _v.size(); ++i)
{
Point2l pt;
pt.x = (int64)cvRound(_v[i].x / XY_ONE) << XY_SHIFT;
pt.y = (int64)cvRound(_v[i].y / XY_ONE) << XY_SHIFT;
pt.x += cvRound(_v[i].x - pt.x);
pt.y += cvRound(_v[i].y - pt.y);
if (pt != prevPt) {
v.push_back(pt);
prevPt = pt;
}
}
// If there are no points, it's a zero-size polygon
if (v.size() == 1) {
v.assign(2, center);
}
if( thickness >= 0 ) if( thickness >= 0 )
PolyLine( img, &v[0], (int)v.size(), false, color, thickness, line_type, XY_SHIFT ); PolyLine( img, &v[0], (int)v.size(), false, color, thickness, line_type, XY_SHIFT );
@@ -1029,23 +1077,24 @@ EllipseEx( Mat& img, Point center, Size axes,
/* filling convex polygon. v - array of vertices, ntps - number of points */ /* filling convex polygon. v - array of vertices, ntps - number of points */
static void static void
FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_type, int shift ) FillConvexPoly( Mat& img, const Point2l* v, int npts, const void* color, int line_type, int shift )
{ {
struct struct
{ {
int idx, di; int idx, di;
int x, dx, ye; int64 x, dx;
int ye;
} }
edge[2]; edge[2];
int delta = shift ? 1 << (shift - 1) : 0; int delta = 1 << shift >> 1;
int i, y, imin = 0, left = 0, right = 1, x1, x2; int i, y, imin = 0, left = 0, right = 1;
int edges = npts; int edges = npts;
int xmin, xmax, ymin, ymax; int64 xmin, xmax, ymin, ymax;
uchar* ptr = img.data; uchar* ptr = img.data;
Size size = img.size(); Size size = img.size();
int pix_size = (int)img.elemSize(); int pix_size = (int)img.elemSize();
Point p0; Point2l p0;
int delta1, delta2; int delta1, delta2;
if( line_type < CV_AA ) if( line_type < CV_AA )
@@ -1063,7 +1112,7 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_
for( i = 0; i < npts; i++ ) for( i = 0; i < npts; i++ )
{ {
Point p = v[i]; Point2l p = v[i];
if( p.y < ymin ) if( p.y < ymin )
{ {
ymin = p.y; ymin = p.y;
@@ -1082,10 +1131,10 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_
if( shift == 0 ) if( shift == 0 )
{ {
Point pt0, pt1; Point pt0, pt1;
pt0.x = p0.x >> XY_SHIFT; pt0.x = (int)(p0.x >> XY_SHIFT);
pt0.y = p0.y >> XY_SHIFT; pt0.y = (int)(p0.y >> XY_SHIFT);
pt1.x = p.x >> XY_SHIFT; pt1.x = (int)(p.x >> XY_SHIFT);
pt1.y = p.y >> XY_SHIFT; pt1.y = (int)(p.y >> XY_SHIFT);
Line( img, pt0, pt1, color, line_type ); Line( img, pt0, pt1, color, line_type );
} }
else else
@@ -1101,13 +1150,13 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_
ymin = (ymin + delta) >> shift; ymin = (ymin + delta) >> shift;
ymax = (ymax + delta) >> shift; ymax = (ymax + delta) >> shift;
if( npts < 3 || xmax < 0 || ymax < 0 || xmin >= size.width || ymin >= size.height ) if( npts < 3 || (int)xmax < 0 || (int)ymax < 0 || (int)xmin >= size.width || (int)ymin >= size.height )
return; return;
ymax = MIN( ymax, size.height - 1 ); ymax = MIN( ymax, size.height - 1 );
edge[0].idx = edge[1].idx = imin; edge[0].idx = edge[1].idx = imin;
edge[0].ye = edge[1].ye = y = ymin; edge[0].ye = edge[1].ye = y = (int)ymin;
edge[0].di = 1; edge[0].di = 1;
edge[1].di = npts - 1; edge[1].di = npts - 1;
@@ -1115,18 +1164,19 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_
do do
{ {
if( line_type < CV_AA || y < ymax || y == ymin ) if( line_type < CV_AA || y < (int)ymax || y == (int)ymin )
{ {
for( i = 0; i < 2; i++ ) for( i = 0; i < 2; i++ )
{ {
if( y >= edge[i].ye ) if( y >= edge[i].ye )
{ {
int idx = edge[i].idx, di = edge[i].di; int idx = edge[i].idx, di = edge[i].di;
int xs = 0, xe, ye, ty = 0; int64 xs = 0, xe;
int ty = 0;
for(;;) for(;;)
{ {
ty = (v[idx].y + delta) >> shift; ty = (int)((v[idx].y + delta) >> shift);
if( ty > y || edges == 0 ) if( ty > y || edges == 0 )
break; break;
xs = v[idx].x; xs = v[idx].x;
@@ -1135,16 +1185,19 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_
edges--; edges--;
} }
ye = ty; xe = v[idx].x;
xs <<= XY_SHIFT - shift; if (XY_SHIFT - shift != 0)
xe = v[idx].x << (XY_SHIFT - shift); {
xs <<= XY_SHIFT - shift;
xe <<= XY_SHIFT - shift;
}
/* no more edges */ /* no more edges */
if( y >= ye ) if( y >= ty)
return; return;
edge[i].ye = ye; edge[i].ye = ty;
edge[i].dx = ((xe - xs)*2 + (ye - y)) / (2 * (ye - y)); edge[i].dx = ((xe - xs)*2 + (ty - y)) / (2 * (ty - y));
edge[i].x = xs; edge[i].x = xs;
edge[i].idx = idx; edge[i].idx = idx;
} }
@@ -1157,13 +1210,10 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_
right ^= 1; right ^= 1;
} }
x1 = edge[left].x;
x2 = edge[right].x;
if( y >= 0 ) if( y >= 0 )
{ {
int xx1 = (x1 + delta1) >> XY_SHIFT; int xx1 = (int)((edge[left].x + delta1) >> XY_SHIFT);
int xx2 = (x2 + delta2) >> XY_SHIFT; int xx2 = (int)((edge[right].x + delta2) >> XY_SHIFT);
if( xx2 >= 0 && xx1 < size.width ) if( xx2 >= 0 && xx1 < size.width )
{ {
@@ -1175,25 +1225,22 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_
} }
} }
x1 += edge[left].dx; edge[left].x += edge[left].dx;
x2 += edge[right].dx; edge[right].x += edge[right].dx;
edge[left].x = x1;
edge[right].x = x2;
ptr += img.step; ptr += img.step;
} }
while( ++y <= ymax ); while( ++y <= (int)ymax );
} }
/******** Arbitrary polygon **********/ /******** Arbitrary polygon **********/
static void static void
CollectPolyEdges( Mat& img, const Point* v, int count, vector<PolyEdge>& edges, CollectPolyEdges( Mat& img, const Point2l* v, int count, vector<PolyEdge>& edges,
const void* color, int line_type, int shift, Point offset ) const void* color, int line_type, int shift, Point offset )
{ {
int i, delta = offset.y + (shift ? 1 << (shift - 1) : 0); int i, delta = offset.y + ((1 << shift) >> 1);
Point pt0 = v[count-1], pt1; Point2l pt0 = v[count-1], pt1;
pt0.x = (pt0.x + offset.x) << (XY_SHIFT - shift); pt0.x = (pt0.x + offset.x) << (XY_SHIFT - shift);
pt0.y = (pt0.y + delta) >> shift; pt0.y = (pt0.y + delta) >> shift;
@@ -1201,7 +1248,7 @@ CollectPolyEdges( Mat& img, const Point* v, int count, vector<PolyEdge>& edges,
for( i = 0; i < count; i++, pt0 = pt1 ) for( i = 0; i < count; i++, pt0 = pt1 )
{ {
Point t0, t1; Point2l t0, t1;
PolyEdge edge; PolyEdge edge;
pt1 = v[i]; pt1 = v[i];
@@ -1213,7 +1260,7 @@ CollectPolyEdges( Mat& img, const Point* v, int count, vector<PolyEdge>& edges,
t0.y = pt0.y; t1.y = pt1.y; t0.y = pt0.y; t1.y = pt1.y;
t0.x = (pt0.x + (XY_ONE >> 1)) >> XY_SHIFT; t0.x = (pt0.x + (XY_ONE >> 1)) >> XY_SHIFT;
t1.x = (pt1.x + (XY_ONE >> 1)) >> XY_SHIFT; t1.x = (pt1.x + (XY_ONE >> 1)) >> XY_SHIFT;
Line( img, t0, t1, color, line_type ); Line( img, Point((int)(t0.x), (int)(t0.y)), Point((int)(t1.x), (int)(t1.y)), color, line_type );
} }
else else
{ {
@@ -1228,14 +1275,14 @@ CollectPolyEdges( Mat& img, const Point* v, int count, vector<PolyEdge>& edges,
if( pt0.y < pt1.y ) if( pt0.y < pt1.y )
{ {
edge.y0 = pt0.y; edge.y0 = (int)(pt0.y);
edge.y1 = pt1.y; edge.y1 = (int)(pt1.y);
edge.x = pt0.x; edge.x = pt0.x;
} }
else else
{ {
edge.y0 = pt1.y; edge.y0 = (int)(pt1.y);
edge.y1 = pt0.y; edge.y1 = (int)(pt0.y);
edge.x = pt1.x; edge.x = pt1.x;
} }
edge.dx = (pt1.x - pt0.x) / (pt1.y - pt0.y); edge.dx = (pt1.x - pt0.x) / (pt1.y - pt0.y);
@@ -1261,7 +1308,8 @@ FillEdgeCollection( Mat& img, vector<PolyEdge>& edges, const void* color )
int i, y, total = (int)edges.size(); int i, y, total = (int)edges.size();
Size size = img.size(); Size size = img.size();
PolyEdge* e; PolyEdge* e;
int y_max = INT_MIN, x_max = INT_MIN, y_min = INT_MAX, x_min = INT_MAX; int y_max = INT_MIN, y_min = INT_MAX;
int64 x_max = 0xFFFFFFFFFFFFFFFF, x_min = 0x7FFFFFFFFFFFFFFF;
int pix_size = (int)img.elemSize(); int pix_size = (int)img.elemSize();
if( total < 2 ) if( total < 2 )
@@ -1273,7 +1321,7 @@ FillEdgeCollection( Mat& img, vector<PolyEdge>& edges, const void* color )
assert( e1.y0 < e1.y1 ); assert( e1.y0 < e1.y1 );
// Determine x-coordinate of the end of the edge. // Determine x-coordinate of the end of the edge.
// (This is not necessary x-coordinate of any vertex in the array.) // (This is not necessary x-coordinate of any vertex in the array.)
int x1 = e1.x + (e1.y1 - e1.y0) * e1.dx; int64 x1 = e1.x + (e1.y1 - e1.y0) * e1.dx;
y_min = std::min( y_min, e1.y0 ); y_min = std::min( y_min, e1.y0 );
y_max = std::max( y_max, e1.y1 ); y_max = std::max( y_max, e1.y1 );
x_min = std::min( x_min, e1.x ); x_min = std::min( x_min, e1.x );
@@ -1282,7 +1330,7 @@ FillEdgeCollection( Mat& img, vector<PolyEdge>& edges, const void* color )
x_max = std::max( x_max, x1 ); x_max = std::max( x_max, x1 );
} }
if( y_max < 0 || y_min >= size.height || x_max < 0 || x_min >= (size.width<<XY_SHIFT) ) if( y_max < 0 || y_min >= size.height || x_max < 0 || x_min >= ((int64)size.width<<XY_SHIFT) )
return; return;
std::sort( edges.begin(), edges.end(), CmpEdges() ); std::sort( edges.begin(), edges.end(), CmpEdges() );
@@ -1338,19 +1386,18 @@ FillEdgeCollection( Mat& img, vector<PolyEdge>& edges, const void* color )
{ {
// convert x's from fixed-point to image coordinates // convert x's from fixed-point to image coordinates
uchar *timg = img.data + y * img.step; uchar *timg = img.data + y * img.step;
int x1 = keep_prelast->x; int x1, x2;
int x2 = prelast->x;
if( x1 > x2 ) if (keep_prelast->x > prelast->x)
{ {
int t = x1; x1 = (int)((prelast->x + XY_ONE - 1) >> XY_SHIFT);
x2 = (int)(keep_prelast->x >> XY_SHIFT);
x1 = x2; }
x2 = t; else
{
x1 = (int)((keep_prelast->x + XY_ONE - 1) >> XY_SHIFT);
x2 = (int)(prelast->x >> XY_SHIFT);
} }
x1 = (x1 + XY_ONE - 1) >> XY_SHIFT;
x2 = x2 >> XY_SHIFT;
// clip and draw the line // clip and draw the line
if( x1 < size.width && x2 >= 0 ) if( x1 < size.width && x2 >= 0 )
@@ -1550,7 +1597,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill )
static void static void
ThickLine( Mat& img, Point p0, Point p1, const void* color, ThickLine( Mat& img, Point2l p0, Point2l p1, const void* color,
int thickness, int line_type, int flags, int shift ) int thickness, int line_type, int flags, int shift )
{ {
static const double INV_XY_ONE = 1./XY_ONE; static const double INV_XY_ONE = 1./XY_ONE;
@@ -1570,7 +1617,7 @@ ThickLine( Mat& img, Point p0, Point p1, const void* color,
p0.y = (p0.y + (XY_ONE>>1)) >> XY_SHIFT; p0.y = (p0.y + (XY_ONE>>1)) >> XY_SHIFT;
p1.x = (p1.x + (XY_ONE>>1)) >> XY_SHIFT; p1.x = (p1.x + (XY_ONE>>1)) >> XY_SHIFT;
p1.y = (p1.y + (XY_ONE>>1)) >> XY_SHIFT; p1.y = (p1.y + (XY_ONE>>1)) >> XY_SHIFT;
Line( img, p0, p1, color, line_type ); Line( img, Point((int)(p0.x), (int)(p0.y)), Point((int)(p1.x), (int)(p1.y)), color, line_type );
} }
else else
Line2( img, p0, p1, color ); Line2( img, p0, p1, color );
@@ -1580,7 +1627,7 @@ ThickLine( Mat& img, Point p0, Point p1, const void* color,
} }
else else
{ {
Point pt[4], dp = Point(0,0); Point2l pt[4], dp = Point2l(0,0);
double dx = (p0.x - p1.x)*INV_XY_ONE, dy = (p1.y - p0.y)*INV_XY_ONE; double dx = (p0.x - p1.x)*INV_XY_ONE, dy = (p1.y - p0.y)*INV_XY_ONE;
double r = dx * dx + dy * dy; double r = dx * dx + dy * dy;
int i, oddThickness = thickness & 1; int i, oddThickness = thickness & 1;
@@ -1611,13 +1658,13 @@ ThickLine( Mat& img, Point p0, Point p1, const void* color,
if( line_type < CV_AA ) if( line_type < CV_AA )
{ {
Point center; Point center;
center.x = (p0.x + (XY_ONE>>1)) >> XY_SHIFT; center.x = (int)((p0.x + (XY_ONE>>1)) >> XY_SHIFT);
center.y = (p0.y + (XY_ONE>>1)) >> XY_SHIFT; center.y = (int)((p0.y + (XY_ONE>>1)) >> XY_SHIFT);
Circle( img, center, (thickness + (XY_ONE>>1)) >> XY_SHIFT, color, 1 ); Circle( img, center, (thickness + (XY_ONE>>1)) >> XY_SHIFT, color, 1 );
} }
else else
{ {
EllipseEx( img, p0, cvSize(thickness, thickness), EllipseEx( img, p0, Size2l(thickness, thickness),
0, 0, 360, color, -1, line_type ); 0, 0, 360, color, -1, line_type );
} }
} }
@@ -1628,7 +1675,7 @@ ThickLine( Mat& img, Point p0, Point p1, const void* color,
static void static void
PolyLine( Mat& img, const Point* v, int count, bool is_closed, PolyLine( Mat& img, const Point2l* v, int count, bool is_closed,
const void* color, int thickness, const void* color, int thickness,
int line_type, int shift ) int line_type, int shift )
{ {
@@ -1637,13 +1684,13 @@ PolyLine( Mat& img, const Point* v, int count, bool is_closed,
int i = is_closed ? count - 1 : 0; int i = is_closed ? count - 1 : 0;
int flags = 2 + !is_closed; int flags = 2 + !is_closed;
Point p0; Point2l p0;
CV_Assert( 0 <= shift && shift <= XY_SHIFT && thickness >= 0 ); CV_Assert( 0 <= shift && shift <= XY_SHIFT && thickness >= 0 );
p0 = v[i]; p0 = v[i];
for( i = !is_closed; i < count; i++ ) for( i = !is_closed; i < count; i++ )
{ {
Point p = v[i]; Point2l p = v[i];
ThickLine( img, p0, p, color, thickness, line_type, flags, shift ); ThickLine( img, p0, p, color, thickness, line_type, flags, shift );
p0 = p; p0 = p;
flags = 2; flags = 2;
@@ -1700,7 +1747,7 @@ void rectangle( Mat& img, Point pt1, Point pt2,
double buf[4]; double buf[4];
scalarToRawData(color, buf, img.type(), 0); scalarToRawData(color, buf, img.type(), 0);
Point pt[4]; Point2l pt[4];
pt[0] = pt1; pt[0] = pt1;
pt[1].x = pt2.x; pt[1].x = pt2.x;
@@ -1741,10 +1788,12 @@ void circle( Mat& img, Point center, int radius,
if( thickness > 1 || line_type >= CV_AA || shift > 0 ) if( thickness > 1 || line_type >= CV_AA || shift > 0 )
{ {
center.x <<= XY_SHIFT - shift; Point2l _center(center.x, center.y);
center.y <<= XY_SHIFT - shift; int64 _radius(radius);
radius <<= XY_SHIFT - shift; _center.x <<= XY_SHIFT - shift;
EllipseEx( img, center, Size(radius, radius), _center.y <<= XY_SHIFT - shift;
_radius <<= XY_SHIFT - shift;
EllipseEx( img, _center, Size2l(_radius, _radius),
0, 0, 360, buf, thickness, line_type ); 0, 0, 360, buf, thickness, line_type );
} }
else else
@@ -1768,12 +1817,14 @@ void ellipse( Mat& img, Point center, Size axes,
int _angle = cvRound(angle); int _angle = cvRound(angle);
int _start_angle = cvRound(start_angle); int _start_angle = cvRound(start_angle);
int _end_angle = cvRound(end_angle); int _end_angle = cvRound(end_angle);
center.x <<= XY_SHIFT - shift; Point2l _center(center.x, center.y);
center.y <<= XY_SHIFT - shift; Size2l _axes(axes.width, axes.height);
axes.width <<= XY_SHIFT - shift; _center.x <<= XY_SHIFT - shift;
axes.height <<= XY_SHIFT - shift; _center.y <<= XY_SHIFT - shift;
_axes.width <<= XY_SHIFT - shift;
_axes.height <<= XY_SHIFT - shift;
EllipseEx( img, center, axes, _angle, _start_angle, EllipseEx( img, _center, _axes, _angle, _start_angle,
_end_angle, buf, thickness, line_type ); _end_angle, buf, thickness, line_type );
} }
@@ -1790,10 +1841,14 @@ void ellipse(Mat& img, const RotatedRect& box, const Scalar& color,
scalarToRawData(color, buf, img.type(), 0); scalarToRawData(color, buf, img.type(), 0);
int _angle = cvRound(box.angle); int _angle = cvRound(box.angle);
Point center(cvRound(box.center.x*(1 << XY_SHIFT)), Point2l center(cvRound(box.center.x),
cvRound(box.center.y*(1 << XY_SHIFT))); cvRound(box.center.y));
Size axes(cvRound(box.size.width*(1 << (XY_SHIFT - 1))), center.x = (center.x << XY_SHIFT) + cvRound((box.center.x - center.x)*XY_ONE);
cvRound(box.size.height*(1 << (XY_SHIFT - 1)))); center.y = (center.y << XY_SHIFT) + cvRound((box.center.y - center.y)*XY_ONE);
Size2l axes(cvRound(box.size.width),
cvRound(box.size.height));
axes.width = (axes.width << (XY_SHIFT - 1)) + cvRound((box.size.width - axes.width)*(XY_ONE>>1));
axes.height = (axes.height << (XY_SHIFT - 1)) + cvRound((box.size.height - axes.height)*(XY_ONE>>1));
EllipseEx( img, center, axes, _angle, 0, 360, buf, thickness, lineType ); EllipseEx( img, center, axes, _angle, 0, 360, buf, thickness, lineType );
} }
@@ -1876,7 +1931,10 @@ void fillConvexPoly( Mat& img, const Point* pts, int npts,
double buf[4]; double buf[4];
CV_Assert( 0 <= shift && shift <= XY_SHIFT ); CV_Assert( 0 <= shift && shift <= XY_SHIFT );
scalarToRawData(color, buf, img.type(), 0); scalarToRawData(color, buf, img.type(), 0);
FillConvexPoly( img, pts, npts, buf, line_type, shift ); vector<Point2l> _pts;
for( int n = 0; n < npts; n++ )
_pts.push_back(Point2l(pts[n].x, pts[n].y));
FillConvexPoly( img, _pts.data(), npts, buf, line_type, shift );
} }
@@ -1900,7 +1958,12 @@ void fillPoly( Mat& img, const Point** pts, const int* npts, int ncontours,
edges.reserve( total + 1 ); edges.reserve( total + 1 );
for( i = 0; i < ncontours; i++ ) for( i = 0; i < ncontours; i++ )
CollectPolyEdges( img, pts[i], npts[i], edges, buf, line_type, shift, offset ); {
vector<Point2l> _pts;
for( int n = 0; n < npts[i]; n++ )
_pts.push_back(Point2l(pts[i][n].x, pts[i][n].y));
CollectPolyEdges( img, _pts.data(), npts[i], edges, buf, line_type, shift, offset );
}
FillEdgeCollection(img, edges, buf); FillEdgeCollection(img, edges, buf);
} }
@@ -1920,7 +1983,12 @@ void polylines( Mat& img, const Point** pts, const int* npts, int ncontours, boo
scalarToRawData( color, buf, img.type(), 0 ); scalarToRawData( color, buf, img.type(), 0 );
for( int i = 0; i < ncontours; i++ ) for( int i = 0; i < ncontours; i++ )
PolyLine( img, pts[i], npts[i], isClosed, buf, thickness, line_type, shift ); {
vector<Point2l> _pts;
for( int n = 0; n < npts[i]; n++ )
_pts.push_back(Point2l(pts[i][n].x, pts[i][n].y));
PolyLine( img, _pts.data(), npts[i], isClosed, buf, thickness, line_type, shift );
}
} }
@@ -2156,23 +2224,23 @@ void putText( Mat& img, const string& text, Point org,
if( bottomLeftOrigin ) if( bottomLeftOrigin )
vscale = -vscale; vscale = -vscale;
int view_x = org.x << XY_SHIFT; int64 view_x = (int64)org.x << XY_SHIFT;
int view_y = (org.y << XY_SHIFT) + base_line*vscale; int64 view_y = ((int64)org.y << XY_SHIFT) + base_line*vscale;
vector<Point> pts; vector<Point2l> pts;
pts.reserve(1 << 10); pts.reserve(1 << 10);
const char **faces = cv::g_HersheyGlyphs; const char **faces = cv::g_HersheyGlyphs;
for( int i = 0; i < (int)text.size(); i++ ) for( int i = 0; i < (int)text.size(); i++ )
{ {
int c = (uchar)text[i]; int c = (uchar)text[i];
Point p; Point2l p;
readCheck(c, i, text, fontFace); readCheck(c, i, text, fontFace);
const char* ptr = faces[ascii[(c-' ')+1]]; const char* ptr = faces[ascii[(c-' ')+1]];
p.x = (uchar)ptr[0] - 'R'; p.x = (uchar)ptr[0] - 'R';
p.y = (uchar)ptr[1] - 'R'; p.y = (uchar)ptr[1] - 'R';
int dx = p.y*hscale; int64 dx = p.y*hscale;
view_x -= p.x*hscale; view_x -= p.x*hscale;
pts.resize(0); pts.resize(0);
@@ -2191,7 +2259,7 @@ void putText( Mat& img, const string& text, Point org,
p.x = (uchar)ptr[0] - 'R'; p.x = (uchar)ptr[0] - 'R';
p.y = (uchar)ptr[1] - 'R'; p.y = (uchar)ptr[1] - 'R';
ptr += 2; ptr += 2;
pts.push_back(Point(p.x*hscale + view_x, p.y*vscale + view_y)); pts.push_back(Point2l(p.x*hscale + view_x, p.y*vscale + view_y));
} }
} }
view_x += dx; view_x += dx;
@@ -2310,7 +2378,7 @@ cvDrawContours( void* _img, CvSeq* contour,
CvSeq *contour0 = contour, *h_next = 0; CvSeq *contour0 = contour, *h_next = 0;
CvTreeNodeIterator iterator; CvTreeNodeIterator iterator;
cv::vector<cv::PolyEdge> edges; cv::vector<cv::PolyEdge> edges;
cv::vector<cv::Point> pts; cv::vector<cv::Point2l> pts;
cv::Scalar externalColor = _externalColor, holeColor = _holeColor; cv::Scalar externalColor = _externalColor, holeColor = _holeColor;
cv::Mat img = cv::cvarrToMat(_img); cv::Mat img = cv::cvarrToMat(_img);
cv::Point offset = _offset; cv::Point offset = _offset;
@@ -2434,7 +2502,7 @@ cvEllipse2Poly( CvPoint center, CvSize axes, int angle,
int arc_start, int arc_end, CvPoint* _pts, int delta ) int arc_start, int arc_end, CvPoint* _pts, int delta )
{ {
cv::vector<cv::Point> pts; cv::vector<cv::Point> pts;
cv::ellipse2Poly( center, axes, angle, arc_start, arc_end, delta, pts ); cv::ellipse2Poly( cv::Point(center), cv::Size(axes), angle, arc_start, arc_end, delta, pts );
memcpy( _pts, &pts[0], pts.size()*sizeof(_pts[0]) ); memcpy( _pts, &pts[0], pts.size()*sizeof(_pts[0]) );
return (int)pts.size(); return (int)pts.size();
} }
+22 -12
View File
@@ -279,21 +279,31 @@ Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) : size(&r
} }
*this = m; *this = m;
if( _rowRange != Range::all() && _rowRange != Range(0,rows) ) try
{ {
CV_Assert( 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows ); if( _rowRange != Range::all() && _rowRange != Range(0,rows) )
rows = _rowRange.size(); {
data += step*_rowRange.start; CV_Assert( 0 <= _rowRange.start && _rowRange.start <= _rowRange.end
flags |= SUBMATRIX_FLAG; && _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();
flags &= cols < m.cols ? ~CONTINUOUS_FLAG : -1;
flags |= SUBMATRIX_FLAG;
}
}
catch(...)
{ {
CV_Assert( 0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols ); release();
cols = _colRange.size(); throw;
data += _colRange.start*elemSize();
flags &= cols < m.cols ? ~CONTINUOUS_FLAG : -1;
flags |= SUBMATRIX_FLAG;
} }
if( rows == 1 ) if( rows == 1 )
+1 -1
View File
@@ -56,7 +56,7 @@
#include <sys/types.h> #include <sys/types.h>
#if defined ANDROID #if defined ANDROID
#include <sys/sysconf.h> #include <sys/sysconf.h>
#else #elif defined __APPLE__
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif #endif
#endif #endif
-2
View File
@@ -163,8 +163,6 @@ std::wstring GetTempFileNameWinRT(std::wstring prefix)
#include <sys/types.h> #include <sys/types.h>
#if defined ANDROID #if defined ANDROID
#include <sys/sysconf.h> #include <sys/sysconf.h>
#else
#include <sys/sysctl.h>
#endif #endif
#endif #endif
@@ -146,6 +146,7 @@ public:
*/ */
LshTable() LshTable()
{ {
feature_size_ = 0;
} }
/** Default constructor /** Default constructor
@@ -156,7 +157,7 @@ public:
*/ */
LshTable(unsigned int feature_size, unsigned int key_size, std::vector<size_t> & indices) LshTable(unsigned int feature_size, unsigned int key_size, std::vector<size_t> & indices)
{ {
(void)feature_size; feature_size_ = feature_size;
(void)key_size; (void)key_size;
(void)indices; (void)indices;
std::cerr << "LSH is not implemented for that type" << std::endl; std::cerr << "LSH is not implemented for that type" << std::endl;
@@ -335,6 +336,8 @@ private:
*/ */
unsigned int key_size_; unsigned int key_size_;
unsigned int feature_size_;
// Members only used for the unsigned char specialization // Members only used for the unsigned char specialization
/** The mask to apply to a feature to get the hash key /** The mask to apply to a feature to get the hash key
* Only used in the unsigned char case * Only used in the unsigned char case
@@ -350,9 +353,10 @@ inline LshTable<unsigned char>::LshTable( unsigned int feature_size,
unsigned int subsignature_size, unsigned int subsignature_size,
std::vector<size_t> & indices ) std::vector<size_t> & indices )
{ {
feature_size_ = feature_size;
initialize(subsignature_size); initialize(subsignature_size);
// Allocate the mask // Allocate the mask
mask_ = std::vector<size_t>((size_t)ceil((float)(feature_size * sizeof(char)) / (float)sizeof(size_t)), 0); mask_ = std::vector<size_t>((feature_size * sizeof(char) + sizeof(size_t) - 1) / sizeof(size_t), 0);
// Generate a random set of order of subsignature_size_ bits // Generate a random set of order of subsignature_size_ bits
for (unsigned int i = 0; i < key_size_; ++i) { for (unsigned int i = 0; i < key_size_; ++i) {
@@ -391,6 +395,7 @@ inline size_t LshTable<unsigned char>::getKey(const unsigned char* feature) cons
{ {
// no need to check if T is dividable by sizeof(size_t) like in the Hamming // no need to check if T is dividable by sizeof(size_t) like in the Hamming
// distance computation as we have a mask // distance computation as we have a mask
// FIXIT: This is bad assumption, because we reading tail bytes after of the allocated features buffer
const size_t* feature_block_ptr = reinterpret_cast<const size_t*> ((const void*)feature); const size_t* feature_block_ptr = reinterpret_cast<const size_t*> ((const void*)feature);
// Figure out the subsignature of the feature // Figure out the subsignature of the feature
@@ -399,10 +404,20 @@ inline size_t LshTable<unsigned char>::getKey(const unsigned char* feature) cons
size_t subsignature = 0; size_t subsignature = 0;
size_t bit_index = 1; size_t bit_index = 1;
for (std::vector<size_t>::const_iterator pmask_block = mask_.begin(); pmask_block != mask_.end(); ++pmask_block) { for (unsigned i = 0; i < feature_size_; i += sizeof(size_t)) {
// get the mask and signature blocks // get the mask and signature blocks
size_t feature_block = *feature_block_ptr; size_t feature_block;
size_t mask_block = *pmask_block; if (i <= feature_size_ - sizeof(size_t))
{
feature_block = *feature_block_ptr;
}
else
{
size_t tmp = 0;
memcpy(&tmp, feature_block_ptr, feature_size_ - i); // preserve bytes order
feature_block = tmp;
}
size_t mask_block = mask_[i / sizeof(size_t)];
while (mask_block) { while (mask_block) {
// Get the lowest set bit in the mask block // Get the lowest set bit in the mask block
size_t lowest_bit = mask_block & (-(ptrdiff_t)mask_block); size_t lowest_bit = mask_block & (-(ptrdiff_t)mask_block);
+3 -3
View File
@@ -186,9 +186,9 @@ Reduces a matrix to a vector.
:param mtx: Source 2D matrix. :param mtx: Source 2D matrix.
:param vec: Destination vector. Its size and type is defined by ``dim`` and ``dtype`` parameters. :param vec: Destination row vector. Its type is defined by ``dtype`` parameter.
:param dim: Dimension index along which the matrix is reduced. 0 means that the matrix is reduced to a single row. 1 means that the matrix is reduced to a single column. :param dim: Dimension index along which the matrix is reduced. 0 means that the matrix is reduced to a single row(of length equal to number of matrix columns). 1 means that the matrix is reduced to a single column(of length equal to the number of matrix rows). In either case, the output is always stored as a row vector of appropriate length.
:param reduceOp: Reduction operation that could be one of the following: :param reduceOp: Reduction operation that could be one of the following:
@@ -202,6 +202,6 @@ Reduces a matrix to a vector.
:param dtype: When it is negative, the destination vector will have the same type as the source matrix. Otherwise, its type will be ``CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())`` . :param dtype: When it is negative, the destination vector will have the same type as the source matrix. Otherwise, its type will be ``CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())`` .
The function ``reduce`` reduces the matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained. For example, the function can be used to compute horizontal and vertical projections of a raster image. In case of ``CV_REDUCE_SUM`` and ``CV_REDUCE_AVG`` , the output may have a larger element bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction modes. The function ``reduce`` reduces the matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single column/row is obtained. However, the result is always stored as a row vector. For example, the function can be used to compute horizontal and vertical projections of a raster image. In case of ``CV_REDUCE_SUM`` and ``CV_REDUCE_AVG`` , the output may have a larger element bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction modes.
.. seealso:: :ocv:func:`reduce` .. seealso:: :ocv:func:`reduce`
+19 -19
View File
@@ -435,13 +435,13 @@ CV_EXPORTS void LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& stre
CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream = Stream::Null()); CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream = Stream::Null());
//! makes multi-channel array out of several single-channel arrays //! makes multi-channel array out of several single-channel arrays
CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, Stream& stream = Stream::Null()); CV_EXPORTS void merge(const std::vector<GpuMat>& src, GpuMat& dst, Stream& stream = Stream::Null());
//! copies each plane of a multi-channel array to a dedicated array //! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::Null()); CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::Null());
//! copies each plane of a multi-channel array to a dedicated array //! copies each plane of a multi-channel array to a dedicated array
CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, Stream& stream = Stream::Null()); CV_EXPORTS void split(const GpuMat& src, std::vector<GpuMat>& dst, Stream& stream = Stream::Null());
//! computes magnitude of complex (x(i).re, x(i).im) vector //! computes magnitude of complex (x(i).re, x(i).im) vector
//! supports only CV_32FC2 type //! supports only CV_32FC2 type
@@ -1268,9 +1268,9 @@ private:
struct CV_EXPORTS HOGConfidence struct CV_EXPORTS HOGConfidence
{ {
double scale; double scale;
vector<Point> locations; std::vector<Point> locations;
vector<double> confidences; std::vector<double> confidences;
vector<double> part_scores[4]; std::vector<double> part_scores[4];
}; };
struct CV_EXPORTS HOGDescriptor struct CV_EXPORTS HOGDescriptor
@@ -1288,27 +1288,27 @@ struct CV_EXPORTS HOGDescriptor
size_t getDescriptorSize() const; size_t getDescriptorSize() const;
size_t getBlockHistogramSize() const; size_t getBlockHistogramSize() const;
void setSVMDetector(const vector<float>& detector); void setSVMDetector(const std::vector<float>& detector);
static vector<float> getDefaultPeopleDetector(); static std::vector<float> getDefaultPeopleDetector();
static vector<float> getPeopleDetector48x96(); static std::vector<float> getPeopleDetector48x96();
static vector<float> getPeopleDetector64x128(); static std::vector<float> getPeopleDetector64x128();
void detect(const GpuMat& img, vector<Point>& found_locations, void detect(const GpuMat& img, std::vector<Point>& found_locations,
double hit_threshold=0, Size win_stride=Size(), double hit_threshold=0, Size win_stride=Size(),
Size padding=Size()); Size padding=Size());
void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations, void detectMultiScale(const GpuMat& img, std::vector<Rect>& found_locations,
double hit_threshold=0, Size win_stride=Size(), double hit_threshold=0, Size win_stride=Size(),
Size padding=Size(), double scale0=1.05, Size padding=Size(), double scale0=1.05,
int group_threshold=2); int group_threshold=2);
void computeConfidence(const GpuMat& img, vector<Point>& hits, double hit_threshold, void computeConfidence(const GpuMat& img, std::vector<Point>& hits, double hit_threshold,
Size win_stride, Size padding, vector<Point>& locations, vector<double>& confidences); Size win_stride, Size padding, std::vector<Point>& locations, std::vector<double>& confidences);
void computeConfidenceMultiScale(const GpuMat& img, vector<Rect>& found_locations, void computeConfidenceMultiScale(const GpuMat& img, std::vector<Rect>& found_locations,
double hit_threshold, Size win_stride, Size padding, double hit_threshold, Size win_stride, Size padding,
vector<HOGConfidence> &conf_out, int group_threshold); std::vector<HOGConfidence> &conf_out, int group_threshold);
void getDescriptors(const GpuMat& img, Size win_stride, void getDescriptors(const GpuMat& img, Size win_stride,
GpuMat& descriptors, GpuMat& descriptors,
@@ -1838,11 +1838,11 @@ public:
private: private:
GpuMat uPyr_[2]; GpuMat uPyr_[2];
vector<GpuMat> prevPyr_; std::vector<GpuMat> prevPyr_;
vector<GpuMat> nextPyr_; std::vector<GpuMat> nextPyr_;
GpuMat vPyr_[2]; GpuMat vPyr_[2];
vector<GpuMat> buf_; std::vector<GpuMat> buf_;
vector<GpuMat> unused; std::vector<GpuMat> unused;
bool isDeviceArch11_; bool isDeviceArch11_;
}; };
+2 -5
View File
@@ -220,7 +220,7 @@ if(HAVE_AVFOUNDATION)
list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore") list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
else() else()
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation_mac.mm) list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation_mac.mm)
list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa" "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore") list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa" "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore")
endif() endif()
endif() endif()
@@ -241,7 +241,7 @@ endif(HAVE_INTELPERC)
if(IOS) if(IOS)
add_definitions(-DHAVE_IOS=1) add_definitions(-DHAVE_IOS=1)
list(APPEND highgui_srcs src/ios_conversions.mm src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm) list(APPEND highgui_srcs src/ios_conversions.mm src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm)
list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework AssetsLibrary") list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework UIKit")
endif() endif()
if(WIN32) if(WIN32)
@@ -293,9 +293,6 @@ if(MSVC)
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG") set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
endif() endif()
#stop automatic dependencies propagation for this module
set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
ocv_add_precompiled_headers(${the_module}) ocv_add_precompiled_headers(${the_module})
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations -Wno-clobbered) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations -Wno-clobbered)
+2
View File
@@ -208,6 +208,8 @@ int RLByteStream::getByte()
current = m_current; current = m_current;
} }
CV_Assert(current < m_end);
val = *((uchar*)current); val = *((uchar*)current);
m_current = current + 1; m_current = current + 1;
return val; return val;
+13 -6
View File
@@ -48,13 +48,20 @@
namespace cv namespace cv
{ {
enum #define DECLARE_RBS_EXCEPTION(name) \
{ class RBS_ ## name ## _Exception : public cv::Exception \
RBS_THROW_EOS=-123, // <end of stream> exception code { \
RBS_THROW_FORB=-124, // <forrbidden huffman code> exception code public: \
RBS_HUFF_FORB=2047, // forrbidden huffman code "value" RBS_ ## name ## _Exception(int code_, const String& err_, const String& func_, const String& file_, int line_) : \
RBS_BAD_HEADER=-125 // invalid header cv::Exception(code_, err_, func_, file_, line_) \
{} \
}; };
DECLARE_RBS_EXCEPTION(THROW_EOS)
#define RBS_THROW_EOS RBS_THROW_EOS_Exception(CV_StsError, "Unexpected end of input stream", CV_Func, __FILE__, __LINE__)
DECLARE_RBS_EXCEPTION(THROW_FORB)
#define RBS_THROW_FORB RBS_THROW_FORB_Exception(CV_StsError, "Forrbidden huffman code", CV_Func, __FILE__, __LINE__)
DECLARE_RBS_EXCEPTION(BAD_HEADER)
#define RBS_BAD_HEADER RBS_BAD_HEADER_Exception(CV_StsError, "Invalid header", CV_Func, __FILE__, __LINE__)
typedef unsigned long ulong; typedef unsigned long ulong;
+9 -1
View File
@@ -697,7 +697,15 @@ CvCaptureFile::CvCaptureFile(const char* filename) {
return; return;
} }
mAssetTrack = [[mAsset tracksWithMediaType: AVMediaTypeVideo][0] retain]; NSArray *tracks = [mAsset tracksWithMediaType:AVMediaTypeVideo];
if ([tracks count] == 0) {
fprintf(stderr, "OpenCV: Couldn't read video stream from file \"%s\"\n", filename);
[localpool drain];
started = 0;
return;
}
mAssetTrack = [tracks[0] retain];
if ( ! setupReadingAt(kCMTimeZero) ) { if ( ! setupReadingAt(kCMTimeZero) ) {
fprintf(stderr, "OpenCV: Couldn't read movie file \"%s\"\n", filename); fprintf(stderr, "OpenCV: Couldn't read movie file \"%s\"\n", filename);
+1 -1
View File
@@ -129,9 +129,9 @@ extern "C" {
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/time.h> #include <sys/time.h>
#if defined __APPLE__ #if defined __APPLE__
#include <sys/sysctl.h>
#include <mach/clock.h> #include <mach/clock.h>
#include <mach/mach.h> #include <mach/mach.h>
#endif #endif
+2 -6
View File
@@ -31,7 +31,7 @@
#import "opencv2/highgui/cap_ios.h" #import "opencv2/highgui/cap_ios.h"
#include "precomp.hpp" #include "precomp.hpp"
#import <AssetsLibrary/AssetsLibrary.h> #import <UIKit/UIKit.h>
static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;}; static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
@@ -595,11 +595,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
return; return;
} }
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; UISaveVideoAtPathToSavedPhotosAlbum([self videoFileString], nil, nil, NULL);
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:[self videoFileURL]]) {
[library writeVideoAtPathToSavedPhotosAlbum:[self videoFileURL]
completionBlock:^(NSURL *assetURL, NSError *error){ (void)assetURL; (void)error; }];
}
} }
+3 -3
View File
@@ -1164,12 +1164,12 @@ static int read_frame_v4l2(CvCaptureCAM_V4L* capture) {
//printf("got data in buff %d, len=%d, flags=0x%X, seq=%d, used=%d)\n", //printf("got data in buff %d, len=%d, flags=0x%X, seq=%d, used=%d)\n",
// buf.index, buf.length, buf.flags, buf.sequence, buf.bytesused); // buf.index, buf.length, buf.flags, buf.sequence, buf.bytesused);
if (-1 == ioctl (capture->deviceHandle, VIDIOC_QBUF, &buf))
perror ("VIDIOC_QBUF");
//set timestamp in capture struct to be timestamp of most recent frame //set timestamp in capture struct to be timestamp of most recent frame
capture->timestamp = buf.timestamp; capture->timestamp = buf.timestamp;
if (-1 == ioctl (capture->deviceHandle, VIDIOC_QBUF, &buf))
perror ("VIDIOC_QBUF");
return 1; return 1;
} }
+23 -11
View File
@@ -115,8 +115,9 @@ bool BmpDecoder::readHeader()
if( m_bpp <= 8 ) if( m_bpp <= 8 )
{ {
memset( m_palette, 0, sizeof(m_palette)); CV_Assert(clrused <= 256);
m_strm.getBytes( m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 ); memset(m_palette, 0, sizeof(m_palette));
m_strm.getBytes(m_palette, (clrused == 0? 1<<m_bpp : clrused)*4 );
iscolor = IsColorPalette( m_palette, m_bpp ); iscolor = IsColorPalette( m_palette, m_bpp );
} }
else if( m_bpp == 16 && m_rle_code == BMP_BITFIELDS ) else if( m_bpp == 16 && m_rle_code == BMP_BITFIELDS )
@@ -165,6 +166,7 @@ bool BmpDecoder::readHeader()
} }
catch(...) catch(...)
{ {
throw;
} }
m_type = iscolor ? CV_8UC3 : CV_8UC1; m_type = iscolor ? CV_8UC3 : CV_8UC1;
@@ -184,7 +186,7 @@ bool BmpDecoder::readHeader()
bool BmpDecoder::readData( Mat& img ) bool BmpDecoder::readData( Mat& img )
{ {
uchar* data = img.data; uchar* data = img.data;
int step = (int)img.step; int step = validateToInt(img.step);
bool color = img.channels() > 1; bool color = img.channels() > 1;
uchar gray_palette[256]; uchar gray_palette[256];
bool result = false; bool result = false;
@@ -197,7 +199,7 @@ bool BmpDecoder::readData( Mat& img )
if( m_origin == IPL_ORIGIN_BL ) if( m_origin == IPL_ORIGIN_BL )
{ {
data += (m_height - 1)*step; data += (m_height - 1)*(size_t)step;
step = -step; step = -step;
} }
@@ -282,7 +284,9 @@ bool BmpDecoder::readData( Mat& img )
else if( code > 2 ) // absolute mode else if( code > 2 ) // absolute mode
{ {
if( data + code*nch > line_end ) goto decode_rle4_bad; if( data + code*nch > line_end ) goto decode_rle4_bad;
m_strm.getBytes( src, (((code + 1)>>1) + 1) & -2 ); int sz = (((code + 1)>>1) + 1) & (~1);
CV_Assert((size_t)sz < _src.getSize());
m_strm.getBytes(src, sz);
if( color ) if( color )
data = FillColorRow4( data, src, code, m_palette ); data = FillColorRow4( data, src, code, m_palette );
else else
@@ -363,6 +367,9 @@ decode_rle4_bad: ;
gray_palette[code] ); gray_palette[code] );
line_end_flag = y - prev_y; line_end_flag = y - prev_y;
if( y >= m_height )
break;
} }
else if( code > 2 ) // absolute mode else if( code > 2 ) // absolute mode
{ {
@@ -371,7 +378,9 @@ decode_rle4_bad: ;
if( data + code3 > line_end ) if( data + code3 > line_end )
goto decode_rle8_bad; goto decode_rle8_bad;
m_strm.getBytes( src, (code + 1) & -2 ); int sz = (code + 1) & (~1);
CV_Assert((size_t)sz < _src.getSize());
m_strm.getBytes(src, sz);
if( color ) if( color )
data = FillColorRow8( data, src, code, m_palette ); data = FillColorRow8( data, src, code, m_palette );
else else
@@ -464,17 +473,20 @@ decode_rle8_bad: ;
if( !color ) if( !color )
icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, cvSize(m_width,1) ); icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, cvSize(m_width,1) );
else else if( img.channels() == 3 )
icvCvt_BGRA2BGR_8u_C4C3R( src, 0, data, 0, cvSize(m_width,1) ); icvCvt_BGRA2BGR_8u_C4C3R(src, 0, data, 0, cvSize(m_width, 1));
else if( img.channels() == 4 )
memcpy(data, src, m_width * 4);
} }
result = true; result = true;
break; break;
default: default:
assert(0); CV_Error(CV_StsError, "Invalid/unsupported mode");
} }
} }
catch(...) catch(...)
{ {
throw;
} }
return result; return result;
@@ -517,7 +529,7 @@ bool BmpEncoder::write( const Mat& img, const vector<int>& )
int bitmapHeaderSize = 40; int bitmapHeaderSize = 40;
int paletteSize = channels > 1 ? 0 : 1024; int paletteSize = channels > 1 ? 0 : 1024;
int headerSize = 14 /* fileheader */ + bitmapHeaderSize + paletteSize; int headerSize = 14 /* fileheader */ + bitmapHeaderSize + paletteSize;
int fileSize = fileStep*height + headerSize; size_t fileSize = (size_t)fileStep*height + headerSize;
PaletteEntry palette[256]; PaletteEntry palette[256];
if( m_buf ) if( m_buf )
@@ -527,7 +539,7 @@ bool BmpEncoder::write( const Mat& img, const vector<int>& )
strm.putBytes( fmtSignBmp, (int)strlen(fmtSignBmp) ); strm.putBytes( fmtSignBmp, (int)strlen(fmtSignBmp) );
// write file header // write file header
strm.putDWord( fileSize ); // file size strm.putDWord( validateToInt(fileSize) ); // file size
strm.putDWord( 0 ); strm.putDWord( 0 );
strm.putDWord( headerSize ); strm.putDWord( headerSize );
+5 -5
View File
@@ -188,7 +188,7 @@ bool ExrDecoder::readData( Mat& img )
bool color = img.channels() > 1; bool color = img.channels() > 1;
uchar* data = img.data; uchar* data = img.data;
int step = img.step; size_t step = img.step;
bool justcopy = m_native_depth; bool justcopy = m_native_depth;
bool chromatorgb = false; bool chromatorgb = false;
bool rgbtogray = false; bool rgbtogray = false;
@@ -196,8 +196,8 @@ bool ExrDecoder::readData( Mat& img )
FrameBuffer frame; FrameBuffer frame;
int xsample[3] = {1, 1, 1}; int xsample[3] = {1, 1, 1};
char *buffer; char *buffer;
int xstep; size_t xstep = 0;
int ystep; size_t ystep = 0;
xstep = m_native_depth ? 4 : 1; xstep = m_native_depth ? 4 : 1;
@@ -589,7 +589,7 @@ bool ExrEncoder::write( const Mat& img, const vector<int>& )
bool isfloat = depth == CV_32F || depth == CV_64F; bool isfloat = depth == CV_32F || depth == CV_64F;
depth = CV_ELEM_SIZE1(depth)*8; depth = CV_ELEM_SIZE1(depth)*8;
uchar* data = img.data; uchar* data = img.data;
int step = img.step; size_t step = img.step;
Header header( width, height ); Header header( width, height );
Imf::PixelType type; Imf::PixelType type;
@@ -619,7 +619,7 @@ bool ExrEncoder::write( const Mat& img, const vector<int>& )
FrameBuffer frame; FrameBuffer frame;
char *buffer; char *buffer;
int bufferstep; size_t bufferstep;
int size; int size;
if( type == FLOAT && depth == 32 ) if( type == FLOAT && depth == 32 )
{ {
+1 -1
View File
@@ -392,7 +392,7 @@ int my_jpeg_load_dht (struct jpeg_decompress_struct *info, unsigned char *dht,
bool JpegDecoder::readData( Mat& img ) bool JpegDecoder::readData( Mat& img )
{ {
bool result = false; bool result = false;
int step = (int)img.step; size_t step = img.step;
bool color = img.channels() > 1; bool color = img.channels() > 1;
if( m_state && m_width && m_height ) if( m_state && m_width && m_height )
+3 -3
View File
@@ -156,7 +156,7 @@ bool Jpeg2KDecoder::readData( Mat& img )
bool result = false; bool result = false;
int color = img.channels() > 1; int color = img.channels() > 1;
uchar* data = img.data; uchar* data = img.data;
int step = (int)img.step; size_t step = img.step;
jas_stream_t* stream = (jas_stream_t*)m_stream; jas_stream_t* stream = (jas_stream_t*)m_stream;
jas_image_t* image = (jas_image_t*)m_image; jas_image_t* image = (jas_image_t*)m_image;
@@ -252,9 +252,9 @@ bool Jpeg2KDecoder::readData( Mat& img )
if( !jas_image_readcmpt( image, cmptlut[i], 0, 0, xend / xstep, yend / ystep, buffer )) if( !jas_image_readcmpt( image, cmptlut[i], 0, 0, xend / xstep, yend / ystep, buffer ))
{ {
if( img.depth() == CV_8U ) if( img.depth() == CV_8U )
result = readComponent8u( data + i, buffer, step, cmptlut[i], maxval, offset, ncmpts ); result = readComponent8u( data + i, buffer, validateToInt(step), cmptlut[i], maxval, offset, ncmpts );
else else
result = readComponent16u( ((unsigned short *)data) + i, buffer, step / 2, cmptlut[i], maxval, offset, ncmpts ); result = readComponent16u( ((unsigned short *)data) + i, buffer, validateToInt(step / 2), cmptlut[i], maxval, offset, ncmpts );
if( !result ) if( !result )
{ {
i = ncmpts; i = ncmpts;
+74 -45
View File
@@ -43,50 +43,58 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "utils.hpp" #include "utils.hpp"
#include "grfmt_pxm.hpp" #include "grfmt_pxm.hpp"
#include <iostream>
namespace cv namespace cv
{ {
///////////////////////// P?M reader ////////////////////////////// ///////////////////////// P?M reader //////////////////////////////
static int ReadNumber( RLByteStream& strm, int maxdigits ) static int ReadNumber(RLByteStream& strm, int maxdigits = 0)
{ {
int code; int code;
int val = 0; int64 val = 0;
int digits = 0; int digits = 0;
code = strm.getByte(); code = strm.getByte();
if( !isdigit(code)) while (!isdigit(code))
{ {
do if (code == '#' )
{ {
if( code == '#' ) do
{ {
do code = strm.getByte();
{
code = strm.getByte();
}
while( code != '\n' && code != '\r' );
} }
while (code != '\n' && code != '\r');
code = strm.getByte(); code = strm.getByte();
}
while( isspace(code)) else if (isspace(code))
{
while (isspace(code))
code = strm.getByte(); code = strm.getByte();
} }
while( !isdigit( code )); else
{
#if 1
CV_Error_(CV_StsError, ("PXM: Unexpected code in ReadNumber(): 0x%x (%d)", code, code));
#else
code = strm.getByte();
#endif
}
} }
do do
{ {
val = val*10 + code - '0'; val = val*10 + (code - '0');
if( ++digits >= maxdigits ) break; CV_Assert(val <= INT_MAX && "PXM: ReadNumber(): result is too large");
digits++;
if (maxdigits != 0 && digits >= maxdigits) break;
code = strm.getByte(); code = strm.getByte();
} }
while( isdigit(code)); while (isdigit(code));
return val; return (int)val;
} }
@@ -119,13 +127,13 @@ ImageDecoder PxMDecoder::newDecoder() const
return new PxMDecoder; return new PxMDecoder;
} }
void PxMDecoder::close() void PxMDecoder::close()
{ {
m_strm.close(); m_strm.close();
} }
bool PxMDecoder::readHeader() bool PxMDecoder::readHeader()
{ {
bool result = false; bool result = false;
@@ -155,10 +163,10 @@ bool PxMDecoder::readHeader()
m_binary = code >= '4'; m_binary = code >= '4';
m_type = m_bpp > 8 ? CV_8UC3 : CV_8UC1; m_type = m_bpp > 8 ? CV_8UC3 : CV_8UC1;
m_width = ReadNumber( m_strm, INT_MAX ); m_width = ReadNumber(m_strm);
m_height = ReadNumber( m_strm, INT_MAX ); m_height = ReadNumber(m_strm);
m_maxval = m_bpp == 1 ? 1 : ReadNumber( m_strm, INT_MAX ); m_maxval = m_bpp == 1 ? 1 : ReadNumber(m_strm);
if( m_maxval > 65535 ) if( m_maxval > 65535 )
throw RBS_BAD_HEADER; throw RBS_BAD_HEADER;
@@ -172,8 +180,14 @@ bool PxMDecoder::readHeader()
result = true; result = true;
} }
} }
catch(...) catch (const cv::Exception&)
{ {
throw;
}
catch (...)
{
std::cerr << "PXM::readHeader(): unknown C++ exception" << std::endl << std::flush;
throw;
} }
if( !result ) if( !result )
@@ -193,27 +207,23 @@ bool PxMDecoder::readData( Mat& img )
int step = (int)img.step; int step = (int)img.step;
PaletteEntry palette[256]; PaletteEntry palette[256];
bool result = false; bool result = false;
int bit_depth = CV_ELEM_SIZE1(m_type)*8; const int bit_depth = CV_ELEM_SIZE1(m_type)*8;
int src_pitch = (m_width*m_bpp*bit_depth/8 + 7)/8; const int src_pitch = (m_width*m_bpp*(bit_depth/8) + 7) / 8;
int nch = CV_MAT_CN(m_type); int nch = CV_MAT_CN(m_type);
int width3 = m_width*nch; int width3 = m_width*nch;
int i, x, y;
if( m_offset < 0 || !m_strm.isOpened()) if( m_offset < 0 || !m_strm.isOpened())
return false; return false;
AutoBuffer<uchar,1024> _src(src_pitch + 32); uchar gray_palette[256] = {0};
uchar* src = _src;
AutoBuffer<uchar,1024> _gray_palette;
uchar* gray_palette = _gray_palette;
// create LUT for converting colors // create LUT for converting colors
if( bit_depth == 8 ) if( bit_depth == 8 )
{ {
_gray_palette.allocate(m_maxval + 1); CV_Assert(m_maxval < 256);
gray_palette = _gray_palette;
for( i = 0; i <= m_maxval; i++ ) for (int i = 0; i <= m_maxval; i++)
gray_palette[i] = (uchar)((i*255/m_maxval)^(m_bpp == 1 ? 255 : 0)); gray_palette[i] = (uchar)((i*255/m_maxval)^(m_bpp == 1 ? 255 : 0));
FillGrayPalette( palette, m_bpp==1 ? 1 : 8 , m_bpp == 1 ); FillGrayPalette( palette, m_bpp==1 ? 1 : 8 , m_bpp == 1 );
@@ -227,12 +237,16 @@ bool PxMDecoder::readData( Mat& img )
{ {
////////////////////////// 1 BPP ///////////////////////// ////////////////////////// 1 BPP /////////////////////////
case 1: case 1:
CV_Assert(CV_MAT_DEPTH(m_type) == CV_8U);
if( !m_binary ) if( !m_binary )
{ {
for( y = 0; y < m_height; y++, data += step ) AutoBuffer<uchar> _src(m_width);
uchar* src = _src;
for (int y = 0; y < m_height; y++, data += step)
{ {
for( x = 0; x < m_width; x++ ) for (int x = 0; x < m_width; x++)
src[x] = ReadNumber( m_strm, 1 ) != 0; src[x] = ReadNumber(m_strm, 1) != 0;
if( color ) if( color )
FillColorRow8( data, src, m_width, palette ); FillColorRow8( data, src, m_width, palette );
@@ -242,7 +256,10 @@ bool PxMDecoder::readData( Mat& img )
} }
else else
{ {
for( y = 0; y < m_height; y++, data += step ) AutoBuffer<uchar> _src(src_pitch);
uchar* src = _src;
for (int y = 0; y < m_height; y++, data += step)
{ {
m_strm.getBytes( src, src_pitch ); m_strm.getBytes( src, src_pitch );
@@ -258,11 +275,15 @@ bool PxMDecoder::readData( Mat& img )
////////////////////////// 8 BPP ///////////////////////// ////////////////////////// 8 BPP /////////////////////////
case 8: case 8:
case 24: case 24:
for( y = 0; y < m_height; y++, data += step ) {
AutoBuffer<uchar> _src(std::max<size_t>(width3*2, src_pitch));
uchar* src = _src;
for (int y = 0; y < m_height; y++, data += step)
{ {
if( !m_binary ) if( !m_binary )
{ {
for( x = 0; x < width3; x++ ) for (int x = 0; x < width3; x++)
{ {
int code = ReadNumber( m_strm, INT_MAX ); int code = ReadNumber( m_strm, INT_MAX );
if( (unsigned)code > (unsigned)m_maxval ) code = m_maxval; if( (unsigned)code > (unsigned)m_maxval ) code = m_maxval;
@@ -277,7 +298,7 @@ bool PxMDecoder::readData( Mat& img )
m_strm.getBytes( src, src_pitch ); m_strm.getBytes( src, src_pitch );
if( bit_depth == 16 && !isBigEndian() ) if( bit_depth == 16 && !isBigEndian() )
{ {
for( x = 0; x < width3; x++ ) for (int x = 0; x < width3; x++)
{ {
uchar v = src[x * 2]; uchar v = src[x * 2];
src[x * 2] = src[x * 2 + 1]; src[x * 2] = src[x * 2 + 1];
@@ -288,7 +309,7 @@ bool PxMDecoder::readData( Mat& img )
if( img.depth() == CV_8U && bit_depth == 16 ) if( img.depth() == CV_8U && bit_depth == 16 )
{ {
for( x = 0; x < width3; x++ ) for (int x = 0; x < width3; x++)
{ {
int v = ((ushort *)src)[x]; int v = ((ushort *)src)[x];
src[x] = (uchar)(v >> 8); src[x] = (uchar)(v >> 8);
@@ -329,12 +350,19 @@ bool PxMDecoder::readData( Mat& img )
} }
result = true; result = true;
break; break;
}
default: default:
assert(0); CV_Error(CV_StsError, "m_bpp is not supported");
} }
} }
catch(...) catch (const cv::Exception&)
{ {
throw;
}
catch (...)
{
std::cerr << "PXM::readData(): unknown exception" << std::endl << std::flush;
throw;
} }
return result; return result;
@@ -410,8 +438,9 @@ bool PxMEncoder::write( const Mat& img, const vector<int>& params )
char* buffer = _buffer; char* buffer = _buffer;
// write header; // write header;
sprintf( buffer, "P%c\n%d %d\n%d\n", sprintf( buffer, "P%c\n# Generated by OpenCV %s\n%d %d\n%d\n",
'2' + (channels > 1 ? 1 : 0) + (isBinary ? 3 : 0), '2' + (channels > 1 ? 1 : 0) + (isBinary ? 3 : 0),
CV_VERSION,
width, height, (1 << depth) - 1 ); width, height, (1 << depth) - 1 );
strm.putBytes( buffer, (int)strlen(buffer) ); strm.putBytes( buffer, (int)strlen(buffer) );
+3 -3
View File
@@ -156,7 +156,7 @@ bool SunRasterDecoder::readData( Mat& img )
{ {
int color = img.channels() > 1; int color = img.channels() > 1;
uchar* data = img.data; uchar* data = img.data;
int step = (int)img.step; size_t step = img.step;
uchar gray_palette[256]; uchar gray_palette[256];
bool result = false; bool result = false;
int src_pitch = ((m_width*m_bpp + 7)/8 + 1) & -2; int src_pitch = ((m_width*m_bpp + 7)/8 + 1) & -2;
@@ -304,11 +304,11 @@ bad_decoding_1bpp:
code = m_strm.getByte(); code = m_strm.getByte();
if( color ) if( color )
data = FillUniColor( data, line_end, step, width3, data = FillUniColor( data, line_end, validateToInt(step), width3,
y, m_height, len, y, m_height, len,
m_palette[code] ); m_palette[code] );
else else
data = FillUniGray( data, line_end, step, width3, data = FillUniGray( data, line_end, validateToInt(step), width3,
y, m_height, len, y, m_height, len,
gray_palette[code] ); gray_palette[code] );
if( y >= m_height ) if( y >= m_height )
+104 -18
View File
@@ -48,12 +48,32 @@
#undef min #undef min
#undef max #undef max
#include <iostream>
/****************************************************************************************\ /****************************************************************************************\
* Image Codecs * * Image Codecs *
\****************************************************************************************/ \****************************************************************************************/
namespace cv namespace cv
{ {
// TODO Add runtime configuration
#define CV_IO_MAX_IMAGE_PARAMS (50)
#define CV_IO_MAX_IMAGE_WIDTH (1<<20)
#define CV_IO_MAX_IMAGE_HEIGHT (1<<20)
#define CV_IO_MAX_IMAGE_PIXELS (1<<30) // 1 Gigapixel
static Size validateInputImageSize(const Size& size)
{
CV_Assert(size.width > 0);
CV_Assert(size.width <= CV_IO_MAX_IMAGE_WIDTH);
CV_Assert(size.height > 0);
CV_Assert(size.height <= CV_IO_MAX_IMAGE_HEIGHT);
uint64 pixels = (uint64)size.width * (uint64)size.height;
CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS);
return size;
}
struct ImageCodecInitializer struct ImageCodecInitializer
{ {
ImageCodecInitializer() ImageCodecInitializer()
@@ -203,12 +223,26 @@ imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
if( decoder.empty() ) if( decoder.empty() )
return 0; return 0;
decoder->setSource(filename); decoder->setSource(filename);
if( !decoder->readHeader() )
return 0;
CvSize size; try
size.width = decoder->width(); {
size.height = decoder->height(); // read the header to make sure it succeeds
if (!decoder->readHeader())
return 0;
}
catch (const cv::Exception& e)
{
std::cerr << "imread_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush;
return 0;
}
catch (...)
{
std::cerr << "imread_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush;
return 0;
}
Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
int type = decoder->type(); int type = decoder->type();
if( flags != -1 ) if( flags != -1 )
@@ -242,7 +276,21 @@ imread_( const string& filename, int flags, int hdrtype, Mat* mat=0 )
temp = cvarrToMat(image); temp = cvarrToMat(image);
} }
if( !decoder->readData( *data )) bool success = false;
try
{
if (decoder->readData(*data))
success = true;
}
catch (const cv::Exception& e)
{
std::cerr << "imread_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush;
}
catch (...)
{
std::cerr << "imread_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush;
}
if (!success)
{ {
cvReleaseImage( &image ); cvReleaseImage( &image );
cvReleaseMat( &matrix ); cvReleaseMat( &matrix );
@@ -288,6 +336,7 @@ static bool imwrite_( const string& filename, const Mat& image,
} }
encoder->setDestination( filename ); encoder->setDestination( filename );
CV_Assert(params.size() <= CV_IO_MAX_IMAGE_PARAMS*2);
bool code = encoder->write( *pimage, params ); bool code = encoder->write( *pimage, params );
// CV_Assert( code ); // CV_Assert( code );
@@ -326,16 +375,34 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
decoder->setSource(filename); decoder->setSource(filename);
} }
if( !decoder->readHeader() ) bool success = false;
try
{ {
if( !filename.empty() ) if (decoder->readHeader())
remove(filename.c_str()); success = true;
}
catch (const cv::Exception& e)
{
std::cerr << "imdecode_('" << filename << "'): can't read header: " << e.what() << std::endl << std::flush;
}
catch (...)
{
std::cerr << "imdecode_('" << filename << "'): can't read header: unknown exception" << std::endl << std::flush;
}
if (!success)
{
if (!filename.empty())
{
if (0 != remove(filename.c_str()))
{
std::cerr << "unable to remove temporary file:" << filename << std::endl << std::flush;
}
}
return 0; return 0;
} }
CvSize size; // established the required input image size
size.width = decoder->width(); Size size = validateInputImageSize(Size(decoder->width(), decoder->height()));
size.height = decoder->height();
int type = decoder->type(); int type = decoder->type();
if( flags != -1 ) if( flags != -1 )
@@ -369,11 +436,30 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
temp = cvarrToMat(image); temp = cvarrToMat(image);
} }
bool code = decoder->readData( *data ); success = false;
if( !filename.empty() ) try
remove(filename.c_str()); {
if (decoder->readData(*data))
success = true;
}
catch (const cv::Exception& e)
{
std::cerr << "imdecode_('" << filename << "'): can't read data: " << e.what() << std::endl << std::flush;
}
catch (...)
{
std::cerr << "imdecode_('" << filename << "'): can't read data: unknown exception" << std::endl << std::flush;
}
if( !code ) if (!filename.empty())
{
if (0 != remove(filename.c_str()))
{
std::cerr << "unable to remove temporary file:" << filename << std::endl << std::flush;
}
}
if (!success)
{ {
cvReleaseImage( &image ); cvReleaseImage( &image );
cvReleaseMat( &matrix ); cvReleaseMat( &matrix );
@@ -490,7 +576,7 @@ cvSaveImage( const char* filename, const CvArr* arr, const int* _params )
if( _params ) if( _params )
{ {
for( ; _params[i] > 0; i += 2 ) for( ; _params[i] > 0; i += 2 )
; CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
} }
return cv::imwrite_(filename, cv::cvarrToMat(arr), return cv::imwrite_(filename, cv::cvarrToMat(arr),
i > 0 ? cv::vector<int>(_params, _params+i) : cv::vector<int>(), i > 0 ? cv::vector<int>(_params, _params+i) : cv::vector<int>(),
@@ -521,7 +607,7 @@ cvEncodeImage( const char* ext, const CvArr* arr, const int* _params )
if( _params ) if( _params )
{ {
for( ; _params[i] > 0; i += 2 ) for( ; _params[i] > 0; i += 2 )
; CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
} }
cv::Mat img = cv::cvarrToMat(arr); cv::Mat img = cv::cvarrToMat(arr);
if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL ) if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL )
+31 -20
View File
@@ -42,6 +42,13 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "utils.hpp" #include "utils.hpp"
int validateToInt(size_t sz)
{
int valueInt = (int)sz;
CV_Assert((size_t)valueInt == sz);
return valueInt;
}
#define SCALE 14 #define SCALE 14
#define cR (int)(0.299*(1 << SCALE) + 0.5) #define cR (int)(0.299*(1 << SCALE) + 0.5)
#define cG (int)(0.587*(1 << SCALE) + 0.5) #define cG (int)(0.587*(1 << SCALE) + 0.5)
@@ -537,23 +544,25 @@ uchar* FillColorRow1( uchar* data, uchar* indices, int len, PaletteEntry* palett
{ {
uchar* end = data + len*3; uchar* end = data + len*3;
const PaletteEntry p0 = palette[0], p1 = palette[1];
while( (data += 24) < end ) while( (data += 24) < end )
{ {
int idx = *indices++; int idx = *indices++;
*((PaletteEntry*)(data - 24)) = palette[(idx & 128) != 0]; *((PaletteEntry*)(data - 24)) = (idx & 128) ? p1 : p0;
*((PaletteEntry*)(data - 21)) = palette[(idx & 64) != 0]; *((PaletteEntry*)(data - 21)) = (idx & 64) ? p1 : p0;
*((PaletteEntry*)(data - 18)) = palette[(idx & 32) != 0]; *((PaletteEntry*)(data - 18)) = (idx & 32) ? p1 : p0;
*((PaletteEntry*)(data - 15)) = palette[(idx & 16) != 0]; *((PaletteEntry*)(data - 15)) = (idx & 16) ? p1 : p0;
*((PaletteEntry*)(data - 12)) = palette[(idx & 8) != 0]; *((PaletteEntry*)(data - 12)) = (idx & 8) ? p1 : p0;
*((PaletteEntry*)(data - 9)) = palette[(idx & 4) != 0]; *((PaletteEntry*)(data - 9)) = (idx & 4) ? p1 : p0;
*((PaletteEntry*)(data - 6)) = palette[(idx & 2) != 0]; *((PaletteEntry*)(data - 6)) = (idx & 2) ? p1 : p0;
*((PaletteEntry*)(data - 3)) = palette[(idx & 1) != 0]; *((PaletteEntry*)(data - 3)) = (idx & 1) ? p1 : p0;
} }
int idx = indices[0] << 24; int idx = indices[0];
for( data -= 24; data < end; data += 3, idx += idx ) for( data -= 24; data < end; data += 3, idx += idx )
{ {
PaletteEntry clr = palette[idx < 0]; const PaletteEntry clr = (idx & 128) ? p1 : p0;
WRITE_PIX( data, clr ); WRITE_PIX( data, clr );
} }
@@ -565,23 +574,25 @@ uchar* FillGrayRow1( uchar* data, uchar* indices, int len, uchar* palette )
{ {
uchar* end = data + len; uchar* end = data + len;
const uchar p0 = palette[0], p1 = palette[1];
while( (data += 8) < end ) while( (data += 8) < end )
{ {
int idx = *indices++; int idx = *indices++;
*((uchar*)(data - 8)) = palette[(idx & 128) != 0]; *((uchar*)(data - 8)) = (idx & 128) ? p1 : p0;
*((uchar*)(data - 7)) = palette[(idx & 64) != 0]; *((uchar*)(data - 7)) = (idx & 64) ? p1 : p0;
*((uchar*)(data - 6)) = palette[(idx & 32) != 0]; *((uchar*)(data - 6)) = (idx & 32) ? p1 : p0;
*((uchar*)(data - 5)) = palette[(idx & 16) != 0]; *((uchar*)(data - 5)) = (idx & 16) ? p1 : p0;
*((uchar*)(data - 4)) = palette[(idx & 8) != 0]; *((uchar*)(data - 4)) = (idx & 8) ? p1 : p0;
*((uchar*)(data - 3)) = palette[(idx & 4) != 0]; *((uchar*)(data - 3)) = (idx & 4) ? p1 : p0;
*((uchar*)(data - 2)) = palette[(idx & 2) != 0]; *((uchar*)(data - 2)) = (idx & 2) ? p1 : p0;
*((uchar*)(data - 1)) = palette[(idx & 1) != 0]; *((uchar*)(data - 1)) = (idx & 1) ? p1 : p0;
} }
int idx = indices[0] << 24; int idx = indices[0];
for( data -= 8; data < end; data++, idx += idx ) for( data -= 8; data < end; data++, idx += idx )
{ {
data[0] = palette[idx < 0]; data[0] = (idx & 128) ? p1 : p0;
} }
return data; return data;
+2
View File
@@ -42,6 +42,8 @@
#ifndef _UTILS_H_ #ifndef _UTILS_H_
#define _UTILS_H_ #define _UTILS_H_
int validateToInt(size_t step);
struct PaletteEntry struct PaletteEntry
{ {
unsigned char b, g, r, a; unsigned char b, g, r, a;
+134
View File
@@ -409,9 +409,143 @@ int CV_DrawingTest_C::checkLineIterator( Mat& _img )
return 0; return 0;
} }
class CV_DrawingTest_Far : public CV_DrawingTest_CPP
{
public:
CV_DrawingTest_Far() {}
protected:
virtual void draw(Mat& img);
};
void CV_DrawingTest_Far::draw(Mat& img)
{
Size imgSize(32768 + 600, 400);
img.create(imgSize, CV_8UC3);
vector<Point> polyline(4);
polyline[0] = Point(32768 + 0, 0);
polyline[1] = Point(imgSize.width, 0);
polyline[2] = Point(imgSize.width, imgSize.height);
polyline[3] = Point(32768 + 0, imgSize.height);
const Point* pts = &polyline[0];
int n = (int)polyline.size();
fillPoly(img, &pts, &n, 1, Scalar::all(255));
Point p1(32768 + 1, 1), p2(32768 + 3, 3);
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
circle(img, Point(32768 + 300, 100), 40, Scalar(0, 0, 255), 3); // draw
p2 = Point(32768 + 3, imgSize.height + 1000);
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
circle(img, Point(65536 + 500, 300), 50, cvColorToScalar(255, CV_8UC3), 5, 8, 1); // draw
p1 = Point(imgSize.width, 1), p2 = Point(imgSize.width, 3);
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
circle(img, Point(32768 + 390, 100), 10, Scalar(0, 0, 255), 3); // not draw
p1 = Point(imgSize.width - 1, 1), p2 = Point(imgSize.width, 3);
if (clipLine(Rect(32768 + 0, 0, imgSize.width, imgSize.height), p1, p2) && clipLine(imgSize, p1, p2))
ellipse(img, Point(32768 + 390, 100), Size(20, 30), 60, 0, 220.0, Scalar(0, 200, 0), 4); //draw
ellipse(img, RotatedRect(Point(32768 + 100, 200), Size(200, 100), 160), Scalar(200, 200, 255), 5);
polyline.clear();
ellipse2Poly(Point(32768 + 430, 180), Size(100, 150), 30, 0, 150, 20, polyline);
pts = &polyline[0];
n = (int)polyline.size();
polylines(img, &pts, &n, 1, false, Scalar(0, 0, 150), 4, CV_AA);
n = 0;
for (vector<Point>::const_iterator it = polyline.begin(); n < (int)polyline.size() - 1; ++it, n++)
{
line(img, *it, *(it + 1), Scalar(50, 250, 100));
}
polyline.clear();
ellipse2Poly(Point(32768 + 500, 300), Size(50, 80), 0, 0, 180, 10, polyline);
pts = &polyline[0];
n = (int)polyline.size();
polylines(img, &pts, &n, 1, true, Scalar(100, 200, 100), 20);
fillConvexPoly(img, pts, n, Scalar(0, 80, 0));
polyline.resize(8);
// external rectengular
polyline[0] = Point(32768 + 0, 0);
polyline[1] = Point(32768 + 80, 0);
polyline[2] = Point(32768 + 80, 80);
polyline[3] = Point(32768 + 0, 80);
// internal rectangular
polyline[4] = Point(32768 + 20, 20);
polyline[5] = Point(32768 + 60, 20);
polyline[6] = Point(32768 + 60, 60);
polyline[7] = Point(32768 + 20, 60);
const Point* ppts[] = { &polyline[0], &polyline[0] + 4 };
int pn[] = { 4, 4 };
fillPoly(img, ppts, pn, 2, Scalar(100, 100, 0), 8, 0, Point(500, 20));
rectangle(img, Point(32768 + 0, 300), Point(32768 + 50, 398), Scalar(0, 0, 255));
string text1 = "OpenCV";
int baseline = 0, thickness = 3, fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
float fontScale = 2;
Size textSize = getTextSize(text1, fontFace, fontScale, thickness, &baseline);
baseline += thickness;
Point textOrg((32768 + img.cols - textSize.width) / 2, (img.rows + textSize.height) / 2);
rectangle(img, textOrg + Point(0, baseline), textOrg + Point(textSize.width, -textSize.height), Scalar(0, 0, 255));
line(img, textOrg + Point(0, thickness), textOrg + Point(textSize.width, thickness), Scalar(0, 0, 255));
putText(img, text1, textOrg, fontFace, fontScale, Scalar(150, 0, 150), thickness, 8);
string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
Scalar color(200, 0, 0);
fontScale = 0.5, thickness = 1;
int dist = 5;
textSize = getTextSize(text2, FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
textOrg = Point(32768 + 5, 5) + Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_SIMPLEX, fontScale, color, thickness, CV_AA);
fontScale = 1;
textSize = getTextSize(text2, FONT_HERSHEY_PLAIN, fontScale, thickness, &baseline);
textOrg += Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_PLAIN, fontScale, color, thickness, CV_AA);
fontScale = 0.5;
textSize = getTextSize(text2, FONT_HERSHEY_DUPLEX, fontScale, thickness, &baseline);
textOrg += Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_DUPLEX, fontScale, color, thickness, CV_AA);
textSize = getTextSize(text2, FONT_HERSHEY_COMPLEX, fontScale, thickness, &baseline);
textOrg += Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX, fontScale, color, thickness, CV_AA);
textSize = getTextSize(text2, FONT_HERSHEY_TRIPLEX, fontScale, thickness, &baseline);
textOrg += Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_TRIPLEX, fontScale, color, thickness, CV_AA);
fontScale = 1;
textSize = getTextSize(text2, FONT_HERSHEY_COMPLEX_SMALL, fontScale, thickness, &baseline);
textOrg += Point(0, 180) + Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_COMPLEX_SMALL, fontScale, color, thickness, CV_AA);
textSize = getTextSize(text2, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, &baseline);
textOrg += Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, color, thickness, CV_AA);
textSize = getTextSize(text2, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, thickness, &baseline);
textOrg += Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_HERSHEY_SCRIPT_COMPLEX, fontScale, color, thickness, CV_AA);
dist = 15, fontScale = 0.5;
textSize = getTextSize(text2, FONT_ITALIC, fontScale, thickness, &baseline);
textOrg += Point(0, textSize.height + dist);
putText(img, text2, textOrg, FONT_ITALIC, fontScale, color, thickness, CV_AA);
img = img(Rect(32768, 0, 600, 400)).clone();
}
#ifdef HAVE_JPEG #ifdef HAVE_JPEG
TEST(Highgui_Drawing, cpp_regression) { CV_DrawingTest_CPP test; test.safe_run(); } TEST(Highgui_Drawing, cpp_regression) { CV_DrawingTest_CPP test; test.safe_run(); }
TEST(Highgui_Drawing, c_regression) { CV_DrawingTest_C test; test.safe_run(); } TEST(Highgui_Drawing, c_regression) { CV_DrawingTest_C test; test.safe_run(); }
TEST(Highgui_Drawing, far_regression) { CV_DrawingTest_Far test; test.safe_run(); }
#endif #endif
class CV_FillConvexPolyTest : public cvtest::BaseTest class CV_FillConvexPolyTest : public cvtest::BaseTest
+81 -43
View File
@@ -102,6 +102,38 @@ static IppStatus sts = ippInit();
namespace cv namespace cv
{ {
//constants for conversion from/to RGB and Gray, YUV, YCrCb according to BT.601
const float B2YF = 0.114f;
const float G2YF = 0.587f;
const float R2YF = 0.299f;
//to YCbCr
const float YCBF = 0.564f; // == 1/2/(1-B2YF)
const float YCRF = 0.713f; // == 1/2/(1-R2YF)
const int YCBI = 9241; // == YCBF*16384
const int YCRI = 11682; // == YCRF*16384
//to YUV
const float B2UF = 0.492f;
const float R2VF = 0.877f;
const int B2UI = 8061; // == B2UF*16384
const int R2VI = 14369; // == R2VF*16384
//from YUV
const float U2BF = 2.032f;
const float U2GF = -0.395f;
const float V2GF = -0.581f;
const float V2RF = 1.140f;
const int U2BI = 33292;
const int U2GI = -6472;
const int V2GI = -9519;
const int V2RI = 18678;
//from YCrCb
const float CR2RF = 1.403f;
const float CB2GF = -0.344f;
const float CR2GF = -0.714f;
const float CB2BF = 1.773f;
const int CR2RI = 22987;
const int CB2GI = -5636;
const int CR2GI = -11698;
const int CB2BI = 29049;
// computes cubic spline coefficients for a function: (xi=i, yi=f[i]), i=0..n // computes cubic spline coefficients for a function: (xi=i, yi=f[i]), i=0..n
template<typename _Tp> static void splineBuild(const _Tp* f, int n, _Tp* tab) template<typename _Tp> static void splineBuild(const _Tp* f, int n, _Tp* tab)
@@ -402,9 +434,9 @@ struct IPPColor2GrayFunctor
{ {
IPPColor2GrayFunctor(ippiColor2GrayFunc _func) : func(_func) IPPColor2GrayFunctor(ippiColor2GrayFunc _func) : func(_func)
{ {
coeffs[0] = 0.114f; coeffs[0] = B2YF;
coeffs[1] = 0.587f; coeffs[1] = G2YF;
coeffs[2] = 0.299f; coeffs[2] = R2YF;
} }
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{ {
@@ -668,9 +700,9 @@ enum
{ {
yuv_shift = 14, yuv_shift = 14,
xyz_shift = 12, xyz_shift = 12,
R2Y = 4899, R2Y = 4899, // B2YF*16384
G2Y = 9617, G2Y = 9617, // G2YF*16384
B2Y = 1868, B2Y = 1868, // B2YF*16384
BLOCK_SIZE = 256 BLOCK_SIZE = 256
}; };
@@ -709,7 +741,7 @@ template<typename _Tp> struct RGB2Gray
RGB2Gray(int _srccn, int blueIdx, const float* _coeffs) : srccn(_srccn) RGB2Gray(int _srccn, int blueIdx, const float* _coeffs) : srccn(_srccn)
{ {
static const float coeffs0[] = { 0.299f, 0.587f, 0.114f }; static const float coeffs0[] = { R2YF, G2YF, B2YF };
memcpy( coeffs, _coeffs ? _coeffs : coeffs0, 3*sizeof(coeffs[0]) ); memcpy( coeffs, _coeffs ? _coeffs : coeffs0, 3*sizeof(coeffs[0]) );
if(blueIdx == 0) if(blueIdx == 0)
std::swap(coeffs[0], coeffs[2]); std::swap(coeffs[0], coeffs[2]);
@@ -787,16 +819,18 @@ template<typename _Tp> struct RGB2YCrCb_f
{ {
typedef _Tp channel_type; typedef _Tp channel_type;
RGB2YCrCb_f(int _srccn, int _blueIdx, const float* _coeffs) : srccn(_srccn), blueIdx(_blueIdx) RGB2YCrCb_f(int _srccn, int _blueIdx, bool _isCrCb) : srccn(_srccn), blueIdx(_blueIdx), isCrCb(_isCrCb)
{ {
static const float coeffs0[] = {0.299f, 0.587f, 0.114f, 0.713f, 0.564f}; static const float coeffs_crb[] = { R2YF, G2YF, B2YF, YCRF, YCBF };
memcpy(coeffs, _coeffs ? _coeffs : coeffs0, 5*sizeof(coeffs[0])); static const float coeffs_yuv[] = { R2YF, G2YF, B2YF, R2VF, B2UF };
memcpy(coeffs, isCrCb ? coeffs_crb : coeffs_yuv, 5*sizeof(coeffs[0]));
if(blueIdx==0) std::swap(coeffs[0], coeffs[2]); if(blueIdx==0) std::swap(coeffs[0], coeffs[2]);
} }
void operator()(const _Tp* src, _Tp* dst, int n) const void operator()(const _Tp* src, _Tp* dst, int n) const
{ {
int scn = srccn, bidx = blueIdx; int scn = srccn, bidx = blueIdx;
int yuvOrder = !isCrCb; //1 if YUV, 0 if YCrCb
const _Tp delta = ColorChannel<_Tp>::half(); const _Tp delta = ColorChannel<_Tp>::half();
float C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3], C4 = coeffs[4]; float C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3], C4 = coeffs[4];
n *= 3; n *= 3;
@@ -805,10 +839,11 @@ template<typename _Tp> struct RGB2YCrCb_f
_Tp Y = saturate_cast<_Tp>(src[0]*C0 + src[1]*C1 + src[2]*C2); _Tp Y = saturate_cast<_Tp>(src[0]*C0 + src[1]*C1 + src[2]*C2);
_Tp Cr = saturate_cast<_Tp>((src[bidx^2] - Y)*C3 + delta); _Tp Cr = saturate_cast<_Tp>((src[bidx^2] - Y)*C3 + delta);
_Tp Cb = saturate_cast<_Tp>((src[bidx] - Y)*C4 + delta); _Tp Cb = saturate_cast<_Tp>((src[bidx] - Y)*C4 + delta);
dst[i] = Y; dst[i+1] = Cr; dst[i+2] = Cb; dst[i] = Y; dst[i+1+yuvOrder] = Cr; dst[i+2-yuvOrder] = Cb;
} }
} }
int srccn, blueIdx; int srccn, blueIdx;
bool isCrCb;
float coeffs[5]; float coeffs[5];
}; };
@@ -817,16 +852,18 @@ template<typename _Tp> struct RGB2YCrCb_i
{ {
typedef _Tp channel_type; typedef _Tp channel_type;
RGB2YCrCb_i(int _srccn, int _blueIdx, const int* _coeffs) RGB2YCrCb_i(int _srccn, int _blueIdx, bool _isCrCb)
: srccn(_srccn), blueIdx(_blueIdx) : srccn(_srccn), blueIdx(_blueIdx), isCrCb(_isCrCb)
{ {
static const int coeffs0[] = {R2Y, G2Y, B2Y, 11682, 9241}; static const int coeffs_crb[] = { R2Y, G2Y, B2Y, YCRI, YCBI };
memcpy(coeffs, _coeffs ? _coeffs : coeffs0, 5*sizeof(coeffs[0])); static const int coeffs_yuv[] = { R2Y, G2Y, B2Y, R2VI, B2UI };
memcpy(coeffs, isCrCb ? coeffs_crb : coeffs_yuv, 5*sizeof(coeffs[0]));
if(blueIdx==0) std::swap(coeffs[0], coeffs[2]); if(blueIdx==0) std::swap(coeffs[0], coeffs[2]);
} }
void operator()(const _Tp* src, _Tp* dst, int n) const void operator()(const _Tp* src, _Tp* dst, int n) const
{ {
int scn = srccn, bidx = blueIdx; int scn = srccn, bidx = blueIdx;
int yuvOrder = !isCrCb; //1 if YUV, 0 if YCrCb
int C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3], C4 = coeffs[4]; int C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3], C4 = coeffs[4];
int delta = ColorChannel<_Tp>::half()*(1 << yuv_shift); int delta = ColorChannel<_Tp>::half()*(1 << yuv_shift);
n *= 3; n *= 3;
@@ -836,11 +873,12 @@ template<typename _Tp> struct RGB2YCrCb_i
int Cr = CV_DESCALE((src[bidx^2] - Y)*C3 + delta, yuv_shift); int Cr = CV_DESCALE((src[bidx^2] - Y)*C3 + delta, yuv_shift);
int Cb = CV_DESCALE((src[bidx] - Y)*C4 + delta, yuv_shift); int Cb = CV_DESCALE((src[bidx] - Y)*C4 + delta, yuv_shift);
dst[i] = saturate_cast<_Tp>(Y); dst[i] = saturate_cast<_Tp>(Y);
dst[i+1] = saturate_cast<_Tp>(Cr); dst[i+1+yuvOrder] = saturate_cast<_Tp>(Cr);
dst[i+2] = saturate_cast<_Tp>(Cb); dst[i+2-yuvOrder] = saturate_cast<_Tp>(Cb);
} }
} }
int srccn, blueIdx; int srccn, blueIdx;
bool isCrCb;
int coeffs[5]; int coeffs[5];
}; };
@@ -849,23 +887,25 @@ template<typename _Tp> struct YCrCb2RGB_f
{ {
typedef _Tp channel_type; typedef _Tp channel_type;
YCrCb2RGB_f(int _dstcn, int _blueIdx, const float* _coeffs) YCrCb2RGB_f(int _dstcn, int _blueIdx, bool _isCrCb)
: dstcn(_dstcn), blueIdx(_blueIdx) : dstcn(_dstcn), blueIdx(_blueIdx), isCrCb(_isCrCb)
{ {
static const float coeffs0[] = {1.403f, -0.714f, -0.344f, 1.773f}; static const float coeffs_cbr[] = {CR2RF, CR2GF, CB2GF, CB2BF};
memcpy(coeffs, _coeffs ? _coeffs : coeffs0, 4*sizeof(coeffs[0])); static const float coeffs_yuv[] = { V2RF, V2GF, U2GF, U2BF};
memcpy(coeffs, isCrCb ? coeffs_cbr : coeffs_yuv, 4*sizeof(coeffs[0]));
} }
void operator()(const _Tp* src, _Tp* dst, int n) const void operator()(const _Tp* src, _Tp* dst, int n) const
{ {
int dcn = dstcn, bidx = blueIdx; int dcn = dstcn, bidx = blueIdx;
int yuvOrder = !isCrCb; //1 if YUV, 0 if YCrCb
const _Tp delta = ColorChannel<_Tp>::half(), alpha = ColorChannel<_Tp>::max(); const _Tp delta = ColorChannel<_Tp>::half(), alpha = ColorChannel<_Tp>::max();
float C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3]; float C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3];
n *= 3; n *= 3;
for(int i = 0; i < n; i += 3, dst += dcn) for(int i = 0; i < n; i += 3, dst += dcn)
{ {
_Tp Y = src[i]; _Tp Y = src[i];
_Tp Cr = src[i+1]; _Tp Cr = src[i+1+yuvOrder];
_Tp Cb = src[i+2]; _Tp Cb = src[i+2-yuvOrder];
_Tp b = saturate_cast<_Tp>(Y + (Cb - delta)*C3); _Tp b = saturate_cast<_Tp>(Y + (Cb - delta)*C3);
_Tp g = saturate_cast<_Tp>(Y + (Cb - delta)*C2 + (Cr - delta)*C1); _Tp g = saturate_cast<_Tp>(Y + (Cb - delta)*C2 + (Cr - delta)*C1);
@@ -877,6 +917,7 @@ template<typename _Tp> struct YCrCb2RGB_f
} }
} }
int dstcn, blueIdx; int dstcn, blueIdx;
bool isCrCb;
float coeffs[4]; float coeffs[4];
}; };
@@ -885,24 +926,26 @@ template<typename _Tp> struct YCrCb2RGB_i
{ {
typedef _Tp channel_type; typedef _Tp channel_type;
YCrCb2RGB_i(int _dstcn, int _blueIdx, const int* _coeffs) YCrCb2RGB_i(int _dstcn, int _blueIdx, bool _isCrCb)
: dstcn(_dstcn), blueIdx(_blueIdx) : dstcn(_dstcn), blueIdx(_blueIdx), isCrCb(_isCrCb)
{ {
static const int coeffs0[] = {22987, -11698, -5636, 29049}; static const int coeffs_crb[] = { CR2RI, CR2GI, CB2GI, CB2BI};
memcpy(coeffs, _coeffs ? _coeffs : coeffs0, 4*sizeof(coeffs[0])); static const int coeffs_yuv[] = { V2RI, V2GI, U2GI, U2BI };
memcpy(coeffs, isCrCb ? coeffs_crb : coeffs_yuv, 4*sizeof(coeffs[0]));
} }
void operator()(const _Tp* src, _Tp* dst, int n) const void operator()(const _Tp* src, _Tp* dst, int n) const
{ {
int dcn = dstcn, bidx = blueIdx; int dcn = dstcn, bidx = blueIdx;
int yuvOrder = !isCrCb; //1 if YUV, 0 if YCrCb
const _Tp delta = ColorChannel<_Tp>::half(), alpha = ColorChannel<_Tp>::max(); const _Tp delta = ColorChannel<_Tp>::half(), alpha = ColorChannel<_Tp>::max();
int C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3]; int C0 = coeffs[0], C1 = coeffs[1], C2 = coeffs[2], C3 = coeffs[3];
n *= 3; n *= 3;
for(int i = 0; i < n; i += 3, dst += dcn) for(int i = 0; i < n; i += 3, dst += dcn)
{ {
_Tp Y = src[i]; _Tp Y = src[i];
_Tp Cr = src[i+1]; _Tp Cr = src[i+1+yuvOrder];
_Tp Cb = src[i+2]; _Tp Cb = src[i+2-yuvOrder];
int b = Y + CV_DESCALE((Cb - delta)*C3, yuv_shift); int b = Y + CV_DESCALE((Cb - delta)*C3, yuv_shift);
int g = Y + CV_DESCALE((Cb - delta)*C2 + (Cr - delta)*C1, yuv_shift); int g = Y + CV_DESCALE((Cb - delta)*C2 + (Cr - delta)*C1, yuv_shift);
@@ -916,6 +959,7 @@ template<typename _Tp> struct YCrCb2RGB_i
} }
} }
int dstcn, blueIdx; int dstcn, blueIdx;
bool isCrCb;
int coeffs[4]; int coeffs[4];
}; };
@@ -3832,10 +3876,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
{ {
CV_Assert( scn == 3 || scn == 4 ); CV_Assert( scn == 3 || scn == 4 );
bidx = code == CV_BGR2YCrCb || code == CV_BGR2YUV ? 0 : 2; bidx = code == CV_BGR2YCrCb || code == CV_BGR2YUV ? 0 : 2;
static const float yuv_f[] = { 0.114f, 0.587f, 0.299f, 0.492f, 0.877f }; const bool isCrCb = (code == CV_BGR2YCrCb || code == CV_RGB2YCrCb);
static const int yuv_i[] = { B2Y, G2Y, R2Y, 8061, 14369 };
const float* coeffs_f = code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? 0 : yuv_f;
const int* coeffs_i = code == CV_BGR2YCrCb || code == CV_RGB2YCrCb ? 0 : yuv_i;
_dst.create(sz, CV_MAKETYPE(depth, 3)); _dst.create(sz, CV_MAKETYPE(depth, 3));
dst = _dst.getMat(); dst = _dst.getMat();
@@ -3846,12 +3887,12 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
if((code == CV_RGB2YCrCb || code == CV_BGR2YCrCb) && tegra::cvtRGB2YCrCb(src, dst, bidx)) if((code == CV_RGB2YCrCb || code == CV_BGR2YCrCb) && tegra::cvtRGB2YCrCb(src, dst, bidx))
break; break;
#endif #endif
CvtColorLoop(src, dst, RGB2YCrCb_i<uchar>(scn, bidx, coeffs_i)); CvtColorLoop(src, dst, RGB2YCrCb_i<uchar>(scn, bidx, isCrCb));
} }
else if( depth == CV_16U ) else if( depth == CV_16U )
CvtColorLoop(src, dst, RGB2YCrCb_i<ushort>(scn, bidx, coeffs_i)); CvtColorLoop(src, dst, RGB2YCrCb_i<ushort>(scn, bidx, isCrCb));
else else
CvtColorLoop(src, dst, RGB2YCrCb_f<float>(scn, bidx, coeffs_f)); CvtColorLoop(src, dst, RGB2YCrCb_f<float>(scn, bidx, isCrCb));
} }
break; break;
@@ -3861,20 +3902,17 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
if( dcn <= 0 ) dcn = 3; if( dcn <= 0 ) dcn = 3;
CV_Assert( scn == 3 && (dcn == 3 || dcn == 4) ); CV_Assert( scn == 3 && (dcn == 3 || dcn == 4) );
bidx = code == CV_YCrCb2BGR || code == CV_YUV2BGR ? 0 : 2; bidx = code == CV_YCrCb2BGR || code == CV_YUV2BGR ? 0 : 2;
static const float yuv_f[] = { 2.032f, -0.395f, -0.581f, 1.140f }; const bool isCrCb = (code == CV_YCrCb2BGR || code == CV_YCrCb2RGB);
static const int yuv_i[] = { 33292, -6472, -9519, 18678 };
const float* coeffs_f = code == CV_YCrCb2BGR || code == CV_YCrCb2RGB ? 0 : yuv_f;
const int* coeffs_i = code == CV_YCrCb2BGR || code == CV_YCrCb2RGB ? 0 : yuv_i;
_dst.create(sz, CV_MAKETYPE(depth, dcn)); _dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat(); dst = _dst.getMat();
if( depth == CV_8U ) if( depth == CV_8U )
CvtColorLoop(src, dst, YCrCb2RGB_i<uchar>(dcn, bidx, coeffs_i)); CvtColorLoop(src, dst, YCrCb2RGB_i<uchar>(dcn, bidx, isCrCb));
else if( depth == CV_16U ) else if( depth == CV_16U )
CvtColorLoop(src, dst, YCrCb2RGB_i<ushort>(dcn, bidx, coeffs_i)); CvtColorLoop(src, dst, YCrCb2RGB_i<ushort>(dcn, bidx, isCrCb));
else else
CvtColorLoop(src, dst, YCrCb2RGB_f<float>(dcn, bidx, coeffs_f)); CvtColorLoop(src, dst, YCrCb2RGB_f<float>(dcn, bidx, isCrCb));
} }
break; break;
+8 -9
View File
@@ -314,25 +314,26 @@ if(BUILD_FAT_JAVA_LIB)
endif() endif()
if(APPLE) if(APPLE)
foreach(_dep ${__deps}) foreach(_dep ${__deps})
target_link_libraries(${the_module} -Wl,-force_load "${_dep}") target_link_libraries(${the_module} LINK_PRIVATE -Wl,-force_load "${_dep}")
endforeach() endforeach()
else() else()
target_link_libraries(${the_module} -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive) target_link_libraries(${the_module} LINK_PRIVATE -Wl,-whole-archive ${__deps} -Wl,-no-whole-archive)
endif() endif()
target_link_libraries(${the_module} ${__extradeps} ${OPENCV_LINKER_LIBS}) target_link_libraries(${the_module} LINK_PRIVATE ${__extradeps} ${OPENCV_LINKER_LIBS})
else() else()
target_link_libraries(${the_module} ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS}) target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_MODULE_${the_module}_DEPS} ${OPENCV_LINKER_LIBS})
endif() endif()
if(ANDROID) if(ANDROID)
target_link_libraries(${the_module} jnigraphics) # for Mat <=> Bitmap converters target_link_libraries(${the_module} LINK_PUBLIC jnigraphics) # for Mat <=> Bitmap converters
target_link_libraries(${the_module} LINK_PUBLIC log dl z)
target_link_libraries(${the_module} LINK_PRIVATE ${OPENCV_LINKER_LIBS})
# force strip library after the build command # force strip library after the build command
# because samples and tests will make a copy of the library before install # because samples and tests will make a copy of the library before install
get_target_property(__opencv_java_location ${the_module} LOCATION)
# Turn off stripping in debug build # Turn off stripping in debug build
if ( NOT (CMAKE_BUILD_TYPE MATCHES "Debug")) if ( NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${__opencv_java_location}") add_custom_command(TARGET ${the_module} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "$<TARGET_FILE:${the_module}>")
endif() endif()
endif() endif()
@@ -342,8 +343,6 @@ set_target_properties(${the_module} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH}
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
INSTALL_NAME_DIR ${OPENCV_LIB_INSTALL_PATH}
LINK_INTERFACE_LIBRARIES ""
) )
if(WIN32) if(WIN32)
+5 -3
View File
@@ -170,10 +170,12 @@ static Mat createInitialImage( const Mat& img, bool doubleImageSize, float sigma
{ {
Mat gray, gray_fpt; Mat gray, gray_fpt;
if( img.channels() == 3 || img.channels() == 4 ) if( img.channels() == 3 || img.channels() == 4 )
{
cvtColor(img, gray, COLOR_BGR2GRAY); cvtColor(img, gray, COLOR_BGR2GRAY);
gray.convertTo(gray_fpt, DataType<sift_wt>::type, SIFT_FIXPT_SCALE, 0);
}
else else
img.copyTo(gray); img.convertTo(gray_fpt, DataType<sift_wt>::type, SIFT_FIXPT_SCALE, 0);
gray.convertTo(gray_fpt, DataType<sift_wt>::type, SIFT_FIXPT_SCALE, 0);
float sig_diff; float sig_diff;
@@ -181,7 +183,7 @@ static Mat createInitialImage( const Mat& img, bool doubleImageSize, float sigma
{ {
sig_diff = sqrtf( std::max(sigma * sigma - SIFT_INIT_SIGMA * SIFT_INIT_SIGMA * 4, 0.01f) ); sig_diff = sqrtf( std::max(sigma * sigma - SIFT_INIT_SIGMA * SIFT_INIT_SIGMA * 4, 0.01f) );
Mat dbl; Mat dbl;
resize(gray_fpt, dbl, Size(gray.cols*2, gray.rows*2), 0, 0, INTER_LINEAR); resize(gray_fpt, dbl, Size(gray_fpt.cols*2, gray_fpt.rows*2), 0, 0, INTER_LINEAR);
GaussianBlur(dbl, dbl, Size(), sig_diff, sig_diff); GaussianBlur(dbl, dbl, Size(), sig_diff, sig_diff);
return dbl; return dbl;
} }
+70 -39
View File
@@ -115,9 +115,42 @@ enum
BLOCK_SIZE = 256 BLOCK_SIZE = 256
}; };
//constants for conversion from/to RGB and Gray, YUV, YCrCb according to BT.601
#define B2YF 0.114f
#define G2YF 0.587f
#define R2YF 0.299f
//to YCbCr
#define YCBF 0.564f
#define YCRF 0.713f
#define YCBI 9241
#define YCRI 11682
//to YUV
#define B2UF 0.492f
#define R2VF 0.877f
#define B2UI 8061
#define R2VI 14369
//from YUV
#define U2BF 2.032f
#define U2GF -0.395f
#define V2GF -0.581f
#define V2RF 1.140f
#define U2BI 33292
#define U2GI -6472
#define V2GI -9519
#define V2RI 18678
//from YCrCb
#define CR2RF 1.403f
#define CB2GF -0.344f
#define CR2GF -0.714f
#define CB2BF 1.773f
#define CR2RI 22987
#define CB2GI -5636
#define CR2GI -11698
#define CB2BI 29049
///////////////////////////////////// RGB <-> GRAY ////////////////////////////////////// ///////////////////////////////////// RGB <-> GRAY //////////////////////////////////////
__constant float c_RGB2GrayCoeffs_f[3] = { 0.114f, 0.587f, 0.299f }; __constant float c_RGB2GrayCoeffs_f[3] = { B2YF, G2YF, R2YF };
__constant int c_RGB2GrayCoeffs_i[3] = { B2Y, G2Y, R2Y }; __constant int c_RGB2GrayCoeffs_i[3] = { B2Y, G2Y, R2Y };
__kernel void RGB2Gray(int cols, int rows, int src_step, int dst_step, __kernel void RGB2Gray(int cols, int rows, int src_step, int dst_step,
@@ -135,7 +168,7 @@ __kernel void RGB2Gray(int cols, int rows, int src_step, int dst_step,
#ifndef INTEL_DEVICE #ifndef INTEL_DEVICE
#ifdef DEPTH_5 #ifdef DEPTH_5
dst[dst_idx] = src[src_idx + bidx] * 0.114f + src[src_idx + 1] * 0.587f + src[src_idx + (bidx^2)] * 0.299f; dst[dst_idx] = src[src_idx + bidx] * B2YF + src[src_idx + 1] * G2YF + src[src_idx + (bidx^2)] * R2YF;
#else #else
dst[dst_idx] = (DATA_TYPE)CV_DESCALE((src[src_idx + bidx] * B2Y + src[src_idx + 1] * G2Y + src[src_idx + (bidx^2)] * R2Y), yuv_shift); dst[dst_idx] = (DATA_TYPE)CV_DESCALE((src[src_idx + bidx] * B2Y + src[src_idx + 1] * G2Y + src[src_idx + (bidx^2)] * R2Y), yuv_shift);
#endif #endif
@@ -221,8 +254,8 @@ __kernel void Gray2RGB(int cols, int rows, int src_step, int dst_step,
///////////////////////////////////// RGB <-> YUV ////////////////////////////////////// ///////////////////////////////////// RGB <-> YUV //////////////////////////////////////
__constant float c_RGB2YUVCoeffs_f[5] = { 0.114f, 0.587f, 0.299f, 0.492f, 0.877f }; __constant float c_RGB2YUVCoeffs_f[5] = { B2YF, G2YF, R2YF, B2UF, R2VF };
__constant int c_RGB2YUVCoeffs_i[5] = { B2Y, G2Y, R2Y, 8061, 14369 }; __constant int c_RGB2YUVCoeffs_i[5] = { B2Y, G2Y, R2Y, B2UI, R2VI };
__kernel void RGB2YUV(int cols, int rows, int src_step, int dst_step, __kernel void RGB2YUV(int cols, int rows, int src_step, int dst_step,
__global const DATA_TYPE* src, __global DATA_TYPE* dst, __global const DATA_TYPE* src, __global DATA_TYPE* dst,
@@ -252,13 +285,13 @@ __kernel void RGB2YUV(int cols, int rows, int src_step, int dst_step,
const DATA_TYPE rgb[] = {src_ptr[0], src_ptr[1], src_ptr[2]}; const DATA_TYPE rgb[] = {src_ptr[0], src_ptr[1], src_ptr[2]};
#ifdef DEPTH_5 #ifdef DEPTH_5
float Y = rgb[0] * coeffs[bidx^2] + rgb[1] * coeffs[1] + rgb[2] * coeffs[bidx]; float Y = rgb[0] * coeffs[bidx] + rgb[1] * coeffs[1] + rgb[2] * coeffs[bidx^2];
float U = (rgb[bidx^2] - Y) * coeffs[3] + HALF_MAX; float U = (rgb[bidx] - Y) * coeffs[3] + HALF_MAX;
float V = (rgb[bidx] - Y) * coeffs[4] + HALF_MAX; float V = (rgb[bidx^2] - Y) * coeffs[4] + HALF_MAX;
#else #else
int Y = CV_DESCALE(rgb[0] * coeffs[bidx^2] + rgb[1] * coeffs[1] + rgb[2] * coeffs[bidx], yuv_shift); int Y = CV_DESCALE(rgb[0] * coeffs[bidx] + rgb[1] * coeffs[1] + rgb[2] * coeffs[bidx^2], yuv_shift);
int U = CV_DESCALE((rgb[bidx^2] - Y) * coeffs[3] + delta, yuv_shift); int U = CV_DESCALE((rgb[bidx] - Y) * coeffs[3] + delta, yuv_shift);
int V = CV_DESCALE((rgb[bidx] - Y) * coeffs[4] + delta, yuv_shift); int V = CV_DESCALE((rgb[bidx^2] - Y) * coeffs[4] + delta, yuv_shift);
#endif #endif
dst_ptr[0] = SAT_CAST( Y ); dst_ptr[0] = SAT_CAST( Y );
@@ -274,23 +307,22 @@ __kernel void RGB2YUV(int cols, int rows, int src_step, int dst_step,
const float2 c1 = r0.s15; const float2 c1 = r0.s15;
const float2 c2 = r0.s26; const float2 c2 = r0.s26;
const float2 Y = (bidx == 0) ? (c0 * coeffs[2] + c1 * coeffs[1] + c2 * coeffs[0]) : (c0 * coeffs[0] + c1 * coeffs[1] + c2 * coeffs[2]); const float2 Y = (bidx == 0) ? (c0 * coeffs[0] + c1 * coeffs[1] + c2 * coeffs[2]) : (c0 * coeffs[2] + c1 * coeffs[1] + c2 * coeffs[0]);
const float2 U = (bidx == 0) ? ((c2 - Y) * coeffs[3] + HALF_MAX) : ((c0 - Y) * coeffs[3] + HALF_MAX); const float2 U = (bidx == 0) ? ((c0 - Y) * coeffs[3] + HALF_MAX) : ((c2 - Y) * coeffs[3] + HALF_MAX);
const float2 V = (bidx == 0) ? ((c0 - Y) * coeffs[4] + HALF_MAX) : ((c2 - Y) * coeffs[4] + HALF_MAX); const float2 V = (bidx == 0) ? ((c2 - Y) * coeffs[4] + HALF_MAX) : ((c0 - Y) * coeffs[4] + HALF_MAX);
#else #else
const int2 c0 = convert_int2(r0.s04); const int2 c0 = convert_int2(r0.s04);
const int2 c1 = convert_int2(r0.s15); const int2 c1 = convert_int2(r0.s15);
const int2 c2 = convert_int2(r0.s26); const int2 c2 = convert_int2(r0.s26);
const int2 yi = (bidx == 0) ? CV_DESCALE(c0 * coeffs[2] + c1 * coeffs[1] + c2 * coeffs[0], yuv_shift) : CV_DESCALE(c0 * coeffs[0] + c1 * coeffs[1] + c2 * coeffs[2], yuv_shift); const int2 yi = (bidx == 0) ? CV_DESCALE(c0 * coeffs[0] + c1 * coeffs[1] + c2 * coeffs[2], yuv_shift) : CV_DESCALE(c0 * coeffs[2] + c1 * coeffs[1] + c2 * coeffs[0], yuv_shift);
const int2 ui = (bidx == 0) ? CV_DESCALE((c2 - yi) * coeffs[3] + delta, yuv_shift) : CV_DESCALE((c0 - yi) * coeffs[3] + delta, yuv_shift); const int2 ui = (bidx == 0) ? CV_DESCALE((c0 - yi) * coeffs[3] + delta, yuv_shift) : CV_DESCALE((c2 - yi) * coeffs[3] + delta, yuv_shift);
const int2 vi = (bidx == 0) ? CV_DESCALE((c0 - yi) * coeffs[4] + delta, yuv_shift) : CV_DESCALE((c2 - yi) * coeffs[4] + delta, yuv_shift); const int2 vi = (bidx == 0) ? CV_DESCALE((c2 - yi) * coeffs[4] + delta, yuv_shift) : CV_DESCALE((c0 - yi) * coeffs[4] + delta, yuv_shift);
const VECTOR2 Y = SAT_CAST2(yi); const VECTOR2 Y = SAT_CAST2(yi);
const VECTOR2 U = SAT_CAST2(ui); const VECTOR2 U = SAT_CAST2(ui);
const VECTOR2 V = SAT_CAST2(vi); const VECTOR2 V = SAT_CAST2(vi);
#endif #endif
vstore8((VECTOR8)(Y.s0, U.s0, V.s0, 0, Y.s1, U.s1, V.s1, 0), 0, dst_ptr); vstore8((VECTOR8)(Y.s0, U.s0, V.s0, 0, Y.s1, U.s1, V.s1, 0), 0, dst_ptr);
} }
#elif (4 == pixels_per_work_item) #elif (4 == pixels_per_work_item)
@@ -302,14 +334,13 @@ __kernel void RGB2YUV(int cols, int rows, int src_step, int dst_step,
const int4 c1 = convert_int4(r0.s159d); const int4 c1 = convert_int4(r0.s159d);
const int4 c2 = convert_int4(r0.s26ae); const int4 c2 = convert_int4(r0.s26ae);
const int4 yi = (bidx == 0) ? CV_DESCALE(c0 * coeffs[2] + c1 * coeffs[1] + c2 * coeffs[0], yuv_shift) : CV_DESCALE(c0 * coeffs[0] + c1 * coeffs[1] + c2 * coeffs[2], yuv_shift); const int4 yi = (bidx == 0) ? CV_DESCALE(c0 * coeffs[0] + c1 * coeffs[1] + c2 * coeffs[2], yuv_shift) : CV_DESCALE(c0 * coeffs[2] + c1 * coeffs[1] + c2 * coeffs[0], yuv_shift);
const int4 ui = (bidx == 0) ? CV_DESCALE((c2 - yi) * coeffs[3] + delta, yuv_shift) : CV_DESCALE((c0 - yi) * coeffs[3] + delta, yuv_shift); const int4 ui = (bidx == 0) ? CV_DESCALE((c0 - yi) * coeffs[3] + delta, yuv_shift) : CV_DESCALE((c2 - yi) * coeffs[3] + delta, yuv_shift);
const int4 vi = (bidx == 0) ? CV_DESCALE((c0 - yi) * coeffs[4] + delta, yuv_shift) : CV_DESCALE((c2 - yi) * coeffs[4] + delta, yuv_shift); const int4 vi = (bidx == 0) ? CV_DESCALE((c2 - yi) * coeffs[4] + delta, yuv_shift) : CV_DESCALE((c0 - yi) * coeffs[4] + delta, yuv_shift);
const VECTOR4 Y = SAT_CAST4(yi); const VECTOR4 Y = SAT_CAST4(yi);
const VECTOR4 U = SAT_CAST4(ui); const VECTOR4 U = SAT_CAST4(ui);
const VECTOR4 V = SAT_CAST4(vi); const VECTOR4 V = SAT_CAST4(vi);
vstore16((VECTOR16)(Y.s0, U.s0, V.s0, 0, Y.s1, U.s1, V.s1, 0, Y.s2, U.s2, V.s2, 0, Y.s3, U.s3, V.s3, 0), 0, dst_ptr); vstore16((VECTOR16)(Y.s0, U.s0, V.s0, 0, Y.s1, U.s1, V.s1, 0, Y.s2, U.s2, V.s2, 0, Y.s3, U.s3, V.s3, 0), 0, dst_ptr);
#endif #endif
} }
@@ -317,8 +348,8 @@ __kernel void RGB2YUV(int cols, int rows, int src_step, int dst_step,
} }
} }
__constant float c_YUV2RGBCoeffs_f[5] = { 2.032f, -0.395f, -0.581f, 1.140f }; __constant float c_YUV2RGBCoeffs_f[5] = { U2BF, U2GF, V2GF, V2RF };
__constant int c_YUV2RGBCoeffs_i[5] = { 33292, -6472, -9519, 18678 }; __constant int c_YUV2RGBCoeffs_i[5] = { U2BI, U2GI, V2GI, V2RI };
__kernel void YUV2RGB(int cols, int rows, int src_step, int dst_step, __kernel void YUV2RGB(int cols, int rows, int src_step, int dst_step,
__global const DATA_TYPE* src, __global DATA_TYPE* dst, __global const DATA_TYPE* src, __global DATA_TYPE* dst,
@@ -347,13 +378,13 @@ __kernel void YUV2RGB(int cols, int rows, int src_step, int dst_step,
const DATA_TYPE yuv[] = {src_ptr[0], src_ptr[1], src_ptr[2]}; const DATA_TYPE yuv[] = {src_ptr[0], src_ptr[1], src_ptr[2]};
#ifdef DEPTH_5 #ifdef DEPTH_5
float B = yuv[0] + (yuv[2] - HALF_MAX) * coeffs[3]; float B = yuv[0] + (yuv[1] - HALF_MAX) * coeffs[0];
float G = yuv[0] + (yuv[2] - HALF_MAX) * coeffs[2] + (yuv[1] - HALF_MAX) * coeffs[1]; float G = yuv[0] + (yuv[1] - HALF_MAX) * coeffs[1] + (yuv[2] - HALF_MAX) * coeffs[2];
float R = yuv[0] + (yuv[1] - HALF_MAX) * coeffs[0]; float R = yuv[0] + (yuv[2] - HALF_MAX) * coeffs[3];
#else #else
int B = yuv[0] + CV_DESCALE((yuv[2] - HALF_MAX) * coeffs[3], yuv_shift); int B = yuv[0] + CV_DESCALE((yuv[1] - HALF_MAX) * coeffs[0], yuv_shift);
int G = yuv[0] + CV_DESCALE((yuv[2] - HALF_MAX) * coeffs[2] + (yuv[1] - HALF_MAX) * coeffs[1], yuv_shift); int G = yuv[0] + CV_DESCALE((yuv[1] - HALF_MAX) * coeffs[1] + (yuv[2] - HALF_MAX) * coeffs[2], yuv_shift);
int R = yuv[0] + CV_DESCALE((yuv[1] - HALF_MAX) * coeffs[0], yuv_shift); int R = yuv[0] + CV_DESCALE((yuv[2] - HALF_MAX) * coeffs[3], yuv_shift);
#endif #endif
dst_ptr[bidx] = SAT_CAST( B ); dst_ptr[bidx] = SAT_CAST( B );
@@ -372,17 +403,17 @@ __kernel void YUV2RGB(int cols, int rows, int src_step, int dst_step,
const float2 U = r0.s15; const float2 U = r0.s15;
const float2 V = r0.s26; const float2 V = r0.s26;
const float2 c0 = (bidx == 0) ? (Y + (V - HALF_MAX) * coeffs[3]) : (Y + (U - HALF_MAX) * coeffs[0]); const float2 c0 = (bidx != 0) ? (Y + (V - HALF_MAX) * coeffs[3]) : (Y + (U - HALF_MAX) * coeffs[0]);
const float2 c1 = Y + (V - HALF_MAX) * coeffs[2] + (U - HALF_MAX) * coeffs[1]; const float2 c1 = Y + (V - HALF_MAX) * coeffs[2] + (U - HALF_MAX) * coeffs[1];
const float2 c2 = (bidx == 0) ? (Y + (U - HALF_MAX) * coeffs[0]) : (Y + (V - HALF_MAX) * coeffs[3]); const float2 c2 = (bidx != 0) ? (Y + (U - HALF_MAX) * coeffs[0]) : (Y + (V - HALF_MAX) * coeffs[3]);
#else #else
const int2 Y = convert_int2(r0.s04); const int2 Y = convert_int2(r0.s04);
const int2 U = convert_int2(r0.s15); const int2 U = convert_int2(r0.s15);
const int2 V = convert_int2(r0.s26); const int2 V = convert_int2(r0.s26);
const int2 c0i = (bidx == 0) ? (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift)) : (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift)); const int2 c0i = (bidx != 0) ? (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift)) : (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift));
const int2 c1i = Y + CV_DESCALE((V - HALF_MAX) * coeffs[2] + (U - HALF_MAX) * coeffs[1], yuv_shift); const int2 c1i = Y + CV_DESCALE((V - HALF_MAX) * coeffs[2] + (U - HALF_MAX) * coeffs[1], yuv_shift);
const int2 c2i = (bidx == 0) ? (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift)) : (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift)); const int2 c2i = (bidx != 0) ? (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift)) : (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift));
const VECTOR2 c0 = SAT_CAST2(c0i); const VECTOR2 c0 = SAT_CAST2(c0i);
const VECTOR2 c1 = SAT_CAST2(c1i); const VECTOR2 c1 = SAT_CAST2(c1i);
@@ -404,9 +435,9 @@ __kernel void YUV2RGB(int cols, int rows, int src_step, int dst_step,
const int4 U = convert_int4(r0.s159d); const int4 U = convert_int4(r0.s159d);
const int4 V = convert_int4(r0.s26ae); const int4 V = convert_int4(r0.s26ae);
const int4 c0i = (bidx == 0) ? (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift)) : (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift)); const int4 c0i = (bidx != 0) ? (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift)) : (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift));
const int4 c1i = Y + CV_DESCALE((V - HALF_MAX) * coeffs[2] + (U - HALF_MAX) * coeffs[1], yuv_shift); const int4 c1i = Y + CV_DESCALE((V - HALF_MAX) * coeffs[2] + (U - HALF_MAX) * coeffs[1], yuv_shift);
const int4 c2i = (bidx == 0) ? (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift)) : (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift)); const int4 c2i = (bidx != 0) ? (Y + CV_DESCALE((U - HALF_MAX) * coeffs[0], yuv_shift)) : (Y + CV_DESCALE((V - HALF_MAX) * coeffs[3], yuv_shift));
const VECTOR4 c0 = SAT_CAST4(c0i); const VECTOR4 c0 = SAT_CAST4(c0i);
const VECTOR4 c1 = SAT_CAST4(c1i); const VECTOR4 c1 = SAT_CAST4(c1i);
@@ -484,8 +515,8 @@ __kernel void YUV2RGBA_NV12(int cols, int rows, int src_step, int dst_step,
///////////////////////////////////// RGB <-> YCrCb ////////////////////////////////////// ///////////////////////////////////// RGB <-> YCrCb //////////////////////////////////////
__constant float c_RGB2YCrCbCoeffs_f[5] = {0.299f, 0.587f, 0.114f, 0.713f, 0.564f}; __constant float c_RGB2YCrCbCoeffs_f[5] = {R2YF, G2YF, B2YF, YCRF, YCBF};
__constant int c_RGB2YCrCbCoeffs_i[5] = {R2Y, G2Y, B2Y, 11682, 9241}; __constant int c_RGB2YCrCbCoeffs_i[5] = {R2Y, G2Y, B2Y, YCRI, YCBI};
__kernel void RGB2YCrCb(int cols, int rows, int src_step, int dst_step, __kernel void RGB2YCrCb(int cols, int rows, int src_step, int dst_step,
__global const DATA_TYPE* src, __global DATA_TYPE* dst, __global const DATA_TYPE* src, __global DATA_TYPE* dst,
@@ -579,8 +610,8 @@ __kernel void RGB2YCrCb(int cols, int rows, int src_step, int dst_step,
} }
} }
__constant float c_YCrCb2RGBCoeffs_f[4] = { 1.403f, -0.714f, -0.344f, 1.773f }; __constant float c_YCrCb2RGBCoeffs_f[4] = { CR2RF, CR2GF, CB2GF, CB2BF };
__constant int c_YCrCb2RGBCoeffs_i[4] = { 22987, -11698, -5636, 29049 }; __constant int c_YCrCb2RGBCoeffs_i[4] = { CR2RI, CR2GI, CB2GI, CB2BI };
__kernel void YCrCb2RGB(int cols, int rows, int src_step, int dst_step, __kernel void YCrCb2RGB(int cols, int rows, int src_step, int dst_step,
__global const DATA_TYPE* src, __global DATA_TYPE* dst, __global const DATA_TYPE* src, __global DATA_TYPE* dst,
+2 -2
View File
@@ -40,7 +40,7 @@ Modification of ``fastNlMeansDenoising`` function for colored images
:param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise :param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise
:param hForColorComponents: The same as h but for color components. For most images value equals 10 will be enought to remove colored noise and do not distort colors :param hColor: The same as h but for color components. For most images value equals 10 will be enought to remove colored noise and do not distort colors
The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoising`` function. The function converts image to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoising`` function.
@@ -85,6 +85,6 @@ Modification of ``fastNlMeansDenoisingMulti`` function for colored images sequen
:param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise. :param h: Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise but also removes image details, smaller h value preserves details but also preserves some noise.
:param hForColorComponents: The same as h but for color components. :param hColor: The same as h but for color components.
The function converts images to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoisingMulti`` function. The function converts images to CIELAB colorspace and then separately denoise L and AB components with given h parameters using ``fastNlMeansDenoisingMulti`` function.
+2
View File
@@ -97,6 +97,8 @@ if(MSVC AND NOT ENABLE_NOISY_WARNINGS)
string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/W4" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif() endif()
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) # accurate guard via #pragma doesn't work (C++ preprocessor doesn't handle #pragma)
if(MSVC AND NOT BUILD_SHARED_LIBS) if(MSVC AND NOT BUILD_SHARED_LIBS)
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
endif() endif()
+1 -1
View File
@@ -7,7 +7,7 @@ set(the_description "Viz")
ocv_define_module(viz opencv_core ${VTK_LIBRARIES}) ocv_define_module(viz opencv_core ${VTK_LIBRARIES})
if(APPLE AND BUILD_opencv_viz) if(APPLE AND BUILD_opencv_viz)
target_link_libraries(opencv_viz "-framework Cocoa") target_link_libraries(opencv_viz LINK_PRIVATE "-framework Cocoa")
endif() endif()
if(TARGET opencv_test_viz) if(TARGET opencv_test_viz)
@@ -101,7 +101,7 @@ public:
} }
else else
{ {
if (readStringList(input, imageList)) if (isListOfImages(input) && readStringList(input, imageList))
{ {
inputType = IMAGE_LIST; inputType = IMAGE_LIST;
nrFrames = (nrFrames < (int)imageList.size()) ? nrFrames : (int)imageList.size(); nrFrames = (nrFrames < (int)imageList.size()) ? nrFrames : (int)imageList.size();
@@ -169,6 +169,16 @@ public:
l.push_back((string)*it); l.push_back((string)*it);
return true; return true;
} }
static bool isListOfImages( const string& filename)
{
string s(filename);
// Look for file extension
if( s.find(".xml") == string::npos && s.find(".yaml") == string::npos && s.find(".yml") == string::npos )
return false;
else
return true;
}
public: public:
Size boardSize; // The size of the board -> Number of items by width and height Size boardSize; // The size of the board -> Number of items by width and height
Pattern calibrationPattern;// One of the Chessboard, circles, or asymmetric circle pattern Pattern calibrationPattern;// One of the Chessboard, circles, or asymmetric circle pattern