From 5dd598fc6d00bf66fe6151bb686515f1a866ce7d Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 6 Aug 2013 18:56:36 +0400 Subject: [PATCH 01/22] Fix building the iOS framework after I dropped the VERSION macro. This version uses CMake to generate Info.plist, which should be more reliable than the old approach. --- CMakeLists.txt | 3 ++- cmake/OpenCVGenInfoPlist.cmake | 4 ++++ platforms/ios/Info.plist.in | 4 ++-- platforms/ios/build_framework.py | 18 ++---------------- 4 files changed, 10 insertions(+), 19 deletions(-) create mode 100644 cmake/OpenCVGenInfoPlist.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 46881c4531..2ddbd84079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -497,6 +497,8 @@ include(cmake/OpenCVGenAndroidMK.cmake) # Generate OpenCVДonfig.cmake and OpenCVConfig-version.cmake for cmake projects include(cmake/OpenCVGenConfig.cmake) +# Generate Info.plist for the IOS framework +include(cmake/OpenCVGenInfoPlist.cmake) # ---------------------------------------------------------------------------- # Summary: @@ -891,4 +893,3 @@ ocv_finalize_status() 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() - diff --git a/cmake/OpenCVGenInfoPlist.cmake b/cmake/OpenCVGenInfoPlist.cmake new file mode 100644 index 0000000000..97c674ceb7 --- /dev/null +++ b/cmake/OpenCVGenInfoPlist.cmake @@ -0,0 +1,4 @@ +if(IOS) + configure_file("${OpenCV_SOURCE_DIR}/platforms/ios/Info.plist.in" + "${CMAKE_BINARY_DIR}/ios/Info.plist") +endif() diff --git a/platforms/ios/Info.plist.in b/platforms/ios/Info.plist.in index 6bcfe862d0..b2a3baf524 100644 --- a/platforms/ios/Info.plist.in +++ b/platforms/ios/Info.plist.in @@ -7,9 +7,9 @@ CFBundleIdentifier org.opencv CFBundleVersion - ${VERSION} + ${OPENCV_LIBVERSION} CFBundleShortVersionString - ${VERSION} + ${OPENCV_LIBVERSION} CFBundleSignature ???? CFBundlePackageType diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index bc385bb1bb..23da296a41 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -71,15 +71,6 @@ def put_framework_together(srcroot, dstroot): os.makedirs(framework_dir) os.chdir(framework_dir) - # determine OpenCV version (without subminor part) - tdir0 = "../build/" + targetlist[0] - cfg = open(tdir0 + "/cvconfig.h", "rt") - for l in cfg.readlines(): - if l.startswith("#define VERSION"): - opencv_version = l[l.find("\"")+1:l.rfind(".")] - break - cfg.close() - # form the directory tree dstdir = "Versions/A" os.makedirs(dstdir + "/Resources") @@ -91,13 +82,8 @@ def put_framework_together(srcroot, dstroot): wlist = " ".join(["../build/" + t + "/lib/Release/libopencv_world.a" for t in targetlist]) os.system("lipo -create " + wlist + " -o " + dstdir + "/opencv2") - # form Info.plist - srcfile = open(srcroot + "/platforms/ios/Info.plist.in", "rt") - dstfile = open(dstdir + "/Resources/Info.plist", "wt") - for l in srcfile.readlines(): - dstfile.write(l.replace("${VERSION}", opencv_version)) - srcfile.close() - dstfile.close() + # copy Info.plist + shutil.copyfile("../build/ios/Info.plist", dstdir + "/Resources/Info.plist") # make symbolic links os.symlink("A", "Versions/Current") From cf39ba5801d420f164f94c621e20d31e7939f15e Mon Sep 17 00:00:00 2001 From: Hanusz Leszek Date: Mon, 19 Aug 2013 19:05:37 +0200 Subject: [PATCH 02/22] Allow to read PNG image of color_type PNG_COLOR_TYPE_PALETTE with alpha channel Correct reading PNG color type palette with or without alpha imread flags -1 or 1 Better not using pnginfo.h, using png_get_tRNS instead --- modules/highgui/src/grfmt_png.cpp | 29 +++++---- modules/highgui/test/test_grfmt.cpp | 92 +++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 10 deletions(-) diff --git a/modules/highgui/src/grfmt_png.cpp b/modules/highgui/src/grfmt_png.cpp index fb0fe6c391..41bd58e80c 100644 --- a/modules/highgui/src/grfmt_png.cpp +++ b/modules/highgui/src/grfmt_png.cpp @@ -171,7 +171,9 @@ bool PngDecoder::readHeader() if( !m_buf.empty() || m_f ) { png_uint_32 wdth, hght; - int bit_depth, color_type; + int bit_depth, color_type, num_trans=0; + png_bytep trans; + png_color_16p trans_values; png_read_info( png_ptr, info_ptr ); @@ -187,15 +189,22 @@ bool PngDecoder::readHeader() { switch(color_type) { - case PNG_COLOR_TYPE_RGB: - case PNG_COLOR_TYPE_PALETTE: - m_type = CV_8UC3; - break; - case PNG_COLOR_TYPE_RGB_ALPHA: - m_type = CV_8UC4; - break; - default: - m_type = CV_8UC1; + case PNG_COLOR_TYPE_RGB: + m_type = CV_8UC3; + break; + case PNG_COLOR_TYPE_PALETTE: + png_get_tRNS( png_ptr, info_ptr, &trans, &num_trans, &trans_values); + //Check if there is a transparency value in the palette + if ( num_trans > 0 ) + m_type = CV_8UC4; + else + m_type = CV_8UC3; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + m_type = CV_8UC4; + break; + default: + m_type = CV_8UC1; } if( bit_depth == 16 ) m_type = CV_MAKETYPE(CV_16U, CV_MAT_CN(m_type)); diff --git a/modules/highgui/test/test_grfmt.cpp b/modules/highgui/test/test_grfmt.cpp index 8366fcdffc..ed16d1cde2 100644 --- a/modules/highgui/test/test_grfmt.cpp +++ b/modules/highgui/test/test_grfmt.cpp @@ -280,6 +280,98 @@ TEST(Highgui_ImreadVSCvtColor, regression) EXPECT_LT(actual_avg_diff, MAX_MEAN_DIFF); EXPECT_LT(actual_maxval, MAX_ABS_DIFF); } + +//Test OpenCV issue 3075 is solved +class CV_GrfmtReadPNGColorPaletteWithAlphaTest : public cvtest::BaseTest +{ +public: + void run(int) + { + try + { + // First Test : Read PNG with alpha, imread flag -1 + Mat img = imread(string(ts->get_data_path()) + "readwrite/color_palette_alpha.png",-1); + if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + + ASSERT_TRUE(img.channels() == 4); + + uint8_t* img_data = (uint8_t*)img.data; + + // Verification first pixel is red in BGRA + ASSERT_TRUE(img_data[0] == 0x00); + ASSERT_TRUE(img_data[1] == 0x00); + ASSERT_TRUE(img_data[2] == 0xFF); + ASSERT_TRUE(img_data[3] == 0xFF); + + // Verification second pixel is red in BGRA + ASSERT_TRUE(img_data[4] == 0x00); + ASSERT_TRUE(img_data[5] == 0x00); + ASSERT_TRUE(img_data[6] == 0xFF); + ASSERT_TRUE(img_data[7] == 0xFF); + + // Second Test : Read PNG without alpha, imread flag -1 + img = imread(string(ts->get_data_path()) + "readwrite/color_palette_no_alpha.png",-1); + if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + + ASSERT_TRUE(img.channels() == 3); + + img_data = (uint8_t*)img.data; + + // Verification first pixel is red in BGR + ASSERT_TRUE(img_data[0] == 0x00); + ASSERT_TRUE(img_data[1] == 0x00); + ASSERT_TRUE(img_data[2] == 0xFF); + + // Verification second pixel is red in BGR + ASSERT_TRUE(img_data[3] == 0x00); + ASSERT_TRUE(img_data[4] == 0x00); + ASSERT_TRUE(img_data[5] == 0xFF); + + // Third Test : Read PNG with alpha, imread flag 1 + img = imread(string(ts->get_data_path()) + "readwrite/color_palette_alpha.png",1); + if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + + ASSERT_TRUE(img.channels() == 3); + + img_data = (uint8_t*)img.data; + + // Verification first pixel is red in BGR + ASSERT_TRUE(img_data[0] == 0x00); + ASSERT_TRUE(img_data[1] == 0x00); + ASSERT_TRUE(img_data[2] == 0xFF); + + // Verification second pixel is red in BGR + ASSERT_TRUE(img_data[3] == 0x00); + ASSERT_TRUE(img_data[4] == 0x00); + ASSERT_TRUE(img_data[5] == 0xFF); + + // Fourth Test : Read PNG without alpha, imread flag 1 + img = imread(string(ts->get_data_path()) + "readwrite/color_palette_no_alpha.png",1); + if (img.empty()) ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + + ASSERT_TRUE(img.channels() == 3); + + img_data = (uint8_t*)img.data; + + // Verification first pixel is red in BGR + ASSERT_TRUE(img_data[0] == 0x00); + ASSERT_TRUE(img_data[1] == 0x00); + ASSERT_TRUE(img_data[2] == 0xFF); + + // Verification second pixel is red in BGR + ASSERT_TRUE(img_data[3] == 0x00); + ASSERT_TRUE(img_data[4] == 0x00); + ASSERT_TRUE(img_data[5] == 0xFF); + } + catch(...) + { + ts->set_failed_test_info(cvtest::TS::FAIL_EXCEPTION); + } + ts->set_failed_test_info(cvtest::TS::OK); + } +}; + +TEST(Highgui_Image, read_png_color_palette_with_alpha) { CV_GrfmtReadPNGColorPaletteWithAlphaTest test; test.safe_run(); } #endif #ifdef HAVE_JPEG From 32635a68348c6f742706d75682cfa6e52b95edc8 Mon Sep 17 00:00:00 2001 From: Hanusz Leszek Date: Wed, 21 Aug 2013 12:33:51 +0200 Subject: [PATCH 03/22] using unsigned char instead of uint8_t to compile under windows --- modules/highgui/test/test_grfmt.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/highgui/test/test_grfmt.cpp b/modules/highgui/test/test_grfmt.cpp index ed16d1cde2..86954e3e10 100644 --- a/modules/highgui/test/test_grfmt.cpp +++ b/modules/highgui/test/test_grfmt.cpp @@ -295,7 +295,7 @@ public: ASSERT_TRUE(img.channels() == 4); - uint8_t* img_data = (uint8_t*)img.data; + unsigned char* img_data = (unsigned char*)img.data; // Verification first pixel is red in BGRA ASSERT_TRUE(img_data[0] == 0x00); @@ -315,7 +315,7 @@ public: ASSERT_TRUE(img.channels() == 3); - img_data = (uint8_t*)img.data; + img_data = (unsigned char*)img.data; // Verification first pixel is red in BGR ASSERT_TRUE(img_data[0] == 0x00); @@ -333,7 +333,7 @@ public: ASSERT_TRUE(img.channels() == 3); - img_data = (uint8_t*)img.data; + img_data = (unsigned char*)img.data; // Verification first pixel is red in BGR ASSERT_TRUE(img_data[0] == 0x00); @@ -351,7 +351,7 @@ public: ASSERT_TRUE(img.channels() == 3); - img_data = (uint8_t*)img.data; + img_data = (unsigned char*)img.data; // Verification first pixel is red in BGR ASSERT_TRUE(img_data[0] == 0x00); From de214950c4777ba7995ac06818cafe692ef225a4 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 21 Aug 2013 18:17:45 +0400 Subject: [PATCH 04/22] minor gpu TVL1 optical flow optimization: don't calc diff term if it is not used for epsilon criterion --- modules/gpu/src/tvl1flow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/gpu/src/tvl1flow.cpp b/modules/gpu/src/tvl1flow.cpp index b8322e2c46..9971324af1 100644 --- a/modules/gpu/src/tvl1flow.cpp +++ b/modules/gpu/src/tvl1flow.cpp @@ -222,7 +222,8 @@ void cv::gpu::OpticalFlowDual_TVL1_GPU::procOneScale(const GpuMat& I0, const Gpu { estimateU(I1wx, I1wy, grad, rho_c, p11, p12, p21, p22, u1, u2, diff, l_t, static_cast(theta)); - error = gpu::sum(diff, norm_buf)[0]; + if (epsilon > 0) + error = gpu::sum(diff, norm_buf)[0]; estimateDualVariables(u1, u2, p11, p12, p21, p22, taut); } From 8aae54b7f4a3130ec49763db072f9a76fa91fc58 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 21 Aug 2013 23:59:27 -0700 Subject: [PATCH 05/22] WindowsRT mode build warning fix. --- modules/contrib/src/inputoutput.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/contrib/src/inputoutput.cpp b/modules/contrib/src/inputoutput.cpp index d6d514f5b8..37510c666e 100644 --- a/modules/contrib/src/inputoutput.cpp +++ b/modules/contrib/src/inputoutput.cpp @@ -137,7 +137,7 @@ namespace cv char* fname; #ifdef HAVE_WINRT char fname_tmp[MAX_PATH]; - size_t copied = wcstombs(fname, FindFileData.cFileName, MAX_PATH); + size_t copied = wcstombs(fname_tmp, FindFileData.cFileName, MAX_PATH); CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1)); fname = fname_tmp; #else From a9e9ce859e6ba6964aaddd5fd735ce05cfccd41c Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Thu, 22 Aug 2013 15:46:13 +0400 Subject: [PATCH 06/22] Fix errors in usages of try_compile * There's no OPENCV_BINARY_DIR variable; * No need to append CMakeFiles/CMakeTmp, as CMake does it for you; * Output variables are unused; * Wrong usage of CMAKE_FLAGS; * Small quoting and style issues. --- cmake/OpenCVCRTLinkage.cmake | 4 ++-- cmake/OpenCVFindLibsGUI.cmake | 9 ++++----- cmake/OpenCVFindLibsVideo.cmake | 11 +++++------ cmake/OpenCVUtils.cmake | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cmake/OpenCVCRTLinkage.cmake b/cmake/OpenCVCRTLinkage.cmake index 26437669d5..8e689da806 100644 --- a/cmake/OpenCVCRTLinkage.cmake +++ b/cmake/OpenCVCRTLinkage.cmake @@ -26,8 +26,8 @@ else() set(HAVE_MSVC2012 TRUE) endif() -TRY_COMPILE(HAVE_WINRT_SDK - "${OPENCV_BINARY_DIR}/CMakeFiles/CMakeTmp" +try_compile(HAVE_WINRT_SDK + "${OpenCV_BINARY_DIR}" "${OpenCV_SOURCE_DIR}/cmake/checks/winrttest.cpp") if (ENABLE_WINRT_MODE AND HAVE_WINRT_SDK AND HAVE_MSVC2012 AND HAVE_MSPDK) diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 270853aeec..fb75344bb2 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -5,12 +5,11 @@ #--- Win32 UI --- ocv_clear_vars(HAVE_WIN32UI) if(WITH_WIN32UI) - TRY_COMPILE(HAVE_WIN32UI - "${OPENCV_BINARY_DIR}/CMakeFiles/CMakeTmp" + try_compile(HAVE_WIN32UI + "${OpenCV_BINARY_DIR}" "${OpenCV_SOURCE_DIR}/cmake/checks/win32uitest.cpp" - CMAKE_FLAGS "\"user32.lib\" \"gdi32.lib\"" - OUTPUT_VARIABLE OUTPUT) -endif(WITH_WIN32UI) + CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=user32;gdi32") +endif() # --- QT4 --- ocv_clear_vars(HAVE_QT HAVE_QT5) diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index d80531bf44..9572c72d7b 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -3,13 +3,12 @@ # ---------------------------------------------------------------------------- ocv_clear_vars(HAVE_VFW) -if (WITH_VFW) - TRY_COMPILE(HAVE_VFW - "${OPENCV_BINARY_DIR}/CMakeFiles/CMakeTmp" +if(WITH_VFW) + try_compile(HAVE_VFW + "${OpenCV_BINARY_DIR}" "${OpenCV_SOURCE_DIR}/cmake/checks/vfwtest.cpp" - CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=vfw32" - OUTPUT_VARIABLE OUTPUT) - endif(WITH_VFW) + CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=vfw32") +endif(WITH_VFW) # --- GStreamer --- ocv_clear_vars(HAVE_GSTREAMER) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index cefe3d812f..ddf0290673 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -77,7 +77,7 @@ MACRO(ocv_check_compiler_flag LANG FLAG RESULT) if(_fname) MESSAGE(STATUS "Performing Test ${RESULT}") TRY_COMPILE(${RESULT} - ${CMAKE_BINARY_DIR} + "${CMAKE_BINARY_DIR}" "${_fname}" COMPILE_DEFINITIONS "${FLAG}" OUTPUT_VARIABLE OUTPUT) From ec461a2ff0a3ebd3fb3ff33f1972062d1ab5ae0b Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 22 Aug 2013 17:37:48 +0400 Subject: [PATCH 07/22] added a test for ocl::norm --- modules/ocl/test/test_norm.cpp | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 modules/ocl/test/test_norm.cpp diff --git a/modules/ocl/test/test_norm.cpp b/modules/ocl/test/test_norm.cpp new file mode 100644 index 0000000000..2bd847068e --- /dev/null +++ b/modules/ocl/test/test_norm.cpp @@ -0,0 +1,63 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "test_precomp.hpp" + +typedef ::testing::TestWithParam normFixture; + +TEST_P(normFixture, DISABLED_accuracy) +{ + const cv::Size srcSize = GetParam(); + + cv::Mat src1(srcSize, CV_8UC1), src2(srcSize, CV_8UC1); + cv::randu(src1, 0, 2); + cv::randu(src2, 0, 2); + + cv::ocl::oclMat oclSrc1(src1), oclSrc2(src2); + + double value = cv::norm(src1, src2, cv::NORM_INF); + double oclValue = cv::ocl::norm(oclSrc1, oclSrc2, cv::NORM_INF); + + ASSERT_EQ(value, oclValue); +} + +INSTANTIATE_TEST_CASE_P(oclNormTest, normFixture, + ::testing::Values(cv::Size(500, 500), cv::Size(1000, 1000))); From 6c4ad9b597e6ca656d6c832f027f650663d1ecd5 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 22 Aug 2013 17:38:55 +0400 Subject: [PATCH 08/22] fixer error with incorrect condition --- modules/ocl/src/arithm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ocl/src/arithm.cpp b/modules/ocl/src/arithm.cpp index a591c82319..11e9c50f43 100644 --- a/modules/ocl/src/arithm.cpp +++ b/modules/ocl/src/arithm.cpp @@ -2336,7 +2336,7 @@ void cv::ocl::pow(const oclMat &x, double p, oclMat &y) return; } - CV_Assert((x.type() == y.type() && x.size() == y.size() && x.depth() == CV_32F) || x.depth() == CV_64F); + CV_Assert(x.depth() == CV_32F || x.depth() == CV_64F); y.create(x.size(), x.type()); string kernelName = "arithm_pow"; From 10860783efa388c3f2573e108b9a14ad91af3af7 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Thu, 22 Aug 2013 18:25:38 +0400 Subject: [PATCH 09/22] Added warnings-as-errors support for MSVC. --- cmake/OpenCVCompilerOptions.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index 4ba6469979..8ead1a1703 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -239,6 +239,10 @@ if(MSVC) set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /fp:fast") # !! important - be on the same wave with x64 compilers endif() endif() + + if(OPENCV_WARNINGS_ARE_ERRORS) + set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /WX") + endif() endif() # Extra link libs if the user selects building static libs: From 2519a219353a78c6286d915da5a5e8b47153b90f Mon Sep 17 00:00:00 2001 From: peng xiao Date: Fri, 23 Aug 2013 15:35:55 +0800 Subject: [PATCH 10/22] Fix a potential bug of ParallelLoopBodyWrapper::operator(Range) On a 32-bit compiler the calculation may result in data (size_t) overflow when running some paralleled algorithms (which can safely run on a 64-bit compiler). This bug is found when running OpenCV's Retina tutorial on 32bit VS2010. --- modules/core/src/parallel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index 1ae8c96314..27d7ecc038 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -144,9 +144,9 @@ namespace { cv::Range r; r.start = (int)(wholeRange.start + - ((size_t)sr.start*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); + ((uint64)sr.start*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); r.end = sr.end >= nstripes ? wholeRange.end : (int)(wholeRange.start + - ((size_t)sr.end*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); + ((uint64)sr.end*(wholeRange.end - wholeRange.start) + nstripes/2)/nstripes); (*body)(r); } cv::Range stripeRange() const { return cv::Range(0, nstripes); } From f826bd8bce08010786a1a6be66a353ba10974126 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 22 Aug 2013 11:46:09 +0400 Subject: [PATCH 11/22] removed NPP implementation --- modules/gpu/src/resize.cpp | 108 +++++++++---------------------- modules/gpu/test/test_resize.cpp | 47 +------------- 2 files changed, 33 insertions(+), 122 deletions(-) diff --git a/modules/gpu/src/resize.cpp b/modules/gpu/src/resize.cpp index 6850135428..0e8c865fa2 100644 --- a/modules/gpu/src/resize.cpp +++ b/modules/gpu/src/resize.cpp @@ -44,18 +44,7 @@ #if !defined HAVE_CUDA || defined(CUDA_DISABLER) -void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, double fy, int interpolation, Stream& s) -{ - (void)src; - (void)dst; - (void)dsize; - (void)fx; - (void)fy; - (void)interpolation; - (void)s; - - throw_nogpu(); -} +void cv::gpu::resize(const GpuMat&, GpuMat&, Size, double, double, int, Stream&) { throw_nogpu(); } #else // HAVE_CUDA @@ -69,94 +58,57 @@ namespace cv { namespace gpu { namespace device } }}} -void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, double fy, int interpolation, Stream& s) +void cv::gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx, double fy, int interpolation, Stream& stream) { - CV_Assert(src.depth() <= CV_32F && src.channels() <= 4); - CV_Assert(interpolation == INTER_NEAREST || interpolation == INTER_LINEAR - || interpolation == INTER_CUBIC || interpolation == INTER_AREA); - CV_Assert(!(dsize == Size()) || (fx > 0 && fy > 0)); + using namespace ::cv::gpu::device::imgproc; + + typedef void (*func_t)(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream); + static const func_t funcs[6][4] = + { + {resize_gpu , 0 /*resize_gpu*/ , resize_gpu , resize_gpu }, + {0 /*resize_gpu*/, 0 /*resize_gpu*/ , 0 /*resize_gpu*/, 0 /*resize_gpu*/}, + {resize_gpu , 0 /*resize_gpu*/, resize_gpu , resize_gpu }, + {resize_gpu , 0 /*resize_gpu*/ , resize_gpu , resize_gpu }, + {0 /*resize_gpu*/ , 0 /*resize_gpu*/ , 0 /*resize_gpu*/ , 0 /*resize_gpu*/ }, + {resize_gpu , 0 /*resize_gpu*/ , resize_gpu , resize_gpu } + }; + + CV_Assert( src.depth() <= CV_32F && src.channels() <= 4 ); + CV_Assert( interpolation == INTER_NEAREST || interpolation == INTER_LINEAR || interpolation == INTER_CUBIC || interpolation == INTER_AREA ); + CV_Assert( !(dsize == Size()) || (fx > 0 && fy > 0) ); if (dsize == Size()) + { dsize = Size(saturate_cast(src.cols * fx), saturate_cast(src.rows * fy)); + } else { fx = static_cast(dsize.width) / src.cols; fy = static_cast(dsize.height) / src.rows; } - if (dsize != dst.size()) - dst.create(dsize, src.type()); + + dst.create(dsize, src.type()); if (dsize == src.size()) { - if (s) - s.enqueueCopy(src, dst); + if (stream) + stream.enqueueCopy(src, dst); else src.copyTo(dst); return; } - cudaStream_t stream = StreamAccessor::getStream(s); + const func_t func = funcs[src.depth()][src.channels() - 1]; + + if (!func) + CV_Error(CV_StsUnsupportedFormat, "Unsupported combination of source and destination types"); Size wholeSize; Point ofs; src.locateROI(wholeSize, ofs); + PtrStepSzb wholeSrc(wholeSize.height, wholeSize.width, src.datastart, src.step); - bool useNpp = (src.type() == CV_8UC1 || src.type() == CV_8UC4); - useNpp = useNpp && (interpolation == INTER_NEAREST || interpolation == INTER_LINEAR); - - if (useNpp) - { - typedef NppStatus (*func_t)(const Npp8u * pSrc, NppiSize oSrcSize, int nSrcStep, NppiRect oSrcROI, Npp8u * pDst, int nDstStep, NppiSize dstROISize, - double xFactor, double yFactor, int eInterpolation); - - const func_t funcs[4] = { nppiResize_8u_C1R, 0, 0, nppiResize_8u_C4R }; - - static const int npp_inter[] = {NPPI_INTER_NN, NPPI_INTER_LINEAR, NPPI_INTER_CUBIC, 0, NPPI_INTER_LANCZOS}; - - NppiSize srcsz; - srcsz.width = wholeSize.width; - srcsz.height = wholeSize.height; - - NppiRect srcrect; - srcrect.x = ofs.x; - srcrect.y = ofs.y; - srcrect.width = src.cols; - srcrect.height = src.rows; - - NppiSize dstsz; - dstsz.width = dst.cols; - dstsz.height = dst.rows; - - NppStreamHandler h(stream); - - nppSafeCall( funcs[src.channels() - 1](src.datastart, srcsz, static_cast(src.step), srcrect, - dst.ptr(), static_cast(dst.step), dstsz, fx, fy, npp_inter[interpolation]) ); - - if (stream == 0) - cudaSafeCall( cudaDeviceSynchronize() ); - } - else - { - using namespace ::cv::gpu::device::imgproc; - - typedef void (*func_t)(PtrStepSzb src, PtrStepSzb srcWhole, int xoff, int yoff, float fx, float fy, PtrStepSzb dst, int interpolation, cudaStream_t stream); - - static const func_t funcs[6][4] = - { - {resize_gpu , 0 /*resize_gpu*/ , resize_gpu , resize_gpu }, - {0 /*resize_gpu*/, 0 /*resize_gpu*/ , 0 /*resize_gpu*/, 0 /*resize_gpu*/}, - {resize_gpu , 0 /*resize_gpu*/, resize_gpu , resize_gpu }, - {resize_gpu , 0 /*resize_gpu*/ , resize_gpu , resize_gpu }, - {0 /*resize_gpu*/ , 0 /*resize_gpu*/ , 0 /*resize_gpu*/ , 0 /*resize_gpu*/ }, - {resize_gpu , 0 /*resize_gpu*/ , resize_gpu , resize_gpu } - }; - - const func_t func = funcs[src.depth()][src.channels() - 1]; - CV_Assert(func != 0); - - func(src, PtrStepSzb(wholeSize.height, wholeSize.width, src.datastart, src.step), ofs.x, ofs.y, - static_cast(1.0 / fx), static_cast(1.0 / fy), dst, interpolation, stream); - } + func(src, wholeSrc, ofs.x, ofs.y, static_cast(1.0 / fx), static_cast(1.0 / fy), dst, interpolation, StreamAccessor::getStream(stream)); } #endif // HAVE_CUDA diff --git a/modules/gpu/test/test_resize.cpp b/modules/gpu/test/test_resize.cpp index 593c891e6a..88e6b1cab7 100644 --- a/modules/gpu/test/test_resize.cpp +++ b/modules/gpu/test/test_resize.cpp @@ -155,7 +155,7 @@ GPU_TEST_P(Resize, Accuracy) INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine( ALL_DEVICES, DIFFERENT_SIZES, - testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), + testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), testing::Values(0.3, 0.5, 1.5, 2.0), testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)), WHOLE_SUBMAT)); @@ -201,50 +201,9 @@ GPU_TEST_P(ResizeSameAsHost, Accuracy) INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine( ALL_DEVICES, DIFFERENT_SIZES, - testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), + testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), testing::Values(0.3, 0.5), - testing::Values(Interpolation(cv::INTER_AREA), Interpolation(cv::INTER_NEAREST)), //, Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC) + testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_AREA)), WHOLE_SUBMAT)); -/////////////////////////////////////////////////////////////////// -// Test NPP - -PARAM_TEST_CASE(ResizeNPP, cv::gpu::DeviceInfo, MatType, double, Interpolation) -{ - cv::gpu::DeviceInfo devInfo; - double coeff; - int interpolation; - int type; - - virtual void SetUp() - { - devInfo = GET_PARAM(0); - type = GET_PARAM(1); - coeff = GET_PARAM(2); - interpolation = GET_PARAM(3); - - cv::gpu::setDevice(devInfo.deviceID()); - } -}; - -GPU_TEST_P(ResizeNPP, Accuracy) -{ - cv::Mat src = readImageType("stereobp/aloe-L.png", type); - ASSERT_FALSE(src.empty()); - - cv::gpu::GpuMat dst; - cv::gpu::resize(loadMat(src), dst, cv::Size(), coeff, coeff, interpolation); - - cv::Mat dst_gold; - resizeGold(src, dst_gold, coeff, coeff, interpolation); - - EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-1); -} - -INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeNPP, testing::Combine( - ALL_DEVICES, - testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)), - testing::Values(0.3, 0.5, 1.5, 2.0), - testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR)))); - #endif // HAVE_CUDA From 030fa5673e625bcf567dd91efb4c234a3f99a627 Mon Sep 17 00:00:00 2001 From: Kirill Kornyakov Date: Fri, 23 Aug 2013 12:34:35 +0400 Subject: [PATCH 12/22] bugfix-for-3231 --- samples/gpu/super_resolution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/gpu/super_resolution.cpp b/samples/gpu/super_resolution.cpp index 4e83c71aba..07dda775b4 100644 --- a/samples/gpu/super_resolution.cpp +++ b/samples/gpu/super_resolution.cpp @@ -211,7 +211,7 @@ int main(int argc, const char* argv[]) #if defined(HAVE_OPENCV_OCL) cout << "Mode : " << (useCuda ? "CUDA" : useOcl? "OpenCL" : "CPU") << endl; #else - cout << "Mode : " << (useGpu ? "CUDA" : "CPU") << endl; + cout << "Mode : " << (useCuda ? "CUDA" : "CPU") << endl; #endif } From cf34b3d65b189eb68a28919e8ffbc8a3c60755a4 Mon Sep 17 00:00:00 2001 From: MarkBelmont Date: Fri, 23 Aug 2013 16:39:39 +0800 Subject: [PATCH 13/22] Changed the brief description of function Mat::colRange from "Create a matrix header for the specified row span." to "Create a matrix header for the specified column span." --- modules/core/doc/basic_structures.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/doc/basic_structures.rst b/modules/core/doc/basic_structures.rst index a3f7f92b65..16d7e500a8 100644 --- a/modules/core/doc/basic_structures.rst +++ b/modules/core/doc/basic_structures.rst @@ -1292,7 +1292,7 @@ The method makes a new header for the specified row span of the matrix. Similarl Mat::colRange ------------- -Creates a matrix header for the specified row span. +Creates a matrix header for the specified column span. .. ocv:function:: Mat Mat::colRange(int startcol, int endcol) const From 16814c7fb186a0788f27d77d021ab27e5e79bc7e Mon Sep 17 00:00:00 2001 From: Alexander Shishkov Date: Fri, 23 Aug 2013 12:51:50 +0400 Subject: [PATCH 14/22] Update build_framework.py --- platforms/ios/build_framework.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index 23da296a41..cb3788f7d5 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -75,6 +75,7 @@ def put_framework_together(srcroot, dstroot): dstdir = "Versions/A" os.makedirs(dstdir + "/Resources") + tdir0 = "../build/" + targetlist[0] # copy headers shutil.copytree(tdir0 + "/install/include/opencv2", dstdir + "/Headers") @@ -83,7 +84,7 @@ def put_framework_together(srcroot, dstroot): os.system("lipo -create " + wlist + " -o " + dstdir + "/opencv2") # copy Info.plist - shutil.copyfile("../build/ios/Info.plist", dstdir + "/Resources/Info.plist") + shutil.copyfile(tdir0 + "/ios/Info.plist", dstdir + "/Resources/Info.plist") # make symbolic links os.symlink("A", "Versions/Current") @@ -108,4 +109,4 @@ if __name__ == "__main__": print "Usage:\n\t./build_framework.py \n\n" sys.exit(0) - build_framework(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../..")), os.path.abspath(sys.argv[1])) \ No newline at end of file + build_framework(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../..")), os.path.abspath(sys.argv[1])) From 396f6bb55fd1264b939581a9540f3d2a29aaa38a Mon Sep 17 00:00:00 2001 From: Alexander Shishkov Date: Fri, 23 Aug 2013 13:41:19 +0400 Subject: [PATCH 15/22] fixed problems with building iOS version --- cmake/OpenCVFindLibsGrfmt.cmake | 2 +- modules/highgui/CMakeLists.txt | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmake/OpenCVFindLibsGrfmt.cmake b/cmake/OpenCVFindLibsGrfmt.cmake index 9381350c0b..f27a302ab7 100644 --- a/cmake/OpenCVFindLibsGrfmt.cmake +++ b/cmake/OpenCVFindLibsGrfmt.cmake @@ -114,7 +114,7 @@ if(WITH_JASPER) endif() # --- libpng (optional, should be searched after zlib) --- -if(WITH_PNG AND NOT IOS) +if(WITH_PNG) if(BUILD_PNG) ocv_clear_vars(PNG_FOUND) else() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index b49d93a965..d5545a7cef 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -210,12 +210,14 @@ if(HAVE_AVFOUNDATION) list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore") endif() -if(HAVE_QUICKTIME) - list(APPEND highgui_srcs src/cap_qt.cpp) - list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore") -elseif(HAVE_QTKIT) - list(APPEND highgui_srcs src/cap_qtkit.mm) - list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit") +if (NOT IOS) + if(HAVE_QUICKTIME) + list(APPEND highgui_srcs src/cap_qt.cpp) + list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore") + elseif(HAVE_QTKIT) + list(APPEND highgui_srcs src/cap_qtkit.mm) + list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit") + endif() endif() if(IOS) From 3b05acf9362a4e554a8590639a1fda7a2658d4e9 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 22 Aug 2013 12:03:17 +0400 Subject: [PATCH 16/22] reorganize code for further modifiction --- modules/gpu/src/cuda/resize.cu | 136 +++++++++++++-------------------- 1 file changed, 52 insertions(+), 84 deletions(-) diff --git a/modules/gpu/src/cuda/resize.cu b/modules/gpu/src/cuda/resize.cu index e720297678..c244ca7d6e 100644 --- a/modules/gpu/src/cuda/resize.cu +++ b/modules/gpu/src/cuda/resize.cu @@ -42,20 +42,19 @@ #if !defined CUDA_DISABLER -#include "internal_shared.hpp" +#include +#include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/border_interpolate.hpp" #include "opencv2/gpu/device/vec_traits.hpp" #include "opencv2/gpu/device/vec_math.hpp" #include "opencv2/gpu/device/saturate_cast.hpp" #include "opencv2/gpu/device/filters.hpp" -#include -#include namespace cv { namespace gpu { namespace device { namespace imgproc { - template __global__ void resize(const Ptr2D src, float fx, float fy, PtrStepSz dst) + template __global__ void resize(const Ptr2D src, const float fx, const float fy, PtrStepSz dst) { const int x = blockDim.x * blockIdx.x + threadIdx.x; const int y = blockDim.y * blockIdx.y + threadIdx.y; @@ -69,23 +68,12 @@ namespace cv { namespace gpu { namespace device } } - template __global__ void resize_area(const Ptr2D src, float fx, float fy, PtrStepSz dst) - { - const int x = blockDim.x * blockIdx.x + threadIdx.x; - const int y = blockDim.y * blockIdx.y + threadIdx.y; - - if (x < dst.cols && y < dst.rows) - { - dst(y, x) = saturate_cast(src(y, x)); - } - } - template