Commit 9c3e86b7 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

parents 648db235 b639795a
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
//M*/ //M*/
#include "precomp.hpp" #include "precomp.hpp"
#undef CV_FORCE_SIMD128_CPP // mixed HAL SIMD/SSE code
#include "opencv2/core/core_c.h" #include "opencv2/core/core_c.h"
#include "opencv2/core/private.hpp" #include "opencv2/core/private.hpp"
#include "opencv2/flann/miniflann.hpp" #include "opencv2/flann/miniflann.hpp"
......
...@@ -123,7 +123,6 @@ void sobelExtractor(const Mat img, const Rect roi, Mat& feat){ ...@@ -123,7 +123,6 @@ void sobelExtractor(const Mat img, const Rect roi, Mat& feat){
//! [sobel] //! [sobel]
//! [postprocess] //! [postprocess]
feat.convertTo(feat,CV_64F);
feat=feat/255.0-0.5; // normalize to range -0.5 .. 0.5 feat=feat/255.0-0.5; // normalize to range -0.5 .. 0.5
//! [postprocess] //! [postprocess]
} }
...@@ -68,6 +68,6 @@ If you need a more detailed information to use @ref cv::Tracker, please refer to ...@@ -68,6 +68,6 @@ If you need a more detailed information to use @ref cv::Tracker, please refer to
-# **Post processing** -# **Post processing**
Make sure to convert the feature into @ref cv::CV_64F data format and normalize its value with range -0.5 to 0.5 Make sure to normalize the feature with range -0.5 to 0.5
@snippet tracking/samples/tutorial_customizing_cn_tracker.cpp postprocess @snippet tracking/samples/tutorial_customizing_cn_tracker.cpp postprocess
...@@ -46,11 +46,11 @@ You need to set the OPENCV_ENABLE_NONFREE option in cmake to use those. Use them ...@@ -46,11 +46,11 @@ You need to set the OPENCV_ENABLE_NONFREE option in cmake to use those. Use them
@param contrast resulting contrast on logarithmic scale, i. e. log(max / min), where max and min @param contrast resulting contrast on logarithmic scale, i. e. log(max / min), where max and min
are maximum and minimum luminance values of the resulting image. are maximum and minimum luminance values of the resulting image.
@param saturation saturation enhancement value. See createTonemapDrago @param saturation saturation enhancement value. See createTonemapDrago
@param sigma_space bilateral filter sigma in color space @param sigma_color bilateral filter sigma in color space
@param sigma_color bilateral filter sigma in coordinate space @param sigma_space bilateral filter sigma in coordinate space
*/ */
CV_EXPORTS_W Ptr<TonemapDurand> CV_EXPORTS_W Ptr<TonemapDurand>
createTonemapDurand(float gamma = 1.0f, float contrast = 4.0f, float saturation = 1.0f, float sigma_space = 2.0f, float sigma_color = 2.0f); createTonemapDurand(float gamma = 1.0f, float contrast = 4.0f, float saturation = 1.0f, float sigma_color = 2.0f, float sigma_space = 2.0f);
}} // namespace }} // namespace
#endif // OPENCV_XPHOTO_TONEMAP_HPP #endif // OPENCV_XPHOTO_TONEMAP_HPP
...@@ -262,26 +262,26 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average ...@@ -262,26 +262,26 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average
uint sumB = 0, sumG = 0, sumR = 0; uint sumB = 0, sumG = 0, sumR = 0;
uchar *src_ptr = src.ptr<uchar>(); uchar *src_ptr = src.ptr<uchar>();
#if CV_SIMD128 #if CV_SIMD128
v_uint8x16 v_inB, v_inG, v_inR, v_mask; v_uint16x8 v_max_sum = v_setall_u16(0), v_brightestR = v_setall_u16(0), v_brightestG = v_setall_u16(0), v_brightestB = v_setall_u16(0);
v_uint16x8 v_sR1, v_sR2, v_sG1, v_sG2, v_sB1, v_sB2, v_sum; v_uint32x4 v_SB = v_setzero_u32(), v_SG = v_setzero_u32(), v_SR = v_setzero_u32();
v_uint16x8 v_max_sum = v_setall_u16(0), v_max_mask, v_brightestR, v_brightestG, v_brightestB;
v_uint32x4 v_uint1, v_uint2, v_SB = v_setzero_u32(), v_SG = v_setzero_u32(), v_SR = v_setzero_u32();
for (; i < src_len - 15; i += 16) for (; i < src_len - 15; i += 16)
{ {
v_uint8x16 v_inB, v_inG, v_inR;
v_load_deinterleave(src_ptr + 3 * i, v_inB, v_inG, v_inR); v_load_deinterleave(src_ptr + 3 * i, v_inB, v_inG, v_inR);
v_mask = v_load(mask_ptr + i); v_uint8x16 v_mask = v_load(mask_ptr + i);
v_inB &= v_mask; v_inB &= v_mask;
v_inG &= v_mask; v_inG &= v_mask;
v_inR &= v_mask; v_inR &= v_mask;
v_uint16x8 v_sR1, v_sR2, v_sG1, v_sG2, v_sB1, v_sB2;
v_expand(v_inB, v_sB1, v_sB2); v_expand(v_inB, v_sB1, v_sB2);
v_expand(v_inG, v_sG1, v_sG2); v_expand(v_inG, v_sG1, v_sG2);
v_expand(v_inR, v_sR1, v_sR2); v_expand(v_inR, v_sR1, v_sR2);
// update the brightest (R,G,B) tuple (process left half): // update the brightest (R,G,B) tuple (process left half):
v_sum = v_sB1 + v_sG1 + v_sR1; v_uint16x8 v_sum = v_sB1 + v_sG1 + v_sR1;
v_max_mask = (v_sum > v_max_sum); v_uint16x8 v_max_mask = (v_sum > v_max_sum);
v_max_sum = v_max(v_sum, v_max_sum); v_max_sum = v_max(v_sum, v_max_sum);
v_brightestB = (v_sB1 & v_max_mask) + (v_brightestB & (~v_max_mask)); v_brightestB = (v_sB1 & v_max_mask) + (v_brightestB & (~v_max_mask));
v_brightestG = (v_sG1 & v_max_mask) + (v_brightestG & (~v_max_mask)); v_brightestG = (v_sG1 & v_max_mask) + (v_brightestG & (~v_max_mask));
...@@ -299,6 +299,8 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average ...@@ -299,6 +299,8 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average
v_sB1 = v_sB1 + v_sB2; v_sB1 = v_sB1 + v_sB2;
v_sG1 = v_sG1 + v_sG2; v_sG1 = v_sG1 + v_sG2;
v_sR1 = v_sR1 + v_sR2; v_sR1 = v_sR1 + v_sR2;
v_uint32x4 v_uint1, v_uint2;
v_expand(v_sB1, v_uint1, v_uint2); v_expand(v_sB1, v_uint1, v_uint2);
v_SB += v_uint1 + v_uint2; v_SB += v_uint1 + v_uint2;
v_expand(v_sG1, v_uint1, v_uint2); v_expand(v_sG1, v_uint1, v_uint2);
...@@ -351,27 +353,28 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average ...@@ -351,27 +353,28 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average
uint64 sumB = 0, sumG = 0, sumR = 0; uint64 sumB = 0, sumG = 0, sumR = 0;
ushort *src_ptr = src.ptr<ushort>(); ushort *src_ptr = src.ptr<ushort>();
#if CV_SIMD128 #if CV_SIMD128
v_uint16x8 v_inB, v_inG, v_inR, v_mask, v_mask_lower = v_setall_u16(255); const v_uint16x8 v_mask_lower = v_setall_u16(255);
v_uint32x4 v_iR1, v_iR2, v_iG1, v_iG2, v_iB1, v_iB2, v_sum; v_uint32x4 v_max_sum = v_setall_u32(0), v_brightestR = v_setall_u32(0), v_brightestG = v_setall_u32(0), v_brightestB = v_setall_u32(0);
v_uint32x4 v_max_sum = v_setall_u32(0), v_max_mask, v_brightestR, v_brightestG, v_brightestB; v_uint64x2 v_SB = v_setzero_u64(), v_SG = v_setzero_u64(), v_SR = v_setzero_u64();
v_uint64x2 v_uint64_1, v_uint64_2, v_SB = v_setzero_u64(), v_SG = v_setzero_u64(), v_SR = v_setzero_u64();
for (; i < src_len - 7; i += 8) for (; i < src_len - 7; i += 8)
{ {
v_uint16x8 v_inB, v_inG, v_inR;
v_load_deinterleave(src_ptr + 3 * i, v_inB, v_inG, v_inR); v_load_deinterleave(src_ptr + 3 * i, v_inB, v_inG, v_inR);
v_mask = v_load_expand(mask_ptr + i); v_uint16x8 v_mask = v_load_expand(mask_ptr + i);
v_mask = v_mask | ((v_mask & v_mask_lower) << 8); v_mask = v_mask | ((v_mask & v_mask_lower) << 8);
v_inB &= v_mask; v_inB &= v_mask;
v_inG &= v_mask; v_inG &= v_mask;
v_inR &= v_mask; v_inR &= v_mask;
v_uint32x4 v_iR1, v_iR2, v_iG1, v_iG2, v_iB1, v_iB2;
v_expand(v_inB, v_iB1, v_iB2); v_expand(v_inB, v_iB1, v_iB2);
v_expand(v_inG, v_iG1, v_iG2); v_expand(v_inG, v_iG1, v_iG2);
v_expand(v_inR, v_iR1, v_iR2); v_expand(v_inR, v_iR1, v_iR2);
// update the brightest (R,G,B) tuple (process left half): // update the brightest (R,G,B) tuple (process left half):
v_sum = v_iB1 + v_iG1 + v_iR1; v_uint32x4 v_sum = v_iB1 + v_iG1 + v_iR1;
v_max_mask = (v_sum > v_max_sum); v_uint32x4 v_max_mask = (v_sum > v_max_sum);
v_max_sum = v_max(v_sum, v_max_sum); v_max_sum = v_max(v_sum, v_max_sum);
v_brightestB = (v_iB1 & v_max_mask) + (v_brightestB & (~v_max_mask)); v_brightestB = (v_iB1 & v_max_mask) + (v_brightestB & (~v_max_mask));
v_brightestG = (v_iG1 & v_max_mask) + (v_brightestG & (~v_max_mask)); v_brightestG = (v_iG1 & v_max_mask) + (v_brightestG & (~v_max_mask));
...@@ -389,6 +392,7 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average ...@@ -389,6 +392,7 @@ void LearningBasedWBImpl::getAverageAndBrightestColorChromaticity(Vec2f &average
v_iB1 = v_iB1 + v_iB2; v_iB1 = v_iB1 + v_iB2;
v_iG1 = v_iG1 + v_iG2; v_iG1 = v_iG1 + v_iG2;
v_iR1 = v_iR1 + v_iR2; v_iR1 = v_iR1 + v_iR2;
v_uint64x2 v_uint64_1, v_uint64_2;
v_expand(v_iB1, v_uint64_1, v_uint64_2); v_expand(v_iB1, v_uint64_1, v_uint64_2);
v_SB += v_uint64_1 + v_uint64_2; v_SB += v_uint64_1 + v_uint64_2;
v_expand(v_iG1, v_uint64_1, v_uint64_2); v_expand(v_iG1, v_uint64_1, v_uint64_2);
......
...@@ -38,6 +38,34 @@ TEST(Photo_Tonemap, Durand_regression) ...@@ -38,6 +38,34 @@ TEST(Photo_Tonemap, Durand_regression)
checkEqual(result, expected, 3, "Durand"); checkEqual(result, expected, 3, "Durand");
} }
TEST(Photo_Tonemap, Durand_property_regression)
{
const float gamma = 1.0f;
const float contrast = 2.0f;
const float saturation = 3.0f;
const float sigma_color = 4.0f;
const float sigma_space = 5.0f;
const Ptr<TonemapDurand> durand1 = createTonemapDurand(gamma, contrast, saturation, sigma_color, sigma_space);
ASSERT_EQ(gamma, durand1->getGamma());
ASSERT_EQ(contrast, durand1->getContrast());
ASSERT_EQ(saturation, durand1->getSaturation());
ASSERT_EQ(sigma_space, durand1->getSigmaSpace());
ASSERT_EQ(sigma_color, durand1->getSigmaColor());
const Ptr<TonemapDurand> durand2 = createTonemapDurand();
durand2->setGamma(gamma);
durand2->setContrast(contrast);
durand2->setSaturation(saturation);
durand2->setSigmaColor(sigma_color);
durand2->setSigmaSpace(sigma_space);
ASSERT_EQ(gamma, durand2->getGamma());
ASSERT_EQ(contrast, durand2->getContrast());
ASSERT_EQ(saturation, durand2->getSaturation());
ASSERT_EQ(sigma_color, durand2->getSigmaColor());
ASSERT_EQ(sigma_space, durand2->getSigmaSpace());
}
#endif // OPENCV_ENABLE_NONFREE #endif // OPENCV_ENABLE_NONFREE
}} // namespace }} // namespace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment