Merge remote-tracking branch 'origin/2.4' into merge-2.4

Conflicts:
	cmake/OpenCVDetectAndroidSDK.cmake
	cmake/OpenCVGenAndroidMK.cmake
	cmake/OpenCVModule.cmake
	cmake/templates/OpenCV.mk.in
	cmake/templates/OpenCVConfig.cmake.in
	doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst
	modules/cudabgsegm/src/cuda/mog.cu
	modules/imgproc/perf/opencl/perf_filters.cpp
	modules/imgproc/src/opencl/filterSep_singlePass.cl
	modules/nonfree/CMakeLists.txt
	modules/nonfree/perf/perf_precomp.hpp
	modules/ocl/perf/perf_haar.cpp
	modules/ocl/src/filtering.cpp
	modules/ocl/src/opencl/bgfg_mog.cl
	modules/superres/CMakeLists.txt
	modules/superres/src/btv_l1_cuda.cpp
	modules/superres/src/cuda/btv_l1_gpu.cu
	modules/superres/src/frame_source.cpp
	modules/superres/src/input_array_utility.cpp
	modules/superres/src/optical_flow.cpp
	modules/superres/src/precomp.hpp
	samples/gpu/CMakeLists.txt
	samples/gpu/brox_optical_flow.cpp
	samples/gpu/super_resolution.cpp
pull/2524/head
Roman Donchenko 11 years ago
commit cc05493730
  1. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r2.2.0.so
  2. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r2.3.3.so
  3. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r3.0.1.so
  4. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.0.so
  5. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r4.0.3.so
  6. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r4.1.1.so
  7. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r4.2.0.so
  8. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r4.3.0.so
  9. BIN
      3rdparty/lib/armeabi-v7a/libnative_camera_r4.4.0.so
  10. BIN
      3rdparty/lib/armeabi/libnative_camera_r2.2.0.so
  11. BIN
      3rdparty/lib/armeabi/libnative_camera_r2.3.3.so
  12. BIN
      3rdparty/lib/armeabi/libnative_camera_r3.0.1.so
  13. BIN
      3rdparty/lib/armeabi/libnative_camera_r4.0.0.so
  14. BIN
      3rdparty/lib/armeabi/libnative_camera_r4.0.3.so
  15. BIN
      3rdparty/lib/armeabi/libnative_camera_r4.1.1.so
  16. BIN
      3rdparty/lib/armeabi/libnative_camera_r4.2.0.so
  17. BIN
      3rdparty/lib/armeabi/libnative_camera_r4.3.0.so
  18. BIN
      3rdparty/lib/armeabi/libnative_camera_r4.4.0.so
  19. BIN
      3rdparty/lib/mips/libnative_camera_r4.0.3.so
  20. BIN
      3rdparty/lib/mips/libnative_camera_r4.1.1.so
  21. BIN
      3rdparty/lib/mips/libnative_camera_r4.2.0.so
  22. BIN
      3rdparty/lib/mips/libnative_camera_r4.3.0.so
  23. BIN
      3rdparty/lib/mips/libnative_camera_r4.4.0.so
  24. BIN
      3rdparty/lib/x86/libnative_camera_r2.3.3.so
  25. BIN
      3rdparty/lib/x86/libnative_camera_r3.0.1.so
  26. BIN
      3rdparty/lib/x86/libnative_camera_r4.0.3.so
  27. BIN
      3rdparty/lib/x86/libnative_camera_r4.1.1.so
  28. BIN
      3rdparty/lib/x86/libnative_camera_r4.2.0.so
  29. BIN
      3rdparty/lib/x86/libnative_camera_r4.3.0.so
  30. BIN
      3rdparty/lib/x86/libnative_camera_r4.4.0.so
  31. 1
      CMakeLists.txt
  32. 39
      cmake/OpenCVDetectCUDA.cmake
  33. 36
      cmake/OpenCVModule.cmake
  34. 28
      cmake/templates/OpenCVConfig.cmake.in
  35. 6
      doc/tutorials/core/adding_images/adding_images.rst
  36. 2
      doc/tutorials/core/how_to_scan_images/how_to_scan_images.rst
  37. 90
      doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.rst
  38. 2
      modules/androidcamera/camera_wrapper/CMakeLists.txt
  39. 297
      modules/androidcamera/camera_wrapper/camera_wrapper.cpp
  40. 6
      modules/androidcamera/include/camera_properties.h
  41. 4
      modules/core/src/persistence.cpp
  42. 5
      modules/cudabgsegm/src/cuda/mog2.cu
  43. 3
      modules/flann/include/opencv2/flann/kmeans_index.h
  44. 2
      modules/highgui/doc/reading_and_writing_images_and_video.rst
  45. 3
      modules/highgui/include/opencv2/highgui/highgui_c.h
  46. 15
      modules/highgui/src/cap_android.cpp
  47. 1
      modules/java/generator/src/java/android+NativeCameraView.java
  48. 3
      modules/nonfree/perf/perf_precomp.hpp
  49. 2
      modules/superres/CMakeLists.txt
  50. 5
      modules/video/src/bgfg_gaussmix2.cpp
  51. 5
      modules/video/src/opencl/bgfg_mog2.cl
  52. 2
      modules/viz/doc/widget.rst
  53. 6
      samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp
  54. 2
      samples/gpu/CMakeLists.txt
  55. 2
      samples/gpu/brox_optical_flow.cpp
  56. 1
      samples/gpu/opticalflow_nvidia_api.cpp
  57. 2
      samples/gpu/super_resolution.cpp

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -438,7 +438,6 @@ include(cmake/OpenCVFindLibsGUI.cmake)
include(cmake/OpenCVFindLibsVideo.cmake) include(cmake/OpenCVFindLibsVideo.cmake)
include(cmake/OpenCVFindLibsPerf.cmake) include(cmake/OpenCVFindLibsPerf.cmake)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Detect other 3rd-party libraries/tools # Detect other 3rd-party libraries/tools
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------

@ -217,3 +217,42 @@ else()
unset(CUDA_ARCH_BIN CACHE) unset(CUDA_ARCH_BIN CACHE)
unset(CUDA_ARCH_PTX CACHE) unset(CUDA_ARCH_PTX CACHE)
endif() endif()
if(HAVE_CUDA)
set(CUDA_LIBS_PATH "")
foreach(p ${CUDA_LIBRARIES} ${CUDA_npp_LIBRARY})
get_filename_component(_tmp ${p} PATH)
list(APPEND CUDA_LIBS_PATH ${_tmp})
endforeach()
if(HAVE_CUBLAS)
foreach(p ${CUDA_cublas_LIBRARY})
get_filename_component(_tmp ${p} PATH)
list(APPEND CUDA_LIBS_PATH ${_tmp})
endforeach()
endif()
if(HAVE_CUFFT)
foreach(p ${CUDA_cufft_LIBRARY})
get_filename_component(_tmp ${p} PATH)
list(APPEND CUDA_LIBS_PATH ${_tmp})
endforeach()
endif()
list(REMOVE_DUPLICATES CUDA_LIBS_PATH)
link_directories(${CUDA_LIBS_PATH})
set(CUDA_LIBRARIES_ABS ${CUDA_LIBRARIES})
ocv_convert_to_lib_name(CUDA_LIBRARIES ${CUDA_LIBRARIES})
set(CUDA_npp_LIBRARY_ABS ${CUDA_npp_LIBRARY})
ocv_convert_to_lib_name(CUDA_npp_LIBRARY ${CUDA_npp_LIBRARY})
if(HAVE_CUBLAS)
set(CUDA_cublas_LIBRARY_ABS ${CUDA_cublas_LIBRARY})
ocv_convert_to_lib_name(CUDA_cublas_LIBRARY ${CUDA_cublas_LIBRARY})
endif()
if(HAVE_CUFFT)
set(CUDA_cufft_LIBRARY_ABS ${CUDA_cufft_LIBRARY})
ocv_convert_to_lib_name(CUDA_cufft_LIBRARY ${CUDA_cufft_LIBRARY})
endif()
endif()

