From 969bb1ef44bf87af3e4c82c727d2bb95c8045ce5 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Tue, 26 Sep 2017 14:45:27 +0300 Subject: [PATCH] Fixed review comments --- modules/ximgproc/CMakeLists.txt | 3 - .../include/opencv2/ximgproc/peilin.hpp | 51 ++------- modules/ximgproc/samples/peilin.cpp | 102 ++++++++---------- modules/ximgproc/src/peilin.cpp | 44 +------- 4 files changed, 57 insertions(+), 143 deletions(-) diff --git a/modules/ximgproc/CMakeLists.txt b/modules/ximgproc/CMakeLists.txt index 62a00bd15..6e163ca76 100644 --- a/modules/ximgproc/CMakeLists.txt +++ b/modules/ximgproc/CMakeLists.txt @@ -1,5 +1,2 @@ set(the_description "Extended image processing module. It includes edge-aware filters and etc.") ocv_define_module(ximgproc opencv_core opencv_imgproc opencv_calib3d opencv_imgcodecs WRAP python) - -file(COPY samples/peilin_plane.png DESTINATION ${OpenCV_BINARY_DIR}/bin) -file(COPY samples/peilin_shape.png DESTINATION ${OpenCV_BINARY_DIR}/bin) \ No newline at end of file diff --git a/modules/ximgproc/include/opencv2/ximgproc/peilin.hpp b/modules/ximgproc/include/opencv2/ximgproc/peilin.hpp index 1d865270d..6c7aa56da 100644 --- a/modules/ximgproc/include/opencv2/ximgproc/peilin.hpp +++ b/modules/ximgproc/include/opencv2/ximgproc/peilin.hpp @@ -1,43 +1,7 @@ -/*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. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2008, Willow Garage Inc., 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*/ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + #ifndef __OPENCV_PEILIN_HPP__ #define __OPENCV_PEILIN_HPP__ @@ -45,18 +9,19 @@ namespace cv { - //! @addtogroup ximgproc_filters + //! @addtogroup ximgproc //! @{ /** * @brief Calculates an affine transformation that normalize given image using Pei&Lin Normalization. * - * Assume given image :math:`I=T(\bar{I})` where :math:`\bar{I}` is a normalized image and :math:`T` is is an affine transformation distorting this image by translation, rotation, scaling and skew. - * The function returns an affine transformation matrix corresponding to the transformation :math:`T^{-1}` described in [PeiLin95]. + * Assume given image \f$I=T(\bar{I})\f$ where \f$\bar{I}\f$ is a normalized image and \f$T\f$ is an affine transformation distorting this image by translation, rotation, scaling and skew. + * The function returns an affine transformation matrix corresponding to the transformation \f$T^{-1}\f$ described in [PeiLin95]. * For more details about this implementation, please see * [PeiLin95] Soo-Chang Pei and Chao-Nan Lin. Image normalization for pattern recognition. Image and Vision Computing, Vol. 13, N.10, pp. 711-723, 1995. * * @param I Given transformed image. + * @return Transformation matrix corresponding to inversed image transformation */ CV_EXPORTS Matx23d PeiLinNormalization ( InputArray I ); /** @overload */ diff --git a/modules/ximgproc/samples/peilin.cpp b/modules/ximgproc/samples/peilin.cpp index 79b7fe3e8..75e934bdc 100644 --- a/modules/ximgproc/samples/peilin.cpp +++ b/modules/ximgproc/samples/peilin.cpp @@ -1,71 +1,59 @@ -/*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. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2008, Willow Garage Inc., 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 #include #include +#include + +static void help() +{ + std::cout << "\nThis program demonstrates Pei&Lin Normalization\n" + "Usage:\n" + "./peilin [image1_name -- default is ../data/peilin_plane.png] [image2_name -- default is ../data/peilin_shape.png]\n" << std::endl; +} + static inline cv::Mat operator& ( const cv::Mat& lhs, const cv::Matx23d& rhs ) { - cv::Mat ret; - cv::warpAffine ( lhs, ret, rhs, lhs.size(), cv::INTER_LINEAR ); - return ret; + cv::Mat ret; + cv::warpAffine ( lhs, ret, rhs, lhs.size(), cv::INTER_LINEAR ); + return ret; } static inline cv::Mat operator& ( const cv::Matx23d& lhs, const cv::Mat& rhs ) { - cv::Mat ret; - cv::warpAffine ( rhs, ret, lhs, rhs.size(), cv::INTER_LINEAR | cv::WARP_INVERSE_MAP ); - return ret; + cv::Mat ret; + cv::warpAffine ( rhs, ret, lhs, rhs.size(), cv::INTER_LINEAR | cv::WARP_INVERSE_MAP ); + return ret; } -int main() +int main(int argc, char** argv) { - cv::Mat I = cv::imread ( "../data/peilin_plane.png", 0 ); - cv::Mat N = I & cv::PeiLinNormalization ( I ); - cv::Mat J = cv::imread ( "../data/peilin_shape.png", 0 ); - cv::Mat D = cv::PeiLinNormalization ( J ) & I; - cv::imshow ( "I", I ); - cv::imshow ( "N", N ); - cv::imshow ( "J", J ); - cv::imshow ( "D", D ); - cv::waitKey(); - return 0; + cv::CommandLineParser parser(argc, argv, "{help h | | }{ @input1 | ../data/peilin_plane.png | }{ @input2 | ../data/peilin_plane.png | }"); + if (parser.has("help")) + { + help(); + return 0; + } + std::string filename1 = parser.get("@input1"); + std::string filename2 = parser.get("@input2"); + + cv::Mat I = cv::imread(filename1, 0); + if (I.empty()) + { + std::cout << "Couldn't open image " << filename1 << std::endl; + return 0; + } + cv::Mat J = cv::imread(filename2, 0); + if (J.empty()) + { + std::cout << "Couldn't open image " << filename2 << std::endl; + return 0; + } + cv::Mat N = I & cv::PeiLinNormalization ( I ); + cv::Mat D = cv::PeiLinNormalization ( J ) & I; + cv::imshow ( "I", I ); + cv::imshow ( "N", N ); + cv::imshow ( "J", J ); + cv::imshow ( "D", D ); + cv::waitKey(); + return 0; } diff --git a/modules/ximgproc/src/peilin.cpp b/modules/ximgproc/src/peilin.cpp index 9f6c7af16..959f2245b 100644 --- a/modules/ximgproc/src/peilin.cpp +++ b/modules/ximgproc/src/peilin.cpp @@ -1,43 +1,7 @@ -/*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. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2008, Willow Garage Inc., 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*/ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + #include "precomp.hpp" namespace cv