diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so old mode 100644 new mode 100755 diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so old mode 100644 new mode 100755 diff --git a/3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so new file mode 100755 index 0000000000..646ae716ec Binary files /dev/null and b/3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so differ diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.1.1.so b/3rdparty/lib/armeabi/libnative_camera_r4.1.1.so old mode 100644 new mode 100755 diff --git a/3rdparty/lib/armeabi/libnative_camera_r4.2.0.so b/3rdparty/lib/armeabi/libnative_camera_r4.2.0.so new file mode 100755 index 0000000000..816669e37c Binary files /dev/null and b/3rdparty/lib/armeabi/libnative_camera_r4.2.0.so differ diff --git a/3rdparty/lib/mips/libnative_camera_r4.0.3.so b/3rdparty/lib/mips/libnative_camera_r4.0.3.so old mode 100644 new mode 100755 diff --git a/3rdparty/lib/mips/libnative_camera_r4.1.1.so b/3rdparty/lib/mips/libnative_camera_r4.1.1.so new file mode 100755 index 0000000000..7ee4f25766 Binary files /dev/null and b/3rdparty/lib/mips/libnative_camera_r4.1.1.so differ diff --git a/3rdparty/lib/mips/libnative_camera_r4.2.0.so b/3rdparty/lib/mips/libnative_camera_r4.2.0.so new file mode 100755 index 0000000000..33d7745ad8 Binary files /dev/null and b/3rdparty/lib/mips/libnative_camera_r4.2.0.so differ diff --git a/3rdparty/lib/x86/libnative_camera_r4.1.1.so b/3rdparty/lib/x86/libnative_camera_r4.1.1.so old mode 100644 new mode 100755 diff --git a/3rdparty/lib/x86/libnative_camera_r4.2.0.so b/3rdparty/lib/x86/libnative_camera_r4.2.0.so new file mode 100755 index 0000000000..7fe74d21ab Binary files /dev/null and b/3rdparty/lib/x86/libnative_camera_r4.2.0.so differ diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake index 25cef0f98b..a282207d83 100644 --- a/android/android.toolchain.cmake +++ b/android/android.toolchain.cmake @@ -596,6 +596,9 @@ if( BUILD_WITH_ANDROID_NDK ) endif() if( NOT __availableToolchains ) file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) + if( __availableToolchains ) + list(SORT __availableToolchains) # we need clang to go after gcc + endif() __LIST_FILTER( __availableToolchains "^[.]" ) __LIST_FILTER( __availableToolchains "llvm" ) __GLOB_NDK_TOOLCHAINS( __availableToolchains ) diff --git a/android/scripts/camera_build.conf b/android/scripts/camera_build.conf index 60c56d1c24..e72fddddbd 100644 --- a/android/scripts/camera_build.conf +++ b/android/scripts/camera_build.conf @@ -16,3 +16,8 @@ native_camera_r4.0.0; armeabi-v7a; 14; /home/alexander/Projects/AndroidSource/4. native_camera_r4.1.1; armeabi; 14; /home/alexander/Projects/AndroidSource/4.1.1 native_camera_r4.1.1; armeabi-v7a; 14; /home/alexander/Projects/AndroidSource/4.1.1 native_camera_r4.1.1; x86; 14; /home/alexander/Projects/AndroidSource/4.1.1 +native_camera_r4.1.1; mips; 14; /home/alexander/Projects/AndroidSource/4.1.1_mips +native_camera_r4.2.0; armeabi-v7a; 14; /home/alexander/Projects/AndroidSource/4.2 +native_camera_r4.2.0; armeabi; 14; /home/alexander/Projects/AndroidSource/4.2 +native_camera_r4.2.0; x86; 14; /home/alexander/Projects/AndroidSource/4.2 +native_camera_r4.2.0; mips; 14; /home/alexander/Projects/AndroidSource/4.2 diff --git a/android/scripts/cmake_android_all_cameras.py b/android/scripts/cmake_android_all_cameras.py index 75470e9c8d..afcab63a75 100755 --- a/android/scripts/cmake_android_all_cameras.py +++ b/android/scripts/cmake_android_all_cameras.py @@ -33,20 +33,27 @@ for s in ConfFile.readlines(): continue shutil.rmtree(os.path.join(AndroidTreeRoot, "out", "target", "product", "generic", "system"), ignore_errors=True) + + LinkerLibs = os.path.join(AndroidTreeRoot, "bin_arm", "system") if (Arch == "x86"): - shutil.copytree(os.path.join(AndroidTreeRoot, "bin_x86", "system"), os.path.join(AndroidTreeRoot, "out", "target", "product", "generic", "system")) + LinkerLibs = os.path.join(AndroidTreeRoot, "bin_x86", "system") elif (Arch == "mips"): - shutil.copytree(os.path.join(AndroidTreeRoot, "bin_mips", "system"), os.path.join(AndroidTreeRoot, "out", "target", "product", "generic", "system")) - else: - shutil.copytree(os.path.join(AndroidTreeRoot, "bin_arm", "system"), os.path.join(AndroidTreeRoot, "out", "target", "product", "generic", "system")) + LinkerLibs = os.path.join(AndroidTreeRoot, "bin_mips", "system") + + if (not os.path.exists(LinkerLibs)): + print("Error: Paltform libs for linker in path \"%s\" not found" % LinkerLibs) + print("Building %s for %s\t[\033[91mFAILED\033[0m]" % (MakeTarget, Arch)) + continue + + shutil.copytree(LinkerLibs, os.path.join(AndroidTreeRoot, "out", "target", "product", "generic", "system")) os.chdir(BuildDir) BuildLog = os.path.join(BuildDir, "build.log") CmakeCmdLine = "cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_SOURCE_TREE=\"%s\" -DANDROID_NATIVE_API_LEVEL=\"%s\" -DANDROID_ABI=\"%s\" -DANDROID_STL=stlport_static ../../ > \"%s\" 2>&1" % (AndroidTreeRoot, NativeApiLevel, Arch, BuildLog) MakeCmdLine = "make %s >> \"%s\" 2>&1" % (MakeTarget, BuildLog); - print(CmakeCmdLine) + #print(CmakeCmdLine) os.system(CmakeCmdLine) - print(MakeCmdLine) + #print(MakeCmdLine) os.system(MakeCmdLine) os.chdir(HomeDir) CameraLib = os.path.join(BuildDir, "lib", Arch, "lib" + MakeTarget + ".so") diff --git a/android/service/engine/AndroidManifest.xml b/android/service/engine/AndroidManifest.xml index fdf6303d9a..c6aa47cf34 100644 --- a/android/service/engine/AndroidManifest.xml +++ b/android/service/engine/AndroidManifest.xml @@ -1,10 +1,10 @@ + android:versionCode="23@ANDROID_PLATFORM_VERSION_CODE@" + android:versionName="2.3" > - + #include #include - -// OpenCV Manager package name -#define OPENCV_ENGINE_PACKAGE "org.opencv.engine" -// Class name of OpenCV engine binder object. Is needned for connection to service -#define OPECV_ENGINE_CLASSNAME "org.opencv.engine.OpenCVEngineInterface" +#include "EngineCommon.h" enum EngineMethonID { diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index 6d801d7c31..ee2f8bcbb2 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -179,7 +179,7 @@ unset(__android_project_chain CACHE) #add_android_project(target_name ${path} NATIVE_DEPS opencv_core LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11) macro(add_android_project target path) # parse arguments - set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA) + set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST) set(__varname "android_proj_") foreach(v ${android_proj_arglist}) set(${__varname}${v} "") @@ -220,9 +220,13 @@ macro(add_android_project target path) # get project sources file(GLOB_RECURSE android_proj_files RELATIVE "${path}" "${path}/res/*" "${path}/src/*") + if(NOT android_proj_IGNORE_MANIFEST) + list(APPEND android_proj_files ${ANDROID_MANIFEST_FILE}) + endif() + # copy sources out from the build tree set(android_proj_file_deps "") - foreach(f ${android_proj_files} ${ANDROID_MANIFEST_FILE}) + foreach(f ${android_proj_files}) add_custom_command( OUTPUT "${android_proj_bin_dir}/${f}" COMMAND ${CMAKE_COMMAND} -E copy "${path}/${f}" "${android_proj_bin_dir}/${f}" @@ -324,6 +328,7 @@ macro(add_android_project target path) install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT main) get_filename_component(sample_dir "${path}" NAME) #java part + list(REMOVE_ITEM android_proj_files ${ANDROID_MANIFEST_FILE}) foreach(f ${android_proj_files} ${ANDROID_MANIFEST_FILE}) get_filename_component(install_subdir "${f}" PATH) install(FILES "${android_proj_bin_dir}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT main) diff --git a/cmake/OpenCVDetectCUDA.cmake b/cmake/OpenCVDetectCUDA.cmake index 2b2cf373eb..c1cd83866b 100644 --- a/cmake/OpenCVDetectCUDA.cmake +++ b/cmake/OpenCVDetectCUDA.cmake @@ -3,8 +3,13 @@ if(${CMAKE_VERSION} VERSION_LESS "2.8.3") return() endif() -if (NOT MSVC AND NOT CMAKE_COMPILER_IS_GNUCXX OR MINGW) - message(STATUS "CUDA compilation was disabled (due to unsuppoted host compiler).") +if (WIN32 AND NOT MSVC) + message(STATUS "CUDA compilation is disabled (due to only Visual Studio compiler suppoted on your platform).") + return() +endif() + +if (CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + message(STATUS "CUDA compilation is disabled (due to Clang unsuppoted on your platform).") return() endif() diff --git a/doc/check_docs.py b/doc/check_docs.py index 18df02685c..2d8799341d 100755 --- a/doc/check_docs.py +++ b/doc/check_docs.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys, glob sys.path.append("../modules/python/src2/") diff --git a/doc/check_docs2.py b/doc/check_docs2.py index a3606bd294..bf03754590 100755 --- a/doc/check_docs2.py +++ b/doc/check_docs2.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import os, sys, fnmatch, re sys.path.append("../modules/python/src2/") diff --git a/doc/conf.py b/doc/conf.py index 40b8e27137..35073e051f 100755 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + # -*- coding: utf-8 -*- # # opencvstd documentation build configuration file, created by diff --git a/doc/ocv.py b/doc/ocv.py index ba321928ab..ce750933b8 100755 --- a/doc/ocv.py +++ b/doc/ocv.py @@ -1,3 +1,4 @@ +#/usr/bin/env python # -*- coding: utf-8 -*- """ ocv domain, a modified copy of sphinx.domains.cpp + shpinx.domains.python. diff --git a/doc/opencv2manager.pdf b/doc/opencv2manager.pdf deleted file mode 100644 index b70f8cd783..0000000000 Binary files a/doc/opencv2manager.pdf and /dev/null differ diff --git a/doc/opencv2refman.pdf b/doc/opencv2refman.pdf deleted file mode 100644 index b2ed9cafdd..0000000000 Binary files a/doc/opencv2refman.pdf and /dev/null differ diff --git a/doc/opencv_cheatsheet.pdf b/doc/opencv_cheatsheet.pdf deleted file mode 100644 index 6616d9bd72..0000000000 Binary files a/doc/opencv_cheatsheet.pdf and /dev/null differ diff --git a/doc/opencv_tutorials.pdf b/doc/opencv_tutorials.pdf deleted file mode 100644 index f6e7a8dbb9..0000000000 Binary files a/doc/opencv_tutorials.pdf and /dev/null differ diff --git a/doc/opencv_user.pdf b/doc/opencv_user.pdf deleted file mode 100644 index db0ffb27b1..0000000000 Binary files a/doc/opencv_user.pdf and /dev/null differ diff --git a/doc/patch_refman_latex.py b/doc/patch_refman_latex.py index 2691746845..352c46cb56 100755 --- a/doc/patch_refman_latex.py +++ b/doc/patch_refman_latex.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys f=open(sys.argv[1], "rt") diff --git a/doc/pattern_tools/gen_pattern.py b/doc/pattern_tools/gen_pattern.py index 455b3b6e8e..45b45af2db 100755 --- a/doc/pattern_tools/gen_pattern.py +++ b/doc/pattern_tools/gen_pattern.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + """gen_pattern.py To run: -c 10 -r 12 -o out.svg diff --git a/doc/pattern_tools/svgfig.py b/doc/pattern_tools/svgfig.py index 04aa257357..bf182a8b09 100755 --- a/doc/pattern_tools/svgfig.py +++ b/doc/pattern_tools/svgfig.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + # svgfig.py copyright (C) 2008 Jim Pivarski # # This program is free software; you can redistribute it and/or diff --git a/doc/reformat.py b/doc/reformat.py index fb52075e90..00e4aae9e0 100755 --- a/doc/reformat.py +++ b/doc/reformat.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import os, sys, re finput=open(sys.argv[1], "rt") diff --git a/doc/tutorials/introduction/android_binary_package/android_dev_intro.rst b/doc/tutorials/introduction/android_binary_package/android_dev_intro.rst index d004132d0f..8855c5bd90 100644 --- a/doc/tutorials/introduction/android_binary_package/android_dev_intro.rst +++ b/doc/tutorials/introduction/android_binary_package/android_dev_intro.rst @@ -334,7 +334,11 @@ and exceptions are used in C++, it also should be created. Example of the file : APP_STL := gnustl_static APP_CPPFLAGS := -frtti -fexceptions - APP_ABI := armeabi-v7a + APP_ABI := all + +.. note:: We recommend setting ``APP_ABI := all`` for all targets. If you want to specify the + target explicitly, use ``armeabi`` for ARMv5/ARMv6, ``armeabi-v7a`` for ARMv7, ``x86`` + for Intel Atom or ``mips`` for MIPS. .. _NDK_build_cli: diff --git a/modules/androidcamera/CMakeLists.txt b/modules/androidcamera/CMakeLists.txt index f55b55136f..d54dd5d208 100644 --- a/modules/androidcamera/CMakeLists.txt +++ b/modules/androidcamera/CMakeLists.txt @@ -6,7 +6,7 @@ set(the_description "Auxiliary module for Android native camera support") set(OPENCV_MODULE_TYPE STATIC) ocv_define_module(androidcamera INTERNAL opencv_core log dl) -ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/camera_wrapper") +ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/camera_wrapper" "${OpenCV_SOURCE_DIR}/android/service/engine/jni/include") # Android source tree for native camera SET (ANDROID_SOURCE_TREE "ANDROID_SOURCE_TREE-NOTFOUND" CACHE PATH diff --git a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp index db6355309a..f6ec2f09cf 100644 --- a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp +++ b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp @@ -1,4 +1,4 @@ -#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) && !defined(ANDROID_r4_0_0) && !defined(ANDROID_r4_0_3) && !defined(ANDROID_r4_1_1) +#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1) && !defined(ANDROID_r4_0_0) && !defined(ANDROID_r4_0_3) && !defined(ANDROID_r4_1_1) && !defined(ANDROID_r4_2_0) # error Building camera wrapper for your version of Android is not supported by OpenCV. You need to modify OpenCV sources in order to compile camera wrapper for your version of Android. #endif @@ -18,7 +18,7 @@ # define MAGIC_OPENCV_TEXTURE_ID (0x10) #else // defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) //TODO: This is either 2.2 or 2.3. Include the headers for ISurface.h access -#if defined(ANDROID_r4_1_1) +#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) #include #include #else @@ -60,7 +60,7 @@ using namespace android; void debugShowFPS(); -#if defined(ANDROID_r4_1_1) +#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) class ConsumerListenerStub: public BufferQueue::ConsumerListener { public: @@ -280,7 +280,7 @@ public: } virtual void postData(int32_t msgType, const sp& dataPtr -#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) + #if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) ,camera_frame_metadata_t* #endif ) @@ -526,7 +526,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, pdstatus = camera->setPreviewTexture(surfaceTexture); if (pdstatus != 0) LOGE("initCameraConnect: failed setPreviewTexture call; camera migth not work correctly"); -#elif defined(ANDROID_r4_1_1) +#elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) sp bufferQueue = new BufferQueue(); sp queueListener = new ConsumerListenerStub(); bufferQueue->consumerConnect(queueListener); diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp index 2cd3e6e493..28e18c479e 100644 --- a/modules/androidcamera/src/camera_activity.cpp +++ b/modules/androidcamera/src/camera_activity.cpp @@ -9,6 +9,7 @@ #include #include "camera_activity.hpp" #include "camera_wrapper.h" +#include "EngineCommon.h" #undef LOG_TAG #undef LOGE @@ -267,12 +268,13 @@ void CameraWrapperConnector::fillListWrapperLibs(const string& folderPath, vecto std::string CameraWrapperConnector::getDefaultPathLibFolder() { - const string packageList[] = {"tegra3", "armv7a_neon", "armv7a", "armv5", "x86"}; - for (size_t i = 0; i < 5; i++) + #define BIN_PACKAGE_NAME(x) "org.opencv.lib_v" CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) "_" x + const char* const packageList[] = {BIN_PACKAGE_NAME("armv7a"), OPENCV_ENGINE_PACKAGE}; + for (size_t i = 0; i < sizeof(packageList)/sizeof(packageList[0]); i++) { char path[128]; - sprintf(path, "/data/data/org.opencv.lib_v%d%d_%s/lib/", CV_MAJOR_VERSION, CV_MINOR_VERSION, packageList[i].c_str()); - LOGD("Trying package \"%s\" (\"%s\")", packageList[i].c_str(), path); + sprintf(path, "/data/data/%s/lib/", packageList[i]); + LOGD("Trying package \"%s\" (\"%s\")", packageList[i], path); DIR* dir = opendir(path); if (!dir) @@ -427,7 +429,6 @@ void CameraActivity::applyProperties() int CameraActivity::getFrameWidth() { - LOGD("CameraActivity::getFrameWidth()"); if (frameWidth <= 0) frameWidth = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEWIDTH); return frameWidth; @@ -435,7 +436,6 @@ int CameraActivity::getFrameWidth() int CameraActivity::getFrameHeight() { - LOGD("CameraActivity::getFrameHeight()"); if (frameHeight <= 0) frameHeight = getProperty(ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT); return frameHeight; diff --git a/modules/calib3d/perf/perf_pnp.cpp b/modules/calib3d/perf/perf_pnp.cpp index fa8f5808db..00a7c7e852 100644 --- a/modules/calib3d/perf/perf_pnp.cpp +++ b/modules/calib3d/perf/perf_pnp.cpp @@ -86,6 +86,7 @@ PERF_TEST(PointsNum_Algo, solveP3P) add(points2d, noise, points2d); declare.in(points3d, points2d); + declare.time(100); TEST_CYCLE_N(1000) { diff --git a/modules/contrib/doc/facerec/src/create_csv.py b/modules/contrib/doc/facerec/src/create_csv.py index 54681afa99..71d773c017 100755 --- a/modules/contrib/doc/facerec/src/create_csv.py +++ b/modules/contrib/doc/facerec/src/create_csv.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys import os.path diff --git a/modules/contrib/doc/retina/index.rst b/modules/contrib/doc/retina/index.rst index f4f43dbd75..913f7d1079 100644 --- a/modules/contrib/doc/retina/index.rst +++ b/modules/contrib/doc/retina/index.rst @@ -208,7 +208,7 @@ Retina::getMagno Retina::getParameters +++++++++++++++++++++ -.. ocv:function:: struct Retina::RetinaParameters Retina::getParameters() +.. ocv:function:: Retina::RetinaParameters Retina::getParameters() Retrieve the current parameters values in a *Retina::RetinaParameters* structure @@ -323,7 +323,8 @@ Retina::RetinaParameters ======================== .. ocv:struct:: Retina::RetinaParameters -This structure merges all the parameters that can be adjusted threw the **Retina::setup()**, **Retina::setupOPLandIPLParvoChannel** and **Retina::setupIPLMagnoChannel** setup methods + + This structure merges all the parameters that can be adjusted threw the **Retina::setup()**, **Retina::setupOPLandIPLParvoChannel** and **Retina::setupIPLMagnoChannel** setup methods Parameters structure for better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel. :: class RetinaParameters{ diff --git a/modules/core/perf/perf_arithm.cpp b/modules/core/perf/perf_arithm.cpp index c7f497892a..962a9e00b1 100644 --- a/modules/core/perf/perf_arithm.cpp +++ b/modules/core/perf/perf_arithm.cpp @@ -123,6 +123,7 @@ PERF_TEST_P(Size_MatType, add, TYPICAL_MATS_CORE_ARITHM) cv::Mat c = Mat(sz, type); declare.in(a, b, WARMUP_RNG).out(c); + declare.time(50); if (CV_MAT_DEPTH(type) == CV_32S) { diff --git a/modules/core/perf/perf_bitwise.cpp b/modules/core/perf/perf_bitwise.cpp index 76354f45c3..d31e019703 100644 --- a/modules/core/perf/perf_bitwise.cpp +++ b/modules/core/perf/perf_bitwise.cpp @@ -19,6 +19,7 @@ PERF_TEST_P(Size_MatType, bitwise_not, TYPICAL_MATS_BITW_ARITHM) cv::Mat c = Mat(sz, type); declare.in(a, WARMUP_RNG).out(c); + declare.time(100); TEST_CYCLE() cv::bitwise_not(a, c); @@ -34,6 +35,7 @@ PERF_TEST_P(Size_MatType, bitwise_and, TYPICAL_MATS_BITW_ARITHM) cv::Mat c = Mat(sz, type); declare.in(a, b, WARMUP_RNG).out(c); + declare.time(100); TEST_CYCLE() bitwise_and(a, b, c); @@ -49,6 +51,7 @@ PERF_TEST_P(Size_MatType, bitwise_or, TYPICAL_MATS_BITW_ARITHM) cv::Mat c = Mat(sz, type); declare.in(a, b, WARMUP_RNG).out(c); + declare.time(100); TEST_CYCLE() bitwise_or(a, b, c); @@ -64,6 +67,7 @@ PERF_TEST_P(Size_MatType, bitwise_xor, TYPICAL_MATS_BITW_ARITHM) cv::Mat c = Mat(sz, type); declare.in(a, b, WARMUP_RNG).out(c); + declare.time(100); TEST_CYCLE() bitwise_xor(a, b, c); diff --git a/modules/core/perf/perf_dot.cpp b/modules/core/perf/perf_dot.cpp index 8de1a7cba1..40dc9a4d5e 100644 --- a/modules/core/perf/perf_dot.cpp +++ b/modules/core/perf/perf_dot.cpp @@ -21,6 +21,7 @@ PERF_TEST_P( MatType_Length, dot, Mat b(size, size, type); declare.in(a, b, WARMUP_RNG); + declare.time(100); double product; diff --git a/modules/core/perf/perf_norm.cpp b/modules/core/perf/perf_norm.cpp index a9428ee9d0..4fb498eb30 100644 --- a/modules/core/perf/perf_norm.cpp +++ b/modules/core/perf/perf_norm.cpp @@ -150,6 +150,7 @@ PERF_TEST_P(Size_MatType_NormType, normalize_mask, if(normType==NORM_L2) alpha = (double)src.total()/10; declare.in(src, WARMUP_RNG).in(mask).out(dst); + declare.time(100); TEST_CYCLE() normalize(src, dst, alpha, 0., normType, -1, mask); diff --git a/modules/core/perf/perf_reduce.cpp b/modules/core/perf/perf_reduce.cpp index 77172770bb..81cdb5db57 100644 --- a/modules/core/perf/perf_reduce.cpp +++ b/modules/core/perf/perf_reduce.cpp @@ -32,6 +32,7 @@ PERF_TEST_P(Size_MatType_ROp, reduceR, Mat vec(1, sz.width, ddepth < 0 ? matType : ddepth); declare.in(src, WARMUP_RNG).out(vec); + declare.time(100); TEST_CYCLE() reduce(src, vec, 0, reduceOp, ddepth); @@ -58,6 +59,7 @@ PERF_TEST_P(Size_MatType_ROp, reduceC, Mat vec(sz.height, 1, ddepth < 0 ? matType : ddepth); declare.in(src, WARMUP_RNG).out(vec); + declare.time(100); TEST_CYCLE() reduce(src, vec, 1, reduceOp, ddepth); diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index 1abffa8b35..019d3616cd 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -1097,25 +1097,25 @@ double cv::invert( InputArray _src, OutputArray _dst, int method ) double d = det3(Sf); if( d != 0. ) { - float CV_DECL_ALIGNED(16) t[12]; + double t[12]; result = true; d = 1./d; - t[0] = (float)(((double)Sf(1,1) * Sf(2,2) - (double)Sf(1,2) * Sf(2,1)) * d); - t[1] = (float)(((double)Sf(0,2) * Sf(2,1) - (double)Sf(0,1) * Sf(2,2)) * d); - t[2] = (float)(((double)Sf(0,1) * Sf(1,2) - (double)Sf(0,2) * Sf(1,1)) * d); + t[0] = (((double)Sf(1,1) * Sf(2,2) - (double)Sf(1,2) * Sf(2,1)) * d); + t[1] = (((double)Sf(0,2) * Sf(2,1) - (double)Sf(0,1) * Sf(2,2)) * d); + t[2] = (((double)Sf(0,1) * Sf(1,2) - (double)Sf(0,2) * Sf(1,1)) * d); - t[3] = (float)(((double)Sf(1,2) * Sf(2,0) - (double)Sf(1,0) * Sf(2,2)) * d); - t[4] = (float)(((double)Sf(0,0) * Sf(2,2) - (double)Sf(0,2) * Sf(2,0)) * d); - t[5] = (float)(((double)Sf(0,2) * Sf(1,0) - (double)Sf(0,0) * Sf(1,2)) * d); + t[3] = (((double)Sf(1,2) * Sf(2,0) - (double)Sf(1,0) * Sf(2,2)) * d); + t[4] = (((double)Sf(0,0) * Sf(2,2) - (double)Sf(0,2) * Sf(2,0)) * d); + t[5] = (((double)Sf(0,2) * Sf(1,0) - (double)Sf(0,0) * Sf(1,2)) * d); - t[6] = (float)(((double)Sf(1,0) * Sf(2,1) - (double)Sf(1,1) * Sf(2,0)) * d); - t[7] = (float)(((double)Sf(0,1) * Sf(2,0) - (double)Sf(0,0) * Sf(2,1)) * d); - t[8] = (float)(((double)Sf(0,0) * Sf(1,1) - (double)Sf(0,1) * Sf(1,0)) * d); + t[6] = (((double)Sf(1,0) * Sf(2,1) - (double)Sf(1,1) * Sf(2,0)) * d); + t[7] = (((double)Sf(0,1) * Sf(2,0) - (double)Sf(0,0) * Sf(2,1)) * d); + t[8] = (((double)Sf(0,0) * Sf(1,1) - (double)Sf(0,1) * Sf(1,0)) * d); - Df(0,0) = t[0]; Df(0,1) = t[1]; Df(0,2) = t[2]; - Df(1,0) = t[3]; Df(1,1) = t[4]; Df(1,2) = t[5]; - Df(2,0) = t[6]; Df(2,1) = t[7]; Df(2,2) = t[8]; + Df(0,0) = (float)t[0]; Df(0,1) = (float)t[1]; Df(0,2) = (float)t[2]; + Df(1,0) = (float)t[3]; Df(1,1) = (float)t[4]; Df(1,2) = (float)t[5]; + Df(2,0) = (float)t[6]; Df(2,1) = (float)t[7]; Df(2,2) = (float)t[8]; } } else diff --git a/modules/features2d/perf/perf_batchDistance.cpp b/modules/features2d/perf/perf_batchDistance.cpp index cf58be4fd4..157b59fb4a 100644 --- a/modules/features2d/perf/perf_batchDistance.cpp +++ b/modules/features2d/perf/perf_batchDistance.cpp @@ -92,6 +92,7 @@ PERF_TEST_P(Source_CrossCheck, batchDistance_L2, generateData(queryDescriptors, trainDescriptors, sourceType); + declare.time(50); TEST_CYCLE() { batchDistance(queryDescriptors, trainDescriptors, dist, CV_32F, (isCrossCheck) ? ndix : noArray(), @@ -118,6 +119,7 @@ PERF_TEST_P(Norm_CrossCheck, batchDistance_32F, Mat ndix; generateData(queryDescriptors, trainDescriptors, CV_32F); + declare.time(100); TEST_CYCLE() { diff --git a/modules/gpu/doc/image_processing.rst b/modules/gpu/doc/image_processing.rst index cc5f4ddc97..0b3254033d 100644 --- a/modules/gpu/doc/image_processing.rst +++ b/modules/gpu/doc/image_processing.rst @@ -873,15 +873,16 @@ gpu::FastNonLocalMeansDenoising ------------------------------- .. ocv:class:: gpu::FastNonLocalMeansDenoising - class FastNonLocalMeansDenoising - { - public: - //! Simple method, recommended for grayscale images (though it supports multichannel images) - void simpleMethod(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) + :: - //! Processes luminance and color components separatelly - void labMethod(const GpuMat& src, GpuMat& dst, float h_luminance, float h_color, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) - }; + class FastNonLocalMeansDenoising + { + public: + //! Simple method, recommended for grayscale images (though it supports multichannel images) + void simpleMethod(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) + //! Processes luminance and color components separatelly + void labMethod(const GpuMat& src, GpuMat& dst, float h_luminance, float h_color, int search_window = 21, int block_size = 7, Stream& s = Stream::Null()) + }; The class implements fast approximate Non Local Means Denoising algorithm. diff --git a/modules/gpu/include/opencv2/gpu/device/utility.hpp b/modules/gpu/include/opencv2/gpu/device/utility.hpp index 4489a20b15..88a73a10ea 100644 --- a/modules/gpu/include/opencv2/gpu/device/utility.hpp +++ b/modules/gpu/include/opencv2/gpu/device/utility.hpp @@ -150,7 +150,7 @@ namespace cv { namespace gpu { namespace device return true; } - static __device__ __forceinline__ bool check(int, int, int, uint offset = 0) + static __device__ __forceinline__ bool check(int, int, int) { return true; } diff --git a/modules/gpu/misc/mark_nvidia.py b/modules/gpu/misc/mark_nvidia.py index 7c1f212869..e8cc3e8417 100755 --- a/modules/gpu/misc/mark_nvidia.py +++ b/modules/gpu/misc/mark_nvidia.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys, re spaces = '[\s]*' diff --git a/modules/gpu/src/cuda/integral_image.cu b/modules/gpu/src/cuda/integral_image.cu index 558f9085db..09187fd259 100644 --- a/modules/gpu/src/cuda/integral_image.cu +++ b/modules/gpu/src/cuda/integral_image.cu @@ -357,18 +357,19 @@ namespace cv { namespace gpu { namespace device #endif } - void shfl_integral_gpu(PtrStepSzb img, PtrStepSz integral, cudaStream_t stream) + void shfl_integral_gpu(const PtrStepSzb& img, PtrStepSz integral, cudaStream_t stream) { { // each thread handles 16 values, use 1 block/row - const int block = img.cols / 16; + // save, becouse step is actually can't be less 512 bytes + int block = integral.cols / 16; // launch 1 block / row const int grid = img.rows; cudaSafeCall( cudaFuncSetCacheConfig(shfl_integral_horizontal, cudaFuncCachePreferL1) ); - shfl_integral_horizontal<<>>((PtrStepSz) img, (PtrStepSz) integral); + shfl_integral_horizontal<<>>((const PtrStepSz) img, (PtrStepSz) integral); cudaSafeCall( cudaGetLastError() ); } diff --git a/modules/gpu/src/cuda/lbp.cu b/modules/gpu/src/cuda/lbp.cu index 9b729fe639..55f5d75124 100644 --- a/modules/gpu/src/cuda/lbp.cu +++ b/modules/gpu/src/cuda/lbp.cu @@ -185,6 +185,7 @@ namespace cv { namespace gpu { namespace device void connectedConmonents(PtrStepSz candidates, int ncandidates, PtrStepSz objects, int groupThreshold, float grouping_eps, unsigned int* nclasses) { + if (!ncandidates) return; int block = ncandidates; int smem = block * ( sizeof(int) + sizeof(int4) ); disjoin<<<1, block, smem>>>(candidates, objects, ncandidates, groupThreshold, grouping_eps, nclasses); diff --git a/modules/gpu/src/cuda/surf.cu b/modules/gpu/src/cuda/surf.cu index 8c80559c5b..37c4eb48ab 100644 --- a/modules/gpu/src/cuda/surf.cu +++ b/modules/gpu/src/cuda/surf.cu @@ -177,7 +177,7 @@ namespace cv { namespace gpu { namespace device return (HAAR_SIZE0 + HAAR_SIZE_INC * layer) << octave; } - __global__ void icvCalcLayerDetAndTrace(PtrStepf det, PtrStepf trace, uint sumOffset) + __global__ void icvCalcLayerDetAndTrace(PtrStepf det, PtrStepf trace) { // Determine the indices const int gridDim_y = gridDim.y / (c_nOctaveLayers + 2); @@ -198,9 +198,9 @@ namespace cv { namespace gpu { namespace device if (size <= c_img_rows && size <= c_img_cols && i < samples_i && j < samples_j) { - const float dx = icvCalcHaarPatternSum<3>(c_DX , 9, size, (i << c_octave), sumOffset + (j << c_octave)); - const float dy = icvCalcHaarPatternSum<3>(c_DY , 9, size, (i << c_octave), sumOffset + (j << c_octave)); - const float dxy = icvCalcHaarPatternSum<4>(c_DXY, 9, size, (i << c_octave), sumOffset + (j << c_octave)); + const float dx = icvCalcHaarPatternSum<3>(c_DX , 9, size, (i << c_octave), (j << c_octave)); + const float dy = icvCalcHaarPatternSum<3>(c_DY , 9, size, (i << c_octave), (j << c_octave)); + const float dxy = icvCalcHaarPatternSum<4>(c_DXY, 9, size, (i << c_octave), (j << c_octave)); det.ptr(layer * c_layer_rows + i + margin)[j + margin] = dx * dy - 0.81f * dxy * dxy; trace.ptr(layer * c_layer_rows + i + margin)[j + margin] = dx + dy; @@ -208,7 +208,7 @@ namespace cv { namespace gpu { namespace device } void icvCalcLayerDetAndTrace_gpu(const PtrStepf& det, const PtrStepf& trace, int img_rows, int img_cols, - int octave, int nOctaveLayers, const size_t sumOffset) + int octave, int nOctaveLayers) { const int min_size = calcSize(octave, 0); const int max_samples_i = 1 + ((img_rows - min_size) >> octave); @@ -220,7 +220,7 @@ namespace cv { namespace gpu { namespace device grid.x = divUp(max_samples_j, threads.x); grid.y = divUp(max_samples_i, threads.y) * (nOctaveLayers + 2); - icvCalcLayerDetAndTrace<<>>(det, trace, (uint)sumOffset); + icvCalcLayerDetAndTrace<<>>(det, trace); cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaDeviceSynchronize() ); @@ -233,7 +233,7 @@ namespace cv { namespace gpu { namespace device struct WithMask { - static __device__ bool check(int sum_i, int sum_j, int size, const uint offset) + static __device__ bool check(int sum_i, int sum_j, int size) { float ratio = (float)size / 9.0f; @@ -245,10 +245,10 @@ namespace cv { namespace gpu { namespace device int dy2 = __float2int_rn(ratio * c_DM[3]); float t = 0; - t += tex2D(maskSumTex, offset + sum_j + dx1, sum_i + dy1); - t -= tex2D(maskSumTex, offset + sum_j + dx1, sum_i + dy2); - t -= tex2D(maskSumTex, offset + sum_j + dx2, sum_i + dy1); - t += tex2D(maskSumTex, offset + sum_j + dx2, sum_i + dy2); + t += tex2D(maskSumTex, sum_j + dx1, sum_i + dy1); + t -= tex2D(maskSumTex, sum_j + dx1, sum_i + dy2); + t -= tex2D(maskSumTex, sum_j + dx2, sum_i + dy1); + t += tex2D(maskSumTex, sum_j + dx2, sum_i + dy2); d += t * c_DM[4] / ((dx2 - dx1) * (dy2 - dy1)); @@ -258,7 +258,7 @@ namespace cv { namespace gpu { namespace device template __global__ void icvFindMaximaInLayer(const PtrStepf det, const PtrStepf trace, int4* maxPosBuffer, - unsigned int* maxCounter, const uint maskOffset) + unsigned int* maxCounter) { #if __CUDA_ARCH__ && __CUDA_ARCH__ >= 110 @@ -299,7 +299,7 @@ namespace cv { namespace gpu { namespace device const int sum_i = (i - ((size >> 1) >> c_octave)) << c_octave; const int sum_j = (j - ((size >> 1) >> c_octave)) << c_octave; - if (Mask::check(sum_i, sum_j, size, maskOffset)) + if (Mask::check(sum_i, sum_j, size)) { // Check to see if we have a max (in its 26 neighbours) const bool condmax = val0 > N9[localLin - 1 - blockDim.x - zoff] @@ -351,7 +351,7 @@ namespace cv { namespace gpu { namespace device } void icvFindMaximaInLayer_gpu(const PtrStepf& det, const PtrStepf& trace, int4* maxPosBuffer, unsigned int* maxCounter, - int img_rows, int img_cols, int octave, bool use_mask, int nOctaveLayers, const size_t maskOffset) + int img_rows, int img_cols, int octave, bool use_mask, int nOctaveLayers) { const int layer_rows = img_rows >> octave; const int layer_cols = img_cols >> octave; @@ -367,9 +367,9 @@ namespace cv { namespace gpu { namespace device const size_t smem_size = threads.x * threads.y * 3 * sizeof(float); if (use_mask) - icvFindMaximaInLayer<<>>(det, trace, maxPosBuffer, maxCounter, (uint)maskOffset); + icvFindMaximaInLayer<<>>(det, trace, maxPosBuffer, maxCounter); else - icvFindMaximaInLayer<<>>(det, trace, maxPosBuffer, maxCounter, 0); + icvFindMaximaInLayer<<>>(det, trace, maxPosBuffer, maxCounter); cudaSafeCall( cudaGetLastError() ); diff --git a/modules/gpu/src/gftt.cpp b/modules/gpu/src/gftt.cpp index ad24debcd7..0c8f165ae1 100644 --- a/modules/gpu/src/gftt.cpp +++ b/modules/gpu/src/gftt.cpp @@ -85,6 +85,12 @@ void cv::gpu::GoodFeaturesToTrackDetector_GPU::operator ()(const GpuMat& image, int total = findCorners_gpu(eig_, static_cast(maxVal * qualityLevel), mask, tmpCorners_.ptr(), tmpCorners_.cols); + if (total == 0) + { + corners.release(); + return; + } + sortCorners_gpu(eig_, tmpCorners_.ptr(), total); if (minDistance < 1) diff --git a/modules/gpu/src/imgproc.cpp b/modules/gpu/src/imgproc.cpp index 0bf9c81c2e..7f63737efc 100644 --- a/modules/gpu/src/imgproc.cpp +++ b/modules/gpu/src/imgproc.cpp @@ -537,7 +537,7 @@ namespace cv { namespace gpu { namespace device { namespace imgproc { - void shfl_integral_gpu(PtrStepSzb img, PtrStepSz integral, cudaStream_t stream); + void shfl_integral_gpu(const PtrStepSzb& img, PtrStepSz integral, cudaStream_t stream); } }}} @@ -553,44 +553,26 @@ void cv::gpu::integralBuffered(const GpuMat& src, GpuMat& sum, GpuMat& buffer, S src.locateROI(whole, offset); - if (info.supports(WARP_SHUFFLE_FUNCTIONS) && src.cols <= 2048) + if (info.supports(WARP_SHUFFLE_FUNCTIONS) && src.cols <= 2048 + && offset.x % 16 == 0 && ((src.cols + 63) / 64) * 64 <= (src.step - offset.x)) { - GpuMat srcAlligned; + ensureSizeIsEnough(((src.rows + 7) / 8) * 8, ((src.cols + 63) / 64) * 64, CV_32SC1, buffer); - if (src.cols % 16 == 0 && src.rows % 8 == 0 && offset.x % 16 == 0 && offset.y % 8 == 0) - srcAlligned = src; - else - { - ensureSizeIsEnough(((src.rows + 7) / 8) * 8, ((src.cols + 15) / 16) * 16, src.type(), buffer); - - GpuMat inner = buffer(Rect(0, 0, src.cols, src.rows)); - - if (s) - { - s.enqueueMemSet(buffer, Scalar::all(0)); - s.enqueueCopy(src, inner); - } - else - { - buffer.setTo(Scalar::all(0)); - src.copyTo(inner); - } - - srcAlligned = buffer; - } - - sum.create(srcAlligned.rows + 1, srcAlligned.cols + 4, CV_32SC1); + cv::gpu::device::imgproc::shfl_integral_gpu(src, buffer, stream); + sum.create(src.rows + 1, src.cols + 1, CV_32SC1); if (s) s.enqueueMemSet(sum, Scalar::all(0)); else sum.setTo(Scalar::all(0)); - GpuMat inner = sum(Rect(4, 1, srcAlligned.cols, srcAlligned.rows)); + GpuMat inner = sum(Rect(1, 1, src.cols, src.rows)); + GpuMat res = buffer(Rect(0, 0, src.cols, src.rows)); - cv::gpu::device::imgproc::shfl_integral_gpu(srcAlligned, inner, stream); - - sum = sum(Rect(3, 0, src.cols + 1, src.rows + 1)); + if (s) + s.enqueueCopy(res, inner); + else + res.copyTo(inner); } else { diff --git a/modules/gpu/src/surf.cpp b/modules/gpu/src/surf.cpp index 72bb9c15e0..5a1b074445 100644 --- a/modules/gpu/src/surf.cpp +++ b/modules/gpu/src/surf.cpp @@ -75,10 +75,10 @@ namespace cv { namespace gpu { namespace device size_t bindMaskSumTex(PtrStepSz maskSum); void icvCalcLayerDetAndTrace_gpu(const PtrStepf& det, const PtrStepf& trace, int img_rows, int img_cols, - int octave, int nOctaveLayers, const size_t sumOffset); + int octave, int nOctaveLayer); void icvFindMaximaInLayer_gpu(const PtrStepf& det, const PtrStepf& trace, int4* maxPosBuffer, unsigned int* maxCounter, - int img_rows, int img_cols, int octave, bool use_mask, int nLayers, const size_t maskOffset); + int img_rows, int img_cols, int octave, bool use_mask, int nLayers); void icvInterpolateKeypoint_gpu(const PtrStepf& det, const int4* maxPosBuffer, unsigned int maxCounter, float* featureX, float* featureY, int* featureLaplacian, int* featureOctave, float* featureSize, float* featureHessian, @@ -146,8 +146,8 @@ namespace loadGlobalConstants(maxCandidates, maxFeatures, img_rows, img_cols, surf_.nOctaveLayers, static_cast(surf_.hessianThreshold)); bindImgTex(img); - integralBuffered(img, surf_.sum, surf_.intBuffer); + integralBuffered(img, surf_.sum, surf_.intBuffer); sumOffset = bindSumTex(surf_.sum); if (use_mask) @@ -174,10 +174,10 @@ namespace loadOctaveConstants(octave, layer_rows, layer_cols); - icvCalcLayerDetAndTrace_gpu(surf_.det, surf_.trace, img_rows, img_cols, octave, surf_.nOctaveLayers, sumOffset); + icvCalcLayerDetAndTrace_gpu(surf_.det, surf_.trace, img_rows, img_cols, octave, surf_.nOctaveLayers); icvFindMaximaInLayer_gpu(surf_.det, surf_.trace, surf_.maxPosBuffer.ptr(), counters.ptr() + 1 + octave, - img_rows, img_cols, octave, use_mask, surf_.nOctaveLayers, maskOffset); + img_rows, img_cols, octave, use_mask, surf_.nOctaveLayers); unsigned int maxCounter; cudaSafeCall( cudaMemcpy(&maxCounter, counters.ptr() + 1 + octave, sizeof(unsigned int), cudaMemcpyDeviceToHost) ); diff --git a/modules/gpu/test/test_video.cpp b/modules/gpu/test/test_video.cpp index ca9442d697..ecba4b5a0f 100644 --- a/modules/gpu/test/test_video.cpp +++ b/modules/gpu/test/test_video.cpp @@ -203,6 +203,21 @@ TEST_P(GoodFeaturesToTrack, Accuracy) } } +TEST_P(GoodFeaturesToTrack, EmptyCorners) +{ + int maxCorners = 1000; + double qualityLevel = 0.01; + + cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance); + + cv::gpu::GpuMat src(100, 100, CV_8UC1, cv::Scalar::all(0)); + cv::gpu::GpuMat corners(1, maxCorners, CV_32FC2); + + detector(src, corners); + + ASSERT_TRUE( corners.empty() ); +} + INSTANTIATE_TEST_CASE_P(GPU_Video, GoodFeaturesToTrack, testing::Combine( ALL_DEVICES, testing::Values(MinDistance(0.0), MinDistance(3.0)))); diff --git a/modules/highgui/src/cap.cpp b/modules/highgui/src/cap.cpp index e818cfe755..f8d32e7eee 100644 --- a/modules/highgui/src/cap.cpp +++ b/modules/highgui/src/cap.cpp @@ -424,7 +424,6 @@ CV_IMPL CvVideoWriter* cvCreateVideoWriter( const char* filename, int fourcc, CV_IMPL int cvWriteFrame( CvVideoWriter* writer, const IplImage* image ) { - return writer ? writer->writeFrame(image) : 0; } diff --git a/modules/highgui/src/cap_ffmpeg.cpp b/modules/highgui/src/cap_ffmpeg.cpp index 0cc60e3a42..040adbd507 100644 --- a/modules/highgui/src/cap_ffmpeg.cpp +++ b/modules/highgui/src/cap_ffmpeg.cpp @@ -57,11 +57,32 @@ static CvCreateVideoWriter_Plugin icvCreateVideoWriter_FFMPEG_p = 0; static CvReleaseVideoWriter_Plugin icvReleaseVideoWriter_FFMPEG_p = 0; static CvWriteFrame_Plugin icvWriteFrame_FFMPEG_p = 0; -static void -icvInitFFMPEG(void) +static cv::Mutex _icvInitFFMPEG_mutex; + +class icvInitFFMPEG { - static int ffmpegInitialized = 0; - if( !ffmpegInitialized ) +public: + static void Init() + { + cv::AutoLock al(_icvInitFFMPEG_mutex); + static icvInitFFMPEG init; + } + +private: + #if defined WIN32 || defined _WIN32 + HMODULE icvFFOpenCV; + + ~icvInitFFMPEG() + { + if (icvFFOpenCV) + { + FreeLibrary(icvFFOpenCV); + icvFFOpenCV = 0; + } + } + #endif + + icvInitFFMPEG() { #if defined WIN32 || defined _WIN32 const char* module_name = "opencv_ffmpeg" @@ -71,7 +92,7 @@ icvInitFFMPEG(void) #endif ".dll"; - static HMODULE icvFFOpenCV = LoadLibrary( module_name ); + icvFFOpenCV = LoadLibrary( module_name ); if( icvFFOpenCV ) { icvCreateFileCapture_FFMPEG_p = @@ -123,10 +144,8 @@ icvInitFFMPEG(void) icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)cvReleaseVideoWriter_FFMPEG; icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)cvWriteFrame_FFMPEG; #endif - - ffmpegInitialized = 1; } -} +}; class CvCapture_FFMPEG_proxy : public CvCapture @@ -161,9 +180,9 @@ public: } virtual bool open( const char* filename ) { + icvInitFFMPEG::Init(); close(); - icvInitFFMPEG(); if( !icvCreateFileCapture_FFMPEG_p ) return false; ffmpegCapture = icvCreateFileCapture_FFMPEG_p( filename ); @@ -196,7 +215,6 @@ CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char * filename) #endif } - class CvVideoWriter_FFMPEG_proxy : public CvVideoWriter { public: @@ -214,8 +232,8 @@ public: } virtual bool open( const char* filename, int fourcc, double fps, CvSize frameSize, bool isColor ) { + icvInitFFMPEG::Init(); close(); - icvInitFFMPEG(); if( !icvCreateVideoWriter_FFMPEG_p ) return false; ffmpegWriter = icvCreateVideoWriter_FFMPEG_p( filename, fourcc, fps, frameSize.width, frameSize.height, isColor ); diff --git a/modules/highgui/src/cap_ffmpeg_impl.hpp b/modules/highgui/src/cap_ffmpeg_impl.hpp index 445a9e6208..d6ccdabc57 100644 --- a/modules/highgui/src/cap_ffmpeg_impl.hpp +++ b/modules/highgui/src/cap_ffmpeg_impl.hpp @@ -328,28 +328,179 @@ void CvCapture_FFMPEG::close() #define AVSEEK_FLAG_ANY 1 #endif -static void icvInitFFMPEG_internal() +class ImplMutex { - static volatile bool initialized = false; - if( !initialized ) +public: + ImplMutex(); + ~ImplMutex(); + + void lock(); + bool trylock(); + void unlock(); + + struct Impl; +protected: + Impl* impl; + +private: + ImplMutex(const ImplMutex&); + ImplMutex& operator = (const ImplMutex& m); +}; + +#if defined WIN32 || defined _WIN32 || defined WINCE + +struct ImplMutex::Impl +{ + Impl() { InitializeCriticalSection(&cs); refcount = 1; } + ~Impl() { DeleteCriticalSection(&cs); } + + void lock() { EnterCriticalSection(&cs); } + bool trylock() { return TryEnterCriticalSection(&cs) != 0; } + void unlock() { LeaveCriticalSection(&cs); } + + CRITICAL_SECTION cs; + int refcount; +}; + +#ifndef __GNUC__ +static int _interlockedExchangeAdd(int* addr, int delta) +{ +#if defined _MSC_VER && _MSC_VER >= 1500 + return (int)_InterlockedExchangeAdd((long volatile*)addr, delta); +#else + return (int)InterlockedExchangeAdd((long volatile*)addr, delta); +#endif +} +#endif // __GNUC__ + +#elif defined __APPLE__ + +#include + +struct ImplMutex::Impl +{ + Impl() { sl = OS_SPINLOCK_INIT; refcount = 1; } + ~Impl() {} + + void lock() { OSSpinLockLock(&sl); } + bool trylock() { return OSSpinLockTry(&sl); } + void unlock() { OSSpinLockUnlock(&sl); } + + OSSpinLock sl; + int refcount; +}; + +#elif defined __linux__ && !defined ANDROID + +struct ImplMutex::Impl +{ + Impl() { pthread_spin_init(&sl, 0); refcount = 1; } + ~Impl() { pthread_spin_destroy(&sl); } + + void lock() { pthread_spin_lock(&sl); } + bool trylock() { return pthread_spin_trylock(&sl) == 0; } + void unlock() { pthread_spin_unlock(&sl); } + + pthread_spinlock_t sl; + int refcount; +}; + +#else + +struct ImplMutex::Impl +{ + Impl() { pthread_mutex_init(&sl, 0); refcount = 1; } + ~Impl() { pthread_mutex_destroy(&sl); } + + void lock() { pthread_mutex_lock(&sl); } + bool trylock() { return pthread_mutex_trylock(&sl) == 0; } + void unlock() { pthread_mutex_unlock(&sl); } + + pthread_mutex_t sl; + int refcount; +}; + +#endif + +ImplMutex::ImplMutex() +{ + impl = new ImplMutex::Impl; +} + +ImplMutex::~ImplMutex() +{ + delete impl; + impl = 0; +} + +void ImplMutex::lock() { impl->lock(); } +void ImplMutex::unlock() { impl->unlock(); } +bool ImplMutex::trylock() { return impl->trylock(); } + +static int LockCallBack(void **mutex, AVLockOp op) +{ + switch (op) { - #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0) + case AV_LOCK_CREATE: + *mutex = reinterpret_cast(new ImplMutex()); + if (!*mutex) + return 1; + break; + + case AV_LOCK_OBTAIN: + reinterpret_cast(*mutex)->lock(); + break; + + case AV_LOCK_RELEASE: + reinterpret_cast(*mutex)->unlock(); + break; + + case AV_LOCK_DESTROY: + ImplMutex* cv_mutex = reinterpret_cast(*mutex); + delete cv_mutex; + cv_mutex = NULL; + break; + } + return 0; +} + +static ImplMutex _InternalFFMpegRegister_mutex; + +class InternalFFMpegRegister +{ +public: + static void Register() + { + _InternalFFMpegRegister_mutex.lock(); + static InternalFFMpegRegister init; + _InternalFFMpegRegister_mutex.unlock(); + } + + ~InternalFFMpegRegister() + { + av_lockmgr_register(NULL); + } + +private: + InternalFFMpegRegister() + { +#if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 13, 0) avformat_network_init(); - #endif +#endif /* register all codecs, demux and protocols */ av_register_all(); - av_log_set_level(AV_LOG_ERROR); + /* register a callback function for synchronization */ + av_lockmgr_register(&LockCallBack); - initialized = true; + av_log_set_level(AV_LOG_ERROR); } -} +}; bool CvCapture_FFMPEG::open( const char* _filename ) { - icvInitFFMPEG_internal(); - + InternalFFMpegRegister::Register(); unsigned i; bool valid = false; @@ -361,7 +512,8 @@ bool CvCapture_FFMPEG::open( const char* _filename ) int err = av_open_input_file(&ic, _filename, NULL, 0, NULL); #endif - if (err < 0) { + if (err < 0) + { CV_WARN("Error opening file"); goto exit_func; } @@ -371,7 +523,8 @@ bool CvCapture_FFMPEG::open( const char* _filename ) #else av_find_stream_info(ic); #endif - if (err < 0) { + if (err < 0) + { CV_WARN("Could not find codec parameters"); goto exit_func; } @@ -393,7 +546,8 @@ bool CvCapture_FFMPEG::open( const char* _filename ) #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO #endif - if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0) { + if( AVMEDIA_TYPE_VIDEO == enc->codec_type && video_stream < 0) + { AVCodec *codec = avcodec_find_decoder(enc->codec_id); if (!codec || #if LIBAVCODEC_VERSION_INT >= ((53<<16)+(8<<8)+0) @@ -401,7 +555,8 @@ bool CvCapture_FFMPEG::open( const char* _filename ) #else avcodec_open(enc, codec) #endif - < 0) goto exit_func; + < 0) + goto exit_func; video_stream = i; video_st = ic->streams[i]; @@ -1275,7 +1430,7 @@ void CvVideoWriter_FFMPEG::close() bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, double fps, int width, int height, bool is_color ) { - icvInitFFMPEG_internal(); + InternalFFMpegRegister::Register(); CodecID codec_id = CODEC_ID_NONE; int err, codec_pix_fmt; @@ -1495,6 +1650,7 @@ bool CvVideoWriter_FFMPEG::open( const char * filename, int fourcc, frame_width = width; frame_height = height; ok = true; + return true; } @@ -1506,6 +1662,7 @@ CvCapture_FFMPEG* cvCreateFileCapture_FFMPEG( const char* filename ) capture->init(); if( capture->open( filename )) return capture; + capture->close(); free(capture); return 0; @@ -1554,7 +1711,6 @@ CvVideoWriter_FFMPEG* cvCreateVideoWriter_FFMPEG( const char* filename, int four return 0; } - void cvReleaseVideoWriter_FFMPEG( CvVideoWriter_FFMPEG** writer ) { if( writer && *writer ) @@ -1741,15 +1897,12 @@ AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext *oc, CodecID bool OutputMediaStream_FFMPEG::open(const char* fileName, int width, int height, double fps) { + InternalFFMpegRegister::Register(); + fmt_ = 0; oc_ = 0; video_st_ = 0; - // tell FFMPEG to register codecs - av_register_all(); - - av_log_set_level(AV_LOG_ERROR); - // auto detect the output format from the name and fourcc code #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 2, 0) fmt_ = av_guess_format(NULL, fileName, NULL); @@ -1920,6 +2073,8 @@ private: bool InputMediaStream_FFMPEG::open(const char* fileName, int* codec, int* chroma_format, int* width, int* height) { + InternalFFMpegRegister::Register(); + int err; ctx_ = 0; @@ -1930,11 +2085,6 @@ bool InputMediaStream_FFMPEG::open(const char* fileName, int* codec, int* chroma avformat_network_init(); #endif - // register all codecs, demux and protocols - av_register_all(); - - av_log_set_level(AV_LOG_ERROR); - #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(53, 6, 0) err = avformat_open_input(&ctx_, fileName, 0, 0); #else @@ -2054,7 +2204,7 @@ bool InputMediaStream_FFMPEG::read(unsigned char** data, int* size, int* endOfFi if (ret < 0) { - if (ret == AVERROR_EOF) + if (ret == (int)AVERROR_EOF) *endOfFile = true; return false; } diff --git a/modules/highgui/src/cap_gstreamer.cpp b/modules/highgui/src/cap_gstreamer.cpp index e8cf213261..60ba8852e6 100644 --- a/modules/highgui/src/cap_gstreamer.cpp +++ b/modules/highgui/src/cap_gstreamer.cpp @@ -65,7 +65,24 @@ #define CV_WARN(message) fprintf(stderr, "warning: %s (%s:%d)\n", message, __FILE__, __LINE__) #endif -static bool isInited = false; +static cv::Mutex gst_initializer_mutex; + +class gst_initializer +{ +public: + static void init() + { + gst_initializer_mutex.lock(); + static gst_initializer init; + gst_initializer_mutex.unlock(); + } +private: + gst_initializer() + { + gst_init(NULL, NULL); + } +}; + class CvCapture_GStreamer : public CvCapture { public: @@ -298,16 +315,18 @@ bool CvCapture_GStreamer::open( int type, const char* filename ) __BEGIN__; - if(!isInited) { + gst_initializer::init(); + +// if(!isInited) { // printf("gst_init\n"); - gst_init (NULL, NULL); +// gst_init (NULL, NULL); // gst_debug_set_active(TRUE); // gst_debug_set_colored(TRUE); // gst_debug_set_default_threshold(GST_LEVEL_WARNING); - isInited = true; - } +// isInited = true; +// } bool stream = false; bool manualpipeline = false; char *uri = NULL; @@ -477,10 +496,11 @@ bool CvVideoWriter_GStreamer::open( const char * filename, int fourcc, encit=encs.find(fourcc); if (encit==encs.end()) CV_ERROR( CV_StsUnsupportedFormat,"Gstreamer Opencv backend doesn't support this codec acutally."); - if(!isInited) { - gst_init (NULL, NULL); - isInited = true; - } +// if(!isInited) { +// gst_init (NULL, NULL); +// isInited = true; +// } + gst_initializer::init(); close(); source=gst_element_factory_make("appsrc",NULL); file=gst_element_factory_make("filesink", NULL); diff --git a/modules/highgui/src/cap_libv4l.cpp b/modules/highgui/src/cap_libv4l.cpp index b1be7f2e86..01b611c66c 100644 --- a/modules/highgui/src/cap_libv4l.cpp +++ b/modules/highgui/src/cap_libv4l.cpp @@ -1008,10 +1008,6 @@ static CvCaptureCAM_V4L * icvCaptureFromCAM_V4L (int index) return NULL; } - /* set the default size */ - capture->width = DEFAULT_V4L_WIDTH; - capture->height = DEFAULT_V4L_HEIGHT; - #ifdef USE_TEMP_BUFFER capture->buffers[MAX_V4L_BUFFERS].start = NULL; #endif @@ -1035,6 +1031,9 @@ static CvCaptureCAM_V4L * icvCaptureFromCAM_V4L (int index) the standard set of cv calls promoting transparency. "Vector Table" insertion. */ capture->FirstCapture = 1; + /* set the default size */ + capture->width = DEFAULT_V4L_WIDTH; + capture->height = DEFAULT_V4L_HEIGHT; if (_capture_V4L2 (capture, deviceName) == -1) { icvCloseCAM_V4L(capture); diff --git a/modules/highgui/test/test_ffmpeg.cpp b/modules/highgui/test/test_ffmpeg.cpp index fb32e015fa..ed06a2cbdd 100644 --- a/modules/highgui/test/test_ffmpeg.cpp +++ b/modules/highgui/test/test_ffmpeg.cpp @@ -43,11 +43,12 @@ #include "test_precomp.hpp" #include "opencv2/highgui/highgui.hpp" +using namespace cv; + #ifdef HAVE_FFMPEG #include "ffmpeg_codecs.hpp" -using namespace cv; using namespace std; class CV_FFmpegWriteBigVideoTest : public cvtest::BaseTest @@ -118,11 +119,11 @@ public: else { Mat img(frame_s, CV_8UC3, Scalar::all(0)); - const int coeff = cvRound(cv::min(frame_s.width, frame_s.height)/(fps0 * time_sec)); + const int coeff = cvRound(min(frame_s.width, frame_s.height)/(fps0 * time_sec)); for (int i = 0 ; i < static_cast(fps * time_sec); i++ ) { - //circle(img, Point2i(img_c / 2, img_r / 2), cv::min(img_r, img_c) / 2 * (i + 1), Scalar(255, 0, 0, 0), 2); + //circle(img, Point2i(img_c / 2, img_r / 2), min(img_r, img_c) / 2 * (i + 1), Scalar(255, 0, 0, 0), 2); rectangle(img, Point2i(coeff * i, coeff * i), Point2i(coeff * (i + 1), coeff * (i + 1)), Scalar::all(255 * (1.0 - static_cast(i) / (fps * time_sec * 2) )), -1); writer << img; @@ -174,3 +175,221 @@ public: TEST(Highgui_Video, ffmpeg_image) { CV_FFmpegReadImageTest test; test.safe_run(); } #endif + +#if defined(HAVE_FFMPEG) || defined(WIN32) || defined(_WIN32) + +//////////////////////////////// Parallel VideoWriters and VideoCaptures //////////////////////////////////// + +class CreateVideoWriterInvoker : + public ParallelLoopBody +{ +public: + const static Size FrameSize; + static std::string TmpDirectory; + + CreateVideoWriterInvoker(std::vector& _writers, std::vector& _files) : + ParallelLoopBody(), writers(&_writers), files(&_files) + { + } + + virtual void operator() (const Range& range) const + { + for (int i = range.start; i != range.end; ++i) + { + std::ostringstream stream; + stream << i << ".avi"; + std::string fileName = tempfile(stream.str().c_str()); + + files->operator[](i) = fileName; + writers->operator[](i) = new VideoWriter(fileName, CV_FOURCC('X','V','I','D'), 25.0f, FrameSize); + + CV_Assert(writers->operator[](i)->isOpened()); + } + } + + +private: + std::vector* writers; + std::vector* files; +}; + +std::string CreateVideoWriterInvoker::TmpDirectory; +const Size CreateVideoWriterInvoker::FrameSize(1020, 900); + +class WriteVideo_Invoker : + public ParallelLoopBody +{ +public: + enum { FrameCount = 300 }; + + static const Scalar ObjectColor; + static const Point Center; + + WriteVideo_Invoker(const std::vector& _writers) : + ParallelLoopBody(), writers(&_writers) + { + } + + static void GenerateFrame(Mat& frame, unsigned int i) + { + frame = Scalar::all(i % 255); + + std::string text = to_string(i); + putText(frame, text, Point(50, Center.y), FONT_HERSHEY_SIMPLEX, 5.0, ObjectColor, 5, CV_AA); + circle(frame, Center, i + 2, ObjectColor, 2, CV_AA); + } + + virtual void operator() (const Range& range) const + { + CV_Assert((range.start + 1) == range.end); + VideoWriter* writer = writers->operator[](range.start); + CV_Assert(writer != NULL); + CV_Assert(writer->isOpened()); + + Mat frame(CreateVideoWriterInvoker::FrameSize, CV_8UC3); + for (unsigned int i = 0; i < FrameCount; ++i) + { + GenerateFrame(frame, i); + writer->operator<< (frame); + } + } + +protected: + static std::string to_string(unsigned int i) + { + std::stringstream stream(std::ios::out); + stream << "frame #" << i; + return stream.str(); + } + +private: + const std::vector* writers; +}; + +const Scalar WriteVideo_Invoker::ObjectColor(Scalar::all(0)); +const Point WriteVideo_Invoker::Center(CreateVideoWriterInvoker::FrameSize.height / 2, + CreateVideoWriterInvoker::FrameSize.width / 2); + +class CreateVideoCaptureInvoker : + public ParallelLoopBody +{ +public: + CreateVideoCaptureInvoker(std::vector& _readers, const std::vector& _files) : + ParallelLoopBody(), readers(&_readers), files(&_files) + { + } + + virtual void operator() (const Range& range) const + { + for (int i = range.start; i != range.end; ++i) + { + readers->operator[](i) = new VideoCapture(files->operator[](i)); + CV_Assert(readers->operator[](i)->isOpened()); + } + } +private: + std::vector* readers; + const std::vector* files; +}; + +class ReadImageAndTest : + public ParallelLoopBody +{ +public: + ReadImageAndTest(const std::vector& _readers, cvtest::TS* _ts) : + ParallelLoopBody(), readers(&_readers), ts(_ts) + { + } + + virtual void operator() (const Range& range) const + { + CV_Assert(range.start + 1 == range.end); + VideoCapture* capture = readers->operator[](range.start); + CV_Assert(capture != NULL); + CV_Assert(capture->isOpened()); + + const static double eps = 23.0; + unsigned int frameCount = static_cast(capture->get(CV_CAP_PROP_FRAME_COUNT)); + CV_Assert(frameCount == WriteVideo_Invoker::FrameCount); + Mat reference(CreateVideoWriterInvoker::FrameSize, CV_8UC3); + + for (unsigned int i = 0; i < frameCount && next; ++i) + { + Mat actual; + (*capture) >> actual; + + WriteVideo_Invoker::GenerateFrame(reference, i); + + EXPECT_EQ(reference.cols, actual.cols); + EXPECT_EQ(reference.rows, actual.rows); + EXPECT_EQ(reference.depth(), actual.depth()); + EXPECT_EQ(reference.channels(), actual.channels()); + + double psnr = PSNR(actual, reference); + if (psnr < eps) + { +#define SUM cvtest::TS::SUMMARY + ts->printf(SUM, "\nPSNR: %lf\n", psnr); + ts->printf(SUM, "Video #: %d\n", range.start); + ts->printf(SUM, "Frame #: %d\n", i); +#undef SUM + ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); + ts->set_gtest_status(); + + Mat diff; + absdiff(actual, reference, diff); + + EXPECT_EQ(countNonZero(diff.reshape(1) > 1), 0); + + next = false; + } + } + } + + static bool next; + +private: + const std::vector* readers; + cvtest::TS* ts; +}; + +bool ReadImageAndTest::next; + +TEST(Highgui_Video_parallel_writers_and_readers, accuracy) +{ + const unsigned int threadsCount = 4; + cvtest::TS* ts = cvtest::TS::ptr(); + + // creating VideoWriters + std::vector writers(threadsCount); + Range range(0, threadsCount); + std::vector files(threadsCount); + CreateVideoWriterInvoker invoker1(writers, files); + parallel_for_(range, invoker1); + + // write a video + parallel_for_(range, WriteVideo_Invoker(writers)); + + // deleting the writers + for (std::vector::iterator i = writers.begin(), end = writers.end(); i != end; ++i) + delete *i; + writers.clear(); + + std::vector readers(threadsCount); + CreateVideoCaptureInvoker invoker2(readers, files); + parallel_for_(range, invoker2); + + ReadImageAndTest::next = true; + + parallel_for_(range, ReadImageAndTest(readers, ts)); + + // deleting tmp video files + for (std::vector::const_iterator i = files.begin(), end = files.end(); i != end; ++i) + { + int code = remove(i->c_str()); + if (code == 1) + std::cerr << "Couldn't delete " << *i << std::endl; + } +} + +#endif diff --git a/modules/imgproc/perf/perf_blur.cpp b/modules/imgproc/perf/perf_blur.cpp index 36519f3eca..a79603f701 100644 --- a/modules/imgproc/perf/perf_blur.cpp +++ b/modules/imgproc/perf/perf_blur.cpp @@ -63,11 +63,7 @@ PERF_TEST_P(Size_MatType_BorderType3x3, gaussianBlur3x3, TEST_CYCLE() GaussianBlur(src, dst, Size(3,3), 0, 0, btype); -#if CV_SSE2 SANITY_CHECK(dst, 1); -#else - SANITY_CHECK(dst); -#endif } PERF_TEST_P(Size_MatType_BorderType3x3, blur3x3, @@ -89,7 +85,7 @@ PERF_TEST_P(Size_MatType_BorderType3x3, blur3x3, TEST_CYCLE() blur(src, dst, Size(3,3), Point(-1,-1), btype); - SANITY_CHECK(dst, 1e-3); + SANITY_CHECK(dst, 1); } PERF_TEST_P(Size_MatType_BorderType, blur16x16, @@ -183,7 +179,7 @@ PERF_TEST_P(Size_MatType_BorderType, gaussianBlur5x5, TEST_CYCLE() GaussianBlur(src, dst, Size(5,5), 0, 0, btype); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1e-3); } PERF_TEST_P(Size_MatType_BorderType, blur5x5, @@ -205,5 +201,5 @@ PERF_TEST_P(Size_MatType_BorderType, blur5x5, TEST_CYCLE() blur(src, dst, Size(5,5), Point(-1,-1), btype); - SANITY_CHECK(dst, 1e-3); + SANITY_CHECK(dst, 1); } diff --git a/modules/imgproc/perf/perf_cvt_color.cpp b/modules/imgproc/perf/perf_cvt_color.cpp index 42914fbdc7..67cec0f1cd 100644 --- a/modules/imgproc/perf/perf_cvt_color.cpp +++ b/modules/imgproc/perf/perf_cvt_color.cpp @@ -244,6 +244,7 @@ PERF_TEST_P(Size_CvtMode, cvtColor8u, Mat src(sz, CV_8UC(ch.scn)); Mat dst(sz, CV_8UC(ch.dcn)); + declare.time(100); declare.in(src, WARMUP_RNG).out(dst); TEST_CYCLE() cvtColor(src, dst, mode, ch.dcn); @@ -268,6 +269,7 @@ PERF_TEST_P(Size_CvtMode2, cvtColorYUV420, Mat src(sz.height + sz.height / 2, sz.width, CV_8UC(ch.scn)); Mat dst(sz, CV_8UC(ch.dcn)); + declare.time(100); declare.in(src, WARMUP_RNG).out(dst); TEST_CYCLE() cvtColor(src, dst, mode, ch.dcn); diff --git a/modules/imgproc/perf/perf_filter2d.cpp b/modules/imgproc/perf/perf_filter2d.cpp index e5310e2676..4176e66a7b 100644 --- a/modules/imgproc/perf/perf_filter2d.cpp +++ b/modules/imgproc/perf/perf_filter2d.cpp @@ -39,7 +39,7 @@ PERF_TEST_P( TestFilter2d, Filter2d, TEST_CYCLE() filter2D(src, dst, CV_8UC4, kernel, Point(1, 1), 0., borderMode); - SANITY_CHECK(dst); + SANITY_CHECK(dst, 1); } PERF_TEST_P( Image_KernelSize, GaborFilter2d, diff --git a/modules/imgproc/perf/perf_houghLines.cpp b/modules/imgproc/perf/perf_houghLines.cpp index 055c575665..c032c35850 100644 --- a/modules/imgproc/perf/perf_houghLines.cpp +++ b/modules/imgproc/perf/perf_houghLines.cpp @@ -32,7 +32,7 @@ PERF_TEST_P(Image_RhoStep_ThetaStep_Threshold, HoughLines, Canny(image, image, 0, 0); Mat lines; - declare.time(7); + declare.time(40); TEST_CYCLE() HoughLines(image, lines, rhoStep, thetaStep, threshold); diff --git a/modules/imgproc/perf/perf_integral.cpp b/modules/imgproc/perf/perf_integral.cpp index 9a6b7ad017..2760d7ad21 100644 --- a/modules/imgproc/perf/perf_integral.cpp +++ b/modules/imgproc/perf/perf_integral.cpp @@ -48,6 +48,7 @@ PERF_TEST_P(Size_MatType_OutMatDepth, integral_sqsum, Mat sqsum(sz, sdepth); declare.in(src, WARMUP_RNG).out(sum, sqsum); + declare.time(100); TEST_CYCLE() integral(src, sum, sqsum, sdepth); @@ -73,6 +74,7 @@ PERF_TEST_P( Size_MatType_OutMatDepth, integral_sqsum_tilted, Mat tilted(sz, sdepth); declare.in(src, WARMUP_RNG).out(sum, sqsum, tilted); + declare.time(100); TEST_CYCLE() integral(src, sum, sqsum, tilted, sdepth); diff --git a/modules/imgproc/perf/perf_resize.cpp b/modules/imgproc/perf/perf_resize.cpp index 4db5e49da8..82bf0d37cf 100644 --- a/modules/imgproc/perf/perf_resize.cpp +++ b/modules/imgproc/perf/perf_resize.cpp @@ -28,7 +28,12 @@ PERF_TEST_P(MatInfo_Size_Size, resizeUpLinear, TEST_CYCLE() resize(src, dst, to); + // Test case temporary disabled for Android Platform +#ifdef ANDROID + SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions +#else SANITY_CHECK(dst, 1 + 1e-6); +#endif } PERF_TEST_P(MatInfo_Size_Size, resizeDownLinear, @@ -52,7 +57,12 @@ PERF_TEST_P(MatInfo_Size_Size, resizeDownLinear, TEST_CYCLE() resize(src, dst, to); + // Test case temporary disabled for Android Platform +#ifdef ANDROID + SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions +#else SANITY_CHECK(dst, 1 + 1e-6); +#endif } @@ -106,6 +116,7 @@ PERF_TEST_P(MatInfo_Size_Scale_Area, ResizeArea, cv::Mat dst(to, matType); declare.in(src, WARMUP_RNG).out(dst); + declare.time(100); TEST_CYCLE() resize(src, dst, dst.size(), 0, 0, INTER_AREA); diff --git a/modules/imgproc/perf/perf_threshold.cpp b/modules/imgproc/perf/perf_threshold.cpp index f80fb65a33..65c13a05e2 100644 --- a/modules/imgproc/perf/perf_threshold.cpp +++ b/modules/imgproc/perf/perf_threshold.cpp @@ -31,6 +31,7 @@ PERF_TEST_P(Size_MatType_ThreshType, threshold, double maxval = theRNG().uniform(1, 254); declare.in(src, WARMUP_RNG).out(dst); + declare.time(100); TEST_CYCLE() threshold(src, dst, thresh, maxval, threshType); diff --git a/modules/imgproc/perf/perf_warp.cpp b/modules/imgproc/perf/perf_warp.cpp index b84e7ca982..1f2ffb6921 100644 --- a/modules/imgproc/perf/perf_warp.cpp +++ b/modules/imgproc/perf/perf_warp.cpp @@ -43,8 +43,12 @@ PERF_TEST_P( TestWarpAffine, WarpAffine, TEST_CYCLE() warpAffine( src, dst, warpMat, sz, interType, borderMode, Scalar::all(150) ); + // Test case temporary disabled for Android Platform +#ifdef ANDROID + SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions +#else SANITY_CHECK(dst, 1); - +#endif } PERF_TEST_P( TestWarpPerspective, WarpPerspective, @@ -133,13 +137,19 @@ PERF_TEST_P( TestWarpPerspectiveNear_t, WarpPerspectiveNear, Mat dst(size, type); declare.in(src).out(dst); + declare.time(100); TEST_CYCLE() { warpPerspective( src, dst, warpMat, size, interType, borderMode, Scalar::all(150) ); } + // Test case temporary disabled for Android Platform +#ifdef ANDROID + SANITY_CHECK(dst, 255); // TODO: Reimplement check in future versions +#else SANITY_CHECK(dst, 1); +#endif } PERF_TEST_P( TestRemap, remap, diff --git a/modules/java/android_lib/res/values/attrs.xml b/modules/java/android_lib/res/values/attrs.xml new file mode 100644 index 0000000000..0cdf1097a0 --- /dev/null +++ b/modules/java/android_lib/res/values/attrs.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/modules/java/check-tests.py b/modules/java/check-tests.py index 55118ca914..4cb80ff724 100755 --- a/modules/java/check-tests.py +++ b/modules/java/check-tests.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys, os, re classes_ignore_list = ( diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 2287058a94..c60730fad3 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys, re, os.path from string import Template diff --git a/modules/java/generator/gen_javadoc.py b/modules/java/generator/gen_javadoc.py index 97eac702ad..3c697277b5 100755 --- a/modules/java/generator/gen_javadoc.py +++ b/modules/java/generator/gen_javadoc.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import os, sys, re, string, glob from optparse import OptionParser diff --git a/modules/java/generator/rst_parser.py b/modules/java/generator/rst_parser.py index 65e66f7f9d..f4ef581904 100755 --- a/modules/java/generator/rst_parser.py +++ b/modules/java/generator/rst_parser.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import os, sys, re, string, fnmatch allmodules = ["core", "flann", "imgproc", "ml", "highgui", "video", "features2d", "calib3d", "objdetect", "legacy", "contrib", "gpu", "androidcamera", "java", "python", "stitching", "ts", "photo", "nonfree", "videostab", "ocl"] verbose = False diff --git a/modules/java/generator/src/java/android+CameraBridgeViewBase.java b/modules/java/generator/src/java/android+CameraBridgeViewBase.java index cbcd78b35e..cd13d1f1a0 100644 --- a/modules/java/generator/src/java/android+CameraBridgeViewBase.java +++ b/modules/java/generator/src/java/android+CameraBridgeViewBase.java @@ -2,6 +2,7 @@ package org.opencv.android; import java.util.List; +import org.opencv.R; import org.opencv.android.Utils; import org.opencv.core.Mat; import org.opencv.core.Size; @@ -11,6 +12,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.util.AttributeSet; @@ -26,22 +28,44 @@ import android.view.SurfaceView; * The clients shall implement CvCameraViewListener. */ public abstract class CameraBridgeViewBase extends SurfaceView implements SurfaceHolder.Callback { -//TODO: add method to control the format in which the frames will be delivered to CvCameraViewListener + private static final String TAG = "CameraBridge"; private static final int MAX_UNSPECIFIED = -1; + private static final int STOPPED = 0; + private static final int STARTED = 1; + + private int mState = STOPPED; + private Bitmap mCacheBitmap; + private CvCameraViewListener mListener; + private boolean mSurfaceExist; + private Object mSyncObject = new Object(); protected int mFrameWidth; protected int mFrameHeight; - protected int mMaxHeight; protected int mMaxWidth; - protected int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA; + protected int mCameraIndex = -1; + protected boolean mEnabled; + protected FpsMeter mFpsMeter = null; - private Bitmap mCacheBitmap; + public CameraBridgeViewBase(Context context, int cameraId) { + super(context); + mCameraIndex = cameraId; + } public CameraBridgeViewBase(Context context, AttributeSet attrs) { super(context, attrs); + + int count = attrs.getAttributeCount(); + Log.d(TAG, "Attr count: " + Integer.valueOf(count)); + + TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase); + if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false)) + enableFpsMeter(); + + mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1); + getHolder().addCallback(this); mMaxWidth = MAX_UNSPECIFIED; mMaxHeight = MAX_UNSPECIFIED; @@ -71,19 +95,6 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac } - private static final int STOPPED = 0; - private static final int STARTED = 1; - - private static final String TAG = "CameraBridge"; - - private CvCameraViewListener mListener; - private int mState = STOPPED; - - private boolean mEnabled; - private boolean mSurfaceExist; - - private Object mSyncObject = new Object(); - public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { Log.d(TAG, "call surfaceChanged event"); synchronized(mSyncObject) { @@ -135,6 +146,25 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac } } + /** + * This method enables label with fps value on the screen + */ + public void enableFpsMeter() { + if (mFpsMeter == null) { + mFpsMeter = new FpsMeter(); + mFpsMeter.setResolution(mFrameWidth, mFrameHeight); + } + } + + public void disableFpsMeter() { + mFpsMeter = null; + } + + /** + * + * @param listener + */ + public void setCvCameraViewListener(CvCameraViewListener listener) { mListener = listener; } @@ -272,6 +302,10 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac if (canvas != null) { canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR); canvas.drawBitmap(mCacheBitmap, (canvas.getWidth() - mCacheBitmap.getWidth()) / 2, (canvas.getHeight() - mCacheBitmap.getHeight()) / 2, null); + if (mFpsMeter != null) { + mFpsMeter.measure(); + mFpsMeter.draw(canvas, 20, 30); + } getHolder().unlockCanvasAndPost(canvas); } } diff --git a/modules/java/generator/src/java/android+FpsMeter.java b/modules/java/generator/src/java/android+FpsMeter.java new file mode 100644 index 0000000000..88e826cf96 --- /dev/null +++ b/modules/java/generator/src/java/android+FpsMeter.java @@ -0,0 +1,66 @@ +package org.opencv.android; + +import java.text.DecimalFormat; + +import org.opencv.core.Core; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.util.Log; + +public class FpsMeter { + private static final String TAG = "FpsMeter"; + private static final int STEP = 20; + private static final DecimalFormat FPS_FORMAT = new DecimalFormat("0.00"); + + private int mFramesCouner; + private double mFrequency; + private long mprevFrameTime; + private String mStrfps; + Paint mPaint; + boolean mIsInitialized = false; + int mWidth = 0; + int mHeight = 0; + + public void init() { + mFramesCouner = 0; + mFrequency = Core.getTickFrequency(); + mprevFrameTime = Core.getTickCount(); + mStrfps = ""; + + mPaint = new Paint(); + mPaint.setColor(Color.BLUE); + mPaint.setTextSize(20); + } + + public void measure() { + if (!mIsInitialized) { + init(); + mIsInitialized = true; + } else { + mFramesCouner++; + if (mFramesCouner % STEP == 0) { + long time = Core.getTickCount(); + double fps = STEP * mFrequency / (time - mprevFrameTime); + mprevFrameTime = time; + if (mWidth != 0 && mHeight != 0) + mStrfps = FPS_FORMAT.format(fps) + " FPS@" + Integer.valueOf(mWidth) + "x" + Integer.valueOf(mHeight); + else + mStrfps = FPS_FORMAT.format(fps) + " FPS"; + Log.i(TAG, mStrfps); + } + } + } + + public void setResolution(int width, int height) { + mWidth = width; + mHeight = height; + } + + public void draw(Canvas canvas, float offsetx, float offsety) { + Log.d(TAG, mStrfps); + canvas.drawText(mStrfps, offsetx, offsety, mPaint); + } + +} diff --git a/modules/java/generator/src/java/android+JavaCameraView.java b/modules/java/generator/src/java/android+JavaCameraView.java index f8b3787819..ce50d66a96 100644 --- a/modules/java/generator/src/java/android+JavaCameraView.java +++ b/modules/java/generator/src/java/android+JavaCameraView.java @@ -40,6 +40,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb private Thread mThread; private boolean mStopThread; + protected Camera mCamera; + private SurfaceTexture mSurfaceTexture; public static class JavaCameraSizeAccessor implements ListItemAccessor { @@ -55,7 +57,9 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb } } - private Camera mCamera; + public JavaCameraView(Context context, int cameraId) { + super(context, cameraId); + } public JavaCameraView(Context context, AttributeSet attrs) { super(context, attrs); @@ -69,25 +73,36 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb synchronized (this) { mCamera = null; - Log.d(TAG, "Trying to open camera with old open()"); - try { - mCamera = Camera.open(); - } - catch (Exception e){ - Log.e(TAG, "Camera is not available (in use or does not exist): " + e.getLocalizedMessage()); - } + if (mCameraIndex == -1) { + Log.d(TAG, "Trying to open camera with old open()"); + try { + mCamera = Camera.open(); + } + catch (Exception e){ + Log.e(TAG, "Camera is not available (in use or does not exist): " + e.getLocalizedMessage()); + } - if(mCamera == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { - boolean connected = false; - for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); ++camIdx) { - Log.d(TAG, "Trying to open camera with new open(" + Integer.valueOf(camIdx) + ")"); - try { - mCamera = Camera.open(camIdx); - connected = true; - } catch (RuntimeException e) { - Log.e(TAG, "Camera #" + camIdx + "failed to open: " + e.getLocalizedMessage()); + if(mCamera == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + boolean connected = false; + for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); ++camIdx) { + Log.d(TAG, "Trying to open camera with new open(" + Integer.valueOf(camIdx) + ")"); + try { + mCamera = Camera.open(camIdx); + connected = true; + } catch (RuntimeException e) { + Log.e(TAG, "Camera #" + camIdx + "failed to open: " + e.getLocalizedMessage()); + } + if (connected) break; + } + } + } else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { + Log.d(TAG, "Trying to open camera with new open(" + Integer.valueOf(mCameraIndex) + ")"); + try { + mCamera = Camera.open(mCameraIndex); + } catch (RuntimeException e) { + Log.e(TAG, "Camera #" + mCameraIndex + "failed to open: " + e.getLocalizedMessage()); } - if (connected) break; } } @@ -120,6 +135,10 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb mFrameWidth = params.getPreviewSize().width; mFrameHeight = params.getPreviewSize().height; + if (mFpsMeter != null) { + mFpsMeter.setResolution(mFrameWidth, mFrameHeight); + } + int size = mFrameWidth * mFrameHeight; size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8; mBuffer = new byte[size]; @@ -217,6 +236,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb releaseCamera(); } + @TargetApi(Build.VERSION_CODES.FROYO) public void onPreviewFrame(byte[] frame, Camera arg1) { Log.i(TAG, "Preview Frame received. Need to create MAT and deliver it to clients"); Log.i(TAG, "Frame size is " + frame.length); diff --git a/modules/java/generator/src/java/android+NativeCameraView.java b/modules/java/generator/src/java/android+NativeCameraView.java index a62d6bb5c7..dad3cb95f5 100644 --- a/modules/java/generator/src/java/android+NativeCameraView.java +++ b/modules/java/generator/src/java/android+NativeCameraView.java @@ -19,7 +19,12 @@ public class NativeCameraView extends CameraBridgeViewBase { public static final String TAG = "NativeCameraView"; private boolean mStopThread; private Thread mThread; - private VideoCapture mCamera; + + protected VideoCapture mCamera; + + public NativeCameraView(Context context, int cameraId) { + super(context, cameraId); + } public NativeCameraView(Context context, AttributeSet attrs) { super(context, attrs); @@ -77,12 +82,17 @@ public class NativeCameraView extends CameraBridgeViewBase { private boolean initializeCamera(int width, int height) { synchronized (this) { - mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID); + + if (mCameraIndex == -1) + mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID); + else + mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID + mCameraIndex); if (mCamera == null) return false; - //TODO: improve error handling + if (mCamera.isOpened() == false) + return false; java.util.List sizes = mCamera.getSupportedPreviewSizes(); @@ -92,6 +102,10 @@ public class NativeCameraView extends CameraBridgeViewBase { mFrameWidth = (int)frameSize.width; mFrameHeight = (int)frameSize.height; + if (mFpsMeter != null) { + mFpsMeter.setResolution(mFrameWidth, mFrameHeight); + } + AllocateCache(); mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, frameSize.width); diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index 8d4ef6957c..ad3a730522 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -46,7 +46,7 @@ #include - +#if defined (LOG_CASCADE_STATISTIC) struct Logger { enum { STADIES_NUM = 20 }; @@ -109,7 +109,7 @@ struct Logger } } logger; - +#endif namespace cv { diff --git a/modules/photo/perf/perf_inpaint.cpp b/modules/photo/perf/perf_inpaint.cpp index 6f039b4194..ea23bb4032 100644 --- a/modules/photo/perf/perf_inpaint.cpp +++ b/modules/photo/perf/perf_inpaint.cpp @@ -29,7 +29,7 @@ PERF_TEST_P(InpaintArea_InpaintingMethod, inpaint, Rect inpaintArea(src.cols/3, src.rows/3, sz.width, sz.height); mask(inpaintArea).setTo(255); - declare.in(src, mask).out(result).time(30); + declare.in(src, mask).out(result).time(120); TEST_CYCLE() inpaint(src, mask, result, 10.0, inpaintingMethod); diff --git a/modules/python/src2/cv.py b/modules/python/src2/cv.py index 2d4daf08b0..4238d05f7a 100755 --- a/modules/python/src2/cv.py +++ b/modules/python/src2/cv.py @@ -1 +1,3 @@ +#/usr/bin/env python + from cv2.cv import * diff --git a/modules/python/src2/gen.py b/modules/python/src2/gen.py index 2ffb445443..65cafc9900 100755 --- a/modules/python/src2/gen.py +++ b/modules/python/src2/gen.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys from string import Template diff --git a/modules/python/src2/gen2.py b/modules/python/src2/gen2.py index e600a82f45..5381579ce4 100755 --- a/modules/python/src2/gen2.py +++ b/modules/python/src2/gen2.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import hdr_parser, sys, re, os, cStringIO from string import Template diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py index a18a4feb42..090ed6f64a 100755 --- a/modules/python/src2/hdr_parser.py +++ b/modules/python/src2/hdr_parser.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import os, sys, re, string # the list only for debugging. The real list, used in the real OpenCV build, is specified in CMakeLists.txt diff --git a/modules/python/test/calchist.py b/modules/python/test/calchist.py index c371e73ce3..0a52258b20 100755 --- a/modules/python/test/calchist.py +++ b/modules/python/test/calchist.py @@ -1,5 +1,6 @@ -# Calculating and displaying 2D Hue-Saturation histogram of a color image +#/usr/bin/env python +# Calculating and displaying 2D Hue-Saturation histogram of a color image import sys import cv2.cv as cv diff --git a/modules/python/test/camera_calibration.py b/modules/python/test/camera_calibration.py index 989207c8a8..488dd15c62 100755 --- a/modules/python/test/camera_calibration.py +++ b/modules/python/test/camera_calibration.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys import math import time diff --git a/modules/python/test/findstereocorrespondence.py b/modules/python/test/findstereocorrespondence.py index 9cc19412c2..8f11738cce 100755 --- a/modules/python/test/findstereocorrespondence.py +++ b/modules/python/test/findstereocorrespondence.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys import cv2.cv as cv diff --git a/modules/python/test/goodfeatures.py b/modules/python/test/goodfeatures.py index e4c4b0a6fd..62907772ab 100755 --- a/modules/python/test/goodfeatures.py +++ b/modules/python/test/goodfeatures.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import cv2.cv as cv import unittest diff --git a/modules/python/test/leak1.py b/modules/python/test/leak1.py index 49326dab50..dde5608951 100755 --- a/modules/python/test/leak1.py +++ b/modules/python/test/leak1.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import cv2.cv as cv import numpy as np cv.NamedWindow('Leak') diff --git a/modules/python/test/leak2.py b/modules/python/test/leak2.py index ca511a40ec..af1cb0556c 100755 --- a/modules/python/test/leak2.py +++ b/modules/python/test/leak2.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import cv2.cv as cv import numpy as np import time diff --git a/modules/python/test/leak3.py b/modules/python/test/leak3.py index 901d7be20f..f72afbbf08 100755 --- a/modules/python/test/leak3.py +++ b/modules/python/test/leak3.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import cv2.cv as cv import math import time diff --git a/modules/python/test/leak4.py b/modules/python/test/leak4.py index 8d8ba8883a..dcfc5cfdc9 100755 --- a/modules/python/test/leak4.py +++ b/modules/python/test/leak4.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import cv2.cv as cv import math import time diff --git a/modules/python/test/precornerdetect.py b/modules/python/test/precornerdetect.py index 49c8e076d9..29a6ca1ecd 100755 --- a/modules/python/test/precornerdetect.py +++ b/modules/python/test/precornerdetect.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import cv2.cv as cv def precornerdetect(image): diff --git a/modules/python/test/test.py b/modules/python/test/test.py index 42dfab209e..924708c483 100755 --- a/modules/python/test/test.py +++ b/modules/python/test/test.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import unittest import random import time diff --git a/modules/python/test/ticket_6.py b/modules/python/test/ticket_6.py index e6cc62f378..533027f5b9 100755 --- a/modules/python/test/ticket_6.py +++ b/modules/python/test/ticket_6.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import urllib import cv2.cv as cv import Image diff --git a/modules/python/test/tickets.py b/modules/python/test/tickets.py index aa6818059a..1e756bcd82 100755 --- a/modules/python/test/tickets.py +++ b/modules/python/test/tickets.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import unittest import random import time diff --git a/modules/python/test/transformations.py b/modules/python/test/transformations.py index 6d6f19e5b9..1f63bcef22 100755 --- a/modules/python/test/transformations.py +++ b/modules/python/test/transformations.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + # -*- coding: utf-8 -*- # transformations.py diff --git a/modules/ts/misc/chart.py b/modules/ts/misc/chart.py index 604b85048a..39a60eb2e7 100755 --- a/modules/ts/misc/chart.py +++ b/modules/ts/misc/chart.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + import testlog_parser, sys, os, xml, re from table_formatter import * from optparse import OptionParser diff --git a/modules/ts/misc/color.py b/modules/ts/misc/color.py index 3ce725276e..4492ed4798 100755 --- a/modules/ts/misc/color.py +++ b/modules/ts/misc/color.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + import math, os, sys webcolors = { diff --git a/modules/ts/misc/concatlogs.py b/modules/ts/misc/concatlogs.py index af95bac20d..afcb9cc89f 100755 --- a/modules/ts/misc/concatlogs.py +++ b/modules/ts/misc/concatlogs.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + from optparse import OptionParser import glob, sys, os, re diff --git a/modules/ts/misc/report.py b/modules/ts/misc/report.py index edee85497e..6da89e512b 100755 --- a/modules/ts/misc/report.py +++ b/modules/ts/misc/report.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + import testlog_parser, sys, os, xml, re, glob from table_formatter import * from optparse import OptionParser diff --git a/modules/ts/misc/run.py b/modules/ts/misc/run.py index e1b275f321..d70effe545 100755 --- a/modules/ts/misc/run.py +++ b/modules/ts/misc/run.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + import sys, os, platform, xml, re, tempfile, glob, datetime, getpass, shutil from optparse import OptionParser from subprocess import Popen, PIPE @@ -267,17 +269,21 @@ class RunInfo(object): else: # assume here that device name may consists of any characters except newline connected_devices = re.findall(r"^[^\n]+[ \t]+device\r?$", adb_res, re.MULTILINE) - if len(connected_devices) != 1: - self.error = "Too many (%s) devices are connected. Please specify single device using --serial option" % (len(connected_devices)) + if not connected_devices: + self.error = "Android device not found" + self.adb = [] + elif len(connected_devices) != 1: + self.error = "Too many (%s) devices are connected. Please specify single device using --serial option:\n\n" % (len(connected_devices)) + adb_res self.adb = [] else: - adb_serial = connected_devices[0].split("\t")[0] - self.adb = self.adb + ["-s", adb_serial] - print "adb command:", " ".join(self.adb) + options.adb_serial = connected_devices[0].split("\t")[0] + self.adb = self.adb + ["-s", options.adb_serial] + if self.adb: + print "adb command:", " ".join(self.adb) - if self.adb: - #construct name for aapt tool - self.aapt = [os.path.join(os.path.dirname(self.adb[0]), ("aapt","aapt.exe")[hostos == 'nt'])] + if self.adb: + #construct name for aapt tool + self.aapt = [os.path.join(os.path.dirname(self.adb[0]), ("aapt","aapt.exe")[hostos == 'nt'])] # fix has_perf_tests param self.has_perf_tests = self.has_perf_tests == "ON" @@ -688,13 +694,12 @@ class RunInfo(object): exename = os.path.basename(exe) androidexe = andoidcwd + exename #upload - print >> _stderr, "Uploading", exename, "to device..." + _stderr.write("Uploading... ") output = Popen(self.adb + ["push", exe, androidexe], stdout=_stdout, stderr=_stderr).wait() if output != 0: print >> _stderr, "adb finishes unexpectedly with error code", output return #chmod - print >> _stderr, "Changing mode of ", androidexe output = Popen(self.adb + ["shell", "chmod 777 " + androidexe], stdout=_stdout, stderr=_stderr).wait() if output != 0: print >> _stderr, "adb finishes unexpectedly with error code", output @@ -704,7 +709,7 @@ class RunInfo(object): command = exename + " --help" else: command = exename + " " + " ".join(args) - print >> _stderr, "Running:", command + print >> _stderr, "Run command:", command if self.setUp is not None: self.setUp() Popen(self.adb + ["shell", "export OPENCV_TEST_DATA_PATH=" + self.test_data_path + "&& cd " + andoidcwd + "&& ./" + command], stdout=_stdout, stderr=_stderr).wait() @@ -712,17 +717,17 @@ class RunInfo(object): self.tearDown() # try get log if not self.options.help: - print >> _stderr, "Pulling", logfile, "from device..." + #_stderr.write("Pull log... ") hostlogpath = os.path.join(workingDir, logfile) - output = Popen(self.adb + ["pull", andoidcwd + logfile, hostlogpath], stdout=_stdout, stderr=_stderr).wait() + output = Popen(self.adb + ["pull", andoidcwd + logfile, hostlogpath], stdout=_stdout, stderr=PIPE).wait() if output != 0: print >> _stderr, "adb finishes unexpectedly with error code", output return #rm log - Popen(self.adb + ["shell", "rm " + andoidcwd + logfile], stdout=_stdout, stderr=_stderr).wait() + Popen(self.adb + ["shell", "rm " + andoidcwd + logfile], stdout=PIPE, stderr=PIPE).wait() # clean temporary files - Popen(self.adb + ["shell", "rm " + tempdir + "__opencv_temp.*"], stdout=_stdout, stderr=_stderr).wait() + Popen(self.adb + ["shell", "rm " + tempdir + "__opencv_temp.*"], stdout=PIPE, stderr=PIPE).wait() except OSError: pass if os.path.isfile(hostlogpath): @@ -739,7 +744,7 @@ class RunInfo(object): temp_path = tempfile.mkdtemp(prefix="__opencv_temp.", dir=orig_temp_path or None) os.environ['OPENCV_TEMP_PATH'] = temp_path - print >> _stderr, "Running:", " ".join(cmd) + print >> _stderr, "Run command:", " ".join(cmd) try: Popen(cmd, stdout=_stdout, stderr=_stderr, cwd = workingDir).wait() except OSError: @@ -806,6 +811,7 @@ if __name__ == "__main__": parser.add_option("", "--serial", dest="adb_serial", help="Android: directs command to the USB device or emulator with the given serial number", metavar="serial number", default="") parser.add_option("", "--package", dest="junit_package", help="Android: run jUnit tests for specified package", metavar="package", default="") parser.add_option("", "--help-tests", dest="help", help="Show help for test executable", action="store_true", default=False) + parser.add_option("", "--check", dest="check", help="Shortcut for '--perf_min_samples=1 --perf_force_samples=1'", action="store_true", default=False) (options, args) = parser.parse_args(argv) @@ -823,9 +829,12 @@ if __name__ == "__main__": tests = [s.strip() for s in options.tests.split(",") if s] if len(tests) != 1 or len(run_args) != 1: - #remove --gtest_output from params + # remove --gtest_output from params test_args = [a for a in test_args if not a.startswith("--gtest_output=")] + if options.check: + test_args.extend(["--perf_min_samples=1", "--perf_force_samples=1"]) + logs = [] for path in run_args: info = RunInfo(path, options) @@ -837,4 +846,4 @@ if __name__ == "__main__": logs.extend(info.runTests(tests, sys.stdout, sys.stderr, options.cwd, test_args)) if logs: - print >> sys.stderr, "Collected:", " ".join(logs) + print >> sys.stderr, "Collected: ", " ".join(logs) diff --git a/modules/ts/misc/summary.py b/modules/ts/misc/summary.py index 45b4aac13a..76c198427d 100755 --- a/modules/ts/misc/summary.py +++ b/modules/ts/misc/summary.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + import testlog_parser, sys, os, xml, glob, re from table_formatter import * from optparse import OptionParser diff --git a/modules/ts/misc/table_formatter.py b/modules/ts/misc/table_formatter.py index be89794f0e..598c9e924e 100755 --- a/modules/ts/misc/table_formatter.py +++ b/modules/ts/misc/table_formatter.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + import sys, re, os.path, cgi, stat from optparse import OptionParser from color import getColorizer diff --git a/modules/ts/misc/testlog_parser.py b/modules/ts/misc/testlog_parser.py index 7f14235d38..ce55b8b1de 100755 --- a/modules/ts/misc/testlog_parser.py +++ b/modules/ts/misc/testlog_parser.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import sys, re, os.path from xml.dom.minidom import parse diff --git a/modules/video/perf/perf_optflowpyrlk.cpp b/modules/video/perf/perf_optflowpyrlk.cpp index 0ac9efe7e7..1e5cfc25ff 100644 --- a/modules/video/perf/perf_optflowpyrlk.cpp +++ b/modules/video/perf/perf_optflowpyrlk.cpp @@ -163,6 +163,7 @@ PERF_TEST_P(Path_Idx_Cn_NPoints_WSize_Deriv, OpticalFlowPyrLK_self, testing::Com maxLevel = buildOpticalFlowPyramid(frame2, pyramid2, Size(winSize, winSize), maxLevel, withDerivatives); declare.in(pyramid1, pyramid2, inPoints).out(outPoints); + declare.time(400); TEST_CYCLE() { diff --git a/samples/android/15-puzzle/AndroidManifest.xml b/samples/android/15-puzzle/AndroidManifest.xml index 184d3d761e..356382bf14 100644 --- a/samples/android/15-puzzle/AndroidManifest.xml +++ b/samples/android/15-puzzle/AndroidManifest.xml @@ -7,7 +7,8 @@ + android:label="@string/app_name" + android:theme="@android:style/Theme.NoTitleBar.Fullscreen" > - + + - + + setMinObjectSize(Size(faceSize, faceSize)); } } - catch(cv::Exception e) + catch(cv::Exception& e) { - LOGD("nativeCreateObject catched cv::Exception: %s", e.what()); + LOGD("nativeCreateObject caught cv::Exception: %s", e.what()); jclass je = jenv->FindClass("org/opencv/core/CvException"); if(!je) je = jenv->FindClass("java/lang/Exception"); @@ -96,7 +96,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker } catch (...) { - LOGD("nativeCreateObject catched unknown exception"); + LOGD("nativeCreateObject caught unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeCreateObject(...)}"); return 0; @@ -119,9 +119,9 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ delete (DetectorAgregator*)thiz; } } - catch(cv::Exception e) + catch(cv::Exception& e) { - LOGD("nativeestroyObject catched cv::Exception: %s", e.what()); + LOGD("nativeestroyObject caught cv::Exception: %s", e.what()); jclass je = jenv->FindClass("org/opencv/core/CvException"); if(!je) je = jenv->FindClass("java/lang/Exception"); @@ -129,7 +129,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ } catch (...) { - LOGD("nativeDestroyObject catched unknown exception"); + LOGD("nativeDestroyObject caught unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDestroyObject(...)}"); } @@ -145,9 +145,9 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ { ((DetectorAgregator*)thiz)->tracker->run(); } - catch(cv::Exception e) + catch(cv::Exception& e) { - LOGD("nativeStart catched cv::Exception: %s", e.what()); + LOGD("nativeStart caught cv::Exception: %s", e.what()); jclass je = jenv->FindClass("org/opencv/core/CvException"); if(!je) je = jenv->FindClass("java/lang/Exception"); @@ -155,7 +155,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ } catch (...) { - LOGD("nativeStart catched unknown exception"); + LOGD("nativeStart caught unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStart(...)}"); } @@ -171,9 +171,9 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ { ((DetectorAgregator*)thiz)->tracker->stop(); } - catch(cv::Exception e) + catch(cv::Exception& e) { - LOGD("nativeStop catched cv::Exception: %s", e.what()); + LOGD("nativeStop caught cv::Exception: %s", e.what()); jclass je = jenv->FindClass("org/opencv/core/CvException"); if(!je) je = jenv->FindClass("java/lang/Exception"); @@ -181,7 +181,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ } catch (...) { - LOGD("nativeStop catched unknown exception"); + LOGD("nativeStop caught unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeStop(...)}"); } @@ -201,9 +201,9 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ //((DetectorAgregator*)thiz)->trackingDetector->setMinObjectSize(Size(faceSize, faceSize)); } } - catch(cv::Exception e) + catch(cv::Exception& e) { - LOGD("nativeStop catched cv::Exception: %s", e.what()); + LOGD("nativeStop caught cv::Exception: %s", e.what()); jclass je = jenv->FindClass("org/opencv/core/CvException"); if(!je) je = jenv->FindClass("java/lang/Exception"); @@ -211,7 +211,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ } catch (...) { - LOGD("nativeSetFaceSize catched unknown exception"); + LOGD("nativeSetFaceSize caught unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeSetFaceSize(...)}"); } @@ -231,9 +231,9 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ ((DetectorAgregator*)thiz)->tracker->getObjects(RectFaces); *((Mat*)faces) = Mat(RectFaces, true); } - catch(cv::Exception e) + catch(cv::Exception& e) { - LOGD("nativeCreateObject catched cv::Exception: %s", e.what()); + LOGD("nativeCreateObject caught cv::Exception: %s", e.what()); jclass je = jenv->FindClass("org/opencv/core/CvException"); if(!je) je = jenv->FindClass("java/lang/Exception"); @@ -241,7 +241,7 @@ JNIEXPORT void JNICALL Java_org_opencv_samples_facedetect_DetectionBasedTracker_ } catch (...) { - LOGD("nativeDetect catched unknown exception"); + LOGD("nativeDetect caught unknown exception"); jclass je = jenv->FindClass("java/lang/Exception"); jenv->ThrowNew(je, "Unknown exception in JNI code {Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect(...)}"); } diff --git a/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java b/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java index 2b949629cc..d59de02609 100644 --- a/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java +++ b/samples/android/face-detection/src/org/opencv/samples/facedetect/FdActivity.java @@ -25,7 +25,6 @@ import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import android.view.Window; import android.view.WindowManager; public class FdActivity extends Activity implements CvCameraViewListener { @@ -120,7 +119,6 @@ public class FdActivity extends Activity implements CvCameraViewListener { public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "called onCreate"); super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.face_detect_surface_view); diff --git a/samples/android/image-manipulations/AndroidManifest.xml b/samples/android/image-manipulations/AndroidManifest.xml index b83f799fe0..50ef788ac6 100644 --- a/samples/android/image-manipulations/AndroidManifest.xml +++ b/samples/android/image-manipulations/AndroidManifest.xml @@ -4,7 +4,11 @@ android:versionCode="21" android:versionName="2.1"> - + + > 1) * getFrameWidth() + (j & ~1); - int y = (0xff & ((int) data[index])); - int u = (0xff & ((int) data[supply_index + 0])); - int v = (0xff & ((int) data[supply_index + 1])); - y = y < 16 ? 16 : y; - - float y_conv = 1.164f * (y - 16); - int r = Math.round(y_conv + 1.596f * (v - 128)); - int g = Math.round(y_conv - 0.813f * (v - 128) - 0.391f * (u - 128)); - int b = Math.round(y_conv + 2.018f * (u - 128)); - - r = r < 0 ? 0 : (r > 255 ? 255 : r); - g = g < 0 ? 0 : (g > 255 ? 255 : g); - b = b < 0 ? 0 : (b > 255 ? 255 : b); - - rgba[i * getFrameWidth() + j] = 0xff000000 + (b << 16) + (g << 8) + r; - } - } - } - - mBitmap.setPixels(rgba, 0/* offset */, getFrameWidth() /* stride */, 0, 0, getFrameWidth(), getFrameHeight()); - return mBitmap; - } - - @Override - protected void onPreviewStarted(int previewWidth, int previewHeight) { - Log.i(TAG, "called onPreviewStarted("+previewWidth+", "+previewHeight+")"); - /* Create a bitmap that will be used through to calculate the image to */ - mBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888); - mRGBA = new int[previewWidth * previewHeight]; - } - - @Override - protected void onPreviewStopped() { - Log.i(TAG, "called onPreviewStopped"); - if(mBitmap != null) { - mBitmap.recycle(); - mBitmap = null; - } - - if(mRGBA != null) { - mRGBA = null; - } - } - - public void setViewMode(int viewMode) { - Log.i(TAG, "called setViewMode("+viewMode+")"); - mViewMode = viewMode; - } -} \ No newline at end of file diff --git a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java b/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java deleted file mode 100644 index 8db6fae8ac..0000000000 --- a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.opencv.samples.tutorial0; - -import java.io.IOException; -import java.util.List; - -import android.annotation.TargetApi; -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.ImageFormat; -import android.graphics.SurfaceTexture; -import android.hardware.Camera; -import android.hardware.Camera.PreviewCallback; -import android.os.Build; -import android.util.Log; -import android.view.SurfaceHolder; -import android.view.SurfaceView; - -public abstract class SampleViewBase extends SurfaceView implements SurfaceHolder.Callback, Runnable { - private static final String TAG = "OCVSample::BaseView"; - - private Camera mCamera; - private SurfaceHolder mHolder; - private int mFrameWidth; - private int mFrameHeight; - private byte[] mFrame; - private volatile boolean mThreadRun; - private byte[] mBuffer; - private SurfaceTexture mSf; - - - public SampleViewBase(Context context) { - super(context); - mHolder = getHolder(); - mHolder.addCallback(this); - Log.i(TAG, "Instantiated new " + this.getClass()); - } - - public int getFrameWidth() { - return mFrameWidth; - } - - public int getFrameHeight() { - return mFrameHeight; - } - - @TargetApi(11) - public void setPreview() throws IOException { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mSf = new SurfaceTexture(10); - mCamera.setPreviewTexture( mSf ); - } - else - mCamera.setPreviewDisplay(null); - } - - public boolean openCamera() { - Log.i(TAG, "Opening Camera"); - mCamera = null; - - try { - mCamera = Camera.open(); - } - catch (Exception e){ - Log.e(TAG, "Camera is not available (in use or does not exist): " + e.getLocalizedMessage()); - } - - if(mCamera == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { - for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); ++camIdx) { - try { - mCamera = Camera.open(camIdx); - } - catch (RuntimeException e) { - Log.e(TAG, "Camera #" + camIdx + "failed to open: " + e.getLocalizedMessage()); - } - } - } - - if(mCamera == null) { - Log.e(TAG, "Can't open any camera"); - return false; - } - - mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() { - public void onPreviewFrame(byte[] data, Camera camera) { - synchronized (SampleViewBase.this) { - System.arraycopy(data, 0, mFrame, 0, data.length); - SampleViewBase.this.notify(); - } - camera.addCallbackBuffer(mBuffer); - } - }); - - return true; - } - - public void releaseCamera() { - Log.i(TAG, "Releasing Camera"); - mThreadRun = false; - synchronized (this) { - if (mCamera != null) { - mCamera.stopPreview(); - mCamera.release(); - mCamera = null; - } - } - onPreviewStopped(); - } - - public synchronized void setupCamera(int width, int height) { - if (mCamera != null) { - Log.i(TAG, "Setup Camera - " + width + "x" + height); - Camera.Parameters params = mCamera.getParameters(); - List sizes = params.getSupportedPreviewSizes(); - mFrameWidth = width; - mFrameHeight = height; - - // selecting optimal camera preview size - { - int minDiff = Integer.MAX_VALUE; - for (Camera.Size size : sizes) { - if (Math.abs(size.height - height) < minDiff) { - mFrameWidth = size.width; - mFrameHeight = size.height; - minDiff = Math.abs(size.height - height); - } - } - } - - params.setPreviewSize(getFrameWidth(), getFrameHeight()); - - List FocusModes = params.getSupportedFocusModes(); - if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) - { - params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); - } - - mCamera.setParameters(params); - - /* Now allocate the buffer */ - params = mCamera.getParameters(); - int size = params.getPreviewSize().width * params.getPreviewSize().height; - size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8; - mBuffer = new byte[size]; - /* The buffer where the current frame will be copied */ - mFrame = new byte [size]; - mCamera.addCallbackBuffer(mBuffer); - - /* Notify that the preview is about to be started and deliver preview size */ - onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); - - try { - setPreview(); - } catch (IOException e) { - Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); - } - - /* Now we can start a preview */ - mCamera.startPreview(); - } - } - - public void surfaceChanged(SurfaceHolder _holder, int format, int width, int height) { - Log.i(TAG, "called surfaceChanged"); - // stop preview before making changes - try { - mCamera.stopPreview(); - } catch (Exception e){ - // ignore: tried to stop a non-existent preview - } - - // start preview with new settings - setupCamera(width, height); - } - - public void surfaceCreated(SurfaceHolder holder) { - Log.i(TAG, "called surfaceCreated"); - (new Thread(this)).start(); - } - - public void surfaceDestroyed(SurfaceHolder holder) { - Log.i(TAG, "called surfaceDestroyed"); - } - - /* The bitmap returned by this method shall be owned by the child and released in onPreviewStopped() */ - protected abstract Bitmap processFrame(byte[] data); - - /** - * This method is called when the preview process is being started. It is called before the first frame delivered and processFrame is called - * It is called with the width and height parameters of the preview process. It can be used to prepare the data needed during the frame processing. - * @param previewWidth - the width of the preview frames that will be delivered via processFrame - * @param previewHeight - the height of the preview frames that will be delivered via processFrame - */ - protected abstract void onPreviewStarted(int previewWidtd, int previewHeight); - - /** - * This method is called when preview is stopped. When this method is called the preview stopped and all the processing of frames already completed. - * If the Bitmap object returned via processFrame is cached - it is a good time to recycle it. - * Any other resources used during the preview can be released. - */ - protected abstract void onPreviewStopped(); - - public void run() { - mThreadRun = true; - Log.i(TAG, "Started processing thread"); - while (mThreadRun) { - Bitmap bmp = null; - - synchronized (this) { - try { - this.wait(); - if (!mThreadRun) - break; - bmp = processFrame(mFrame); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - if (bmp != null) { - Canvas canvas = mHolder.lockCanvas(); - if (canvas != null) { - canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR); - canvas.drawBitmap(bmp, (canvas.getWidth() - getFrameWidth()) / 2, (canvas.getHeight() - getFrameHeight()) / 2, null); - mHolder.unlockCanvasAndPost(canvas); - } - } - } - Log.i(TAG, "Finished processing thread"); - } -} \ No newline at end of file diff --git a/samples/android/tutorial-1-addopencv/AndroidManifest.xml b/samples/android/tutorial-1-addopencv/AndroidManifest.xml index 5ec908429a..9b4e797dab 100644 --- a/samples/android/tutorial-1-addopencv/AndroidManifest.xml +++ b/samples/android/tutorial-1-addopencv/AndroidManifest.xml @@ -4,7 +4,11 @@ android:versionCode="21" android:versionName="2.1"> - + + @@ -7,12 +8,16 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="gone" - android:id="@+id/tutorial1_activity_java_surface_view" /> + android:id="@+id/tutorial1_activity_java_surface_view" + opencv:show_fps="true" + opencv:camera_id="any" /> + android:id="@+id/tutorial1_activity_native_surface_view" + opencv:show_fps="true" + opencv:camera_id="any" /> diff --git a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java index 6478f3bb05..9e5150f6cb 100644 --- a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java +++ b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/Sample1Java.java @@ -13,7 +13,6 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.SurfaceView; -import android.view.Window; import android.view.WindowManager; import android.widget.Toast; @@ -50,7 +49,6 @@ public class Sample1Java extends Activity implements CvCameraViewListener { public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "called onCreate"); super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.tutorial1_surface_view); diff --git a/samples/android/tutorial-2-opencvcamera/AndroidManifest.xml b/samples/android/tutorial-2-opencvcamera/AndroidManifest.xml index 71e9c99857..3378b40e67 100644 --- a/samples/android/tutorial-2-opencvcamera/AndroidManifest.xml +++ b/samples/android/tutorial-2-opencvcamera/AndroidManifest.xml @@ -4,7 +4,11 @@ android:versionCode="21" android:versionName="2.1"> - + + - + + v; FastFeatureDetector detector(50); - detector.detect(*pMatGr, v); - for( size_t i = 0; i < v.size(); i++ ) - circle(*pMatRgb, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(255,0,0,255)); + detector.detect(mGr, v); + for( unsigned int i = 0; i < v.size(); i++ ) + { + const KeyPoint& kp = v[i]; + circle(mRgb, Point(kp.pt.x, kp.pt.y), 10, Scalar(255,0,0,255)); + } } - } diff --git a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java index 5f0e6c8801..ea7998edc4 100644 --- a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java +++ b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/Sample3Native.java @@ -12,7 +12,6 @@ import org.opencv.imgproc.Imgproc; import android.app.Activity; import android.os.Bundle; import android.util.Log; -import android.view.Window; import android.view.WindowManager; public class Sample3Native extends Activity implements CvCameraViewListener { @@ -52,7 +51,6 @@ public class Sample3Native extends Activity implements CvCameraViewListener { public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "called onCreate"); super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.tutorial3_surface_view); diff --git a/samples/android/tutorial-4-mixed/AndroidManifest.xml b/samples/android/tutorial-4-mixed/AndroidManifest.xml index 51460d34b3..22266fb765 100644 --- a/samples/android/tutorial-4-mixed/AndroidManifest.xml +++ b/samples/android/tutorial-4-mixed/AndroidManifest.xml @@ -4,7 +4,11 @@ android:versionCode="21" android:versionName="2.1"> - + + v; FastFeatureDetector detector(50); - detector.detect(*pMatGr, v); - for( size_t i = 0; i < v.size(); i++ ) - circle(*pMatRgb, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(255,0,0,255)); + detector.detect(mGr, v); + for( unsigned int i = 0; i < v.size(); i++ ) + { + const KeyPoint& kp = v[i]; + circle(mRgb, Point(kp.pt.x, kp.pt.y), 10, Scalar(255,0,0,255)); + } } - } diff --git a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java index e70f9d68c7..a1b455b680 100644 --- a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java +++ b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/Sample4Mixed.java @@ -15,7 +15,6 @@ import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import android.view.Window; import android.view.WindowManager; public class Sample4Mixed extends Activity implements CvCameraViewListener { @@ -68,7 +67,6 @@ public class Sample4Mixed extends Activity implements CvCameraViewListener { public void onCreate(Bundle savedInstanceState) { Log.i(TAG, "called onCreate"); super.onCreate(savedInstanceState); - requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.tutorial4_surface_view); diff --git a/samples/android/tutorial-0-androidcamera/.classpath b/samples/android/tutorial-5-cameracontrol/.classpath similarity index 75% rename from samples/android/tutorial-0-androidcamera/.classpath rename to samples/android/tutorial-5-cameracontrol/.classpath index d3bb07b44c..3f9691c5dd 100644 --- a/samples/android/tutorial-0-androidcamera/.classpath +++ b/samples/android/tutorial-5-cameracontrol/.classpath @@ -1,7 +1,7 @@ - + diff --git a/samples/android/tutorial-0-androidcamera/.project b/samples/android/tutorial-5-cameracontrol/.project similarity index 94% rename from samples/android/tutorial-0-androidcamera/.project rename to samples/android/tutorial-5-cameracontrol/.project index 33b00651d7..40a2d7ff25 100644 --- a/samples/android/tutorial-0-androidcamera/.project +++ b/samples/android/tutorial-5-cameracontrol/.project @@ -1,6 +1,6 @@ - OpenCV Tutorial 0 - Android Camera + OpenCV Tutorial 5 - Camera Control diff --git a/samples/android/tutorial-0-androidcamera/.settings/org.eclipse.jdt.core.prefs b/samples/android/tutorial-5-cameracontrol/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from samples/android/tutorial-0-androidcamera/.settings/org.eclipse.jdt.core.prefs rename to samples/android/tutorial-5-cameracontrol/.settings/org.eclipse.jdt.core.prefs diff --git a/samples/android/tutorial-0-androidcamera/AndroidManifest.xml b/samples/android/tutorial-5-cameracontrol/AndroidManifest.xml similarity index 79% rename from samples/android/tutorial-0-androidcamera/AndroidManifest.xml rename to samples/android/tutorial-5-cameracontrol/AndroidManifest.xml index d703810c14..053033d6c0 100644 --- a/samples/android/tutorial-0-androidcamera/AndroidManifest.xml +++ b/samples/android/tutorial-5-cameracontrol/AndroidManifest.xml @@ -1,11 +1,15 @@ - - + + @@ -30,5 +34,6 @@ + diff --git a/samples/android/tutorial-5-cameracontrol/CMakeLists.txt b/samples/android/tutorial-5-cameracontrol/CMakeLists.txt new file mode 100644 index 0000000000..986f75402e --- /dev/null +++ b/samples/android/tutorial-5-cameracontrol/CMakeLists.txt @@ -0,0 +1,7 @@ +set(sample example-tutorial-5-cameracontrol) + +add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET}) +if(TARGET ${sample}) + add_dependencies(opencv_android_examples ${sample}) +endif() + diff --git a/samples/android/tutorial-0-androidcamera/res/drawable/icon.png b/samples/android/tutorial-5-cameracontrol/res/drawable/icon.png similarity index 100% rename from samples/android/tutorial-0-androidcamera/res/drawable/icon.png rename to samples/android/tutorial-5-cameracontrol/res/drawable/icon.png diff --git a/samples/android/tutorial-5-cameracontrol/res/layout/tutorial5_surface_view.xml b/samples/android/tutorial-5-cameracontrol/res/layout/tutorial5_surface_view.xml new file mode 100644 index 0000000000..36376e56bc --- /dev/null +++ b/samples/android/tutorial-5-cameracontrol/res/layout/tutorial5_surface_view.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/samples/android/tutorial-0-androidcamera/res/values/strings.xml b/samples/android/tutorial-5-cameracontrol/res/values/strings.xml similarity index 52% rename from samples/android/tutorial-0-androidcamera/res/values/strings.xml rename to samples/android/tutorial-5-cameracontrol/res/values/strings.xml index 66388980c3..bf1a740ffb 100644 --- a/samples/android/tutorial-0-androidcamera/res/values/strings.xml +++ b/samples/android/tutorial-5-cameracontrol/res/values/strings.xml @@ -1,4 +1,4 @@ - OCV T0 Android Camera + OCV T5 Camera Control diff --git a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java new file mode 100644 index 0000000000..358d527b98 --- /dev/null +++ b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java @@ -0,0 +1,127 @@ +package org.opencv.samples.tutorial5; + +import java.util.List; +import java.util.ListIterator; + +import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.LoaderCallbackInterface; +import org.opencv.android.OpenCVLoader; +import org.opencv.core.Mat; +import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Environment; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.SurfaceView; +import android.view.View; +import android.view.View.OnTouchListener; +import android.view.WindowManager; + +public class Sample5CameraControl extends Activity implements CvCameraViewListener, OnTouchListener { + private static final String TAG = "OCVSample::Activity"; + + private SampleJavaCameraView mOpenCvCameraView; + private MenuItem[] mEffectMenuItems; + + private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { + @Override + public void onManagerConnected(int status) { + switch (status) { + case LoaderCallbackInterface.SUCCESS: + { + Log.i(TAG, "OpenCV loaded successfully"); + mOpenCvCameraView.enableView(); + mOpenCvCameraView.setOnTouchListener(Sample5CameraControl.this); + } break; + default: + { + super.onManagerConnected(status); + } break; + } + } + }; + + public Sample5CameraControl() { + Log.i(TAG, "Instantiated new " + this.getClass()); + } + + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + Log.i(TAG, "called onCreate"); + super.onCreate(savedInstanceState); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + setContentView(R.layout.tutorial5_surface_view); + + mOpenCvCameraView = (SampleJavaCameraView) findViewById(R.id.tutorial5_activity_java_surface_view); + + mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); + + mOpenCvCameraView.setCvCameraViewListener(this); + } + + @Override + public void onPause() + { + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + super.onPause(); + } + + @Override + public void onResume() + { + super.onResume(); + OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); + } + + public void onDestroy() { + super.onDestroy(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + } + + public void onCameraViewStarted(int width, int height) { + } + + public void onCameraViewStopped() { + } + + public Mat onCameraFrame(Mat inputFrame) { + return inputFrame; + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + List effects = mOpenCvCameraView.getEffectList(); + + mEffectMenuItems = new MenuItem[effects.size()]; + + int idx = 0; + ListIterator itr = effects.listIterator(); + while(itr.hasNext()) { + String element = itr.next(); + mEffectMenuItems[idx] = menu.add(element); + idx++; + } + return true; + } + + public boolean onOptionsItemSelected(MenuItem item) { + Log.i(TAG, "called onOptionsItemSelected; selected item: " + item); + mOpenCvCameraView.setEffect((String) item.getTitle()); + return true; + } + + @Override + public boolean onTouch(View v, MotionEvent event) { + Log.i(TAG,"onTouch event"); + mOpenCvCameraView.takePicture(Environment.getExternalStorageDirectory().getPath() + "/sample_picture.jpg"); + return false; + } +} diff --git a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/SampleJavaCameraView.java b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/SampleJavaCameraView.java new file mode 100644 index 0000000000..fa33b8f4b7 --- /dev/null +++ b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/SampleJavaCameraView.java @@ -0,0 +1,60 @@ +package org.opencv.samples.tutorial5; + +import java.io.FileOutputStream; +import java.util.List; + +import org.opencv.android.JavaCameraView; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.hardware.Camera; +import android.hardware.Camera.PictureCallback; +import android.util.AttributeSet; +import android.util.Log; + +public class SampleJavaCameraView extends JavaCameraView { + + private static final String TAG = "Sample::SampleJavaCameraView"; + + public SampleJavaCameraView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public List getEffectList() { + return mCamera.getParameters().getSupportedColorEffects(); + } + + public String getEffect() { + return mCamera.getParameters().getColorEffect(); + } + + public void setEffect(String effect) { + Camera.Parameters params = mCamera.getParameters(); + params.setColorEffect(effect); + mCamera.setParameters(params); + } + + public void takePicture(final String fileName) { + Log.i(TAG, "Tacking picture"); + PictureCallback callback = new PictureCallback() { + + private String mPictureFileName = fileName; + + @Override + public void onPictureTaken(byte[] data, Camera camera) { + Log.i(TAG, "Saving a bitmap to file"); + Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length); + try { + FileOutputStream out = new FileOutputStream(mPictureFileName); + picture.compress(Bitmap.CompressFormat.JPEG, 90, out); + mCamera.startPreview(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }; + + mCamera.takePicture(null, null, callback); + } +} diff --git a/samples/python/camera.py b/samples/python/camera.py index 747bb4575c..5d1c63b047 100755 --- a/samples/python/camera.py +++ b/samples/python/camera.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + import cv2.cv as cv import time diff --git a/samples/python/cv20squares.py b/samples/python/cv20squares.py index ddeeebd3f9..e472fa1973 100755 --- a/samples/python/cv20squares.py +++ b/samples/python/cv20squares.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + """ Find Squares in image by finding countours and filtering """ diff --git a/samples/python/cvutils.py b/samples/python/cvutils.py index 6e81a3a44d..a2ef8ae325 100755 --- a/samples/python/cvutils.py +++ b/samples/python/cvutils.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + import cv2.cv as cv import urllib2 from sys import argv diff --git a/samples/python/dmtx.py b/samples/python/dmtx.py index 6b3a6bd180..0ff2b43da5 100755 --- a/samples/python/dmtx.py +++ b/samples/python/dmtx.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + import cv2.cv as cv import time from pydmtx import DataMatrix diff --git a/samples/python/peopledetect.py b/samples/python/peopledetect.py index 35c600c961..2824299791 100755 --- a/samples/python/peopledetect.py +++ b/samples/python/peopledetect.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + import sys from cv import * diff --git a/samples/python2/_coverage.py b/samples/python2/_coverage.py index 1fb8b17f0e..1d0f0418be 100755 --- a/samples/python2/_coverage.py +++ b/samples/python2/_coverage.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Utility for measuring python opencv API coverage by samples. ''' diff --git a/samples/python2/_doc.py b/samples/python2/_doc.py index 1204ae65a5..71c9faa7dd 100755 --- a/samples/python2/_doc.py +++ b/samples/python2/_doc.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Scans current directory for *.py files and reports ones with missing __doc__ string. diff --git a/samples/python2/asift.py b/samples/python2/asift.py index 4f2b0cd40a..09894dd4c2 100755 --- a/samples/python2/asift.py +++ b/samples/python2/asift.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Affine invariant feature-based image matching sample. diff --git a/samples/python2/browse.py b/samples/python2/browse.py index 238d2a3ec0..da2c98d1c7 100755 --- a/samples/python2/browse.py +++ b/samples/python2/browse.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' browse.py ========= diff --git a/samples/python2/calibrate.py b/samples/python2/calibrate.py index 03a2a6f7a6..54aba8aaf9 100755 --- a/samples/python2/calibrate.py +++ b/samples/python2/calibrate.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np import cv2 import os diff --git a/samples/python2/camshift.py b/samples/python2/camshift.py index 0554e1ecd6..43543dcfc5 100755 --- a/samples/python2/camshift.py +++ b/samples/python2/camshift.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Camshift tracker ================ diff --git a/samples/python2/coherence.py b/samples/python2/coherence.py index d3fe4daba9..082a7c6101 100755 --- a/samples/python2/coherence.py +++ b/samples/python2/coherence.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Coherence-enhancing filtering example ===================================== diff --git a/samples/python2/color_histogram.py b/samples/python2/color_histogram.py index 8e6747aac7..c27744ed5a 100755 --- a/samples/python2/color_histogram.py +++ b/samples/python2/color_histogram.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np import cv2 from time import clock diff --git a/samples/python2/common.py b/samples/python2/common.py index ccfbe5c722..4c6f800c44 100755 --- a/samples/python2/common.py +++ b/samples/python2/common.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' This module contais some common routines used by other samples. ''' diff --git a/samples/python2/contours.py b/samples/python2/contours.py index 13a3857d3d..daa13b2a11 100755 --- a/samples/python2/contours.py +++ b/samples/python2/contours.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' This program illustrates the use of findContours and drawContours. The original image is put up along with the image of drawn contours. diff --git a/samples/python2/deconvolution.py b/samples/python2/deconvolution.py index 9463c4545b..5e3becc645 100755 --- a/samples/python2/deconvolution.py +++ b/samples/python2/deconvolution.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Wiener deconvolution. diff --git a/samples/python2/demo.py b/samples/python2/demo.py index fd988bc31f..a9c1070154 100755 --- a/samples/python2/demo.py +++ b/samples/python2/demo.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Sample-launcher application. ''' diff --git a/samples/python2/digits.py b/samples/python2/digits.py index 582e5fc0ff..c84bc241cb 100755 --- a/samples/python2/digits.py +++ b/samples/python2/digits.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' SVM and KNearest digit recognition. diff --git a/samples/python2/digits_adjust.py b/samples/python2/digits_adjust.py index d8e70f2ec7..72805d3f00 100755 --- a/samples/python2/digits_adjust.py +++ b/samples/python2/digits_adjust.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Digit recognition adjustment. Grid search is used to find the best parameters for SVM and KNearest classifiers. diff --git a/samples/python2/digits_video.py b/samples/python2/digits_video.py index a8b486f2a8..ef62826fd1 100755 --- a/samples/python2/digits_video.py +++ b/samples/python2/digits_video.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np import cv2 import os diff --git a/samples/python2/distrans.py b/samples/python2/distrans.py index 1322636290..386ea8ab99 100755 --- a/samples/python2/distrans.py +++ b/samples/python2/distrans.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Distance transform sample. diff --git a/samples/python2/edge.py b/samples/python2/edge.py index 02276f2d25..9ce3457d30 100755 --- a/samples/python2/edge.py +++ b/samples/python2/edge.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' This sample demonstrates Canny edge detection. diff --git a/samples/python2/facedetect.py b/samples/python2/facedetect.py index 94807b82a9..27a78950a9 100755 --- a/samples/python2/facedetect.py +++ b/samples/python2/facedetect.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np import cv2 import cv2.cv as cv diff --git a/samples/python2/feature_homography.py b/samples/python2/feature_homography.py index aa19d45f57..4dd8ddf136 100755 --- a/samples/python2/feature_homography.py +++ b/samples/python2/feature_homography.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Feature homography ================== diff --git a/samples/python2/find_obj.py b/samples/python2/find_obj.py index 48b9d44ea2..7a875ca4f7 100755 --- a/samples/python2/find_obj.py +++ b/samples/python2/find_obj.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Feature-based image matching sample. diff --git a/samples/python2/fitline.py b/samples/python2/fitline.py index e4a5091f13..c19dbdc35b 100755 --- a/samples/python2/fitline.py +++ b/samples/python2/fitline.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Robust line fitting. ================== diff --git a/samples/python2/floodfill.py b/samples/python2/floodfill.py index 540e7ad8f0..177e380255 100755 --- a/samples/python2/floodfill.py +++ b/samples/python2/floodfill.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Floodfill sample. diff --git a/samples/python2/gabor_threads.py b/samples/python2/gabor_threads.py index 962a50189a..9582bdb04f 100755 --- a/samples/python2/gabor_threads.py +++ b/samples/python2/gabor_threads.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' gabor_threads.py ========= diff --git a/samples/python2/gaussian_mix.py b/samples/python2/gaussian_mix.py index 63ee3adece..de714fa353 100755 --- a/samples/python2/gaussian_mix.py +++ b/samples/python2/gaussian_mix.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np from numpy import random import cv2 diff --git a/samples/python2/hist.py b/samples/python2/hist.py index d7938958fc..ea950c8326 100755 --- a/samples/python2/hist.py +++ b/samples/python2/hist.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' This is a sample for histogram plotting for RGB images and grayscale images for better understanding of colour distribution Benefit : Learn how to draw histogram of images diff --git a/samples/python2/inpaint.py b/samples/python2/inpaint.py index 0070f55681..d2b8c849a7 100755 --- a/samples/python2/inpaint.py +++ b/samples/python2/inpaint.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Inpainting sample. diff --git a/samples/python2/kmeans.py b/samples/python2/kmeans.py index 3b55830508..4418a46792 100755 --- a/samples/python2/kmeans.py +++ b/samples/python2/kmeans.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' K-means clusterization sample. Usage: diff --git a/samples/python2/lappyr.py b/samples/python2/lappyr.py index e1951ed63a..232ec54b92 100755 --- a/samples/python2/lappyr.py +++ b/samples/python2/lappyr.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' An example of Laplacian Pyramid construction and merging. Level : Intermediate diff --git a/samples/python2/letter_recog.py b/samples/python2/letter_recog.py index 282b300d89..73eeff3bb7 100755 --- a/samples/python2/letter_recog.py +++ b/samples/python2/letter_recog.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' The sample demonstrates how to train Random Trees classifier (or Boosting classifier, or MLP, or Knearest, or Support Vector Machines) using the provided dataset. diff --git a/samples/python2/lk_homography.py b/samples/python2/lk_homography.py index 9e6d8a9e80..9996764c6f 100755 --- a/samples/python2/lk_homography.py +++ b/samples/python2/lk_homography.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Lucas-Kanade homography tracker =============================== diff --git a/samples/python2/lk_track.py b/samples/python2/lk_track.py index ea8b25d1b8..f0d0439622 100755 --- a/samples/python2/lk_track.py +++ b/samples/python2/lk_track.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Lucas-Kanade tracker ==================== diff --git a/samples/python2/morphology.py b/samples/python2/morphology.py index 2c81cd81e0..0980981380 100755 --- a/samples/python2/morphology.py +++ b/samples/python2/morphology.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Morphology operations. diff --git a/samples/python2/mosse.py b/samples/python2/mosse.py index 1d5eb29389..aecb423452 100755 --- a/samples/python2/mosse.py +++ b/samples/python2/mosse.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' MOSSE tracking sample diff --git a/samples/python2/motempl.py b/samples/python2/motempl.py index 08f3100643..4f78ebad57 100755 --- a/samples/python2/motempl.py +++ b/samples/python2/motempl.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np import cv2 import video diff --git a/samples/python2/mouse_and_match.py b/samples/python2/mouse_and_match.py index b979445c9e..a9fa882adc 100755 --- a/samples/python2/mouse_and_match.py +++ b/samples/python2/mouse_and_match.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + #!/usr/bin/env python ''' mouse_and_match.py [-i path | --input path: default ./] diff --git a/samples/python2/mser.py b/samples/python2/mser.py index 88773534ab..73e0a4f8da 100755 --- a/samples/python2/mser.py +++ b/samples/python2/mser.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' MSER detector demo ================== diff --git a/samples/python2/opt_flow.py b/samples/python2/opt_flow.py index a70046a06e..d0bc5c5c11 100755 --- a/samples/python2/opt_flow.py +++ b/samples/python2/opt_flow.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np import cv2 import video diff --git a/samples/python2/peopledetect.py b/samples/python2/peopledetect.py index 4cd7a8efd6..f4bd46702f 100755 --- a/samples/python2/peopledetect.py +++ b/samples/python2/peopledetect.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + import numpy as np import cv2 diff --git a/samples/python2/plane_ar.py b/samples/python2/plane_ar.py index 45e35603d3..dc2d5d584f 100755 --- a/samples/python2/plane_ar.py +++ b/samples/python2/plane_ar.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Planar augmented reality ================== diff --git a/samples/python2/plane_tracker.py b/samples/python2/plane_tracker.py index d588b94cde..189f50b362 100755 --- a/samples/python2/plane_tracker.py +++ b/samples/python2/plane_tracker.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Multitarget planar tracking ================== diff --git a/samples/python2/squares.py b/samples/python2/squares.py index 7842bb18c7..a247c35627 100755 --- a/samples/python2/squares.py +++ b/samples/python2/squares.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Simple "Square Detector" program. diff --git a/samples/python2/stereo_match.py b/samples/python2/stereo_match.py index ef562225d6..0e46c26617 100755 --- a/samples/python2/stereo_match.py +++ b/samples/python2/stereo_match.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Simple example of stereo image matching and point cloud generation. diff --git a/samples/python2/texture_flow.py b/samples/python2/texture_flow.py index 5b095e63ad..66eb58fe69 100755 --- a/samples/python2/texture_flow.py +++ b/samples/python2/texture_flow.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Texture flow direction estimation. diff --git a/samples/python2/turing.py b/samples/python2/turing.py index 679bf9926a..101f22c045 100755 --- a/samples/python2/turing.py +++ b/samples/python2/turing.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Multiscale Turing Patterns generator ==================================== diff --git a/samples/python2/video.py b/samples/python2/video.py index c4168f6b51..2cdcb2a600 100755 --- a/samples/python2/video.py +++ b/samples/python2/video.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Video capture sample. diff --git a/samples/python2/video_dmtx.py b/samples/python2/video_dmtx.py index 98cdd85652..1ed06c4adc 100755 --- a/samples/python2/video_dmtx.py +++ b/samples/python2/video_dmtx.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Data matrix detector sample. Usage: diff --git a/samples/python2/video_threaded.py b/samples/python2/video_threaded.py index 7498d83606..6fce334183 100755 --- a/samples/python2/video_threaded.py +++ b/samples/python2/video_threaded.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Multithreaded video processing sample. Usage: diff --git a/samples/python2/watershed.py b/samples/python2/watershed.py index 711f940d0e..d4ab22ad59 100755 --- a/samples/python2/watershed.py +++ b/samples/python2/watershed.py @@ -1,3 +1,5 @@ +#/usr/bin/env python + ''' Watershed segmentation =========