@ -27,7 +27,8 @@
# The verbose template for OpenCV module: # The verbose template for OpenCV module:
# #
# ocv_add_module(modname <dependencies>) # ocv_add_module(modname <dependencies>)
# ocv_glob_module_sources() or glob them manually and ocv_set_module_sources(...) # ocv_glob_module_sources(([EXCLUDE_CUDA] <extra sources&headers>)
# or glob them manually and ocv_set_module_sources(...)
# ocv_module_include_directories(<extra include directories>) # ocv_module_include_directories(<extra include directories>)
# ocv_create_module() # ocv_create_module()
# <add extra link dependencies, compiler options, etc> # <add extra link dependencies, compiler options, etc>
@ -478,8 +479,14 @@ endmacro()
# finds and sets headers and sources for the standard OpenCV module # finds and sets headers and sources for the standard OpenCV module
# Usage: # Usage:
# ocv_glob_module_sources(<extra sources&headers in the same format as used in ocv_set_module_sources>) # ocv_glob_module_sources([EXCLUDE_CUDA] <extra sources&headers in the same format as used in ocv_set_module_sources>)
macro(ocv_glob_module_sources) macro(ocv_glob_module_sources)
set(_argn ${ARGN})
list(FIND _argn "EXCLUDE_CUDA" exclude_cuda)
if(NOT exclude_cuda EQUAL -1)
list(REMOVE_AT _argn ${exclude_cuda})
endif()
file(GLOB_RECURSE lib_srcs "src/*.cpp") file(GLOB_RECURSE lib_srcs "src/*.cpp")
file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h") file(GLOB_RECURSE lib_int_hdrs "src/*.hpp" "src/*.h")
file(GLOB lib_hdrs "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") file(GLOB lib_hdrs "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
@ -492,16 +499,22 @@ macro(ocv_glob_module_sources)
ocv_source_group("Src" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/src" FILES ${lib_srcs} ${lib_int_hdrs}) ocv_source_group("Src" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/src" FILES ${lib_srcs} ${lib_int_hdrs})
ocv_source_group("Include" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/include" FILES ${lib_hdrs} ${lib_hdrs_detail}) ocv_source_group("Include" DIRBASE "${CMAKE_CURRENT_SOURCE_DIR}/include" FILES ${lib_hdrs} ${lib_hdrs_detail})
if (exclude_cuda EQUAL -1)
file(GLOB lib_cuda_srcs "src/cuda/*.cu") file(GLOB lib_cuda_srcs "src/cuda/*.cu")
set(cuda_objs "") set(cuda_objs "")
set(lib_cuda_hdrs "") set(lib_cuda_hdrs "")
if(HAVE_CUDA AND lib_cuda_srcs) if(HAVE_CUDA)
ocv_include_directories(${CUDA_INCLUDE_DIRS}) ocv_include_directories(${CUDA_INCLUDE_DIRS})
file(GLOB lib_cuda_hdrs "src/cuda/*.hpp") file(GLOB lib_cuda_hdrs "src/cuda/*.hpp")
ocv_cuda_compile(cuda_objs ${lib_cuda_srcs} ${lib_cuda_hdrs}) ocv_cuda_compile(cuda_objs ${lib_cuda_srcs} ${lib_cuda_hdrs})
source_group("Src\\Cuda" FILES ${lib_cuda_srcs} ${lib_cuda_hdrs}) source_group("Src\\Cuda" FILES ${lib_cuda_srcs} ${lib_cuda_hdrs})
endif() endif()
else()
set(cuda_objs "")
set(lib_cuda_srcs "")
set(lib_cuda_hdrs "")
endif()
file(GLOB cl_kernels "src/opencl/*.cl") file(GLOB cl_kernels "src/opencl/*.cl")
if(cl_kernels) if(cl_kernels)
@ -516,7 +529,7 @@ macro(ocv_glob_module_sources)
list(APPEND lib_srcs ${cl_kernels} "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp") list(APPEND lib_srcs ${cl_kernels} "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.cpp" "${CMAKE_CURRENT_BINARY_DIR}/opencl_kernels.hpp")
endif() endif()
ocv_set_module_sources(${ARGN} HEADERS ${lib_hdrs} ${lib_hdrs_detail} ocv_set_module_sources(${_argn} HEADERS ${lib_hdrs} ${lib_hdrs_detail}
SOURCES ${lib_srcs} ${lib_int_hdrs} ${cuda_objs} ${lib_cuda_srcs} ${lib_cuda_hdrs}) SOURCES ${lib_srcs} ${lib_int_hdrs} ${cuda_objs} ${lib_cuda_srcs} ${lib_cuda_hdrs})
endmacro() endmacro()
@ -622,11 +635,20 @@ endmacro()
# short command for adding simple OpenCV module # short command for adding simple OpenCV module
# see ocv_add_module for argument details # see ocv_add_module for argument details
# Usage: # Usage:
# ocv_define_module(module_name [INTERNAL] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>]) # ocv_define_module(module_name [INTERNAL] [EXCLUDE_CUDA] [REQUIRED] [<list of dependencies>] [OPTIONAL <list of optional dependencies>])
macro(ocv_define_module module_name) macro(ocv_define_module module_name)
ocv_add_module(${module_name} ${ARGN}) set(_argn ${ARGN})
set(exclude_cuda "")
foreach(arg ${_argn})
if("${arg}" STREQUAL "EXCLUDE_CUDA")
set(exclude_cuda "${arg}")
list(REMOVE_ITEM _argn ${arg})
endif()
endforeach()
ocv_add_module(${module_name} ${_argn})
ocv_module_include_directories() ocv_module_include_directories()
ocv_glob_module_sources() ocv_glob_module_sources(${exclude_cuda})
ocv_create_module() ocv_create_module()
ocv_add_precompiled_headers(${the_module}) ocv_add_precompiled_headers(${the_module})

@ -19,8 +19,8 @@
# This file will define the following variables: # This file will define the following variables:
# - OpenCV_LIBS : The list of all imported targets for OpenCV modules. # - OpenCV_LIBS : The list of all imported targets for OpenCV modules.
# - OpenCV_INCLUDE_DIRS : The OpenCV include directories. # - OpenCV_INCLUDE_DIRS : The OpenCV include directories.
# - OpenCV_COMPUTE_CAPABILITIES : The version of compute capability # - OpenCV_COMPUTE_CAPABILITIES : The version of compute capability.
# - OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API # - OpenCV_ANDROID_NATIVE_API_LEVEL : Minimum required level of Android API.
# - OpenCV_VERSION : The version of this OpenCV build: "@OPENCV_VERSION_PLAIN@" # - OpenCV_VERSION : The version of this OpenCV build: "@OPENCV_VERSION_PLAIN@"
# - OpenCV_VERSION_MAJOR : Major version part of OpenCV_VERSION: "@OPENCV_VERSION_MAJOR@" # - OpenCV_VERSION_MAJOR : Major version part of OpenCV_VERSION: "@OPENCV_VERSION_MAJOR@"
# - OpenCV_VERSION_MINOR : Minor version part of OpenCV_VERSION: "@OPENCV_VERSION_MINOR@" # - OpenCV_VERSION_MINOR : Minor version part of OpenCV_VERSION: "@OPENCV_VERSION_MINOR@"
@ -28,25 +28,29 @@
# - OpenCV_VERSION_STATUS : Development status of this build: "@OPENCV_VERSION_STATUS@" # - OpenCV_VERSION_STATUS : Development status of this build: "@OPENCV_VERSION_STATUS@"
# #
# Advanced variables: # Advanced variables:
# - OpenCV_SHARED # - OpenCV_SHARED : Use OpenCV as shared library
# - OpenCV_CONFIG_PATH # - OpenCV_CONFIG_PATH : Path to this OpenCVConfig.cmake
# - OpenCV_INSTALL_PATH (not set on Windows) # - OpenCV_INSTALL_PATH : OpenCV location (not set on Windows)
# - OpenCV_LIB_COMPONENTS # - OpenCV_LIB_COMPONENTS : Present OpenCV modules list
# - OpenCV_USE_MANGLED_PATHS # - OpenCV_USE_MANGLED_PATHS : Mangled OpenCV path flag
# - OpenCV_HAVE_ANDROID_CAMERA # - OpenCV_MODULES_SUFFIX : The suffix for OpenCVModules-XXX.cmake file
# - OpenCV_HAVE_ANDROID_CAMERA : Presence of Android native camera wrappers
# #
# Deprecated variables: # Deprecated variables:
# - OpenCV_VERSION_TWEAK : Always "0" # - OpenCV_VERSION_TWEAK : Always "0"
# #
# =================================================================================== # ===================================================================================
set(modules_file_suffix "") if(NOT DEFINED OpenCV_MODULES_SUFFIX)
if(ANDROID) if(ANDROID)
string(REPLACE - _ modules_file_suffix "_${ANDROID_NDK_ABI_NAME}") string(REPLACE - _ OpenCV_MODULES_SUFFIX "_${ANDROID_NDK_ABI_NAME}")
else()
set(OpenCV_MODULES_SUFFIX "")
endif()
endif() endif()
if(NOT TARGET opencv_core) if(NOT TARGET opencv_core)
include(${CMAKE_CURRENT_LIST_DIR}/OpenCVModules${modules_file_suffix}.cmake) include(${CMAKE_CURRENT_LIST_DIR}/OpenCVModules${OpenCV_MODULES_SUFFIX}.cmake)
endif() endif()
# TODO All things below should be reviewed. What is about of moving this code into related modules (special vars/hooks/files) # TODO All things below should be reviewed. What is about of moving this code into related modules (special vars/hooks/files)

@ -6,12 +6,12 @@ Adding (blending) two images using OpenCV
Goal Goal
===== =====
In this tutorial you will learn how to: In this tutorial you will learn:
.. container:: enumeratevisibleitemswithsquare .. container:: enumeratevisibleitemswithsquare
* What is *linear blending* and why it is useful. * what is *linear blending* and why it is useful;
* Add two images using :add_weighted:`addWeighted <>` * how to add two images using :add_weighted:`addWeighted <>`
Theory Theory
======= =======

@ -18,7 +18,7 @@ We'll seek answers for the following questions:
Our test case Our test case
============= =============
Let us consider a simple color reduction method. Using the unsigned char C and C++ type for matrix item storing a channel of pixel may have up to 256 different values. For a three channel image this can allow the formation of way too many colors (16 million to be exact). Working with so many color shades may give a heavy blow to our algorithm performance. However, sometimes it is enough to work with a lot less of them to get the same final result. Let us consider a simple color reduction method. By using the unsigned char C and C++ type for matrix item storing, a channel of pixel may have up to 256 different values. For a three channel image this can allow the formation of way too many colors (16 million to be exact). Working with so many color shades may give a heavy blow to our algorithm performance. However, sometimes it is enough to work with a lot less of them to get the same final result.
In this cases it's common that we make a *color space reduction*. This means that we divide the color space current value with a new input value to end up with fewer colors. For instance every value between zero and nine takes the new value zero, every value between ten and nineteen the value ten and so on. In this cases it's common that we make a *color space reduction*. This means that we divide the color space current value with a new input value to end up with fewer colors. For instance every value between zero and nine takes the new value zero, every value between ten and nineteen the value ten and so on.

@ -84,88 +84,10 @@ Code
* **Code at glance:** * **Code at glance:**
.. code-block:: cpp .. literalinclude:: ../../../../../samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp
:language: cpp
:tab-width: 4
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** @function main */
int main( int argc, char** argv )
{
Mat src_base, hsv_base;
Mat src_test1, hsv_test1;
Mat src_test2, hsv_test2;
Mat hsv_half_down;
/// Load three images with different environment settings
if( argc < 4 )
{ printf("** Error. Usage: ./compareHist_Demo <image_settings0> <image_setting1> <image_settings2>\n");
return -1;
}
src_base = imread( argv[1], 1 );
src_test1 = imread( argv[2], 1 );
src_test2 = imread( argv[3], 1 );
/// Convert to HSV
cvtColor( src_base, hsv_base, CV_BGR2HSV );
cvtColor( src_test1, hsv_test1, CV_BGR2HSV );
cvtColor( src_test2, hsv_test2, CV_BGR2HSV );
hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) );
/// Using 30 bins for hue and 32 for saturation
int h_bins = 50; int s_bins = 60;
int histSize[] = { h_bins, s_bins };
// hue varies from 0 to 256, saturation from 0 to 180
float h_ranges[] = { 0, 256 };
float s_ranges[] = { 0, 180 };
const float* ranges[] = { h_ranges, s_ranges };
// Use the o-th and 1-st channels
int channels[] = { 0, 1 };
/// Histograms
MatND hist_base;
MatND hist_half_down;
MatND hist_test1;
MatND hist_test2;
/// Calculate the histograms for the HSV images
calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false );
normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() );
calcHist( &hsv_half_down, 1, channels, Mat(), hist_half_down, 2, histSize, ranges, true, false );
normalize( hist_half_down, hist_half_down, 0, 1, NORM_MINMAX, -1, Mat() );
calcHist( &hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges, true, false );
normalize( hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat() );
calcHist( &hsv_test2, 1, channels, Mat(), hist_test2, 2, histSize, ranges, true, false );
normalize( hist_test2, hist_test2, 0, 1, NORM_MINMAX, -1, Mat() );
/// Apply the histogram comparison methods
for( int i = 0; i < 4; i++ )
{ int compare_method = i;
double base_base = compareHist( hist_base, hist_base, compare_method );
double base_half = compareHist( hist_base, hist_half_down, compare_method );
double base_test1 = compareHist( hist_base, hist_test1, compare_method );
double base_test2 = compareHist( hist_base, hist_test2, compare_method );
printf( " Method [%d] Perfect, Base-Half, Base-Test(1), Base-Test(2) : %f, %f, %f, %f \n", i, base_base, base_half , base_test1, base_test2 );
}
printf( "Done \n" );
return 0;
}
Explanation Explanation
@ -211,11 +133,11 @@ Explanation
.. code-block:: cpp .. code-block:: cpp
int h_bins = 50; int s_bins = 32; int h_bins = 50; int s_bins = 60;
int histSize[] = { h_bins, s_bins }; int histSize[] = { h_bins, s_bins };
float h_ranges[] = { 0, 256 }; float h_ranges[] = { 0, 180 };
float s_ranges[] = { 0, 180 }; float s_ranges[] = { 0, 256 };
const float* ranges[] = { h_ranges, s_ranges }; const float* ranges[] = { h_ranges, s_ranges };

