created GPU new-style test project, ported StereoBP test
authorAlexey Spizhevoy <no@email>
Wed, 16 Feb 2011 11:38:58 +0000 (11:38 +0000)
committerAlexey Spizhevoy <no@email>
Wed, 16 Feb 2011 11:38:58 +0000 (11:38 +0000)
modules/gpu/CMakeLists.txt
modules/gpu/test/CMakeLists.txt [new file with mode: 0644]
modules/gpu/test/test_main.cpp [new file with mode: 0644]
modules/gpu/test/test_precomp.cpp [new file with mode: 0644]
modules/gpu/test/test_precomp.hpp [new file with mode: 0644]
modules/gpu/test/test_stereo_bp.cpp [new file with mode: 0644]
modules/objdetect/test/test_precomp.hpp
tests/CMakeLists.txt

index 7e8389f..d094956 100644 (file)
@@ -147,4 +147,8 @@ install(FILES ${lib_hdrs}
 #      DESTINATION include/opencv2/${name}/device
 #      COMPONENT main)
 
-
+# Test files processing is in the separated directory to avoid 'Src' source 
+# filter creation in Visual Studio 
+if(BUILD_TESTS AND NOT ANDROID AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
+       add_subdirectory(test)
+endif()
\ No newline at end of file
diff --git a/modules/gpu/test/CMakeLists.txt b/modules/gpu/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..744f151
--- /dev/null
@@ -0,0 +1,53 @@
+set(the_target "opencv_test_${name}")  \r
+project(${the_target})\r
+\r
+include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include"\r
+                    "${CMAKE_CURRENT_SOURCE_DIR}/.."\r
+                    "${CMAKE_CURRENT_BINARY_DIR}")                                             \r
+\r
+set(test_deps opencv_${name} opencv_ts opencv_highgui ${DEPS})\r
+foreach(d ${test_deps})\r
+    if(${d} MATCHES "opencv_")\r
+        if(${d} MATCHES "opencv_lapack")\r
+        else()\r
+            string(REPLACE "opencv_" "${CMAKE_CURRENT_SOURCE_DIR}/../../" d_dir ${d})\r
+            include_directories("${d_dir}/include")\r
+        endif()\r
+    endif()\r
+endforeach()\r
+\r
+file(GLOB test_srcs "*.cpp")\r
+file(GLOB test_hdrs "*.h*")\r
+\r
+add_executable(${the_target} ${test_srcs} ${test_hdrs})\r
+\r
+if(PCHSupport_FOUND)\r
+    set(pch_header ${CMAKE_CURRENT_SOURCE_DIR}/test_precomp.hpp)\r
+    if(${CMAKE_GENERATOR} MATCHES "Visual*" OR ${CMAKE_GENERATOR} MATCHES "Xcode*")\r
+        if(${CMAKE_GENERATOR} MATCHES "Visual*")\r
+            set(${the_target}_pch "test_precomp.cpp")\r
+        endif()            \r
+        add_native_precompiled_header(${the_target} ${pch_header})\r
+    elseif(CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_GENERATOR} MATCHES ".*Makefiles")\r
+        add_precompiled_header(${the_target} ${pch_header})\r
+    endif()\r
+endif()\r
+\r
+# Additional target properties\r
+set_target_properties(${the_target} PROPERTIES\r
+    DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"\r
+    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/"\r
+    )\r
+\r
+add_dependencies(${the_target} ${test_deps})\r
+\r
+# Add the required libraries for linking:\r
+target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${test_deps})\r
+\r
+enable_testing()\r
+get_target_property(LOC ${the_target} LOCATION)\r
+add_test(${the_target} "${LOC}")\r
+\r
+if(WIN32)\r
+    install(TARGETS ${the_target} RUNTIME DESTINATION bin COMPONENT main)\r
+endif()
\ No newline at end of file
diff --git a/modules/gpu/test/test_main.cpp b/modules/gpu/test/test_main.cpp
new file mode 100644 (file)
index 0000000..c4b5e24
--- /dev/null
@@ -0,0 +1,3 @@
+#include "test_precomp.hpp"\r
+\r
+CV_TEST_MAIN("gpu")\r
diff --git a/modules/gpu/test/test_precomp.cpp b/modules/gpu/test/test_precomp.cpp
new file mode 100644 (file)
index 0000000..26a8f3f
--- /dev/null
@@ -0,0 +1 @@
+#include "test_precomp.hpp"\r
diff --git a/modules/gpu/test/test_precomp.hpp b/modules/gpu/test/test_precomp.hpp
new file mode 100644 (file)
index 0000000..228fdb8
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef __OPENCV_TEST_PRECOMP_HPP__\r
+#define __OPENCV_TEST_PRECOMP_HPP__\r
+\r
+#include "opencv2/ts/ts.hpp"\r
+#include "opencv2/gpu/gpu.hpp"\r
+#include "opencv2/highgui/highgui.hpp"\r
+\r
+static inline bool check_and_treat_gpu_exception(const cv::Exception& e, cvtest::TS* ts)\r
+{\r
+    switch (e.code)\r
+    {\r
+    case CV_GpuNotSupported: \r
+        ts->printf(cvtest::TS::LOG, "\nGpu not supported by the library"); \r
+        break;\r
+\r
+    case CV_GpuApiCallError: \r
+        ts->printf(cvtest::TS::LOG, "\nGPU Error: %s", e.what());\r
+        break;\r
+\r
+    case CV_GpuNppCallError: \r
+        ts->printf(cvtest::TS::LOG, "\nNPP Error: %s", e.what());\r
+        break;\r
+\r
+    default:\r
+        return false;\r
+    }\r
+    ts->set_failed_test_info(cvtest::TS::FAIL_GENERIC);                        \r
+    return true;\r
+}\r
+\r
+#endif\r
diff --git a/modules/gpu/test/test_stereo_bp.cpp b/modules/gpu/test/test_stereo_bp.cpp
new file mode 100644 (file)
index 0000000..fcf01f7
--- /dev/null
@@ -0,0 +1,91 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+//  By downloading, copying, installing or using the software you agree to this license.\r
+//  If you do not agree to this license, do not download, install,\r
+//  copy or use the software.\r
+//\r
+//\r
+//                        Intel License Agreement\r
+//                For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+//   * Redistribution's of source code must retain the above copyright notice,\r
+//     this list of conditions and the following disclaimer.\r
+//\r
+//   * Redistribution's in binary form must reproduce the above copyright notice,\r
+//     this list of conditions and the following disclaimer in the documentation\r
+//     and/or other materials provided with the distribution.\r
+//\r
+//   * The name of Intel Corporation may not be used to endorse or promote products\r
+//     derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+#include "test_precomp.hpp"\r
+\r
+struct CV_GpuStereoBPTest : public cvtest::BaseTest\r
+{\r
+    void run(int )\r
+    {\r
+        cv::Mat img_l = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");\r
+        cv::Mat img_r = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-R.png");\r
+        cv::Mat img_template = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", 0);\r
+\r
+        if (img_l.empty() || img_r.empty() || img_template.empty())\r
+        {\r
+            ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA);\r
+            return;\r
+        }\r
+\r
+        try\r
+        {\r
+            {cv::Mat temp; cv::cvtColor(img_l, temp, CV_BGR2BGRA); cv::swap(temp, img_l);}\r
+            {cv::Mat temp; cv::cvtColor(img_r, temp, CV_BGR2BGRA); cv::swap(temp, img_r);}\r
+\r
+            cv::gpu::GpuMat disp;\r
+            cv::gpu::StereoBeliefPropagation bpm(64, 8, 2, 25, 0.1f, 15, 1, CV_16S);\r
+\r
+            bpm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), disp);\r
+\r
+            //cv::imwrite(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", disp);\r
+\r
+            disp.convertTo(disp, img_template.type());\r
+\r
+           double norm = cv::norm(disp, img_template, cv::NORM_INF);\r
+               if (norm >= 0.5)\r
+           {\r
+               ts->printf(cvtest::TS::LOG, "\nStereoBP norm = %f\n", norm);\r
+               ts->set_failed_test_info(cvtest::TS::FAIL_GENERIC);\r
+               return;\r
+           }\r
+       }\r
+       catch(const cv::Exception& e)\r
+       {\r
+           if (!check_and_treat_gpu_exception(e, ts))\r
+               throw;\r
+           return;\r
+       }\r
+\r
+        ts->set_failed_test_info(cvtest::TS::OK);\r
+    }\r
+};\r
+\r
+TEST(StereoBP, StereoBP) { CV_GpuStereoBPTest test; test.safe_run(); }
\ No newline at end of file
index 67dd004..77ff308 100644 (file)
@@ -3,8 +3,7 @@
 
 #include "opencv2/ts/ts.hpp"
 #include "opencv2/objdetect/objdetect.hpp"
-#include "opencv2/imgproc/imgproc_c.h"
+#include "opencv2/imgproc/imgproc.hpp"
 #include "opencv2/highgui/highgui.hpp"
-#include <iostream>
 
 #endif
index 3c7bcdf..ef95f23 100644 (file)
@@ -9,6 +9,6 @@
 #    set (BUILD_TESTS_GPU OFF CACHE BOOL "Build tests GPU")
        
 #    if(BUILD_TESTS_GPU AND WITH_CUDA)
-        add_subdirectory(gpu)
+#        add_subdirectory(gpu)
 #       endif()
 #endif()