From 5cb008454729de5a78c23fee2245ee45acad48aa Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 21 Jan 2014 14:35:34 +0400 Subject: [PATCH 001/662] split CUDA Hough sources (cherry picked from commit d84738769422aad33038d90681c47486e47a0380) --- modules/gpu/src/cuda/build_point_list.cu | 138 ++++ .../cuda/{hough.cu => generalized_hough.cu} | 638 +----------------- modules/gpu/src/cuda/hough_circles.cu | 254 +++++++ modules/gpu/src/cuda/hough_lines.cu | 212 ++++++ modules/gpu/src/cuda/hough_segments.cu | 249 +++++++ .../src/{hough.cpp => generalized_hough.cpp} | 303 --------- modules/gpu/src/hough_circles.cpp | 223 ++++++ modules/gpu/src/hough_lines.cpp | 142 ++++ modules/gpu/src/hough_segments.cpp | 110 +++ 9 files changed, 1330 insertions(+), 939 deletions(-) create mode 100644 modules/gpu/src/cuda/build_point_list.cu rename modules/gpu/src/cuda/{hough.cu => generalized_hough.cu} (65%) create mode 100644 modules/gpu/src/cuda/hough_circles.cu create mode 100644 modules/gpu/src/cuda/hough_lines.cu create mode 100644 modules/gpu/src/cuda/hough_segments.cu rename modules/gpu/src/{hough.cpp => generalized_hough.cpp} (79%) create mode 100644 modules/gpu/src/hough_circles.cpp create mode 100644 modules/gpu/src/hough_lines.cpp create mode 100644 modules/gpu/src/hough_segments.cpp diff --git a/modules/gpu/src/cuda/build_point_list.cu b/modules/gpu/src/cuda/build_point_list.cu new file mode 100644 index 0000000000..8a9c73b3f1 --- /dev/null +++ b/modules/gpu/src/cuda/build_point_list.cu @@ -0,0 +1,138 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#if !defined CUDA_DISABLER + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/emulation.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ static int g_counter; + + template + __global__ void buildPointList(const PtrStepSzb src, unsigned int* list) + { + __shared__ unsigned int s_queues[4][32 * PIXELS_PER_THREAD]; + __shared__ int s_qsize[4]; + __shared__ int s_globStart[4]; + + const int x = blockIdx.x * blockDim.x * PIXELS_PER_THREAD + threadIdx.x; + const int y = blockIdx.y * blockDim.y + threadIdx.y; + + if (threadIdx.x == 0) + s_qsize[threadIdx.y] = 0; + __syncthreads(); + + if (y < src.rows) + { + // fill the queue + const uchar* srcRow = src.ptr(y); + for (int i = 0, xx = x; i < PIXELS_PER_THREAD && xx < src.cols; ++i, xx += blockDim.x) + { + if (srcRow[xx]) + { + const unsigned int val = (y << 16) | xx; + const int qidx = Emulation::smem::atomicAdd(&s_qsize[threadIdx.y], 1); + s_queues[threadIdx.y][qidx] = val; + } + } + } + + __syncthreads(); + + // let one thread reserve the space required in the global list + if (threadIdx.x == 0 && threadIdx.y == 0) + { + // find how many items are stored in each list + int totalSize = 0; + for (int i = 0; i < blockDim.y; ++i) + { + s_globStart[i] = totalSize; + totalSize += s_qsize[i]; + } + + // calculate the offset in the global list + const int globalOffset = atomicAdd(&g_counter, totalSize); + for (int i = 0; i < blockDim.y; ++i) + s_globStart[i] += globalOffset; + } + + __syncthreads(); + + // copy local queues to global queue + const int qsize = s_qsize[threadIdx.y]; + int gidx = s_globStart[threadIdx.y] + threadIdx.x; + for(int i = threadIdx.x; i < qsize; i += blockDim.x, gidx += blockDim.x) + list[gidx] = s_queues[threadIdx.y][i]; + } + + int buildPointList_gpu(PtrStepSzb src, unsigned int* list) + { + const int PIXELS_PER_THREAD = 16; + + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 4); + const dim3 grid(divUp(src.cols, block.x * PIXELS_PER_THREAD), divUp(src.rows, block.y)); + + cudaSafeCall( cudaFuncSetCacheConfig(buildPointList, cudaFuncCachePreferShared) ); + + buildPointList<<>>(src, list); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + return totalCount; + } + } +}}} + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/hough.cu b/modules/gpu/src/cuda/generalized_hough.cu similarity index 65% rename from modules/gpu/src/cuda/hough.cu rename to modules/gpu/src/cuda/generalized_hough.cu index 59eba26081..5e2041eae4 100644 --- a/modules/gpu/src/cuda/hough.cu +++ b/modules/gpu/src/cuda/generalized_hough.cu @@ -43,651 +43,18 @@ #if !defined CUDA_DISABLER #include -#include +#include #include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/emulation.hpp" #include "opencv2/gpu/device/vec_math.hpp" #include "opencv2/gpu/device/functional.hpp" -#include "opencv2/gpu/device/limits.hpp" -#include "opencv2/gpu/device/dynamic_smem.hpp" namespace cv { namespace gpu { namespace device { namespace hough { - __device__ int g_counter; - - //////////////////////////////////////////////////////////////////////// - // buildPointList - - template - __global__ void buildPointList(const PtrStepSzb src, unsigned int* list) - { - __shared__ unsigned int s_queues[4][32 * PIXELS_PER_THREAD]; - __shared__ int s_qsize[4]; - __shared__ int s_globStart[4]; - - const int x = blockIdx.x * blockDim.x * PIXELS_PER_THREAD + threadIdx.x; - const int y = blockIdx.y * blockDim.y + threadIdx.y; - - if (threadIdx.x == 0) - s_qsize[threadIdx.y] = 0; - __syncthreads(); - - if (y < src.rows) - { - // fill the queue - const uchar* srcRow = src.ptr(y); - for (int i = 0, xx = x; i < PIXELS_PER_THREAD && xx < src.cols; ++i, xx += blockDim.x) - { - if (srcRow[xx]) - { - const unsigned int val = (y << 16) | xx; - const int qidx = Emulation::smem::atomicAdd(&s_qsize[threadIdx.y], 1); - s_queues[threadIdx.y][qidx] = val; - } - } - } - - __syncthreads(); - - // let one thread reserve the space required in the global list - if (threadIdx.x == 0 && threadIdx.y == 0) - { - // find how many items are stored in each list - int totalSize = 0; - for (int i = 0; i < blockDim.y; ++i) - { - s_globStart[i] = totalSize; - totalSize += s_qsize[i]; - } - - // calculate the offset in the global list - const int globalOffset = atomicAdd(&g_counter, totalSize); - for (int i = 0; i < blockDim.y; ++i) - s_globStart[i] += globalOffset; - } - - __syncthreads(); - - // copy local queues to global queue - const int qsize = s_qsize[threadIdx.y]; - int gidx = s_globStart[threadIdx.y] + threadIdx.x; - for(int i = threadIdx.x; i < qsize; i += blockDim.x, gidx += blockDim.x) - list[gidx] = s_queues[threadIdx.y][i]; - } - - int buildPointList_gpu(PtrStepSzb src, unsigned int* list) - { - const int PIXELS_PER_THREAD = 16; - - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 4); - const dim3 grid(divUp(src.cols, block.x * PIXELS_PER_THREAD), divUp(src.rows, block.y)); - - cudaSafeCall( cudaFuncSetCacheConfig(buildPointList, cudaFuncCachePreferShared) ); - - buildPointList<<>>(src, list); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // linesAccum - - __global__ void linesAccumGlobal(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) - { - const int n = blockIdx.x; - const float ang = n * theta; - - float sinVal; - float cosVal; - sincosf(ang, &sinVal, &cosVal); - sinVal *= irho; - cosVal *= irho; - - const int shift = (numrho - 1) / 2; - - int* accumRow = accum.ptr(n + 1); - for (int i = threadIdx.x; i < count; i += blockDim.x) - { - const unsigned int val = list[i]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - int r = __float2int_rn(x * cosVal + y * sinVal); - r += shift; - - ::atomicAdd(accumRow + r + 1, 1); - } - } - - __global__ void linesAccumShared(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) - { - int* smem = DynamicSharedMem(); - - for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) - smem[i] = 0; - - __syncthreads(); - - const int n = blockIdx.x; - const float ang = n * theta; - - float sinVal; - float cosVal; - sincosf(ang, &sinVal, &cosVal); - sinVal *= irho; - cosVal *= irho; - - const int shift = (numrho - 1) / 2; - - for (int i = threadIdx.x; i < count; i += blockDim.x) - { - const unsigned int val = list[i]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - int r = __float2int_rn(x * cosVal + y * sinVal); - r += shift; - - Emulation::smem::atomicAdd(&smem[r + 1], 1); - } - - __syncthreads(); - - int* accumRow = accum.ptr(n + 1); - for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) - accumRow[i] = smem[i]; - } - - void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20) - { - const dim3 block(has20 ? 1024 : 512); - const dim3 grid(accum.rows - 2); - - size_t smemSize = (accum.cols - 1) * sizeof(int); - - if (smemSize < sharedMemPerBlock - 1000) - linesAccumShared<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); - else - linesAccumGlobal<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); - - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - } - - //////////////////////////////////////////////////////////////////////// - // linesGetResult - - __global__ void linesGetResult(const PtrStepSzi accum, float2* out, int* votes, const int maxSize, const float rho, const float theta, const int threshold, const int numrho) - { - const int r = blockIdx.x * blockDim.x + threadIdx.x; - const int n = blockIdx.y * blockDim.y + threadIdx.y; - - if (r >= accum.cols - 2 || n >= accum.rows - 2) - return; - - const int curVotes = accum(n + 1, r + 1); - - if (curVotes > threshold && - curVotes > accum(n + 1, r) && - curVotes >= accum(n + 1, r + 2) && - curVotes > accum(n, r + 1) && - curVotes >= accum(n + 2, r + 1)) - { - const float radius = (r - (numrho - 1) * 0.5f) * rho; - const float angle = n * theta; - - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxSize) - { - out[ind] = make_float2(radius, angle); - votes[ind] = curVotes; - } - } - } - - int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 8); - const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); - - cudaSafeCall( cudaFuncSetCacheConfig(linesGetResult, cudaFuncCachePreferL1) ); - - linesGetResult<<>>(accum, out, votes, maxSize, rho, theta, threshold, accum.cols - 2); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - totalCount = ::min(totalCount, maxSize); - - if (doSort && totalCount > 0) - { - thrust::device_ptr outPtr(out); - thrust::device_ptr votesPtr(votes); - thrust::sort_by_key(votesPtr, votesPtr + totalCount, outPtr, thrust::greater()); - } - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // houghLinesProbabilistic - - texture tex_mask(false, cudaFilterModePoint, cudaAddressModeClamp); - - __global__ void houghLinesProbabilistic(const PtrStepSzi accum, - int4* out, const int maxSize, - const float rho, const float theta, - const int lineGap, const int lineLength, - const int rows, const int cols) - { - const int r = blockIdx.x * blockDim.x + threadIdx.x; - const int n = blockIdx.y * blockDim.y + threadIdx.y; - - if (r >= accum.cols - 2 || n >= accum.rows - 2) - return; - - const int curVotes = accum(n + 1, r + 1); - - if (curVotes >= lineLength && - curVotes > accum(n, r) && - curVotes > accum(n, r + 1) && - curVotes > accum(n, r + 2) && - curVotes > accum(n + 1, r) && - curVotes > accum(n + 1, r + 2) && - curVotes > accum(n + 2, r) && - curVotes > accum(n + 2, r + 1) && - curVotes > accum(n + 2, r + 2)) - { - const float radius = (r - (accum.cols - 2 - 1) * 0.5f) * rho; - const float angle = n * theta; - - float cosa; - float sina; - sincosf(angle, &sina, &cosa); - - float2 p0 = make_float2(cosa * radius, sina * radius); - float2 dir = make_float2(-sina, cosa); - - float2 pb[4] = {make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1)}; - float a; - - if (dir.x != 0) - { - a = -p0.x / dir.x; - pb[0].x = 0; - pb[0].y = p0.y + a * dir.y; - - a = (cols - 1 - p0.x) / dir.x; - pb[1].x = cols - 1; - pb[1].y = p0.y + a * dir.y; - } - if (dir.y != 0) - { - a = -p0.y / dir.y; - pb[2].x = p0.x + a * dir.x; - pb[2].y = 0; - - a = (rows - 1 - p0.y) / dir.y; - pb[3].x = p0.x + a * dir.x; - pb[3].y = rows - 1; - } - - if (pb[0].x == 0 && (pb[0].y >= 0 && pb[0].y < rows)) - { - p0 = pb[0]; - if (dir.x < 0) - dir = -dir; - } - else if (pb[1].x == cols - 1 && (pb[0].y >= 0 && pb[0].y < rows)) - { - p0 = pb[1]; - if (dir.x > 0) - dir = -dir; - } - else if (pb[2].y == 0 && (pb[2].x >= 0 && pb[2].x < cols)) - { - p0 = pb[2]; - if (dir.y < 0) - dir = -dir; - } - else if (pb[3].y == rows - 1 && (pb[3].x >= 0 && pb[3].x < cols)) - { - p0 = pb[3]; - if (dir.y > 0) - dir = -dir; - } - - float2 d; - if (::fabsf(dir.x) > ::fabsf(dir.y)) - { - d.x = dir.x > 0 ? 1 : -1; - d.y = dir.y / ::fabsf(dir.x); - } - else - { - d.x = dir.x / ::fabsf(dir.y); - d.y = dir.y > 0 ? 1 : -1; - } - - float2 line_end[2]; - int gap; - bool inLine = false; - - float2 p1 = p0; - if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) - return; - - for (;;) - { - if (tex2D(tex_mask, p1.x, p1.y)) - { - gap = 0; - - if (!inLine) - { - line_end[0] = p1; - line_end[1] = p1; - inLine = true; - } - else - { - line_end[1] = p1; - } - } - else if (inLine) - { - if (++gap > lineGap) - { - bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || - ::abs(line_end[1].y - line_end[0].y) >= lineLength; - - if (good_line) - { - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxSize) - out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); - } - - gap = 0; - inLine = false; - } - } - - p1 = p1 + d; - if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) - { - if (inLine) - { - bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || - ::abs(line_end[1].y - line_end[0].y) >= lineLength; - - if (good_line) - { - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxSize) - out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); - } - - } - break; - } - } - } - } - - int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 8); - const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); - - bindTexture(&tex_mask, mask); - - houghLinesProbabilistic<<>>(accum, - out, maxSize, - rho, theta, - lineGap, lineLength, - mask.rows, mask.cols); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - totalCount = ::min(totalCount, maxSize); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // circlesAccumCenters - - __global__ void circlesAccumCenters(const unsigned int* list, const int count, const PtrStepi dx, const PtrStepi dy, - PtrStepi accum, const int width, const int height, const int minRadius, const int maxRadius, const float idp) - { - const int SHIFT = 10; - const int ONE = 1 << SHIFT; - - const int tid = blockIdx.x * blockDim.x + threadIdx.x; - - if (tid >= count) - return; - - const unsigned int val = list[tid]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - const int vx = dx(y, x); - const int vy = dy(y, x); - - if (vx == 0 && vy == 0) - return; - - const float mag = ::sqrtf(vx * vx + vy * vy); - - const int x0 = __float2int_rn((x * idp) * ONE); - const int y0 = __float2int_rn((y * idp) * ONE); - - int sx = __float2int_rn((vx * idp) * ONE / mag); - int sy = __float2int_rn((vy * idp) * ONE / mag); - - // Step from minRadius to maxRadius in both directions of the gradient - for (int k1 = 0; k1 < 2; ++k1) - { - int x1 = x0 + minRadius * sx; - int y1 = y0 + minRadius * sy; - - for (int r = minRadius; r <= maxRadius; x1 += sx, y1 += sy, ++r) - { - const int x2 = x1 >> SHIFT; - const int y2 = y1 >> SHIFT; - - if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) - break; - - ::atomicAdd(accum.ptr(y2 + 1) + x2 + 1, 1); - } - - sx = -sx; - sy = -sy; - } - } - - void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp) - { - const dim3 block(256); - const dim3 grid(divUp(count, block.x)); - - cudaSafeCall( cudaFuncSetCacheConfig(circlesAccumCenters, cudaFuncCachePreferL1) ); - - circlesAccumCenters<<>>(list, count, dx, dy, accum, accum.cols - 2, accum.rows - 2, minRadius, maxRadius, idp); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - } - - //////////////////////////////////////////////////////////////////////// - // buildCentersList - - __global__ void buildCentersList(const PtrStepSzi accum, unsigned int* centers, const int threshold) - { - const int x = blockIdx.x * blockDim.x + threadIdx.x; - const int y = blockIdx.y * blockDim.y + threadIdx.y; - - if (x < accum.cols - 2 && y < accum.rows - 2) - { - const int top = accum(y, x + 1); - - const int left = accum(y + 1, x); - const int cur = accum(y + 1, x + 1); - const int right = accum(y + 1, x + 2); - - const int bottom = accum(y + 2, x + 1); - - if (cur > threshold && cur > top && cur >= bottom && cur > left && cur >= right) - { - const unsigned int val = (y << 16) | x; - const int idx = ::atomicAdd(&g_counter, 1); - centers[idx] = val; - } - } - } - - int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(32, 8); - const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); - - cudaSafeCall( cudaFuncSetCacheConfig(buildCentersList, cudaFuncCachePreferL1) ); - - buildCentersList<<>>(accum, centers, threshold); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // circlesAccumRadius - - __global__ void circlesAccumRadius(const unsigned int* centers, const unsigned int* list, const int count, - float3* circles, const int maxCircles, const float dp, - const int minRadius, const int maxRadius, const int histSize, const int threshold) - { - int* smem = DynamicSharedMem(); - - for (int i = threadIdx.x; i < histSize + 2; i += blockDim.x) - smem[i] = 0; - __syncthreads(); - - unsigned int val = centers[blockIdx.x]; - - float cx = (val & 0xFFFF); - float cy = (val >> 16) & 0xFFFF; - - cx = (cx + 0.5f) * dp; - cy = (cy + 0.5f) * dp; - - for (int i = threadIdx.x; i < count; i += blockDim.x) - { - val = list[i]; - - const int x = (val & 0xFFFF); - const int y = (val >> 16) & 0xFFFF; - - const float rad = ::sqrtf((cx - x) * (cx - x) + (cy - y) * (cy - y)); - if (rad >= minRadius && rad <= maxRadius) - { - const int r = __float2int_rn(rad - minRadius); - - Emulation::smem::atomicAdd(&smem[r + 1], 1); - } - } - - __syncthreads(); - - for (int i = threadIdx.x; i < histSize; i += blockDim.x) - { - const int curVotes = smem[i + 1]; - - if (curVotes >= threshold && curVotes > smem[i] && curVotes >= smem[i + 2]) - { - const int ind = ::atomicAdd(&g_counter, 1); - if (ind < maxCircles) - circles[ind] = make_float3(cx, cy, i + minRadius); - } - } - } - - int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, - float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20) - { - void* counterPtr; - cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); - - cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); - - const dim3 block(has20 ? 1024 : 512); - const dim3 grid(centersCount); - - const int histSize = maxRadius - minRadius + 1; - size_t smemSize = (histSize + 2) * sizeof(int); - - circlesAccumRadius<<>>(centers, list, count, circles, maxCircles, dp, minRadius, maxRadius, histSize, threshold); - cudaSafeCall( cudaGetLastError() ); - - cudaSafeCall( cudaDeviceSynchronize() ); - - int totalCount; - cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); - - totalCount = ::min(totalCount, maxCircles); - - return totalCount; - } - - //////////////////////////////////////////////////////////////////////// - // Generalized Hough + __device__ static int g_counter; template __global__ void buildEdgePointList(const PtrStepSzb edges, const PtrStep dx, const PtrStep dy, unsigned int* coordList, float* thetaList) @@ -1706,5 +1073,4 @@ namespace cv { namespace gpu { namespace device } }}} - #endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/hough_circles.cu b/modules/gpu/src/cuda/hough_circles.cu new file mode 100644 index 0000000000..5df7887b0b --- /dev/null +++ b/modules/gpu/src/cuda/hough_circles.cu @@ -0,0 +1,254 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#if !defined CUDA_DISABLER + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/emulation.hpp" +#include "opencv2/gpu/device/dynamic_smem.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ static int g_counter; + + //////////////////////////////////////////////////////////////////////// + // circlesAccumCenters + + __global__ void circlesAccumCenters(const unsigned int* list, const int count, const PtrStepi dx, const PtrStepi dy, + PtrStepi accum, const int width, const int height, const int minRadius, const int maxRadius, const float idp) + { + const int SHIFT = 10; + const int ONE = 1 << SHIFT; + + const int tid = blockIdx.x * blockDim.x + threadIdx.x; + + if (tid >= count) + return; + + const unsigned int val = list[tid]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + const int vx = dx(y, x); + const int vy = dy(y, x); + + if (vx == 0 && vy == 0) + return; + + const float mag = ::sqrtf(vx * vx + vy * vy); + + const int x0 = __float2int_rn((x * idp) * ONE); + const int y0 = __float2int_rn((y * idp) * ONE); + + int sx = __float2int_rn((vx * idp) * ONE / mag); + int sy = __float2int_rn((vy * idp) * ONE / mag); + + // Step from minRadius to maxRadius in both directions of the gradient + for (int k1 = 0; k1 < 2; ++k1) + { + int x1 = x0 + minRadius * sx; + int y1 = y0 + minRadius * sy; + + for (int r = minRadius; r <= maxRadius; x1 += sx, y1 += sy, ++r) + { + const int x2 = x1 >> SHIFT; + const int y2 = y1 >> SHIFT; + + if (x2 < 0 || x2 >= width || y2 < 0 || y2 >= height) + break; + + ::atomicAdd(accum.ptr(y2 + 1) + x2 + 1, 1); + } + + sx = -sx; + sy = -sy; + } + } + + void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp) + { + const dim3 block(256); + const dim3 grid(divUp(count, block.x)); + + cudaSafeCall( cudaFuncSetCacheConfig(circlesAccumCenters, cudaFuncCachePreferL1) ); + + circlesAccumCenters<<>>(list, count, dx, dy, accum, accum.cols - 2, accum.rows - 2, minRadius, maxRadius, idp); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + } + + //////////////////////////////////////////////////////////////////////// + // buildCentersList + + __global__ void buildCentersList(const PtrStepSzi accum, unsigned int* centers, const int threshold) + { + const int x = blockIdx.x * blockDim.x + threadIdx.x; + const int y = blockIdx.y * blockDim.y + threadIdx.y; + + if (x < accum.cols - 2 && y < accum.rows - 2) + { + const int top = accum(y, x + 1); + + const int left = accum(y + 1, x); + const int cur = accum(y + 1, x + 1); + const int right = accum(y + 1, x + 2); + + const int bottom = accum(y + 2, x + 1); + + if (cur > threshold && cur > top && cur >= bottom && cur > left && cur >= right) + { + const unsigned int val = (y << 16) | x; + const int idx = ::atomicAdd(&g_counter, 1); + centers[idx] = val; + } + } + } + + int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 8); + const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); + + cudaSafeCall( cudaFuncSetCacheConfig(buildCentersList, cudaFuncCachePreferL1) ); + + buildCentersList<<>>(accum, centers, threshold); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + return totalCount; + } + + //////////////////////////////////////////////////////////////////////// + // circlesAccumRadius + + __global__ void circlesAccumRadius(const unsigned int* centers, const unsigned int* list, const int count, + float3* circles, const int maxCircles, const float dp, + const int minRadius, const int maxRadius, const int histSize, const int threshold) + { + int* smem = DynamicSharedMem(); + + for (int i = threadIdx.x; i < histSize + 2; i += blockDim.x) + smem[i] = 0; + __syncthreads(); + + unsigned int val = centers[blockIdx.x]; + + float cx = (val & 0xFFFF); + float cy = (val >> 16) & 0xFFFF; + + cx = (cx + 0.5f) * dp; + cy = (cy + 0.5f) * dp; + + for (int i = threadIdx.x; i < count; i += blockDim.x) + { + val = list[i]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + const float rad = ::sqrtf((cx - x) * (cx - x) + (cy - y) * (cy - y)); + if (rad >= minRadius && rad <= maxRadius) + { + const int r = __float2int_rn(rad - minRadius); + + Emulation::smem::atomicAdd(&smem[r + 1], 1); + } + } + + __syncthreads(); + + for (int i = threadIdx.x; i < histSize; i += blockDim.x) + { + const int curVotes = smem[i + 1]; + + if (curVotes >= threshold && curVotes > smem[i] && curVotes >= smem[i + 2]) + { + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxCircles) + circles[ind] = make_float3(cx, cy, i + minRadius); + } + } + } + + int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, + float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(has20 ? 1024 : 512); + const dim3 grid(centersCount); + + const int histSize = maxRadius - minRadius + 1; + size_t smemSize = (histSize + 2) * sizeof(int); + + circlesAccumRadius<<>>(centers, list, count, circles, maxCircles, dp, minRadius, maxRadius, histSize, threshold); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + totalCount = ::min(totalCount, maxCircles); + + return totalCount; + } + } +}}} + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/hough_lines.cu b/modules/gpu/src/cuda/hough_lines.cu new file mode 100644 index 0000000000..2f2fe9a7e2 --- /dev/null +++ b/modules/gpu/src/cuda/hough_lines.cu @@ -0,0 +1,212 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#if !defined CUDA_DISABLER + +#include +#include + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/emulation.hpp" +#include "opencv2/gpu/device/dynamic_smem.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ static int g_counter; + + //////////////////////////////////////////////////////////////////////// + // linesAccum + + __global__ void linesAccumGlobal(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) + { + const int n = blockIdx.x; + const float ang = n * theta; + + float sinVal; + float cosVal; + sincosf(ang, &sinVal, &cosVal); + sinVal *= irho; + cosVal *= irho; + + const int shift = (numrho - 1) / 2; + + int* accumRow = accum.ptr(n + 1); + for (int i = threadIdx.x; i < count; i += blockDim.x) + { + const unsigned int val = list[i]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + int r = __float2int_rn(x * cosVal + y * sinVal); + r += shift; + + ::atomicAdd(accumRow + r + 1, 1); + } + } + + __global__ void linesAccumShared(const unsigned int* list, const int count, PtrStepi accum, const float irho, const float theta, const int numrho) + { + int* smem = DynamicSharedMem(); + + for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) + smem[i] = 0; + + __syncthreads(); + + const int n = blockIdx.x; + const float ang = n * theta; + + float sinVal; + float cosVal; + sincosf(ang, &sinVal, &cosVal); + sinVal *= irho; + cosVal *= irho; + + const int shift = (numrho - 1) / 2; + + for (int i = threadIdx.x; i < count; i += blockDim.x) + { + const unsigned int val = list[i]; + + const int x = (val & 0xFFFF); + const int y = (val >> 16) & 0xFFFF; + + int r = __float2int_rn(x * cosVal + y * sinVal); + r += shift; + + Emulation::smem::atomicAdd(&smem[r + 1], 1); + } + + __syncthreads(); + + int* accumRow = accum.ptr(n + 1); + for (int i = threadIdx.x; i < numrho + 1; i += blockDim.x) + accumRow[i] = smem[i]; + } + + void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20) + { + const dim3 block(has20 ? 1024 : 512); + const dim3 grid(accum.rows - 2); + + size_t smemSize = (accum.cols - 1) * sizeof(int); + + if (smemSize < sharedMemPerBlock - 1000) + linesAccumShared<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); + else + linesAccumGlobal<<>>(list, count, accum, 1.0f / rho, theta, accum.cols - 2); + + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + } + + //////////////////////////////////////////////////////////////////////// + // linesGetResult + + __global__ void linesGetResult(const PtrStepSzi accum, float2* out, int* votes, const int maxSize, const float rho, const float theta, const int threshold, const int numrho) + { + const int r = blockIdx.x * blockDim.x + threadIdx.x; + const int n = blockIdx.y * blockDim.y + threadIdx.y; + + if (r >= accum.cols - 2 || n >= accum.rows - 2) + return; + + const int curVotes = accum(n + 1, r + 1); + + if (curVotes > threshold && + curVotes > accum(n + 1, r) && + curVotes >= accum(n + 1, r + 2) && + curVotes > accum(n, r + 1) && + curVotes >= accum(n + 2, r + 1)) + { + const float radius = (r - (numrho - 1) * 0.5f) * rho; + const float angle = n * theta; + + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxSize) + { + out[ind] = make_float2(radius, angle); + votes[ind] = curVotes; + } + } + } + + int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 8); + const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); + + cudaSafeCall( cudaFuncSetCacheConfig(linesGetResult, cudaFuncCachePreferL1) ); + + linesGetResult<<>>(accum, out, votes, maxSize, rho, theta, threshold, accum.cols - 2); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + totalCount = ::min(totalCount, maxSize); + + if (doSort && totalCount > 0) + { + thrust::device_ptr outPtr(out); + thrust::device_ptr votesPtr(votes); + thrust::sort_by_key(votesPtr, votesPtr + totalCount, outPtr, thrust::greater()); + } + + return totalCount; + } + } +}}} + + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/cuda/hough_segments.cu b/modules/gpu/src/cuda/hough_segments.cu new file mode 100644 index 0000000000..f55bb4de9f --- /dev/null +++ b/modules/gpu/src/cuda/hough_segments.cu @@ -0,0 +1,249 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#if !defined CUDA_DISABLER + +#include "opencv2/gpu/device/common.hpp" +#include "opencv2/gpu/device/vec_math.hpp" + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + __device__ int g_counter; + + texture tex_mask(false, cudaFilterModePoint, cudaAddressModeClamp); + + __global__ void houghLinesProbabilistic(const PtrStepSzi accum, + int4* out, const int maxSize, + const float rho, const float theta, + const int lineGap, const int lineLength, + const int rows, const int cols) + { + const int r = blockIdx.x * blockDim.x + threadIdx.x; + const int n = blockIdx.y * blockDim.y + threadIdx.y; + + if (r >= accum.cols - 2 || n >= accum.rows - 2) + return; + + const int curVotes = accum(n + 1, r + 1); + + if (curVotes >= lineLength && + curVotes > accum(n, r) && + curVotes > accum(n, r + 1) && + curVotes > accum(n, r + 2) && + curVotes > accum(n + 1, r) && + curVotes > accum(n + 1, r + 2) && + curVotes > accum(n + 2, r) && + curVotes > accum(n + 2, r + 1) && + curVotes > accum(n + 2, r + 2)) + { + const float radius = (r - (accum.cols - 2 - 1) * 0.5f) * rho; + const float angle = n * theta; + + float cosa; + float sina; + sincosf(angle, &sina, &cosa); + + float2 p0 = make_float2(cosa * radius, sina * radius); + float2 dir = make_float2(-sina, cosa); + + float2 pb[4] = {make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1), make_float2(-1, -1)}; + float a; + + if (dir.x != 0) + { + a = -p0.x / dir.x; + pb[0].x = 0; + pb[0].y = p0.y + a * dir.y; + + a = (cols - 1 - p0.x) / dir.x; + pb[1].x = cols - 1; + pb[1].y = p0.y + a * dir.y; + } + if (dir.y != 0) + { + a = -p0.y / dir.y; + pb[2].x = p0.x + a * dir.x; + pb[2].y = 0; + + a = (rows - 1 - p0.y) / dir.y; + pb[3].x = p0.x + a * dir.x; + pb[3].y = rows - 1; + } + + if (pb[0].x == 0 && (pb[0].y >= 0 && pb[0].y < rows)) + { + p0 = pb[0]; + if (dir.x < 0) + dir = -dir; + } + else if (pb[1].x == cols - 1 && (pb[0].y >= 0 && pb[0].y < rows)) + { + p0 = pb[1]; + if (dir.x > 0) + dir = -dir; + } + else if (pb[2].y == 0 && (pb[2].x >= 0 && pb[2].x < cols)) + { + p0 = pb[2]; + if (dir.y < 0) + dir = -dir; + } + else if (pb[3].y == rows - 1 && (pb[3].x >= 0 && pb[3].x < cols)) + { + p0 = pb[3]; + if (dir.y > 0) + dir = -dir; + } + + float2 d; + if (::fabsf(dir.x) > ::fabsf(dir.y)) + { + d.x = dir.x > 0 ? 1 : -1; + d.y = dir.y / ::fabsf(dir.x); + } + else + { + d.x = dir.x / ::fabsf(dir.y); + d.y = dir.y > 0 ? 1 : -1; + } + + float2 line_end[2]; + int gap; + bool inLine = false; + + float2 p1 = p0; + if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) + return; + + for (;;) + { + if (tex2D(tex_mask, p1.x, p1.y)) + { + gap = 0; + + if (!inLine) + { + line_end[0] = p1; + line_end[1] = p1; + inLine = true; + } + else + { + line_end[1] = p1; + } + } + else if (inLine) + { + if (++gap > lineGap) + { + bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || + ::abs(line_end[1].y - line_end[0].y) >= lineLength; + + if (good_line) + { + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxSize) + out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); + } + + gap = 0; + inLine = false; + } + } + + p1 = p1 + d; + if (p1.x < 0 || p1.x >= cols || p1.y < 0 || p1.y >= rows) + { + if (inLine) + { + bool good_line = ::abs(line_end[1].x - line_end[0].x) >= lineLength || + ::abs(line_end[1].y - line_end[0].y) >= lineLength; + + if (good_line) + { + const int ind = ::atomicAdd(&g_counter, 1); + if (ind < maxSize) + out[ind] = make_int4(line_end[0].x, line_end[0].y, line_end[1].x, line_end[1].y); + } + + } + break; + } + } + } + } + + int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength) + { + void* counterPtr; + cudaSafeCall( cudaGetSymbolAddress(&counterPtr, g_counter) ); + + cudaSafeCall( cudaMemset(counterPtr, 0, sizeof(int)) ); + + const dim3 block(32, 8); + const dim3 grid(divUp(accum.cols - 2, block.x), divUp(accum.rows - 2, block.y)); + + bindTexture(&tex_mask, mask); + + houghLinesProbabilistic<<>>(accum, + out, maxSize, + rho, theta, + lineGap, lineLength, + mask.rows, mask.cols); + cudaSafeCall( cudaGetLastError() ); + + cudaSafeCall( cudaDeviceSynchronize() ); + + int totalCount; + cudaSafeCall( cudaMemcpy(&totalCount, counterPtr, sizeof(int), cudaMemcpyDeviceToHost) ); + + totalCount = ::min(totalCount, maxSize); + + return totalCount; + } + } +}}} + + +#endif /* CUDA_DISABLER */ diff --git a/modules/gpu/src/hough.cpp b/modules/gpu/src/generalized_hough.cpp similarity index 79% rename from modules/gpu/src/hough.cpp rename to modules/gpu/src/generalized_hough.cpp index 09cf01850e..a92c37d1a5 100644 --- a/modules/gpu/src/hough.cpp +++ b/modules/gpu/src/generalized_hough.cpp @@ -48,16 +48,6 @@ using namespace cv::gpu; #if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) -void cv::gpu::HoughLines(const GpuMat&, GpuMat&, float, float, int, bool, int) { throw_nogpu(); } -void cv::gpu::HoughLines(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, bool, int) { throw_nogpu(); } -void cv::gpu::HoughLinesDownload(const GpuMat&, OutputArray, OutputArray) { throw_nogpu(); } - -void cv::gpu::HoughLinesP(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, int, int) { throw_nogpu(); } - -void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, int, float, float, int, int, int, int, int) { throw_nogpu(); } -void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, HoughCirclesBuf&, int, float, float, int, int, int, int, int) { throw_nogpu(); } -void cv::gpu::HoughCirclesDownload(const GpuMat&, OutputArray) { throw_nogpu(); } - Ptr cv::gpu::GeneralizedHough_GPU::create(int) { throw_nogpu(); return Ptr(); } cv::gpu::GeneralizedHough_GPU::~GeneralizedHough_GPU() {} void cv::gpu::GeneralizedHough_GPU::setTemplate(const GpuMat&, int, Point) { throw_nogpu(); } @@ -77,299 +67,6 @@ namespace cv { namespace gpu { namespace device } }}} -////////////////////////////////////////////////////////// -// HoughLines - -namespace cv { namespace gpu { namespace device -{ - namespace hough - { - void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20); - int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort); - } -}}} - -void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) -{ - HoughLinesBuf buf; - HoughLines(src, lines, buf, rho, theta, threshold, doSort, maxLines); -} - -void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort, int maxLines) -{ - using namespace cv::gpu::device::hough; - - CV_Assert(src.type() == CV_8UC1); - CV_Assert(src.cols < std::numeric_limits::max()); - CV_Assert(src.rows < std::numeric_limits::max()); - - ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); - unsigned int* srcPoints = buf.list.ptr(); - - const int pointsCount = buildPointList_gpu(src, srcPoints); - if (pointsCount == 0) - { - lines.release(); - return; - } - - const int numangle = cvRound(CV_PI / theta); - const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); - CV_Assert(numangle > 0 && numrho > 0); - - ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); - buf.accum.setTo(Scalar::all(0)); - - DeviceInfo devInfo; - linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); - - ensureSizeIsEnough(2, maxLines, CV_32FC2, lines); - - int linesCount = linesGetResult_gpu(buf.accum, lines.ptr(0), lines.ptr(1), maxLines, rho, theta, threshold, doSort); - if (linesCount > 0) - lines.cols = linesCount; - else - lines.release(); -} - -void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_votes_) -{ - if (d_lines.empty()) - { - h_lines_.release(); - if (h_votes_.needed()) - h_votes_.release(); - return; - } - - CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2); - - h_lines_.create(1, d_lines.cols, CV_32FC2); - Mat h_lines = h_lines_.getMat(); - d_lines.row(0).download(h_lines); - - if (h_votes_.needed()) - { - h_votes_.create(1, d_lines.cols, CV_32SC1); - Mat h_votes = h_votes_.getMat(); - GpuMat d_votes(1, d_lines.cols, CV_32SC1, const_cast(d_lines.ptr(1))); - d_votes.download(h_votes); - } -} - -////////////////////////////////////////////////////////// -// HoughLinesP - -namespace cv { namespace gpu { namespace device -{ - namespace hough - { - int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength); - } -}}} - -void cv::gpu::HoughLinesP(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int minLineLength, int maxLineGap, int maxLines) -{ - using namespace cv::gpu::device::hough; - - CV_Assert( src.type() == CV_8UC1 ); - CV_Assert( src.cols < std::numeric_limits::max() ); - CV_Assert( src.rows < std::numeric_limits::max() ); - - ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); - unsigned int* srcPoints = buf.list.ptr(); - - const int pointsCount = buildPointList_gpu(src, srcPoints); - if (pointsCount == 0) - { - lines.release(); - return; - } - - const int numangle = cvRound(CV_PI / theta); - const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); - CV_Assert( numangle > 0 && numrho > 0 ); - - ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); - buf.accum.setTo(Scalar::all(0)); - - DeviceInfo devInfo; - linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); - - ensureSizeIsEnough(1, maxLines, CV_32SC4, lines); - - int linesCount = houghLinesProbabilistic_gpu(src, buf.accum, lines.ptr(), maxLines, rho, theta, maxLineGap, minLineLength); - - if (linesCount > 0) - lines.cols = linesCount; - else - lines.release(); -} - -////////////////////////////////////////////////////////// -// HoughCircles - -namespace cv { namespace gpu { namespace device -{ - namespace hough - { - void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp); - int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold); - int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, - float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20); - } -}}} - -void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) -{ - HoughCirclesBuf buf; - HoughCircles(src, circles, buf, method, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius, maxCircles); -} - -void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, - float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) -{ - using namespace cv::gpu::device::hough; - - CV_Assert(src.type() == CV_8UC1); - CV_Assert(src.cols < std::numeric_limits::max()); - CV_Assert(src.rows < std::numeric_limits::max()); - CV_Assert(method == CV_HOUGH_GRADIENT); - CV_Assert(dp > 0); - CV_Assert(minRadius > 0 && maxRadius > minRadius); - CV_Assert(cannyThreshold > 0); - CV_Assert(votesThreshold > 0); - CV_Assert(maxCircles > 0); - - const float idp = 1.0f / dp; - - cv::gpu::Canny(src, buf.cannyBuf, buf.edges, std::max(cannyThreshold / 2, 1), cannyThreshold); - - ensureSizeIsEnough(2, src.size().area(), CV_32SC1, buf.list); - unsigned int* srcPoints = buf.list.ptr(0); - unsigned int* centers = buf.list.ptr(1); - - const int pointsCount = buildPointList_gpu(buf.edges, srcPoints); - if (pointsCount == 0) - { - circles.release(); - return; - } - - ensureSizeIsEnough(cvCeil(src.rows * idp) + 2, cvCeil(src.cols * idp) + 2, CV_32SC1, buf.accum); - buf.accum.setTo(Scalar::all(0)); - - circlesAccumCenters_gpu(srcPoints, pointsCount, buf.cannyBuf.dx, buf.cannyBuf.dy, buf.accum, minRadius, maxRadius, idp); - - int centersCount = buildCentersList_gpu(buf.accum, centers, votesThreshold); - if (centersCount == 0) - { - circles.release(); - return; - } - - if (minDist > 1) - { - cv::AutoBuffer oldBuf_(centersCount); - cv::AutoBuffer newBuf_(centersCount); - int newCount = 0; - - ushort2* oldBuf = oldBuf_; - ushort2* newBuf = newBuf_; - - cudaSafeCall( cudaMemcpy(oldBuf, centers, centersCount * sizeof(ushort2), cudaMemcpyDeviceToHost) ); - - const int cellSize = cvRound(minDist); - const int gridWidth = (src.cols + cellSize - 1) / cellSize; - const int gridHeight = (src.rows + cellSize - 1) / cellSize; - - std::vector< std::vector > grid(gridWidth * gridHeight); - - const float minDist2 = minDist * minDist; - - for (int i = 0; i < centersCount; ++i) - { - ushort2 p = oldBuf[i]; - - bool good = true; - - int xCell = static_cast(p.x / cellSize); - int yCell = static_cast(p.y / cellSize); - - int x1 = xCell - 1; - int y1 = yCell - 1; - int x2 = xCell + 1; - int y2 = yCell + 1; - - // boundary check - x1 = std::max(0, x1); - y1 = std::max(0, y1); - x2 = std::min(gridWidth - 1, x2); - y2 = std::min(gridHeight - 1, y2); - - for (int yy = y1; yy <= y2; ++yy) - { - for (int xx = x1; xx <= x2; ++xx) - { - vector& m = grid[yy * gridWidth + xx]; - - for(size_t j = 0; j < m.size(); ++j) - { - float dx = (float)(p.x - m[j].x); - float dy = (float)(p.y - m[j].y); - - if (dx * dx + dy * dy < minDist2) - { - good = false; - goto break_out; - } - } - } - } - - break_out: - - if(good) - { - grid[yCell * gridWidth + xCell].push_back(p); - - newBuf[newCount++] = p; - } - } - - cudaSafeCall( cudaMemcpy(centers, newBuf, newCount * sizeof(unsigned int), cudaMemcpyHostToDevice) ); - centersCount = newCount; - } - - ensureSizeIsEnough(1, maxCircles, CV_32FC3, circles); - - const int circlesCount = circlesAccumRadius_gpu(centers, centersCount, srcPoints, pointsCount, circles.ptr(), maxCircles, - dp, minRadius, maxRadius, votesThreshold, deviceSupports(FEATURE_SET_COMPUTE_20)); - - if (circlesCount > 0) - circles.cols = circlesCount; - else - circles.release(); -} - -void cv::gpu::HoughCirclesDownload(const GpuMat& d_circles, cv::OutputArray h_circles_) -{ - if (d_circles.empty()) - { - h_circles_.release(); - return; - } - - CV_Assert(d_circles.rows == 1 && d_circles.type() == CV_32FC3); - - h_circles_.create(1, d_circles.cols, CV_32FC3); - Mat h_circles = h_circles_.getMat(); - d_circles.download(h_circles); -} - -////////////////////////////////////////////////////////// -// GeneralizedHough - namespace cv { namespace gpu { namespace device { namespace hough diff --git a/modules/gpu/src/hough_circles.cpp b/modules/gpu/src/hough_circles.cpp new file mode 100644 index 0000000000..74aa7394f2 --- /dev/null +++ b/modules/gpu/src/hough_circles.cpp @@ -0,0 +1,223 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "precomp.hpp" + +using namespace std; +using namespace cv; +using namespace cv::gpu; + +#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) + +void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, int, float, float, int, int, int, int, int) { throw_nogpu(); } +void cv::gpu::HoughCircles(const GpuMat&, GpuMat&, HoughCirclesBuf&, int, float, float, int, int, int, int, int) { throw_nogpu(); } +void cv::gpu::HoughCirclesDownload(const GpuMat&, OutputArray) { throw_nogpu(); } + +#else /* !defined (HAVE_CUDA) */ + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + int buildPointList_gpu(PtrStepSzb src, unsigned int* list); + } +}}} + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + void circlesAccumCenters_gpu(const unsigned int* list, int count, PtrStepi dx, PtrStepi dy, PtrStepSzi accum, int minRadius, int maxRadius, float idp); + int buildCentersList_gpu(PtrStepSzi accum, unsigned int* centers, int threshold); + int circlesAccumRadius_gpu(const unsigned int* centers, int centersCount, const unsigned int* list, int count, + float3* circles, int maxCircles, float dp, int minRadius, int maxRadius, int threshold, bool has20); + } +}}} + +void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) +{ + HoughCirclesBuf buf; + HoughCircles(src, circles, buf, method, dp, minDist, cannyThreshold, votesThreshold, minRadius, maxRadius, maxCircles); +} + +void cv::gpu::HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, + float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles) +{ + using namespace cv::gpu::device::hough; + + CV_Assert(src.type() == CV_8UC1); + CV_Assert(src.cols < std::numeric_limits::max()); + CV_Assert(src.rows < std::numeric_limits::max()); + CV_Assert(method == CV_HOUGH_GRADIENT); + CV_Assert(dp > 0); + CV_Assert(minRadius > 0 && maxRadius > minRadius); + CV_Assert(cannyThreshold > 0); + CV_Assert(votesThreshold > 0); + CV_Assert(maxCircles > 0); + + const float idp = 1.0f / dp; + + cv::gpu::Canny(src, buf.cannyBuf, buf.edges, std::max(cannyThreshold / 2, 1), cannyThreshold); + + ensureSizeIsEnough(2, src.size().area(), CV_32SC1, buf.list); + unsigned int* srcPoints = buf.list.ptr(0); + unsigned int* centers = buf.list.ptr(1); + + const int pointsCount = buildPointList_gpu(buf.edges, srcPoints); + if (pointsCount == 0) + { + circles.release(); + return; + } + + ensureSizeIsEnough(cvCeil(src.rows * idp) + 2, cvCeil(src.cols * idp) + 2, CV_32SC1, buf.accum); + buf.accum.setTo(Scalar::all(0)); + + circlesAccumCenters_gpu(srcPoints, pointsCount, buf.cannyBuf.dx, buf.cannyBuf.dy, buf.accum, minRadius, maxRadius, idp); + + int centersCount = buildCentersList_gpu(buf.accum, centers, votesThreshold); + if (centersCount == 0) + { + circles.release(); + return; + } + + if (minDist > 1) + { + cv::AutoBuffer oldBuf_(centersCount); + cv::AutoBuffer newBuf_(centersCount); + int newCount = 0; + + ushort2* oldBuf = oldBuf_; + ushort2* newBuf = newBuf_; + + cudaSafeCall( cudaMemcpy(oldBuf, centers, centersCount * sizeof(ushort2), cudaMemcpyDeviceToHost) ); + + const int cellSize = cvRound(minDist); + const int gridWidth = (src.cols + cellSize - 1) / cellSize; + const int gridHeight = (src.rows + cellSize - 1) / cellSize; + + std::vector< std::vector > grid(gridWidth * gridHeight); + + const float minDist2 = minDist * minDist; + + for (int i = 0; i < centersCount; ++i) + { + ushort2 p = oldBuf[i]; + + bool good = true; + + int xCell = static_cast(p.x / cellSize); + int yCell = static_cast(p.y / cellSize); + + int x1 = xCell - 1; + int y1 = yCell - 1; + int x2 = xCell + 1; + int y2 = yCell + 1; + + // boundary check + x1 = std::max(0, x1); + y1 = std::max(0, y1); + x2 = std::min(gridWidth - 1, x2); + y2 = std::min(gridHeight - 1, y2); + + for (int yy = y1; yy <= y2; ++yy) + { + for (int xx = x1; xx <= x2; ++xx) + { + vector& m = grid[yy * gridWidth + xx]; + + for(size_t j = 0; j < m.size(); ++j) + { + float dx = (float)(p.x - m[j].x); + float dy = (float)(p.y - m[j].y); + + if (dx * dx + dy * dy < minDist2) + { + good = false; + goto break_out; + } + } + } + } + + break_out: + + if(good) + { + grid[yCell * gridWidth + xCell].push_back(p); + + newBuf[newCount++] = p; + } + } + + cudaSafeCall( cudaMemcpy(centers, newBuf, newCount * sizeof(unsigned int), cudaMemcpyHostToDevice) ); + centersCount = newCount; + } + + ensureSizeIsEnough(1, maxCircles, CV_32FC3, circles); + + const int circlesCount = circlesAccumRadius_gpu(centers, centersCount, srcPoints, pointsCount, circles.ptr(), maxCircles, + dp, minRadius, maxRadius, votesThreshold, deviceSupports(FEATURE_SET_COMPUTE_20)); + + if (circlesCount > 0) + circles.cols = circlesCount; + else + circles.release(); +} + +void cv::gpu::HoughCirclesDownload(const GpuMat& d_circles, cv::OutputArray h_circles_) +{ + if (d_circles.empty()) + { + h_circles_.release(); + return; + } + + CV_Assert(d_circles.rows == 1 && d_circles.type() == CV_32FC3); + + h_circles_.create(1, d_circles.cols, CV_32FC3); + Mat h_circles = h_circles_.getMat(); + d_circles.download(h_circles); +} + +#endif /* !defined (HAVE_CUDA) */ diff --git a/modules/gpu/src/hough_lines.cpp b/modules/gpu/src/hough_lines.cpp new file mode 100644 index 0000000000..4cc4067b20 --- /dev/null +++ b/modules/gpu/src/hough_lines.cpp @@ -0,0 +1,142 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "precomp.hpp" + +using namespace std; +using namespace cv; +using namespace cv::gpu; + +#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) + +void cv::gpu::HoughLines(const GpuMat&, GpuMat&, float, float, int, bool, int) { throw_nogpu(); } +void cv::gpu::HoughLines(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, bool, int) { throw_nogpu(); } +void cv::gpu::HoughLinesDownload(const GpuMat&, OutputArray, OutputArray) { throw_nogpu(); } + +#else /* !defined (HAVE_CUDA) */ + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + int buildPointList_gpu(PtrStepSzb src, unsigned int* list); + } +}}} + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20); + int linesGetResult_gpu(PtrStepSzi accum, float2* out, int* votes, int maxSize, float rho, float theta, int threshold, bool doSort); + } +}}} + +void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort, int maxLines) +{ + HoughLinesBuf buf; + HoughLines(src, lines, buf, rho, theta, threshold, doSort, maxLines); +} + +void cv::gpu::HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort, int maxLines) +{ + using namespace cv::gpu::device::hough; + + CV_Assert(src.type() == CV_8UC1); + CV_Assert(src.cols < std::numeric_limits::max()); + CV_Assert(src.rows < std::numeric_limits::max()); + + ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); + unsigned int* srcPoints = buf.list.ptr(); + + const int pointsCount = buildPointList_gpu(src, srcPoints); + if (pointsCount == 0) + { + lines.release(); + return; + } + + const int numangle = cvRound(CV_PI / theta); + const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); + CV_Assert(numangle > 0 && numrho > 0); + + ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); + buf.accum.setTo(Scalar::all(0)); + + DeviceInfo devInfo; + linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); + + ensureSizeIsEnough(2, maxLines, CV_32FC2, lines); + + int linesCount = linesGetResult_gpu(buf.accum, lines.ptr(0), lines.ptr(1), maxLines, rho, theta, threshold, doSort); + if (linesCount > 0) + lines.cols = linesCount; + else + lines.release(); +} + +void cv::gpu::HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines_, OutputArray h_votes_) +{ + if (d_lines.empty()) + { + h_lines_.release(); + if (h_votes_.needed()) + h_votes_.release(); + return; + } + + CV_Assert(d_lines.rows == 2 && d_lines.type() == CV_32FC2); + + h_lines_.create(1, d_lines.cols, CV_32FC2); + Mat h_lines = h_lines_.getMat(); + d_lines.row(0).download(h_lines); + + if (h_votes_.needed()) + { + h_votes_.create(1, d_lines.cols, CV_32SC1); + Mat h_votes = h_votes_.getMat(); + GpuMat d_votes(1, d_lines.cols, CV_32SC1, const_cast(d_lines.ptr(1))); + d_votes.download(h_votes); + } +} + +#endif /* !defined (HAVE_CUDA) */ diff --git a/modules/gpu/src/hough_segments.cpp b/modules/gpu/src/hough_segments.cpp new file mode 100644 index 0000000000..c34f33a626 --- /dev/null +++ b/modules/gpu/src/hough_segments.cpp @@ -0,0 +1,110 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "precomp.hpp" + +using namespace std; +using namespace cv; +using namespace cv::gpu; + +#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) + +void cv::gpu::HoughLinesP(const GpuMat&, GpuMat&, HoughLinesBuf&, float, float, int, int, int) { throw_nogpu(); } + +#else /* !defined (HAVE_CUDA) */ + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + int buildPointList_gpu(PtrStepSzb src, unsigned int* list); + } +}}} + +namespace cv { namespace gpu { namespace device +{ + namespace hough + { + void linesAccum_gpu(const unsigned int* list, int count, PtrStepSzi accum, float rho, float theta, size_t sharedMemPerBlock, bool has20); + int houghLinesProbabilistic_gpu(PtrStepSzb mask, PtrStepSzi accum, int4* out, int maxSize, float rho, float theta, int lineGap, int lineLength); + } +}}} + +void cv::gpu::HoughLinesP(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int minLineLength, int maxLineGap, int maxLines) +{ + using namespace cv::gpu::device::hough; + + CV_Assert( src.type() == CV_8UC1 ); + CV_Assert( src.cols < std::numeric_limits::max() ); + CV_Assert( src.rows < std::numeric_limits::max() ); + + ensureSizeIsEnough(1, src.size().area(), CV_32SC1, buf.list); + unsigned int* srcPoints = buf.list.ptr(); + + const int pointsCount = buildPointList_gpu(src, srcPoints); + if (pointsCount == 0) + { + lines.release(); + return; + } + + const int numangle = cvRound(CV_PI / theta); + const int numrho = cvRound(((src.cols + src.rows) * 2 + 1) / rho); + CV_Assert( numangle > 0 && numrho > 0 ); + + ensureSizeIsEnough(numangle + 2, numrho + 2, CV_32SC1, buf.accum); + buf.accum.setTo(Scalar::all(0)); + + DeviceInfo devInfo; + linesAccum_gpu(srcPoints, pointsCount, buf.accum, rho, theta, devInfo.sharedMemPerBlock(), devInfo.supports(FEATURE_SET_COMPUTE_20)); + + ensureSizeIsEnough(1, maxLines, CV_32SC4, lines); + + int linesCount = houghLinesProbabilistic_gpu(src, buf.accum, lines.ptr(), maxLines, rho, theta, maxLineGap, minLineLength); + + if (linesCount > 0) + lines.cols = linesCount; + else + lines.release(); +} + +#endif /* !defined (HAVE_CUDA) */ From e9638d09975935bb11417340a3103b5fb4adcbd0 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 21 Jan 2014 14:35:51 +0400 Subject: [PATCH 002/662] disable CUDA generalized Hough Transform (cherry picked from commit 33d42b740c6fe938b63a0b25c9ad51741aba48c3) --- modules/gpu/src/cuda/generalized_hough.cu | 2 ++ modules/gpu/src/generalized_hough.cpp | 2 ++ modules/gpu/test/test_hough.cpp | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/gpu/src/cuda/generalized_hough.cu b/modules/gpu/src/cuda/generalized_hough.cu index 5e2041eae4..35451e7e23 100644 --- a/modules/gpu/src/cuda/generalized_hough.cu +++ b/modules/gpu/src/cuda/generalized_hough.cu @@ -40,6 +40,8 @@ // //M*/ +#define CUDA_DISABLER + #if !defined CUDA_DISABLER #include diff --git a/modules/gpu/src/generalized_hough.cpp b/modules/gpu/src/generalized_hough.cpp index a92c37d1a5..867ba7ee71 100644 --- a/modules/gpu/src/generalized_hough.cpp +++ b/modules/gpu/src/generalized_hough.cpp @@ -40,6 +40,8 @@ // //M*/ +#define CUDA_DISABLER + #include "precomp.hpp" using namespace std; diff --git a/modules/gpu/test/test_hough.cpp b/modules/gpu/test/test_hough.cpp index f876a7a2b0..6441fc69ab 100644 --- a/modules/gpu/test/test_hough.cpp +++ b/modules/gpu/test/test_hough.cpp @@ -189,7 +189,7 @@ PARAM_TEST_CASE(GeneralizedHough, cv::gpu::DeviceInfo, UseRoi) { }; -GPU_TEST_P(GeneralizedHough, POSITION) +GPU_TEST_P(GeneralizedHough, DISABLED_POSITION) { const cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::gpu::setDevice(devInfo.deviceID()); From d6ba52c3f9f323a2bf6aac2f3f46fadf70be7a6c Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Sat, 18 Jan 2014 23:50:07 +0400 Subject: [PATCH 003/662] Initial Linux packages build rools for CPack. (cherry picked from commit 7821fe2bde331c6b1abd612315ca9fc59da58619) Conflicts: cmake/OpenCVModule.cmake --- CMakeLists.txt | 6 +++ LICENSE | 33 ++++++++++++++ cmake/OpenCVModule.cmake | 6 +-- cmake/OpenCVPackaging.cmake | 89 +++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 LICENSE create mode 100644 cmake/OpenCVPackaging.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d7db8fd130..eb25cd3474 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -975,3 +975,9 @@ ocv_finalize_status() if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") message(WARNING "The source directory is the same as binary directory. \"make clean\" may damage the source tree") endif() + +# ---------------------------------------------------------------------------- +# CPack stuff +# ---------------------------------------------------------------------------- + +include(cmake/OpenCVPackaging.cmake) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..5e32d88b47 --- /dev/null +++ b/LICENSE @@ -0,0 +1,33 @@ +By downloading, copying, installing or using the software you agree to this license. +If you do not agree to this license, do not download, install, +copy or use the software. + + + License Agreement + For Open Source Computer Vision Library + (3-clause BSD License) + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the names of the copyright holders nor the names of the contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +This software is provided by the copyright holders and contributors "as is" and +any express or implied warranties, including, but not limited to, the implied +warranties of merchantability and fitness for a particular purpose are disclaimed. +In no event shall copyright holders or contributors be liable for any direct, +indirect, incidental, special, exemplary, or consequential damages +(including, but not limited to, procurement of substitute goods or services; +loss of use, data, or profits; or business interruption) however caused +and on any theory of liability, whether in contract, strict liability, +or tort (including negligence or otherwise) arising in any way out of +the use of this software, even if advised of the possibility of such damage. diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 3dd749b053..93571684bf 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -577,9 +577,9 @@ macro(ocv_create_module) endif() ocv_install_target(${the_module} EXPORT OpenCVModules - RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main - LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main + RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs + ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT dev ) # only "public" headers need to be installed diff --git a/cmake/OpenCVPackaging.cmake b/cmake/OpenCVPackaging.cmake new file mode 100644 index 0000000000..4a81c255bf --- /dev/null +++ b/cmake/OpenCVPackaging.cmake @@ -0,0 +1,89 @@ +if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") +set(CPACK_set_DESTDIR "on") + +if(NOT OPENCV_CUSTOM_PACKAGE_INFO) + set(CPACK_PACKAGE_DESCRIPTION "Open Computer Vision Library") + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenCV") + set(CPACK_PACKAGE_VENDOR "OpenCV Foundation") + set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") + set(CPACK_PACKAGE_CONTACT "admin@opencv.org") +endif(NOT OPENCV_CUSTOM_PACKAGE_INFO) + +set(CPACK_PACKAGE_VERSION_MAJOR "${OPENCV_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${OPENCV_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${OPENCV_VERSION_PATCH}") + +#arch +if(X86) + set(CPACK_DEBIAN_ARCHITECTURE "i386") + set(CPACK_RPM_PACKAGE_ARCHITECTURE "i686") +elseif(X86_64) + set(CPACK_DEBIAN_ARCHITECTURE "amd64") + set(CPACK_RPM_PACKAGE_ARCHITECTURE "amd64") +elseif(ARM) + set(CPACK_DEBIAN_ARCHITECTURE "armhf") + set(CPACK_RPM_PACKAGE_ARCHITECTURE "armhf") +else() + set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) + set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +endif() + +if(CPACK_GENERATOR STREQUAL "DEB") + set(OPENCV_PACKAGE_ARCH_SUFFIX ${CPACK_DEBIAN_ARCHITECTURE}) +elseif(CPACK_GENERATOR STREQUAL "RPM") + set(OPENCV_PACKAGE_ARCH_SUFFIX ${CPACK_RPM_PACKAGE_ARCHITECTURE}) +else() + set(OPENCV_PACKAGE_ARCH_SUFFIX ${CMAKE_SYSTEM_PROCESSOR}) +endif() + +set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}") +set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-${OPENCV_PACKAGE_ARCH_SUFFIX}") + +#rpm options +set(CPACK_RPM_COMPONENT_INSTALL TRUE) +set(CPACK_RPM_PACKAGE_LICENSE ${CPACK_RESOURCE_FILE_LICENSE}) + +#deb options +set(CPACK_DEB_COMPONENT_INSTALL TRUE) +set(CPACK_DEBIAN_PACKAGE_PRIORITY "extra") + +#depencencies +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE) +set(CPACK_COMPONENT_samples_DEPENDS libs) +set(CPACK_COMPONENT_dev_DEPENDS libs) +set(CPACK_COMPONENT_docs_DEPENDS libs) +set(CPACK_COMPONENT_java_DEPENDS libs) +set(CPACK_COMPONENT_python_DEPENDS libs) + +if(NOT OPENCV_CUSTOM_PACKAGE_INFO) + set(CPACK_COMPONENT_libs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}") + set(CPACK_COMPONENT_libs_DESCRIPTION "Open Computer Vision Library") + + set(CPACK_COMPONENT_python_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-python") + set(CPACK_COMPONENT_python_DESCRIPTION "Python bindings for Open Computer Vision Library") + + set(CPACK_COMPONENT_java_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-java") + set(CPACK_COMPONENT_java_DESCRIPTION "Java bindings for Open Computer Vision Library") + + set(CPACK_COMPONENT_dev_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-dev") + set(CPACK_COMPONENT_dev_DESCRIPTION "Development files for Open Computer Vision Library") + + set(CPACK_COMPONENT_docs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-docs") + set(CPACK_COMPONENT_docs_DESCRIPTION "Documentation for Open Computer Vision Library") + + set(CPACK_COMPONENT_samples_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-samples") + set(CPACK_COMPONENT_samples_DESCRIPTION "Samples for Open Computer Vision Library") +endif(NOT OPENCV_CUSTOM_PACKAGE_INFO) + +if(NOT OPENCV_CUSTOM_PACKAGE_LAYOUT) + set(CPACK_libs_COMPONENT_INSTALL TRUE) + set(CPACK_dev_COMPONENT_INSTALL TRUE) + set(CPACK_docs_COMPONENT_INSTALL TRUE) + set(CPACK_python_COMPONENT_INSTALL TRUE) + set(CPACK_java_COMPONENT_INSTALL TRUE) + set(CPACK_samples_COMPONENT_INSTALL TRUE) +endif(NOT OPENCV_CUSTOM_PACKAGE_LAYOUT) + +include(CPack) + +ENDif(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") \ No newline at end of file From 33f423de043ace86d76dd81fc4f980a25711fc7c Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 23 Jan 2014 20:57:30 +0400 Subject: [PATCH 004/662] Improvements in package build. (cherry picked from commit 086792ec06ff78a45fdd5e1b2fa7f72fe3b7c9a2) --- cmake/OpenCVPackaging.cmake | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/cmake/OpenCVPackaging.cmake b/cmake/OpenCVPackaging.cmake index 4a81c255bf..3b8d4db547 100644 --- a/cmake/OpenCVPackaging.cmake +++ b/cmake/OpenCVPackaging.cmake @@ -2,24 +2,29 @@ if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake") set(CPACK_set_DESTDIR "on") if(NOT OPENCV_CUSTOM_PACKAGE_INFO) - set(CPACK_PACKAGE_DESCRIPTION "Open Computer Vision Library") - set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenCV") + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open Computer Vision Library") + set(CPACK_PACKAGE_DESCRIPTION +"OpenCV (Open Source Computer Vision Library) is an open source computer vision +and machine learning software library. OpenCV was built to provide a common +infrastructure for computer vision applications and to accelerate the use of +machine perception in the commercial products. Being a BSD-licensed product, +OpenCV makes it easy for businesses to utilize and modify the code.") set(CPACK_PACKAGE_VENDOR "OpenCV Foundation") set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") set(CPACK_PACKAGE_CONTACT "admin@opencv.org") + set(CPACK_PACKAGE_VERSION_MAJOR "${OPENCV_VERSION_MAJOR}") + set(CPACK_PACKAGE_VERSION_MINOR "${OPENCV_VERSION_MINOR}") + set(CPACK_PACKAGE_VERSION_PATCH "${OPENCV_VERSION_PATCH}") + set(CPACK_PACKAGE_VERSION "${OPENCV_VCSVERSION}") endif(NOT OPENCV_CUSTOM_PACKAGE_INFO) -set(CPACK_PACKAGE_VERSION_MAJOR "${OPENCV_VERSION_MAJOR}") -set(CPACK_PACKAGE_VERSION_MINOR "${OPENCV_VERSION_MINOR}") -set(CPACK_PACKAGE_VERSION_PATCH "${OPENCV_VERSION_PATCH}") - #arch if(X86) set(CPACK_DEBIAN_ARCHITECTURE "i386") set(CPACK_RPM_PACKAGE_ARCHITECTURE "i686") elseif(X86_64) set(CPACK_DEBIAN_ARCHITECTURE "amd64") - set(CPACK_RPM_PACKAGE_ARCHITECTURE "amd64") + set(CPACK_RPM_PACKAGE_ARCHITECTURE "x86_64") elseif(ARM) set(CPACK_DEBIAN_ARCHITECTURE "armhf") set(CPACK_RPM_PACKAGE_ARCHITECTURE "armhf") @@ -41,11 +46,16 @@ set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENCV_VCSVERSION}-$ #rpm options set(CPACK_RPM_COMPONENT_INSTALL TRUE) -set(CPACK_RPM_PACKAGE_LICENSE ${CPACK_RESOURCE_FILE_LICENSE}) +set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) +set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION}) +set(CPACK_RPM_PACKAGE_URL "http://opencv.org") +set(CPACK_RPM_PACKAGE_LICENSE "BSD") #deb options set(CPACK_DEB_COMPONENT_INSTALL TRUE) -set(CPACK_DEBIAN_PACKAGE_PRIORITY "extra") +set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") +set(CPACK_DEBIAN_PACKAGE_SECTION "libs") +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org") #depencencies set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE) @@ -55,6 +65,13 @@ set(CPACK_COMPONENT_docs_DEPENDS libs) set(CPACK_COMPONENT_java_DEPENDS libs) set(CPACK_COMPONENT_python_DEPENDS libs) +if(HAVE_CUDA) + string(REPLACE "." "-" cuda_version_suffix ${CUDA_VERSION}) + set(CPACK_DEB_libs_PACKAGE_DEPENDS "cuda-core-libs-${cuda_version_suffix}, cuda-extra-libs-${cuda_version_suffix}") + set(CPACK_COMPONENT_dev_DEPENDS libs) + set(CPACK_DEB_dev_PACKAGE_DEPENDS "cuda-headers-${cuda_version_suffix}") +endif() + if(NOT OPENCV_CUSTOM_PACKAGE_INFO) set(CPACK_COMPONENT_libs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}") set(CPACK_COMPONENT_libs_DESCRIPTION "Open Computer Vision Library") From a348f3eeaa3b2a8bb6344cc3de802143cdb26968 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 24 Jan 2014 14:49:56 +0400 Subject: [PATCH 005/662] OpenCV version++ --- modules/core/include/opencv2/core/version.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/version.hpp b/modules/core/include/opencv2/core/version.hpp index 25e5892b6c..3e1ad43746 100644 --- a/modules/core/include/opencv2/core/version.hpp +++ b/modules/core/include/opencv2/core/version.hpp @@ -50,7 +50,7 @@ #define CV_VERSION_EPOCH 2 #define CV_VERSION_MAJOR 4 #define CV_VERSION_MINOR 8 -#define CV_VERSION_REVISION 0 +#define CV_VERSION_REVISION 1 #define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) From 3ebdcafdd37649644dc625ee9492dd60f7b47682 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 17 Jan 2014 16:30:31 +0400 Subject: [PATCH 006/662] All installed files marked with component names for install customization. (cherry picked from commit b75cbfde45c00fc956f033d0af7fe6d63312fd33) Conflicts: cmake/OpenCVModule.cmake --- 3rdparty/libjasper/CMakeLists.txt | 2 +- 3rdparty/libjpeg/CMakeLists.txt | 2 +- 3rdparty/libpng/CMakeLists.txt | 2 +- 3rdparty/libtiff/CMakeLists.txt | 2 +- 3rdparty/openexr/CMakeLists.txt | 2 +- 3rdparty/tbb/CMakeLists.txt | 6 ++--- 3rdparty/zlib/CMakeLists.txt | 2 +- apps/haartraining/CMakeLists.txt | 12 ++++----- apps/traincascade/CMakeLists.txt | 4 +-- cmake/OpenCVDetectAndroidSDK.cmake | 10 +++---- cmake/OpenCVGenAndroidMK.cmake | 2 +- cmake/OpenCVGenConfig.cmake | 26 +++++++++---------- cmake/OpenCVGenHeaders.cmake | 2 +- cmake/OpenCVGenPkgconfig.cmake | 2 +- cmake/OpenCVModule.cmake | 6 ++--- data/CMakeLists.txt | 8 +++--- doc/CMakeLists.txt | 4 +-- include/CMakeLists.txt | 4 +-- modules/androidcamera/CMakeLists.txt | 2 +- .../camera_wrapper/CMakeLists.txt | 2 +- modules/gpu/CMakeLists.txt | 2 +- modules/highgui/CMakeLists.txt | 2 +- modules/java/CMakeLists.txt | 26 +++++++++---------- modules/python/CMakeLists.txt | 12 ++++----- platforms/android/libinfo/CMakeLists.txt | 2 +- platforms/android/package/CMakeLists.txt | 2 +- platforms/android/service/CMakeLists.txt | 2 +- samples/c/CMakeLists.txt | 4 +-- samples/cpp/CMakeLists.txt | 4 +-- samples/gpu/CMakeLists.txt | 4 +-- samples/gpu/performance/CMakeLists.txt | 2 +- samples/ocl/CMakeLists.txt | 4 +-- 32 files changed, 84 insertions(+), 84 deletions(-) diff --git a/3rdparty/libjasper/CMakeLists.txt b/3rdparty/libjasper/CMakeLists.txt index dda9cd2556..7b3dcb08a5 100644 --- a/3rdparty/libjasper/CMakeLists.txt +++ b/3rdparty/libjasper/CMakeLists.txt @@ -46,5 +46,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/libjpeg/CMakeLists.txt b/3rdparty/libjpeg/CMakeLists.txt index 8d622f24ff..02d71ade2b 100644 --- a/3rdparty/libjpeg/CMakeLists.txt +++ b/3rdparty/libjpeg/CMakeLists.txt @@ -39,5 +39,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${JPEG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/libpng/CMakeLists.txt b/3rdparty/libpng/CMakeLists.txt index 42b6263e52..8d3d5f4976 100644 --- a/3rdparty/libpng/CMakeLists.txt +++ b/3rdparty/libpng/CMakeLists.txt @@ -55,5 +55,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${PNG_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index 6c34fb5e34..addbb5551c 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -115,5 +115,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${TIFF_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/3rdparty/openexr/CMakeLists.txt b/3rdparty/openexr/CMakeLists.txt index 2b11436e1d..c4facad2fc 100644 --- a/3rdparty/openexr/CMakeLists.txt +++ b/3rdparty/openexr/CMakeLists.txt @@ -62,7 +62,7 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(IlmImf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(IlmImf EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() set(OPENEXR_INCLUDE_PATHS ${OPENEXR_INCLUDE_PATHS} PARENT_SCOPE) diff --git a/3rdparty/tbb/CMakeLists.txt b/3rdparty/tbb/CMakeLists.txt index 272c195b36..e16f6cd38d 100644 --- a/3rdparty/tbb/CMakeLists.txt +++ b/3rdparty/tbb/CMakeLists.txt @@ -248,9 +248,9 @@ if(ENABLE_SOLUTION_FOLDERS) endif() ocv_install_target(tbb EXPORT OpenCVModules - RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main - LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main + RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs + ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev ) # get TBB version diff --git a/3rdparty/zlib/CMakeLists.txt b/3rdparty/zlib/CMakeLists.txt index f1b28fd396..410f2420bf 100644 --- a/3rdparty/zlib/CMakeLists.txt +++ b/3rdparty/zlib/CMakeLists.txt @@ -95,5 +95,5 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(NOT BUILD_SHARED_LIBS) - ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + ocv_install_target(${ZLIB_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) endif() diff --git a/apps/haartraining/CMakeLists.txt b/apps/haartraining/CMakeLists.txt index cdc280556e..d8a3c55c8d 100644 --- a/apps/haartraining/CMakeLists.txt +++ b/apps/haartraining/CMakeLists.txt @@ -71,14 +71,14 @@ set_target_properties(opencv_performance PROPERTIES if(INSTALL_CREATE_DISTRIB) if(BUILD_SHARED_LIBS) - install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) - install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) - install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) + install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) + install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) + install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) endif() else() - install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) - install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) - install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) + install(TARGETS opencv_haartraining RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) + install(TARGETS opencv_createsamples RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) + install(TARGETS opencv_performance RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) endif() if(ENABLE_SOLUTION_FOLDERS) diff --git a/apps/traincascade/CMakeLists.txt b/apps/traincascade/CMakeLists.txt index 8f6fbe0348..941c0ec711 100644 --- a/apps/traincascade/CMakeLists.txt +++ b/apps/traincascade/CMakeLists.txt @@ -35,8 +35,8 @@ endif() if(INSTALL_CREATE_DISTRIB) if(BUILD_SHARED_LIBS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT dev) endif() else() - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT dev) endif() diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index 393dbb62d2..7a37051e49 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -344,20 +344,20 @@ macro(add_android_project target path) add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${android_proj_bin_dir}/bin/${target}-debug.apk" "${OpenCV_BINARY_DIR}/bin/${target}.apk") if(INSTALL_ANDROID_EXAMPLES AND "${target}" MATCHES "^example-") #apk - install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT main) + install(FILES "${OpenCV_BINARY_DIR}/bin/${target}.apk" DESTINATION "samples" COMPONENT samples) 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) + install(FILES "${android_proj_bin_dir}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT samples) endforeach() #jni part + eclipse files file(GLOB_RECURSE jni_files RELATIVE "${path}" "${path}/jni/*" "${path}/.cproject") ocv_list_filterout(jni_files "\\\\.svn") foreach(f ${jni_files} ".classpath" ".project" ".settings/org.eclipse.jdt.core.prefs") get_filename_component(install_subdir "${f}" PATH) - install(FILES "${path}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT main) + install(FILES "${path}/${f}" DESTINATION "samples/${sample_dir}/${install_subdir}" COMPONENT samples) endforeach() #update proj if(android_proj_lib_deps_commands) @@ -365,9 +365,9 @@ macro(add_android_project target path) endif() install(CODE "EXECUTE_PROCESS(COMMAND ${ANDROID_EXECUTABLE} --silent update project --path . --target \"${android_proj_sdk_target}\" --name \"${target}\" ${inst_lib_opt} WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}\" - )" COMPONENT main) + )" COMPONENT dev) #empty 'gen' - install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT main) + install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT samples) endif() endif() endmacro() diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake index eed47652b4..45193a2732 100644 --- a/cmake/OpenCVGenAndroidMK.cmake +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -116,5 +116,5 @@ if(ANDROID) set(OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE "\$(OPENCV_THIS_DIR)/../3rdparty/libs/\$(OPENCV_TARGET_ARCH_ABI)") configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCV.mk.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk" IMMEDIATE @ONLY) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCV.mk DESTINATION ${OPENCV_CONFIG_INSTALL_PATH} COMPONENT dev) endif(ANDROID) diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake index 411d22582d..18411e8786 100644 --- a/cmake/OpenCVGenConfig.cmake +++ b/cmake/OpenCVGenConfig.cmake @@ -109,18 +109,18 @@ if(UNIX) # ANDROID configuration is created here also # /(share|lib)/*/ (U) # /(share|lib)/*/(cmake|CMake)/ (U) if(INSTALL_TO_MANGLED_PATHS) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/) - install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ COMPONENT dev) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) else() - install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/) - install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) endif() endif() if(ANDROID) - install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/) + install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev) endif() # -------------------------------------------------------------------------------------------- @@ -134,12 +134,12 @@ if(WIN32) configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY) configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY) if(BUILD_SHARED_LIBS) - install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib") - install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) else() - install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib") - install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" FILE OpenCVModules${modules_file_suffix}.cmake) + install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" COMPONENT dev) + install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev) endif() - install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}") - install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/") + install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT dev) + install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/" COMPONENT dev) endif() diff --git a/cmake/OpenCVGenHeaders.cmake b/cmake/OpenCVGenHeaders.cmake index 35da0fb4be..c892a929c2 100644 --- a/cmake/OpenCVGenHeaders.cmake +++ b/cmake/OpenCVGenHeaders.cmake @@ -23,4 +23,4 @@ set(OPENCV_MODULE_DEFINITIONS_CONFIGMAKE "${OPENCV_MODULE_DEFINITIONS_CONFIGMAKE #endforeach() configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv_modules.hpp.in" "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp") -install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 COMPONENT main) +install(FILES "${OPENCV_CONFIG_FILE_INCLUDE_DIR}/opencv2/opencv_modules.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 COMPONENT dev) diff --git a/cmake/OpenCVGenPkgconfig.cmake b/cmake/OpenCVGenPkgconfig.cmake index cd54f11bf3..13b1e44970 100644 --- a/cmake/OpenCVGenPkgconfig.cmake +++ b/cmake/OpenCVGenPkgconfig.cmake @@ -81,5 +81,5 @@ configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in" @ONLY IMMEDIATE) if(UNIX AND NOT ANDROID) - install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig) + install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev) endif() diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 93571684bf..6734462fc2 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -587,7 +587,7 @@ macro(ocv_create_module) foreach(hdr ${OPENCV_MODULE_${the_module}_HEADERS}) string(REGEX REPLACE "^.*opencv2/" "opencv2/" hdr2 "${hdr}") if(hdr2 MATCHES "^(opencv2/.*)/[^/]+.h(..)?$") - install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT main) + install(FILES ${hdr} DESTINATION "${OPENCV_INCLUDE_INSTALL_PATH}/${CMAKE_MATCH_1}" COMPONENT dev) endif() endforeach() endif() @@ -795,7 +795,7 @@ function(ocv_add_samples) endif() if(WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "samples/${module_id}" COMPONENT samples) endif() endforeach() endif() @@ -805,7 +805,7 @@ function(ocv_add_samples) file(GLOB sample_files "${samples_path}/*") install(FILES ${sample_files} DESTINATION share/OpenCV/samples/${module_id} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() endfunction() diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 70efd6fd03..48094df402 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -2,9 +2,9 @@ file(GLOB HAAR_CASCADES haarcascades/*.xml) file(GLOB LBP_CASCADES lbpcascades/*.xml) if(ANDROID) - install(FILES ${HAAR_CASCADES} DESTINATION sdk/etc/haarcascades COMPONENT main) - install(FILES ${LBP_CASCADES} DESTINATION sdk/etc/lbpcascades COMPONENT main) + install(FILES ${HAAR_CASCADES} DESTINATION sdk/etc/haarcascades COMPONENT libs) + install(FILES ${LBP_CASCADES} DESTINATION sdk/etc/lbpcascades COMPONENT libs) elseif(NOT WIN32) - install(FILES ${HAAR_CASCADES} DESTINATION share/OpenCV/haarcascades COMPONENT main) - install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT main) + install(FILES ${HAAR_CASCADES} DESTINATION share/OpenCV/haarcascades COMPONENT libs) + install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT libs) endif() diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 5793f7298b..3557a2bd2c 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -143,11 +143,11 @@ if(BUILD_DOCS AND HAVE_SPHINX) endif() foreach(f ${DOC_LIST}) - install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" COMPONENT main) + install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" COMPONENT docs) endforeach() foreach(f ${OPTIONAL_DOC_LIST}) - install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" OPTIONAL) + install(FILES "${f}" DESTINATION "${OPENCV_DOC_INSTALL_PATH}" OPTIONAL COMPONENT docs) endforeach() endif() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index ed3b85a8fc..b4e48e6fa7 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,7 +1,7 @@ file(GLOB old_hdrs "opencv/*.h*") install(FILES ${old_hdrs} DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv - COMPONENT main) + COMPONENT dev) install(FILES "opencv2/opencv.hpp" DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2 - COMPONENT main) + COMPONENT dev) diff --git a/modules/androidcamera/CMakeLists.txt b/modules/androidcamera/CMakeLists.txt index 8ac8ced88e..3858ba9f6d 100644 --- a/modules/androidcamera/CMakeLists.txt +++ b/modules/androidcamera/CMakeLists.txt @@ -40,6 +40,6 @@ else() get_filename_component(wrapper_name "${wrapper}" NAME) install(FILES "${LIBRARY_OUTPUT_PATH}/${wrapper_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} - COMPONENT main) + COMPONENT libs) endforeach() endif() diff --git a/modules/androidcamera/camera_wrapper/CMakeLists.txt b/modules/androidcamera/camera_wrapper/CMakeLists.txt index 21b9ee1ad2..bc5585a7a8 100644 --- a/modules/androidcamera/camera_wrapper/CMakeLists.txt +++ b/modules/androidcamera/camera_wrapper/CMakeLists.txt @@ -63,4 +63,4 @@ if (NOT (CMAKE_BUILD_TYPE MATCHES "debug")) endif() -install(TARGETS ${the_target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) +install(TARGETS ${the_target} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs) diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 9171febc74..6de3e0efab 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -82,7 +82,7 @@ ocv_create_module(${cuda_link_libs}) if(HAVE_CUDA) install(FILES src/nvidia/NPP_staging/NPP_staging.hpp src/nvidia/core/NCV.hpp DESTINATION ${OPENCV_INCLUDE_INSTALL_PATH}/opencv2/${name} - COMPONENT main) + COMPONENT dev) endif() ocv_add_precompiled_headers(${the_module}) diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index fd2eec6a1e..7d2547bcff 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -315,7 +315,7 @@ if(WIN32 AND WITH_FFMPEG) COMMENT "Copying ${ffmpeg_path} to the output directory") endif() - install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT main RENAME "${ffmpeg_bare_name_ver}") + install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs RENAME "${ffmpeg_bare_name_ver}") endif() ocv_add_accuracy_tests() diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 3a6ebe8362..198048ebe2 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -175,7 +175,7 @@ foreach(java_file ${step3_input_files}) if(ANDROID) get_filename_component(install_subdir "${java_file_name}" PATH) - install(FILES "${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/org/opencv/${install_subdir}" COMPONENT main) + install(FILES "${output_name}" DESTINATION "${JAVA_INSTALL_ROOT}/src/org/opencv/${install_subdir}" COMPONENT java) endif() endforeach() @@ -189,7 +189,7 @@ if(ANDROID) if(NOT file MATCHES "jni/.+") get_filename_component(install_subdir "${file}" PATH) - install(FILES "${OpenCV_BINARY_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT main) + install(FILES "${OpenCV_BINARY_DIR}/${file}" DESTINATION "${JAVA_INSTALL_ROOT}/${install_subdir}" COMPONENT java) endif() endforeach() @@ -225,11 +225,11 @@ if(ANDROID AND ANDROID_EXECUTABLE) list(APPEND copied_files ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}") list(APPEND step3_input_files "${CMAKE_CURRENT_BINARY_DIR}/${ANDROID_MANIFEST_FILE}") - install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main) - install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT main) + install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_PROJECT_PROPERTIES_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT java) + install(FILES "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}" DESTINATION ${JAVA_INSTALL_ROOT} COMPONENT java) # creating empty 'gen' and 'res' folders - install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/gen\")" COMPONENT main) - install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/res\")" COMPONENT main) + install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/gen\")" COMPONENT java) + install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${JAVA_INSTALL_ROOT}/res\")" COMPONENT java) endif(ANDROID AND ANDROID_EXECUTABLE) set(step3_depends ${step2_depends} ${step3_input_files} ${copied_files}) @@ -282,7 +282,7 @@ else(ANDROID) else(WIN32) set(JAR_INSTALL_DIR share/OpenCV/java) endif(WIN32) - install(FILES ${JAR_FILE} DESTINATION ${JAR_INSTALL_DIR} COMPONENT main) + install(FILES ${JAR_FILE} DESTINATION ${JAR_INSTALL_DIR} COMPONENT java) endif(ANDROID) # step 5: build native part @@ -353,17 +353,17 @@ endif() if(ANDROID) ocv_install_target(${the_module} EXPORT OpenCVModules - LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main - ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) + LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT java + ARCHIVE DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT java) else() if(NOT INSTALL_CREATE_DISTRIB) ocv_install_target(${the_module} EXPORT OpenCVModules - RUNTIME DESTINATION ${JAR_INSTALL_DIR} COMPONENT main - LIBRARY DESTINATION ${JAR_INSTALL_DIR} COMPONENT main) + RUNTIME DESTINATION ${JAR_INSTALL_DIR} COMPONENT java + LIBRARY DESTINATION ${JAR_INSTALL_DIR} COMPONENT java) else() ocv_install_target(${the_module} EXPORT OpenCVModules - RUNTIME DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT main - LIBRARY DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT main) + RUNTIME DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT java + LIBRARY DESTINATION ${JAR_INSTALL_DIR}/${OpenCV_ARCH} COMPONENT java) endif() endif() diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index 2c44a3906d..bab8b061b3 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -108,17 +108,17 @@ endif() if(WIN32) set(PYTHON_INSTALL_ARCHIVE "") else() - set(PYTHON_INSTALL_ARCHIVE ARCHIVE DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main) + set(PYTHON_INSTALL_ARCHIVE ARCHIVE DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python) endif() if(NOT INSTALL_CREATE_DISTRIB) install(TARGETS ${the_module} ${PYTHON_INSTALL_CONFIGURATIONS} - RUNTIME DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main - LIBRARY DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main + RUNTIME DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python + LIBRARY DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python ${PYTHON_INSTALL_ARCHIVE} ) - install(FILES src2/cv.py ${PYTHON_INSTALL_CONFIGURATIONS} DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main) + install(FILES src2/cv.py ${PYTHON_INSTALL_CONFIGURATIONS} DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT python) else() if(DEFINED PYTHON_VERSION_MAJOR) set(__ver "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") @@ -127,7 +127,7 @@ else() endif() install(TARGETS ${the_module} CONFIGURATIONS Release - RUNTIME DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT main - LIBRARY DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT main + RUNTIME DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT python + LIBRARY DESTINATION python/${__ver}/${OpenCV_ARCH} COMPONENT python ) endif() diff --git a/platforms/android/libinfo/CMakeLists.txt b/platforms/android/libinfo/CMakeLists.txt index 028413ec6e..55dd278594 100644 --- a/platforms/android/libinfo/CMakeLists.txt +++ b/platforms/android/libinfo/CMakeLists.txt @@ -36,4 +36,4 @@ set_target_properties(${the_module} PROPERTIES ) get_filename_component(lib_name "libopencv_info.so" NAME) -install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) +install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT libs) diff --git a/platforms/android/package/CMakeLists.txt b/platforms/android/package/CMakeLists.txt index 1382a078cf..b48a55a6a1 100644 --- a/platforms/android/package/CMakeLists.txt +++ b/platforms/android/package/CMakeLists.txt @@ -89,6 +89,6 @@ add_custom_command( DEPENDS "${OpenCV_BINARY_DIR}/bin/classes.jar.dephelper" "${PACKAGE_DIR}/res/values/strings.xml" "${PACKAGE_DIR}/res/drawable/icon.png" ${camera_wrappers} opencv_java ) -install(FILES "${APK_NAME}" DESTINATION "apk/" COMPONENT main) +install(FILES "${APK_NAME}" DESTINATION "apk/" COMPONENT libs) add_custom_target(android_package ALL SOURCES "${APK_NAME}" ) add_dependencies(android_package opencv_java) diff --git a/platforms/android/service/CMakeLists.txt b/platforms/android/service/CMakeLists.txt index dde1455138..c99b71392f 100644 --- a/platforms/android/service/CMakeLists.txt +++ b/platforms/android/service/CMakeLists.txt @@ -3,4 +3,4 @@ if(BUILD_ANDROID_SERVICE) #add_subdirectory(engine_test) endif() -install(FILES "readme.txt" DESTINATION "apk/" COMPONENT main) +install(FILES "readme.txt" DESTINATION "apk/" COMPONENT libs) diff --git a/samples/c/CMakeLists.txt b/samples/c/CMakeLists.txt index 77a42949d0..ab6e15dbf2 100644 --- a/samples/c/CMakeLists.txt +++ b/samples/c/CMakeLists.txt @@ -39,7 +39,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() install(TARGETS ${the_target} - RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/c" COMPONENT main) + RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/c" COMPONENT samples) endif() ENDMACRO() @@ -55,5 +55,5 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${C_SAMPLES} DESTINATION share/OpenCV/samples/c - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif () diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index ebee5bd0a8..e0842d9e4a 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -68,7 +68,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() install(TARGETS ${the_target} - RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT main) + RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${sample_subfolder}" COMPONENT samples) endif() ENDMACRO() @@ -92,5 +92,5 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${C_SAMPLES} DESTINATION share/OpenCV/samples/cpp - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 732a9172a5..7093cf5d19 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -65,7 +65,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) if(MSVC AND NOT BUILD_SHARED_LIBS) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) endif() ENDMACRO() @@ -84,5 +84,5 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${install_list} DESTINATION share/OpenCV/samples/${project} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index 8f3caac5b3..0b2346f91f 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -23,7 +23,7 @@ if(ENABLE_SOLUTION_FOLDERS) endif() if(WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/gpu" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/gpu" COMPONENT samples) endif() if(INSTALL_C_EXAMPLES AND NOT WIN32) diff --git a/samples/ocl/CMakeLists.txt b/samples/ocl/CMakeLists.txt index 8db77d52c8..4139211000 100644 --- a/samples/ocl/CMakeLists.txt +++ b/samples/ocl/CMakeLists.txt @@ -38,7 +38,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) if(MSVC AND NOT BUILD_SHARED_LIBS) set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG") endif() - install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT main) + install(TARGETS ${the_target} RUNTIME DESTINATION "${OPENCV_SAMPLES_BIN_INSTALL_PATH}/${project}" COMPONENT samples) endif() ENDMACRO() @@ -55,5 +55,5 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) install(FILES ${install_list} DESTINATION share/OpenCV/samples/${project} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() From 6cf7d6ef4e0259bdf0bd9fd6612a5324242093bd Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 27 Jan 2014 14:20:30 +0400 Subject: [PATCH 007/662] OpenCV C/C++/OCL/CUDA samples install path fixed. Install rools for tests added. (cherry picked from commit f332cba14b2a86017e1d2081130db110c2048c00) --- CMakeLists.txt | 2 +- cmake/OpenCVModule.cmake | 15 +++++++++++++++ cmake/OpenCVPackaging.cmake | 22 +++++++++++++++++----- cmake/templates/postinst | 3 +++ data/CMakeLists.txt | 8 ++++++++ samples/c/CMakeLists.txt | 12 +++++++++--- samples/cpp/CMakeLists.txt | 12 +++++++++--- samples/gpu/CMakeLists.txt | 12 +++++++++--- samples/gpu/performance/CMakeLists.txt | 3 ++- samples/ocl/CMakeLists.txt | 12 +++++++++--- 10 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 cmake/templates/postinst diff --git a/CMakeLists.txt b/CMakeLists.txt index eb25cd3474..2adc320435 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,7 @@ OCV_OPTION(INSTALL_C_EXAMPLES "Install C examples" OFF ) OCV_OPTION(INSTALL_PYTHON_EXAMPLES "Install Python examples" OFF ) OCV_OPTION(INSTALL_ANDROID_EXAMPLES "Install Android examples" OFF IF ANDROID ) OCV_OPTION(INSTALL_TO_MANGLED_PATHS "Enables mangled install paths, that help with side by side installs." OFF IF (UNIX AND NOT ANDROID AND NOT IOS AND BUILD_SHARED_LIBS) ) - +OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binaries and test data" OFF) # OpenCV build options # =================================================== diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 6734462fc2..0e1ee250e7 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -711,6 +711,13 @@ function(ocv_add_perf_tests) else(OCV_DEPENDENCIES_FOUND) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) + if(INSTALL_TESTS) + if(ANDROID) + install(TARGETS ${the_target} RUNTIME DESTINATION sdk/etc/bin COMPONENT tests) + elseif(NOT WIN32) + install(TARGETS ${the_target} RUNTIME DESTINATION share/OpenCV/bin COMPONENT tests) + endif() + endif() endif() endfunction() @@ -764,6 +771,14 @@ function(ocv_add_accuracy_tests) else(OCV_DEPENDENCIES_FOUND) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) + + if(INSTALL_TESTS) + if(ANDROID) + install(TARGETS ${the_target} RUNTIME DESTINATION sdk/etc/bin COMPONENT tests) + elseif(NOT WIN32) + install(TARGETS ${the_target} RUNTIME DESTINATION share/OpenCV/bin COMPONENT tests) + endif() + endif() endif() endfunction() diff --git a/cmake/OpenCVPackaging.cmake b/cmake/OpenCVPackaging.cmake index 3b8d4db547..32d5c5da7f 100644 --- a/cmake/OpenCVPackaging.cmake +++ b/cmake/OpenCVPackaging.cmake @@ -56,6 +56,12 @@ set(CPACK_DEB_COMPONENT_INSTALL TRUE) set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") set(CPACK_DEBIAN_PACKAGE_SECTION "libs") set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org") +if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) + set(prefix "${CMAKE_INSTALL_PREFIX}") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/postinst" + "${CMAKE_BINARY_DIR}/junk/postinst" @ONLY IMMEDIATE) + set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/junk/postinst") +endif() #depencencies set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE) @@ -64,6 +70,9 @@ set(CPACK_COMPONENT_dev_DEPENDS libs) set(CPACK_COMPONENT_docs_DEPENDS libs) set(CPACK_COMPONENT_java_DEPENDS libs) set(CPACK_COMPONENT_python_DEPENDS libs) +if(INSTALL_TESTS) +set(CPACK_COMPONENT_tests_DEPENDS libs) +endif() if(HAVE_CUDA) string(REPLACE "." "-" cuda_version_suffix ${CUDA_VERSION}) @@ -77,19 +86,22 @@ if(NOT OPENCV_CUSTOM_PACKAGE_INFO) set(CPACK_COMPONENT_libs_DESCRIPTION "Open Computer Vision Library") set(CPACK_COMPONENT_python_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-python") - set(CPACK_COMPONENT_python_DESCRIPTION "Python bindings for Open Computer Vision Library") + set(CPACK_COMPONENT_python_DESCRIPTION "Python bindings for Open Source Computer Vision Library") set(CPACK_COMPONENT_java_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-java") - set(CPACK_COMPONENT_java_DESCRIPTION "Java bindings for Open Computer Vision Library") + set(CPACK_COMPONENT_java_DESCRIPTION "Java bindings for Open Source Computer Vision Library") set(CPACK_COMPONENT_dev_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-dev") - set(CPACK_COMPONENT_dev_DESCRIPTION "Development files for Open Computer Vision Library") + set(CPACK_COMPONENT_dev_DESCRIPTION "Development files for Open Source Computer Vision Library") set(CPACK_COMPONENT_docs_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-docs") - set(CPACK_COMPONENT_docs_DESCRIPTION "Documentation for Open Computer Vision Library") + set(CPACK_COMPONENT_docs_DESCRIPTION "Documentation for Open Source Computer Vision Library") set(CPACK_COMPONENT_samples_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-samples") - set(CPACK_COMPONENT_samples_DESCRIPTION "Samples for Open Computer Vision Library") + set(CPACK_COMPONENT_samples_DESCRIPTION "Samples for Open Source Computer Vision Library") + + set(CPACK_COMPONENT_tests_DISPLAY_NAME "lib${CMAKE_PROJECT_NAME}-tests") + set(CPACK_COMPONENT_tests_DESCRIPTION "Accuracy and performance tests for Open Source Computer Vision Library") endif(NOT OPENCV_CUSTOM_PACKAGE_INFO) if(NOT OPENCV_CUSTOM_PACKAGE_LAYOUT) diff --git a/cmake/templates/postinst b/cmake/templates/postinst new file mode 100644 index 0000000000..f6763781b6 --- /dev/null +++ b/cmake/templates/postinst @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "export OPENCV_TEST_DATA_PATH=@prefix@/share/OpenCV/testdata" >> /etc/profile \ No newline at end of file diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 48094df402..726fc0d10d 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -8,3 +8,11 @@ elseif(NOT WIN32) install(FILES ${HAAR_CASCADES} DESTINATION share/OpenCV/haarcascades COMPONENT libs) install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT libs) endif() + +if (OPENCV_TEST_DATA_PATH) + if(ANDROID) + install(FILES ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests) + elseif(NOT WIN32) + install(FILES ${OPENCV_TEST_DATA_PATH} DESTINATION share/OpenCV/testdata COMPONENT tests) + endif() +endif() \ No newline at end of file diff --git a/samples/c/CMakeLists.txt b/samples/c/CMakeLists.txt index ab6e15dbf2..aca8886f09 100644 --- a/samples/c/CMakeLists.txt +++ b/samples/c/CMakeLists.txt @@ -53,7 +53,13 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${C_SAMPLES} - DESTINATION share/OpenCV/samples/c - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + if (ANDROID) + install(FILES ${C_SAMPLES} + DESTINATION samples/native/c + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + else() + install(FILES ${C_SAMPLES} + DESTINATION share/OpenCV/samples/c + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + endif() endif () diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index e0842d9e4a..6ccc75a747 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -90,7 +90,13 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${C_SAMPLES} - DESTINATION share/OpenCV/samples/cpp - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + if (ANDROID) + install(FILES ${C_SAMPLES} + DESTINATION samples/native/cpp + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + else() + install(FILES ${C_SAMPLES} + DESTINATION share/OpenCV/samples/cpp + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + endif() endif() diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 7093cf5d19..226869aaa1 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -82,7 +82,13 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${install_list} - DESTINATION share/OpenCV/samples/${project} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + if(ANDROID) + install(FILES ${install_list} + DESTINATION samples/native/gpu + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + else() + install(FILES ${install_list} + DESTINATION share/OpenCV/samples/gpu + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + endif() endif() diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index 0b2346f91f..32dc002aec 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -30,5 +30,6 @@ if(INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB GPU_FILES performance/*.cpp performance/*.h) install(FILES ${GPU_FILES} DESTINATION share/OpenCV/samples/gpu/performance - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + COMPONENT samples) endif() diff --git a/samples/ocl/CMakeLists.txt b/samples/ocl/CMakeLists.txt index 4139211000..8889452a01 100644 --- a/samples/ocl/CMakeLists.txt +++ b/samples/ocl/CMakeLists.txt @@ -53,7 +53,13 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - install(FILES ${install_list} - DESTINATION share/OpenCV/samples/${project} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + if(ANDROID) + install(FILES ${install_list} + DESTINATION samples/native/ocl + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + else() + install(FILES ${install_list} + DESTINATION share/OpenCV/samples/ocl + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) + endif() endif() From 00d555f051cdf5ef4944daa8088bf25c19bc3773 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Mon, 27 Jan 2014 17:57:11 +0400 Subject: [PATCH 008/662] Code review notes fixed. Env setup for testing package implemented using /etc/profile.d; Variable with path for all native samples added; Path for test binaries and test data updated. (cherry picked from commit 39201e68e2649955f40936a1d07f2d1c64c560f5) --- CMakeLists.txt | 3 +++ cmake/OpenCVModule.cmake | 14 +++----------- cmake/OpenCVPackaging.cmake | 8 +++----- cmake/templates/postinst | 3 --- samples/c/CMakeLists.txt | 12 +++--------- samples/cpp/CMakeLists.txt | 12 +++--------- samples/gpu/CMakeLists.txt | 12 +++--------- samples/gpu/performance/CMakeLists.txt | 2 +- samples/ocl/CMakeLists.txt | 12 +++--------- 9 files changed, 22 insertions(+), 56 deletions(-) delete mode 100644 cmake/templates/postinst diff --git a/CMakeLists.txt b/CMakeLists.txt index 2adc320435..752c991b0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -283,6 +283,7 @@ if(ANDROID) set(OPENCV_3P_LIB_INSTALL_PATH sdk/native/3rdparty/libs/${ANDROID_NDK_ABI_NAME}) set(OPENCV_CONFIG_INSTALL_PATH sdk/native/jni) set(OPENCV_INCLUDE_INSTALL_PATH sdk/native/jni/include) + set(OPENCV_SAMPLES_SRC_INSTALL_PATH samples/native) else() set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib") set(3P_LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/3rdparty/lib${LIB_SUFFIX}") @@ -293,9 +294,11 @@ else() set(OPENCV_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}lib${LIB_SUFFIX}") endif() set(OPENCV_3P_LIB_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib${LIB_SUFFIX}") + set(OPENCV_SAMPLES_SRC_INSTALL_PATH samples/native) else() set(OPENCV_LIB_INSTALL_PATH lib${LIB_SUFFIX}) set(OPENCV_3P_LIB_INSTALL_PATH share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}) + set(OPENCV_SAMPLES_SRC_INSTALL_PATH share/OpenCV/samples) endif() set(OPENCV_INCLUDE_INSTALL_PATH "include") diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 0e1ee250e7..2328d89bda 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -712,11 +712,7 @@ function(ocv_add_perf_tests) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) if(INSTALL_TESTS) - if(ANDROID) - install(TARGETS ${the_target} RUNTIME DESTINATION sdk/etc/bin COMPONENT tests) - elseif(NOT WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION share/OpenCV/bin COMPONENT tests) - endif() + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT tests) endif() endif() endfunction() @@ -773,11 +769,7 @@ function(ocv_add_accuracy_tests) endif(OCV_DEPENDENCIES_FOUND) if(INSTALL_TESTS) - if(ANDROID) - install(TARGETS ${the_target} RUNTIME DESTINATION sdk/etc/bin COMPONENT tests) - elseif(NOT WIN32) - install(TARGETS ${the_target} RUNTIME DESTINATION share/OpenCV/bin COMPONENT tests) - endif() + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT tests) endif() endif() endfunction() @@ -819,7 +811,7 @@ function(ocv_add_samples) if(INSTALL_C_EXAMPLES AND NOT WIN32 AND EXISTS "${samples_path}") file(GLOB sample_files "${samples_path}/*") install(FILES ${sample_files} - DESTINATION share/OpenCV/samples/${module_id} + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/${module_id} PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() endfunction() diff --git a/cmake/OpenCVPackaging.cmake b/cmake/OpenCVPackaging.cmake index 32d5c5da7f..0117873776 100644 --- a/cmake/OpenCVPackaging.cmake +++ b/cmake/OpenCVPackaging.cmake @@ -58,9 +58,9 @@ set(CPACK_DEBIAN_PACKAGE_SECTION "libs") set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org") if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) set(prefix "${CMAKE_INSTALL_PREFIX}") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/postinst" - "${CMAKE_BINARY_DIR}/junk/postinst" @ONLY IMMEDIATE) - set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/junk/postinst") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY IMMEDIATE) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" DESTINATION /etc/profile.d/ COMPONENT tests) endif() #depencencies @@ -70,9 +70,7 @@ set(CPACK_COMPONENT_dev_DEPENDS libs) set(CPACK_COMPONENT_docs_DEPENDS libs) set(CPACK_COMPONENT_java_DEPENDS libs) set(CPACK_COMPONENT_python_DEPENDS libs) -if(INSTALL_TESTS) set(CPACK_COMPONENT_tests_DEPENDS libs) -endif() if(HAVE_CUDA) string(REPLACE "." "-" cuda_version_suffix ${CUDA_VERSION}) diff --git a/cmake/templates/postinst b/cmake/templates/postinst deleted file mode 100644 index f6763781b6..0000000000 --- a/cmake/templates/postinst +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -echo "export OPENCV_TEST_DATA_PATH=@prefix@/share/OpenCV/testdata" >> /etc/profile \ No newline at end of file diff --git a/samples/c/CMakeLists.txt b/samples/c/CMakeLists.txt index aca8886f09..6d374e7443 100644 --- a/samples/c/CMakeLists.txt +++ b/samples/c/CMakeLists.txt @@ -53,13 +53,7 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - if (ANDROID) - install(FILES ${C_SAMPLES} - DESTINATION samples/native/c - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - else() - install(FILES ${C_SAMPLES} - DESTINATION share/OpenCV/samples/c - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - endif() + install(FILES ${C_SAMPLES} + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/c + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif () diff --git a/samples/cpp/CMakeLists.txt b/samples/cpp/CMakeLists.txt index 6ccc75a747..b21fe86996 100644 --- a/samples/cpp/CMakeLists.txt +++ b/samples/cpp/CMakeLists.txt @@ -90,13 +90,7 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - if (ANDROID) - install(FILES ${C_SAMPLES} - DESTINATION samples/native/cpp - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - else() - install(FILES ${C_SAMPLES} - DESTINATION share/OpenCV/samples/cpp - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - endif() + install(FILES ${C_SAMPLES} + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/cpp + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/gpu/CMakeLists.txt b/samples/gpu/CMakeLists.txt index 226869aaa1..8fa539473b 100644 --- a/samples/gpu/CMakeLists.txt +++ b/samples/gpu/CMakeLists.txt @@ -82,13 +82,7 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - if(ANDROID) - install(FILES ${install_list} - DESTINATION samples/native/gpu - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - else() - install(FILES ${install_list} - DESTINATION share/OpenCV/samples/gpu - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - endif() + install(FILES ${install_list} + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/gpu/performance/CMakeLists.txt b/samples/gpu/performance/CMakeLists.txt index 32dc002aec..de0feadd26 100644 --- a/samples/gpu/performance/CMakeLists.txt +++ b/samples/gpu/performance/CMakeLists.txt @@ -29,7 +29,7 @@ endif() if(INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB GPU_FILES performance/*.cpp performance/*.h) install(FILES ${GPU_FILES} - DESTINATION share/OpenCV/samples/gpu/performance + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/gpu/performance PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() diff --git a/samples/ocl/CMakeLists.txt b/samples/ocl/CMakeLists.txt index 8889452a01..7fc20fd356 100644 --- a/samples/ocl/CMakeLists.txt +++ b/samples/ocl/CMakeLists.txt @@ -53,13 +53,7 @@ endif() if (INSTALL_C_EXAMPLES AND NOT WIN32) file(GLOB install_list *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd ) - if(ANDROID) - install(FILES ${install_list} - DESTINATION samples/native/ocl - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - else() - install(FILES ${install_list} - DESTINATION share/OpenCV/samples/ocl - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) - endif() + install(FILES ${install_list} + DESTINATION ${OPENCV_SAMPLES_SRC_INSTALL_PATH}/ocl + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ COMPONENT samples) endif() From 7fec87d3f6c29326228ba02f6d1c31fe4480f4a1 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 28 Jan 2014 14:05:26 +0400 Subject: [PATCH 009/662] Multiple fixes for tests deb package build. Added opencv_testing.sh.in file; opencv_testing.sh installation guarded by OS check. (cherry picked from commit d9dc5ffa918639e5d8be76644aef4385def13688) --- CMakeLists.txt | 7 +++++++ cmake/OpenCVPackaging.cmake | 6 ------ cmake/templates/opencv_testing.sh.in | 2 ++ data/CMakeLists.txt | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 cmake/templates/opencv_testing.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 752c991b0d..4e576ea4fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -561,6 +561,13 @@ include(cmake/OpenCVGenConfig.cmake) # Generate Info.plist for the IOS framework include(cmake/OpenCVGenInfoPlist.cmake) +# Generate environment setup file +if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX AND NOT ANDROID) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY IMMEDIATE) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" DESTINATION /etc/profile.d/ COMPONENT tests) +endif() + # ---------------------------------------------------------------------------- # Summary: # ---------------------------------------------------------------------------- diff --git a/cmake/OpenCVPackaging.cmake b/cmake/OpenCVPackaging.cmake index 0117873776..91f5940960 100644 --- a/cmake/OpenCVPackaging.cmake +++ b/cmake/OpenCVPackaging.cmake @@ -56,12 +56,6 @@ set(CPACK_DEB_COMPONENT_INSTALL TRUE) set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") set(CPACK_DEBIAN_PACKAGE_SECTION "libs") set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencv.org") -if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) - set(prefix "${CMAKE_INSTALL_PREFIX}") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in" - "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY IMMEDIATE) - install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" DESTINATION /etc/profile.d/ COMPONENT tests) -endif() #depencencies set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE) diff --git a/cmake/templates/opencv_testing.sh.in b/cmake/templates/opencv_testing.sh.in new file mode 100644 index 0000000000..3140136eb2 --- /dev/null +++ b/cmake/templates/opencv_testing.sh.in @@ -0,0 +1,2 @@ +# Environment setup for OpenCV testing +export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata \ No newline at end of file diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 726fc0d10d..2f10c82f64 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -9,10 +9,10 @@ elseif(NOT WIN32) install(FILES ${LBP_CASCADES} DESTINATION share/OpenCV/lbpcascades COMPONENT libs) endif() -if (OPENCV_TEST_DATA_PATH) +if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) if(ANDROID) - install(FILES ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests) + install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests) elseif(NOT WIN32) - install(FILES ${OPENCV_TEST_DATA_PATH} DESTINATION share/OpenCV/testdata COMPONENT tests) + install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION share/OpenCV/testdata COMPONENT tests) endif() endif() \ No newline at end of file From 514b714cc24685edf3b4dcea873f45187de10b01 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 29 Jan 2014 12:01:06 +0400 Subject: [PATCH 010/662] opencv_run_all_tests.sh script added to -tests package. (cherry picked from commit d45350a06a287a8ab8a812659d5afea898ffe95a) --- CMakeLists.txt | 13 ++++++++++-- cmake/OpenCVModule.cmake | 4 ++-- cmake/templates/opencv_run_all_tests.sh.in | 24 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 cmake/templates/opencv_run_all_tests.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e576ea4fb..0d342cfac9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,6 +275,9 @@ endif() set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples") set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin") +if(NOT OPENCV_TEST_INSTALL_PATH) + set(OPENCV_TEST_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}") +endif() if(ANDROID) set(LIBRARY_OUTPUT_PATH "${OpenCV_BINARY_DIR}/lib/${ANDROID_NDK_ABI_NAME}") @@ -564,8 +567,14 @@ include(cmake/OpenCVGenInfoPlist.cmake) # Generate environment setup file if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX AND NOT ANDROID) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in" - "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY IMMEDIATE) - install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" DESTINATION /etc/profile.d/ COMPONENT tests) + "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" + DESTINATION /etc/profile.d/ COMPONENT tests) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE + DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) endif() # ---------------------------------------------------------------------------- diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 2328d89bda..86a9d0c83c 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -712,7 +712,7 @@ function(ocv_add_perf_tests) # TODO: warn about unsatisfied dependencies endif(OCV_DEPENDENCIES_FOUND) if(INSTALL_TESTS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT tests) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) endif() endif() endfunction() @@ -769,7 +769,7 @@ function(ocv_add_accuracy_tests) endif(OCV_DEPENDENCIES_FOUND) if(INSTALL_TESTS) - install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT tests) + install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) endif() endif() endfunction() diff --git a/cmake/templates/opencv_run_all_tests.sh.in b/cmake/templates/opencv_run_all_tests.sh.in new file mode 100644 index 0000000000..c8bb0297a1 --- /dev/null +++ b/cmake/templates/opencv_run_all_tests.sh.in @@ -0,0 +1,24 @@ +#!/bin/sh + +OPENCV_TEST_PATH=@OPENCV_TEST_INSTALL_PATH@ +export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata + +SUMMARY_STATUS=0 +for t in "$OPENCV_TEST_PATH/"opencv_test_* "$OPENCV_TEST_PATH/"opencv_perf_*; +do + "$t" --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:$t-`date --rfc-3339=date`.xml + TEST_STATUS=$? + if [ $TEST_STATUS -ne 0 ]; then + SUMMARY_STATUS=$TEST_STATUS + fi +done + +rm -f /tmp/__opencv_temp.* + +if [ $SUMMARY_STATUS -eq 0 ]; then + echo "All OpenCV tests finished successfully" +else + echo "OpenCV tests finished with status $SUMMARY_STATUS" +fi + +return $SUMMARY_STATUS \ No newline at end of file From c6b31481b68970a9031ecd6f01fb0db1cc8f29e3 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 31 Jan 2014 12:15:22 +0400 Subject: [PATCH 011/662] OpenCV Manager version++. --- .../android_binary_package/O4A_SDK.rst | 14 +++++++------- .../dev_with_OCV_on_Android.rst | 14 +++++++------- .../android/service/engine/AndroidManifest.xml | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst index 9a683ea496..4e61b5a7cc 100644 --- a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst +++ b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst @@ -48,10 +48,10 @@ The structure of package contents looks as follows: :: - OpenCV-2.4.8-android-sdk + OpenCV-2.4.8.1-android-sdk |_ apk - | |_ OpenCV_2.4.8_binary_pack_armv7a.apk - | |_ OpenCV_2.4.8_Manager_2.16_XXX.apk + | |_ OpenCV_2.4.8.1_binary_pack_armv7a.apk + | |_ OpenCV_2.4.8.1_Manager_2.17_XXX.apk | |_ doc |_ samples @@ -157,10 +157,10 @@ Get the OpenCV4Android SDK .. code-block:: bash - unzip ~/Downloads/OpenCV-2.4.8-android-sdk.zip + unzip ~/Downloads/OpenCV-2.4.8.1-android-sdk.zip -.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.8-android-sdk.zip` -.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.8/OpenCV-2.4.8-android-sdk.zip/download +.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.8.1-android-sdk.zip` +.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.8.1/OpenCV-2.4.8.1-android-sdk.zip/download .. |opencv_android_bin_pack_url| replace:: |opencv_android_bin_pack| .. |seven_zip| replace:: 7-Zip .. _seven_zip: http://www.7-zip.org/ @@ -295,7 +295,7 @@ Well, running samples from Eclipse is very simple: .. code-block:: sh :linenos: - /platform-tools/adb install /apk/OpenCV_2.4.8_Manager_2.16_armv7a-neon.apk + /platform-tools/adb install /apk/OpenCV_2.4.8.1_Manager_2.17_armv7a-neon.apk .. note:: ``armeabi``, ``armv7a-neon``, ``arm7a-neon-android8``, ``mips`` and ``x86`` stand for platform targets: diff --git a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst index 3d7268c809..2eb6489175 100644 --- a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst +++ b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst @@ -55,14 +55,14 @@ Manager to access OpenCV libraries externally installed in the target system. :guilabel:`File -> Import -> Existing project in your workspace`. Press :guilabel:`Browse` button and locate OpenCV4Android SDK - (:file:`OpenCV-2.4.8-android-sdk/sdk`). + (:file:`OpenCV-2.4.8.1-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In application project add a reference to the OpenCV Java SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``. + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8.1``. .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library @@ -128,27 +128,27 @@ described above. #. Add the OpenCV library project to your workspace the same way as for the async initialization above. Use menu :guilabel:`File -> Import -> Existing project in your workspace`, press :guilabel:`Browse` button and select OpenCV SDK path - (:file:`OpenCV-2.4.8-android-sdk/sdk`). + (:file:`OpenCV-2.4.8.1-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In the application project add a reference to the OpenCV4Android SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``; + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8.1``; .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library :align: center #. If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV - native libs from :file:`/sdk/native/libs/` to your + native libs from :file:`/sdk/native/libs/` to your project directory to folder :file:`libs/`. In case of the application project **with a JNI part**, instead of manual libraries copying you need to modify your ``Android.mk`` file: add the following two code lines after the ``"include $(CLEAR_VARS)"`` and before - ``"include path_to_OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk"`` + ``"include path_to_OpenCV-2.4.8.1-android-sdk/sdk/native/jni/OpenCV.mk"`` .. code-block:: make :linenos: @@ -221,7 +221,7 @@ taken: .. code-block:: make - include C:\Work\OpenCV4Android\OpenCV-2.4.8-android-sdk\sdk\native\jni\OpenCV.mk + include C:\Work\OpenCV4Android\OpenCV-2.4.8.1-android-sdk\sdk\native\jni\OpenCV.mk Should be inserted into the :file:`jni/Android.mk` file **after** this line: diff --git a/platforms/android/service/engine/AndroidManifest.xml b/platforms/android/service/engine/AndroidManifest.xml index 7cae6ce8a0..ed99c90fc4 100644 --- a/platforms/android/service/engine/AndroidManifest.xml +++ b/platforms/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="217@ANDROID_PLATFORM_VERSION_CODE@" + android:versionName="2.17" > From 48d9be70d534b91f8b6994657032acb015958bdb Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 30 Jan 2014 11:08:49 +0400 Subject: [PATCH 012/662] Android toolchain file sync with original project. Original project: https://github.com/taka-no-me/android-cmake/ Revision: 5db45cfb87fec180b74963d3680dd60d4d8d8c3a (cherry picked from commit c8150436073a4c25ec4f4273b80c1b76201b8be1) --- platforms/android/android.toolchain.cmake | 123 +++++++++++++--------- 1 file changed, 75 insertions(+), 48 deletions(-) diff --git a/platforms/android/android.toolchain.cmake b/platforms/android/android.toolchain.cmake index 68b256fbd0..457164a1ee 100644 --- a/platforms/android/android.toolchain.cmake +++ b/platforms/android/android.toolchain.cmake @@ -1,5 +1,5 @@ # Copyright (c) 2010-2011, Ethan Rublee -# Copyright (c) 2011-2013, Andrey Kamaev +# Copyright (c) 2011-2014, Andrey Kamaev # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -12,9 +12,9 @@ # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # -# 3. The name of the copyright holders may be used to endorse or promote -# products derived from this software without specific prior written -# permission. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -29,12 +29,12 @@ # POSSIBILITY OF SUCH DAMAGE. # ------------------------------------------------------------------------------ -# Android CMake toolchain file, for use with the Android NDK r5-r8 +# Android CMake toolchain file, for use with the Android NDK r5-r9 # Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). # See home page: https://github.com/taka-no-me/android-cmake # # The file is mantained by the OpenCV project. The latest version can be get at -# https://github.com/Itseez/opencv/tree/master/platforms/android/android.toolchain.cmake +# http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake # # Usage Linux: # $ export ANDROID_NDK=/absolute/path/to/the/android-ndk @@ -87,8 +87,7 @@ # "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP. # "x86" - matches to the NDK ABI with the same name. # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. -# "mips" - matches to the NDK ABI with the same name -# (It is not tested on real devices by the authos of this toolchain) +# "mips" - matches to the NDK ABI with the same name. # See ${ANDROID_NDK}/docs/CPU-ARCH-ABIS.html for the documentation. # # ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. @@ -292,6 +291,16 @@ # - April 2013 # [+] support non-release NDK layouts (from Linaro git and Android git) # [~] automatically detect if explicit link to crtbegin_*.o is needed +# - June 2013 +# [~] fixed stl include path for standalone toolchain made by NDK >= r8c +# - July 2013 +# [+] updated for NDK r9 +# - November 2013 +# [+] updated for NDK r9b +# - December 2013 +# [+] updated for NDK r9c +# - January 2014 +# [~] fix copying of shared STL # ------------------------------------------------------------------------------ cmake_minimum_required( VERSION 2.6.3 ) @@ -318,7 +327,7 @@ set( CMAKE_SYSTEM_VERSION 1 ) # rpath makes low sence for Android set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) -set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) if( CMAKE_HOST_WIN32 ) file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) @@ -464,7 +473,7 @@ endif() # detect current host platform -if( NOT DEFINED ANDROID_NDK_HOST_X64 AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64") +if( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE) ) set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" ) mark_as_advanced( ANDROID_NDK_HOST_X64 ) endif() @@ -484,9 +493,7 @@ else() message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) endif() -# CMAKE_HOST_SYSTEM_PROCESSOR on MacOS X always says i386 on Intel platform -# So we do not trust ANDROID_NDK_HOST_X64 on Apple hosts -if( NOT ANDROID_NDK_HOST_X64 AND NOT CMAKE_HOST_APPLE) +if( NOT ANDROID_NDK_HOST_X64 ) set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) endif() @@ -634,30 +641,27 @@ endif() macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath ) foreach( __toolchain ${${__availableToolchainsLst}} ) - # Skip renderscript folder. It's not C++ toolchain - if (NOT ${__toolchain} STREQUAL "renderscript") - if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) - string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) - else() - set( __gcc_toolchain "${__toolchain}" ) - endif() - __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) - if( __machine ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) - if( __machine MATCHES i686 ) - set( __arch "x86" ) - elseif( __machine MATCHES arm ) - set( __arch "arm" ) - elseif( __machine MATCHES mipsel ) - set( __arch "mipsel" ) - endif() - list( APPEND __availableToolchainMachines "${__machine}" ) - list( APPEND __availableToolchainArchs "${__arch}" ) - list( APPEND __availableToolchainCompilerVersions "${__version}" ) - list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) - endif() - unset( __gcc_toolchain ) + if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) + string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) + else() + set( __gcc_toolchain "${__toolchain}" ) endif() + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) + if( __machine MATCHES i686 ) + set( __arch "x86" ) + elseif( __machine MATCHES arm ) + set( __arch "arm" ) + elseif( __machine MATCHES mipsel ) + set( __arch "mipsel" ) + endif() + list( APPEND __availableToolchainMachines "${__machine}" ) + list( APPEND __availableToolchainArchs "${__arch}" ) + list( APPEND __availableToolchainCompilerVersions "${__version}" ) + list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) + endif() + unset( __gcc_toolchain ) endforeach() endmacro() @@ -687,6 +691,7 @@ if( BUILD_WITH_ANDROID_NDK ) endif() __LIST_FILTER( __availableToolchainsLst "^[.]" ) __LIST_FILTER( __availableToolchainsLst "llvm" ) + __LIST_FILTER( __availableToolchainsLst "renderscript" ) __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) @@ -975,7 +980,11 @@ if( BUILD_WITH_STANDALONE_TOOLCHAIN ) set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) if( NOT ANDROID_STL STREQUAL "none" ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" ) + if( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" ) + # old location ( pre r8c ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + endif() if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) @@ -1130,15 +1139,7 @@ endif() # case of shared STL linkage if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" ) - if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" ) - get_filename_component( __libstlname "${__libstl}" NAME ) - execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) - if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") - message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) - endif() - unset( __fileCopyProcess ) - unset( __libstlname ) - endif() + # TODO: check if .so file exists before the renaming endif() @@ -1503,7 +1504,8 @@ endif() # global includes and link directories include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) -link_directories( "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ) +get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning +link_directories( "${__android_install_path}" ) # detect if need link crtbegin_so.o explicitly if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK ) @@ -1555,6 +1557,18 @@ if(NOT _CMAKE_IN_TRY_COMPILE) set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) endif() +# copy shaed stl library to build directory +if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" ) + get_filename_component( __libstlname "${__libstl}" NAME ) + execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) + if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") + message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) + endif() + unset( __fileCopyProcess ) + unset( __libstlname ) +endif() + + # set these global flags for cmake client scripts to change behavior set( ANDROID True ) set( BUILD_ANDROID True ) @@ -1663,6 +1677,19 @@ if( NOT PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE" ) endif() +# force cmake to produce / instead of \ in build commands for Ninja generator +if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 ) + # it is a bad hack after all + # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW + set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW + set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion + enable_language( C ) + enable_language( CXX ) + # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it + unset( MINGW ) +endif() + + # set some obsolete variables for backward compatibility set( ANDROID_SET_OBSOLETE_VARIABLES ON CACHE BOOL "Define obsolete Andrid-specific cmake variables" ) mark_as_advanced( ANDROID_SET_OBSOLETE_VARIABLES ) @@ -1717,7 +1744,7 @@ endif() # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86" or "mips" depending on ANDROID_ABI -# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c, r8d, r8e; set only for NDK +# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c, r8d, r8e, r9, r9b, r9c; set only for NDK # ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI # ANDROID_SYSROOT : path to the compiler sysroot # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform From ed10f50d255e0f2eb57c9b002c00c5f7f9217cd5 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 31 Jan 2014 10:47:01 +0400 Subject: [PATCH 013/662] Reports path fix for opencv_run_all_tests.sh.in script. (cherry picked from commit 3d261e8a010eda45908592d3b2caa76d939d342c) --- cmake/templates/opencv_run_all_tests.sh.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/templates/opencv_run_all_tests.sh.in b/cmake/templates/opencv_run_all_tests.sh.in index c8bb0297a1..b614900026 100644 --- a/cmake/templates/opencv_run_all_tests.sh.in +++ b/cmake/templates/opencv_run_all_tests.sh.in @@ -6,7 +6,8 @@ export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata SUMMARY_STATUS=0 for t in "$OPENCV_TEST_PATH/"opencv_test_* "$OPENCV_TEST_PATH/"opencv_perf_*; do - "$t" --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:$t-`date --rfc-3339=date`.xml + report="`basename "$t"`-`date --rfc-3339=date`.xml" + "$t" --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:"$report" TEST_STATUS=$? if [ $TEST_STATUS -ne 0 ]; then SUMMARY_STATUS=$TEST_STATUS From 32414afe7278969b525bdf4a1616ac914c3681d1 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 31 Jan 2014 12:40:40 +0400 Subject: [PATCH 014/662] disable performance test for gpu generalized hough(cherry picked from commit 063d8b421136b2ed0f537c663b89828f6a2b263c) --- modules/gpu/perf/perf_imgproc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index d942bed612..609e82a82b 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -1825,7 +1825,7 @@ CV_FLAGS(GHMethod, GHT_POSITION, GHT_SCALE, GHT_ROTATION); DEF_PARAM_TEST(Method_Sz, GHMethod, cv::Size); -PERF_TEST_P(Method_Sz, ImgProc_GeneralizedHough, +PERF_TEST_P(Method_Sz, DISABLED_ImgProc_GeneralizedHough, Combine(Values(GHMethod(cv::GHT_POSITION), GHMethod(cv::GHT_POSITION | cv::GHT_SCALE), GHMethod(cv::GHT_POSITION | cv::GHT_ROTATION), GHMethod(cv::GHT_POSITION | cv::GHT_SCALE | cv::GHT_ROTATION)), GPU_TYPICAL_MAT_SIZES)) { From ca10e5e8ae185e3d64a8016d305ba67bf2d9cd26 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 31 Jan 2014 12:49:10 +0400 Subject: [PATCH 015/662] Highgui test output fixes. Useless output to console fixed; Test output files moved from cwd to temp folder. (cherry picked from commit 87935f35600228a746d8a29cb1a5c108e710429d) --- modules/highgui/test/test_ffmpeg.cpp | 2 +- modules/highgui/test/test_video_io.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/highgui/test/test_ffmpeg.cpp b/modules/highgui/test/test_ffmpeg.cpp index 30410eaab8..55bf952213 100644 --- a/modules/highgui/test/test_ffmpeg.cpp +++ b/modules/highgui/test/test_ffmpeg.cpp @@ -88,7 +88,7 @@ public: stringstream s; s << tag; - const string filename = "output_"+s.str()+".avi"; + const string filename = tempfile((s.str()+".avi").c_str()); try { diff --git a/modules/highgui/test/test_video_io.cpp b/modules/highgui/test/test_video_io.cpp index cf47b73a6f..755bcd0677 100644 --- a/modules/highgui/test/test_video_io.cpp +++ b/modules/highgui/test/test_video_io.cpp @@ -332,9 +332,7 @@ void CV_HighGuiTest::VideoTest(const string& dir, const cvtest::VideoFormat& fmt } } - printf("Before saved release for %s\n", tmp_name.c_str()); cvReleaseCapture( &saved ); - printf("After release\n"); ts->printf(ts->LOG, "end test function : ImagesVideo \n"); } From a7d0448faa683fb3bf3a8df4f2f7930c3b44e7ee Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 31 Jan 2014 13:19:15 +0400 Subject: [PATCH 016/662] gpu test output files moved from cwd to temp folder(cherry picked from commit 49731ad5303a714302ff053aaeb32900845304bf) --- modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp b/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp index 42552295d2..1c0e691ba2 100644 --- a/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp +++ b/modules/gpu/test/nvidia/TestHaarCascadeLoader.cpp @@ -98,7 +98,7 @@ bool TestHaarCascadeLoader::process() NCV_SET_SKIP_COND(this->allocatorGPU.get()->isCounting()); NCV_SKIP_COND_BEGIN - const std::string testNvbinName = "test.nvbin"; + const std::string testNvbinName = cv::tempfile("test.nvbin"); ncvStat = ncvHaarLoadFromFile_host(this->cascadeName, haar, h_HaarStages, h_HaarNodes, h_HaarFeatures); ncvAssertReturn(ncvStat == NCV_SUCCESS, false); From c319625a079d17420b954601bd6586563cef6665 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 31 Jan 2014 15:40:59 +0400 Subject: [PATCH 017/662] disable some gpu tests if library was built without CUFFT(cherry picked from commit b4b929d27cc25822dd15b5b96b8d335c59d4408c) --- modules/gpu/perf/perf_imgproc.cpp | 4 ++++ modules/gpu/test/test_imgproc.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index 609e82a82b..ca0ec6cf85 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -851,6 +851,8 @@ PERF_TEST_P(Sz_Depth_Cn, ImgProc_BlendLinear, } } +#ifdef HAVE_CUFFT + ////////////////////////////////////////////////////////////////////// // Convolve @@ -1085,6 +1087,8 @@ PERF_TEST_P(Sz_Flags, ImgProc_Dft, } } +#endif + ////////////////////////////////////////////////////////////////////// // CornerHarris diff --git a/modules/gpu/test/test_imgproc.cpp b/modules/gpu/test/test_imgproc.cpp index 811d1294cf..9ce32d12b8 100644 --- a/modules/gpu/test/test_imgproc.cpp +++ b/modules/gpu/test/test_imgproc.cpp @@ -563,6 +563,8 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Blend, testing::Combine( testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), WHOLE_SUBMAT)); +#ifdef HAVE_CUFFT + //////////////////////////////////////////////////////// // Convolve @@ -1090,6 +1092,8 @@ GPU_TEST_P(Dft, R2CThenC2R) INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Dft, ALL_DEVICES); +#endif + /////////////////////////////////////////////////////////////////////////////////////////////////////// // CornerHarris From 43c75c64b56601a6a8a3e340c5a10bd3dacea713 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 31 Jan 2014 15:52:06 +0400 Subject: [PATCH 018/662] disable NPP for GpuMat methods and for copyMakeBorder(cherry picked from commit 316d49fc0fb7a609ebb0a65efc207faea6b978a4) --- .../include/opencv2/dynamicuda/dynamicuda.hpp | 61 +++++++++++++++++-- modules/gpu/src/imgproc.cpp | 6 ++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp b/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp index d4d0220e00..00f0873030 100644 --- a/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp +++ b/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp @@ -129,15 +129,20 @@ public: #if defined(USE_CUDA) -#define cudaSafeCall(expr) ___cudaSafeCall(expr, __FILE__, __LINE__, CV_Func) -#define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__, CV_Func) +// Disable NPP for this file +//#define USE_NPP +#undef USE_NPP +#define cudaSafeCall(expr) ___cudaSafeCall(expr, __FILE__, __LINE__, CV_Func) inline void ___cudaSafeCall(cudaError_t err, const char *file, const int line, const char *func = "") { if (cudaSuccess != err) cv::gpu::error(cudaGetErrorString(err), file, line, func); } +#ifdef USE_NPP + +#define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__, CV_Func) inline void ___nppSafeCall(int err, const char *file, const int line, const char *func = "") { if (err < 0) @@ -148,6 +153,8 @@ inline void ___nppSafeCall(int err, const char *file, const int line, const char } } +#endif + namespace cv { namespace gpu { namespace device { void copyToWithMask_gpu(PtrStepSzb src, PtrStepSzb dst, size_t elemSize1, int cn, PtrStepSzb mask, bool colorMask, cudaStream_t stream); @@ -173,6 +180,8 @@ template void kernelSetCaller(GpuMat& src, Scalar s, const GpuMat& cv::gpu::device::set_to_gpu(src, sf.val, mask, src.channels(), stream); } +#ifdef USE_NPP + template struct NPPTypeTraits; template<> struct NPPTypeTraits { typedef Npp8u npp_type; }; template<> struct NPPTypeTraits { typedef Npp8s npp_type; }; @@ -182,9 +191,13 @@ template<> struct NPPTypeTraits { typedef Npp32s npp_type; }; template<> struct NPPTypeTraits { typedef Npp32f npp_type; }; template<> struct NPPTypeTraits { typedef Npp64f npp_type; }; +#endif + ////////////////////////////////////////////////////////////////////////// // Convert +#ifdef USE_NPP + template struct NppConvertFunc { typedef typename NPPTypeTraits::npp_type src_t; @@ -232,9 +245,13 @@ template::func_ptr func> str } }; +#endif + ////////////////////////////////////////////////////////////////////////// // Set +#ifdef USE_NPP + template struct NppSetFunc { typedef typename NPPTypeTraits::npp_type src_t; @@ -339,9 +356,13 @@ template::func_ptr func> struct N } }; +#endif + ////////////////////////////////////////////////////////////////////////// // CopyMasked +#ifdef USE_NPP + template struct NppCopyMaskedFunc { typedef typename NPPTypeTraits::npp_type src_t; @@ -365,6 +386,8 @@ template::func_ptr func> struct N } }; +#endif + template static inline bool isAligned(const T* ptr, size_t size) { return reinterpret_cast(ptr) % size == 0; @@ -877,6 +900,8 @@ public: } typedef void (*func_t)(const GpuMat& src, GpuMat& dst, const GpuMat& mask, cudaStream_t stream); + +#ifdef USE_NPP static const func_t funcs[7][4] = { /* 8U */ {NppCopyMasked::call, cv::gpu::device::copyWithMask, NppCopyMasked::call, NppCopyMasked::call}, @@ -889,6 +914,9 @@ public: }; const func_t func = mask.channels() == src.channels() ? funcs[src.depth()][src.channels() - 1] : cv::gpu::device::copyWithMask; +#else + const func_t func = cv::gpu::device::copyWithMask; +#endif func(src, dst, mask, 0); } @@ -896,6 +924,8 @@ public: void convert(const GpuMat& src, GpuMat& dst) const { typedef void (*func_t)(const GpuMat& src, GpuMat& dst); + +#ifdef USE_NPP static const func_t funcs[7][7][4] = { { @@ -962,6 +992,7 @@ public: /* 64F -> 64F */ {0,0,0,0} } }; +#endif CV_Assert(src.depth() <= CV_64F && src.channels() <= 4); CV_Assert(dst.depth() <= CV_64F); @@ -980,8 +1011,12 @@ public: return; } +#ifdef USE_NPP const func_t func = funcs[src.depth()][dst.depth()][src.channels() - 1]; CV_DbgAssert(func != 0); +#else + const func_t func = cv::gpu::device::convertTo; +#endif func(src, dst); } @@ -1023,6 +1058,8 @@ public: } typedef void (*func_t)(GpuMat& src, Scalar s); + +#ifdef USE_NPP static const func_t funcs[7][4] = { {NppSet::call, cv::gpu::device::setTo , cv::gpu::device::setTo , NppSet::call}, @@ -1033,6 +1070,7 @@ public: {NppSet::call, cv::gpu::device::setTo , cv::gpu::device::setTo , NppSet::call}, {cv::gpu::device::setTo , cv::gpu::device::setTo , cv::gpu::device::setTo , cv::gpu::device::setTo } }; +#endif CV_Assert(m.depth() <= CV_64F && m.channels() <= 4); @@ -1042,14 +1080,22 @@ public: CV_Error(CV_StsUnsupportedFormat, "The device doesn't support double"); } +#ifdef USE_NPP + const func_t func = funcs[m.depth()][m.channels() - 1]; +#else + const func_t func = cv::gpu::device::setTo; +#endif + if (stream) cv::gpu::device::setTo(m, s, stream); else - funcs[m.depth()][m.channels() - 1](m, s); + func(m, s); } else { typedef void (*func_t)(GpuMat& src, Scalar s, const GpuMat& mask); + +#ifdef USE_NPP static const func_t funcs[7][4] = { {NppSetMask::call, cv::gpu::device::setTo, cv::gpu::device::setTo, NppSetMask::call}, @@ -1060,6 +1106,7 @@ public: {NppSetMask::call, cv::gpu::device::setTo, cv::gpu::device::setTo, NppSetMask::call}, {cv::gpu::device::setTo , cv::gpu::device::setTo, cv::gpu::device::setTo, cv::gpu::device::setTo } }; +#endif CV_Assert(m.depth() <= CV_64F && m.channels() <= 4); @@ -1069,10 +1116,16 @@ public: CV_Error(CV_StsUnsupportedFormat, "The device doesn't support double"); } +#ifdef USE_NPP + const func_t func = funcs[m.depth()][m.channels() - 1]; +#else + const func_t func = cv::gpu::device::setTo; +#endif + if (stream) cv::gpu::device::setTo(m, s, mask, stream); else - funcs[m.depth()][m.channels() - 1](m, s, mask); + func(m, s, mask); } } diff --git a/modules/gpu/src/imgproc.cpp b/modules/gpu/src/imgproc.cpp index 1904b6aad6..97adb685ff 100644 --- a/modules/gpu/src/imgproc.cpp +++ b/modules/gpu/src/imgproc.cpp @@ -244,6 +244,10 @@ void cv::gpu::reprojectImageTo3D(const GpuMat& disp, GpuMat& xyz, const Mat& Q, //////////////////////////////////////////////////////////////////////// // copyMakeBorder +// Disable NPP for this file +//#define USE_NPP +#undef USE_NPP + namespace cv { namespace gpu { namespace device { namespace imgproc @@ -279,6 +283,7 @@ void cv::gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom cudaStream_t stream = StreamAccessor::getStream(s); +#ifdef USE_NPP if (borderType == BORDER_CONSTANT && (src.type() == CV_8UC1 || src.type() == CV_8UC4 || src.type() == CV_32SC1 || src.type() == CV_32FC1)) { NppiSize srcsz; @@ -328,6 +333,7 @@ void cv::gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom cudaSafeCall( cudaDeviceSynchronize() ); } else +#endif { typedef void (*caller_t)(const PtrStepSzb& src, const PtrStepSzb& dst, int top, int left, int borderType, const Scalar& value, cudaStream_t stream); static const caller_t callers[6][4] = From 397ac5e68ff34130b58dbb16337d103d5c7a634e Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 31 Jan 2014 16:10:37 +0400 Subject: [PATCH 019/662] disable gpu Canny and HoughCircles perf tests: it fails because driver terminates CUDA kernels after time out (cherry picked from commit fa5bbb5f8dc1a86cfe004fb258d66e56c90560d6) --- modules/gpu/perf/perf_imgproc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index ca0ec6cf85..b5df5a9b81 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -672,7 +672,7 @@ PERF_TEST_P(Sz, ImgProc_ColumnSum, DEF_PARAM_TEST(Image_AppertureSz_L2gradient, string, int, bool); -PERF_TEST_P(Image_AppertureSz_L2gradient, ImgProc_Canny, +PERF_TEST_P(Image_AppertureSz_L2gradient, DISABLED_ImgProc_Canny, Combine(Values("perf/800x600.png", "perf/1280x1024.png", "perf/1680x1050.png"), Values(3, 5), Bool())) @@ -1777,7 +1777,7 @@ PERF_TEST_P(Image, ImgProc_HoughLinesP, DEF_PARAM_TEST(Sz_Dp_MinDist, cv::Size, float, float); -PERF_TEST_P(Sz_Dp_MinDist, ImgProc_HoughCircles, +PERF_TEST_P(Sz_Dp_MinDist, DISABLED_ImgProc_HoughCircles, Combine(GPU_TYPICAL_MAT_SIZES, Values(1.0f, 2.0f, 4.0f), Values(1.0f))) From 4f79b9de4834a38b2ce9b0ba5d38e5224124fb57 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 31 Jan 2014 16:15:11 +0400 Subject: [PATCH 020/662] disable gpu Subtract_Array test: possible bug in CPU version(cherry picked from commit 59155c1eefb6f22e362e34a8d73b31841eb3413a) --- modules/gpu/test/test_core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gpu/test/test_core.cpp b/modules/gpu/test/test_core.cpp index 1edc69b971..2f1bbd7b2c 100644 --- a/modules/gpu/test/test_core.cpp +++ b/modules/gpu/test/test_core.cpp @@ -422,7 +422,7 @@ PARAM_TEST_CASE(Subtract_Array, cv::gpu::DeviceInfo, cv::Size, std::pair Date: Fri, 31 Jan 2014 16:20:45 +0400 Subject: [PATCH 021/662] disable gpu CvtColor.*2HSV tests: possible bug in CPU version(cherry picked from commit 3cb8b352e52f85847d98d2b0ece32ba5bdb5c31b) --- modules/gpu/test/test_color.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/gpu/test/test_color.cpp b/modules/gpu/test/test_color.cpp index 3b4b326e4d..16f5fc84ea 100644 --- a/modules/gpu/test/test_color.cpp +++ b/modules/gpu/test/test_color.cpp @@ -840,7 +840,7 @@ GPU_TEST_P(CvtColor, YCrCb42RGBA) EXPECT_MAT_NEAR(dst_gold, dst, 1e-5); } -GPU_TEST_P(CvtColor, BGR2HSV) +GPU_TEST_P(CvtColor, DISABLED_BGR2HSV) { if (depth == CV_16U) return; @@ -856,7 +856,7 @@ GPU_TEST_P(CvtColor, BGR2HSV) EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } -GPU_TEST_P(CvtColor, RGB2HSV) +GPU_TEST_P(CvtColor, DISABLED_RGB2HSV) { if (depth == CV_16U) return; @@ -872,7 +872,7 @@ GPU_TEST_P(CvtColor, RGB2HSV) EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } -GPU_TEST_P(CvtColor, RGB2HSV4) +GPU_TEST_P(CvtColor, DISABLED_RGB2HSV4) { if (depth == CV_16U) return; @@ -896,7 +896,7 @@ GPU_TEST_P(CvtColor, RGB2HSV4) EXPECT_MAT_NEAR(dst_gold, h_dst, depth == CV_32F ? 1e-2 : 1); } -GPU_TEST_P(CvtColor, RGBA2HSV4) +GPU_TEST_P(CvtColor, DISABLED_RGBA2HSV4) { if (depth == CV_16U) return; From bc653add7495e0d97d45257c62c2b20eb8ad8366 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 6 Feb 2014 12:35:14 +0400 Subject: [PATCH 022/662] Absolute path to tests in opencv_run_app_tests.sh fixed. (cherry picked from commit 530702c5f2350c58f0e9078b5fde8185af6a3c77) --- cmake/templates/opencv_run_all_tests.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/templates/opencv_run_all_tests.sh.in b/cmake/templates/opencv_run_all_tests.sh.in index b614900026..77dc1191a9 100644 --- a/cmake/templates/opencv_run_all_tests.sh.in +++ b/cmake/templates/opencv_run_all_tests.sh.in @@ -1,6 +1,6 @@ #!/bin/sh -OPENCV_TEST_PATH=@OPENCV_TEST_INSTALL_PATH@ +OPENCV_TEST_PATH=@CMAKE_INSTALL_PREFIX@/@OPENCV_TEST_INSTALL_PATH@ export OPENCV_TEST_DATA_PATH=@CMAKE_INSTALL_PREFIX@/share/OpenCV/testdata SUMMARY_STATUS=0 From 8ba84f4b47f6ea146c130e2e08795667aee90350 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 6 Feb 2014 23:36:23 +0400 Subject: [PATCH 023/662] Implicit testdata directory permissions setup added. (cherry picked from commit b86088b89c43ba1b7db2d8435f222489722e62c9) --- data/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt index 2f10c82f64..998e78520c 100644 --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -13,6 +13,10 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH) if(ANDROID) install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION sdk/etc/testdata COMPONENT tests) elseif(NOT WIN32) - install(DIRECTORY ${OPENCV_TEST_DATA_PATH} DESTINATION share/OpenCV/testdata COMPONENT tests) + # CPack does not set correct permissions by default, so we do it explicitly. + install(DIRECTORY ${OPENCV_TEST_DATA_PATH} + DIRECTORY_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + DESTINATION share/OpenCV/testdata COMPONENT tests) endif() endif() \ No newline at end of file From 48612d7c58247a64857c534cdcf2ab4bcffabd17 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 5 Feb 2014 15:59:13 +0400 Subject: [PATCH 024/662] Revert "disable gpu Subtract_Array test:" This reverts commit e91bf95d5832e87aa70240c50f0bf7fcc587e8c8. (cherry picked from commit da44a2fac1c0be45d2a987c165298a9629757723) --- modules/gpu/test/test_core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gpu/test/test_core.cpp b/modules/gpu/test/test_core.cpp index 2f1bbd7b2c..1edc69b971 100644 --- a/modules/gpu/test/test_core.cpp +++ b/modules/gpu/test/test_core.cpp @@ -422,7 +422,7 @@ PARAM_TEST_CASE(Subtract_Array, cv::gpu::DeviceInfo, cv::Size, std::pair Date: Thu, 6 Feb 2014 10:12:20 +0400 Subject: [PATCH 025/662] Revert "disable gpu CvtColor.*2HSV tests:" This reverts commit 952027a8536215a5e4308c79a59308c6b3426354. (cherry picked from commit b6ba1f226c3da6ba726416f92550410145e89c10) --- modules/gpu/test/test_color.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/gpu/test/test_color.cpp b/modules/gpu/test/test_color.cpp index 16f5fc84ea..3b4b326e4d 100644 --- a/modules/gpu/test/test_color.cpp +++ b/modules/gpu/test/test_color.cpp @@ -840,7 +840,7 @@ GPU_TEST_P(CvtColor, YCrCb42RGBA) EXPECT_MAT_NEAR(dst_gold, dst, 1e-5); } -GPU_TEST_P(CvtColor, DISABLED_BGR2HSV) +GPU_TEST_P(CvtColor, BGR2HSV) { if (depth == CV_16U) return; @@ -856,7 +856,7 @@ GPU_TEST_P(CvtColor, DISABLED_BGR2HSV) EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } -GPU_TEST_P(CvtColor, DISABLED_RGB2HSV) +GPU_TEST_P(CvtColor, RGB2HSV) { if (depth == CV_16U) return; @@ -872,7 +872,7 @@ GPU_TEST_P(CvtColor, DISABLED_RGB2HSV) EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } -GPU_TEST_P(CvtColor, DISABLED_RGB2HSV4) +GPU_TEST_P(CvtColor, RGB2HSV4) { if (depth == CV_16U) return; @@ -896,7 +896,7 @@ GPU_TEST_P(CvtColor, DISABLED_RGB2HSV4) EXPECT_MAT_NEAR(dst_gold, h_dst, depth == CV_32F ? 1e-2 : 1); } -GPU_TEST_P(CvtColor, DISABLED_RGBA2HSV4) +GPU_TEST_P(CvtColor, RGBA2HSV4) { if (depth == CV_16U) return; From cc73c7000fb978e4ccc780787c00c9aebd278a2f Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 6 Feb 2014 12:41:19 +0400 Subject: [PATCH 026/662] fix epsilons for several gpu tests (cherry picked from commit 3e4bb371c8a364315dec18df14674d9164b7523d) --- modules/gpu/test/test_color.cpp | 8 ++++---- modules/gpu/test/test_core.cpp | 4 ++-- modules/gpu/test/test_gpumat.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/gpu/test/test_color.cpp b/modules/gpu/test/test_color.cpp index 3b4b326e4d..321785ffe0 100644 --- a/modules/gpu/test/test_color.cpp +++ b/modules/gpu/test/test_color.cpp @@ -715,7 +715,7 @@ GPU_TEST_P(CvtColor, BGR2YCrCb) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_BGR2YCrCb); - EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, RGB2YCrCb) @@ -728,7 +728,7 @@ GPU_TEST_P(CvtColor, RGB2YCrCb) cv::Mat dst_gold; cv::cvtColor(src, dst_gold, cv::COLOR_RGB2YCrCb); - EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + EXPECT_MAT_NEAR(dst_gold, dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, BGR2YCrCb4) @@ -749,7 +749,7 @@ GPU_TEST_P(CvtColor, BGR2YCrCb4) cv::split(h_dst, channels); cv::merge(channels, 3, h_dst); - EXPECT_MAT_NEAR(dst_gold, h_dst, 1.0); + EXPECT_MAT_NEAR(dst_gold, h_dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, RGBA2YCrCb4) @@ -771,7 +771,7 @@ GPU_TEST_P(CvtColor, RGBA2YCrCb4) cv::split(h_dst, channels); cv::merge(channels, 3, h_dst); - EXPECT_MAT_NEAR(dst_gold, h_dst, 1.0); + EXPECT_MAT_NEAR(dst_gold, h_dst, depth == CV_32F ? 1e-2 : 1); } GPU_TEST_P(CvtColor, YCrCb2BGR) diff --git a/modules/gpu/test/test_core.cpp b/modules/gpu/test/test_core.cpp index 1edc69b971..7ceeaedf08 100644 --- a/modules/gpu/test/test_core.cpp +++ b/modules/gpu/test/test_core.cpp @@ -3582,7 +3582,7 @@ GPU_TEST_P(Normalize, WithOutMask) cv::Mat dst_gold; cv::normalize(src, dst_gold, alpha, beta, norm_type, type); - EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + EXPECT_MAT_NEAR(dst_gold, dst, type < CV_32F ? 1.0 : 1e-4); } GPU_TEST_P(Normalize, WithMask) @@ -3598,7 +3598,7 @@ GPU_TEST_P(Normalize, WithMask) dst_gold.setTo(cv::Scalar::all(0)); cv::normalize(src, dst_gold, alpha, beta, norm_type, type, mask); - EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + EXPECT_MAT_NEAR(dst_gold, dst, type < CV_32F ? 1.0 : 1e-4); } INSTANTIATE_TEST_CASE_P(GPU_Core, Normalize, testing::Combine( diff --git a/modules/gpu/test/test_gpumat.cpp b/modules/gpu/test/test_gpumat.cpp index 210b6a4415..fee264341b 100644 --- a/modules/gpu/test/test_gpumat.cpp +++ b/modules/gpu/test/test_gpumat.cpp @@ -281,7 +281,7 @@ GPU_TEST_P(ConvertTo, WithOutScaling) cv::Mat dst_gold; src.convertTo(dst_gold, depth2); - EXPECT_MAT_NEAR(dst_gold, dst, 1.0); + EXPECT_MAT_NEAR(dst_gold, dst, depth2 < CV_32F ? 1.0 : 1e-4); } } From 79e4f7eb780a8398b61e6d525ed5933d1e07e89f Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 6 Feb 2014 16:58:40 +0400 Subject: [PATCH 027/662] Revert "disable CUDA generalized Hough Transform" This reverts commit 33d42b740c6fe938b63a0b25c9ad51741aba48c3. (cherry picked from commit 5d099df57864d083881f026ffe32637afac6ba2e) --- modules/gpu/src/cuda/generalized_hough.cu | 2 -- modules/gpu/src/generalized_hough.cpp | 2 -- modules/gpu/test/test_hough.cpp | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/gpu/src/cuda/generalized_hough.cu b/modules/gpu/src/cuda/generalized_hough.cu index 35451e7e23..5e2041eae4 100644 --- a/modules/gpu/src/cuda/generalized_hough.cu +++ b/modules/gpu/src/cuda/generalized_hough.cu @@ -40,8 +40,6 @@ // //M*/ -#define CUDA_DISABLER - #if !defined CUDA_DISABLER #include diff --git a/modules/gpu/src/generalized_hough.cpp b/modules/gpu/src/generalized_hough.cpp index 867ba7ee71..a92c37d1a5 100644 --- a/modules/gpu/src/generalized_hough.cpp +++ b/modules/gpu/src/generalized_hough.cpp @@ -40,8 +40,6 @@ // //M*/ -#define CUDA_DISABLER - #include "precomp.hpp" using namespace std; diff --git a/modules/gpu/test/test_hough.cpp b/modules/gpu/test/test_hough.cpp index 6441fc69ab..f876a7a2b0 100644 --- a/modules/gpu/test/test_hough.cpp +++ b/modules/gpu/test/test_hough.cpp @@ -189,7 +189,7 @@ PARAM_TEST_CASE(GeneralizedHough, cv::gpu::DeviceInfo, UseRoi) { }; -GPU_TEST_P(GeneralizedHough, DISABLED_POSITION) +GPU_TEST_P(GeneralizedHough, POSITION) { const cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::gpu::setDevice(devInfo.deviceID()); From dc2dbb4173502b459379fb706c39693c952f4fa8 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 7 Feb 2014 14:55:06 +0400 Subject: [PATCH 028/662] Revert "disable gpu Canny and HoughCircles perf tests:" This reverts commit dbce90692acd84fbf46bde4da4b1726049f42857. (cherry picked from commit bfc27271e2543bb0807f6dc000f770993a740581) --- modules/gpu/perf/perf_imgproc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index b5df5a9b81..ca0ec6cf85 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -672,7 +672,7 @@ PERF_TEST_P(Sz, ImgProc_ColumnSum, DEF_PARAM_TEST(Image_AppertureSz_L2gradient, string, int, bool); -PERF_TEST_P(Image_AppertureSz_L2gradient, DISABLED_ImgProc_Canny, +PERF_TEST_P(Image_AppertureSz_L2gradient, ImgProc_Canny, Combine(Values("perf/800x600.png", "perf/1280x1024.png", "perf/1680x1050.png"), Values(3, 5), Bool())) @@ -1777,7 +1777,7 @@ PERF_TEST_P(Image, ImgProc_HoughLinesP, DEF_PARAM_TEST(Sz_Dp_MinDist, cv::Size, float, float); -PERF_TEST_P(Sz_Dp_MinDist, DISABLED_ImgProc_HoughCircles, +PERF_TEST_P(Sz_Dp_MinDist, ImgProc_HoughCircles, Combine(GPU_TYPICAL_MAT_SIZES, Values(1.0f, 2.0f, 4.0f), Values(1.0f))) From 5170f0b5da76163d5734f77a166844b0fb14921f Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 7 Feb 2014 16:04:29 +0400 Subject: [PATCH 029/662] fixed several bugs in CUDA Canny implementation: * out of border access in edgesHysteresisLocalKernel * incorrect usage of atomicAdd(cherry picked from commit 5dbdadb769e97f47b64655b5b3144787c57e2740) --- modules/gpu/src/cuda/canny.cu | 49 +++++++++++++++++++++-------------- modules/gpu/src/imgproc.cpp | 14 +++++----- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/modules/gpu/src/cuda/canny.cu b/modules/gpu/src/cuda/canny.cu index aab922f22c..2ab260ec26 100644 --- a/modules/gpu/src/cuda/canny.cu +++ b/modules/gpu/src/cuda/canny.cu @@ -239,30 +239,35 @@ namespace canny { __device__ int counter = 0; - __global__ void edgesHysteresisLocalKernel(PtrStepSzi map, ushort2* st) + __device__ __forceinline__ bool checkIdx(int y, int x, int rows, int cols) + { + return (y >= 0) && (y < rows) && (x >= 0) && (x < cols); + } + + __global__ void edgesHysteresisLocalKernel(PtrStepSzi map, short2* st) { __shared__ volatile int smem[18][18]; const int x = blockIdx.x * blockDim.x + threadIdx.x; const int y = blockIdx.y * blockDim.y + threadIdx.y; - smem[threadIdx.y + 1][threadIdx.x + 1] = x < map.cols && y < map.rows ? map(y, x) : 0; + smem[threadIdx.y + 1][threadIdx.x + 1] = checkIdx(y, x, map.rows, map.cols) ? map(y, x) : 0; if (threadIdx.y == 0) - smem[0][threadIdx.x + 1] = y > 0 ? map(y - 1, x) : 0; + smem[0][threadIdx.x + 1] = checkIdx(y - 1, x, map.rows, map.cols) ? map(y - 1, x) : 0; if (threadIdx.y == blockDim.y - 1) - smem[blockDim.y + 1][threadIdx.x + 1] = y + 1 < map.rows ? map(y + 1, x) : 0; + smem[blockDim.y + 1][threadIdx.x + 1] = checkIdx(y + 1, x, map.rows, map.cols) ? map(y + 1, x) : 0; if (threadIdx.x == 0) - smem[threadIdx.y + 1][0] = x > 0 ? map(y, x - 1) : 0; + smem[threadIdx.y + 1][0] = checkIdx(y, x - 1, map.rows, map.cols) ? map(y, x - 1) : 0; if (threadIdx.x == blockDim.x - 1) - smem[threadIdx.y + 1][blockDim.x + 1] = x + 1 < map.cols ? map(y, x + 1) : 0; + smem[threadIdx.y + 1][blockDim.x + 1] = checkIdx(y, x + 1, map.rows, map.cols) ? map(y, x + 1) : 0; if (threadIdx.x == 0 && threadIdx.y == 0) - smem[0][0] = y > 0 && x > 0 ? map(y - 1, x - 1) : 0; + smem[0][0] = checkIdx(y - 1, x - 1, map.rows, map.cols) ? map(y - 1, x - 1) : 0; if (threadIdx.x == blockDim.x - 1 && threadIdx.y == 0) - smem[0][blockDim.x + 1] = y > 0 && x + 1 < map.cols ? map(y - 1, x + 1) : 0; + smem[0][blockDim.x + 1] = checkIdx(y - 1, x + 1, map.rows, map.cols) ? map(y - 1, x + 1) : 0; if (threadIdx.x == 0 && threadIdx.y == blockDim.y - 1) - smem[blockDim.y + 1][0] = y + 1 < map.rows && x > 0 ? map(y + 1, x - 1) : 0; + smem[blockDim.y + 1][0] = checkIdx(y + 1, x - 1, map.rows, map.cols) ? map(y + 1, x - 1) : 0; if (threadIdx.x == blockDim.x - 1 && threadIdx.y == blockDim.y - 1) - smem[blockDim.y + 1][blockDim.x + 1] = y + 1 < map.rows && x + 1 < map.cols ? map(y + 1, x + 1) : 0; + smem[blockDim.y + 1][blockDim.x + 1] = checkIdx(y + 1, x + 1, map.rows, map.cols) ? map(y + 1, x + 1) : 0; __syncthreads(); @@ -317,11 +322,11 @@ namespace canny if (n > 0) { const int ind = ::atomicAdd(&counter, 1); - st[ind] = make_ushort2(x, y); + st[ind] = make_short2(x, y); } } - void edgesHysteresisLocal(PtrStepSzi map, ushort2* st1) + void edgesHysteresisLocal(PtrStepSzi map, short2* st1) { void* counter_ptr; cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, counter) ); @@ -345,13 +350,13 @@ namespace canny __constant__ int c_dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; __constant__ int c_dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; - __global__ void edgesHysteresisGlobalKernel(PtrStepSzi map, ushort2* st1, ushort2* st2, const int count) + __global__ void edgesHysteresisGlobalKernel(PtrStepSzi map, short2* st1, short2* st2, const int count) { const int stack_size = 512; __shared__ int s_counter; __shared__ int s_ind; - __shared__ ushort2 s_st[stack_size]; + __shared__ short2 s_st[stack_size]; if (threadIdx.x == 0) s_counter = 0; @@ -363,14 +368,14 @@ namespace canny if (ind >= count) return; - ushort2 pos = st1[ind]; + short2 pos = st1[ind]; if (threadIdx.x < 8) { pos.x += c_dx[threadIdx.x]; pos.y += c_dy[threadIdx.x]; - if (pos.x > 0 && pos.x < map.cols && pos.y > 0 && pos.y < map.rows && map(pos.y, pos.x) == 1) + if (pos.x > 0 && pos.x < map.cols - 1 && pos.y > 0 && pos.y < map.rows - 1 && map(pos.y, pos.x) == 1) { map(pos.y, pos.x) = 2; @@ -402,7 +407,7 @@ namespace canny pos.x += c_dx[threadIdx.x & 7]; pos.y += c_dy[threadIdx.x & 7]; - if (pos.x > 0 && pos.x < map.cols && pos.y > 0 && pos.y < map.rows && map(pos.y, pos.x) == 1) + if (pos.x > 0 && pos.x < map.cols - 1 && pos.y > 0 && pos.y < map.rows - 1 && map(pos.y, pos.x) == 1) { map(pos.y, pos.x) = 2; @@ -419,8 +424,10 @@ namespace canny { if (threadIdx.x == 0) { - ind = ::atomicAdd(&counter, s_counter); - s_ind = ind - s_counter; + s_ind = ::atomicAdd(&counter, s_counter); + + if (s_ind + s_counter > map.cols * map.rows) + s_counter = 0; } __syncthreads(); @@ -432,7 +439,7 @@ namespace canny } } - void edgesHysteresisGlobal(PtrStepSzi map, ushort2* st1, ushort2* st2) + void edgesHysteresisGlobal(PtrStepSzi map, short2* st1, short2* st2) { void* counter_ptr; cudaSafeCall( cudaGetSymbolAddress(&counter_ptr, canny::counter) ); @@ -454,6 +461,8 @@ namespace canny cudaSafeCall( cudaMemcpy(&count, counter_ptr, sizeof(int), cudaMemcpyDeviceToHost) ); + count = min(count, map.cols * map.rows); + std::swap(st1, st2); } } diff --git a/modules/gpu/src/imgproc.cpp b/modules/gpu/src/imgproc.cpp index 97adb685ff..66f838f77a 100644 --- a/modules/gpu/src/imgproc.cpp +++ b/modules/gpu/src/imgproc.cpp @@ -1491,6 +1491,8 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, void cv::gpu::CannyBuf::create(const Size& image_size, int apperture_size) { + CV_Assert(image_size.width < std::numeric_limits::max() && image_size.height < std::numeric_limits::max()); + if (apperture_size > 0) { ensureSizeIsEnough(image_size, CV_32SC1, dx); @@ -1506,8 +1508,8 @@ void cv::gpu::CannyBuf::create(const Size& image_size, int apperture_size) ensureSizeIsEnough(image_size, CV_32FC1, mag); ensureSizeIsEnough(image_size, CV_32SC1, map); - ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st1); - ensureSizeIsEnough(1, image_size.area(), CV_16UC2, st2); + ensureSizeIsEnough(1, image_size.area(), CV_16SC2, st1); + ensureSizeIsEnough(1, image_size.area(), CV_16SC2, st2); } void cv::gpu::CannyBuf::release() @@ -1527,9 +1529,9 @@ namespace canny void calcMap(PtrStepSzi dx, PtrStepSzi dy, PtrStepSzf mag, PtrStepSzi map, float low_thresh, float high_thresh); - void edgesHysteresisLocal(PtrStepSzi map, ushort2* st1); + void edgesHysteresisLocal(PtrStepSzi map, short2* st1); - void edgesHysteresisGlobal(PtrStepSzi map, ushort2* st1, ushort2* st2); + void edgesHysteresisGlobal(PtrStepSzi map, short2* st1, short2* st2); void getEdges(PtrStepSzi map, PtrStepSzb dst); } @@ -1543,9 +1545,9 @@ namespace buf.map.setTo(Scalar::all(0)); calcMap(dx, dy, buf.mag, buf.map, low_thresh, high_thresh); - edgesHysteresisLocal(buf.map, buf.st1.ptr()); + edgesHysteresisLocal(buf.map, buf.st1.ptr()); - edgesHysteresisGlobal(buf.map, buf.st1.ptr(), buf.st2.ptr()); + edgesHysteresisGlobal(buf.map, buf.st1.ptr(), buf.st2.ptr()); getEdges(buf.map, dst); } From 5e00fc6afe864c7a5805bd2646b3ffc85288e5cd Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Mon, 30 Dec 2013 18:00:29 +0400 Subject: [PATCH 030/662] Fixed MinGW build by declaring the minimal required Windows version. Also deleted miscellaneous remaining multimon cruft. Deleted #include , because includes it already. This should have a nice side effect of preventing us from accidentally using any Windows API that's too new. (cherry picked from commit 795c108f2bf2880a81a8d0db1ddc2da71c91864e) --- modules/highgui/src/precomp.hpp | 8 ++++++++ modules/highgui/src/window_w32.cpp | 16 ---------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index 88ba8e4b20..af5383b142 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -57,6 +57,14 @@ #include #if defined WIN32 || defined WINCE + #if !defined _WIN32_WINNT + #ifdef HAVE_MSMF + #define _WIN32_WINNT 0x0600 // Windows Vista + #else + #define _WIN32_WINNT 0x0500 // Windows 2000 + #endif + #endif + #include #undef small #undef min diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index 7b78ebc81f..59d66b100a 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -43,27 +43,11 @@ #if defined WIN32 || defined _WIN32 -#define COMPILE_MULTIMON_STUBS // Required for multi-monitor support -#ifndef _MULTIMON_USE_SECURE_CRT -# define _MULTIMON_USE_SECURE_CRT 0 // some MinGW platforms have no strncpy_s -#endif - -#if defined SM_CMONITORS && !defined MONITOR_DEFAULTTONEAREST -# define MONITOR_DEFAULTTONULL 0x00000000 -# define MONITOR_DEFAULTTOPRIMARY 0x00000001 -# define MONITOR_DEFAULTTONEAREST 0x00000002 -# define MONITORINFOF_PRIMARY 0x00000001 -#endif -#ifndef __inout -# define __inout -#endif - #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" #endif #include -#include #include #include #include From 469aef2e5e6cc47f0e421685a3e334ca17064d82 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 28 Dec 2013 15:09:45 +0400 Subject: [PATCH 031/662] fixed bug #3341 (cherry picked from commit 09d25e11c65fa20f9ddba1d25ee4f3344ba4e655) --- modules/core/src/arithm.cpp | 4 ++-- modules/core/test/test_arithm.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index a11b64b442..0517a5fae6 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1272,8 +1272,8 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, bool haveScalar = false, swapped12 = false; int depth2 = src2.depth(); if( src1.size != src2.size || src1.channels() != src2.channels() || - ((kind1 == _InputArray::MATX || kind2 == _InputArray::MATX) && - src1.cols == 1 && src2.rows == 4) ) + (kind1 == _InputArray::MATX && (src1.size() == Size(1,4) || src1.size() == Size(1,1))) || + (kind2 == _InputArray::MATX && (src2.size() == Size(1,4) || src2.size() == Size(1,1))) ) { if( checkScalar(src1, src2.type(), kind1, kind2) ) { diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 664fa0204a..f16c801713 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -1564,3 +1564,19 @@ TEST(Core_round, CvRound) ASSERT_EQ(-2, cvRound(-2.5)); ASSERT_EQ(-4, cvRound(-3.5)); } + + +typedef testing::TestWithParam Mul1; + +TEST_P(Mul1, One) +{ + Size size = GetParam(); + cv::Mat src(size, CV_32FC1, cv::Scalar::all(2)), dst, + ref_dst(size, CV_32FC1, cv::Scalar::all(6)); + + cv::multiply(3, src, dst); + + ASSERT_EQ(0, cv::norm(dst, ref_dst, cv::NORM_INF)); +} + +INSTANTIATE_TEST_CASE_P(Arithm, Mul1, testing::Values(Size(2, 2), Size(1, 1))); From 7868733002e1d7418e4c3e223de2594a2f9cfbf2 Mon Sep 17 00:00:00 2001 From: Seunghoon Park Date: Sat, 28 Dec 2013 14:45:41 -0500 Subject: [PATCH 032/662] fixing bug #3345 (cherry picked from commit b036fc756a65c8be5b9b0e4d77d94b6f8099fc20) --- modules/imgproc/src/smooth.cpp | 2 +- modules/imgproc/test/test_filter.cpp | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index bbce3deedf..ae14ca9e11 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -718,7 +718,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, ddepth = sdepth; _dst.create( src.size(), CV_MAKETYPE(ddepth, cn) ); Mat dst = _dst.getMat(); - if( borderType != BORDER_CONSTANT && normalize ) + if( borderType != BORDER_CONSTANT && normalize && (borderType & BORDER_ISOLATED) != 0 ) { if( src.rows == 1 ) ksize.height = 1; diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index efbad99749..d1e45b0414 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -1886,3 +1886,33 @@ protected: }; TEST(Imgproc_Filtering, supportedFormats) { CV_FilterSupportedFormatsTest test; test.safe_run(); } + +TEST(Imgproc_Blur, borderTypes) +{ + Size kernelSize(3, 3); + + /// ksize > src_roi.size() + Mat src(3, 3, CV_8UC1, cv::Scalar::all(255)), dst; + Mat src_roi = src(Rect(1, 1, 1, 1)); + src_roi.setTo(cv::Scalar::all(0)); + + // should work like !BORDER_ISOLATED + blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE); + EXPECT_EQ(227, dst.at(0, 0)); + + // should work like BORDER_ISOLATED + blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_ISOLATED); + EXPECT_EQ(0, dst.at(0, 0)); + + /// ksize <= src_roi.size() + src = Mat(5, 5, CV_8UC1, cv::Scalar(255)); + src_roi = src(Rect(1, 1, 3, 3)); + src_roi.setTo(0); + src.at(2, 2) = 255; + + // should work like !BORDER_ISOLATED + blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE); + Mat expected_dst = + (Mat_(3, 3) << 170, 113, 170, 113, 28, 113, 170, 113, 170); + EXPECT_EQ(9 * 255, cv::sum(expected_dst == dst).val[0]); +} From 27a8bb471be1a17982883b5424391924c206c36e Mon Sep 17 00:00:00 2001 From: Seunghoon Park Date: Tue, 14 Jan 2014 20:47:23 -0500 Subject: [PATCH 033/662] fixing bug #3345. don't use BORDER_ISOLATED alone. it should be combined with some border type (cherry picked from commit 2272a5876972f74684c43f2069c3046bd2888d01) --- modules/imgproc/test/test_filter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index d1e45b0414..ac678e83a6 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -1901,7 +1901,7 @@ TEST(Imgproc_Blur, borderTypes) EXPECT_EQ(227, dst.at(0, 0)); // should work like BORDER_ISOLATED - blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_ISOLATED); + blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE | BORDER_ISOLATED); EXPECT_EQ(0, dst.at(0, 0)); /// ksize <= src_roi.size() From 5e986f334722ef176d700240a36dc5fd1a924b74 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Sat, 28 Dec 2013 01:40:21 +0400 Subject: [PATCH 034/662] fixed bug #3319 (cherry picked from commit 4f9c081dc313f8fdfee3f0a4572779ae13e27e40) --- modules/core/src/precomp.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index c53224e0aa..ec8dcc9f23 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -129,12 +129,14 @@ template struct OpMax inline Size getContinuousSize( const Mat& m1, int widthScale=1 ) { + CV_Assert(m1.dims <= 2); return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows); } inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 ) { + CV_Assert(m1.dims <= 2 && m1.size() == m2.size()); return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ? Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows); } @@ -142,6 +144,7 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 ) inline Size getContinuousSize( const Mat& m1, const Mat& m2, const Mat& m3, int widthScale=1 ) { + CV_Assert(m1.dims <= 2 && m1.size() == m2.size() && m1.size() == m3.size()); return (m1.flags & m2.flags & m3.flags & Mat::CONTINUOUS_FLAG) != 0 ? Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows); } @@ -150,6 +153,7 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2, const Mat& m3, const Mat& m4, int widthScale=1 ) { + CV_Assert(m1.dims <= 2 && m1.size() == m2.size() && m1.size() == m3.size() && m1.size() == m4.size()); return (m1.flags & m2.flags & m3.flags & m4.flags & Mat::CONTINUOUS_FLAG) != 0 ? Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows); } @@ -158,6 +162,7 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2, const Mat& m3, const Mat& m4, const Mat& m5, int widthScale=1 ) { + CV_Assert(m1.dims <= 2 && m1.size() == m2.size() && m1.size() == m3.size() && m1.size() == m4.size() && m1.size() == m5.size()); return (m1.flags & m2.flags & m3.flags & m4.flags & m5.flags & Mat::CONTINUOUS_FLAG) != 0 ? Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows); } From a65d7d4dd3d7dd91d078f2b7f8c37133e647f094 Mon Sep 17 00:00:00 2001 From: Kazuki Matsuda Date: Mon, 6 Jan 2014 02:24:14 +0900 Subject: [PATCH 035/662] Fix typo of SparseMat_<_Tp>::SparseMat_(const SparseMat& m) Fix compilation erros when compiling this constructor. First argument type of "convertTo" should be instance, not a pointer of instance. First pull request was created for master branch. But it should be marged for 2.4. https://github.com/Itseez/opencv/pull/2113 (cherry picked from commit 2ae20c74a2661d5975529211f4c95206e8558243) --- modules/core/include/opencv2/core/mat.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 8ddc16eb1d..45c25900c3 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -2401,7 +2401,7 @@ template inline SparseMat_<_Tp>::SparseMat_(const SparseMat& m) if( m.type() == DataType<_Tp>::type ) *this = (const SparseMat_<_Tp>&)m; else - m.convertTo(this, DataType<_Tp>::type); + m.convertTo(*this, DataType<_Tp>::type); } template inline SparseMat_<_Tp>::SparseMat_(const SparseMat_<_Tp>& m) From 345b3b0bdd4dc55cb1408346a9fdb6673ddd0435 Mon Sep 17 00:00:00 2001 From: Robbert Klarenbeek Date: Thu, 2 Jan 2014 21:17:55 +0100 Subject: [PATCH 036/662] Fix algorithm setter argument validation for uchar(cherry picked from commit e21c6e19db0183e40d12b6634aec2d1923496336) --- modules/core/src/algorithm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/algorithm.cpp b/modules/core/src/algorithm.cpp index f96f243cba..5f16f95ed4 100644 --- a/modules/core/src/algorithm.cpp +++ b/modules/core/src/algorithm.cpp @@ -647,7 +647,7 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con || argType == Param::FLOAT || argType == Param::UNSIGNED_INT || argType == Param::UINT64 || argType == Param::UCHAR) { if ( !( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN - || p->type == Param::UNSIGNED_INT || p->type == Param::UINT64 || p->type == Param::FLOAT || argType == Param::UCHAR + || p->type == Param::UNSIGNED_INT || p->type == Param::UINT64 || p->type == Param::FLOAT || p->type == Param::UCHAR || (p->type == Param::SHORT && argType == Param::INT)) ) { string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); From 7c13d3277ca296ac3fd85bae616085cb8fd8d4e5 Mon Sep 17 00:00:00 2001 From: Nghia Ho Date: Mon, 6 Jan 2014 20:19:07 +1100 Subject: [PATCH 037/662] Fixed a valgrind 'Conditional jump or move depends on uninitialised value(s)' on cv::kmeans(...). The original code used points(sampleCount, 1, CV_32FC2), which confused generateCentersPP into thinking it is a 1 dimensional center, instead of 2. As a result it would set only the x variable and leave y unitialised. (cherry picked from commit 601b7d1dd3a3ec9e8af5df461d43632d98ed3a7a) --- samples/cpp/kmeans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/cpp/kmeans.cpp b/samples/cpp/kmeans.cpp index 97de6a0a48..b742112059 100644 --- a/samples/cpp/kmeans.cpp +++ b/samples/cpp/kmeans.cpp @@ -33,7 +33,7 @@ int main( int /*argc*/, char** /*argv*/ ) { int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1); int i, sampleCount = rng.uniform(1, 1001); - Mat points(sampleCount, 1, CV_32FC2), labels; + Mat points(sampleCount, 2, CV_32F), labels; clusterCount = MIN(clusterCount, sampleCount); Mat centers(clusterCount, 1, points.type()); From d01e3529a64e3c11e135a59e4b9a5559a8687b2b Mon Sep 17 00:00:00 2001 From: ComFreek Date: Thu, 9 Jan 2014 17:24:20 +0100 Subject: [PATCH 038/662] Corrected package name in tutorial See also #2101(cherry picked from commit ae795e5797ba3b85812d56edc7fe497d05cc2d77) --- doc/tutorials/introduction/linux_install/linux_install.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorials/introduction/linux_install/linux_install.rst b/doc/tutorials/introduction/linux_install/linux_install.rst index 1e02b64c9d..8e1409650e 100644 --- a/doc/tutorials/introduction/linux_install/linux_install.rst +++ b/doc/tutorials/introduction/linux_install/linux_install.rst @@ -16,7 +16,7 @@ Required Packages * CMake 2.6 or higher; * Git; * GTK+2.x or higher, including headers (libgtk2.0-dev); - * pkgconfig; + * pkg-config; * Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy); * ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev; * [optional] libdc1394 2.x; From cdea6b532f34543afb742edb763dfbe620621137 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Viel Date: Fri, 3 Jan 2014 13:16:36 +0100 Subject: [PATCH 039/662] Fix: freeing previous elements has to be done before loading new parameters to avoid trying to delete unexisting objects if arrays size was modified (cherry picked from commit 3f458c6eb114bd46ce7f08b8ca471822ea16d26e) --- .../opencv2/flann/hierarchical_clustering_index.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h index c27b64834e..b511ee9089 100644 --- a/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h +++ b/modules/flann/include/opencv2/flann/hierarchical_clustering_index.h @@ -414,12 +414,6 @@ public: void loadIndex(FILE* stream) { - load_value(stream, branching_); - load_value(stream, trees_); - load_value(stream, centers_init_); - load_value(stream, leaf_size_); - load_value(stream, memoryCounter); - free_elements(); if (root!=NULL) { @@ -430,6 +424,12 @@ public: delete[] indices; } + load_value(stream, branching_); + load_value(stream, trees_); + load_value(stream, centers_init_); + load_value(stream, leaf_size_); + load_value(stream, memoryCounter); + indices = new int*[trees_]; root = new NodePtr[trees_]; for (int i=0; i Date: Sat, 18 Jan 2014 16:39:50 -0700 Subject: [PATCH 040/662] Fixed bug #3489: The code assumed that two global variables would be constructed in a particular order, but global variable initialization order is compiler-dependent. (cherry picked from commit 6bf599b1bca8a58c7a656ddc169f7be0fc3094c6) --- modules/core/src/system.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 09daceed53..e881ac3f63 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1129,17 +1129,24 @@ public: } } }; -static TLSContainerStorage tlsContainerStorage; + +// This is a wrapper function that will ensure 'tlsContainerStorage' is constructed on first use. +// For more information: http://www.parashift.com/c++-faq/static-init-order-on-first-use.html +static TLSContainerStorage& getTLSContainerStorage() +{ + static TLSContainerStorage *tlsContainerStorage = new TLSContainerStorage(); + return *tlsContainerStorage; +} TLSDataContainer::TLSDataContainer() : key_(-1) { - key_ = tlsContainerStorage.allocateKey(this); + key_ = getTLSContainerStorage().allocateKey(this); } TLSDataContainer::~TLSDataContainer() { - tlsContainerStorage.releaseKey(key_, this); + getTLSContainerStorage().releaseKey(key_, this); key_ = -1; } @@ -1164,7 +1171,7 @@ TLSStorage::~TLSStorage() void*& data = tlsData_[i]; if (data) { - tlsContainerStorage.destroyData(i, data); + getTLSContainerStorage().destroyData(i, data); data = NULL; } } From d5d88efd5d03c8257d7b01d6d3222efbdaf803c7 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 22 Jan 2014 10:40:14 +0400 Subject: [PATCH 041/662] fix GpuMat::copyTo method with mask: fill destination matrix with zeros if it was reallocated(cherry picked from commit dda999545c9dd1cca56081a4b2d56755210b840a) --- modules/core/src/gpumat.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp index ec26801ddc..96691919fd 100644 --- a/modules/core/src/gpumat.cpp +++ b/modules/core/src/gpumat.cpp @@ -620,11 +620,19 @@ void cv::gpu::GpuMat::copyTo(GpuMat& m) const void cv::gpu::GpuMat::copyTo(GpuMat& mat, const GpuMat& mask) const { if (mask.empty()) + { copyTo(mat); + } else { + uchar* data0 = mat.data; + mat.create(size(), type()); + // do not leave dst uninitialized + if (mat.data != data0) + mat.setTo(Scalar::all(0)); + gpuFuncTable()->copyWithMask(*this, mat, mask); } } From b7c5083a8752a3569524e00ed62dfdfacd6ef70c Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Wed, 22 Jan 2014 21:47:50 +0400 Subject: [PATCH 042/662] removing duplicated legacy license, the actual instance is in 'opencv/LICENSE' (cherry picked from commit dca56841459dadfa01ac74eb1ac01cd7e05d8522) --- doc/license.txt | 37 ------------------- .../android_binary_package/O4A_SDK.rst | 2 +- 2 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 doc/license.txt diff --git a/doc/license.txt b/doc/license.txt deleted file mode 100644 index 8824228d03..0000000000 --- a/doc/license.txt +++ /dev/null @@ -1,37 +0,0 @@ -IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. - - By downloading, copying, installing or using the software you agree to this license. - If you do not agree to this license, do not download, install, - copy or use the software. - - - License Agreement - For Open Source Computer Vision Library - -Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved. -Third party copyrights are property of their respective owners. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * The name of the copyright holders may not be used to endorse or promote products - derived from this software without specific prior written permission. - -This software is provided by the copyright holders and contributors "as is" and -any express or implied warranties, including, but not limited to, the implied -warranties of merchantability and fitness for a particular purpose are disclaimed. -In no event shall the Intel Corporation or contributors be liable for any direct, -indirect, incidental, special, exemplary, or consequential damages -(including, but not limited to, procurement of substitute goods or services; -loss of use, data, or profits; or business interruption) however caused -and on any theory of liability, whether in contract, strict liability, -or tort (including negligence or otherwise) arising in any way out of -the use of this software, even if advised of the possibility of such damage. diff --git a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst index 4e61b5a7cc..e5d1680244 100644 --- a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst +++ b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst @@ -66,7 +66,7 @@ The structure of package contents looks as follows: | |_ armeabi-v7a | |_ x86 | - |_ license.txt + |_ LICENSE |_ README.android * :file:`sdk` folder contains OpenCV API and libraries for Android: From 2c7cf52e3b18b3735865b012c3e1e1deeae22943 Mon Sep 17 00:00:00 2001 From: Seunghoon Park Date: Mon, 27 Jan 2014 20:57:40 -0500 Subject: [PATCH 043/662] fixing bug #3345. use norm to make sure two matrices are the same. (cherry picked from commit eb9d7c4dd54eea87950d98b843b349db7a95c951) --- modules/imgproc/test/test_filter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index ac678e83a6..c860a6f114 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -1914,5 +1914,7 @@ TEST(Imgproc_Blur, borderTypes) blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE); Mat expected_dst = (Mat_(3, 3) << 170, 113, 170, 113, 28, 113, 170, 113, 170); - EXPECT_EQ(9 * 255, cv::sum(expected_dst == dst).val[0]); + EXPECT_EQ(expected_dst.type(), dst.type()); + EXPECT_EQ(expected_dst.size(), dst.size()); + EXPECT_DOUBLE_EQ(0.0, cvtest::norm(expected_dst, dst, NORM_INF)); } From 5f88e2b496f320ca86389316d13d7b4e571a4568 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 28 Jan 2014 10:28:00 +0400 Subject: [PATCH 044/662] fix #3477: CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING property is not supported by all VideoCapture backends. Some backends can return 0.0 or -1.0.(cherry picked from commit c41e8006c7e9a3e796b5f78d3bfc5a97a9e87c4c) --- modules/java/generator/src/cpp/VideoCapture.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/java/generator/src/cpp/VideoCapture.cpp b/modules/java/generator/src/cpp/VideoCapture.cpp index a9d0a56c1c..e4a8bc25a9 100644 --- a/modules/java/generator/src/cpp/VideoCapture.cpp +++ b/modules/java/generator/src/cpp/VideoCapture.cpp @@ -329,7 +329,10 @@ JNIEXPORT jstring JNICALL Java_org_opencv_highgui_VideoCapture_n_1getSupportedPr VideoCapture* me = (VideoCapture*) self; //TODO: check for NULL union {double prop; const char* name;} u; u.prop = me->get(CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING); - return env->NewStringUTF(u.name); + // VideoCapture::get can return 0.0 or -1.0 if it doesn't support + // CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING + if (u.prop != 0.0 && u.prop != -1.0) + return env->NewStringUTF(u.name); } catch(const std::exception &e) { throwJavaException(env, &e, method_name); } catch (...) { From f6367a2ea519a2bde3547d5fa457e18168dcda48 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Thu, 30 Jan 2014 01:14:02 +0400 Subject: [PATCH 045/662] eliminated possible memory leak (cherry picked from commit e7e63fac6c3eaa65a8eb0926c7c9557f0614ab03) --- modules/core/test/test_math.cpp | 36 ++++++++++++++------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index 3847afce6e..a572cd0d92 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -2392,16 +2392,14 @@ TYPED_TEST_P(Core_CheckRange, Negative) double min_bound = 4.5; double max_bound = 16.0; - TypeParam data[] = {5, 10, 15, 4, 10 ,2, 8, 12, 14}; + TypeParam data[] = {5, 10, 15, 4, 10, 2, 8, 12, 14}; cv::Mat src = cv::Mat(3,3, cv::DataDepth::value, data); - cv::Point* bad_pt = new cv::Point(0, 0); + cv::Point bad_pt(0, 0); - ASSERT_FALSE(checkRange(src, true, bad_pt, min_bound, max_bound)); - ASSERT_EQ(bad_pt->x,0); - ASSERT_EQ(bad_pt->y,1); - - delete bad_pt; + ASSERT_FALSE(checkRange(src, true, &bad_pt, min_bound, max_bound)); + ASSERT_EQ(bad_pt.x, 0); + ASSERT_EQ(bad_pt.y, 1); } TYPED_TEST_P(Core_CheckRange, Positive) @@ -2409,16 +2407,14 @@ TYPED_TEST_P(Core_CheckRange, Positive) double min_bound = -1; double max_bound = 16.0; - TypeParam data[] = {5, 10, 15, 4, 10 ,2, 8, 12, 14}; + TypeParam data[] = {5, 10, 15, 4, 10, 2, 8, 12, 14}; cv::Mat src = cv::Mat(3,3, cv::DataDepth::value, data); - cv::Point* bad_pt = new cv::Point(0, 0); + cv::Point bad_pt(0, 0); - ASSERT_TRUE(checkRange(src, true, bad_pt, min_bound, max_bound)); - ASSERT_EQ(bad_pt->x,0); - ASSERT_EQ(bad_pt->y,0); - - delete bad_pt; + ASSERT_TRUE(checkRange(src, true, &bad_pt, min_bound, max_bound)); + ASSERT_EQ(bad_pt.x, 0); + ASSERT_EQ(bad_pt.y, 0); } TYPED_TEST_P(Core_CheckRange, Bounds) @@ -2426,16 +2422,14 @@ TYPED_TEST_P(Core_CheckRange, Bounds) double min_bound = 24.5; double max_bound = 1.0; - TypeParam data[] = {5, 10, 15, 4, 10 ,2, 8, 12, 14}; + TypeParam data[] = {5, 10, 15, 4, 10, 2, 8, 12, 14}; cv::Mat src = cv::Mat(3,3, cv::DataDepth::value, data); - cv::Point* bad_pt = new cv::Point(0, 0); + cv::Point bad_pt(0, 0); - ASSERT_FALSE(checkRange(src, true, bad_pt, min_bound, max_bound)); - ASSERT_EQ(bad_pt->x,0); - ASSERT_EQ(bad_pt->y,0); - - delete bad_pt; + ASSERT_FALSE(checkRange(src, true, &bad_pt, min_bound, max_bound)); + ASSERT_EQ(bad_pt.x, 0); + ASSERT_EQ(bad_pt.y, 0); } TYPED_TEST_P(Core_CheckRange, Zero) From f15a167df4791f74ebcaa006373b19f4f48758b5 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 3 Feb 2014 11:52:43 +0400 Subject: [PATCH 046/662] turn on CUDA part of nonfree module on Android for non-dynamic build(cherry picked from commit d8f7377122a65512db2f443535a9d01ea336470c) --- modules/nonfree/CMakeLists.txt | 6 +++--- modules/nonfree/include/opencv2/nonfree/gpu.hpp | 8 +------- modules/nonfree/perf/perf_gpu.cpp | 4 +++- modules/nonfree/src/cuda/surf.cu | 2 +- modules/nonfree/src/precomp.hpp | 2 +- modules/nonfree/src/surf_gpu.cpp | 6 +----- modules/nonfree/test/test_gpu.cpp | 4 +++- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/modules/nonfree/CMakeLists.txt b/modules/nonfree/CMakeLists.txt index d5c5562eca..53fb2f73e9 100644 --- a/modules/nonfree/CMakeLists.txt +++ b/modules/nonfree/CMakeLists.txt @@ -4,9 +4,9 @@ endif() set(the_description "Functionality with possible limitations on the use") ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) -if (ENABLE_DYNAMIC_CUDA) - set(HAVE_CUDA FALSE) +if(ENABLE_DYNAMIC_CUDA) + add_definitions(-DDYNAMIC_CUDA_SUPPORT) ocv_define_module(nonfree opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_ocl) else() ocv_define_module(nonfree opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_gpu opencv_ocl) -endif() \ No newline at end of file +endif() diff --git a/modules/nonfree/include/opencv2/nonfree/gpu.hpp b/modules/nonfree/include/opencv2/nonfree/gpu.hpp index c8730fb3b9..722ef26a25 100644 --- a/modules/nonfree/include/opencv2/nonfree/gpu.hpp +++ b/modules/nonfree/include/opencv2/nonfree/gpu.hpp @@ -43,11 +43,7 @@ #ifndef __OPENCV_NONFREE_GPU_HPP__ #define __OPENCV_NONFREE_GPU_HPP__ -#include "opencv2/opencv_modules.hpp" - -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) - -#include "opencv2/gpu/gpu.hpp" +#include "opencv2/core/gpumat.hpp" namespace cv { namespace gpu { @@ -129,6 +125,4 @@ public: } // namespace cv -#endif // defined(HAVE_OPENCV_GPU) - #endif // __OPENCV_NONFREE_GPU_HPP__ diff --git a/modules/nonfree/perf/perf_gpu.cpp b/modules/nonfree/perf/perf_gpu.cpp index 9f451deaba..e29eeb2fa8 100644 --- a/modules/nonfree/perf/perf_gpu.cpp +++ b/modules/nonfree/perf/perf_gpu.cpp @@ -42,7 +42,9 @@ #include "perf_precomp.hpp" -#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) +#include "cvconfig.h" + +#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/ts/gpu_perf.hpp" diff --git a/modules/nonfree/src/cuda/surf.cu b/modules/nonfree/src/cuda/surf.cu index df5905d31d..65345a363d 100644 --- a/modules/nonfree/src/cuda/surf.cu +++ b/modules/nonfree/src/cuda/surf.cu @@ -42,7 +42,7 @@ #include "opencv2/opencv_modules.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/limits.hpp" diff --git a/modules/nonfree/src/precomp.hpp b/modules/nonfree/src/precomp.hpp index 0d2e180fc5..28531390d6 100644 --- a/modules/nonfree/src/precomp.hpp +++ b/modules/nonfree/src/precomp.hpp @@ -51,7 +51,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/core/internal.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/nonfree/gpu.hpp" #if defined(HAVE_CUDA) diff --git a/modules/nonfree/src/surf_gpu.cpp b/modules/nonfree/src/surf_gpu.cpp index e0cf6ff517..b3c2ce22b2 100644 --- a/modules/nonfree/src/surf_gpu.cpp +++ b/modules/nonfree/src/surf_gpu.cpp @@ -42,12 +42,10 @@ #include "precomp.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) - using namespace cv; using namespace cv::gpu; -#if !defined (HAVE_CUDA) +#if !defined (HAVE_CUDA) || !defined(HAVE_OPENCV_GPU) || defined(DYNAMIC_CUDA_SUPPORT) cv::gpu::SURF_GPU::SURF_GPU() { throw_nogpu(); } cv::gpu::SURF_GPU::SURF_GPU(double, int, int, bool, float, bool) { throw_nogpu(); } @@ -421,5 +419,3 @@ void cv::gpu::SURF_GPU::releaseMemory() } #endif // !defined (HAVE_CUDA) - -#endif // defined(HAVE_OPENCV_GPU) && !defined(ANDROID) diff --git a/modules/nonfree/test/test_gpu.cpp b/modules/nonfree/test/test_gpu.cpp index 3f63eeddf2..938bc1d328 100644 --- a/modules/nonfree/test/test_gpu.cpp +++ b/modules/nonfree/test/test_gpu.cpp @@ -42,7 +42,9 @@ #include "test_precomp.hpp" -#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) +#include "cvconfig.h" + +#if defined(HAVE_OPENCV_GPU) && defined(HAVE_CUDA) && !defined(DYNAMIC_CUDA_SUPPORT) using namespace cvtest; From 3e755b22901c215e56e4136d981035f28484376f Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 3 Feb 2014 12:35:24 +0400 Subject: [PATCH 047/662] turn on CUDA part of stitching module on Android for non-dynamic build(cherry picked from commit a138e5a6a585e9dfc686d76b9769adeff02672b3) --- modules/stitching/CMakeLists.txt | 5 +- .../opencv2/stitching/detail/matchers.hpp | 5 +- .../opencv2/stitching/detail/seam_finders.hpp | 4 +- .../opencv2/stitching/detail/warpers.hpp | 7 +- .../include/opencv2/stitching/warpers.hpp | 2 - modules/stitching/src/blenders.cpp | 8 +- modules/stitching/src/matchers.cpp | 34 +++++-- modules/stitching/src/precomp.hpp | 2 +- modules/stitching/src/seam_finders.cpp | 58 +++++++++++- modules/stitching/src/stitcher.cpp | 2 +- modules/stitching/src/warpers.cpp | 92 ++++++++++++++++++- 11 files changed, 190 insertions(+), 29 deletions(-) diff --git a/modules/stitching/CMakeLists.txt b/modules/stitching/CMakeLists.txt index 6e9a35ba73..fc8b2fcf96 100644 --- a/modules/stitching/CMakeLists.txt +++ b/modules/stitching/CMakeLists.txt @@ -1,6 +1,7 @@ set(the_description "Images stitching") -if (ENABLE_DYNAMIC_CUDA) +if(ENABLE_DYNAMIC_CUDA) + add_definitions(-DDYNAMIC_CUDA_SUPPORT) ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_nonfree) else() ocv_define_module(stitching opencv_imgproc opencv_features2d opencv_calib3d opencv_objdetect OPTIONAL opencv_gpu opencv_nonfree) -endif() \ No newline at end of file +endif() diff --git a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp index 36f80f481c..af7439fba2 100644 --- a/modules/stitching/include/opencv2/stitching/detail/matchers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/matchers.hpp @@ -44,11 +44,12 @@ #define __OPENCV_STITCHING_MATCHERS_HPP__ #include "opencv2/core/core.hpp" +#include "opencv2/core/gpumat.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/opencv_modules.hpp" -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) #include "opencv2/nonfree/gpu.hpp" #endif @@ -104,7 +105,7 @@ private: }; -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder { public: diff --git a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp index 9301dc5ebe..5034c80043 100644 --- a/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp @@ -45,7 +45,7 @@ #include #include "opencv2/core/core.hpp" -#include "opencv2/opencv_modules.hpp" +#include "opencv2/core/gpumat.hpp" namespace cv { namespace detail { @@ -227,7 +227,6 @@ private: }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder { public: @@ -251,7 +250,6 @@ private: float terminal_cost_; float bad_region_penalty_; }; -#endif } // namespace detail } // namespace cv diff --git a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp index d44bfe69eb..60d5e54188 100644 --- a/modules/stitching/include/opencv2/stitching/detail/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/warpers.hpp @@ -44,11 +44,8 @@ #define __OPENCV_STITCHING_WARPERS_HPP__ #include "opencv2/core/core.hpp" +#include "opencv2/core/gpumat.hpp" #include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/opencv_modules.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) -# include "opencv2/gpu/gpu.hpp" -#endif namespace cv { namespace detail { @@ -331,7 +328,6 @@ public: }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class CV_EXPORTS PlaneWarperGpu : public PlaneWarper { public: @@ -448,7 +444,6 @@ public: private: gpu::GpuMat d_xmap_, d_ymap_, d_src_, d_dst_; }; -#endif struct SphericalPortraitProjector : ProjectorBase diff --git a/modules/stitching/include/opencv2/stitching/warpers.hpp b/modules/stitching/include/opencv2/stitching/warpers.hpp index 87efa7e80a..11e012ff09 100644 --- a/modules/stitching/include/opencv2/stitching/warpers.hpp +++ b/modules/stitching/include/opencv2/stitching/warpers.hpp @@ -145,7 +145,6 @@ public: -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) class PlaneWarperGpu: public WarperCreator { public: @@ -165,7 +164,6 @@ class SphericalWarperGpu: public WarperCreator public: Ptr create(float scale) const { return new detail::SphericalWarperGpu(scale); } }; -#endif } // namespace cv diff --git a/modules/stitching/src/blenders.cpp b/modules/stitching/src/blenders.cpp index fb3c0d666b..316263e998 100644 --- a/modules/stitching/src/blenders.cpp +++ b/modules/stitching/src/blenders.cpp @@ -189,7 +189,7 @@ Rect FeatherBlender::createWeightMaps(const vector &masks, const vector &pyr) void createLaplacePyrGpu(const Mat &img, int num_levels, vector &pyr) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) pyr.resize(num_levels + 1); vector gpu_pyr(num_levels + 1); @@ -512,6 +512,7 @@ void createLaplacePyrGpu(const Mat &img, int num_levels, vector &pyr) (void)img; (void)num_levels; (void)pyr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); #endif } @@ -531,7 +532,7 @@ void restoreImageFromLaplacePyr(vector &pyr) void restoreImageFromLaplacePyrGpu(vector &pyr) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (pyr.empty()) return; @@ -549,6 +550,7 @@ void restoreImageFromLaplacePyrGpu(vector &pyr) gpu_pyr[0].download(pyr[0]); #else (void)pyr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); #endif } diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index d86206233f..ac29d7ca2b 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -45,10 +45,7 @@ using namespace std; using namespace cv; using namespace cv::detail; - -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) using namespace cv::gpu; -#endif #ifdef HAVE_OPENCV_NONFREE #include "opencv2/nonfree/nonfree.hpp" @@ -129,7 +126,7 @@ private: float match_conf_; }; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) class GpuMatcher : public FeaturesMatcher { public: @@ -204,7 +201,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat LOG("1->2 & 2->1 matches: " << matches_info.matches.size() << endl); } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo& matches_info) { matches_info.matches.clear(); @@ -432,7 +429,7 @@ void OrbFeaturesFinder::find(const Mat &image, ImageFeatures &features) } } -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) SurfFeaturesFinderGpu::SurfFeaturesFinderGpu(double hess_thresh, int num_octaves, int num_layers, int num_octaves_descr, int num_layers_descr) { @@ -478,6 +475,29 @@ void SurfFeaturesFinderGpu::collectGarbage() keypoints_.release(); descriptors_.release(); } +#elif defined(HAVE_OPENCV_NONFREE) +SurfFeaturesFinderGpu::SurfFeaturesFinderGpu(double hess_thresh, int num_octaves, int num_layers, + int num_octaves_descr, int num_layers_descr) +{ + (void)hess_thresh; + (void)num_octaves; + (void)num_layers; + (void)num_octaves_descr; + (void)num_layers_descr; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void SurfFeaturesFinderGpu::find(const Mat &image, ImageFeatures &features) +{ + (void)image; + (void)features; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + +void SurfFeaturesFinderGpu::collectGarbage() +{ +} #endif @@ -533,7 +553,7 @@ void FeaturesMatcher::operator ()(const vector &features, vector< BestOf2NearestMatcher::BestOf2NearestMatcher(bool try_use_gpu, float match_conf, int num_matches_thresh1, int num_matches_thresh2) { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (try_use_gpu && getCudaEnabledDeviceCount() > 0) impl_ = new GpuMatcher(match_conf); else diff --git a/modules/stitching/src/precomp.hpp b/modules/stitching/src/precomp.hpp index 54b6721437..699f19c38c 100644 --- a/modules/stitching/src/precomp.hpp +++ b/modules/stitching/src/precomp.hpp @@ -68,7 +68,7 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/calib3d/calib3d.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) #include "opencv2/gpu/gpu.hpp" #ifdef HAVE_OPENCV_NONFREE diff --git a/modules/stitching/src/seam_finders.cpp b/modules/stitching/src/seam_finders.cpp index a198c1ebb4..234f2047e6 100644 --- a/modules/stitching/src/seam_finders.cpp +++ b/modules/stitching/src/seam_finders.cpp @@ -1318,7 +1318,7 @@ void GraphCutSeamFinder::find(const vector &src, const vector &corne } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) void GraphCutSeamFinderGpu::find(const vector &src, const vector &corners, vector &masks) { @@ -1642,6 +1642,62 @@ void GraphCutSeamFinderGpu::setGraphWeightsColorGrad( } } } +#else +void GraphCutSeamFinderGpu::find(const vector &src, const vector &corners, + vector &masks) +{ + (void)src; + (void)corners; + (void)masks; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::findInPair(size_t first, size_t second, Rect roi) +{ + (void)first; + (void)second; + (void)roi; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::setGraphWeightsColor(const Mat &img1, const Mat &img2, const Mat &mask1, const Mat &mask2, + Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom) +{ + (void)img1; + (void)img2; + (void)mask1; + (void)mask2; + (void)terminals; + (void)leftT; + (void)rightT; + (void)top; + (void)bottom; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} + + +void GraphCutSeamFinderGpu::setGraphWeightsColorGrad( + const Mat &img1, const Mat &img2, const Mat &dx1, const Mat &dx2, + const Mat &dy1, const Mat &dy2, const Mat &mask1, const Mat &mask2, + Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom) +{ + (void)img1; + (void)img2; + (void)dx1; + (void)dx2; + (void)dy1; + (void)dy2; + (void)mask1; + (void)mask2; + (void)terminals; + (void)leftT; + (void)rightT; + (void)top; + (void)bottom; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); +} #endif } // namespace detail diff --git a/modules/stitching/src/stitcher.cpp b/modules/stitching/src/stitcher.cpp index 4a36ab0a45..83ea60954e 100644 --- a/modules/stitching/src/stitcher.cpp +++ b/modules/stitching/src/stitcher.cpp @@ -58,7 +58,7 @@ Stitcher Stitcher::createDefault(bool try_use_gpu) stitcher.setFeaturesMatcher(new detail::BestOf2NearestMatcher(try_use_gpu)); stitcher.setBundleAdjuster(new detail::BundleAdjusterRay()); -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) if (try_use_gpu && gpu::getCudaEnabledDeviceCount() > 0) { #if defined(HAVE_OPENCV_NONFREE) diff --git a/modules/stitching/src/warpers.cpp b/modules/stitching/src/warpers.cpp index 935831950f..3b1d9c2287 100644 --- a/modules/stitching/src/warpers.cpp +++ b/modules/stitching/src/warpers.cpp @@ -212,7 +212,7 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b } -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) { return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); @@ -294,6 +294,96 @@ Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode); return dst_roi.tl(); } +#else +Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap); +} + +Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)T; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + +Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + return warp(src, K, R, Mat::zeros(3, 1, CV_32F), interp_mode, border_mode, dst); +} + + +Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)T; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} + + +Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + + +Point SphericalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} + + +Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap) +{ + (void)src_size; + (void)K; + (void)R; + (void)xmap; + (void)ymap; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Rect(); +} + + +Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode, + gpu::GpuMat &dst) +{ + (void)src; + (void)K; + (void)R; + (void)interp_mode; + (void)border_mode; + (void)dst; + CV_Error(CV_StsNotImplemented, "CUDA optimization is unavailable"); + return Point(); +} #endif void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br) From 1ab02631b0b211df7756415c6f00361e1c662fd3 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 3 Feb 2014 12:55:03 +0400 Subject: [PATCH 048/662] update stitching sample (cherry picked from commit 214cbabc4073c17413c2982ce06266e777e73654) --- samples/cpp/stitching_detailed.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/cpp/stitching_detailed.cpp b/samples/cpp/stitching_detailed.cpp index 7394a72821..4162addb38 100644 --- a/samples/cpp/stitching_detailed.cpp +++ b/samples/cpp/stitching_detailed.cpp @@ -355,7 +355,7 @@ int main(int argc, char* argv[]) Ptr finder; if (features_type == "surf") { -#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) finder = new SurfFeaturesFinderGpu(); else @@ -543,7 +543,7 @@ int main(int argc, char* argv[]) // Warp images and their masks Ptr warper_creator; -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) { if (warp_type == "plane") warper_creator = new cv::PlaneWarperGpu(); @@ -608,7 +608,7 @@ int main(int argc, char* argv[]) seam_finder = new detail::VoronoiSeamFinder(); else if (seam_find_type == "gc_color") { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR); else @@ -617,7 +617,7 @@ int main(int argc, char* argv[]) } else if (seam_find_type == "gc_colorgrad") { -#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID) +#if defined(HAVE_OPENCV_GPU) if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0) seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR_GRAD); else From daa7b9ce5f4eed5cd2ae50b0ef8b0d748b50ac63 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 4 Feb 2014 10:29:15 +0400 Subject: [PATCH 049/662] fix path to CUDA libraries (use targets/armv7-linux-androideabi/lib)(cherry picked from commit a098fb1803a6bd4d6ebe58c4a1dd0f2dfea464ab) --- cmake/templates/OpenCV.mk.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index 0fd7b9e058..690d2ef62b 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -157,7 +157,7 @@ LOCAL_LDLIBS += $(foreach lib,$(OPENCV_EXTRA_COMPONENTS), -l$(lib)) ifeq ($(OPENCV_USE_GPU_MODULE),on) LOCAL_STATIC_LIBRARIES+=libopencv_gpu - LOCAL_LDLIBS += -L$(CUDA_TOOLKIT_DIR)/lib $(foreach lib, $(CUDA_RUNTIME_LIBS), -l$(lib)) + LOCAL_LDLIBS += -L$(CUDA_TOOLKIT_DIR)/targets/armv7-linux-androideabi/lib $(foreach lib, $(CUDA_RUNTIME_LIBS), -l$(lib)) endif #restore the LOCAL_PATH From c10692deffe44cf46c297da3679cd99da333efbe Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 4 Feb 2014 10:29:43 +0400 Subject: [PATCH 050/662] save previous values of LOCAL_* variables and restore them at the end(cherry picked from commit 286fe261d07a7faf481ac907c6f09b3fece4aa64) --- cmake/templates/OpenCV.mk.in | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index 690d2ef62b..104ddb6dd2 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -2,6 +2,13 @@ # you might need to define NDK_USE_CYGPATH=1 before calling the ndk-build USER_LOCAL_PATH:=$(LOCAL_PATH) + +USER_LOCAL_C_INCLUDES:=$(LOCAL_C_INCLUDES) +USER_LOCAL_CFLAGS:=$(LOCAL_CFLAGS) +USER_LOCAL_STATIC_LIBRARIES:=$(LOCAL_STATIC_LIBRARIES) +USER_LOCAL_SHARED_LIBRARIES:=$(LOCAL_SHARED_LIBRARIES) +USER_LOCAL_LDLIBS:=$(LOCAL_LDLIBS) + LOCAL_PATH:=$(subst ?,,$(firstword ?$(subst \, ,$(subst /, ,$(call my-dir))))) OPENCV_TARGET_ARCH_ABI:=$(TARGET_ARCH_ABI) @@ -136,6 +143,13 @@ ifeq ($(OPENCV_LOCAL_CFLAGS),) endif include $(CLEAR_VARS) + +LOCAL_C_INCLUDES:=$(USER_LOCAL_C_INCLUDES) +LOCAL_CFLAGS:=$(USER_LOCAL_CFLAGS) +LOCAL_STATIC_LIBRARIES:=$(USER_LOCAL_STATIC_LIBRARIES) +LOCAL_SHARED_LIBRARIES:=$(USER_LOCAL_SHARED_LIBRARIES) +LOCAL_LDLIBS:=$(USER_LOCAL_LDLIBS) + LOCAL_C_INCLUDES += $(OPENCV_LOCAL_C_INCLUDES) LOCAL_CFLAGS += $(OPENCV_LOCAL_CFLAGS) From 826fc0037445a2b4ddeef90010f22feeb4b35f3c Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 4 Feb 2014 16:23:01 +0400 Subject: [PATCH 051/662] Tests install path fix for Android SDK. (cherry picked from commit 0cd0e4749bd74c2050b3e3cf082ced6bdc489376) --- CMakeLists.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d342cfac9..c3dc8028ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,13 +268,24 @@ if(WIN32) message(STATUS "Can't detect runtime and/or arch") set(OpenCV_INSTALL_BINARIES_PREFIX "") endif() +elseif(ANDROID) + set(OpenCV_INSTALL_BINARIES_PREFIX "sdk/native/") else() set(OpenCV_INSTALL_BINARIES_PREFIX "") endif() -set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples") +if(ANDROID) + set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples/${ANDROID_NDK_ABI_NAME}") +else() + set(OPENCV_SAMPLES_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}samples") +endif() + +if(ANDROID) + set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin/${ANDROID_NDK_ABI_NAME}") +else() + set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin") +endif() -set(OPENCV_BIN_INSTALL_PATH "${OpenCV_INSTALL_BINARIES_PREFIX}bin") if(NOT OPENCV_TEST_INSTALL_PATH) set(OPENCV_TEST_INSTALL_PATH "${OPENCV_BIN_INSTALL_PATH}") endif() From 51dff5b9e81352e57a06be298cb424384f3fb8d9 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 5 Feb 2014 17:34:19 +0400 Subject: [PATCH 052/662] project.properties file generation fixed for per-component installation. (cherry picked from commit 65b4d779597ffdfe909cb01f6163b1c404b040c2) --- cmake/OpenCVDetectAndroidSDK.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index 7a37051e49..d9e10213ae 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -365,7 +365,7 @@ macro(add_android_project target path) endif() install(CODE "EXECUTE_PROCESS(COMMAND ${ANDROID_EXECUTABLE} --silent update project --path . --target \"${android_proj_sdk_target}\" --name \"${target}\" ${inst_lib_opt} WORKING_DIRECTORY \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}\" - )" COMPONENT dev) + )" COMPONENT samples) #empty 'gen' install(CODE "MAKE_DIRECTORY(\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/samples/${sample_dir}/gen\")" COMPONENT samples) endif() From a49beb7c7392f470c5a32d3600c51c0666c660a7 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 4 Feb 2014 13:25:47 +0400 Subject: [PATCH 053/662] Multiple improvements in OpenCV examples build. EMBED_CUDA and FORCE_EMBED_OPENCV flags added to cmake macro add_android_project; INSTALL_CUDA_LIBRARIES option added to OpenCV.mk opencv_dynamicuda library installation with enabled OPENCV_INSTALL_MODULES flag fixed; CUDA initialization apportunity added to OpenCVLoader.initDebug(); Tutorial-4-CUDA sample reimplemented with static OpenCV and CUDA initialization. (cherry picked from commit 6ae4a9b09bf4b3572b2d31136528f1faa809a065) --- cmake/OpenCVDetectAndroidSDK.cmake | 42 +++++++++++++++- cmake/OpenCVGenAndroidMK.cmake | 23 +++++++++ cmake/OpenCVUtils.cmake | 14 ++++++ cmake/templates/OpenCV.mk.in | 34 +++++++++++-- .../src/java/android+OpenCVLoader.java | 12 ++++- .../src/java/android+StaticHelper.java | 14 +++++- .../android/tutorial-4-cuda/CMakeLists.txt | 7 +-- .../android/tutorial-4-cuda/jni/Android.mk | 2 + .../samples/tutorial4/Tutorial4Activity.java | 50 ++++++++++--------- 9 files changed, 163 insertions(+), 35 deletions(-) diff --git a/cmake/OpenCVDetectAndroidSDK.cmake b/cmake/OpenCVDetectAndroidSDK.cmake index d9e10213ae..af7427194e 100644 --- a/cmake/OpenCVDetectAndroidSDK.cmake +++ b/cmake/OpenCVDetectAndroidSDK.cmake @@ -180,7 +180,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 IGNORE_MANIFEST) + set(android_proj_arglist NATIVE_DEPS LIBRARY_DEPS SDK_TARGET IGNORE_JAVA IGNORE_MANIFEST EMBED_CUDA FORCE_EMBED_OPENCV) set(__varname "android_proj_") foreach(v ${android_proj_arglist}) set(${__varname}${v} "") @@ -303,6 +303,46 @@ macro(add_android_project target path) add_custom_command(TARGET ${JNI_LIB_NAME} POST_BUILD COMMAND ${CMAKE_STRIP} --strip-unneeded "${android_proj_jni_location}") endif() endif() + + # copy opencv_java, tbb if it is shared and dynamicuda if present if FORCE_EMBED_OPENCV flag is set + if(android_proj_FORCE_EMBED_OPENCV) + set(native_deps ${android_proj_NATIVE_DEPS}) + # filter out gpu module as it is always static library on Android + list(REMOVE_ITEM native_deps "opencv_gpu") + if(ENABLE_DYNAMIC_CUDA) + list(APPEND native_deps "opencv_dynamicuda") + endif() + foreach(lib ${native_deps}) + get_property(f TARGET ${lib} PROPERTY LOCATION) + get_filename_component(f_name ${f} NAME) + add_custom_command( + OUTPUT "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}" + COMMAND ${CMAKE_COMMAND} -E copy "${f}" "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}" + DEPENDS "${lib}" VERBATIM + COMMENT "Embedding ${f}") + list(APPEND android_proj_file_deps "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}") + endforeach() + endif() + + # copy all needed CUDA libs to project if EMBED_CUDA flag is present + if(android_proj_EMBED_CUDA) + set(android_proj_culibs ${CUDA_npp_LIBRARY} ${CUDA_LIBRARIES}) + if(HAVE_CUFFT) + list(INSERT android_proj_culibs 0 ${CUDA_cufft_LIBRARY}) + endif() + if(HAVE_CUBLAS) + list(INSERT android_proj_culibs 0 ${CUDA_cublas_LIBRARY}) + endif() + foreach(lib ${android_proj_culibs}) + get_filename_component(f "${lib}" NAME) + add_custom_command( + OUTPUT "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}" + COMMAND ${CMAKE_COMMAND} -E copy "${lib}" "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}" + DEPENDS "${lib}" VERBATIM + COMMENT "Embedding ${f}") + list(APPEND android_proj_file_deps "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f}") + endforeach() + endif() endif() # build java part diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake index 45193a2732..cacc6ca22e 100644 --- a/cmake/OpenCVGenAndroidMK.cmake +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -59,6 +59,24 @@ if(ANDROID) ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "libcu") ocv_list_filterout(OPENCV_EXTRA_COMPONENTS_CONFIGMAKE "libnpp") + if(HAVE_CUDA) + # CUDA runtime libraries and are required always + set(culibs ${CUDA_LIBRARIES}) + + # right now NPP is requared always too + list(INSERT culibs 0 ${CUDA_npp_LIBRARY}) + + if(HAVE_CUFFT) + list(INSERT culibs 0 ${CUDA_cufft_LIBRARY}) + endif() + + if(HAVE_CUBLAS) + list(INSERT culibs 0 ${CUDA_cublas_LIBRARY}) + endif() + endif() + + ocv_convert_to_lib_name(CUDA_RUNTIME_LIBS_CONFIGMAKE ${culibs}) + # split 3rdparty libs and modules foreach(mod ${OPENCV_MODULES_CONFIGMAKE}) if(NOT mod MATCHES "^opencv_.+$") @@ -69,6 +87,10 @@ if(ANDROID) list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) endif() + if(ENABLE_DYNAMIC_CUDA) + set(OPENCV_DYNAMICUDA_MODULE_CONFIGMAKE "dynamicuda") + endif() + # GPU module enabled separately list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE "opencv_gpu") list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE "opencv_dynamicuda") @@ -84,6 +106,7 @@ if(ANDROID) string(REPLACE ";" " " ${lst} "${${lst}}") endforeach() string(REPLACE "opencv_" "" OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}") + string(REPLACE ";" " " CUDA_RUNTIME_LIBS_CONFIGMAKE "${CUDA_RUNTIME_LIBS_CONFIGMAKE}") # prepare 3rd-party component list without TBB for armeabi and mips platforms. TBB is useless there. set(OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 13461e82c1..9fa94bb8bd 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -448,6 +448,20 @@ macro(ocv_convert_to_full_paths VAR) endmacro() +# convert list of paths to libraries names without lib prefix +macro(ocv_convert_to_lib_name var) + set(__tmp "") + foreach(path ${ARGN}) + get_filename_component(__tmp_name "${path}" NAME_WE) + string(REGEX REPLACE "^lib" "" __tmp_name ${__tmp_name}) + list(APPEND __tmp "${__tmp_name}") + endforeach() + set(${var} ${__tmp}) + unset(__tmp) + unset(__tmp_name) +endmacro() + + # add install command function(ocv_install_target) install(TARGETS ${ARGN}) diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index 104ddb6dd2..97330e8545 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -19,8 +19,9 @@ OPENCV_3RDPARTY_LIBS_DIR:=@OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE@ OPENCV_BASEDIR:=@OPENCV_BASE_INCLUDE_DIR_CONFIGCMAKE@ OPENCV_LOCAL_C_INCLUDES:=@OPENCV_INCLUDE_DIRS_CONFIGCMAKE@ OPENCV_MODULES:=@OPENCV_MODULES_CONFIGMAKE@ +OPENCV_DYNAMICUDA_MODULE:=@OPENCV_DYNAMICUDA_MODULE_CONFIGMAKE@ -OPENCV_HAVE_GPU_MODULE=@OPENCV_HAVE_GPU_MODULE_CONFIGMAKE@ +OPENCV_HAVE_GPU_MODULE:=@OPENCV_HAVE_GPU_MODULE_CONFIGMAKE@ OPENCV_USE_GPU_MODULE:= ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) @@ -31,7 +32,7 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) endif endif -CUDA_RUNTIME_LIBS:=cufft npps nppi nppc cudart +CUDA_RUNTIME_LIBS:=@CUDA_RUNTIME_LIBS_CONFIGMAKE@ ifeq ($(OPENCV_LIB_TYPE),) OPENCV_LIB_TYPE:=@OPENCV_LIBTYPE_CONFIGMAKE@ @@ -67,7 +68,7 @@ else endif endif -ifeq (${OPENCV_CAMERA_MODULES},on) +ifeq ($(OPENCV_CAMERA_MODULES),on) ifeq ($(TARGET_ARCH_ABI),armeabi) OPENCV_CAMERA_MODULES:=@OPENCV_CAMERA_LIBS_ARMEABI_CONFIGCMAKE@ endif @@ -98,6 +99,13 @@ define add_opencv_module include $(PREBUILT_$(OPENCV_LIB_TYPE)_LIBRARY) endef +define add_cuda_module + include $(CLEAR_VARS) + LOCAL_MODULE:=$1 + LOCAL_SRC_FILES:=$(CUDA_TOOLKIT_DIR)/targets/armv7-linux-androideabi/lib/lib$1.so + include $(PREBUILT_SHARED_LIBRARY) +endef + define add_opencv_3rdparty_component include $(CLEAR_VARS) LOCAL_MODULE:=$1 @@ -115,6 +123,15 @@ endef ifeq ($(OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_ALREADY_INCLUDED),) ifeq ($(OPENCV_INSTALL_MODULES),on) $(foreach module,$(OPENCV_LIBS),$(eval $(call add_opencv_module,$(module)))) + ifneq ($(OPENCV_DYNAMICUDA_MODULE),) + $(eval $(call add_opencv_module,$(OPENCV_DYNAMICUDA_MODULE))) + endif + endif + + ifeq ($(OPENCV_USE_GPU_MODULE),on) + ifeq ($(INSTALL_CUDA_LIBRARIES),on) + $(foreach module,$(CUDA_RUNTIME_LIBS),$(eval $(call add_cuda_module,$(module)))) + endif endif $(foreach module,$(OPENCV_3RDPARTY_COMPONENTS),$(eval $(call add_opencv_3rdparty_component,$(module)))) @@ -159,6 +176,11 @@ endif ifeq ($(OPENCV_INSTALL_MODULES),on) LOCAL_$(OPENCV_LIB_TYPE)_LIBRARIES += $(foreach mod, $(OPENCV_LIBS), opencv_$(mod)) + ifeq ($(OPENCV_LIB_TYPE),SHARED) + ifneq ($(OPENCV_DYNAMICUDA_MODULE),) + LOCAL_$(OPENCV_LIB_TYPE)_LIBRARIES += $(OPENCV_DYNAMICUDA_MODULE) + endif + endif else LOCAL_LDLIBS += -L$(call host-path,$(LOCAL_PATH)/$(OPENCV_LIBS_DIR)) $(foreach lib, $(OPENCV_LIBS), -lopencv_$(lib)) endif @@ -170,8 +192,12 @@ endif LOCAL_LDLIBS += $(foreach lib,$(OPENCV_EXTRA_COMPONENTS), -l$(lib)) ifeq ($(OPENCV_USE_GPU_MODULE),on) + ifeq ($(INSTALL_CUDA_LIBRARIES),on) + LOCAL_SHARED_LIBRARIES += $(foreach mod, $(CUDA_RUNTIME_LIBS), $(mod)) + else + LOCAL_LDLIBS += -L$(CUDA_TOOLKIT_DIR)/targets/armv7-linux-androideabi/lib $(foreach lib, $(CUDA_RUNTIME_LIBS), -l$(lib)) + endif LOCAL_STATIC_LIBRARIES+=libopencv_gpu - LOCAL_LDLIBS += -L$(CUDA_TOOLKIT_DIR)/targets/armv7-linux-androideabi/lib $(foreach lib, $(CUDA_RUNTIME_LIBS), -l$(lib)) endif #restore the LOCAL_PATH diff --git a/modules/java/generator/src/java/android+OpenCVLoader.java b/modules/java/generator/src/java/android+OpenCVLoader.java index 46e62eb347..0892e3af3c 100644 --- a/modules/java/generator/src/java/android+OpenCVLoader.java +++ b/modules/java/generator/src/java/android+OpenCVLoader.java @@ -48,7 +48,17 @@ public class OpenCVLoader */ public static boolean initDebug() { - return StaticHelper.initOpenCV(); + return StaticHelper.initOpenCV(false); + } + + /** + * Loads and initializes OpenCV library from current application package. Roughly, it's an analog of system.loadLibrary("opencv_java"). + * @param InitCuda load and initialize CUDA runtime libraries. + * @return Returns true is initialization of OpenCV was successful. + */ + public static boolean initDebug(boolean InitCuda) + { + return StaticHelper.initOpenCV(InitCuda); } /** diff --git a/modules/java/generator/src/java/android+StaticHelper.java b/modules/java/generator/src/java/android+StaticHelper.java index 8d0629c8d3..10442c904d 100644 --- a/modules/java/generator/src/java/android+StaticHelper.java +++ b/modules/java/generator/src/java/android+StaticHelper.java @@ -7,11 +7,21 @@ import android.util.Log; class StaticHelper { - public static boolean initOpenCV() + public static boolean initOpenCV(boolean InitCuda) { boolean result; String libs = ""; + if(InitCuda) + { + loadLibrary("cudart"); + loadLibrary("nppc"); + loadLibrary("nppi"); + loadLibrary("npps"); + loadLibrary("cufft"); + loadLibrary("cublas"); + } + Log.d(TAG, "Trying to get library list"); try @@ -52,7 +62,7 @@ class StaticHelper { try { System.loadLibrary(Name); - Log.d(TAG, "OpenCV libs init was ok!"); + Log.d(TAG, "Library " + Name + " loaded"); } catch(UnsatisfiedLinkError e) { diff --git a/samples/android/tutorial-4-cuda/CMakeLists.txt b/samples/android/tutorial-4-cuda/CMakeLists.txt index a011b33492..da9fe9871d 100644 --- a/samples/android/tutorial-4-cuda/CMakeLists.txt +++ b/samples/android/tutorial-4-cuda/CMakeLists.txt @@ -1,15 +1,16 @@ set(sample example-tutorial-4-cuda) -ocv_check_dependencies(opencv_core opencv_java opencv_gpu) +ocv_check_dependencies(opencv_core opencv_features2d opencv_java opencv_gpu) if (OCV_DEPENDENCIES_FOUND) if(BUILD_FAT_JAVA_LIB) set(native_deps opencv_java opencv_gpu) else() - set(native_deps opencv_gpu) + set(native_deps opencv_core opencv_features2d opencv_java opencv_gpu) endif() - add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS ${native_deps}) + add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS ${native_deps} EMBED_CUDA ON FORCE_EMBED_OPENCV ON) + if(TARGET ${sample}) add_dependencies(opencv_android_examples ${sample}) endif() diff --git a/samples/android/tutorial-4-cuda/jni/Android.mk b/samples/android/tutorial-4-cuda/jni/Android.mk index 3d709dff3b..e14b1990f2 100644 --- a/samples/android/tutorial-4-cuda/jni/Android.mk +++ b/samples/android/tutorial-4-cuda/jni/Android.mk @@ -2,6 +2,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) +INSTALL_CUDA_LIBRARIES:=on +OPENCV_INSTALL_MODULES:=on CUDA_TOOLKIT_DIR=$(CUDA_TOOLKIT_ROOT) include ../../sdk/native/jni/OpenCV.mk diff --git a/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java b/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java index c1753b68cc..6a8cb5ec04 100644 --- a/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java +++ b/samples/android/tutorial-4-cuda/src/org/opencv/samples/tutorial4/Tutorial4Activity.java @@ -49,29 +49,6 @@ public class Tutorial4Activity extends Activity implements CvCameraViewListener2 { Log.i(TAG, "OpenCV loaded successfully"); - // Check CUDA support - if (Gpu.getCudaEnabledDeviceCount() <= 0) - { - Log.e(TAG, "No CUDA capable device found!"); - AlertDialog InitFailedDialog = new AlertDialog.Builder(Tutorial4Activity.this).create(); - InitFailedDialog.setTitle("OpenCV CUDA error"); - InitFailedDialog.setMessage("CUDA compatible device was not found!"); - InitFailedDialog.setCancelable(false); // This blocks the 'BACK' button - InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { - - public void onClick(DialogInterface dialog, int which) { - Tutorial4Activity.this.finish(); - } - }); - InitFailedDialog.show(); - } - else - { - // Load native library after(!) OpenCV initialization - Log.i(TAG, "Found CUDA capable device!"); - System.loadLibrary("cuda_sample"); - mOpenCvCameraView.enableView(); - } } break; default: { @@ -120,7 +97,32 @@ public class Tutorial4Activity extends Activity implements CvCameraViewListener2 public void onResume() { super.onResume(); - OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback); + if (OpenCVLoader.initDebug(true)) + { + // Check CUDA support + if (Gpu.getCudaEnabledDeviceCount() <= 0) + { + Log.e(TAG, "No CUDA capable device found!"); + AlertDialog InitFailedDialog = new AlertDialog.Builder(Tutorial4Activity.this).create(); + InitFailedDialog.setTitle("OpenCV CUDA error"); + InitFailedDialog.setMessage("CUDA compatible device was not found!"); + InitFailedDialog.setCancelable(false); // This blocks the 'BACK' button + InitFailedDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + Tutorial4Activity.this.finish(); + } + }); + InitFailedDialog.show(); + } + else + { + // Load native library after(!) OpenCV initialization + Log.i(TAG, "Found CUDA capable device!"); + System.loadLibrary("cuda_sample"); + mOpenCvCameraView.enableView(); + } + + } } public void onDestroy() { From f9e9ae85bd038f7a261e409eeeebc024ac09c491 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 7 Feb 2014 12:46:24 +0400 Subject: [PATCH 054/662] dynamicuda module disabled in OpenCv.mk for all arches except armeabi-v7a. (cherry picked from commit b10d4b05ed3eb9947bcb3dd183da69e44be5e30a) --- cmake/templates/OpenCV.mk.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index 97330e8545..16fc4c9ccb 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -19,7 +19,6 @@ OPENCV_3RDPARTY_LIBS_DIR:=@OPENCV_3RDPARTY_LIBS_DIR_CONFIGCMAKE@ OPENCV_BASEDIR:=@OPENCV_BASE_INCLUDE_DIR_CONFIGCMAKE@ OPENCV_LOCAL_C_INCLUDES:=@OPENCV_INCLUDE_DIRS_CONFIGCMAKE@ OPENCV_MODULES:=@OPENCV_MODULES_CONFIGMAKE@ -OPENCV_DYNAMICUDA_MODULE:=@OPENCV_DYNAMICUDA_MODULE_CONFIGMAKE@ OPENCV_HAVE_GPU_MODULE:=@OPENCV_HAVE_GPU_MODULE_CONFIGMAKE@ OPENCV_USE_GPU_MODULE:= @@ -30,6 +29,9 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) OPENCV_USE_GPU_MODULE:=on endif endif + OPENCV_DYNAMICUDA_MODULE:=@OPENCV_DYNAMICUDA_MODULE_CONFIGMAKE@ +else + OPENCV_DYNAMICUDA_MODULE:= endif CUDA_RUNTIME_LIBS:=@CUDA_RUNTIME_LIBS_CONFIGMAKE@ @@ -124,7 +126,9 @@ ifeq ($(OPENCV_MK_$(OPENCV_TARGET_ARCH_ABI)_ALREADY_INCLUDED),) ifeq ($(OPENCV_INSTALL_MODULES),on) $(foreach module,$(OPENCV_LIBS),$(eval $(call add_opencv_module,$(module)))) ifneq ($(OPENCV_DYNAMICUDA_MODULE),) - $(eval $(call add_opencv_module,$(OPENCV_DYNAMICUDA_MODULE))) + ifeq ($(OPENCV_LIB_TYPE),SHARED) + $(eval $(call add_opencv_module,$(OPENCV_DYNAMICUDA_MODULE))) + endif endif endif From f15b42018cea6dd28f21a9faff70de21ec052692 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 7 Feb 2014 13:40:37 +0400 Subject: [PATCH 055/662] fix nonfree module compilation without CUDA(cherry picked from commit 3e1f74f2cafc5c38d0e64928149edb87d9b28d28) --- modules/nonfree/src/precomp.hpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/modules/nonfree/src/precomp.hpp b/modules/nonfree/src/precomp.hpp index 28531390d6..6311ee2aa9 100644 --- a/modules/nonfree/src/precomp.hpp +++ b/modules/nonfree/src/precomp.hpp @@ -51,17 +51,14 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/core/internal.hpp" -#if defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) - #include "opencv2/nonfree/gpu.hpp" +#include "opencv2/nonfree/gpu.hpp" - #if defined(HAVE_CUDA) - #include "opencv2/gpu/stream_accessor.hpp" - #include "opencv2/gpu/device/common.hpp" - - static inline void throw_nogpu() { CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform"); } - #else - static inline void throw_nogpu() { CV_Error(CV_GpuNotSupported, "The library is compiled without GPU support"); } - #endif +#if defined(HAVE_CUDA) && defined(HAVE_OPENCV_GPU) && !defined(DYNAMIC_CUDA_SUPPORT) + #include "opencv2/gpu/stream_accessor.hpp" + #include "opencv2/gpu/device/common.hpp" + static inline void throw_nogpu() { CV_Error(CV_StsNotImplemented, "The called functionality is disabled for current build or platform"); } +#else + static inline void throw_nogpu() { CV_Error(CV_GpuNotSupported, "The library is compiled without GPU support"); } #endif #ifdef HAVE_OPENCV_OCL From 9997aa8187cfa7a6c3f75ba65181c38b76d2e16e Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Mon, 10 Feb 2014 11:50:14 +0400 Subject: [PATCH 056/662] decrease input size for several gpu tests to fix "timed out" error: * BruteForceNonLocalMeans * OpticalFlowBM(cherry picked from commit 8b44a42a403548c244aaea6852fb09935a0741e9) --- modules/gpu/test/test_denoising.cpp | 3 +++ modules/gpu/test/test_optflow.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/gpu/test/test_denoising.cpp b/modules/gpu/test/test_denoising.cpp index e480cf4680..e416e92597 100644 --- a/modules/gpu/test/test_denoising.cpp +++ b/modules/gpu/test/test_denoising.cpp @@ -114,6 +114,7 @@ GPU_TEST_P(BruteForceNonLocalMeans, Regression) cv::Mat bgr = readImage("denoising/lena_noised_gaussian_sigma=20_multi_0.png", cv::IMREAD_COLOR); ASSERT_FALSE(bgr.empty()); + cv::resize(bgr, bgr, cv::Size(256, 256)); cv::Mat gray; cv::cvtColor(bgr, gray, CV_BGR2GRAY); @@ -130,6 +131,8 @@ GPU_TEST_P(BruteForceNonLocalMeans, Regression) cv::Mat bgr_gold = readImage("denoising/nlm_denoised_lena_bgr.png", cv::IMREAD_COLOR); cv::Mat gray_gold = readImage("denoising/nlm_denoised_lena_gray.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(bgr_gold.empty() || gray_gold.empty()); + cv::resize(bgr_gold, bgr_gold, cv::Size(256, 256)); + cv::resize(gray_gold, gray_gold, cv::Size(256, 256)); EXPECT_MAT_NEAR(bgr_gold, dbgr, 1e-4); EXPECT_MAT_NEAR(gray_gold, dgray, 1e-4); diff --git a/modules/gpu/test/test_optflow.cpp b/modules/gpu/test/test_optflow.cpp index 53b93a096b..571403d2a7 100644 --- a/modules/gpu/test/test_optflow.cpp +++ b/modules/gpu/test/test_optflow.cpp @@ -483,13 +483,15 @@ GPU_TEST_P(OpticalFlowBM, Accuracy) cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(frame0.empty()); + cv::resize(frame0, frame0, cv::Size(), 0.5, 0.5); cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE); ASSERT_FALSE(frame1.empty()); + cv::resize(frame1, frame1, cv::Size(), 0.5, 0.5); - cv::Size block_size(16, 16); + cv::Size block_size(8, 8); cv::Size shift_size(1, 1); - cv::Size max_range(16, 16); + cv::Size max_range(8, 8); cv::gpu::GpuMat d_velx, d_vely, buf; cv::gpu::calcOpticalFlowBM(loadMat(frame0), loadMat(frame1), From f1ef3a4865c892f92d9554bdd26fd3a46aaf537b Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 11 Feb 2014 10:15:02 +0400 Subject: [PATCH 057/662] OpenCV version++. --- .../android_binary_package/O4A_SDK.rst | 14 +++++++------- .../dev_with_OCV_on_Android.rst | 14 +++++++------- modules/core/include/opencv2/core/version.hpp | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst index e5d1680244..9e0ebc005d 100644 --- a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst +++ b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst @@ -48,10 +48,10 @@ The structure of package contents looks as follows: :: - OpenCV-2.4.8.1-android-sdk + OpenCV-2.4.8.2-android-sdk |_ apk - | |_ OpenCV_2.4.8.1_binary_pack_armv7a.apk - | |_ OpenCV_2.4.8.1_Manager_2.17_XXX.apk + | |_ OpenCV_2.4.8.2_binary_pack_armv7a.apk + | |_ OpenCV_2.4.8.2_Manager_2.17_XXX.apk | |_ doc |_ samples @@ -157,10 +157,10 @@ Get the OpenCV4Android SDK .. code-block:: bash - unzip ~/Downloads/OpenCV-2.4.8.1-android-sdk.zip + unzip ~/Downloads/OpenCV-2.4.8.2-android-sdk.zip -.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.8.1-android-sdk.zip` -.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.8.1/OpenCV-2.4.8.1-android-sdk.zip/download +.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.8.2-android-sdk.zip` +.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.8.2/OpenCV-2.4.8.2-android-sdk.zip/download .. |opencv_android_bin_pack_url| replace:: |opencv_android_bin_pack| .. |seven_zip| replace:: 7-Zip .. _seven_zip: http://www.7-zip.org/ @@ -295,7 +295,7 @@ Well, running samples from Eclipse is very simple: .. code-block:: sh :linenos: - /platform-tools/adb install /apk/OpenCV_2.4.8.1_Manager_2.17_armv7a-neon.apk + /platform-tools/adb install /apk/OpenCV_2.4.8.2_Manager_2.17_armv7a-neon.apk .. note:: ``armeabi``, ``armv7a-neon``, ``arm7a-neon-android8``, ``mips`` and ``x86`` stand for platform targets: diff --git a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst index 2eb6489175..0801ab7c42 100644 --- a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst +++ b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst @@ -55,14 +55,14 @@ Manager to access OpenCV libraries externally installed in the target system. :guilabel:`File -> Import -> Existing project in your workspace`. Press :guilabel:`Browse` button and locate OpenCV4Android SDK - (:file:`OpenCV-2.4.8.1-android-sdk/sdk`). + (:file:`OpenCV-2.4.8.2-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In application project add a reference to the OpenCV Java SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8.1``. + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8.2``. .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library @@ -128,27 +128,27 @@ described above. #. Add the OpenCV library project to your workspace the same way as for the async initialization above. Use menu :guilabel:`File -> Import -> Existing project in your workspace`, press :guilabel:`Browse` button and select OpenCV SDK path - (:file:`OpenCV-2.4.8.1-android-sdk/sdk`). + (:file:`OpenCV-2.4.8.2-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In the application project add a reference to the OpenCV4Android SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8.1``; + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8.2``; .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library :align: center #. If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV - native libs from :file:`/sdk/native/libs/` to your + native libs from :file:`/sdk/native/libs/` to your project directory to folder :file:`libs/`. In case of the application project **with a JNI part**, instead of manual libraries copying you need to modify your ``Android.mk`` file: add the following two code lines after the ``"include $(CLEAR_VARS)"`` and before - ``"include path_to_OpenCV-2.4.8.1-android-sdk/sdk/native/jni/OpenCV.mk"`` + ``"include path_to_OpenCV-2.4.8.2-android-sdk/sdk/native/jni/OpenCV.mk"`` .. code-block:: make :linenos: @@ -221,7 +221,7 @@ taken: .. code-block:: make - include C:\Work\OpenCV4Android\OpenCV-2.4.8.1-android-sdk\sdk\native\jni\OpenCV.mk + include C:\Work\OpenCV4Android\OpenCV-2.4.8.2-android-sdk\sdk\native\jni\OpenCV.mk Should be inserted into the :file:`jni/Android.mk` file **after** this line: diff --git a/modules/core/include/opencv2/core/version.hpp b/modules/core/include/opencv2/core/version.hpp index 3e1ad43746..3a37bfdbef 100644 --- a/modules/core/include/opencv2/core/version.hpp +++ b/modules/core/include/opencv2/core/version.hpp @@ -50,7 +50,7 @@ #define CV_VERSION_EPOCH 2 #define CV_VERSION_MAJOR 4 #define CV_VERSION_MINOR 8 -#define CV_VERSION_REVISION 1 +#define CV_VERSION_REVISION 2 #define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) From 116311b7b4bfc74e362e066819e5e1867e6f4c2e Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 12 Feb 2014 10:56:57 +0400 Subject: [PATCH 058/662] opencv_run_all_tests.sh implemented for Android SDK. (cherry picked from commit d02c2911607b199e18988c29c3fb9df141555974) --- CMakeLists.txt | 28 ++++++---- .../opencv_run_all_tests_android.sh.in | 51 +++++++++++++++++++ ....sh.in => opencv_run_all_tests_unix.sh.in} | 0 3 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 cmake/templates/opencv_run_all_tests_android.sh.in rename cmake/templates/{opencv_run_all_tests.sh.in => opencv_run_all_tests_unix.sh.in} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3dc8028ad..392c87dee7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -576,16 +576,24 @@ include(cmake/OpenCVGenConfig.cmake) include(cmake/OpenCVGenInfoPlist.cmake) # Generate environment setup file -if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX AND NOT ANDROID) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in" - "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY) - install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" - DESTINATION /etc/profile.d/ COMPONENT tests) - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests.sh.in" - "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY) - install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE - DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) +if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX) + if(ANDROID) + get_filename_component(TEST_PATH ${OPENCV_TEST_INSTALL_PATH} DIRECTORY) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests_android.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY) + install(PROGRAMS "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" + DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT tests) + else() + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_testing.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" @ONLY) + install(FILES "${CMAKE_BINARY_DIR}/unix-install/opencv_testing.sh" + DESTINATION /etc/profile.d/ COMPONENT tests) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/opencv_run_all_tests_unix.sh.in" + "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" @ONLY) + install(PROGRAMS "${CMAKE_BINARY_DIR}/unix-install/opencv_run_all_tests.sh" + DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests) + + endif() endif() # ---------------------------------------------------------------------------- diff --git a/cmake/templates/opencv_run_all_tests_android.sh.in b/cmake/templates/opencv_run_all_tests_android.sh.in new file mode 100644 index 0000000000..93373fa964 --- /dev/null +++ b/cmake/templates/opencv_run_all_tests_android.sh.in @@ -0,0 +1,51 @@ +#!/bin/sh + +BASE_DIR=`dirname $0` +OPENCV_TEST_PATH=$BASE_DIR/@TEST_PATH@ +OPENCV_TEST_DATA_PATH=$BASE_DIR/sdk/etc/testdata/ + +if [ $# -ne 1 ]; then + echo "Device architecture is not preset in command line" + echo "Tests are available for architectures: `ls -m ${OPENCV_TEST_PATH}`" + echo "Usage: $0 " + return 1 +else + TARGET_ARCH=$1 +fi + +if [ -z `which adb` ]; then + echo "adb command was not found in PATH" + return 1 +fi + +adb push $OPENCV_TEST_DATA_PATH /sdcard/opencv_testdata + +adb shell "mkdir -p /data/local/tmp/opencv_test" +SUMMARY_STATUS=0 +for t in "$OPENCV_TEST_PATH/$TARGET_ARCH/"opencv_test_* "$OPENCV_TEST_PATH/$TARGET_ARCH/"opencv_perf_*; +do + test_name=`basename "$t"` + report="$test_name-`date --rfc-3339=date`.xml" + adb push $t /data/local/tmp/opencv_test/ + adb shell "export OPENCV_TEST_DATA_PATH=/sdcard/opencv_testdata && /data/local/tmp/opencv_test/$test_name --perf_min_samples=1 --perf_force_samples=1 --gtest_output=xml:/data/local/tmp/opencv_test/$report" + adb pull "/data/local/tmp/opencv_test/$report" $report + TEST_STATUS=0 + if [ -e $report ]; then + if [ `grep -c " Date: Wed, 12 Feb 2014 10:29:53 +0400 Subject: [PATCH 059/662] LICENSE and README files installation rules added. (cherry picked from commit e55f2b26028a5261806fb8e972b6165c40593357) --- CMakeLists.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 392c87dee7..a54479d001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -596,6 +596,28 @@ if(INSTALL_TESTS AND OPENCV_TEST_DATA_PATH AND UNIX) endif() endif() +if(NOT OPENCV_README_FILE) + if(ANDROID) + set(OPENCV_README_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platforms/android/README.android) + endif() +endif() + +if(NOT OPENCV_LICENSE_FILE) + set(OPENCV_LICENSE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) +endif() + +# for UNIX it does not make sense as LICENSE and readme will be part of the package automatically +if(ANDROID OR NOT UNIX) + install(FILES ${OPENCV_LICENSE_FILE} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT libs) + if(OPENCV_README_FILE) + install(FILES ${OPENCV_README_FILE} + PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT libs) + endif() +endif() + # ---------------------------------------------------------------------------- # Summary: # ---------------------------------------------------------------------------- From 25159d8e8162a8574f9adb0da7bd37263fb16f99 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 13 Feb 2014 16:47:02 +0400 Subject: [PATCH 060/662] Application pause/resume fix for Android sample NativeActivity. (cherry picked from commit 7da3e98dfd1539c027b26fd67f9225e93af8d144) --- .../org/opencv/samples/NativeActivity/CvNativeActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java b/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java index 04da9a9496..b9db22de1f 100644 --- a/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java +++ b/samples/android/native-activity/src/org/opencv/samples/NativeActivity/CvNativeActivity.java @@ -21,6 +21,7 @@ public class CvNativeActivity extends Activity { System.loadLibrary("native_activity"); Intent intent = new Intent(CvNativeActivity.this, android.app.NativeActivity.class); CvNativeActivity.this.startActivity(intent); + CvNativeActivity.this.finish(); } break; default: { @@ -34,7 +35,7 @@ public class CvNativeActivity extends Activity { Log.i(TAG, "Instantiated new " + this.getClass()); } - @Override + @Override public void onResume() { super.onResume(); From 2da7eae2c4ad01010ec04b239bc1b03d5ec98104 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 13 Feb 2014 17:16:43 +0400 Subject: [PATCH 061/662] increase epsilon for AlphaComp sanity test for integer input(cherry picked from commit 9e69e2a07a9798d75a0949ab2b4ad063dd84e8f2) --- modules/gpu/perf/perf_imgproc.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index ca0ec6cf85..ec6524e245 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -1563,7 +1563,14 @@ PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp, TEST_CYCLE() cv::gpu::alphaComp(d_img1, d_img2, dst, alpha_op); - GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); + if (CV_MAT_DEPTH(type) < CV_32F) + { + GPU_SANITY_CHECK(dst, 1); + } + else + { + GPU_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE); + } } else { From aa82f921cc638e07f65698bc1d66d815aec4e62c Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 13 Feb 2014 17:25:59 +0400 Subject: [PATCH 062/662] temporary disable perf test for StereoBeliefPropagation(cherry picked from commit eb247d826f04673a23e4d050ee5cf0395bde82c2) --- modules/gpu/perf/perf_calib3d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gpu/perf/perf_calib3d.cpp b/modules/gpu/perf/perf_calib3d.cpp index 91800649c2..4a67405980 100644 --- a/modules/gpu/perf/perf_calib3d.cpp +++ b/modules/gpu/perf/perf_calib3d.cpp @@ -93,7 +93,7 @@ PERF_TEST_P(ImagePair, Calib3D_StereoBM, ////////////////////////////////////////////////////////////////////// // StereoBeliefPropagation -PERF_TEST_P(ImagePair, Calib3D_StereoBeliefPropagation, +PERF_TEST_P(ImagePair, DISABLED_Calib3D_StereoBeliefPropagation, Values(pair_string("gpu/stereobp/aloe-L.png", "gpu/stereobp/aloe-R.png"))) { declare.time(300.0); From ea513967315e82aa4a1f2e280b6f0514c6c16b93 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 13 Feb 2014 18:17:47 +0400 Subject: [PATCH 063/662] Dead code removed as this cannot be null in Java. (cherry picked from commit dbe7634286d405161adb30677aa4d07cc17e0de2) --- modules/java/generator/src/java/core+TermCriteria.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/java/generator/src/java/core+TermCriteria.java b/modules/java/generator/src/java/core+TermCriteria.java index 98a5e3c394..c67e51ea8d 100644 --- a/modules/java/generator/src/java/core+TermCriteria.java +++ b/modules/java/generator/src/java/core+TermCriteria.java @@ -87,7 +87,6 @@ public class TermCriteria { @Override public String toString() { - if (this == null) return "null"; return "{ type: " + type + ", maxCount: " + maxCount + ", epsilon: " + epsilon + "}"; } } From b4845d8c9ff5b40956191e0302fbd6559e53a27c Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Fri, 14 Feb 2014 14:27:43 +0400 Subject: [PATCH 064/662] temporary disable performance test for alphaComp function(cherry picked from commit 1ce5165cb7ccabdd0280970e3f1b6bc180055a3d) --- modules/gpu/perf/perf_imgproc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gpu/perf/perf_imgproc.cpp b/modules/gpu/perf/perf_imgproc.cpp index ec6524e245..bf47dd8c7f 100644 --- a/modules/gpu/perf/perf_imgproc.cpp +++ b/modules/gpu/perf/perf_imgproc.cpp @@ -1542,7 +1542,7 @@ CV_ENUM(AlphaOp, ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_P DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, AlphaOp); -PERF_TEST_P(Sz_Type_Op, ImgProc_AlphaComp, +PERF_TEST_P(Sz_Type_Op, DISABLED_ImgProc_AlphaComp, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC4, CV_16UC4, CV_32SC4, CV_32FC4), AlphaOp::all())) From 0c30b187690861e643a3aced1771c16fc1a3e273 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 1 Apr 2014 18:00:44 -0700 Subject: [PATCH 065/662] Bug #3611 Initializing static cv::Mat with cv::Mat::zeros causes segmentation fault fixed. --- modules/core/src/matop.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/core/src/matop.cpp b/modules/core/src/matop.cpp index 5c518146c7..eefd633189 100644 --- a/modules/core/src/matop.cpp +++ b/modules/core/src/matop.cpp @@ -202,7 +202,11 @@ public: static void makeExpr(MatExpr& res, int method, Size sz, int type, double alpha=1); }; -static MatOp_Initializer g_MatOp_Initializer; +static MatOp_Initializer* getGlobalMatOpInitializer() +{ + static MatOp_Initializer initializer; + return &initializer; +} static inline bool isIdentity(const MatExpr& e) { return e.op == &g_MatOp_Identity; } static inline bool isAddEx(const MatExpr& e) { return e.op == &g_MatOp_AddEx; } @@ -215,7 +219,7 @@ static inline bool isInv(const MatExpr& e) { return e.op == &g_MatOp_Invert; } static inline bool isSolve(const MatExpr& e) { return e.op == &g_MatOp_Solve; } static inline bool isGEMM(const MatExpr& e) { return e.op == &g_MatOp_GEMM; } static inline bool isMatProd(const MatExpr& e) { return e.op == &g_MatOp_GEMM && (!e.c.data || e.beta == 0); } -static inline bool isInitializer(const MatExpr& e) { return e.op == &g_MatOp_Initializer; } +static inline bool isInitializer(const MatExpr& e) { return e.op == getGlobalMatOpInitializer(); } ///////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1570,7 +1574,7 @@ void MatOp_Initializer::multiply(const MatExpr& e, double s, MatExpr& res) const inline void MatOp_Initializer::makeExpr(MatExpr& res, int method, Size sz, int type, double alpha) { - res = MatExpr(&g_MatOp_Initializer, method, Mat(sz, type, (void*)0), Mat(), Mat(), alpha, 0); + res = MatExpr(getGlobalMatOpInitializer(), method, Mat(sz, type, (void*)0), Mat(), Mat(), alpha, 0); } From 6fb83f869cc9d2eea313424d1198a114c0b62d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Aedla?= Date: Thu, 1 May 2014 15:37:12 +0300 Subject: [PATCH 066/662] Android camera qcom HAL doesn't like it when no consumer usage bits are set. Set a usage bit for preview BufferQueue. --- modules/androidcamera/camera_wrapper/camera_wrapper.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp index 0ed301323a..202aa29bbb 100644 --- a/modules/androidcamera/camera_wrapper/camera_wrapper.cpp +++ b/modules/androidcamera/camera_wrapper/camera_wrapper.cpp @@ -25,6 +25,7 @@ #elif defined(ANDROID_r4_3_0) || defined(ANDROID_r4_4_0) # include # include +# include #else # include #endif @@ -681,6 +682,7 @@ CameraHandler* CameraHandler::initCameraConnect(const CameraCallback& callback, # elif defined(ANDROID_r4_4_0) void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL); handler->queue = new(buffer_queue_obj) BufferQueue(); + handler->queue->setConsumerUsageBits(GraphicBuffer::USAGE_HW_TEXTURE); void* consumer_listener_obj = operator new(sizeof(ConsumerListenerStub) + MAGIC_TAIL); handler->listener = new(consumer_listener_obj) ConsumerListenerStub(); handler->queue->consumerConnect(handler->listener, true); @@ -1085,6 +1087,7 @@ void CameraHandler::applyProperties(CameraHandler** ppcameraHandler) # elif defined(ANDROID_r4_4_0) void* buffer_queue_obj = operator new(sizeof(BufferQueue) + MAGIC_TAIL); handler->queue = new(buffer_queue_obj) BufferQueue(); + handler->queue->setConsumerUsageBits(GraphicBuffer::USAGE_HW_TEXTURE); handler->queue->consumerConnect(handler->listener, true); bufferStatus = handler->camera->setPreviewTarget(handler->queue); if (bufferStatus != 0) From f9ff9c56183e92cfb54992f7a07dcc18f4f86e65 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 7 May 2014 13:15:19 +0400 Subject: [PATCH 067/662] fix cv::subtract function: call dst.create(...) before using it(cherry picked from commit 4c66614e07319b66537b6327e2dcf871c5aa6829) --- modules/core/src/arithm.cpp | 6 +++++- modules/core/test/test_arithm.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 0517a5fae6..f0ef920554 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1562,8 +1562,12 @@ void cv::subtract( InputArray src1, InputArray src2, OutputArray dst, if (dtype == -1 && dst.fixedType()) dtype = dst.depth(); - if (!dst.fixedType() || dtype == dst.depth()) + dtype = CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src1.channels()); + + if (!dst.fixedType() || dtype == dst.type()) { + dst.create(src1.size(), dtype); + if (dtype == CV_16S) { Mat _dst = dst.getMat(); diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index a240941847..1687285a60 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -1579,3 +1579,13 @@ TEST_P(Mul1, One) } INSTANTIATE_TEST_CASE_P(Arithm, Mul1, testing::Values(Size(2, 2), Size(1, 1))); + +TEST(Subtract8u8u16s, EmptyOutputMat) +{ + cv::Mat src1 = cv::Mat::zeros(16, 16, CV_8UC1); + cv::Mat src2 = cv::Mat::zeros(16, 16, CV_8UC1); + cv::Mat dst; + cv::subtract(src1, src2, dst, cv::noArray(), CV_16S); + ASSERT_FALSE(dst.empty()); + ASSERT_EQ(0, cv::countNonZero(dst)); +} From 942401de162838964f79cd4d6e6aed27ddc1a487 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 7 May 2014 19:52:35 +0400 Subject: [PATCH 068/662] fix output matrix allocation in cv::subtract(cherry picked from commit 629461c83652e2416ccb6c8685a0788bb6fb15f5) --- modules/core/src/arithm.cpp | 47 ++++++++++++++++++++----------- modules/core/test/test_arithm.cpp | 19 +++++++++---- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index f0ef920554..4058856fff 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1553,43 +1553,58 @@ void cv::add( InputArray src1, InputArray src2, OutputArray dst, arithm_op(src1, src2, dst, mask, dtype, getAddTab() ); } -void cv::subtract( InputArray src1, InputArray src2, OutputArray dst, +void cv::subtract( InputArray _src1, InputArray _src2, OutputArray _dst, InputArray mask, int dtype ) { #ifdef HAVE_TEGRA_OPTIMIZATION - if (mask.empty() && src1.depth() == CV_8U && src2.depth() == CV_8U) + int kind1 = _src1.kind(), kind2 = _src2.kind(); + Mat src1 = _src1.getMat(), src2 = _src2.getMat(); + bool src1Scalar = checkScalar(src1, _src2.type(), kind1, kind2); + bool src2Scalar = checkScalar(src2, _src1.type(), kind2, kind1); + + if (!src1Scalar && !src2Scalar && mask.empty() && + src1.depth() == CV_8U && src2.depth() == CV_8U) { - if (dtype == -1 && dst.fixedType()) - dtype = dst.depth(); - - dtype = CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), src1.channels()); - - if (!dst.fixedType() || dtype == dst.type()) + if (dtype == -1) { - dst.create(src1.size(), dtype); + if (_dst.fixedType()) + { + dtype = _dst.depth(); + } + else + { + dtype = src1.depth(); + } + } + + dtype = CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), _src1.channels()); + + if (dtype == _dst.type()) + { + _dst.create(_src1.size(), dtype); if (dtype == CV_16S) { - Mat _dst = dst.getMat(); - if(tegra::subtract_8u8u16s(src1.getMat(), src2.getMat(), _dst)) + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u16s(src1, src2, dst)) return; } else if (dtype == CV_32F) { - Mat _dst = dst.getMat(); - if(tegra::subtract_8u8u32f(src1.getMat(), src2.getMat(), _dst)) + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u32f(src1, src2, dst)) return; } else if (dtype == CV_8S) { - Mat _dst = dst.getMat(); - if(tegra::subtract_8u8u8s(src1.getMat(), src2.getMat(), _dst)) + Mat dst = _dst.getMat(); + if(tegra::subtract_8u8u8s(src1, src2, dst)) return; } } } #endif - arithm_op(src1, src2, dst, mask, dtype, getSubTab() ); + arithm_op(_src1, _src2, _dst, mask, dtype, getSubTab() ); } void cv::absdiff( InputArray src1, InputArray src2, OutputArray dst ) diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 1687285a60..68b06267b2 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -1580,12 +1580,21 @@ TEST_P(Mul1, One) INSTANTIATE_TEST_CASE_P(Arithm, Mul1, testing::Values(Size(2, 2), Size(1, 1))); -TEST(Subtract8u8u16s, EmptyOutputMat) +TEST(Subtract, EmptyOutputMat) { cv::Mat src1 = cv::Mat::zeros(16, 16, CV_8UC1); cv::Mat src2 = cv::Mat::zeros(16, 16, CV_8UC1); - cv::Mat dst; - cv::subtract(src1, src2, dst, cv::noArray(), CV_16S); - ASSERT_FALSE(dst.empty()); - ASSERT_EQ(0, cv::countNonZero(dst)); + cv::Mat dst1, dst2, dst3; + + cv::subtract(src1, src2, dst1, cv::noArray(), CV_16S); + cv::subtract(src1, src2, dst2); + cv::subtract(src1, cv::Scalar::all(0), dst3, cv::noArray(), CV_16S); + + ASSERT_FALSE(dst1.empty()); + ASSERT_FALSE(dst2.empty()); + ASSERT_FALSE(dst3.empty()); + + ASSERT_EQ(0, cv::countNonZero(dst1)); + ASSERT_EQ(0, cv::countNonZero(dst2)); + ASSERT_EQ(0, cv::countNonZero(dst3)); } From ca40d635e41f2a8bde27458d5d8fe78942820d1a Mon Sep 17 00:00:00 2001 From: Hernan Badino Date: Mon, 19 May 2014 10:12:07 -0400 Subject: [PATCH 069/662] Switched insertion of connected components in filterSpecklesImpl --- modules/calib3d/src/stereosgbm.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/calib3d/src/stereosgbm.cpp b/modules/calib3d/src/stereosgbm.cpp index 0de9189b9e..01661813a2 100644 --- a/modules/calib3d/src/stereosgbm.cpp +++ b/modules/calib3d/src/stereosgbm.cpp @@ -913,18 +913,6 @@ namespace T dp = *dpp; int* lpp = labels + width*p.y + p.x; - if( p.x < width-1 && !lpp[+1] && dpp[+1] != newVal && std::abs(dp - dpp[+1]) <= maxDiff ) - { - lpp[+1] = curlabel; - *ws++ = Point2s(p.x+1, p.y); - } - - if( p.x > 0 && !lpp[-1] && dpp[-1] != newVal && std::abs(dp - dpp[-1]) <= maxDiff ) - { - lpp[-1] = curlabel; - *ws++ = Point2s(p.x-1, p.y); - } - if( p.y < height-1 && !lpp[+width] && dpp[+dstep] != newVal && std::abs(dp - dpp[+dstep]) <= maxDiff ) { lpp[+width] = curlabel; @@ -937,6 +925,18 @@ namespace *ws++ = Point2s(p.x, p.y-1); } + if( p.x < width-1 && !lpp[+1] && dpp[+1] != newVal && std::abs(dp - dpp[+1]) <= maxDiff ) + { + lpp[+1] = curlabel; + *ws++ = Point2s(p.x+1, p.y); + } + + if( p.x > 0 && !lpp[-1] && dpp[-1] != newVal && std::abs(dp - dpp[-1]) <= maxDiff ) + { + lpp[-1] = curlabel; + *ws++ = Point2s(p.x-1, p.y); + } + // pop most recent and propagate // NB: could try least recent, maybe better convergence p = *--ws; From 1020a93fa36ac4470ef426d2d4de0070e5fca881 Mon Sep 17 00:00:00 2001 From: aletheios Date: Sat, 31 May 2014 18:44:32 +0200 Subject: [PATCH 070/662] Bugfix #3705: params.setRecordingHint(true) breaks camera preview on Samsung Galaxy S2 --- modules/java/generator/src/java/android+JavaCameraView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/java/generator/src/java/android+JavaCameraView.java b/modules/java/generator/src/java/android+JavaCameraView.java index c29ba2b6f0..95bdc01f4a 100644 --- a/modules/java/generator/src/java/android+JavaCameraView.java +++ b/modules/java/generator/src/java/android+JavaCameraView.java @@ -146,7 +146,7 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb Log.d(TAG, "Set preview size to " + Integer.valueOf((int)frameSize.width) + "x" + Integer.valueOf((int)frameSize.height)); params.setPreviewSize((int)frameSize.width, (int)frameSize.height); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && !android.os.Build.MODEL.equals("GT-I9100")) params.setRecordingHint(true); List FocusModes = params.getSupportedFocusModes(); From cd3aa0184afd2b857c171f88eb5c314dc0b29e59 Mon Sep 17 00:00:00 2001 From: Ehren Metcalfe Date: Sat, 31 May 2014 19:41:16 -0400 Subject: [PATCH 071/662] Fix resource leak with iOS camera due to failure to remove AVCaptureSession input/outputs on stop (Bug #3389) --- modules/highgui/src/cap_ios_abstract_camera.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/highgui/src/cap_ios_abstract_camera.mm b/modules/highgui/src/cap_ios_abstract_camera.mm index b40b3648de..663609e0e1 100644 --- a/modules/highgui/src/cap_ios_abstract_camera.mm +++ b/modules/highgui/src/cap_ios_abstract_camera.mm @@ -193,6 +193,14 @@ // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; + for (AVCaptureInput *input in self.captureSession.inputs) { + [self.captureSession removeInput:input]; + } + + for (AVCaptureOutput *output in self.captureSession.outputs) { + [self.captureSession removeOutput:output]; + } + [self.captureSession stopRunning]; self.captureSession = nil; self.captureVideoPreviewLayer = nil; From 1a1cd9b4e963f3cb8b7e90eac80cf69319b0aa0d Mon Sep 17 00:00:00 2001 From: Aleksandr Petrikov Date: Wed, 4 Jun 2014 12:06:33 +0400 Subject: [PATCH 072/662] add NEON realization for StereoBM(findCorrespondence, prefilterXSobel) --- modules/calib3d/src/stereobm.cpp | 163 ++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-) diff --git a/modules/calib3d/src/stereobm.cpp b/modules/calib3d/src/stereobm.cpp index 623883df74..4a978eb14e 100644 --- a/modules/calib3d/src/stereobm.cpp +++ b/modules/calib3d/src/stereobm.cpp @@ -224,6 +224,42 @@ prefilterXSobel( const Mat& src, Mat& dst, int ftzero ) } } #endif + #if CV_NEON + int16x8_t ftz = vdupq_n_s16 ((short) ftzero); + uint8x8_t ftz2 = vdup_n_u8 (cv::saturate_cast(ftzero*2)); + + for(; x <=size.width-9; x += 8 ) + { + uint8x8_t c0 = vld1_u8 (srow0 + x - 1); + uint8x8_t c1 = vld1_u8 (srow1 + x - 1); + uint8x8_t d0 = vld1_u8 (srow0 + x + 1); + uint8x8_t d1 = vld1_u8 (srow1 + x + 1); + + int16x8_t t0 = vreinterpretq_s16_u16 (vsubl_u8 (d0, c0)); + int16x8_t t1 = vreinterpretq_s16_u16 (vsubl_u8 (d1, c1)); + + uint8x8_t c2 = vld1_u8 (srow2 + x - 1); + uint8x8_t c3 = vld1_u8 (srow3 + x - 1); + uint8x8_t d2 = vld1_u8 (srow2 + x + 1); + uint8x8_t d3 = vld1_u8 (srow3 + x + 1); + + int16x8_t t2 = vreinterpretq_s16_u16 (vsubl_u8 (d2, c2)); + int16x8_t t3 = vreinterpretq_s16_u16 (vsubl_u8 (d3, c3)); + + int16x8_t v0 = vaddq_s16 (vaddq_s16 (t2, t0), vaddq_s16 (t1, t1)); + int16x8_t v1 = vaddq_s16 (vaddq_s16 (t3, t1), vaddq_s16 (t2, t2)); + + + uint8x8_t v0_u8 = vqmovun_s16 (vaddq_s16 (v0, ftz)); + uint8x8_t v1_u8 = vqmovun_s16 (vaddq_s16 (v1, ftz)); + v0_u8 = vmin_u8 (v0_u8, ftz2); + v1_u8 = vmin_u8 (v1_u8, ftz2); + vqmovun_s16 (vaddq_s16 (v1, ftz)); + + vst1_u8 (dptr0 + x, v0_u8); + vst1_u8 (dptr1 + x, v1_u8); + } + #endif for( ; x < size.width-1; x++ ) { @@ -236,10 +272,19 @@ prefilterXSobel( const Mat& src, Mat& dst, int ftzero ) } } +#if CV_NEON + uint8x16_t val0_16 = vdupq_n_u8 (val0); +#endif + for( ; y < size.height; y++ ) { uchar* dptr = dst.ptr(y); - for( x = 0; x < size.width; x++ ) + x = 0; + #if CV_NEON + for(; x <= size.width-16; x+=16 ) + vst1q_u8 (dptr + x, val0_16); + #endif + for(; x < size.width; x++ ) dptr[x] = val0; } } @@ -510,6 +555,15 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, Mat& disp, Mat& cost, const CvStereoBMState& state, uchar* buf, int _dy0, int _dy1 ) { + +#if CV_NEON + int32_t d0_4_temp [4]; + for (int i = 0; i < 4; i ++) + d0_4_temp[i] = i; + int32x4_t d0_4 = vld1q_s32 (d0_4_temp); + int32x4_t dd_4 = vdupq_n_s32 (4); +#endif + const int ALIGN = 16; int x, y, d; int wsz = state.SADWindowSize, wsz2 = wsz/2; @@ -560,12 +614,29 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, for( y = -dy0; y < height + dy1; y++, hsad += ndisp, cbuf += ndisp, lptr += sstep, rptr += sstep ) { int lval = lptr[0]; + #if CV_NEON + int16x8_t lv = vdupq_n_s16 ((int16_t)lval); + + for( d = 0; d < ndisp; d += 8 ) + { + int16x8_t rv = vreinterpretq_s16_u16 (vmovl_u8 (vld1_u8 (rptr + d))); + int32x4_t hsad_l = vld1q_s32 (hsad + d); + int32x4_t hsad_h = vld1q_s32 (hsad + d + 4); + int16x8_t diff = vabdq_s16 (lv, rv); + vst1_u8 (cbuf + d, vmovn_u16(vreinterpretq_u16_s16(diff))); + hsad_l = vaddq_s32 (hsad_l, vmovl_s16(vget_low_s16 (diff))); + hsad_h = vaddq_s32 (hsad_h, vmovl_s16(vget_high_s16 (diff))); + vst1q_s32 ((hsad + d), hsad_l); + vst1q_s32 ((hsad + d + 4), hsad_h); + } + #else for( d = 0; d < ndisp; d++ ) { int diff = std::abs(lval - rptr[d]); cbuf[d] = (uchar)diff; hsad[d] = (int)(hsad[d] + diff); } + #endif htext[y] += tab[lval]; } } @@ -595,12 +666,31 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, hsad += ndisp, lptr += sstep, lptr_sub += sstep, rptr += sstep ) { int lval = lptr[0]; + #if CV_NEON + int16x8_t lv = vdupq_n_s16 ((int16_t)lval); + for( d = 0; d < ndisp; d += 8 ) + { + int16x8_t rv = vreinterpretq_s16_u16 (vmovl_u8 (vld1_u8 (rptr + d))); + int32x4_t hsad_l = vld1q_s32 (hsad + d); + int32x4_t hsad_h = vld1q_s32 (hsad + d + 4); + int16x8_t cbs = vreinterpretq_s16_u16 (vmovl_u8 (vld1_u8 (cbuf_sub + d))); + int16x8_t diff = vabdq_s16 (lv, rv); + int32x4_t diff_h = vsubl_s16 (vget_high_s16 (diff), vget_high_s16 (cbs)); + int32x4_t diff_l = vsubl_s16 (vget_low_s16 (diff), vget_low_s16 (cbs)); + vst1_u8 (cbuf + d, vmovn_u16(vreinterpretq_u16_s16(diff))); + hsad_h = vaddq_s32 (hsad_h, diff_h); + hsad_l = vaddq_s32 (hsad_l, diff_l); + vst1q_s32 ((hsad + d), hsad_l); + vst1q_s32 ((hsad + d + 4), hsad_h); + } + #else for( d = 0; d < ndisp; d++ ) { int diff = std::abs(lval - rptr[d]); cbuf[d] = (uchar)diff; hsad[d] = hsad[d] + diff - cbuf_sub[d]; } + #endif htext[y] += tab[lval] - tab[lptr_sub[0]]; } @@ -616,8 +706,24 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, hsad = hsad0 + (1 - dy0)*ndisp; for( y = 1 - dy0; y < wsz2; y++, hsad += ndisp ) + { + #if CV_NEON + for( d = 0; d <= ndisp-8; d += 8 ) + { + int32x4_t s0 = vld1q_s32 (sad + d); + int32x4_t s1 = vld1q_s32 (sad + d + 4); + int32x4_t t0 = vld1q_s32 (hsad + d); + int32x4_t t1 = vld1q_s32 (hsad + d + 4); + s0 = vaddq_s32 (s0, t0); + s1 = vaddq_s32 (s1, t1); + vst1q_s32 (sad + d, s0); + vst1q_s32 (sad + d + 4, s1); + } + #else for( d = 0; d < ndisp; d++ ) sad[d] = (int)(sad[d] + hsad[d]); + #endif + } int tsum = 0; for( y = -wsz2-1; y < wsz2; y++ ) tsum += htext[y]; @@ -628,7 +734,61 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, int minsad = INT_MAX, mind = -1; hsad = hsad0 + MIN(y + wsz2, height+dy1-1)*ndisp; hsad_sub = hsad0 + MAX(y - wsz2 - 1, -dy0)*ndisp; + #if CV_NEON + int32x4_t minsad4 = vdupq_n_s32 (INT_MAX); + int32x4_t mind4 = vdupq_n_s32(0), d4 = d0_4; + for( d = 0; d <= ndisp-8; d += 8 ) + { + int32x4_t u0 = vld1q_s32 (hsad_sub + d); + int32x4_t u1 = vld1q_s32 (hsad + d); + + int32x4_t v0 = vld1q_s32 (hsad_sub + d + 4); + int32x4_t v1 = vld1q_s32 (hsad + d + 4); + + int32x4_t usad4 = vld1q_s32(sad + d); + int32x4_t vsad4 = vld1q_s32(sad + d + 4); + + u1 = vsubq_s32 (u1, u0); + v1 = vsubq_s32 (v1, v0); + usad4 = vaddq_s32 (usad4, u1); + vsad4 = vaddq_s32 (vsad4, v1); + + uint32x4_t mask = vcgtq_s32 (minsad4, usad4); + minsad4 = vminq_s32 (minsad4, usad4); + mind4 = vbslq_s32(mask, d4, mind4); + + vst1q_s32 (sad + d, usad4); + vst1q_s32 (sad + d + 4, vsad4); + d4 = vaddq_s32 (d4, dd_4); + + mask = vcgtq_s32 (minsad4, vsad4); + minsad4 = vminq_s32 (minsad4, vsad4); + mind4 = vbslq_s32(mask, d4, mind4); + + d4 = vaddq_s32 (d4, dd_4); + + } + int32x2_t mind4_h = vget_high_s32 (mind4); + int32x2_t mind4_l = vget_low_s32 (mind4); + int32x2_t minsad4_h = vget_high_s32 (minsad4); + int32x2_t minsad4_l = vget_low_s32 (minsad4); + + uint32x2_t mask = vorr_u32 (vclt_s32 (minsad4_h, minsad4_l), vand_u32 (vceq_s32 (minsad4_h, minsad4_l), vclt_s32 (mind4_h, mind4_l))); + mind4_h = vbsl_s32 (mask, mind4_h, mind4_l); + minsad4_h = vbsl_s32 (mask, minsad4_h, minsad4_l); + + mind4_l = vext_s32 (mind4_h,mind4_h,1); + minsad4_l = vext_s32 (minsad4_h,minsad4_h,1); + + mask = vorr_u32 (vclt_s32 (minsad4_h, minsad4_l), vand_u32 (vceq_s32 (minsad4_h, minsad4_l), vclt_s32 (mind4_h, mind4_l))); + mind4_h = vbsl_s32 (mask, mind4_h, mind4_l); + minsad4_h = vbsl_s32 (mask, minsad4_h, minsad4_l); + + mind = (int) vget_lane_s32 (mind4_h, 0); + minsad = sad[mind]; + + #else for( d = 0; d < ndisp; d++ ) { int currsad = sad[d] + hsad[d] - hsad_sub[d]; @@ -639,6 +799,7 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, mind = d; } } + #endif tsum += htext[y + wsz2] - htext[y - wsz2 - 1]; if( tsum < textureThreshold ) { From 11a09ef5ccda32b166b7384949f485ec053e3ba5 Mon Sep 17 00:00:00 2001 From: Richard Yoo Date: Fri, 6 Jun 2014 13:37:13 -0700 Subject: [PATCH 073/662] Changes to support Intel AVX/AVX2 in cvResize(). --- CMakeLists.txt | 1 + cmake/OpenCVCompilerOptions.cmake | 14 +- modules/core/include/opencv2/core/core_c.h | 1 + .../core/include/opencv2/core/internal.hpp | 7 + modules/core/src/system.cpp | 35 + modules/imgproc/src/imgwarp.cpp | 1264 ++++++++++++----- modules/ts/src/ts_func.cpp | 3 + 7 files changed, 1005 insertions(+), 320 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b610ecf971..50e6cd0230 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,6 +217,7 @@ OCV_OPTION(ENABLE_SSSE3 "Enable SSSE3 instructions" OCV_OPTION(ENABLE_SSE41 "Enable SSE4.1 instructions" OFF IF ((CV_ICC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_SSE42 "Enable SSE4.2 instructions" OFF IF (CMAKE_COMPILER_IS_GNUCXX AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_AVX "Enable AVX instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) ) +OCV_OPTION(ENABLE_AVX2 "Enable AVX2 instructions" OFF IF ((MSVC OR CMAKE_COMPILER_IS_GNUCXX) AND (X86 OR X86_64)) ) OCV_OPTION(ENABLE_NEON "Enable NEON instructions" OFF IF CMAKE_COMPILER_IS_GNUCXX AND ARM ) OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF CMAKE_COMPILER_IS_GNUCXX AND ARM ) OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF ) diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index d525609d18..f28aaeed50 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -143,8 +143,12 @@ if(CMAKE_COMPILER_IS_GNUCXX) add_extra_compiler_option(-mavx) endif() + if(ENABLE_AVX2) + add_extra_compiler_option(-mavx2) + endif() + # GCC depresses SSEx instructions when -mavx is used. Instead, it generates new AVX instructions or AVX equivalence for all SSEx instructions when needed. - if(NOT OPENCV_EXTRA_CXX_FLAGS MATCHES "-mavx") + if(NOT OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(avx|avx2)") if(ENABLE_SSE3) add_extra_compiler_option(-msse3) endif() @@ -165,7 +169,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) if(X86 OR X86_64) if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) - if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx)") + if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx|avx2)") add_extra_compiler_option(-mfpmath=sse)# !! important - be on the same wave with x64 compilers else() add_extra_compiler_option(-mfpmath=387) @@ -220,6 +224,10 @@ if(MSVC) set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /arch:AVX") endif() + if(ENABLE_AVX2 AND NOT MSVC_VERSION LESS 1800) + set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /arch:AVX2") + endif() + if(ENABLE_SSE4_1 AND CV_ICC AND NOT OPENCV_EXTRA_FLAGS MATCHES "/arch:") set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /arch:SSE4.1") endif() @@ -238,7 +246,7 @@ if(MSVC) endif() endif() - if(ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1 OR ENABLE_AVX) + if(ENABLE_SSE OR ENABLE_SSE2 OR ENABLE_SSE3 OR ENABLE_SSE4_1 OR ENABLE_AVX OR ENABLE_AVX2) set(OPENCV_EXTRA_FLAGS "${OPENCV_EXTRA_FLAGS} /Oi") endif() diff --git a/modules/core/include/opencv2/core/core_c.h b/modules/core/include/opencv2/core/core_c.h index 38abfc409b..b108e3498e 100644 --- a/modules/core/include/opencv2/core/core_c.h +++ b/modules/core/include/opencv2/core/core_c.h @@ -1706,6 +1706,7 @@ CVAPI(double) cvGetTickFrequency( void ); #define CV_CPU_SSE4_2 7 #define CV_CPU_POPCNT 8 #define CV_CPU_AVX 10 +#define CV_CPU_AVX2 11 #define CV_HARDWARE_MAX_FEATURE 255 CVAPI(int) cvCheckHardwareSupport(int feature); diff --git a/modules/core/include/opencv2/core/internal.hpp b/modules/core/include/opencv2/core/internal.hpp index 6c9d3d2f13..9959c169ac 100644 --- a/modules/core/include/opencv2/core/internal.hpp +++ b/modules/core/include/opencv2/core/internal.hpp @@ -141,6 +141,10 @@ CV_INLINE IppiSize ippiSize(const cv::Size & _size) # define __xgetbv() 0 # endif # endif +# if defined __AVX2__ +# include +# define CV_AVX2 1 +# endif #endif @@ -176,6 +180,9 @@ CV_INLINE IppiSize ippiSize(const cv::Size & _size) #ifndef CV_AVX # define CV_AVX 0 #endif +#ifndef CV_AVX2 +# define CV_AVX2 0 +#endif #ifndef CV_NEON # define CV_NEON 0 #endif diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 68aff531f1..40d64ffe1b 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -253,6 +253,41 @@ struct HWFeatures f.have[CV_CPU_AVX] = (((cpuid_data[2] & (1<<28)) != 0)&&((cpuid_data[2] & (1<<27)) != 0));//OS uses XSAVE_XRSTORE and CPU support AVX } +#if CV_AVX2 + #if defined _MSC_VER && (defined _M_IX86 || defined _M_X64) + __cpuidex(cpuid_data, 7, 0); + #elif defined __GNUC__ && (defined __i386__ || defined __x86_64__) + #ifdef __x86_64__ + asm __volatile__ + ( + "movl $7, %%eax\n\t" + "movl $0, %%ecx\n\t" + "cpuid\n\t" + :[eax]"=a"(cpuid_data[0]),[ebx]"=b"(cpuid_data[1]),[ecx]"=c"(cpuid_data[2]),[edx]"=d"(cpuid_data[3]) + : + : "cc" + ); + #else + asm volatile + ( + "pushl %%ebx\n\t" + "movl $7,%%eax\n\t" + "movl $0,%%ecx\n\t" + "cpuid\n\t" + "popl %%ebx\n\t" + : "=a"(cpuid_data[0]), "=b"(cpuid_data[1]), "=c"(cpuid_data[2]), "=d"(cpuid_data[3]) + : + : "cc" + ); + #endif + #endif + + if( f.x86_family >= 6 ) + { + f.have[CV_CPU_AVX2] = (cpuid_data[1] & (1<<5)) != 0; + } +#endif + return f; } diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index dcd718fb68..88b278710d 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -54,6 +54,10 @@ static IppStatus sts = ippInit(); #endif +#ifdef _MSC_VER +# pragma warning(disable:4752) // Disable warning for mixing SSE and AVX +#endif + namespace cv { @@ -451,350 +455,741 @@ struct HResizeNoVec #if CV_SSE2 +static int VResizeLinearVec_32s8u_sse2(const uchar** _src, uchar* dst, const uchar* _beta, int width) +{ + const int** src = (const int**)_src; + const short* beta = (const short*)_beta; + const int *S0 = src[0], *S1 = src[1]; + int x = 0; + __m128i b0 = _mm_set1_epi16(beta[0]), b1 = _mm_set1_epi16(beta[1]); + __m128i delta = _mm_set1_epi16(2); + + if( (((size_t)S0|(size_t)S1)&15) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m128i x0, x1, x2, y0, y1, y2; + x0 = _mm_load_si128((const __m128i*)(S0 + x)); + x1 = _mm_load_si128((const __m128i*)(S0 + x + 4)); + y0 = _mm_load_si128((const __m128i*)(S1 + x)); + y1 = _mm_load_si128((const __m128i*)(S1 + x + 4)); + x0 = _mm_packs_epi32(_mm_srai_epi32(x0, 4), _mm_srai_epi32(x1, 4)); + y0 = _mm_packs_epi32(_mm_srai_epi32(y0, 4), _mm_srai_epi32(y1, 4)); + + x1 = _mm_load_si128((const __m128i*)(S0 + x + 8)); + x2 = _mm_load_si128((const __m128i*)(S0 + x + 12)); + y1 = _mm_load_si128((const __m128i*)(S1 + x + 8)); + y2 = _mm_load_si128((const __m128i*)(S1 + x + 12)); + x1 = _mm_packs_epi32(_mm_srai_epi32(x1, 4), _mm_srai_epi32(x2, 4)); + y1 = _mm_packs_epi32(_mm_srai_epi32(y1, 4), _mm_srai_epi32(y2, 4)); + + x0 = _mm_adds_epi16(_mm_mulhi_epi16( x0, b0 ), _mm_mulhi_epi16( y0, b1 )); + x1 = _mm_adds_epi16(_mm_mulhi_epi16( x1, b0 ), _mm_mulhi_epi16( y1, b1 )); + + x0 = _mm_srai_epi16(_mm_adds_epi16(x0, delta), 2); + x1 = _mm_srai_epi16(_mm_adds_epi16(x1, delta), 2); + _mm_storeu_si128( (__m128i*)(dst + x), _mm_packus_epi16(x0, x1)); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m128i x0, x1, x2, y0, y1, y2; + x0 = _mm_loadu_si128((const __m128i*)(S0 + x)); + x1 = _mm_loadu_si128((const __m128i*)(S0 + x + 4)); + y0 = _mm_loadu_si128((const __m128i*)(S1 + x)); + y1 = _mm_loadu_si128((const __m128i*)(S1 + x + 4)); + x0 = _mm_packs_epi32(_mm_srai_epi32(x0, 4), _mm_srai_epi32(x1, 4)); + y0 = _mm_packs_epi32(_mm_srai_epi32(y0, 4), _mm_srai_epi32(y1, 4)); + + x1 = _mm_loadu_si128((const __m128i*)(S0 + x + 8)); + x2 = _mm_loadu_si128((const __m128i*)(S0 + x + 12)); + y1 = _mm_loadu_si128((const __m128i*)(S1 + x + 8)); + y2 = _mm_loadu_si128((const __m128i*)(S1 + x + 12)); + x1 = _mm_packs_epi32(_mm_srai_epi32(x1, 4), _mm_srai_epi32(x2, 4)); + y1 = _mm_packs_epi32(_mm_srai_epi32(y1, 4), _mm_srai_epi32(y2, 4)); + + x0 = _mm_adds_epi16(_mm_mulhi_epi16( x0, b0 ), _mm_mulhi_epi16( y0, b1 )); + x1 = _mm_adds_epi16(_mm_mulhi_epi16( x1, b0 ), _mm_mulhi_epi16( y1, b1 )); + + x0 = _mm_srai_epi16(_mm_adds_epi16(x0, delta), 2); + x1 = _mm_srai_epi16(_mm_adds_epi16(x1, delta), 2); + _mm_storeu_si128( (__m128i*)(dst + x), _mm_packus_epi16(x0, x1)); + } + + for( ; x < width - 4; x += 4 ) + { + __m128i x0, y0; + x0 = _mm_srai_epi32(_mm_loadu_si128((const __m128i*)(S0 + x)), 4); + y0 = _mm_srai_epi32(_mm_loadu_si128((const __m128i*)(S1 + x)), 4); + x0 = _mm_packs_epi32(x0, x0); + y0 = _mm_packs_epi32(y0, y0); + x0 = _mm_adds_epi16(_mm_mulhi_epi16(x0, b0), _mm_mulhi_epi16(y0, b1)); + x0 = _mm_srai_epi16(_mm_adds_epi16(x0, delta), 2); + x0 = _mm_packus_epi16(x0, x0); + *(int*)(dst + x) = _mm_cvtsi128_si32(x0); + } + + return x; +} + +#if CV_AVX2 +int VResizeLinearVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) +{ + const int** src = (const int**)_src; + const short* beta = (const short*)_beta; + const int *S0 = src[0], *S1 = src[1]; + int x = 0; + __m256i b0 = _mm256_set1_epi16(beta[0]), b1 = _mm256_set1_epi16(beta[1]); + __m256i delta = _mm256_set1_epi16(2); + const int index[8] = { 0, 4, 1, 5, 2, 6, 3, 7 }; + __m256i shuffle = _mm256_load_si256((const __m256i*)index); + + if( (((size_t)S0|(size_t)S1)&31) == 0 ) + for( ; x <= width - 32; x += 32 ) + { + __m256i x0, x1, x2, y0, y1, y2; + x0 = _mm256_load_si256((const __m256i*)(S0 + x)); + x1 = _mm256_load_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_load_si256((const __m256i*)(S1 + x)); + y1 = _mm256_load_si256((const __m256i*)(S1 + x + 8)); + x0 = _mm256_packs_epi32(_mm256_srai_epi32(x0, 4), _mm256_srai_epi32(x1, 4)); + y0 = _mm256_packs_epi32(_mm256_srai_epi32(y0, 4), _mm256_srai_epi32(y1, 4)); + + x1 = _mm256_load_si256((const __m256i*)(S0 + x + 16)); + x2 = _mm256_load_si256((const __m256i*)(S0 + x + 24)); + y1 = _mm256_load_si256((const __m256i*)(S1 + x + 16)); + y2 = _mm256_load_si256((const __m256i*)(S1 + x + 24)); + x1 = _mm256_packs_epi32(_mm256_srai_epi32(x1, 4), _mm256_srai_epi32(x2, 4)); + y1 = _mm256_packs_epi32(_mm256_srai_epi32(y1, 4), _mm256_srai_epi32(y2, 4)); + + x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); + x1 = _mm256_adds_epi16(_mm256_mulhi_epi16(x1, b0), _mm256_mulhi_epi16(y1, b1)); + + x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); + x1 = _mm256_srai_epi16(_mm256_adds_epi16(x1, delta), 2); + x0 = _mm256_packus_epi16(x0, x1); + x0 = _mm256_permutevar8x32_epi32(x0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), x0); + } + else + for( ; x <= width - 32; x += 32 ) + { + __m256i x0, x1, x2, y0, y1, y2; + x0 = _mm256_loadu_si256((const __m256i*)(S0 + x)); + x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_loadu_si256((const __m256i*)(S1 + x)); + y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 8)); + x0 = _mm256_packs_epi32(_mm256_srai_epi32(x0, 4), _mm256_srai_epi32(x1, 4)); + y0 = _mm256_packs_epi32(_mm256_srai_epi32(y0, 4), _mm256_srai_epi32(y1, 4)); + + x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 16)); + x2 = _mm256_loadu_si256((const __m256i*)(S0 + x + 24)); + y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 16)); + y2 = _mm256_loadu_si256((const __m256i*)(S1 + x + 24)); + x1 = _mm256_packs_epi32(_mm256_srai_epi32(x1, 4), _mm256_srai_epi32(x2, 4)); + y1 = _mm256_packs_epi32(_mm256_srai_epi32(y1, 4), _mm256_srai_epi32(y2, 4)); + + x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); + x1 = _mm256_adds_epi16(_mm256_mulhi_epi16(x1, b0), _mm256_mulhi_epi16(y1, b1)); + + x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); + x1 = _mm256_srai_epi16(_mm256_adds_epi16(x1, delta), 2); + x0 = _mm256_packus_epi16(x0, x1); + x0 = _mm256_permutevar8x32_epi32(x0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), x0); + } + + for( ; x < width - 8; x += 8 ) + { + __m256i x0, y0; + x0 = _mm256_srai_epi32(_mm256_loadu_si256((const __m256i*)(S0 + x)), 4); + y0 = _mm256_srai_epi32(_mm256_loadu_si256((const __m256i*)(S1 + x)), 4); + x0 = _mm256_packs_epi32(x0, x0); + y0 = _mm256_packs_epi32(y0, y0); + x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); + x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); + x0 = _mm256_packus_epi16(x0, x0); + *(int*)(dst + x) = _mm_cvtsi128_si32(_mm256_extracti128_si256(x0, 0)); + *(int*)(dst + x + 4) = _mm_cvtsi128_si32(_mm256_extracti128_si256(x0, 1)); + } + + return x; +} +#endif + struct VResizeLinearVec_32s8u { int operator()(const uchar** _src, uchar* dst, const uchar* _beta, int width ) const { - if( !checkHardwareSupport(CV_CPU_SSE2) ) - return 0; +#if CV_AVX2 + if( checkHardwareSupport(CV_CPU_AVX2) ) + return VResizeLinearVec_32s8u_avx2(_src, dst, _beta, width); +#endif + if( checkHardwareSupport(CV_CPU_SSE2) ) + return VResizeLinearVec_32s8u_sse2(_src, dst, _beta, width); - const int** src = (const int**)_src; - const short* beta = (const short*)_beta; - const int *S0 = src[0], *S1 = src[1]; - int x = 0; - __m128i b0 = _mm_set1_epi16(beta[0]), b1 = _mm_set1_epi16(beta[1]); - __m128i delta = _mm_set1_epi16(2); - - if( (((size_t)S0|(size_t)S1)&15) == 0 ) - for( ; x <= width - 16; x += 16 ) - { - __m128i x0, x1, x2, y0, y1, y2; - x0 = _mm_load_si128((const __m128i*)(S0 + x)); - x1 = _mm_load_si128((const __m128i*)(S0 + x + 4)); - y0 = _mm_load_si128((const __m128i*)(S1 + x)); - y1 = _mm_load_si128((const __m128i*)(S1 + x + 4)); - x0 = _mm_packs_epi32(_mm_srai_epi32(x0, 4), _mm_srai_epi32(x1, 4)); - y0 = _mm_packs_epi32(_mm_srai_epi32(y0, 4), _mm_srai_epi32(y1, 4)); - - x1 = _mm_load_si128((const __m128i*)(S0 + x + 8)); - x2 = _mm_load_si128((const __m128i*)(S0 + x + 12)); - y1 = _mm_load_si128((const __m128i*)(S1 + x + 8)); - y2 = _mm_load_si128((const __m128i*)(S1 + x + 12)); - x1 = _mm_packs_epi32(_mm_srai_epi32(x1, 4), _mm_srai_epi32(x2, 4)); - y1 = _mm_packs_epi32(_mm_srai_epi32(y1, 4), _mm_srai_epi32(y2, 4)); - - x0 = _mm_adds_epi16(_mm_mulhi_epi16( x0, b0 ), _mm_mulhi_epi16( y0, b1 )); - x1 = _mm_adds_epi16(_mm_mulhi_epi16( x1, b0 ), _mm_mulhi_epi16( y1, b1 )); - - x0 = _mm_srai_epi16(_mm_adds_epi16(x0, delta), 2); - x1 = _mm_srai_epi16(_mm_adds_epi16(x1, delta), 2); - _mm_storeu_si128( (__m128i*)(dst + x), _mm_packus_epi16(x0, x1)); - } - else - for( ; x <= width - 16; x += 16 ) - { - __m128i x0, x1, x2, y0, y1, y2; - x0 = _mm_loadu_si128((const __m128i*)(S0 + x)); - x1 = _mm_loadu_si128((const __m128i*)(S0 + x + 4)); - y0 = _mm_loadu_si128((const __m128i*)(S1 + x)); - y1 = _mm_loadu_si128((const __m128i*)(S1 + x + 4)); - x0 = _mm_packs_epi32(_mm_srai_epi32(x0, 4), _mm_srai_epi32(x1, 4)); - y0 = _mm_packs_epi32(_mm_srai_epi32(y0, 4), _mm_srai_epi32(y1, 4)); - - x1 = _mm_loadu_si128((const __m128i*)(S0 + x + 8)); - x2 = _mm_loadu_si128((const __m128i*)(S0 + x + 12)); - y1 = _mm_loadu_si128((const __m128i*)(S1 + x + 8)); - y2 = _mm_loadu_si128((const __m128i*)(S1 + x + 12)); - x1 = _mm_packs_epi32(_mm_srai_epi32(x1, 4), _mm_srai_epi32(x2, 4)); - y1 = _mm_packs_epi32(_mm_srai_epi32(y1, 4), _mm_srai_epi32(y2, 4)); - - x0 = _mm_adds_epi16(_mm_mulhi_epi16( x0, b0 ), _mm_mulhi_epi16( y0, b1 )); - x1 = _mm_adds_epi16(_mm_mulhi_epi16( x1, b0 ), _mm_mulhi_epi16( y1, b1 )); - - x0 = _mm_srai_epi16(_mm_adds_epi16(x0, delta), 2); - x1 = _mm_srai_epi16(_mm_adds_epi16(x1, delta), 2); - _mm_storeu_si128( (__m128i*)(dst + x), _mm_packus_epi16(x0, x1)); - } - - for( ; x < width - 4; x += 4 ) - { - __m128i x0, y0; - x0 = _mm_srai_epi32(_mm_loadu_si128((const __m128i*)(S0 + x)), 4); - y0 = _mm_srai_epi32(_mm_loadu_si128((const __m128i*)(S1 + x)), 4); - x0 = _mm_packs_epi32(x0, x0); - y0 = _mm_packs_epi32(y0, y0); - x0 = _mm_adds_epi16(_mm_mulhi_epi16(x0, b0), _mm_mulhi_epi16(y0, b1)); - x0 = _mm_srai_epi16(_mm_adds_epi16(x0, delta), 2); - x0 = _mm_packus_epi16(x0, x0); - *(int*)(dst + x) = _mm_cvtsi128_si32(x0); - } - - return x; + return 0; } }; +template +int VResizeLinearVec_32f16_sse2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1]; + ushort* dst = (ushort*)_dst; + int x = 0; + + __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]); + __m128i preshift = _mm_set1_epi32(shiftval); + __m128i postshift = _mm_set1_epi16((short)shiftval); + + if( (((size_t)S0|(size_t)S1)&15) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m128 x0, x1, y0, y1; + __m128i t0, t1, t2; + x0 = _mm_load_ps(S0 + x); + x1 = _mm_load_ps(S0 + x + 4); + y0 = _mm_load_ps(S1 + x); + y1 = _mm_load_ps(S1 + x + 4); + + x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); + x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); + t0 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); + t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); + t0 = _mm_add_epi16(_mm_packs_epi32(t0, t2), postshift); + + x0 = _mm_load_ps(S0 + x + 8); + x1 = _mm_load_ps(S0 + x + 12); + y0 = _mm_load_ps(S1 + x + 8); + y1 = _mm_load_ps(S1 + x + 12); + + x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); + x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); + t1 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); + t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); + t1 = _mm_add_epi16(_mm_packs_epi32(t1, t2), postshift); + + _mm_storeu_si128( (__m128i*)(dst + x), t0); + _mm_storeu_si128( (__m128i*)(dst + x + 8), t1); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m128 x0, x1, y0, y1; + __m128i t0, t1, t2; + x0 = _mm_loadu_ps(S0 + x); + x1 = _mm_loadu_ps(S0 + x + 4); + y0 = _mm_loadu_ps(S1 + x); + y1 = _mm_loadu_ps(S1 + x + 4); + + x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); + x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); + t0 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); + t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); + t0 = _mm_add_epi16(_mm_packs_epi32(t0, t2), postshift); + + x0 = _mm_loadu_ps(S0 + x + 8); + x1 = _mm_loadu_ps(S0 + x + 12); + y0 = _mm_loadu_ps(S1 + x + 8); + y1 = _mm_loadu_ps(S1 + x + 12); + + x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); + x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); + t1 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); + t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); + t1 = _mm_add_epi16(_mm_packs_epi32(t1, t2), postshift); + + _mm_storeu_si128( (__m128i*)(dst + x), t0); + _mm_storeu_si128( (__m128i*)(dst + x + 8), t1); + } + + for( ; x < width - 4; x += 4 ) + { + __m128 x0, y0; + __m128i t0; + x0 = _mm_loadu_ps(S0 + x); + y0 = _mm_loadu_ps(S1 + x); + + x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); + t0 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); + t0 = _mm_add_epi16(_mm_packs_epi32(t0, t0), postshift); + _mm_storel_epi64( (__m128i*)(dst + x), t0); + } + + return x; +} + +#if CV_AVX2 +template +int VResizeLinearVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1]; + ushort* dst = (ushort*)_dst; + int x = 0; + + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]); + __m256i preshift = _mm256_set1_epi32(shiftval); + __m256i postshift = _mm256_set1_epi16((short)shiftval); + + if( (((size_t)S0|(size_t)S1)&31) == 0 ) + for( ; x <= width - 32; x += 32 ) + { + __m256 x0, x1, y0, y1; + __m256i t0, t1, t2; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t2), postshift); + + x0 = _mm256_load_ps(S0 + x + 16); + x1 = _mm256_load_ps(S0 + x + 24); + y0 = _mm256_load_ps(S1 + x + 16); + y1 = _mm256_load_ps(S1 + x + 24); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t1 = _mm256_add_epi16(_mm256_packs_epi32(t1, t2), postshift); + + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + _mm256_storeu_si256( (__m256i*)(dst + x + 16), t1); + } + else + for( ; x <= width - 32; x += 32 ) + { + __m256 x0, x1, y0, y1; + __m256i t0, t1, t2; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t2), postshift); + + x0 = _mm256_loadu_ps(S0 + x + 16); + x1 = _mm256_loadu_ps(S0 + x + 24); + y0 = _mm256_loadu_ps(S1 + x + 16); + y1 = _mm256_loadu_ps(S1 + x + 24); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t1 = _mm256_add_epi16(_mm256_packs_epi32(t1, t2), postshift); + + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + _mm256_storeu_si256( (__m256i*)(dst + x + 16), t1); + } + + for( ; x < width - 8; x += 8 ) + { + __m256 x0, y0; + __m256i t0; + x0 = _mm256_loadu_ps(S0 + x); + y0 = _mm256_loadu_ps(S1 + x); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t0), postshift); + _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(t0, 0)); + _mm_storel_epi64( (__m128i*)(dst + x + 4), _mm256_extracti128_si256(t0, 1)); + } + + return x; +} +#endif template struct VResizeLinearVec_32f16 { int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const { - if( !checkHardwareSupport(CV_CPU_SSE2) ) - return 0; +#if CV_AVX2 + if( checkHardwareSupport(CV_CPU_AVX2) ) + return VResizeLinearVec_32f16_avx2(_src, _dst, _beta, width); +#endif + if( checkHardwareSupport(CV_CPU_SSE2) ) + return VResizeLinearVec_32f16_sse2(_src, _dst, _beta, width); - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1]; - ushort* dst = (ushort*)_dst; - int x = 0; - - __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]); - __m128i preshift = _mm_set1_epi32(shiftval); - __m128i postshift = _mm_set1_epi16((short)shiftval); - - if( (((size_t)S0|(size_t)S1)&15) == 0 ) - for( ; x <= width - 16; x += 16 ) - { - __m128 x0, x1, y0, y1; - __m128i t0, t1, t2; - x0 = _mm_load_ps(S0 + x); - x1 = _mm_load_ps(S0 + x + 4); - y0 = _mm_load_ps(S1 + x); - y1 = _mm_load_ps(S1 + x + 4); - - x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); - x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); - t0 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); - t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); - t0 = _mm_add_epi16(_mm_packs_epi32(t0, t2), postshift); - - x0 = _mm_load_ps(S0 + x + 8); - x1 = _mm_load_ps(S0 + x + 12); - y0 = _mm_load_ps(S1 + x + 8); - y1 = _mm_load_ps(S1 + x + 12); - - x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); - x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); - t1 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); - t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); - t1 = _mm_add_epi16(_mm_packs_epi32(t1, t2), postshift); - - _mm_storeu_si128( (__m128i*)(dst + x), t0); - _mm_storeu_si128( (__m128i*)(dst + x + 8), t1); - } - else - for( ; x <= width - 16; x += 16 ) - { - __m128 x0, x1, y0, y1; - __m128i t0, t1, t2; - x0 = _mm_loadu_ps(S0 + x); - x1 = _mm_loadu_ps(S0 + x + 4); - y0 = _mm_loadu_ps(S1 + x); - y1 = _mm_loadu_ps(S1 + x + 4); - - x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); - x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); - t0 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); - t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); - t0 = _mm_add_epi16(_mm_packs_epi32(t0, t2), postshift); - - x0 = _mm_loadu_ps(S0 + x + 8); - x1 = _mm_loadu_ps(S0 + x + 12); - y0 = _mm_loadu_ps(S1 + x + 8); - y1 = _mm_loadu_ps(S1 + x + 12); - - x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); - x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); - t1 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); - t2 = _mm_add_epi32(_mm_cvtps_epi32(x1), preshift); - t1 = _mm_add_epi16(_mm_packs_epi32(t1, t2), postshift); - - _mm_storeu_si128( (__m128i*)(dst + x), t0); - _mm_storeu_si128( (__m128i*)(dst + x + 8), t1); - } - - for( ; x < width - 4; x += 4 ) - { - __m128 x0, y0; - __m128i t0; - x0 = _mm_loadu_ps(S0 + x); - y0 = _mm_loadu_ps(S1 + x); - - x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); - t0 = _mm_add_epi32(_mm_cvtps_epi32(x0), preshift); - t0 = _mm_add_epi16(_mm_packs_epi32(t0, t0), postshift); - _mm_storel_epi64( (__m128i*)(dst + x), t0); - } - - return x; + return 0; } }; typedef VResizeLinearVec_32f16 VResizeLinearVec_32f16u; typedef VResizeLinearVec_32f16<0> VResizeLinearVec_32f16s; +static int VResizeLinearVec_32f_sse(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1]; + float* dst = (float*)_dst; + int x = 0; + + __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]); + + if( (((size_t)S0|(size_t)S1)&15) == 0 ) + for( ; x <= width - 8; x += 8 ) + { + __m128 x0, x1, y0, y1; + x0 = _mm_load_ps(S0 + x); + x1 = _mm_load_ps(S0 + x + 4); + y0 = _mm_load_ps(S1 + x); + y1 = _mm_load_ps(S1 + x + 4); + + x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); + x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); + + _mm_storeu_ps( dst + x, x0); + _mm_storeu_ps( dst + x + 4, x1); + } + else + for( ; x <= width - 8; x += 8 ) + { + __m128 x0, x1, y0, y1; + x0 = _mm_loadu_ps(S0 + x); + x1 = _mm_loadu_ps(S0 + x + 4); + y0 = _mm_loadu_ps(S1 + x); + y1 = _mm_loadu_ps(S1 + x + 4); + + x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); + x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); + + _mm_storeu_ps( dst + x, x0); + _mm_storeu_ps( dst + x + 4, x1); + } + + return x; +} + +#if CV_AVX +int VResizeLinearVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1]; + float* dst = (float*)_dst; + int x = 0; + + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]); + + if( (((size_t)S0|(size_t)S1)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + + _mm256_storeu_ps( dst + x, x0); + _mm256_storeu_ps( dst + x + 8, x1); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + + _mm256_storeu_ps( dst + x, x0); + _mm256_storeu_ps( dst + x + 8, x1); + } + + return x; +} +#endif + struct VResizeLinearVec_32f { int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const { - if( !checkHardwareSupport(CV_CPU_SSE) ) - return 0; +#if CV_AVX + if( checkHardwareSupport(CV_CPU_AVX) ) + return VResizeLinearVec_32f_avx(_src, _dst, _beta, width); +#endif + if( checkHardwareSupport(CV_CPU_SSE) ) + return VResizeLinearVec_32f_sse(_src, _dst, _beta, width); - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1]; - float* dst = (float*)_dst; - int x = 0; - - __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]); - - if( (((size_t)S0|(size_t)S1)&15) == 0 ) - for( ; x <= width - 8; x += 8 ) - { - __m128 x0, x1, y0, y1; - x0 = _mm_load_ps(S0 + x); - x1 = _mm_load_ps(S0 + x + 4); - y0 = _mm_load_ps(S1 + x); - y1 = _mm_load_ps(S1 + x + 4); - - x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); - x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); - - _mm_storeu_ps( dst + x, x0); - _mm_storeu_ps( dst + x + 4, x1); - } - else - for( ; x <= width - 8; x += 8 ) - { - __m128 x0, x1, y0, y1; - x0 = _mm_loadu_ps(S0 + x); - x1 = _mm_loadu_ps(S0 + x + 4); - y0 = _mm_loadu_ps(S1 + x); - y1 = _mm_loadu_ps(S1 + x + 4); - - x0 = _mm_add_ps(_mm_mul_ps(x0, b0), _mm_mul_ps(y0, b1)); - x1 = _mm_add_ps(_mm_mul_ps(x1, b0), _mm_mul_ps(y1, b1)); - - _mm_storeu_ps( dst + x, x0); - _mm_storeu_ps( dst + x + 4, x1); - } - - return x; + return 0; } }; +static int VResizeCubicVec_32s8u_sse2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) +{ + const int** src = (const int**)_src; + const short* beta = (const short*)_beta; + const int *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + int x = 0; + float scale = 1.f/(INTER_RESIZE_COEF_SCALE*INTER_RESIZE_COEF_SCALE); + __m128 b0 = _mm_set1_ps(beta[0]*scale), b1 = _mm_set1_ps(beta[1]*scale), + b2 = _mm_set1_ps(beta[2]*scale), b3 = _mm_set1_ps(beta[3]*scale); + + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&15) == 0 ) + for( ; x <= width - 8; x += 8 ) + { + __m128i x0, x1, y0, y1; + __m128 s0, s1, f0, f1; + x0 = _mm_load_si128((const __m128i*)(S0 + x)); + x1 = _mm_load_si128((const __m128i*)(S0 + x + 4)); + y0 = _mm_load_si128((const __m128i*)(S1 + x)); + y1 = _mm_load_si128((const __m128i*)(S1 + x + 4)); + + s0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b0); + s1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b0); + f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b1); + f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b1); + s0 = _mm_add_ps(s0, f0); + s1 = _mm_add_ps(s1, f1); + + x0 = _mm_load_si128((const __m128i*)(S2 + x)); + x1 = _mm_load_si128((const __m128i*)(S2 + x + 4)); + y0 = _mm_load_si128((const __m128i*)(S3 + x)); + y1 = _mm_load_si128((const __m128i*)(S3 + x + 4)); + + f0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b2); + f1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b2); + s0 = _mm_add_ps(s0, f0); + s1 = _mm_add_ps(s1, f1); + f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b3); + f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b3); + s0 = _mm_add_ps(s0, f0); + s1 = _mm_add_ps(s1, f1); + + x0 = _mm_cvtps_epi32(s0); + x1 = _mm_cvtps_epi32(s1); + + x0 = _mm_packs_epi32(x0, x1); + _mm_storel_epi64( (__m128i*)(dst + x), _mm_packus_epi16(x0, x0)); + } + else + for( ; x <= width - 8; x += 8 ) + { + __m128i x0, x1, y0, y1; + __m128 s0, s1, f0, f1; + x0 = _mm_loadu_si128((const __m128i*)(S0 + x)); + x1 = _mm_loadu_si128((const __m128i*)(S0 + x + 4)); + y0 = _mm_loadu_si128((const __m128i*)(S1 + x)); + y1 = _mm_loadu_si128((const __m128i*)(S1 + x + 4)); + + s0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b0); + s1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b0); + f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b1); + f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b1); + s0 = _mm_add_ps(s0, f0); + s1 = _mm_add_ps(s1, f1); + + x0 = _mm_loadu_si128((const __m128i*)(S2 + x)); + x1 = _mm_loadu_si128((const __m128i*)(S2 + x + 4)); + y0 = _mm_loadu_si128((const __m128i*)(S3 + x)); + y1 = _mm_loadu_si128((const __m128i*)(S3 + x + 4)); + + f0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b2); + f1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b2); + s0 = _mm_add_ps(s0, f0); + s1 = _mm_add_ps(s1, f1); + f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b3); + f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b3); + s0 = _mm_add_ps(s0, f0); + s1 = _mm_add_ps(s1, f1); + + x0 = _mm_cvtps_epi32(s0); + x1 = _mm_cvtps_epi32(s1); + + x0 = _mm_packs_epi32(x0, x1); + _mm_storel_epi64( (__m128i*)(dst + x), _mm_packus_epi16(x0, x0)); + } + + return x; +} + +#if CV_AVX2 +int VResizeCubicVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) +{ + const int** src = (const int**)_src; + const short* beta = (const short*)_beta; + const int *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + int x = 0; + float scale = 1.f/(INTER_RESIZE_COEF_SCALE*INTER_RESIZE_COEF_SCALE); + __m256 b0 = _mm256_set1_ps(beta[0]*scale), b1 = _mm256_set1_ps(beta[1]*scale), + b2 = _mm256_set1_ps(beta[2]*scale), b3 = _mm256_set1_ps(beta[3]*scale); + const int shuffle = 0xd8; // 11 | 01 | 10 | 00 + + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256i x0, x1, y0, y1; + __m256 s0, s1, f0, f1; + x0 = _mm256_load_si256((const __m256i*)(S0 + x)); + x1 = _mm256_load_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_load_si256((const __m256i*)(S1 + x)); + y1 = _mm256_load_si256((const __m256i*)(S1 + x + 8)); + + s0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b0); + s1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b0); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b1); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b1); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_load_si256((const __m256i*)(S2 + x)); + x1 = _mm256_load_si256((const __m256i*)(S2 + x + 8)); + y0 = _mm256_load_si256((const __m256i*)(S3 + x)); + y1 = _mm256_load_si256((const __m256i*)(S3 + x + 8)); + + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b2); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b2); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b3); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b3); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_cvtps_epi32(s0); + x1 = _mm256_cvtps_epi32(s1); + + x0 = _mm256_packs_epi32(x0, x1); + x0 = _mm256_permute4x64_epi64(x0, shuffle); + x0 = _mm256_packus_epi16(x0, x0); + _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(x0, 0)); + _mm_storel_epi64( (__m128i*)(dst + x + 8), _mm256_extracti128_si256(x0, 1)); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256i x0, x1, y0, y1; + __m256 s0, s1, f0, f1; + x0 = _mm256_loadu_si256((const __m256i*)(S0 + x)); + x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_loadu_si256((const __m256i*)(S1 + x)); + y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 8)); + + s0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b0); + s1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b0); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b1); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b1); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_loadu_si256((const __m256i*)(S2 + x)); + x1 = _mm256_loadu_si256((const __m256i*)(S2 + x + 8)); + y0 = _mm256_loadu_si256((const __m256i*)(S3 + x)); + y1 = _mm256_loadu_si256((const __m256i*)(S3 + x + 8)); + + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b2); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b2); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b3); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b3); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_cvtps_epi32(s0); + x1 = _mm256_cvtps_epi32(s1); + + x0 = _mm256_packs_epi32(x0, x1); + x0 = _mm256_permute4x64_epi64(x0, shuffle); + x0 = _mm256_packus_epi16(x0, x0); + _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(x0, 0)); + _mm_storel_epi64( (__m128i*)(dst + x + 8), _mm256_extracti128_si256(x0, 1)); + } + + return x; +} +#endif + struct VResizeCubicVec_32s8u { int operator()(const uchar** _src, uchar* dst, const uchar* _beta, int width ) const { - if( !checkHardwareSupport(CV_CPU_SSE2) ) - return 0; +#if CV_AVX2 + if( checkHardwareSupport(CV_CPU_AVX2) ) + return VResizeCubicVec_32s8u_avx2(_src, dst, _beta, width); +#endif + if( checkHardwareSupport(CV_CPU_SSE2) ) + return VResizeCubicVec_32s8u_sse2(_src, dst, _beta, width); - const int** src = (const int**)_src; - const short* beta = (const short*)_beta; - const int *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; - int x = 0; - float scale = 1.f/(INTER_RESIZE_COEF_SCALE*INTER_RESIZE_COEF_SCALE); - __m128 b0 = _mm_set1_ps(beta[0]*scale), b1 = _mm_set1_ps(beta[1]*scale), - b2 = _mm_set1_ps(beta[2]*scale), b3 = _mm_set1_ps(beta[3]*scale); - - if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&15) == 0 ) - for( ; x <= width - 8; x += 8 ) - { - __m128i x0, x1, y0, y1; - __m128 s0, s1, f0, f1; - x0 = _mm_load_si128((const __m128i*)(S0 + x)); - x1 = _mm_load_si128((const __m128i*)(S0 + x + 4)); - y0 = _mm_load_si128((const __m128i*)(S1 + x)); - y1 = _mm_load_si128((const __m128i*)(S1 + x + 4)); - - s0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b0); - s1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b0); - f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b1); - f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b1); - s0 = _mm_add_ps(s0, f0); - s1 = _mm_add_ps(s1, f1); - - x0 = _mm_load_si128((const __m128i*)(S2 + x)); - x1 = _mm_load_si128((const __m128i*)(S2 + x + 4)); - y0 = _mm_load_si128((const __m128i*)(S3 + x)); - y1 = _mm_load_si128((const __m128i*)(S3 + x + 4)); - - f0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b2); - f1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b2); - s0 = _mm_add_ps(s0, f0); - s1 = _mm_add_ps(s1, f1); - f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b3); - f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b3); - s0 = _mm_add_ps(s0, f0); - s1 = _mm_add_ps(s1, f1); - - x0 = _mm_cvtps_epi32(s0); - x1 = _mm_cvtps_epi32(s1); - - x0 = _mm_packs_epi32(x0, x1); - _mm_storel_epi64( (__m128i*)(dst + x), _mm_packus_epi16(x0, x0)); - } - else - for( ; x <= width - 8; x += 8 ) - { - __m128i x0, x1, y0, y1; - __m128 s0, s1, f0, f1; - x0 = _mm_loadu_si128((const __m128i*)(S0 + x)); - x1 = _mm_loadu_si128((const __m128i*)(S0 + x + 4)); - y0 = _mm_loadu_si128((const __m128i*)(S1 + x)); - y1 = _mm_loadu_si128((const __m128i*)(S1 + x + 4)); - - s0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b0); - s1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b0); - f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b1); - f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b1); - s0 = _mm_add_ps(s0, f0); - s1 = _mm_add_ps(s1, f1); - - x0 = _mm_loadu_si128((const __m128i*)(S2 + x)); - x1 = _mm_loadu_si128((const __m128i*)(S2 + x + 4)); - y0 = _mm_loadu_si128((const __m128i*)(S3 + x)); - y1 = _mm_loadu_si128((const __m128i*)(S3 + x + 4)); - - f0 = _mm_mul_ps(_mm_cvtepi32_ps(x0), b2); - f1 = _mm_mul_ps(_mm_cvtepi32_ps(x1), b2); - s0 = _mm_add_ps(s0, f0); - s1 = _mm_add_ps(s1, f1); - f0 = _mm_mul_ps(_mm_cvtepi32_ps(y0), b3); - f1 = _mm_mul_ps(_mm_cvtepi32_ps(y1), b3); - s0 = _mm_add_ps(s0, f0); - s1 = _mm_add_ps(s1, f1); - - x0 = _mm_cvtps_epi32(s0); - x1 = _mm_cvtps_epi32(s1); - - x0 = _mm_packs_epi32(x0, x1); - _mm_storel_epi64( (__m128i*)(dst + x), _mm_packus_epi16(x0, x0)); - } - - return x; + return 0; } }; -template struct VResizeCubicVec_32f16 +template +int VResizeCubicVec_32f16_sse2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) { - int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const - { - if( !checkHardwareSupport(CV_CPU_SSE2) ) - return 0; + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + ushort* dst = (ushort*)_dst; + int x = 0; + __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]), + b2 = _mm_set1_ps(beta[2]), b3 = _mm_set1_ps(beta[3]); + __m128i preshift = _mm_set1_epi32(shiftval); + __m128i postshift = _mm_set1_epi16((short)shiftval); - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; - ushort* dst = (ushort*)_dst; - int x = 0; - __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]), - b2 = _mm_set1_ps(beta[2]), b3 = _mm_set1_ps(beta[3]); - __m128i preshift = _mm_set1_epi32(shiftval); - __m128i postshift = _mm_set1_epi16((short)shiftval); + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&15) == 0 ) + for( ; x <= width - 8; x += 8 ) + { + __m128 x0, x1, y0, y1, s0, s1; + __m128i t0, t1; + x0 = _mm_load_ps(S0 + x); + x1 = _mm_load_ps(S0 + x + 4); + y0 = _mm_load_ps(S1 + x); + y1 = _mm_load_ps(S1 + x + 4); + s0 = _mm_mul_ps(x0, b0); + s1 = _mm_mul_ps(x1, b0); + y0 = _mm_mul_ps(y0, b1); + y1 = _mm_mul_ps(y1, b1); + s0 = _mm_add_ps(s0, y0); + s1 = _mm_add_ps(s1, y1); + + x0 = _mm_load_ps(S2 + x); + x1 = _mm_load_ps(S2 + x + 4); + y0 = _mm_load_ps(S3 + x); + y1 = _mm_load_ps(S3 + x + 4); + + x0 = _mm_mul_ps(x0, b2); + x1 = _mm_mul_ps(x1, b2); + y0 = _mm_mul_ps(y0, b3); + y1 = _mm_mul_ps(y1, b3); + s0 = _mm_add_ps(s0, x0); + s1 = _mm_add_ps(s1, x1); + s0 = _mm_add_ps(s0, y0); + s1 = _mm_add_ps(s1, y1); + + t0 = _mm_add_epi32(_mm_cvtps_epi32(s0), preshift); + t1 = _mm_add_epi32(_mm_cvtps_epi32(s1), preshift); + + t0 = _mm_add_epi16(_mm_packs_epi32(t0, t1), postshift); + _mm_storeu_si128( (__m128i*)(dst + x), t0); + } + else for( ; x <= width - 8; x += 8 ) { __m128 x0, x1, y0, y1, s0, s1; @@ -832,28 +1227,167 @@ template struct VResizeCubicVec_32f16 _mm_storeu_si128( (__m128i*)(dst + x), t0); } - return x; + return x; +} + +#if CV_AVX2 +template +int VResizeCubicVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + ushort* dst = (ushort*)_dst; + int x = 0; + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]), + b2 = _mm256_set1_ps(beta[2]), b3 = _mm256_set1_ps(beta[3]); + __m256i preshift = _mm256_set1_epi32(shiftval); + __m256i postshift = _mm256_set1_epi16((short)shiftval); + const int shuffle = 0xd8; // 11 | 01 | 10 | 00 + + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + __m256i t0, t1; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_load_ps(S2 + x); + x1 = _mm256_load_ps(S2 + x + 8); + y0 = _mm256_load_ps(S3 + x); + y1 = _mm256_load_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(s0), preshift); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(s1), preshift); + + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t1), postshift); + t0 = _mm256_permute4x64_epi64(t0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + __m256i t0, t1; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_loadu_ps(S2 + x); + x1 = _mm256_loadu_ps(S2 + x + 8); + y0 = _mm256_loadu_ps(S3 + x); + y1 = _mm256_loadu_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(s0), preshift); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(s1), preshift); + + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t1), postshift); + t0 = _mm256_permute4x64_epi64(t0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + } + + return x; +} +#endif + +template struct VResizeCubicVec_32f16 +{ + int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const + { +#if CV_AVX2 + if( checkHardwareSupport(CV_CPU_AVX2) ) + return VResizeCubicVec_32f16_avx2(_src, _dst, _beta, width); +#endif + if( checkHardwareSupport(CV_CPU_SSE2) ) + return VResizeCubicVec_32f16_sse2(_src, _dst, _beta, width); + + return 0; } }; typedef VResizeCubicVec_32f16 VResizeCubicVec_32f16u; typedef VResizeCubicVec_32f16<0> VResizeCubicVec_32f16s; -struct VResizeCubicVec_32f +static int VResizeCubicVec_32f_sse(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) { - int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const - { - if( !checkHardwareSupport(CV_CPU_SSE) ) - return 0; + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + float* dst = (float*)_dst; + int x = 0; + __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]), + b2 = _mm_set1_ps(beta[2]), b3 = _mm_set1_ps(beta[3]); - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; - float* dst = (float*)_dst; - int x = 0; - __m128 b0 = _mm_set1_ps(beta[0]), b1 = _mm_set1_ps(beta[1]), - b2 = _mm_set1_ps(beta[2]), b3 = _mm_set1_ps(beta[3]); + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&15) == 0 ) + for( ; x <= width - 8; x += 8 ) + { + __m128 x0, x1, y0, y1, s0, s1; + x0 = _mm_load_ps(S0 + x); + x1 = _mm_load_ps(S0 + x + 4); + y0 = _mm_load_ps(S1 + x); + y1 = _mm_load_ps(S1 + x + 4); + s0 = _mm_mul_ps(x0, b0); + s1 = _mm_mul_ps(x1, b0); + y0 = _mm_mul_ps(y0, b1); + y1 = _mm_mul_ps(y1, b1); + s0 = _mm_add_ps(s0, y0); + s1 = _mm_add_ps(s1, y1); + + x0 = _mm_load_ps(S2 + x); + x1 = _mm_load_ps(S2 + x + 4); + y0 = _mm_load_ps(S3 + x); + y1 = _mm_load_ps(S3 + x + 4); + + x0 = _mm_mul_ps(x0, b2); + x1 = _mm_mul_ps(x1, b2); + y0 = _mm_mul_ps(y0, b3); + y1 = _mm_mul_ps(y1, b3); + s0 = _mm_add_ps(s0, x0); + s1 = _mm_add_ps(s1, x1); + s0 = _mm_add_ps(s0, y0); + s1 = _mm_add_ps(s1, y1); + + _mm_storeu_ps( dst + x, s0); + _mm_storeu_ps( dst + x + 4, s1); + } + else for( ; x <= width - 8; x += 8 ) { __m128 x0, x1, y0, y1, s0, s1; @@ -887,7 +1421,103 @@ struct VResizeCubicVec_32f _mm_storeu_ps( dst + x + 4, s1); } - return x; + return x; +} + +#if CV_AVX +int VResizeCubicVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + float* dst = (float*)_dst; + int x = 0; + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]), + b2 = _mm256_set1_ps(beta[2]), b3 = _mm256_set1_ps(beta[3]); + + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_load_ps(S2 + x); + x1 = _mm256_load_ps(S2 + x + 8); + y0 = _mm256_load_ps(S3 + x); + y1 = _mm256_load_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + _mm256_storeu_ps( dst + x, s0); + _mm256_storeu_ps( dst + x + 8, s1); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_loadu_ps(S2 + x); + x1 = _mm256_loadu_ps(S2 + x + 8); + y0 = _mm256_loadu_ps(S3 + x); + y1 = _mm256_loadu_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + _mm256_storeu_ps( dst + x, s0); + _mm256_storeu_ps( dst + x + 8, s1); + } + + return x; +} +#endif + +struct VResizeCubicVec_32f +{ + int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const + { +#if CV_AVX + if( checkHardwareSupport(CV_CPU_AVX) ) + return VResizeCubicVec_32f_avx(_src, _dst, _beta, width); +#endif + if( checkHardwareSupport(CV_CPU_SSE) ) + return VResizeCubicVec_32f_sse(_src, _dst, _beta, width); + + return 0; } }; diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 44f3e483fd..39907edac4 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -3005,6 +3005,9 @@ void printVersionInfo(bool useStdOut) #if CV_AVX if (checkHardwareSupport(CV_CPU_AVX)) cpu_features += " avx"; #endif +#if CV_AVX2 + if (checkHardwareSupport(CV_CPU_AVX2)) cpu_features += " avx2"; +#endif #if CV_NEON cpu_features += " neon"; // NEON is currently not checked at runtime #endif From 6882970248f163c7c0dd16b11c18595e20726200 Mon Sep 17 00:00:00 2001 From: Alexander Petrikov Date: Mon, 23 Jun 2014 11:08:51 +0400 Subject: [PATCH 074/662] Add CV_Assert (ndisp % 8 == 0) to NEON version --- modules/calib3d/src/stereobm.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/calib3d/src/stereobm.cpp b/modules/calib3d/src/stereobm.cpp index 4a978eb14e..e7094c642c 100644 --- a/modules/calib3d/src/stereobm.cpp +++ b/modules/calib3d/src/stereobm.cpp @@ -556,14 +556,6 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, uchar* buf, int _dy0, int _dy1 ) { -#if CV_NEON - int32_t d0_4_temp [4]; - for (int i = 0; i < 4; i ++) - d0_4_temp[i] = i; - int32x4_t d0_4 = vld1q_s32 (d0_4_temp); - int32x4_t dd_4 = vdupq_n_s32 (4); -#endif - const int ALIGN = 16; int x, y, d; int wsz = state.SADWindowSize, wsz2 = wsz/2; @@ -579,6 +571,15 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right, int uniquenessRatio = state.uniquenessRatio; short FILTERED = (short)((mindisp - 1) << DISPARITY_SHIFT); +#if CV_NEON + CV_Assert (ndisp % 8 == 0); + int32_t d0_4_temp [4]; + for (int i = 0; i < 4; i ++) + d0_4_temp[i] = i; + int32x4_t d0_4 = vld1q_s32 (d0_4_temp); + int32x4_t dd_4 = vdupq_n_s32 (4); +#endif + int *sad, *hsad0, *hsad, *hsad_sub, *htext; uchar *cbuf0, *cbuf; const uchar* lptr0 = left.data + lofs; From ade46bd4287c59807869a87cb4089d73a8d1dad8 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Jun 2014 14:17:57 +0200 Subject: [PATCH 075/662] Fixed typos in comments --- ...mera_calibration_and_3d_reconstruction.rst | 2 +- modules/core/include/opencv2/core/core.hpp | 4 +- modules/highgui/src/cap_libv4l.cpp | 8 +-- modules/highgui/src/cap_v4l.cpp | 8 +-- .../include/opencv2/imgproc/imgproc.hpp | 4 +- modules/imgproc/src/contours.cpp | 8 +-- modules/legacy/src/epilines.cpp | 4 +- modules/legacy/src/lcm.cpp | 4 +- modules/legacy/src/lee.cpp | 52 +++++++++---------- modules/ml/src/svm.cpp | 2 +- modules/ocl/src/fft.cpp | 8 +-- modules/ts/include/opencv2/ts/ts.hpp | 4 +- 12 files changed, 54 insertions(+), 54 deletions(-) diff --git a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst index d616dfdea2..59bd533e85 100644 --- a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst +++ b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst @@ -1588,7 +1588,7 @@ The distorted point coordinates are [x'; y'] where x' = (\theta_d / r) x \\ y' = (\theta_d / r) y -Finally, convertion into pixel coordinates: The final pixel coordinates vector [u; v] where: +Finally, conversion into pixel coordinates: The final pixel coordinates vector [u; v] where: .. class:: center .. math:: diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 5667e9e50f..f98a4fd779 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -495,7 +495,7 @@ public: //! dot product computed in double-precision arithmetics double ddot(const Matx<_Tp, m, n>& v) const; - //! convertion to another data type + //! conversion to another data type template operator Matx() const; //! change the matrix shape @@ -636,7 +636,7 @@ public: For other dimensionalities the exception is raised */ Vec cross(const Vec& v) const; - //! convertion to another data type + //! conversion to another data type template operator Vec() const; //! conversion to 4-element CvScalar. operator CvScalar() const; diff --git a/modules/highgui/src/cap_libv4l.cpp b/modules/highgui/src/cap_libv4l.cpp index a05c4b2123..ff153042d1 100644 --- a/modules/highgui/src/cap_libv4l.cpp +++ b/modules/highgui/src/cap_libv4l.cpp @@ -102,7 +102,7 @@ I modified the following: autosetup_capture_mode_v4l2 -> autodetect capture modes for v4l2 - Modifications are according with Video4Linux old codes - Video4Linux handling is automatically if it does not recognize a Video4Linux2 device - - Tested succesful with Logitech Quickcam Express (V4L), Creative Vista (V4L) and Genius VideoCam Notebook (V4L2) + - Tested successfully with Logitech Quickcam Express (V4L), Creative Vista (V4L) and Genius VideoCam Notebook (V4L2) - Correct source lines with compiler warning messages - Information message from v4l/v4l2 detection @@ -113,7 +113,7 @@ I modified the following: - SN9C10x chip based webcams support - New methods are internal: bayer2rgb24, sonix_decompress -> decoder routines for SN9C10x decoding from Takafumi Mizuno with his pleasure :) - - Tested succesful with Genius VideoCam Notebook (V4L2) + - Tested successfully with Genius VideoCam Notebook (V4L2) Sixth Patch: Sept 10, 2005 Csaba Kertesz sign@freemail.hu For Release: OpenCV-Linux Beta5 OpenCV-0.9.7 @@ -123,7 +123,7 @@ I added the following: - Get and change V4L capture controls (hue, saturation, brightness, contrast) - New method is internal: icvSetControl -> set capture controls - - Tested succesful with Creative Vista (V4L) + - Tested successfully with Creative Vista (V4L) Seventh Patch: Sept 10, 2005 Csaba Kertesz sign@freemail.hu For Release: OpenCV-Linux Beta5 OpenCV-0.9.7 @@ -132,7 +132,7 @@ I added the following: - Detect, get and change V4L2 capture controls (hue, saturation, brightness, contrast, gain) - New methods are internal: v4l2_scan_controls_enumerate_menu, v4l2_scan_controls -> detect capture control intervals - - Tested succesful with Genius VideoCam Notebook (V4L2) + - Tested successfully with Genius VideoCam Notebook (V4L2) 8th patch: Jan 5, 2006, Olivier.Bornet@idiap.ch Add support of V4L2_PIX_FMT_YUYV and V4L2_PIX_FMT_MJPEG. diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index c9fca05819..d09c8f88cf 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -102,7 +102,7 @@ I modified the following: autosetup_capture_mode_v4l2 -> autodetect capture modes for v4l2 - Modifications are according with Video4Linux old codes - Video4Linux handling is automatically if it does not recognize a Video4Linux2 device - - Tested succesful with Logitech Quickcam Express (V4L), Creative Vista (V4L) and Genius VideoCam Notebook (V4L2) + - Tested successfully with Logitech Quickcam Express (V4L), Creative Vista (V4L) and Genius VideoCam Notebook (V4L2) - Correct source lines with compiler warning messages - Information message from v4l/v4l2 detection @@ -113,7 +113,7 @@ I modified the following: - SN9C10x chip based webcams support - New methods are internal: bayer2rgb24, sonix_decompress -> decoder routines for SN9C10x decoding from Takafumi Mizuno with his pleasure :) - - Tested succesful with Genius VideoCam Notebook (V4L2) + - Tested successfully with Genius VideoCam Notebook (V4L2) Sixth Patch: Sept 10, 2005 Csaba Kertesz sign@freemail.hu For Release: OpenCV-Linux Beta5 OpenCV-0.9.7 @@ -123,7 +123,7 @@ I added the following: - Get and change V4L capture controls (hue, saturation, brightness, contrast) - New method is internal: icvSetControl -> set capture controls - - Tested succesful with Creative Vista (V4L) + - Tested successfully with Creative Vista (V4L) Seventh Patch: Sept 10, 2005 Csaba Kertesz sign@freemail.hu For Release: OpenCV-Linux Beta5 OpenCV-0.9.7 @@ -132,7 +132,7 @@ I added the following: - Detect, get and change V4L2 capture controls (hue, saturation, brightness, contrast, gain) - New methods are internal: v4l2_scan_controls_enumerate_menu, v4l2_scan_controls -> detect capture control intervals - - Tested succesful with Genius VideoCam Notebook (V4L2) + - Tested successfully with Genius VideoCam Notebook (V4L2) 8th patch: Jan 5, 2006, Olivier.Bornet@idiap.ch Add support of V4L2_PIX_FMT_YUYV and V4L2_PIX_FMT_MJPEG. diff --git a/modules/imgproc/include/opencv2/imgproc/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc/imgproc.hpp index 2fcccfe30d..339476a633 100644 --- a/modules/imgproc/include/opencv2/imgproc/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc/imgproc.hpp @@ -84,7 +84,7 @@ public: BaseRowFilter(); //! the destructor virtual ~BaseRowFilter(); - //! the filtering operator. Must be overrided in the derived classes. The horizontal border interpolation is done outside of the class. + //! the filtering operator. Must be overridden in the derived classes. The horizontal border interpolation is done outside of the class. virtual void operator()(const uchar* src, uchar* dst, int width, int cn) = 0; int ksize, anchor; @@ -111,7 +111,7 @@ public: BaseColumnFilter(); //! the destructor virtual ~BaseColumnFilter(); - //! the filtering operator. Must be overrided in the derived classes. The vertical border interpolation is done outside of the class. + //! the filtering operator. Must be overridden in the derived classes. The vertical border interpolation is done outside of the class. virtual void operator()(const uchar** src, uchar* dst, int dststep, int dstcount, int width) = 0; //! resets the internal buffers, if any diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index c34f3e62f2..304214257c 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -125,7 +125,7 @@ _CvContourInfo; /* - Structure that is used for sequental retrieving contours from the image. + Structure that is used for sequential retrieving contours from the image. It supports both hierarchical and plane variants of Suzuki algorithm. */ typedef struct _CvContourScanner @@ -314,7 +314,7 @@ cvStartFindContours( void* _img, CvMemStorage* storage, tree. The retrieved contour itself is removed from the storage. Here two cases are possible: 2a. If one deals with plane variant of algorithm - (hierarchical strucutre is not reconstructed), + (hierarchical structure is not reconstructed), the contour is removed completely. 2b. In hierarchical case, the header of the contour is not removed. It's marked as "link to contour" and h_next pointer of it is set to @@ -326,8 +326,8 @@ cvStartFindContours( void* _img, CvMemStorage* storage, leaves header if hierarchical (but doesn't mark header as "link"). ------------------------------------------------------------------------ The 1st variant can be used to retrieve and store all the contours from the image - (with optional convertion from chains to contours using some approximation from - restriced set of methods). Some characteristics of contour can be computed in the + (with optional conversion from chains to contours using some approximation from + restricted set of methods). Some characteristics of contour can be computed in the same pass. The usage scheme can look like: diff --git a/modules/legacy/src/epilines.cpp b/modules/legacy/src/epilines.cpp index b63f8e1c77..d45aa8bab4 100644 --- a/modules/legacy/src/epilines.cpp +++ b/modules/legacy/src/epilines.cpp @@ -377,7 +377,7 @@ int icvComCoeffForLine( CvPoint2D64d point1, camMatr2, &directS4); - /* Create convertion for camera 2: two direction and camera point */ + /* Create conversion for camera 2: two direction and camera point */ double convRotMatr[9]; double convTransVect[3]; @@ -1928,7 +1928,7 @@ void icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, if( numPoints < 2 ) { *result = 0; - return;/* Error. Not enought points */ + return;/* Error. Not enough points */ } /* Project all points to middle line and get max and min */ diff --git a/modules/legacy/src/lcm.cpp b/modules/legacy/src/lcm.cpp index 8416952a35..1426f8a931 100644 --- a/modules/legacy/src/lcm.cpp +++ b/modules/legacy/src/lcm.cpp @@ -100,8 +100,8 @@ typedef struct CvLCMData // Context: // Parameters: // LCM : in&out. -// Returns: 1, if hybrid model was succesfully constructed -// 0, if some error occures +// Returns: 1, if hybrid model was successfully constructed +// 0, if some error occurs //F*/ CV_IMPL int _cvConstructLCM(CvLCM* LCM); diff --git a/modules/legacy/src/lee.cpp b/modules/legacy/src/lee.cpp index 85fe497885..2df212763b 100644 --- a/modules/legacy/src/lee.cpp +++ b/modules/legacy/src/lee.cpp @@ -182,8 +182,8 @@ typedef CvDirection* pCvDirection; // attempt_number: in, number of unsuccessful attemts made by program to compute // the Voronoi Diagram befor return the error // -// Returns: 1, if Voronoi Diagram was succesfully computed -// 0, if some error occures +// Returns: 1, if Voronoi Diagram was successfully computed +// 0, if some error occurs //F*/ static int _cvLee(CvSeq* ContourSeq, CvVoronoiDiagramInt* pVoronoiDiagramInt, @@ -207,8 +207,8 @@ static int _cvLee(CvSeq* ContourSeq, // contour_orientation: in, orientation of polygons. // = 1, if contour is left - oriented in left coordinat system // =-1, if contour is left - oriented in right coordinat system -// Return: 1, if sites were succesfully constructed -// 0, if some error occures +// Return: 1, if sites were successfully constructed +// 0, if some error occurs //F*/ static int _cvConstuctSites(CvSeq* ContourSeq, CvVoronoiDiagramInt* pVoronoiDiagram, @@ -223,8 +223,8 @@ static int _cvConstuctSites(CvSeq* ContourSeq, // Parameters: // pVoronoiDiagram : in, pointer to struct, which contains the // description of Voronoi Diagram -// Return: 1, if chains were succesfully constructed -// 0, if some error occures +// Return: 1, if chains were successfully constructed +// 0, if some error occurs //F*/ static int _cvConstructChains(CvVoronoiDiagramInt* pVoronoiDiagram); @@ -236,8 +236,8 @@ static int _cvConstructChains(CvVoronoiDiagramInt* pVoronoiDiagram); // Parameters: // VoronoiDiagram : in, pointer to struct, which contains the // description of Voronoi Diagram. -// Returns: 1, if skeleton was succesfully computed -// 0, if some error occures +// Returns: 1, if skeleton was successfully computed +// 0, if some error occurs //F*/ static int _cvConstructSkeleton(CvVoronoiDiagramInt* pVoronoiDiagram); @@ -280,11 +280,11 @@ static void _cvReleaseVoronoiStorage(CvVoronoiStorageInt* pVoronoiStorage, int g // Parameters: // VoronoiDiagram: in // VoronoiStorage: in -// change_orientation: in, if = -1 then the convertion is accompanied with change +// change_orientation: in, if = -1 then the conversion is accompanied with change // of orientation // -// Return: 1, if convertion was succesfully completed -// 0, if some error occures +// Return: 1, if conversion was successfully completed +// 0, if some error occurs //F*/ /* static int _cvConvert(CvVoronoiDiagram2D* VoronoiDiagram, @@ -311,8 +311,8 @@ static int _cvConvert(CvVoronoiDiagram2D* VoronoiDiagram, // VoronoiDiagram: in // VoronoiStorage: in / -// Return: 1, if convertion was succesfully completed -// 0, if some error occures +// Return: 1, if conversion was successfully completed +// 0, if some error occurs //F*/ /* static int _cvConvertSameOrientation(CvVoronoiDiagram2D* VoronoiDiagram, @@ -337,8 +337,8 @@ static int _cvConvertSameOrientation(CvVoronoiDiagram2D* VoronoiDiagram, // VoronoiDiagram: in // VoronoiStorage: in / -// Return: 1, if convertion was succesfully completed -// 0, if some error occures +// Return: 1, if conversion was successfully completed +// 0, if some error occurs //F*/ /* static int _cvConvertChangeOrientation(CvVoronoiDiagram2D* VoronoiDiagram, @@ -362,8 +362,8 @@ static int _cvConvertChangeOrientation(CvVoronoiDiagram2D* VoronoiDiagram, orientation: in, orientation of contour ( = 1 or = -1) type: in, type of vertices. The possible values are (int)1, (float)1,(double)1. - Return: 1, if sites were succesfully constructed - 0, if some error occures : + Return: 1, if sites were successfully constructed + 0, if some error occurs : --------------------------------------------------------------------------*/ template int _cvConstructExtSites(CvVoronoiDiagramInt* pVoronoiDiagram, @@ -384,8 +384,8 @@ int _cvConstructExtSites(CvVoronoiDiagramInt* pVoronoiDiagram, orientation: in, orientation of contour ( = 1 or = -1) type: in, type of vertices. The possible values are (int)1, (float)1,(double)1. - Return: 1, if sites were succesfully constructed - 0, if some error occures : + Return: 1, if sites were successfully constructed + 0, if some error occurs : --------------------------------------------------------------------------*/ template int _cvConstructIntSites(CvVoronoiDiagramInt* pVoronoiDiagram, @@ -402,8 +402,8 @@ int _cvConstructIntSites(CvVoronoiDiagramInt* pVoronoiDiagram, pVoronoiDiagram : in&out, pointer to struct, which contains the description of Voronoi Diagram - Return: 1, if chains were succesfully constructed - 0, if some error occures + Return: 1, if chains were successfully constructed + 0, if some error occurs --------------------------------------------------------------------------*/ static int _cvConstructExtChains(CvVoronoiDiagramInt* pVoronoiDiagram); @@ -456,7 +456,7 @@ static void _cvRandomModification(CvVoronoiDiagramInt* pVoronoiDiagram, int begi Arguments pVoronoiDiagram : in, pointer to struct, which contains the description of Voronoi Diagram - Return : 1, if VD was constructed succesfully + Return : 1, if VD was constructed successfully 0, if some error occure --------------------------------------------------------------------------*/ static int _cvConstructExtVD(CvVoronoiDiagramInt* pVoronoiDiagram); @@ -479,7 +479,7 @@ static void _cvConstructIntVD(CvVoronoiDiagramInt* pVoronoiDiagram); pVoronoiDiagram : in, pointer to struct, which contains the description of Voronoi Diagram pChain1,pChain1: in, given chains - Return : 1, if joining was succesful + Return : 1, if joining was successful 0, if some error occure --------------------------------------------------------------------------*/ static int _cvJoinChains(pCvVoronoiChain pChain1, @@ -507,7 +507,7 @@ static void _cvFindNearestSite(CvVoronoiDiagramInt* pVoronoiDiagram); pVoronoiDiagram : in, pointer to struct, which contains the description of Voronoi Diagram pHole : in, given hole - Return : 1, if the search was succesful + Return : 1, if the search was successful 0, if some error occure --------------------------------------------------------------------------*/ static int _cvFindOppositSiteCW(pCvVoronoiHole pHole, CvVoronoiDiagramInt* pVoronoiDiagram); @@ -522,7 +522,7 @@ static int _cvFindOppositSiteCW(pCvVoronoiHole pHole, CvVoronoiDiagramInt* pVoro pVoronoiDiagram : in, pointer to struct, which contains the description of Voronoi Diagram pHole : in, given hole - Return : 1, if the search was succesful + Return : 1, if the search was successful 0, if some error occure --------------------------------------------------------------------------*/ static int _cvFindOppositSiteCCW(pCvVoronoiHole pHole,CvVoronoiDiagramInt* pVoronoiDiagram); @@ -535,7 +535,7 @@ static int _cvFindOppositSiteCCW(pCvVoronoiHole pHole,CvVoronoiDiagramInt* pVoro pVoronoiDiagram : in, pointer to struct, which contains the description of Voronoi Diagram pHole : in, given hole - Return : 1, if merging was succesful + Return : 1, if merging was successful 0, if some error occure --------------------------------------------------------------------------*/ static int _cvMergeVD(pCvVoronoiHole pHole,CvVoronoiDiagramInt* pVoronoiDiagram); diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp index f158805219..0a5bfffa31 100644 --- a/modules/ml/src/svm.cpp +++ b/modules/ml/src/svm.cpp @@ -1632,7 +1632,7 @@ bool CvSVM::train( const CvMat* _train_data, const CvMat* _responses, if( !do_train( svm_type, sample_count, var_count, samples, responses, temp_storage, alpha )) EXIT; - ok = true; // model has been trained succesfully + ok = true; // model has been trained successfully __END__; diff --git a/modules/ocl/src/fft.cpp b/modules/ocl/src/fft.cpp index 05b7968ea2..2cc935c27e 100644 --- a/modules/ocl/src/fft.cpp +++ b/modules/ocl/src/fft.cpp @@ -200,8 +200,8 @@ cv::ocl::FftPlan::FftPlan(Size _dft_size, int _src_step, int _dst_step, int _fla clStridesOut[1] = dst_step / sizeof(float); break; default: - //std::runtime_error("does not support this convertion!"); - cout << "Does not support this convertion!" << endl; + //std::runtime_error("does not support this conversion!"); + cout << "Does not support this conversion!" << endl; throw exception(); break; } @@ -324,8 +324,8 @@ void cv::ocl::dft(const oclMat &src, oclMat &dst, Size dft_size, int flags) dst.create(src.rows, dft_size.width, CV_32FC1); break; default: - //std::runtime_error("does not support this convertion!"); - cout << "Does not support this convertion!" << endl; + //std::runtime_error("does not support this conversion!"); + cout << "Does not support this conversion!" << endl; throw exception(); break; } diff --git a/modules/ts/include/opencv2/ts/ts.hpp b/modules/ts/include/opencv2/ts/ts.hpp index f4cd3ffbcd..c3e50b6ed7 100644 --- a/modules/ts/include/opencv2/ts/ts.hpp +++ b/modules/ts/include/opencv2/ts/ts.hpp @@ -373,7 +373,7 @@ public: FAIL_HANG=-13, // unexpected response on passing bad arguments to the tested function - // (the function crashed, proceed succesfully (while it should not), or returned + // (the function crashed, proceed successfully (while it should not), or returned // error code that is different from what is expected) FAIL_BAD_ARG_CHECK=-14, @@ -383,7 +383,7 @@ public: // the test has been skipped because it is not in the selected subset of the tests to run, // because it has been run already within the same run with the same parameters, or because // of some other reason and this is not considered as an error. - // Normally TS::run() (or overrided method in the derived class) takes care of what + // Normally TS::run() (or overridden method in the derived class) takes care of what // needs to be run, so this code should not occur. SKIPPED=1 }; From fbac578c79168373d4037ada2bc3afb6f9f1bdee Mon Sep 17 00:00:00 2001 From: Mike Maraya Date: Fri, 27 Jun 2014 23:26:09 -0400 Subject: [PATCH 076/662] Fixes resizeWindow() on OS X (Bug #3200) --- modules/highgui/src/window_cocoa.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index d3a68107fc..03b144f3a5 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -253,7 +253,7 @@ CV_IMPL void cvResizeWindow( const char* name, int width, int height) //cout << "cvResizeWindow" << endl; NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init]; CVWindow *window = cvGetWindow(name); - if(window) { + if(window && ![window autosize]) { NSRect frame = [window frame]; frame.size.width = width; frame.size.height = height; From 56683e6d112a808fbd51c74917f0c4d9d752f502 Mon Sep 17 00:00:00 2001 From: Mike Maraya Date: Fri, 27 Jun 2014 08:02:01 -0400 Subject: [PATCH 077/662] Fixes build failure on Mac OS X 10.10 Yosemite Beta due to highgui/src/window_cocoa.mm (Bug #3737) --- modules/highgui/src/window_cocoa.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 03b144f3a5..433e437a77 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -151,7 +151,7 @@ CV_IMPL int cvInitSystem( int , char** ) #define NSAppKitVersionNumber10_5 949 #endif if( floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5 ) - [application setActivationPolicy:0/*NSApplicationActivationPolicyRegular*/]; + [application setActivationPolicy:NSApplicationActivationPolicyRegular]; #endif //[application finishLaunching]; //atexit(icvCocoaCleanup); From 5c85f816c9da66c203034f9ab32bd1e8e7a12727 Mon Sep 17 00:00:00 2001 From: Mike Maraya Date: Fri, 27 Jun 2014 08:20:22 -0400 Subject: [PATCH 078/662] Revert "Fixes build failure on Mac OS X 10.10 Yosemite Beta due to highgui/src/window_cocoa.mm (Bug #3737)" This reverts commit 56683e6d112a808fbd51c74917f0c4d9d752f502. --- modules/highgui/src/window_cocoa.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 433e437a77..03b144f3a5 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -151,7 +151,7 @@ CV_IMPL int cvInitSystem( int , char** ) #define NSAppKitVersionNumber10_5 949 #endif if( floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5 ) - [application setActivationPolicy:NSApplicationActivationPolicyRegular]; + [application setActivationPolicy:0/*NSApplicationActivationPolicyRegular*/]; #endif //[application finishLaunching]; //atexit(icvCocoaCleanup); From 7936faf9a33acd0438807b28436877eb44ccdc24 Mon Sep 17 00:00:00 2001 From: Mike Maraya Date: Fri, 27 Jun 2014 08:34:40 -0400 Subject: [PATCH 079/662] Fixes build failure on Mac OS X 10.10 Yosemite Beta due to highgui/src/window_cocoa.mm (Bug #3737) --- modules/highgui/src/window_cocoa.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index d3a68107fc..1d2e306030 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -151,7 +151,7 @@ CV_IMPL int cvInitSystem( int , char** ) #define NSAppKitVersionNumber10_5 949 #endif if( floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5 ) - [application setActivationPolicy:0/*NSApplicationActivationPolicyRegular*/]; + [application setActivationPolicy:NSApplicationActivationPolicyRegular]; #endif //[application finishLaunching]; //atexit(icvCocoaCleanup); From 939c60bcaa18e3b075d8e4f78b87ea105546910f Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Fri, 27 Jun 2014 14:53:43 +0200 Subject: [PATCH 080/662] fixed two models, adding xml identifier to correct position --- data/lbpcascades/lbpcascade_profileface.xml | 14 +++++++------- data/lbpcascades/lbpcascade_silverware.xml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data/lbpcascades/lbpcascade_profileface.xml b/data/lbpcascades/lbpcascade_profileface.xml index a9e8437306..f5453d29ba 100755 --- a/data/lbpcascades/lbpcascade_profileface.xml +++ b/data/lbpcascades/lbpcascade_profileface.xml @@ -1,11 +1,11 @@ - + BOOST diff --git a/data/lbpcascades/lbpcascade_silverware.xml b/data/lbpcascades/lbpcascade_silverware.xml index 33aa443c24..20ce15622c 100755 --- a/data/lbpcascades/lbpcascade_silverware.xml +++ b/data/lbpcascades/lbpcascade_silverware.xml @@ -1,3 +1,4 @@ + - BOOST From 4b8fb6c246493480bd0ea1874914343fe49256c0 Mon Sep 17 00:00:00 2001 From: Alexander Karsakov Date: Thu, 3 Jul 2014 10:27:53 +0400 Subject: [PATCH 081/662] Fixed dst size --- modules/core/src/dxt.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index 033bf45120..30053f28e1 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -1496,6 +1496,7 @@ void cv::dft( InputArray _src0, OutputArray _dst, int flags, int nonzero_rows ) int elem_size = (int)src.elemSize1(), complex_elem_size = elem_size*2; int factors[34]; bool inplace_transform = false; + bool is1d = (flags & DFT_ROWS) != 0 || src.rows == 1; #ifdef USE_IPP_DFT AutoBuffer ippbuf; int ipp_norm_flag = !(flags & DFT_SCALE) ? 8 : inv ? 2 : 1; @@ -1504,7 +1505,10 @@ void cv::dft( InputArray _src0, OutputArray _dst, int flags, int nonzero_rows ) CV_Assert( type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 ); if( !inv && src.channels() == 1 && (flags & DFT_COMPLEX_OUTPUT) ) - _dst.create( src.size(), CV_MAKETYPE(depth, 2) ); + if (!is1d) + _dst.create( src.size(), CV_MAKETYPE(depth, 2) ); + else + _dst.create( Size(src.cols/2+1, src.rows), CV_MAKETYPE(depth, 2) ); else if( inv && src.channels() == 2 && (flags & DFT_REAL_OUTPUT) ) _dst.create( src.size(), depth ); else From aafda43df12207be7c3981c7a7ac91309977f042 Mon Sep 17 00:00:00 2001 From: PhilLab Date: Tue, 8 Jul 2014 11:52:42 +0200 Subject: [PATCH 082/662] Double precision for solvePnPRansac() solvePnPRansac() and pnpTask() now accept object or image points with double precision. --- modules/calib3d/src/solvepnp.cpp | 43 ++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index b0ef1d9830..2b4552463f 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -137,11 +137,13 @@ namespace cv CameraParameters camera; }; + template static void pnpTask(const vector& pointsMask, const Mat& objectPoints, const Mat& imagePoints, const Parameters& params, vector& inliers, Mat& rvec, Mat& tvec, const Mat& rvecInit, const Mat& tvecInit, Mutex& resultsMutex) { - Mat modelObjectPoints(1, MIN_POINTS_COUNT, CV_32FC3), modelImagePoints(1, MIN_POINTS_COUNT, CV_32FC2); + Mat modelObjectPoints(1, MIN_POINTS_COUNT, CV_MAKETYPE(DataDepth::value, 3)); + Mat modelImagePoints(1, MIN_POINTS_COUNT, CV_MAKETYPE(DataDepth::value, 2)); for (int i = 0, colIndex = 0; i < (int)pointsMask.size(); i++) { if (pointsMask[i]) @@ -160,7 +162,7 @@ namespace cv for (int i = 0; i < MIN_POINTS_COUNT; i++) for (int j = i + 1; j < MIN_POINTS_COUNT; j++) { - if (norm(modelObjectPoints.at(0, i) - modelObjectPoints.at(0, j)) < eps) + if (norm(modelObjectPoints.at>(0, i) - modelObjectPoints.at>(0, j)) < eps) num_same_points++; } if (num_same_points > 0) @@ -174,7 +176,7 @@ namespace cv params.useExtrinsicGuess, params.flags); - vector projected_points; + vector> projected_points; projected_points.resize(objectPoints.cols); projectPoints(objectPoints, localRvec, localTvec, params.camera.intrinsics, params.camera.distortion, projected_points); @@ -184,9 +186,10 @@ namespace cv vector localInliers; for (int i = 0; i < objectPoints.cols; i++) { - Point2f p(imagePoints.at(0, i)[0], imagePoints.at(0, i)[1]); + //Although p is a 2D point it needs the same type as the object points to enable the norm calculation + Point_ p(imagePoints.at>(0, i)[0], imagePoints.at>(0, i)[1]); if ((norm(p - projected_points[i]) < params.reprojectionError) - && (rotatedPoints.at(0, i)[2] > 0)) //hack + && (rotatedPoints.at>(0, i)[2] > 0)) //hack { localInliers.push_back(i); } @@ -206,6 +209,30 @@ namespace cv } } + static void pnpTask(const vector& pointsMask, const Mat& objectPoints, const Mat& imagePoints, + const Parameters& params, vector& inliers, Mat& rvec, Mat& tvec, + const Mat& rvecInit, const Mat& tvecInit, Mutex& resultsMutex) + { + CV_Assert(objectPoints.depth() == CV_64F || objectPoints.depth() == CV_32F); + CV_Assert(imagePoints.depth() == CV_64F || imagePoints.depth() == CV_32F); + const bool objectDoublePrecision = objectPoints.depth() == CV_64F; + const bool imageDoublePrecision = imagePoints.depth() == CV_64F; + if(objectDoublePrecision) + { + if(imageDoublePrecision) + pnpTask(pointsMask, objectPoints, imagePoints, params, inliers, rvec, tvec, rvecInit, tvecInit, resultsMutex); + else + pnpTask(pointsMask, objectPoints, imagePoints, params, inliers, rvec, tvec, rvecInit, tvecInit, resultsMutex); + } + else + { + if(imageDoublePrecision) + pnpTask(pointsMask, objectPoints, imagePoints, params, inliers, rvec, tvec, rvecInit, tvecInit, resultsMutex); + else + pnpTask(pointsMask, objectPoints, imagePoints, params, inliers, rvec, tvec, rvecInit, tvecInit, resultsMutex); + } + } + class PnPSolver { public: @@ -281,10 +308,10 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints, Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat(); CV_Assert(opoints.isContinuous()); - CV_Assert(opoints.depth() == CV_32F); + CV_Assert(opoints.depth() == CV_32F || opoints.depth() == CV_64F); CV_Assert((opoints.rows == 1 && opoints.channels() == 3) || opoints.cols*opoints.channels() == 3); CV_Assert(ipoints.isContinuous()); - CV_Assert(ipoints.depth() == CV_32F); + CV_Assert(ipoints.depth() == CV_32F || ipoints.depth() == CV_64F); CV_Assert((ipoints.rows == 1 && ipoints.channels() == 2) || ipoints.cols*ipoints.channels() == 2); _rvec.create(3, 1, CV_64FC1); @@ -320,7 +347,7 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints, if (flags != CV_P3P) { int i, pointsCount = (int)localInliers.size(); - Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2); + Mat inlierObjectPoints(1, pointsCount, CV_MAKE_TYPE(opoints.depth(), 3)), inlierImagePoints(1, pointsCount, CV_MAKE_TYPE(ipoints.depth(), 2)); for (i = 0; i < pointsCount; i++) { int index = localInliers[i]; From 2c29ee9e00c204f0c4b3b3685485c4c9b0350650 Mon Sep 17 00:00:00 2001 From: PhilLab Date: Tue, 8 Jul 2014 13:24:35 +0200 Subject: [PATCH 083/662] Added cast and removed formatting error --- modules/calib3d/src/solvepnp.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index 2b4552463f..081d6bd5c8 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -187,7 +187,8 @@ namespace cv for (int i = 0; i < objectPoints.cols; i++) { //Although p is a 2D point it needs the same type as the object points to enable the norm calculation - Point_ p(imagePoints.at>(0, i)[0], imagePoints.at>(0, i)[1]); + Point_ p((OpointType)imagePoints.at>(0, i)[0], + (OpointType)imagePoints.at>(0, i)[1]); if ((norm(p - projected_points[i]) < params.reprojectionError) && (rotatedPoints.at>(0, i)[2] > 0)) //hack { @@ -212,9 +213,9 @@ namespace cv static void pnpTask(const vector& pointsMask, const Mat& objectPoints, const Mat& imagePoints, const Parameters& params, vector& inliers, Mat& rvec, Mat& tvec, const Mat& rvecInit, const Mat& tvecInit, Mutex& resultsMutex) - { - CV_Assert(objectPoints.depth() == CV_64F || objectPoints.depth() == CV_32F); - CV_Assert(imagePoints.depth() == CV_64F || imagePoints.depth() == CV_32F); + { + CV_Assert(objectPoints.depth() == CV_64F || objectPoints.depth() == CV_32F); + CV_Assert(imagePoints.depth() == CV_64F || imagePoints.depth() == CV_32F); const bool objectDoublePrecision = objectPoints.depth() == CV_64F; const bool imageDoublePrecision = imagePoints.depth() == CV_64F; if(objectDoublePrecision) From 7b160fa3cb1e921ff070e858295e6f3c56ffb454 Mon Sep 17 00:00:00 2001 From: berak Date: Tue, 8 Jul 2014 17:26:23 +0200 Subject: [PATCH 084/662] added missing impl for multi-dim Mat::ones, Mat::zeros (issue #3756) --- modules/core/src/matop.cpp | 30 ++++++++++++++++++++++++++++-- modules/core/test/test_mat.cpp | 15 +++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/modules/core/src/matop.cpp b/modules/core/src/matop.cpp index eefd633189..23b6940c85 100644 --- a/modules/core/src/matop.cpp +++ b/modules/core/src/matop.cpp @@ -200,6 +200,7 @@ public: void multiply(const MatExpr& e, double s, MatExpr& res) const; static void makeExpr(MatExpr& res, int method, Size sz, int type, double alpha=1); + static void makeExpr(MatExpr& res, int method, int ndims, const int* sizes, int type, double alpha=1); }; static MatOp_Initializer* getGlobalMatOpInitializer() @@ -1555,8 +1556,13 @@ void MatOp_Initializer::assign(const MatExpr& e, Mat& m, int _type) const { if( _type == -1 ) _type = e.a.type(); - m.create(e.a.size(), _type); - if( e.flags == 'I' ) + + if( e.a.dims <= 2 ) + m.create(e.a.size(), _type); + else + m.create(e.a.dims, e.a.size, _type); + + if( e.flags == 'I' && e.a.dims <= 2 ) setIdentity(m, Scalar(e.alpha)); else if( e.flags == '0' ) m = Scalar(); @@ -1577,6 +1583,12 @@ inline void MatOp_Initializer::makeExpr(MatExpr& res, int method, Size sz, int t res = MatExpr(getGlobalMatOpInitializer(), method, Mat(sz, type, (void*)0), Mat(), Mat(), alpha, 0); } +inline void MatOp_Initializer::makeExpr(MatExpr& res, int method, int ndims, const int* sizes, int type, double alpha) +{ + res = MatExpr(getGlobalMatOpInitializer(), method, Mat(ndims, sizes, type, (void*)0), Mat(), Mat(), alpha, 0); +} + + /////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1636,6 +1648,20 @@ MatExpr Mat::ones(Size size, int type) return e; } +MatExpr Mat::zeros(int ndims, const int* sizes, int type) +{ + MatExpr e; + MatOp_Initializer::makeExpr(e, '0', ndims, sizes, type); + return e; +} + +MatExpr Mat::ones(int ndims, const int* sizes, int type) +{ + MatExpr e; + MatOp_Initializer::makeExpr(e, '1', ndims, sizes, type); + return e; +} + MatExpr Mat::eye(int rows, int cols, int type) { MatExpr e; diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index a6ebe152d9..f854abed7e 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -918,3 +918,18 @@ TEST(Core_Mat, copyNx1ToVector) ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst16, cv::Mat_(dst16)); } + +TEST(Core_Mat, multiDim) +{ + int d[]={3,3,3}; + Mat m0 = Mat::zeros(3,d,CV_8U); + ASSERT_EQ(0,sum(m0)[0]); + Mat m = Mat::ones(3,d,CV_8U); + ASSERT_EQ(27,sum(m)[0]); + m += 2; + ASSERT_EQ(81,sum(m)[0]); + m *= 3; + ASSERT_EQ(243,sum(m)[0]); + m += m; + ASSERT_EQ(486,sum(m)[0]); +} From 52c05e75cc1987575d7287ece117ec0c321638c1 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 9 Jul 2014 14:19:15 +0200 Subject: [PATCH 085/662] Fixed C++11 compatibility warning --- modules/calib3d/src/solvepnp.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index 081d6bd5c8..1aeb82f64b 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -162,7 +162,7 @@ namespace cv for (int i = 0; i < MIN_POINTS_COUNT; i++) for (int j = i + 1; j < MIN_POINTS_COUNT; j++) { - if (norm(modelObjectPoints.at>(0, i) - modelObjectPoints.at>(0, j)) < eps) + if (norm(modelObjectPoints.at >(0, i) - modelObjectPoints.at >(0, j)) < eps) num_same_points++; } if (num_same_points > 0) @@ -176,7 +176,7 @@ namespace cv params.useExtrinsicGuess, params.flags); - vector> projected_points; + vector > projected_points; projected_points.resize(objectPoints.cols); projectPoints(objectPoints, localRvec, localTvec, params.camera.intrinsics, params.camera.distortion, projected_points); @@ -187,10 +187,10 @@ namespace cv for (int i = 0; i < objectPoints.cols; i++) { //Although p is a 2D point it needs the same type as the object points to enable the norm calculation - Point_ p((OpointType)imagePoints.at>(0, i)[0], - (OpointType)imagePoints.at>(0, i)[1]); + Point_ p((OpointType)imagePoints.at >(0, i)[0], + (OpointType)imagePoints.at >(0, i)[1]); if ((norm(p - projected_points[i]) < params.reprojectionError) - && (rotatedPoints.at>(0, i)[2] > 0)) //hack + && (rotatedPoints.at >(0, i)[2] > 0)) //hack { localInliers.push_back(i); } From 023102c80411eb1b8755ab561327c5c507e378fc Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Wed, 9 Jul 2014 16:55:40 +0400 Subject: [PATCH 086/662] cap_libv4l.cpp depends on both libv4l 1 and 2, so search for both How this worked before, I do not know. --- CMakeLists.txt | 5 +++-- cmake/OpenCVFindLibsVideo.cmake | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b610ecf971..505b2716e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -905,8 +905,9 @@ if(DEFINED WITH_V4L) else() set(HAVE_CAMV4L2_STR "NO") endif() - status(" V4L/V4L2:" HAVE_LIBV4L THEN "Using libv4l (ver ${ALIASOF_libv4l1_VERSION})" - ELSE "${HAVE_CAMV4L_STR}/${HAVE_CAMV4L2_STR}") + status(" V4L/V4L2:" HAVE_LIBV4L + THEN "Using libv4l1 (ver ${ALIASOF_libv4l1_VERSION}) / libv4l2 (ver ${ALIASOF_libv4l2_VERSION})" + ELSE "${HAVE_CAMV4L_STR}/${HAVE_CAMV4L2_STR}") endif(DEFINED WITH_V4L) if(DEFINED WITH_DSHOW) diff --git a/cmake/OpenCVFindLibsVideo.cmake b/cmake/OpenCVFindLibsVideo.cmake index a797f04169..90b8c146a9 100644 --- a/cmake/OpenCVFindLibsVideo.cmake +++ b/cmake/OpenCVFindLibsVideo.cmake @@ -126,7 +126,13 @@ endif(WITH_XINE) ocv_clear_vars(HAVE_LIBV4L HAVE_CAMV4L HAVE_CAMV4L2 HAVE_VIDEOIO) if(WITH_V4L) if(WITH_LIBV4L) - CHECK_MODULE(libv4l1 HAVE_LIBV4L) + CHECK_MODULE(libv4l1 HAVE_LIBV4L1) + CHECK_MODULE(libv4l2 HAVE_LIBV4L2) + if(HAVE_LIBV4L1 AND HAVE_LIBV4L2) + set(HAVE_LIBV4L YES) + else() + set(HAVE_LIBV4L NO) + endif() endif() CHECK_INCLUDE_FILE(linux/videodev.h HAVE_CAMV4L) CHECK_INCLUDE_FILE(linux/videodev2.h HAVE_CAMV4L2) From ecec53f509520ad990cb2d20fcaaa85d0f00d5e9 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Wed, 9 Jul 2014 17:46:22 +0400 Subject: [PATCH 087/662] fixed docs --- modules/gpu/doc/video.rst | 8 ++++---- modules/imgproc/doc/filtering.rst | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/gpu/doc/video.rst b/modules/gpu/doc/video.rst index ea15a062a3..ac9e698412 100644 --- a/modules/gpu/doc/video.rst +++ b/modules/gpu/doc/video.rst @@ -302,7 +302,7 @@ gpu::FGDStatModel ----------------- .. ocv:class:: gpu::FGDStatModel -Class used for background/foreground segmentation. :: + Class used for background/foreground segmentation. :: class FGDStatModel { @@ -400,7 +400,7 @@ gpu::MOG_GPU ------------ .. ocv:class:: gpu::MOG_GPU -Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm. :: + Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm. :: class MOG_GPU { @@ -479,7 +479,7 @@ gpu::MOG2_GPU ------------- .. ocv:class:: gpu::MOG2_GPU -Gaussian Mixture-based Background/Foreground Segmentation Algorithm. :: + Gaussian Mixture-based Background/Foreground Segmentation Algorithm. :: class MOG2_GPU { @@ -594,7 +594,7 @@ gpu::GMG_GPU Class used for background/foreground segmentation. :: - class GMG_GPU_GPU + class GMG_GPU { public: GMG_GPU(); diff --git a/modules/imgproc/doc/filtering.rst b/modules/imgproc/doc/filtering.rst index 130b8e01a3..8232b06ac3 100755 --- a/modules/imgproc/doc/filtering.rst +++ b/modules/imgproc/doc/filtering.rst @@ -1213,7 +1213,7 @@ Performs advanced morphological transformations. .. ocv:cfunction:: void cvMorphologyEx( const CvArr* src, CvArr* dst, CvArr* temp, IplConvKernel* element, int operation, int iterations=1 ) .. ocv:pyoldfunction:: cv.MorphologyEx(src, dst, temp, element, operation, iterations=1)-> None - :param src: Source image. The number of channels can be arbitrary. The depth should be one of ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32F` or ``CV_64F``. + :param src: Source image. The number of channels can be arbitrary. The depth should be one of ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32F`` or ``CV_64F``. :param dst: Destination image of the same size and type as ``src`` . From cbb5fc0acc3637006e7cb8480ade9e13a2da99fc Mon Sep 17 00:00:00 2001 From: Camille Date: Wed, 9 Jul 2014 22:35:56 +0200 Subject: [PATCH 088/662] bug fix 3696 --- modules/core/src/matop.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/core/src/matop.cpp b/modules/core/src/matop.cpp index 23b6940c85..1135d9a0da 100644 --- a/modules/core/src/matop.cpp +++ b/modules/core/src/matop.cpp @@ -1043,14 +1043,14 @@ MatExpr min(const Mat& a, const Mat& b) MatExpr min(const Mat& a, double s) { MatExpr e; - MatOp_Bin::makeExpr(e, 'm', a, s); + MatOp_Bin::makeExpr(e, 'n', a, s); return e; } MatExpr min(double s, const Mat& a) { MatExpr e; - MatOp_Bin::makeExpr(e, 'm', a, s); + MatOp_Bin::makeExpr(e, 'n', a, s); return e; } @@ -1064,14 +1064,14 @@ MatExpr max(const Mat& a, const Mat& b) MatExpr max(const Mat& a, double s) { MatExpr e; - MatOp_Bin::makeExpr(e, 'M', a, s); + MatOp_Bin::makeExpr(e, 'N', a, s); return e; } MatExpr max(double s, const Mat& a) { MatExpr e; - MatOp_Bin::makeExpr(e, 'M', a, s); + MatOp_Bin::makeExpr(e, 'N', a, s); return e; } @@ -1337,13 +1337,13 @@ void MatOp_Bin::assign(const MatExpr& e, Mat& m, int _type) const bitwise_xor(e.a, e.s, dst); else if( e.flags == '~' && !e.b.data ) bitwise_not(e.a, dst); - else if( e.flags == 'm' && e.b.data ) + else if( e.flags == 'm' ) cv::min(e.a, e.b, dst); - else if( e.flags == 'm' && !e.b.data ) + else if( e.flags == 'n' ) cv::min(e.a, e.s[0], dst); - else if( e.flags == 'M' && e.b.data ) + else if( e.flags == 'M' ) cv::max(e.a, e.b, dst); - else if( e.flags == 'M' && !e.b.data ) + else if( e.flags == 'N' ) cv::max(e.a, e.s[0], dst); else if( e.flags == 'a' && e.b.data ) cv::absdiff(e.a, e.b, dst); From c38023f4e78b68d0fba9fb5ba682cb91ee0d42b5 Mon Sep 17 00:00:00 2001 From: Richard Yoo Date: Wed, 9 Jul 2014 16:55:39 -0700 Subject: [PATCH 089/662] Modifications to support dynamic vector dispatch. --- cmake/OpenCVCompilerOptions.cmake | 8 +- cmake/OpenCVModule.cmake | 14 + ...tility_and_system_functions_and_macros.rst | 1 + modules/core/include/opencv2/core/core.hpp | 1 + modules/core/src/system.cpp | 2 - modules/imgproc/src/avx/imgwarp_avx.cpp | 176 ++++++ modules/imgproc/src/avx/imgwarp_avx.hpp | 51 ++ modules/imgproc/src/avx2/imgwarp_avx2.cpp | 431 +++++++++++++ modules/imgproc/src/avx2/imgwarp_avx2.hpp | 57 ++ modules/imgproc/src/imgwarp.cpp | 598 ++---------------- modules/ts/src/ts_func.cpp | 4 - 11 files changed, 786 insertions(+), 557 deletions(-) create mode 100644 modules/imgproc/src/avx/imgwarp_avx.cpp create mode 100644 modules/imgproc/src/avx/imgwarp_avx.hpp create mode 100644 modules/imgproc/src/avx2/imgwarp_avx2.cpp create mode 100644 modules/imgproc/src/avx2/imgwarp_avx2.hpp diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index f28aaeed50..7de23a66bc 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -140,15 +140,15 @@ if(CMAKE_COMPILER_IS_GNUCXX) # SSE3 and further should be disabled under MingW because it generates compiler errors if(NOT MINGW) if(ENABLE_AVX) - add_extra_compiler_option(-mavx) + ocv_check_flag_support(CXX "-mavx" _varname) endif() if(ENABLE_AVX2) - add_extra_compiler_option(-mavx2) + ocv_check_flag_support(CXX "-mavx2" _varname) endif() # GCC depresses SSEx instructions when -mavx is used. Instead, it generates new AVX instructions or AVX equivalence for all SSEx instructions when needed. - if(NOT OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(avx|avx2)") + if(NOT OPENCV_EXTRA_CXX_FLAGS MATCHES "-mavx") if(ENABLE_SSE3) add_extra_compiler_option(-msse3) endif() @@ -169,7 +169,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) if(X86 OR X86_64) if(NOT APPLE AND CMAKE_SIZEOF_VOID_P EQUAL 4) - if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx|avx2)") + if(OPENCV_EXTRA_CXX_FLAGS MATCHES "-m(sse2|avx)") add_extra_compiler_option(-mfpmath=sse)# !! important - be on the same wave with x64 compilers else() add_extra_compiler_option(-mfpmath=387) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index 79e508609e..f9d333f8d9 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -526,6 +526,20 @@ 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") endif() + if(ENABLE_AVX) + file(GLOB avx_srcs "src/avx/*.cpp") + foreach(src ${avx_srcs}) + set_source_files_properties(${src} PROPERTIES COMPILE_FLAGS -mavx) + endforeach() + endif() + + if(ENABLE_AVX2) + file(GLOB avx2_srcs "src/avx2/*.cpp") + foreach(src ${avx2_srcs}) + set_source_files_properties(${src} PROPERTIES COMPILE_FLAGS -mavx2) + endforeach() + endif() + source_group("Include" FILES ${lib_hdrs}) source_group("Include\\detail" FILES ${lib_hdrs_detail}) diff --git a/modules/core/doc/utility_and_system_functions_and_macros.rst b/modules/core/doc/utility_and_system_functions_and_macros.rst index 41cf7e1b72..73a6b65386 100644 --- a/modules/core/doc/utility_and_system_functions_and_macros.rst +++ b/modules/core/doc/utility_and_system_functions_and_macros.rst @@ -317,6 +317,7 @@ Returns true if the specified feature is supported by the host hardware. * ``CV_CPU_SSE4_2`` - SSE 4.2 * ``CV_CPU_POPCNT`` - POPCOUNT * ``CV_CPU_AVX`` - AVX + * ``CV_CPU_AVX2`` - AVX2 The function returns true if the host hardware supports the specified feature. When user calls ``setUseOptimized(false)``, the subsequent calls to ``checkHardwareSupport()`` will return false until ``setUseOptimized(true)`` is called. This way user can dynamically switch on and off the optimized code in OpenCV. diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 5667e9e50f..76b9e68133 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -284,6 +284,7 @@ CV_EXPORTS_W int64 getCPUTickCount(); - CV_CPU_SSE4_2 - SSE 4.2 - CV_CPU_POPCNT - POPCOUNT - CV_CPU_AVX - AVX + - CV_CPU_AVX2 - AVX2 \note {Note that the function output is not static. Once you called cv::useOptimized(false), most of the hardware acceleration is disabled and thus the function will returns false, diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 40d64ffe1b..5a970d511e 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -253,7 +253,6 @@ struct HWFeatures f.have[CV_CPU_AVX] = (((cpuid_data[2] & (1<<28)) != 0)&&((cpuid_data[2] & (1<<27)) != 0));//OS uses XSAVE_XRSTORE and CPU support AVX } -#if CV_AVX2 #if defined _MSC_VER && (defined _M_IX86 || defined _M_X64) __cpuidex(cpuid_data, 7, 0); #elif defined __GNUC__ && (defined __i386__ || defined __x86_64__) @@ -286,7 +285,6 @@ struct HWFeatures { f.have[CV_CPU_AVX2] = (cpuid_data[1] & (1<<5)) != 0; } -#endif return f; } diff --git a/modules/imgproc/src/avx/imgwarp_avx.cpp b/modules/imgproc/src/avx/imgwarp_avx.cpp new file mode 100644 index 0000000000..b7ab44a189 --- /dev/null +++ b/modules/imgproc/src/avx/imgwarp_avx.cpp @@ -0,0 +1,176 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "../precomp.hpp" +#include "imgwarp_avx.hpp" + +#if CV_AVX +int VResizeLinearVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1]; + float* dst = (float*)_dst; + int x = 0; + + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]); + + if( (((size_t)S0|(size_t)S1)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + + _mm256_storeu_ps( dst + x, x0); + _mm256_storeu_ps( dst + x + 8, x1); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + + _mm256_storeu_ps( dst + x, x0); + _mm256_storeu_ps( dst + x + 8, x1); + } + + return x; +} + +int VResizeCubicVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + float* dst = (float*)_dst; + int x = 0; + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]), + b2 = _mm256_set1_ps(beta[2]), b3 = _mm256_set1_ps(beta[3]); + + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_load_ps(S2 + x); + x1 = _mm256_load_ps(S2 + x + 8); + y0 = _mm256_load_ps(S3 + x); + y1 = _mm256_load_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + _mm256_storeu_ps( dst + x, s0); + _mm256_storeu_ps( dst + x + 8, s1); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_loadu_ps(S2 + x); + x1 = _mm256_loadu_ps(S2 + x + 8); + y0 = _mm256_loadu_ps(S3 + x); + y1 = _mm256_loadu_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + _mm256_storeu_ps( dst + x, s0); + _mm256_storeu_ps( dst + x + 8, s1); + } + + return x; +} +#else +int VResizeLinearVec_32f_avx(const uchar**, uchar*, const uchar*, int ) { return 0; } + +int VResizeCubicVec_32f_avx(const uchar**, uchar*, const uchar*, int ) { return 0; } +#endif + +/* End of file. */ diff --git a/modules/imgproc/src/avx/imgwarp_avx.hpp b/modules/imgproc/src/avx/imgwarp_avx.hpp new file mode 100644 index 0000000000..d3e3a2b342 --- /dev/null +++ b/modules/imgproc/src/avx/imgwarp_avx.hpp @@ -0,0 +1,51 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef _CV_IMGWARP_AVX_H_ +#define _CV_IMGWARP_AVX_H_ + +int VResizeLinearVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); + +int VResizeCubicVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); + +#endif + +/* End of file. */ diff --git a/modules/imgproc/src/avx2/imgwarp_avx2.cpp b/modules/imgproc/src/avx2/imgwarp_avx2.cpp new file mode 100644 index 0000000000..6e4f1fc6e8 --- /dev/null +++ b/modules/imgproc/src/avx2/imgwarp_avx2.cpp @@ -0,0 +1,431 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "../precomp.hpp" +#include "imgwarp_avx2.hpp" + +const int INTER_RESIZE_COEF_BITS=11; +const int INTER_RESIZE_COEF_SCALE=1 << INTER_RESIZE_COEF_BITS; + +#if CV_AVX2 +int VResizeLinearVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) +{ + const int** src = (const int**)_src; + const short* beta = (const short*)_beta; + const int *S0 = src[0], *S1 = src[1]; + int x = 0; + __m256i b0 = _mm256_set1_epi16(beta[0]), b1 = _mm256_set1_epi16(beta[1]); + __m256i delta = _mm256_set1_epi16(2); + const int index[8] = { 0, 4, 1, 5, 2, 6, 3, 7 }; + __m256i shuffle = _mm256_load_si256((const __m256i*)index); + + if( (((size_t)S0|(size_t)S1)&31) == 0 ) + for( ; x <= width - 32; x += 32 ) + { + __m256i x0, x1, x2, y0, y1, y2; + x0 = _mm256_load_si256((const __m256i*)(S0 + x)); + x1 = _mm256_load_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_load_si256((const __m256i*)(S1 + x)); + y1 = _mm256_load_si256((const __m256i*)(S1 + x + 8)); + x0 = _mm256_packs_epi32(_mm256_srai_epi32(x0, 4), _mm256_srai_epi32(x1, 4)); + y0 = _mm256_packs_epi32(_mm256_srai_epi32(y0, 4), _mm256_srai_epi32(y1, 4)); + + x1 = _mm256_load_si256((const __m256i*)(S0 + x + 16)); + x2 = _mm256_load_si256((const __m256i*)(S0 + x + 24)); + y1 = _mm256_load_si256((const __m256i*)(S1 + x + 16)); + y2 = _mm256_load_si256((const __m256i*)(S1 + x + 24)); + x1 = _mm256_packs_epi32(_mm256_srai_epi32(x1, 4), _mm256_srai_epi32(x2, 4)); + y1 = _mm256_packs_epi32(_mm256_srai_epi32(y1, 4), _mm256_srai_epi32(y2, 4)); + + x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); + x1 = _mm256_adds_epi16(_mm256_mulhi_epi16(x1, b0), _mm256_mulhi_epi16(y1, b1)); + + x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); + x1 = _mm256_srai_epi16(_mm256_adds_epi16(x1, delta), 2); + x0 = _mm256_packus_epi16(x0, x1); + x0 = _mm256_permutevar8x32_epi32(x0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), x0); + } + else + for( ; x <= width - 32; x += 32 ) + { + __m256i x0, x1, x2, y0, y1, y2; + x0 = _mm256_loadu_si256((const __m256i*)(S0 + x)); + x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_loadu_si256((const __m256i*)(S1 + x)); + y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 8)); + x0 = _mm256_packs_epi32(_mm256_srai_epi32(x0, 4), _mm256_srai_epi32(x1, 4)); + y0 = _mm256_packs_epi32(_mm256_srai_epi32(y0, 4), _mm256_srai_epi32(y1, 4)); + + x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 16)); + x2 = _mm256_loadu_si256((const __m256i*)(S0 + x + 24)); + y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 16)); + y2 = _mm256_loadu_si256((const __m256i*)(S1 + x + 24)); + x1 = _mm256_packs_epi32(_mm256_srai_epi32(x1, 4), _mm256_srai_epi32(x2, 4)); + y1 = _mm256_packs_epi32(_mm256_srai_epi32(y1, 4), _mm256_srai_epi32(y2, 4)); + + x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); + x1 = _mm256_adds_epi16(_mm256_mulhi_epi16(x1, b0), _mm256_mulhi_epi16(y1, b1)); + + x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); + x1 = _mm256_srai_epi16(_mm256_adds_epi16(x1, delta), 2); + x0 = _mm256_packus_epi16(x0, x1); + x0 = _mm256_permutevar8x32_epi32(x0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), x0); + } + + for( ; x < width - 8; x += 8 ) + { + __m256i x0, y0; + x0 = _mm256_srai_epi32(_mm256_loadu_si256((const __m256i*)(S0 + x)), 4); + y0 = _mm256_srai_epi32(_mm256_loadu_si256((const __m256i*)(S1 + x)), 4); + x0 = _mm256_packs_epi32(x0, x0); + y0 = _mm256_packs_epi32(y0, y0); + x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); + x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); + x0 = _mm256_packus_epi16(x0, x0); + *(int*)(dst + x) = _mm_cvtsi128_si32(_mm256_extracti128_si256(x0, 0)); + *(int*)(dst + x + 4) = _mm_cvtsi128_si32(_mm256_extracti128_si256(x0, 1)); + } + + return x; +} + +template +int VResizeLinearVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1]; + ushort* dst = (ushort*)_dst; + int x = 0; + + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]); + __m256i preshift = _mm256_set1_epi32(shiftval); + __m256i postshift = _mm256_set1_epi16((short)shiftval); + + if( (((size_t)S0|(size_t)S1)&31) == 0 ) + for( ; x <= width - 32; x += 32 ) + { + __m256 x0, x1, y0, y1; + __m256i t0, t1, t2; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t2), postshift); + + x0 = _mm256_load_ps(S0 + x + 16); + x1 = _mm256_load_ps(S0 + x + 24); + y0 = _mm256_load_ps(S1 + x + 16); + y1 = _mm256_load_ps(S1 + x + 24); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t1 = _mm256_add_epi16(_mm256_packs_epi32(t1, t2), postshift); + + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + _mm256_storeu_si256( (__m256i*)(dst + x + 16), t1); + } + else + for( ; x <= width - 32; x += 32 ) + { + __m256 x0, x1, y0, y1; + __m256i t0, t1, t2; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t2), postshift); + + x0 = _mm256_loadu_ps(S0 + x + 16); + x1 = _mm256_loadu_ps(S0 + x + 24); + y0 = _mm256_loadu_ps(S1 + x + 16); + y1 = _mm256_loadu_ps(S1 + x + 24); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); + t1 = _mm256_add_epi16(_mm256_packs_epi32(t1, t2), postshift); + + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + _mm256_storeu_si256( (__m256i*)(dst + x + 16), t1); + } + + for( ; x < width - 8; x += 8 ) + { + __m256 x0, y0; + __m256i t0; + x0 = _mm256_loadu_ps(S0 + x); + y0 = _mm256_loadu_ps(S1 + x); + + x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t0), postshift); + _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(t0, 0)); + _mm_storel_epi64( (__m128i*)(dst + x + 4), _mm256_extracti128_si256(t0, 1)); + } + + return x; +} + +int VResizeCubicVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) +{ + const int** src = (const int**)_src; + const short* beta = (const short*)_beta; + const int *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + int x = 0; + float scale = 1.f/(INTER_RESIZE_COEF_SCALE*INTER_RESIZE_COEF_SCALE); + __m256 b0 = _mm256_set1_ps(beta[0]*scale), b1 = _mm256_set1_ps(beta[1]*scale), + b2 = _mm256_set1_ps(beta[2]*scale), b3 = _mm256_set1_ps(beta[3]*scale); + const int shuffle = 0xd8; // 11 | 01 | 10 | 00 + + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256i x0, x1, y0, y1; + __m256 s0, s1, f0, f1; + x0 = _mm256_load_si256((const __m256i*)(S0 + x)); + x1 = _mm256_load_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_load_si256((const __m256i*)(S1 + x)); + y1 = _mm256_load_si256((const __m256i*)(S1 + x + 8)); + + s0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b0); + s1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b0); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b1); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b1); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_load_si256((const __m256i*)(S2 + x)); + x1 = _mm256_load_si256((const __m256i*)(S2 + x + 8)); + y0 = _mm256_load_si256((const __m256i*)(S3 + x)); + y1 = _mm256_load_si256((const __m256i*)(S3 + x + 8)); + + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b2); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b2); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b3); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b3); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_cvtps_epi32(s0); + x1 = _mm256_cvtps_epi32(s1); + + x0 = _mm256_packs_epi32(x0, x1); + x0 = _mm256_permute4x64_epi64(x0, shuffle); + x0 = _mm256_packus_epi16(x0, x0); + _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(x0, 0)); + _mm_storel_epi64( (__m128i*)(dst + x + 8), _mm256_extracti128_si256(x0, 1)); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256i x0, x1, y0, y1; + __m256 s0, s1, f0, f1; + x0 = _mm256_loadu_si256((const __m256i*)(S0 + x)); + x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 8)); + y0 = _mm256_loadu_si256((const __m256i*)(S1 + x)); + y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 8)); + + s0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b0); + s1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b0); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b1); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b1); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_loadu_si256((const __m256i*)(S2 + x)); + x1 = _mm256_loadu_si256((const __m256i*)(S2 + x + 8)); + y0 = _mm256_loadu_si256((const __m256i*)(S3 + x)); + y1 = _mm256_loadu_si256((const __m256i*)(S3 + x + 8)); + + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b2); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b2); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b3); + f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b3); + s0 = _mm256_add_ps(s0, f0); + s1 = _mm256_add_ps(s1, f1); + + x0 = _mm256_cvtps_epi32(s0); + x1 = _mm256_cvtps_epi32(s1); + + x0 = _mm256_packs_epi32(x0, x1); + x0 = _mm256_permute4x64_epi64(x0, shuffle); + x0 = _mm256_packus_epi16(x0, x0); + _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(x0, 0)); + _mm_storel_epi64( (__m128i*)(dst + x + 8), _mm256_extracti128_si256(x0, 1)); + } + + return x; +} + +template +int VResizeCubicVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) +{ + const float** src = (const float**)_src; + const float* beta = (const float*)_beta; + const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; + ushort* dst = (ushort*)_dst; + int x = 0; + __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]), + b2 = _mm256_set1_ps(beta[2]), b3 = _mm256_set1_ps(beta[3]); + __m256i preshift = _mm256_set1_epi32(shiftval); + __m256i postshift = _mm256_set1_epi16((short)shiftval); + const int shuffle = 0xd8; // 11 | 01 | 10 | 00 + + if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + __m256i t0, t1; + x0 = _mm256_load_ps(S0 + x); + x1 = _mm256_load_ps(S0 + x + 8); + y0 = _mm256_load_ps(S1 + x); + y1 = _mm256_load_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_load_ps(S2 + x); + x1 = _mm256_load_ps(S2 + x + 8); + y0 = _mm256_load_ps(S3 + x); + y1 = _mm256_load_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(s0), preshift); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(s1), preshift); + + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t1), postshift); + t0 = _mm256_permute4x64_epi64(t0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + } + else + for( ; x <= width - 16; x += 16 ) + { + __m256 x0, x1, y0, y1, s0, s1; + __m256i t0, t1; + x0 = _mm256_loadu_ps(S0 + x); + x1 = _mm256_loadu_ps(S0 + x + 8); + y0 = _mm256_loadu_ps(S1 + x); + y1 = _mm256_loadu_ps(S1 + x + 8); + + s0 = _mm256_mul_ps(x0, b0); + s1 = _mm256_mul_ps(x1, b0); + y0 = _mm256_mul_ps(y0, b1); + y1 = _mm256_mul_ps(y1, b1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + x0 = _mm256_loadu_ps(S2 + x); + x1 = _mm256_loadu_ps(S2 + x + 8); + y0 = _mm256_loadu_ps(S3 + x); + y1 = _mm256_loadu_ps(S3 + x + 8); + + x0 = _mm256_mul_ps(x0, b2); + x1 = _mm256_mul_ps(x1, b2); + y0 = _mm256_mul_ps(y0, b3); + y1 = _mm256_mul_ps(y1, b3); + s0 = _mm256_add_ps(s0, x0); + s1 = _mm256_add_ps(s1, x1); + s0 = _mm256_add_ps(s0, y0); + s1 = _mm256_add_ps(s1, y1); + + t0 = _mm256_add_epi32(_mm256_cvtps_epi32(s0), preshift); + t1 = _mm256_add_epi32(_mm256_cvtps_epi32(s1), preshift); + + t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t1), postshift); + t0 = _mm256_permute4x64_epi64(t0, shuffle); + _mm256_storeu_si256( (__m256i*)(dst + x), t0); + } + + return x; +} +#else +int VResizeLinearVec_32s8u_avx2(const uchar**, uchar*, const uchar*, int ) { return 0; } + +template +int VResizeLinearVec_32f16_avx2(const uchar**, uchar*, const uchar*, int ) { return 0; } + +int VResizeCubicVec_32s8u_avx2(const uchar**, uchar*, const uchar*, int ) { return 0; } + +template +int VResizeCubicVec_32f16_avx2(const uchar**, uchar*, const uchar*, int ) { return 0; } +#endif + +// Template instantiations. +template int VResizeLinearVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); +template int VResizeLinearVec_32f16_avx2<0>(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); + +template int VResizeCubicVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); +template int VResizeCubicVec_32f16_avx2<0>(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); + +/* End of file. */ diff --git a/modules/imgproc/src/avx2/imgwarp_avx2.hpp b/modules/imgproc/src/avx2/imgwarp_avx2.hpp new file mode 100644 index 0000000000..f4d4e63c73 --- /dev/null +++ b/modules/imgproc/src/avx2/imgwarp_avx2.hpp @@ -0,0 +1,57 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// Intel License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000, Intel Corporation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of Intel Corporation may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#ifndef _CV_IMGWARP_AVX2_H_ +#define _CV_IMGWARP_AVX2_H_ + +int VResizeLinearVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ); + +template +int VResizeLinearVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); + +int VResizeCubicVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ); + +template +int VResizeCubicVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ); + +#endif + +/* End of file. */ diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index 88b278710d..b77526044c 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -47,6 +47,8 @@ // */ #include "precomp.hpp" +#include "avx/imgwarp_avx.hpp" +#include "avx2/imgwarp_avx2.hpp" #include #include @@ -54,10 +56,6 @@ static IppStatus sts = ippInit(); #endif -#ifdef _MSC_VER -# pragma warning(disable:4752) // Disable warning for mixing SSE and AVX -#endif - namespace cv { @@ -455,7 +453,7 @@ struct HResizeNoVec #if CV_SSE2 -static int VResizeLinearVec_32s8u_sse2(const uchar** _src, uchar* dst, const uchar* _beta, int width) +static int VResizeLinearVec_32s8u_sse2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) { const int** src = (const int**)_src; const short* beta = (const short*)_beta; @@ -531,103 +529,19 @@ static int VResizeLinearVec_32s8u_sse2(const uchar** _src, uchar* dst, const uch return x; } -#if CV_AVX2 -int VResizeLinearVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) -{ - const int** src = (const int**)_src; - const short* beta = (const short*)_beta; - const int *S0 = src[0], *S1 = src[1]; - int x = 0; - __m256i b0 = _mm256_set1_epi16(beta[0]), b1 = _mm256_set1_epi16(beta[1]); - __m256i delta = _mm256_set1_epi16(2); - const int index[8] = { 0, 4, 1, 5, 2, 6, 3, 7 }; - __m256i shuffle = _mm256_load_si256((const __m256i*)index); - - if( (((size_t)S0|(size_t)S1)&31) == 0 ) - for( ; x <= width - 32; x += 32 ) - { - __m256i x0, x1, x2, y0, y1, y2; - x0 = _mm256_load_si256((const __m256i*)(S0 + x)); - x1 = _mm256_load_si256((const __m256i*)(S0 + x + 8)); - y0 = _mm256_load_si256((const __m256i*)(S1 + x)); - y1 = _mm256_load_si256((const __m256i*)(S1 + x + 8)); - x0 = _mm256_packs_epi32(_mm256_srai_epi32(x0, 4), _mm256_srai_epi32(x1, 4)); - y0 = _mm256_packs_epi32(_mm256_srai_epi32(y0, 4), _mm256_srai_epi32(y1, 4)); - - x1 = _mm256_load_si256((const __m256i*)(S0 + x + 16)); - x2 = _mm256_load_si256((const __m256i*)(S0 + x + 24)); - y1 = _mm256_load_si256((const __m256i*)(S1 + x + 16)); - y2 = _mm256_load_si256((const __m256i*)(S1 + x + 24)); - x1 = _mm256_packs_epi32(_mm256_srai_epi32(x1, 4), _mm256_srai_epi32(x2, 4)); - y1 = _mm256_packs_epi32(_mm256_srai_epi32(y1, 4), _mm256_srai_epi32(y2, 4)); - - x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); - x1 = _mm256_adds_epi16(_mm256_mulhi_epi16(x1, b0), _mm256_mulhi_epi16(y1, b1)); - - x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); - x1 = _mm256_srai_epi16(_mm256_adds_epi16(x1, delta), 2); - x0 = _mm256_packus_epi16(x0, x1); - x0 = _mm256_permutevar8x32_epi32(x0, shuffle); - _mm256_storeu_si256( (__m256i*)(dst + x), x0); - } - else - for( ; x <= width - 32; x += 32 ) - { - __m256i x0, x1, x2, y0, y1, y2; - x0 = _mm256_loadu_si256((const __m256i*)(S0 + x)); - x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 8)); - y0 = _mm256_loadu_si256((const __m256i*)(S1 + x)); - y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 8)); - x0 = _mm256_packs_epi32(_mm256_srai_epi32(x0, 4), _mm256_srai_epi32(x1, 4)); - y0 = _mm256_packs_epi32(_mm256_srai_epi32(y0, 4), _mm256_srai_epi32(y1, 4)); - - x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 16)); - x2 = _mm256_loadu_si256((const __m256i*)(S0 + x + 24)); - y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 16)); - y2 = _mm256_loadu_si256((const __m256i*)(S1 + x + 24)); - x1 = _mm256_packs_epi32(_mm256_srai_epi32(x1, 4), _mm256_srai_epi32(x2, 4)); - y1 = _mm256_packs_epi32(_mm256_srai_epi32(y1, 4), _mm256_srai_epi32(y2, 4)); - - x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); - x1 = _mm256_adds_epi16(_mm256_mulhi_epi16(x1, b0), _mm256_mulhi_epi16(y1, b1)); - - x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); - x1 = _mm256_srai_epi16(_mm256_adds_epi16(x1, delta), 2); - x0 = _mm256_packus_epi16(x0, x1); - x0 = _mm256_permutevar8x32_epi32(x0, shuffle); - _mm256_storeu_si256( (__m256i*)(dst + x), x0); - } - - for( ; x < width - 8; x += 8 ) - { - __m256i x0, y0; - x0 = _mm256_srai_epi32(_mm256_loadu_si256((const __m256i*)(S0 + x)), 4); - y0 = _mm256_srai_epi32(_mm256_loadu_si256((const __m256i*)(S1 + x)), 4); - x0 = _mm256_packs_epi32(x0, x0); - y0 = _mm256_packs_epi32(y0, y0); - x0 = _mm256_adds_epi16(_mm256_mulhi_epi16(x0, b0), _mm256_mulhi_epi16(y0, b1)); - x0 = _mm256_srai_epi16(_mm256_adds_epi16(x0, delta), 2); - x0 = _mm256_packus_epi16(x0, x0); - *(int*)(dst + x) = _mm_cvtsi128_si32(_mm256_extracti128_si256(x0, 0)); - *(int*)(dst + x + 4) = _mm_cvtsi128_si32(_mm256_extracti128_si256(x0, 1)); - } - - return x; -} -#endif - struct VResizeLinearVec_32s8u { int operator()(const uchar** _src, uchar* dst, const uchar* _beta, int width ) const { -#if CV_AVX2 - if( checkHardwareSupport(CV_CPU_AVX2) ) - return VResizeLinearVec_32s8u_avx2(_src, dst, _beta, width); -#endif - if( checkHardwareSupport(CV_CPU_SSE2) ) - return VResizeLinearVec_32s8u_sse2(_src, dst, _beta, width); + int processed = 0; - return 0; + if( checkHardwareSupport(CV_CPU_AVX2) ) + processed += VResizeLinearVec_32s8u_avx2(_src, dst, _beta, width); + + if( !processed && checkHardwareSupport(CV_CPU_SSE2) ) + processed += VResizeLinearVec_32s8u_sse2(_src, dst, _beta, width); + + return processed; } }; @@ -721,111 +635,19 @@ int VResizeLinearVec_32f16_sse2(const uchar** _src, uchar* _dst, const uchar* _b return x; } -#if CV_AVX2 -template -int VResizeLinearVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) -{ - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1]; - ushort* dst = (ushort*)_dst; - int x = 0; - - __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]); - __m256i preshift = _mm256_set1_epi32(shiftval); - __m256i postshift = _mm256_set1_epi16((short)shiftval); - - if( (((size_t)S0|(size_t)S1)&31) == 0 ) - for( ; x <= width - 32; x += 32 ) - { - __m256 x0, x1, y0, y1; - __m256i t0, t1, t2; - x0 = _mm256_load_ps(S0 + x); - x1 = _mm256_load_ps(S0 + x + 8); - y0 = _mm256_load_ps(S1 + x); - y1 = _mm256_load_ps(S1 + x + 8); - - x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); - x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); - t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); - t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); - t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t2), postshift); - - x0 = _mm256_load_ps(S0 + x + 16); - x1 = _mm256_load_ps(S0 + x + 24); - y0 = _mm256_load_ps(S1 + x + 16); - y1 = _mm256_load_ps(S1 + x + 24); - - x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); - x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); - t1 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); - t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); - t1 = _mm256_add_epi16(_mm256_packs_epi32(t1, t2), postshift); - - _mm256_storeu_si256( (__m256i*)(dst + x), t0); - _mm256_storeu_si256( (__m256i*)(dst + x + 16), t1); - } - else - for( ; x <= width - 32; x += 32 ) - { - __m256 x0, x1, y0, y1; - __m256i t0, t1, t2; - x0 = _mm256_loadu_ps(S0 + x); - x1 = _mm256_loadu_ps(S0 + x + 8); - y0 = _mm256_loadu_ps(S1 + x); - y1 = _mm256_loadu_ps(S1 + x + 8); - - x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); - x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); - t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); - t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); - t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t2), postshift); - - x0 = _mm256_loadu_ps(S0 + x + 16); - x1 = _mm256_loadu_ps(S0 + x + 24); - y0 = _mm256_loadu_ps(S1 + x + 16); - y1 = _mm256_loadu_ps(S1 + x + 24); - - x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); - x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); - t1 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); - t2 = _mm256_add_epi32(_mm256_cvtps_epi32(x1), preshift); - t1 = _mm256_add_epi16(_mm256_packs_epi32(t1, t2), postshift); - - _mm256_storeu_si256( (__m256i*)(dst + x), t0); - _mm256_storeu_si256( (__m256i*)(dst + x + 16), t1); - } - - for( ; x < width - 8; x += 8 ) - { - __m256 x0, y0; - __m256i t0; - x0 = _mm256_loadu_ps(S0 + x); - y0 = _mm256_loadu_ps(S1 + x); - - x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); - t0 = _mm256_add_epi32(_mm256_cvtps_epi32(x0), preshift); - t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t0), postshift); - _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(t0, 0)); - _mm_storel_epi64( (__m128i*)(dst + x + 4), _mm256_extracti128_si256(t0, 1)); - } - - return x; -} -#endif - template struct VResizeLinearVec_32f16 { int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const { -#if CV_AVX2 - if( checkHardwareSupport(CV_CPU_AVX2) ) - return VResizeLinearVec_32f16_avx2(_src, _dst, _beta, width); -#endif - if( checkHardwareSupport(CV_CPU_SSE2) ) - return VResizeLinearVec_32f16_sse2(_src, _dst, _beta, width); + int processed = 0; - return 0; + if( checkHardwareSupport(CV_CPU_AVX2) ) + processed += VResizeLinearVec_32f16_avx2(_src, _dst, _beta, width); + + if( !processed && checkHardwareSupport(CV_CPU_SSE2) ) + processed += VResizeLinearVec_32f16_sse2(_src, _dst, _beta, width); + + return processed; } }; @@ -876,68 +698,22 @@ static int VResizeLinearVec_32f_sse(const uchar** _src, uchar* _dst, const uchar return x; } -#if CV_AVX -int VResizeLinearVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) -{ - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1]; - float* dst = (float*)_dst; - int x = 0; - - __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]); - - if( (((size_t)S0|(size_t)S1)&31) == 0 ) - for( ; x <= width - 16; x += 16 ) - { - __m256 x0, x1, y0, y1; - x0 = _mm256_load_ps(S0 + x); - x1 = _mm256_load_ps(S0 + x + 8); - y0 = _mm256_load_ps(S1 + x); - y1 = _mm256_load_ps(S1 + x + 8); - - x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); - x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); - - _mm256_storeu_ps( dst + x, x0); - _mm256_storeu_ps( dst + x + 8, x1); - } - else - for( ; x <= width - 16; x += 16 ) - { - __m256 x0, x1, y0, y1; - x0 = _mm256_loadu_ps(S0 + x); - x1 = _mm256_loadu_ps(S0 + x + 8); - y0 = _mm256_loadu_ps(S1 + x); - y1 = _mm256_loadu_ps(S1 + x + 8); - - x0 = _mm256_add_ps(_mm256_mul_ps(x0, b0), _mm256_mul_ps(y0, b1)); - x1 = _mm256_add_ps(_mm256_mul_ps(x1, b0), _mm256_mul_ps(y1, b1)); - - _mm256_storeu_ps( dst + x, x0); - _mm256_storeu_ps( dst + x + 8, x1); - } - - return x; -} -#endif - struct VResizeLinearVec_32f { int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const { -#if CV_AVX - if( checkHardwareSupport(CV_CPU_AVX) ) - return VResizeLinearVec_32f_avx(_src, _dst, _beta, width); -#endif - if( checkHardwareSupport(CV_CPU_SSE) ) - return VResizeLinearVec_32f_sse(_src, _dst, _beta, width); + int processed = 0; - return 0; + if( checkHardwareSupport(CV_CPU_AVX) ) + processed += VResizeLinearVec_32f_avx(_src, _dst, _beta, width); + + if( !processed && checkHardwareSupport(CV_CPU_SSE) ) + processed += VResizeLinearVec_32f_sse(_src, _dst, _beta, width); + + return processed; } }; - static int VResizeCubicVec_32s8u_sse2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) { const int** src = (const int**)_src; @@ -1026,115 +802,19 @@ static int VResizeCubicVec_32s8u_sse2(const uchar** _src, uchar* dst, const ucha return x; } -#if CV_AVX2 -int VResizeCubicVec_32s8u_avx2(const uchar** _src, uchar* dst, const uchar* _beta, int width ) -{ - const int** src = (const int**)_src; - const short* beta = (const short*)_beta; - const int *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; - int x = 0; - float scale = 1.f/(INTER_RESIZE_COEF_SCALE*INTER_RESIZE_COEF_SCALE); - __m256 b0 = _mm256_set1_ps(beta[0]*scale), b1 = _mm256_set1_ps(beta[1]*scale), - b2 = _mm256_set1_ps(beta[2]*scale), b3 = _mm256_set1_ps(beta[3]*scale); - const int shuffle = 0xd8; // 11 | 01 | 10 | 00 - - if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) - for( ; x <= width - 16; x += 16 ) - { - __m256i x0, x1, y0, y1; - __m256 s0, s1, f0, f1; - x0 = _mm256_load_si256((const __m256i*)(S0 + x)); - x1 = _mm256_load_si256((const __m256i*)(S0 + x + 8)); - y0 = _mm256_load_si256((const __m256i*)(S1 + x)); - y1 = _mm256_load_si256((const __m256i*)(S1 + x + 8)); - - s0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b0); - s1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b0); - f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b1); - f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b1); - s0 = _mm256_add_ps(s0, f0); - s1 = _mm256_add_ps(s1, f1); - - x0 = _mm256_load_si256((const __m256i*)(S2 + x)); - x1 = _mm256_load_si256((const __m256i*)(S2 + x + 8)); - y0 = _mm256_load_si256((const __m256i*)(S3 + x)); - y1 = _mm256_load_si256((const __m256i*)(S3 + x + 8)); - - f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b2); - f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b2); - s0 = _mm256_add_ps(s0, f0); - s1 = _mm256_add_ps(s1, f1); - f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b3); - f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b3); - s0 = _mm256_add_ps(s0, f0); - s1 = _mm256_add_ps(s1, f1); - - x0 = _mm256_cvtps_epi32(s0); - x1 = _mm256_cvtps_epi32(s1); - - x0 = _mm256_packs_epi32(x0, x1); - x0 = _mm256_permute4x64_epi64(x0, shuffle); - x0 = _mm256_packus_epi16(x0, x0); - _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(x0, 0)); - _mm_storel_epi64( (__m128i*)(dst + x + 8), _mm256_extracti128_si256(x0, 1)); - } - else - for( ; x <= width - 16; x += 16 ) - { - __m256i x0, x1, y0, y1; - __m256 s0, s1, f0, f1; - x0 = _mm256_loadu_si256((const __m256i*)(S0 + x)); - x1 = _mm256_loadu_si256((const __m256i*)(S0 + x + 8)); - y0 = _mm256_loadu_si256((const __m256i*)(S1 + x)); - y1 = _mm256_loadu_si256((const __m256i*)(S1 + x + 8)); - - s0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b0); - s1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b0); - f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b1); - f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b1); - s0 = _mm256_add_ps(s0, f0); - s1 = _mm256_add_ps(s1, f1); - - x0 = _mm256_loadu_si256((const __m256i*)(S2 + x)); - x1 = _mm256_loadu_si256((const __m256i*)(S2 + x + 8)); - y0 = _mm256_loadu_si256((const __m256i*)(S3 + x)); - y1 = _mm256_loadu_si256((const __m256i*)(S3 + x + 8)); - - f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(x0), b2); - f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(x1), b2); - s0 = _mm256_add_ps(s0, f0); - s1 = _mm256_add_ps(s1, f1); - f0 = _mm256_mul_ps(_mm256_cvtepi32_ps(y0), b3); - f1 = _mm256_mul_ps(_mm256_cvtepi32_ps(y1), b3); - s0 = _mm256_add_ps(s0, f0); - s1 = _mm256_add_ps(s1, f1); - - x0 = _mm256_cvtps_epi32(s0); - x1 = _mm256_cvtps_epi32(s1); - - x0 = _mm256_packs_epi32(x0, x1); - x0 = _mm256_permute4x64_epi64(x0, shuffle); - x0 = _mm256_packus_epi16(x0, x0); - _mm_storel_epi64( (__m128i*)(dst + x), _mm256_extracti128_si256(x0, 0)); - _mm_storel_epi64( (__m128i*)(dst + x + 8), _mm256_extracti128_si256(x0, 1)); - } - - return x; -} -#endif - struct VResizeCubicVec_32s8u { int operator()(const uchar** _src, uchar* dst, const uchar* _beta, int width ) const { -#if CV_AVX2 - if( checkHardwareSupport(CV_CPU_AVX2) ) - return VResizeCubicVec_32s8u_avx2(_src, dst, _beta, width); -#endif - if( checkHardwareSupport(CV_CPU_SSE2) ) - return VResizeCubicVec_32s8u_sse2(_src, dst, _beta, width); + int processed = 0; - return 0; + if( checkHardwareSupport(CV_CPU_AVX2) ) + processed += VResizeCubicVec_32s8u_avx2(_src, dst, _beta, width); + + if( !processed && checkHardwareSupport(CV_CPU_SSE2) ) + processed += VResizeCubicVec_32s8u_sse2(_src, dst, _beta, width); + + return processed; } }; @@ -1230,114 +910,19 @@ int VResizeCubicVec_32f16_sse2(const uchar** _src, uchar* _dst, const uchar* _be return x; } -#if CV_AVX2 -template -int VResizeCubicVec_32f16_avx2(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) -{ - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; - ushort* dst = (ushort*)_dst; - int x = 0; - __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]), - b2 = _mm256_set1_ps(beta[2]), b3 = _mm256_set1_ps(beta[3]); - __m256i preshift = _mm256_set1_epi32(shiftval); - __m256i postshift = _mm256_set1_epi16((short)shiftval); - const int shuffle = 0xd8; // 11 | 01 | 10 | 00 - - if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) - for( ; x <= width - 16; x += 16 ) - { - __m256 x0, x1, y0, y1, s0, s1; - __m256i t0, t1; - x0 = _mm256_load_ps(S0 + x); - x1 = _mm256_load_ps(S0 + x + 8); - y0 = _mm256_load_ps(S1 + x); - y1 = _mm256_load_ps(S1 + x + 8); - - s0 = _mm256_mul_ps(x0, b0); - s1 = _mm256_mul_ps(x1, b0); - y0 = _mm256_mul_ps(y0, b1); - y1 = _mm256_mul_ps(y1, b1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - x0 = _mm256_load_ps(S2 + x); - x1 = _mm256_load_ps(S2 + x + 8); - y0 = _mm256_load_ps(S3 + x); - y1 = _mm256_load_ps(S3 + x + 8); - - x0 = _mm256_mul_ps(x0, b2); - x1 = _mm256_mul_ps(x1, b2); - y0 = _mm256_mul_ps(y0, b3); - y1 = _mm256_mul_ps(y1, b3); - s0 = _mm256_add_ps(s0, x0); - s1 = _mm256_add_ps(s1, x1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - t0 = _mm256_add_epi32(_mm256_cvtps_epi32(s0), preshift); - t1 = _mm256_add_epi32(_mm256_cvtps_epi32(s1), preshift); - - t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t1), postshift); - t0 = _mm256_permute4x64_epi64(t0, shuffle); - _mm256_storeu_si256( (__m256i*)(dst + x), t0); - } - else - for( ; x <= width - 16; x += 16 ) - { - __m256 x0, x1, y0, y1, s0, s1; - __m256i t0, t1; - x0 = _mm256_loadu_ps(S0 + x); - x1 = _mm256_loadu_ps(S0 + x + 8); - y0 = _mm256_loadu_ps(S1 + x); - y1 = _mm256_loadu_ps(S1 + x + 8); - - s0 = _mm256_mul_ps(x0, b0); - s1 = _mm256_mul_ps(x1, b0); - y0 = _mm256_mul_ps(y0, b1); - y1 = _mm256_mul_ps(y1, b1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - x0 = _mm256_loadu_ps(S2 + x); - x1 = _mm256_loadu_ps(S2 + x + 8); - y0 = _mm256_loadu_ps(S3 + x); - y1 = _mm256_loadu_ps(S3 + x + 8); - - x0 = _mm256_mul_ps(x0, b2); - x1 = _mm256_mul_ps(x1, b2); - y0 = _mm256_mul_ps(y0, b3); - y1 = _mm256_mul_ps(y1, b3); - s0 = _mm256_add_ps(s0, x0); - s1 = _mm256_add_ps(s1, x1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - t0 = _mm256_add_epi32(_mm256_cvtps_epi32(s0), preshift); - t1 = _mm256_add_epi32(_mm256_cvtps_epi32(s1), preshift); - - t0 = _mm256_add_epi16(_mm256_packs_epi32(t0, t1), postshift); - t0 = _mm256_permute4x64_epi64(t0, shuffle); - _mm256_storeu_si256( (__m256i*)(dst + x), t0); - } - - return x; -} -#endif - template struct VResizeCubicVec_32f16 { int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const { -#if CV_AVX2 - if( checkHardwareSupport(CV_CPU_AVX2) ) - return VResizeCubicVec_32f16_avx2(_src, _dst, _beta, width); -#endif - if( checkHardwareSupport(CV_CPU_SSE2) ) - return VResizeCubicVec_32f16_sse2(_src, _dst, _beta, width); + int processed = 0; - return 0; + if( checkHardwareSupport(CV_CPU_AVX2) ) + processed += VResizeCubicVec_32f16_avx2(_src, _dst, _beta, width); + + if( !processed && checkHardwareSupport(CV_CPU_SSE2) ) + processed += VResizeCubicVec_32f16_sse2(_src, _dst, _beta, width); + + return processed; } }; @@ -1424,100 +1009,19 @@ static int VResizeCubicVec_32f_sse(const uchar** _src, uchar* _dst, const uchar* return x; } -#if CV_AVX -int VResizeCubicVec_32f_avx(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) -{ - const float** src = (const float**)_src; - const float* beta = (const float*)_beta; - const float *S0 = src[0], *S1 = src[1], *S2 = src[2], *S3 = src[3]; - float* dst = (float*)_dst; - int x = 0; - __m256 b0 = _mm256_set1_ps(beta[0]), b1 = _mm256_set1_ps(beta[1]), - b2 = _mm256_set1_ps(beta[2]), b3 = _mm256_set1_ps(beta[3]); - - if( (((size_t)S0|(size_t)S1|(size_t)S2|(size_t)S3)&31) == 0 ) - for( ; x <= width - 16; x += 16 ) - { - __m256 x0, x1, y0, y1, s0, s1; - x0 = _mm256_load_ps(S0 + x); - x1 = _mm256_load_ps(S0 + x + 8); - y0 = _mm256_load_ps(S1 + x); - y1 = _mm256_load_ps(S1 + x + 8); - - s0 = _mm256_mul_ps(x0, b0); - s1 = _mm256_mul_ps(x1, b0); - y0 = _mm256_mul_ps(y0, b1); - y1 = _mm256_mul_ps(y1, b1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - x0 = _mm256_load_ps(S2 + x); - x1 = _mm256_load_ps(S2 + x + 8); - y0 = _mm256_load_ps(S3 + x); - y1 = _mm256_load_ps(S3 + x + 8); - - x0 = _mm256_mul_ps(x0, b2); - x1 = _mm256_mul_ps(x1, b2); - y0 = _mm256_mul_ps(y0, b3); - y1 = _mm256_mul_ps(y1, b3); - s0 = _mm256_add_ps(s0, x0); - s1 = _mm256_add_ps(s1, x1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - _mm256_storeu_ps( dst + x, s0); - _mm256_storeu_ps( dst + x + 8, s1); - } - else - for( ; x <= width - 16; x += 16 ) - { - __m256 x0, x1, y0, y1, s0, s1; - x0 = _mm256_loadu_ps(S0 + x); - x1 = _mm256_loadu_ps(S0 + x + 8); - y0 = _mm256_loadu_ps(S1 + x); - y1 = _mm256_loadu_ps(S1 + x + 8); - - s0 = _mm256_mul_ps(x0, b0); - s1 = _mm256_mul_ps(x1, b0); - y0 = _mm256_mul_ps(y0, b1); - y1 = _mm256_mul_ps(y1, b1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - x0 = _mm256_loadu_ps(S2 + x); - x1 = _mm256_loadu_ps(S2 + x + 8); - y0 = _mm256_loadu_ps(S3 + x); - y1 = _mm256_loadu_ps(S3 + x + 8); - - x0 = _mm256_mul_ps(x0, b2); - x1 = _mm256_mul_ps(x1, b2); - y0 = _mm256_mul_ps(y0, b3); - y1 = _mm256_mul_ps(y1, b3); - s0 = _mm256_add_ps(s0, x0); - s1 = _mm256_add_ps(s1, x1); - s0 = _mm256_add_ps(s0, y0); - s1 = _mm256_add_ps(s1, y1); - - _mm256_storeu_ps( dst + x, s0); - _mm256_storeu_ps( dst + x + 8, s1); - } - - return x; -} -#endif - struct VResizeCubicVec_32f { int operator()(const uchar** _src, uchar* _dst, const uchar* _beta, int width ) const { -#if CV_AVX - if( checkHardwareSupport(CV_CPU_AVX) ) - return VResizeCubicVec_32f_avx(_src, _dst, _beta, width); -#endif - if( checkHardwareSupport(CV_CPU_SSE) ) - return VResizeCubicVec_32f_sse(_src, _dst, _beta, width); + int processed = 0; - return 0; + if( checkHardwareSupport(CV_CPU_AVX) ) + processed += VResizeCubicVec_32f_avx(_src, _dst, _beta, width); + + if( !processed && checkHardwareSupport(CV_CPU_SSE) ) + processed += VResizeCubicVec_32f_sse(_src, _dst, _beta, width); + + return processed; } }; diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 39907edac4..428a5f8128 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -3002,12 +3002,8 @@ void printVersionInfo(bool useStdOut) #if CV_SSE4_2 if (checkHardwareSupport(CV_CPU_SSE4_2)) cpu_features += " sse4.2"; #endif -#if CV_AVX if (checkHardwareSupport(CV_CPU_AVX)) cpu_features += " avx"; -#endif -#if CV_AVX2 if (checkHardwareSupport(CV_CPU_AVX2)) cpu_features += " avx2"; -#endif #if CV_NEON cpu_features += " neon"; // NEON is currently not checked at runtime #endif From 6e022dcb069c5f31f5bf64a3551f84724d32f7f0 Mon Sep 17 00:00:00 2001 From: Raaj Date: Thu, 10 Jul 2014 17:44:40 -0700 Subject: [PATCH 090/662] Update facedetect.cpp Somebody forgot to add curly brackets --- samples/ocl/facedetect.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/ocl/facedetect.cpp b/samples/ocl/facedetect.cpp index 378105906e..df9eff47cc 100644 --- a/samples/ocl/facedetect.cpp +++ b/samples/ocl/facedetect.cpp @@ -93,9 +93,10 @@ static int facedetect_one_thread(bool useCPU, double scale ) if( image.empty() ) { capture = cvCaptureFromAVI( inputName.c_str() ); - if(!capture) + if(!capture){ cout << "Capture from AVI didn't work" << endl; - return EXIT_FAILURE; + return EXIT_FAILURE; + } } } From 13a0c14e6c3541e117bf6ff0531293201b5df1d0 Mon Sep 17 00:00:00 2001 From: PhilLab Date: Fri, 11 Jul 2014 09:22:55 +0200 Subject: [PATCH 091/662] Added publication reference --- modules/contrib/doc/stereo.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/contrib/doc/stereo.rst b/modules/contrib/doc/stereo.rst index 103bd0f3fd..9ee0d81632 100644 --- a/modules/contrib/doc/stereo.rst +++ b/modules/contrib/doc/stereo.rst @@ -38,7 +38,7 @@ Class for computing stereo correspondence using the variational matching algorit ... }; -The class implements the modified S. G. Kosov algorithm [Publication] that differs from the original one as follows: +The class implements the modified S. G. Kosov algorithm [KTS09]_ that differs from the original one as follows: * The automatic initialization of method's parameters is added. @@ -48,6 +48,9 @@ The class implements the modified S. G. Kosov algorithm [Publication] that diffe * The method of dynamic adaptation of method's parameters is not included. +.. [KTS09] Sergey Kosov, Thorsten Thormählen and Hans-Peter Seidel: Accurate real-time disparity estimation with variational methods. In: Advances in Visual Computing. Springer Berlin Heidelberg, 2009. 796-807. + + StereoVar::StereoVar -------------------------- From 03fe86f0a3df2d9771b27ba5dadd8a94aa278f77 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Thu, 10 Jul 2014 13:28:32 +0200 Subject: [PATCH 092/662] added extra warning about the automatic parameter loading for traincascade application when the param.xml file already exists --- apps/traincascade/cascadeclassifier.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/traincascade/cascadeclassifier.cpp b/apps/traincascade/cascadeclassifier.cpp index 7c18348ae5..b1bd4fa004 100644 --- a/apps/traincascade/cascadeclassifier.cpp +++ b/apps/traincascade/cascadeclassifier.cpp @@ -506,6 +506,8 @@ void CvCascadeClassifier::save( const string filename, bool baseFormat ) bool CvCascadeClassifier::load( const string cascadeDirName ) { + cout << "Training parameters are loaded from the parameter file in data folder!" << endl; + cout << "Please empty the data folder if you want to use your own set of parameters." << endl; FileStorage fs( cascadeDirName + CC_PARAMS_FILENAME, FileStorage::READ ); if ( !fs.isOpened() ) return false; From 79878a57a90ebe25b68e7c40b377e4e548d7c6cd Mon Sep 17 00:00:00 2001 From: Leonid Beynenson Date: Fri, 11 Jul 2014 15:47:41 +0400 Subject: [PATCH 093/662] Fixed bug in cv::detail::waveCorrect The function makes wave correction of a stitched panorama. Earlier it gave wrong results for panorama made from 1 frame. --- modules/stitching/src/motion_estimators.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stitching/src/motion_estimators.cpp b/modules/stitching/src/motion_estimators.cpp index 98f4ec2e2d..2ba691b7d7 100644 --- a/modules/stitching/src/motion_estimators.cpp +++ b/modules/stitching/src/motion_estimators.cpp @@ -589,6 +589,11 @@ void waveCorrect(vector &rmats, WaveCorrectKind kind) #if ENABLE_LOG int64 t = getTickCount(); #endif + if (rmats.size() <= 1) + { + LOGLN("Wave correcting, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec"); + return; + } Mat moment = Mat::zeros(3, 3, CV_32F); for (size_t i = 0; i < rmats.size(); ++i) From cce2d9927e2bf900ebdb5f4e3dbc2894d58f5f4e Mon Sep 17 00:00:00 2001 From: Leonid Beynenson Date: Fri, 11 Jul 2014 16:37:30 +0400 Subject: [PATCH 094/662] Fixed bug which caused crash of GPU version of feature matcher in stitcher The bug caused crash of GPU version of feature matcher in stitcher when we use ORB features. --- modules/stitching/src/matchers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index ac29d7ca2b..a0cb13203d 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -212,7 +212,7 @@ void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat descriptors1_.upload(features1.descriptors); descriptors2_.upload(features2.descriptors); - BFMatcher_GPU matcher(NORM_L2); + BFMatcher_GPU matcher(NORM_L1); MatchesSet matches; // Find 1->2 matches From 64d8cf1e2e09bb0a51bcccaffce5bb7723791404 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Sat, 12 Jul 2014 19:28:43 +0400 Subject: [PATCH 095/662] improving face-rec sample: * CSV can contain dir-s and wildcards * save trained model --- samples/cpp/facerec_demo.cpp | 135 +++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 60 deletions(-) diff --git a/samples/cpp/facerec_demo.cpp b/samples/cpp/facerec_demo.cpp index b92308e898..f3837d4d3f 100644 --- a/samples/cpp/facerec_demo.cpp +++ b/samples/cpp/facerec_demo.cpp @@ -27,35 +27,38 @@ using namespace cv; using namespace std; -static Mat toGrayscale(InputArray _src) { - Mat src = _src.getMat(); - // only allow one channel - if(src.channels() != 1) { - CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported"); - } - // create and return normalized image - Mat dst; - cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1); - return dst; -} - static void read_csv(const string& filename, vector& images, vector& labels, std::map& labelsInfo, char separator = ';') { - std::ifstream file(filename.c_str(), ifstream::in); - if (!file) { - string error_message = "No valid input file was given, please check the given filename."; - CV_Error(CV_StsBadArg, error_message); - } + ifstream csv(filename.c_str()); + if (!csv) CV_Error(CV_StsBadArg, "No valid input file was given, please check the given filename."); string line, path, classlabel, info; - while (getline(file, line)) { + while (getline(csv, line)) { stringstream liness(line); + path.clear(); classlabel.clear(); info.clear(); getline(liness, path, separator); getline(liness, classlabel, separator); getline(liness, info, separator); if(!path.empty() && !classlabel.empty()) { - images.push_back(imread(path, 0)); - labels.push_back(atoi(classlabel.c_str())); + cout << "Processing " << path << endl; + int label = atoi(classlabel.c_str()); if(!info.empty()) - labelsInfo.insert(std::make_pair(labels.back(), info)); + labelsInfo.insert(std::make_pair(label, info)); + // 'path' can be file, dir or wildcard path + String root(path.c_str()); + vector files; + glob(root, files, true); + for(vector::const_iterator f = files.begin(); f != files.end(); ++f) { + cout << "\t" << *f << endl; + Mat img = imread(*f, CV_LOAD_IMAGE_GRAYSCALE); + static int w=-1, h=-1; + static bool showSmallSizeWarning = true; + if(w>0 && h>0 && (w!=img.cols || h!=img.rows)) cout << "\t* Warning: images should be of the same size!" << endl; + if(showSmallSizeWarning && (img.cols<50 || img.rows<50)) { + cout << "* Warning: for better results images should be not smaller than 50x50!" << endl; + showSmallSizeWarning = false; + } + images.push_back(img); + labels.push_back(label); + } } } } @@ -63,8 +66,17 @@ static void read_csv(const string& filename, vector& images, vector& l int main(int argc, const char *argv[]) { // Check for valid command line arguments, print usage // if no arguments were given. - if (argc != 2) { - cout << "usage: " << argv[0] << " " << endl; + if (argc != 2 && argc != 3) { + cout << "Usage: " << argv[0] << " [arg2]\n" + << "\t - path to config file in CSV format\n" + << "\targ2 - if the 2nd argument is provided (with any value) " + << "the advanced stuff is run and shown to console.\n" + << "The CSV config file consists of the following lines:\n" + << ";