@ -58,7 +58,7 @@ SET_TARGET_PROPERTIES(${the_target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
) )
if (NOT (CMAKE_BUILD_TYPE MATCHES "debug")) if (NOT (CMAKE_BUILD_TYPE MATCHES "Debug"))
ADD_CUSTOM_COMMAND( TARGET ${the_target} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${LIBRARY_OUTPUT_PATH}/lib${the_target}.so" ) ADD_CUSTOM_COMMAND( TARGET ${the_target} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${LIBRARY_OUTPUT_PATH}/lib${the_target}.so" )
endif() endif()

@ -61,6 +61,12 @@
using namespace android; using namespace android;
// non-public camera related classes are not binary compatible
// objects of these classes have different sizeof on different platforms
// additional memory tail to all system objects to overcome sizeof issue
#define MAGIC_TAIL 4096
void debugShowFPS(); void debugShowFPS();
#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) #if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
@ -90,6 +96,7 @@ public:
}; };
#endif #endif
std::string getProcessName() std::string getProcessName()
{ {
std::string result; std::string result;
@ -142,12 +149,22 @@ class CameraHandler: public CameraListener
protected: protected:
int cameraId; int cameraId;
sp<Camera> camera; sp<Camera> camera;
CameraParameters params; #if defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
sp<SurfaceTexture> surface;
#endif
#if defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
sp<BufferQueue> queue;
sp<ConsumerListenerStub> listener;
#endif
CameraParameters* params;
CameraCallback cameraCallback; CameraCallback cameraCallback;
void* userData; void* userData;
int emptyCameraCallbackReported; int emptyCameraCallbackReported;
int width;
int height;
static const char* flashModesNames[ANDROID_CAMERA_FLASH_MODES_NUM]; static const char* flashModesNames[ANDROID_CAMERA_FLASH_MODES_NUM];
static const char* focusModesNames[ANDROID_CAMERA_FOCUS_MODES_NUM]; static const char* focusModesNames[ANDROID_CAMERA_FOCUS_MODES_NUM];
static const char* whiteBalanceModesNames[ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM]; static const char* whiteBalanceModesNames[ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM];
@ -258,7 +275,7 @@ protected:
int is_supported(const char* supp_modes_key, const char* mode) int is_supported(const char* supp_modes_key, const char* mode)
{ {
const char* supported_modes = params.get(supp_modes_key); const char* supported_modes = params->get(supp_modes_key);
return (supported_modes && mode && (strstr(supported_modes, mode) > 0)); return (supported_modes && mode && (strstr(supported_modes, mode) > 0));
} }
@ -268,7 +285,7 @@ protected:
if (focus_distance_type >= 0 && focus_distance_type < 3) if (focus_distance_type >= 0 && focus_distance_type < 3)
{ {
float focus_distances[3]; float focus_distances[3];
const char* output = params.get(CameraParameters::KEY_FOCUS_DISTANCES); const char* output = params->get(CameraParameters::KEY_FOCUS_DISTANCES);
int val_num = CameraHandler::split_float(output, focus_distances, ',', 3); int val_num = CameraHandler::split_float(output, focus_distances, ',', 3);
if(val_num == 3) if(val_num == 3)
{ {
@ -300,10 +317,15 @@ public:
emptyCameraCallbackReported(0) emptyCameraCallbackReported(0)
{ {
LOGD("Instantiated new CameraHandler (%p, %p)", callback, _userData); LOGD("Instantiated new CameraHandler (%p, %p)", callback, _userData);
void* params_buffer = operator new(sizeof(CameraParameters) + MAGIC_TAIL);
params = new(params_buffer) CameraParameters();
} }
virtual ~CameraHandler() virtual ~CameraHandler()
{ {
if (params)
params->~CameraParameters();
operator delete(params);
LOGD("CameraHandler destructor is called"); LOGD("CameraHandler destructor is called");
} }
@ -371,10 +393,18 @@ const char* CameraHandler::focusModesNames[ANDROID_CAMERA_FOCUS_MODES_NUM] =
CameraParameters::FOCUS_MODE_AUTO, CameraParameters::FOCUS_MODE_AUTO,
#if !defined(ANDROID_r2_2_0) #if !defined(ANDROID_r2_2_0)
CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO,
#else
CameraParameters::FOCUS_MODE_AUTO,
#endif #endif
CameraParameters::FOCUS_MODE_EDOF, CameraParameters::FOCUS_MODE_EDOF,
CameraParameters::FOCUS_MODE_FIXED, CameraParameters::FOCUS_MODE_FIXED,
CameraParameters::FOCUS_MODE_INFINITY CameraParameters::FOCUS_MODE_INFINITY,
CameraParameters::FOCUS_MODE_MACRO,
#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1)
CameraParameters::FOCUS_MODE_CONTINUOUS_PICTURE
#else
CameraParameters::FOCUS_MODE_AUTO
#endif
}; };
const char* CameraHandler::whiteBalanceModesNames[ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM] = const char* CameraHandler::whiteBalanceModesNames[ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM] =
@ -534,39 +564,39 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
{ {
LOGI("initCameraConnect: Setting paramers from previous camera handler"); LOGI("initCameraConnect: Setting paramers from previous camera handler");
camera->setParameters(prevCameraParameters->flatten()); camera->setParameters(prevCameraParameters->flatten());
handler->params.unflatten(prevCameraParameters->flatten()); handler->params->unflatten(prevCameraParameters->flatten());
} }
else else
{ {
android::String8 params_str = camera->getParameters(); android::String8 params_str = camera->getParameters();
LOGI("initCameraConnect: [%s]", params_str.string()); LOGI("initCameraConnect: [%s]", params_str.string());
handler->params.unflatten(params_str); handler->params->unflatten(params_str);
LOGD("Supported Cameras: %s", handler->params.get("camera-indexes")); LOGD("Supported Cameras: %s", handler->params->get("camera-indexes"));
LOGD("Supported Picture Sizes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES)); LOGD("Supported Picture Sizes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES));
LOGD("Supported Picture Formats: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS)); LOGD("Supported Picture Formats: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS));
LOGD("Supported Preview Sizes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES)); LOGD("Supported Preview Sizes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES));
LOGD("Supported Preview Formats: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS)); LOGD("Supported Preview Formats: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS));
LOGD("Supported Preview Frame Rates: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES)); LOGD("Supported Preview Frame Rates: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES));
LOGD("Supported Thumbnail Sizes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES)); LOGD("Supported Thumbnail Sizes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES));
LOGD("Supported Whitebalance Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE)); LOGD("Supported Whitebalance Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE));
LOGD("Supported Effects: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_EFFECTS)); LOGD("Supported Effects: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_EFFECTS));
LOGD("Supported Scene Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_SCENE_MODES)); LOGD("Supported Scene Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_SCENE_MODES));
LOGD("Supported Focus Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES)); LOGD("Supported Focus Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES));
LOGD("Supported Antibanding Options: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_ANTIBANDING)); LOGD("Supported Antibanding Options: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_ANTIBANDING));
LOGD("Supported Flash Modes: %s", handler->params.get(CameraParameters::KEY_SUPPORTED_FLASH_MODES)); LOGD("Supported Flash Modes: %s", handler->params->get(CameraParameters::KEY_SUPPORTED_FLASH_MODES));
#if !defined(ANDROID_r2_2_0) #if !defined(ANDROID_r2_2_0)
// Set focus mode to continuous-video if supported // Set focus mode to continuous-video if supported
const char* available_focus_modes = handler->params.get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES); const char* available_focus_modes = handler->params->get(CameraParameters::KEY_SUPPORTED_FOCUS_MODES);
if (available_focus_modes != 0) if (available_focus_modes != 0)
{ {
if (strstr(available_focus_modes, "continuous-video") != NULL) if (strstr(available_focus_modes, "continuous-video") != NULL)
{ {
handler->params.set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO); handler->params->set(CameraParameters::KEY_FOCUS_MODE, CameraParameters::FOCUS_MODE_CONTINUOUS_VIDEO);
status_t resParams = handler->camera->setParameters(handler->params.flatten()); status_t resParams = handler->camera->setParameters(handler->params->flatten());
if (resParams != 0) if (resParams != 0)
{ {
@ -581,7 +611,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
#endif #endif
//check if yuv420sp format available. Set this format as preview format. //check if yuv420sp format available. Set this format as preview format.
const char* available_formats = handler->params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS); const char* available_formats = handler->params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS);
if (available_formats != 0) if (available_formats != 0)
{ {
const char* format_to_set = 0; const char* format_to_set = 0;
@ -607,9 +637,9 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
if (0 != format_to_set) if (0 != format_to_set)
{ {
handler->params.setPreviewFormat(format_to_set); handler->params->setPreviewFormat(format_to_set);
status_t resParams = handler->camera->setParameters(handler->params.flatten()); status_t resParams = handler->camera->setParameters(handler->params->flatten());
if (resParams != 0) if (resParams != 0)
LOGE("initCameraConnect: failed to set preview format to %s", format_to_set); LOGE("initCameraConnect: failed to set preview format to %s", format_to_set);
@ -617,6 +647,13 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
LOGD("initCameraConnect: preview format is set to %s", format_to_set); LOGD("initCameraConnect: preview format is set to %s", format_to_set);
} }
} }
handler->params->setPreviewSize(640, 480);
status_t resParams = handler->camera->setParameters(handler->params->flatten());
if (resParams != 0)
LOGE("initCameraConnect: failed to set preview resolution to 640x480");
else
LOGD("initCameraConnect: preview format is set to 640x480");
} }
status_t bufferStatus; status_t bufferStatus;
@ -627,22 +664,27 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback,
#elif defined(ANDROID_r2_3_3) #elif defined(ANDROID_r2_3_3)
/* Do nothing in case of 2.3 for now */ /* Do nothing in case of 2.3 for now */
#elif defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) #elif defined(ANDROID_r3_0_1) || defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
sp<SurfaceTexture> surfaceTexture = new SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID); void* surface_texture_obj = operator new(sizeof(SurfaceTexture) + MAGIC_TAIL);
bufferStatus = camera->setPreviewTexture(surfaceTexture); handler->surface = new(surface_texture_obj) SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID);
bufferStatus = camera->setPreviewTexture(handler->surface);
if (bufferStatus != 0) if (bufferStatus != 0)
LOGE("initCameraConnect: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus); LOGE("initCameraConnect: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus);
#elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) #elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
sp<BufferQueue> bufferQueue = new BufferQueue(); void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL);
sp<BufferQueue::ConsumerListener> queueListener = new ConsumerListenerStub(); handler->queue = new(buffer_queue_obj) BufferQueue();
bufferQueue->consumerConnect(queueListener); void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL);
bufferStatus = camera->setPreviewTexture(bufferQueue); handler->listener = new(consumer_listener_obj) ConsumerListenerStub();
handler->queue->consumerConnect(handler->listener);
bufferStatus = camera->setPreviewTexture(handler->queue);
if (bufferStatus != 0) if (bufferStatus != 0)
LOGE("initCameraConnect: failed setPreviewTexture call; camera might not work correctly"); LOGE("initCameraConnect: failed setPreviewTexture call; camera might not work correctly");
# elif defined(ANDROID_r4_4_0) # elif defined(ANDROID_r4_4_0)
sp<BufferQueue> bufferQueue = new BufferQueue(); void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL);
sp<IConsumerListener> queueListener = new ConsumerListenerStub(); handler->queue = new(buffer_queue_obj) BufferQueue();
bufferQueue->consumerConnect(queueListener, true); void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL);
bufferStatus = handler->camera->setPreviewTarget(bufferQueue); handler->listener = new(consumer_listener_obj) ConsumerListenerStub();
handler->queue->consumerConnect(handler->listener, true);
bufferStatus = handler->camera->setPreviewTarget(handler->queue);
if (bufferStatus != 0) if (bufferStatus != 0)
LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly"); LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
# endif # endif
@ -723,18 +765,18 @@ double CameraHandler::getProperty(int propIdx)
case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH:
{ {
int w,h; int w,h;
params.getPreviewSize(&w, &h); params->getPreviewSize(&w, &h);
return w; return w;
} }
case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT:
{ {
int w,h; int w,h;
params.getPreviewSize(&w, &h); params->getPreviewSize(&w, &h);
return h; return h;
} }
case ANDROID_CAMERA_PROPERTY_SUPPORTED_PREVIEW_SIZES_STRING: case ANDROID_CAMERA_PROPERTY_SUPPORTED_PREVIEW_SIZES_STRING:
{ {
cameraPropertySupportedPreviewSizesString = params.get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES); cameraPropertySupportedPreviewSizesString = params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES);
union {const char* str;double res;} u; union {const char* str;double res;} u;
memset(&u.res, 0, sizeof(u.res)); memset(&u.res, 0, sizeof(u.res));
u.str = cameraPropertySupportedPreviewSizesString.c_str(); u.str = cameraPropertySupportedPreviewSizesString.c_str();
@ -742,7 +784,7 @@ double CameraHandler::getProperty(int propIdx)
} }
case ANDROID_CAMERA_PROPERTY_PREVIEW_FORMAT_STRING: case ANDROID_CAMERA_PROPERTY_PREVIEW_FORMAT_STRING:
{ {
const char* fmt = params.get(CameraParameters::KEY_PREVIEW_FORMAT); const char* fmt = params->get(CameraParameters::KEY_PREVIEW_FORMAT);
if (fmt == CameraParameters::PIXEL_FORMAT_YUV422SP) if (fmt == CameraParameters::PIXEL_FORMAT_YUV422SP)
fmt = "yuv422sp"; fmt = "yuv422sp";
else if (fmt == CameraParameters::PIXEL_FORMAT_YUV420SP) else if (fmt == CameraParameters::PIXEL_FORMAT_YUV420SP)
@ -762,44 +804,44 @@ double CameraHandler::getProperty(int propIdx)
} }
case ANDROID_CAMERA_PROPERTY_EXPOSURE: case ANDROID_CAMERA_PROPERTY_EXPOSURE:
{ {
int exposure = params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION); int exposure = params->getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION);
return exposure; return exposure;
} }
case ANDROID_CAMERA_PROPERTY_FPS: case ANDROID_CAMERA_PROPERTY_FPS:
{ {
return params.getPreviewFrameRate(); return params->getPreviewFrameRate();
} }
case ANDROID_CAMERA_PROPERTY_FLASH_MODE: case ANDROID_CAMERA_PROPERTY_FLASH_MODE:
{ {
int flash_mode = getModeNum(CameraHandler::flashModesNames, int flash_mode = getModeNum(CameraHandler::flashModesNames,
ANDROID_CAMERA_FLASH_MODES_NUM, ANDROID_CAMERA_FLASH_MODES_NUM,
params.get(CameraParameters::KEY_FLASH_MODE)); params->get(CameraParameters::KEY_FLASH_MODE));
return flash_mode; return flash_mode;
} }
case ANDROID_CAMERA_PROPERTY_FOCUS_MODE: case ANDROID_CAMERA_PROPERTY_FOCUS_MODE:
{ {
int focus_mode = getModeNum(CameraHandler::focusModesNames, int focus_mode = getModeNum(CameraHandler::focusModesNames,
ANDROID_CAMERA_FOCUS_MODES_NUM, ANDROID_CAMERA_FOCUS_MODES_NUM,
params.get(CameraParameters::KEY_FOCUS_MODE)); params->get(CameraParameters::KEY_FOCUS_MODE));
return focus_mode; return focus_mode;
} }
case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE: case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE:
{ {
int white_balance = getModeNum(CameraHandler::whiteBalanceModesNames, int white_balance = getModeNum(CameraHandler::whiteBalanceModesNames,
ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM, ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM,
params.get(CameraParameters::KEY_WHITE_BALANCE)); params->get(CameraParameters::KEY_WHITE_BALANCE));
return white_balance; return white_balance;
} }
case ANDROID_CAMERA_PROPERTY_ANTIBANDING: case ANDROID_CAMERA_PROPERTY_ANTIBANDING:
{ {
int antibanding = getModeNum(CameraHandler::antibandingModesNames, int antibanding = getModeNum(CameraHandler::antibandingModesNames,
ANDROID_CAMERA_ANTIBANDING_MODES_NUM, ANDROID_CAMERA_ANTIBANDING_MODES_NUM,
params.get(CameraParameters::KEY_ANTIBANDING)); params->get(CameraParameters::KEY_ANTIBANDING));
return antibanding; return antibanding;
} }
case ANDROID_CAMERA_PROPERTY_FOCAL_LENGTH: case ANDROID_CAMERA_PROPERTY_FOCAL_LENGTH:
{ {
float focal_length = params.getFloat(CameraParameters::KEY_FOCAL_LENGTH); float focal_length = params->getFloat(CameraParameters::KEY_FOCAL_LENGTH);
return focal_length; return focal_length;
} }
case ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_NEAR: case ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_NEAR:
@ -814,6 +856,24 @@ double CameraHandler::getProperty(int propIdx)
{ {
return getFocusDistance(ANDROID_CAMERA_FOCUS_DISTANCE_FAR_INDEX); return getFocusDistance(ANDROID_CAMERA_FOCUS_DISTANCE_FAR_INDEX);
} }
#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1)
case ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK:
{
const char* status = params->get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK);
if (status == CameraParameters::TRUE)
return 1.;
else
return 0.;
}
case ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK:
{
const char* status = params->get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK);
if (status == CameraParameters::TRUE)
return 1.;
else
return 0.;
}
#endif
default: default:
LOGW("CameraHandler::getProperty - Unsupported property."); LOGW("CameraHandler::getProperty - Unsupported property.");
}; };
@ -824,99 +884,151 @@ void CameraHandler::setProperty(int propIdx, double value)
{ {
LOGD("CameraHandler::setProperty(%d, %f)", propIdx, value); LOGD("CameraHandler::setProperty(%d, %f)", propIdx, value);
android::String8 params_str;
params_str = camera->getParameters();
LOGI("Params before set: [%s]", params_str.string());
switch (propIdx) switch (propIdx)
{ {
case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH: case ANDROID_CAMERA_PROPERTY_FRAMEWIDTH:
{ {
int w,h; int w,h;
params.getPreviewSize(&w, &h); params->getPreviewSize(&w, &h);
w = (int)value; width = (int)value;
params.setPreviewSize(w, h);
} }
break; break;
case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT: case ANDROID_CAMERA_PROPERTY_FRAMEHEIGHT:
{ {
int w,h; int w,h;
params.getPreviewSize(&w, &h); params->getPreviewSize(&w, &h);
h = (int)value; height = (int)value;
params.setPreviewSize(w, h);
} }
break; break;
case ANDROID_CAMERA_PROPERTY_EXPOSURE: case ANDROID_CAMERA_PROPERTY_EXPOSURE:
{ {
int max_exposure = params.getInt("max-exposure-compensation"); int max_exposure = params->getInt("max-exposure-compensation");
int min_exposure = params.getInt("min-exposure-compensation"); int min_exposure = params->getInt("min-exposure-compensation");
if(max_exposure && min_exposure){ if(max_exposure && min_exposure)
{
int exposure = (int)value; int exposure = (int)value;
if(exposure >= min_exposure && exposure <= max_exposure){ if(exposure >= min_exposure && exposure <= max_exposure)
params.set("exposure-compensation", exposure); params->set("exposure-compensation", exposure);
} else { else
LOGE("Exposure compensation not in valid range (%i,%i).", min_exposure, max_exposure); LOGE("Exposure compensation not in valid range (%i,%i).", min_exposure, max_exposure);
} } else
} else {
LOGE("Exposure compensation adjust is not supported."); LOGE("Exposure compensation adjust is not supported.");
}
camera->setParameters(params->flatten());
} }
break; break;
case ANDROID_CAMERA_PROPERTY_FLASH_MODE: case ANDROID_CAMERA_PROPERTY_FLASH_MODE:
{ {
int new_val = (int)value; int new_val = (int)value;
if(new_val >= 0 && new_val < ANDROID_CAMERA_FLASH_MODES_NUM){ if(new_val >= 0 && new_val < ANDROID_CAMERA_FLASH_MODES_NUM)
{
const char* mode_name = flashModesNames[new_val]; const char* mode_name = flashModesNames[new_val];
if(is_supported(CameraParameters::KEY_SUPPORTED_FLASH_MODES, mode_name)) if(is_supported(CameraParameters::KEY_SUPPORTED_FLASH_MODES, mode_name))
params.set(CameraParameters::KEY_FLASH_MODE, mode_name); params->set(CameraParameters::KEY_FLASH_MODE, mode_name);
else else
LOGE("Flash mode %s is not supported.", mode_name); LOGE("Flash mode %s is not supported.", mode_name);
} else {
LOGE("Flash mode value not in valid range.");
} }
else
LOGE("Flash mode value not in valid range.");
camera->setParameters(params->flatten());
} }
break; break;
case ANDROID_CAMERA_PROPERTY_FOCUS_MODE: case ANDROID_CAMERA_PROPERTY_FOCUS_MODE:
{ {
int new_val = (int)value; int new_val = (int)value;
if(new_val >= 0 && new_val < ANDROID_CAMERA_FOCUS_MODES_NUM){ if(new_val >= 0 && new_val < ANDROID_CAMERA_FOCUS_MODES_NUM)
{
const char* mode_name = focusModesNames[new_val]; const char* mode_name = focusModesNames[new_val];
if(is_supported(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, mode_name)) if(is_supported(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, mode_name))
params.set(CameraParameters::KEY_FOCUS_MODE, mode_name); params->set(CameraParameters::KEY_FOCUS_MODE, mode_name);
else else
LOGE("Focus mode %s is not supported.", mode_name); LOGE("Focus mode %s is not supported.", mode_name);
} else {
LOGE("Focus mode value not in valid range.");
} }
else
LOGE("Focus mode value not in valid range.");
camera->setParameters(params->flatten());
} }
break; break;
case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE: case ANDROID_CAMERA_PROPERTY_WHITE_BALANCE:
{ {
int new_val = (int)value; int new_val = (int)value;
if(new_val >= 0 && new_val < ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM){ if(new_val >= 0 && new_val < ANDROID_CAMERA_WHITE_BALANCE_MODES_NUM)
{
const char* mode_name = whiteBalanceModesNames[new_val]; const char* mode_name = whiteBalanceModesNames[new_val];
if(is_supported(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, mode_name)) if(is_supported(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, mode_name))
params.set(CameraParameters::KEY_WHITE_BALANCE, mode_name); params->set(CameraParameters::KEY_WHITE_BALANCE, mode_name);
else else
LOGE("White balance mode %s is not supported.", mode_name); LOGE("White balance mode %s is not supported.", mode_name);
} else {
LOGE("White balance mode value not in valid range.");
} }
else
LOGE("White balance mode value not in valid range.");
camera->setParameters(params->flatten());
} }
break; break;
case ANDROID_CAMERA_PROPERTY_ANTIBANDING: case ANDROID_CAMERA_PROPERTY_ANTIBANDING:
{ {
int new_val = (int)value; int new_val = (int)value;
if(new_val >= 0 && new_val < ANDROID_CAMERA_ANTIBANDING_MODES_NUM){ if(new_val >= 0 && new_val < ANDROID_CAMERA_ANTIBANDING_MODES_NUM)
{
const char* mode_name = antibandingModesNames[new_val]; const char* mode_name = antibandingModesNames[new_val];
if(is_supported(CameraParameters::KEY_SUPPORTED_ANTIBANDING, mode_name)) if(is_supported(CameraParameters::KEY_SUPPORTED_ANTIBANDING, mode_name))
params.set(CameraParameters::KEY_ANTIBANDING, mode_name); params->set(CameraParameters::KEY_ANTIBANDING, mode_name);
else else
LOGE("Antibanding mode %s is not supported.", mode_name); LOGE("Antibanding mode %s is not supported.", mode_name);
} else { }
else
LOGE("Antibanding mode value not in valid range."); LOGE("Antibanding mode value not in valid range.");
camera->setParameters(params->flatten());
} }
break;
#if !defined(ANDROID_r2_2_0) && !defined(ANDROID_r2_3_3) && !defined(ANDROID_r3_0_1)
case ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK:
{
if (is_supported(CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED, "true"))
{
if (value != 0)
params->set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, CameraParameters::TRUE);
else
params->set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, CameraParameters::FALSE);
LOGE("Expose lock is set");
}
else
LOGE("Expose lock is not supported");
camera->setParameters(params->flatten());
} }
break; break;
case ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK:
{
if (is_supported(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED, "true"))
{
if (value != 0)
params->set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, CameraParameters::TRUE);
else
params->set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, CameraParameters::FALSE);
LOGE("White balance lock is set");
}
else
LOGE("White balance lock is not supported");
camera->setParameters(params->flatten());
}
break;
#endif
default: default:
LOGW("CameraHandler::setProperty - Unsupported property."); LOGW("CameraHandler::setProperty - Unsupported property.");
}; };
params_str = camera->getParameters();
LOGI("Params after set: [%s]", params_str.string());
} }
void CameraHandler::applyProperties(CameraHandler** ppcameraHandler) void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
@ -935,7 +1047,10 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
return; return;
} }
CameraParameters curCameraParameters((*ppcameraHandler)->params.flatten()); // delayed resolution setup to exclude errors during other parameres setup on the fly
// without camera restart
if (((*ppcameraHandler)->width != 0) && ((*ppcameraHandler)->height != 0))
(*ppcameraHandler)->params->setPreviewSize((*ppcameraHandler)->width, (*ppcameraHandler)->height);
#if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \ #if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) || defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) \
|| defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) || defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0)
@ -951,27 +1066,27 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
return; return;
} }
handler->camera->setParameters(curCameraParameters.flatten()); handler->camera->setParameters((*ppcameraHandler)->params->flatten());
handler->params.unflatten(curCameraParameters.flatten());
status_t bufferStatus; status_t bufferStatus;
# if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3) # if defined(ANDROID_r4_0_0) || defined(ANDROID_r4_0_3)
sp<SurfaceTexture> surfaceTexture = new SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID); void* surface_texture_obj = operator new(sizeof(SurfaceTexture) + MAGIC_TAIL);
bufferStatus = handler->camera->setPreviewTexture(surfaceTexture); handler->surface = new(surface_texture_obj) SurfaceTexture(MAGIC_OPENCV_TEXTURE_ID);
bufferStatus = handler->camera->setPreviewTexture(handler->surface);
if (bufferStatus != 0) if (bufferStatus != 0)
LOGE("applyProperties: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus); LOGE("applyProperties: failed setPreviewTexture call (status %d); camera might not work correctly", bufferStatus);
# elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0) # elif defined(ANDROID_r4_1_1) || defined(ANDROID_r4_2_0) || defined(ANDROID_r4_3_0)
sp<BufferQueue> bufferQueue = new BufferQueue(); void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL);
sp<BufferQueue::ConsumerListener> queueListener = new ConsumerListenerStub(); handler->queue = new(buffer_queue_obj) BufferQueue();
bufferQueue->consumerConnect(queueListener); handler->queue->consumerConnect(handler->listener);
bufferStatus = handler->camera->setPreviewTexture(bufferQueue); bufferStatus = handler->camera->setPreviewTexture(handler->queue);
if (bufferStatus != 0) if (bufferStatus != 0)
LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly"); LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
# elif defined(ANDROID_r4_4_0) # elif defined(ANDROID_r4_4_0)
sp<BufferQueue> bufferQueue = new BufferQueue(); void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL);
sp<IConsumerListener> queueListener = new ConsumerListenerStub(); handler->queue = new(buffer_queue_obj) BufferQueue();
bufferQueue->consumerConnect(queueListener, true); handler->queue->consumerConnect(handler->listener, true);
bufferStatus = handler->camera->setPreviewTarget(bufferQueue); bufferStatus = handler->camera->setPreviewTarget(handler->queue);
if (bufferStatus != 0) if (bufferStatus != 0)
LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly"); LOGE("applyProperties: failed setPreviewTexture call; camera might not work correctly");
# endif # endif
@ -1002,7 +1117,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler)
LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect"); LOGD("CameraHandler::applyProperties(): after previousCameraHandler->closeCameraConnect");
LOGD("CameraHandler::applyProperties(): before initCameraConnect"); LOGD("CameraHandler::applyProperties(): before initCameraConnect");
CameraHandler* handler=initCameraConnect(cameraCallback, cameraId, userData, &curCameraParameters); CameraHandler* handler=initCameraConnect(cameraCallback, cameraId, userData, (*ppcameraHandler)->params);
LOGD("CameraHandler::applyProperties(): after initCameraConnect, handler=0x%x", (int)handler); LOGD("CameraHandler::applyProperties(): after initCameraConnect, handler=0x%x", (int)handler);
if (handler == NULL) { if (handler == NULL) {
LOGE("ERROR in applyProperties --- cannot reinit camera"); LOGE("ERROR in applyProperties --- cannot reinit camera");

@ -15,7 +15,9 @@ enum {
ANDROID_CAMERA_PROPERTY_FOCAL_LENGTH = 105, ANDROID_CAMERA_PROPERTY_FOCAL_LENGTH = 105,
ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_NEAR = 106, ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_NEAR = 106,
ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_OPTIMAL = 107, ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_OPTIMAL = 107,
ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR = 108 ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR = 108,
ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK = 109,
ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK = 110
}; };
@ -30,12 +32,12 @@ enum {
enum { enum {
ANDROID_CAMERA_FOCUS_MODE_AUTO = 0, ANDROID_CAMERA_FOCUS_MODE_AUTO = 0,
ANDROID_CAMERA_FOCUS_MODE_CONTINUOUS_PICTURE,
ANDROID_CAMERA_FOCUS_MODE_CONTINUOUS_VIDEO, ANDROID_CAMERA_FOCUS_MODE_CONTINUOUS_VIDEO,
ANDROID_CAMERA_FOCUS_MODE_EDOF, ANDROID_CAMERA_FOCUS_MODE_EDOF,
ANDROID_CAMERA_FOCUS_MODE_FIXED, ANDROID_CAMERA_FOCUS_MODE_FIXED,
ANDROID_CAMERA_FOCUS_MODE_INFINITY, ANDROID_CAMERA_FOCUS_MODE_INFINITY,
ANDROID_CAMERA_FOCUS_MODE_MACRO, ANDROID_CAMERA_FOCUS_MODE_MACRO,
ANDROID_CAMERA_FOCUS_MODE_CONTINUOUS_PICTURE,
ANDROID_CAMERA_FOCUS_MODES_NUM ANDROID_CAMERA_FOCUS_MODES_NUM
}; };

@ -4824,7 +4824,7 @@ cvRegisterType( const CvTypeInfo* _info )
"Type name should contain only letters, digits, - and _" ); "Type name should contain only letters, digits, - and _" );
} }
info = (CvTypeInfo*)malloc( sizeof(*info) + len + 1 ); info = (CvTypeInfo*)cvAlloc( sizeof(*info) + len + 1 );
*info = *_info; *info = *_info;
info->type_name = (char*)(info + 1); info->type_name = (char*)(info + 1);
@ -4862,7 +4862,7 @@ cvUnregisterType( const char* type_name )
if( !CvType::first || !CvType::last ) if( !CvType::first || !CvType::last )
CvType::first = CvType::last = 0; CvType::first = CvType::last = 0;
free( info ); cvFree( &info );
} }
} }

@ -163,7 +163,7 @@ namespace cv { namespace cuda { namespace device
{ {
//need only weight if fit is found //need only weight if fit is found
float weight = alpha1 * gmm_weight(mode * frame.rows + y, x) + prune; float weight = alpha1 * gmm_weight(mode * frame.rows + y, x) + prune;
int swap_count = 0;
//fit not found yet //fit not found yet
if (!fitsPDF) if (!fitsPDF)
{ {
@ -214,6 +214,7 @@ namespace cv { namespace cuda { namespace device
if (weight < gmm_weight((i - 1) * frame.rows + y, x)) if (weight < gmm_weight((i - 1) * frame.rows + y, x))
break; break;
swap_count++;
//swap one up //swap one up
swap(gmm_weight, x, y, i - 1, frame.rows); swap(gmm_weight, x, y, i - 1, frame.rows);
swap(gmm_variance, x, y, i - 1, frame.rows); swap(gmm_variance, x, y, i - 1, frame.rows);
@ -231,7 +232,7 @@ namespace cv { namespace cuda { namespace device
nmodes--; nmodes--;
} }
gmm_weight(mode * frame.rows + y, x) = weight; //update weight by the calculated value gmm_weight((mode - swap_count) * frame.rows + y, x) = weight; //update weight by the calculated value
totalWeight += weight; totalWeight += weight;
} }

@ -758,12 +758,15 @@ private:
for (int k=0; k<indices_length; ++k) { for (int k=0; k<indices_length; ++k) {
if (belongs_to[k]==j) { if (belongs_to[k]==j) {
// for cluster j, we move the furthest element from the center to the empty cluster i
if ( distance_(dataset_[indices[k]], dcenters[j], veclen_) == radiuses[j] ) {
belongs_to[k] = i; belongs_to[k] = i;
count[j]--; count[j]--;
count[i]++; count[i]++;
break; break;
} }
} }
}
converged = false; converged = false;
} }
} }

@ -483,7 +483,7 @@ VideoWriter constructors
:param filename: Name of the output video file. :param filename: Name of the output video file.
:param fourcc: 4-character code of codec used to compress the frames. For example, ``CV_FOURCC('P','I','M,'1')`` is a MPEG-1 codec, ``CV_FOURCC('M','J','P','G')`` is a motion-jpeg codec etc. List of codes can be obtained at `Video Codecs by FOURCC <http://www.fourcc.org/codecs.php>`_ page. :param fourcc: 4-character code of codec used to compress the frames. For example, ``CV_FOURCC('P','I','M','1')`` is a MPEG-1 codec, ``CV_FOURCC('M','J','P','G')`` is a motion-jpeg codec etc. List of codes can be obtained at `Video Codecs by FOURCC <http://www.fourcc.org/codecs.php>`_ page.
:param fps: Framerate of the created video stream. :param fps: Framerate of the created video stream.

@ -463,6 +463,8 @@ enum
CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_NEAR = 8006, CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_NEAR = 8006,
CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_OPTIMAL = 8007, CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_OPTIMAL = 8007,
CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR = 8008, CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR = 8008,
CV_CAP_PROP_ANDROID_EXPOSE_LOCK = 8009,
CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK = 8010,
// Properties of cameras available through AVFOUNDATION interface // Properties of cameras available through AVFOUNDATION interface
CV_CAP_PROP_IOS_DEVICE_FOCUS = 9001, CV_CAP_PROP_IOS_DEVICE_FOCUS = 9001,
@ -543,6 +545,7 @@ enum
enum enum
{ {
CV_CAP_ANDROID_FOCUS_MODE_AUTO = 0, CV_CAP_ANDROID_FOCUS_MODE_AUTO = 0,
CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_PICTURE,
CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_VIDEO, CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_VIDEO,
CV_CAP_ANDROID_FOCUS_MODE_EDOF, CV_CAP_ANDROID_FOCUS_MODE_EDOF,
CV_CAP_ANDROID_FOCUS_MODE_FIXED, CV_CAP_ANDROID_FOCUS_MODE_FIXED,

@ -289,6 +289,10 @@ double CvCapture_Android::getProperty( int propIdx )
return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_OPTIMAL); return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_OPTIMAL);
case CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR: case CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR:
return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR); return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_FOCUS_DISTANCE_FAR);
case CV_CAP_PROP_ANDROID_EXPOSE_LOCK:
return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK);
case CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK:
return (double)m_activity->getProperty(ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK);
default: default:
CV_Error( CV_StsOutOfRange, "Failed attempt to GET unsupported camera property." ); CV_Error( CV_StsOutOfRange, "Failed attempt to GET unsupported camera property." );
break; break;
@ -327,14 +331,23 @@ bool CvCapture_Android::setProperty( int propIdx, double propValue )
case CV_CAP_PROP_ANDROID_ANTIBANDING: case CV_CAP_PROP_ANDROID_ANTIBANDING:
m_activity->setProperty(ANDROID_CAMERA_PROPERTY_ANTIBANDING, propValue); m_activity->setProperty(ANDROID_CAMERA_PROPERTY_ANTIBANDING, propValue);
break; break;
case CV_CAP_PROP_ANDROID_EXPOSE_LOCK:
m_activity->setProperty(ANDROID_CAMERA_PROPERTY_EXPOSE_LOCK, propValue);
break;
case CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK:
m_activity->setProperty(ANDROID_CAMERA_PROPERTY_WHITEBALANCE_LOCK, propValue);
break;
default: default:
CV_Error( CV_StsOutOfRange, "Failed attempt to SET unsupported camera property." ); CV_Error( CV_StsOutOfRange, "Failed attempt to SET unsupported camera property." );
return false; return false;
} }
if (propIdx != CV_CAP_PROP_AUTOGRAB) {// property for highgui class CvCapture_Android only // Only changes in frame size require camera restart
if ((propIdx == CV_CAP_PROP_FRAME_WIDTH) || (propIdx == CV_CAP_PROP_FRAME_HEIGHT))
{ // property for highgui class CvCapture_Android only
m_CameraParamsChanged = true; m_CameraParamsChanged = true;
} }
res = true; res = true;
} }

@ -175,7 +175,6 @@ public class NativeCameraView extends CameraBridgeViewBase {
} }
deliverAndDrawFrame(mFrame); deliverAndDrawFrame(mFrame);
} while (!mStopThread); } while (!mStopThread);
} }
} }

@ -9,12 +9,13 @@
#ifndef __OPENCV_PERF_PRECOMP_HPP__ #ifndef __OPENCV_PERF_PRECOMP_HPP__
#define __OPENCV_PERF_PRECOMP_HPP__ #define __OPENCV_PERF_PRECOMP_HPP__
#include "cvconfig.h"
#include "opencv2/ts.hpp" #include "opencv2/ts.hpp"
#include "opencv2/nonfree.hpp" #include "opencv2/nonfree.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"
#include "opencv2/opencv_modules.hpp" #include "opencv2/opencv_modules.hpp"
#include "cvconfig.h"
#ifdef HAVE_OPENCV_OCL #ifdef HAVE_OPENCV_OCL
# include "opencv2/nonfree/ocl.hpp" # include "opencv2/nonfree/ocl.hpp"

@ -1,4 +1,4 @@
if(ANDROID OR IOS) if(IOS)
ocv_module_disable(superres) ocv_module_disable(superres)
endif() endif()

@ -578,7 +578,7 @@ public:
for( int mode = 0; mode < nmodes; mode++, mean_m += nchannels ) for( int mode = 0; mode < nmodes; mode++, mean_m += nchannels )
{ {
float weight = alpha1*gmm[mode].weight + prune;//need only weight if fit is found float weight = alpha1*gmm[mode].weight + prune;//need only weight if fit is found
int swap_count = 0;
//// ////
//fit not found yet //fit not found yet
if( !fitsPDF ) if( !fitsPDF )
@ -643,6 +643,7 @@ public:
if( weight < gmm[i-1].weight ) if( weight < gmm[i-1].weight )
break; break;
swap_count++;
//swap one up //swap one up
std::swap(gmm[i], gmm[i-1]); std::swap(gmm[i], gmm[i-1]);
for( int c = 0; c < nchannels; c++ ) for( int c = 0; c < nchannels; c++ )
@ -660,7 +661,7 @@ public:
nmodes--; nmodes--;
} }
gmm[mode].weight = weight;//update weight by the calculated value gmm[mode-swap_count].weight = weight;//update weight by the calculated value
totalWeight += weight; totalWeight += weight;
} }
//go through all modes //go through all modes

@ -102,7 +102,7 @@ __kernel void mog2_kernel(__global const uchar* frame, int frame_step, int frame
{ {
float c_weight = alpha1 * _weight[(mode * frame_row + y) * weight_step + x] + prune; float c_weight = alpha1 * _weight[(mode * frame_row + y) * weight_step + x] + prune;
int swap_count = 0;
if (!fitsPDF) if (!fitsPDF)
{ {
float c_var = _variance[(mode * frame_row + y) * var_step + x]; float c_var = _variance[(mode * frame_row + y) * var_step + x];
@ -132,6 +132,7 @@ __kernel void mog2_kernel(__global const uchar* frame, int frame_step, int frame
{ {
if (c_weight < _weight[((i - 1) * frame_row + y) * weight_step + x]) if (c_weight < _weight[((i - 1) * frame_row + y) * weight_step + x])
break; break;
swap_count++;
swap(_weight, x, y, i - 1, frame_row, weight_step); swap(_weight, x, y, i - 1, frame_row, weight_step);
swap(_variance, x, y, i - 1, frame_row, var_step); swap(_variance, x, y, i - 1, frame_row, var_step);
#if (CN==1) #if (CN==1)
@ -149,7 +150,7 @@ __kernel void mog2_kernel(__global const uchar* frame, int frame_step, int frame
nmodes--; nmodes--;
} }
_weight[(mode * frame_row + y) * weight_step + x] = c_weight; //update weight by the calculated value _weight[((mode - swap_count) * frame_row + y) * weight_step + x] = c_weight; //update weight by the calculated value
totalWeight += c_weight; totalWeight += c_weight;
} }

@ -1050,7 +1050,7 @@ viz::WWidgetMerger::WWidgetMerger
--------------------------------------- ---------------------------------------
Constructs a WWidgetMerger. Constructs a WWidgetMerger.
.. ocv:WWidgetMerger:: WWidgetMerger() .. ocv:function:: WWidgetMerger()
viz::WWidgetMerger::addCloud viz::WWidgetMerger::addCloud
------------------------------- -------------------------------

@ -40,13 +40,13 @@ int main( int argc, char** argv )
hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) ); hsv_half_down = hsv_base( Range( hsv_base.rows/2, hsv_base.rows - 1 ), Range( 0, hsv_base.cols - 1 ) );
/// Using 30 bins for hue and 32 for saturation /// Using 50 bins for hue and 60 for saturation
int h_bins = 50; int s_bins = 60; int h_bins = 50; int s_bins = 60;
int histSize[] = { h_bins, s_bins }; int histSize[] = { h_bins, s_bins };
// hue varies from 0 to 256, saturation from 0 to 180 // hue varies from 0 to 179, saturation from 0 to 255
float s_ranges[] = { 0, 256 };
float h_ranges[] = { 0, 180 }; float h_ranges[] = { 0, 180 };
float s_ranges[] = { 0, 256 };
const float* ranges[] = { h_ranges, s_ranges }; const float* ranges[] = { h_ranges, s_ranges };

@ -49,7 +49,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS}) target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS})
if(HAVE_CUDA) if(HAVE_CUDA AND NOT ANDROID)
target_link_libraries(${the_target} ${CUDA_CUDA_LIBRARY}) target_link_libraries(${the_target} ${CUDA_CUDA_LIBRARY})
endif() endif()

@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <cctype> #include <ctype.h>
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"

@ -7,6 +7,7 @@
#include <memory> #include <memory>
#include <exception> #include <exception>
#include <ctime> #include <ctime>
#include <ctype.h>
#include "cvconfig.h" #include "cvconfig.h"
#include <iostream> #include <iostream>

@ -1,6 +1,8 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <string> #include <string>
#include <ctype.h>
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp" #include "opencv2/core/utility.hpp"
#include "opencv2/highgui.hpp" #include "opencv2/highgui.hpp"

Loading…
Cancel
Save