mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge remote-tracking branch 'origin/master' into merge-2.4
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
namespace cvtest
|
||||
{
|
||||
|
||||
@@ -2981,7 +2981,7 @@ The class provides the following features for all derived classes:
|
||||
|
||||
* so called "virtual constructor". That is, each Algorithm derivative is registered at program start and you can get the list of registered algorithms and create instance of a particular algorithm by its name (see ``Algorithm::create``). If you plan to add your own algorithms, it is good practice to add a unique prefix to your algorithms to distinguish them from other algorithms.
|
||||
|
||||
* setting/retrieving algorithm parameters by name. If you used video capturing functionality from OpenCV highgui module, you are probably familar with ``cvSetCaptureProperty()``, ``cvGetCaptureProperty()``, ``VideoCapture::set()`` and ``VideoCapture::get()``. ``Algorithm`` provides similar method where instead of integer id's you specify the parameter names as text strings. See ``Algorithm::set`` and ``Algorithm::get`` for details.
|
||||
* setting/retrieving algorithm parameters by name. If you used video capturing functionality from OpenCV videoio module, you are probably familar with ``cvSetCaptureProperty()``, ``cvGetCaptureProperty()``, ``VideoCapture::set()`` and ``VideoCapture::get()``. ``Algorithm`` provides similar method where instead of integer id's you specify the parameter names as text strings. See ``Algorithm::set`` and ``Algorithm::get`` for details.
|
||||
|
||||
* reading and writing parameters from/to XML or YAML files. Every Algorithm derivative can store all its parameters and then read them back. There is no need to re-implement it each time.
|
||||
|
||||
|
||||
@@ -361,6 +361,37 @@ The function ``line`` draws the line segment between ``pt1`` and ``pt2`` points
|
||||
Antialiased lines are drawn using Gaussian filtering.
|
||||
|
||||
|
||||
arrowedLine
|
||||
----------------
|
||||
Draws a arrow segment pointing from the first point to the second one.
|
||||
|
||||
.. ocv:function:: void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0, double tipLength=0.1)
|
||||
|
||||
:param img: Image.
|
||||
|
||||
:param pt1: The point the arrow starts from.
|
||||
|
||||
:param pt2: The point the arrow points to.
|
||||
|
||||
:param color: Line color.
|
||||
|
||||
:param thickness: Line thickness.
|
||||
|
||||
:param lineType: Type of the line:
|
||||
|
||||
* **8** (or omitted) - 8-connected line.
|
||||
|
||||
* **4** - 4-connected line.
|
||||
|
||||
* **CV_AA** - antialiased line.
|
||||
|
||||
:param shift: Number of fractional bits in the point coordinates.
|
||||
|
||||
:param tipLength: The length of the arrow tip in relation to the arrow length
|
||||
|
||||
The function ``arrowedLine`` draws an arrow between ``pt1`` and ``pt2`` points in the image. See also :ocv:func:`line`.
|
||||
|
||||
|
||||
LineIterator
|
||||
------------
|
||||
.. ocv:class:: LineIterator
|
||||
|
||||
@@ -14,7 +14,8 @@ OpenCV has a modular structure, which means that the package includes several sh
|
||||
* **calib3d** - basic multiple-view geometry algorithms, single and stereo camera calibration, object pose estimation, stereo correspondence algorithms, and elements of 3D reconstruction.
|
||||
* **features2d** - salient feature detectors, descriptors, and descriptor matchers.
|
||||
* **objdetect** - detection of objects and instances of the predefined classes (for example, faces, eyes, mugs, people, cars, and so on).
|
||||
* **highgui** - an easy-to-use interface to video capturing, image and video codecs, as well as simple UI capabilities.
|
||||
* **highgui** - an easy-to-use interface to simple UI capabilities.
|
||||
* **videoio** - an easy-to-use interface to video capturing and video codecs.
|
||||
* **gpu** - GPU-accelerated algorithms from different OpenCV modules.
|
||||
* ... some other helper modules, such as FLANN and Google test wrappers, Python bindings, and others.
|
||||
|
||||
|
||||
@@ -510,6 +510,10 @@ CV_EXPORTS_W void randShuffle(InputOutputArray dst, double iterFactor = 1., RNG*
|
||||
CV_EXPORTS_W void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
|
||||
int thickness = 1, int lineType = LINE_8, int shift = 0);
|
||||
|
||||
//! draws an arrow from pt1 to pt2 in the image
|
||||
CV_EXPORTS_W void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
|
||||
int thickness=1, int line_type=8, int shift=0, double tipLength=0.1);
|
||||
|
||||
//! draws the rectangle outline or a solid rectangle with the opposite corners pt1 and pt2 in the image
|
||||
CV_EXPORTS_W void rectangle(InputOutputArray img, Point pt1, Point pt2,
|
||||
const Scalar& color, int thickness = 1,
|
||||
|
||||
@@ -244,6 +244,7 @@ typedef signed char schar;
|
||||
|
||||
/* fundamental constants */
|
||||
#define CV_PI 3.1415926535897932384626433832795
|
||||
#define CV_2PI 6.283185307179586476925286766559
|
||||
#define CV_LOG2 0.69314718055994530941723212145818
|
||||
|
||||
/****************************************************************************************\
|
||||
|
||||
@@ -360,7 +360,7 @@ struct CV_EXPORTS UMatData
|
||||
{
|
||||
enum { COPY_ON_MAP=1, HOST_COPY_OBSOLETE=2,
|
||||
DEVICE_COPY_OBSOLETE=4, TEMP_UMAT=8, TEMP_COPIED_UMAT=24,
|
||||
USER_ALLOCATED=32 };
|
||||
USER_ALLOCATED=32, DEVICE_MEM_MAPPED=64};
|
||||
UMatData(const MatAllocator* allocator);
|
||||
~UMatData();
|
||||
|
||||
@@ -370,11 +370,13 @@ struct CV_EXPORTS UMatData
|
||||
|
||||
bool hostCopyObsolete() const;
|
||||
bool deviceCopyObsolete() const;
|
||||
bool deviceMemMapped() const;
|
||||
bool copyOnMap() const;
|
||||
bool tempUMat() const;
|
||||
bool tempCopiedUMat() const;
|
||||
void markHostCopyObsolete(bool flag);
|
||||
void markDeviceCopyObsolete(bool flag);
|
||||
void markDeviceMemMapped(bool flag);
|
||||
|
||||
const MatAllocator* prevAllocator;
|
||||
const MatAllocator* currAllocator;
|
||||
|
||||
@@ -3351,10 +3351,19 @@ size_t UMat::total() const
|
||||
|
||||
inline bool UMatData::hostCopyObsolete() const { return (flags & HOST_COPY_OBSOLETE) != 0; }
|
||||
inline bool UMatData::deviceCopyObsolete() const { return (flags & DEVICE_COPY_OBSOLETE) != 0; }
|
||||
inline bool UMatData::deviceMemMapped() const { return (flags & DEVICE_MEM_MAPPED) != 0; }
|
||||
inline bool UMatData::copyOnMap() const { return (flags & COPY_ON_MAP) != 0; }
|
||||
inline bool UMatData::tempUMat() const { return (flags & TEMP_UMAT) != 0; }
|
||||
inline bool UMatData::tempCopiedUMat() const { return (flags & TEMP_COPIED_UMAT) == TEMP_COPIED_UMAT; }
|
||||
|
||||
inline void UMatData::markDeviceMemMapped(bool flag)
|
||||
{
|
||||
if(flag)
|
||||
flags |= DEVICE_MEM_MAPPED;
|
||||
else
|
||||
flags &= ~DEVICE_MEM_MAPPED;
|
||||
}
|
||||
|
||||
inline void UMatData::markHostCopyObsolete(bool flag)
|
||||
{
|
||||
if(flag)
|
||||
|
||||
@@ -54,23 +54,42 @@ namespace ocl {
|
||||
|
||||
///////////// dft ////////////////////////
|
||||
|
||||
typedef tuple<Size, int> DftParams;
|
||||
enum OCL_FFT_TYPE
|
||||
{
|
||||
R2R = 0,
|
||||
C2R = 1,
|
||||
R2C = 2,
|
||||
C2C = 3
|
||||
};
|
||||
|
||||
typedef tuple<OCL_FFT_TYPE, Size, int> DftParams;
|
||||
typedef TestBaseWithParam<DftParams> DftFixture;
|
||||
|
||||
OCL_PERF_TEST_P(DftFixture, Dft, ::testing::Combine(Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3),
|
||||
Values((int)DFT_ROWS, (int)DFT_SCALE, (int)DFT_INVERSE,
|
||||
(int)DFT_INVERSE | DFT_SCALE, (int)DFT_ROWS | DFT_INVERSE)))
|
||||
OCL_PERF_TEST_P(DftFixture, Dft, ::testing::Combine(Values(C2C, R2R, C2R, R2C),
|
||||
Values(OCL_SIZE_1, OCL_SIZE_2, OCL_SIZE_3, Size(512, 512), Size(1024, 1024), Size(2048, 2048)),
|
||||
Values((int) 0, (int)DFT_ROWS, (int)DFT_SCALE, (int)DFT_INVERSE,
|
||||
(int)DFT_INVERSE | DFT_SCALE, (int)DFT_ROWS | DFT_INVERSE)))
|
||||
{
|
||||
const DftParams params = GetParam();
|
||||
const Size srcSize = get<0>(params);
|
||||
const int flags = get<1>(params);
|
||||
const int dft_type = get<0>(params);
|
||||
const Size srcSize = get<1>(params);
|
||||
int flags = get<2>(params);
|
||||
|
||||
UMat src(srcSize, CV_32FC2), dst(srcSize, CV_32FC2);
|
||||
int in_cn, out_cn;
|
||||
switch (dft_type)
|
||||
{
|
||||
case R2R: flags |= cv::DFT_REAL_OUTPUT; in_cn = 1; out_cn = 1; break;
|
||||
case C2R: flags |= cv::DFT_REAL_OUTPUT; in_cn = 2; out_cn = 2; break;
|
||||
case R2C: flags |= cv::DFT_COMPLEX_OUTPUT; in_cn = 1; out_cn = 2; break;
|
||||
case C2C: flags |= cv::DFT_COMPLEX_OUTPUT; in_cn = 2; out_cn = 2; break;
|
||||
}
|
||||
|
||||
UMat src(srcSize, CV_MAKE_TYPE(CV_32F, in_cn)), dst(srcSize, CV_MAKE_TYPE(CV_32F, out_cn));
|
||||
declare.in(src, WARMUP_RNG).out(dst);
|
||||
|
||||
OCL_TEST_CYCLE() cv::dft(src, dst, flags | DFT_COMPLEX_OUTPUT);
|
||||
OCL_TEST_CYCLE() cv::dft(src, dst, flags);
|
||||
|
||||
SANITY_CHECK(dst, 1e-3);
|
||||
SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE);
|
||||
}
|
||||
|
||||
///////////// MulSpectrums ////////////////////////
|
||||
|
||||
@@ -139,6 +139,7 @@ OCL_PERF_TEST_P(CopyToFixture, CopyToWithMaskUninit,
|
||||
dst.release();
|
||||
startTimer();
|
||||
src.copyTo(dst, mask);
|
||||
cv::ocl::finish();
|
||||
stopTimer();
|
||||
}
|
||||
|
||||
|
||||
+292
-7
@@ -54,21 +54,23 @@ namespace cv
|
||||
|
||||
struct NOP {};
|
||||
|
||||
#if CV_SSE2
|
||||
#if CV_SSE2 || CV_NEON
|
||||
|
||||
#define FUNCTOR_TEMPLATE(name) \
|
||||
template<typename T> struct name {}
|
||||
|
||||
FUNCTOR_TEMPLATE(VLoadStore128);
|
||||
#if CV_SSE2
|
||||
FUNCTOR_TEMPLATE(VLoadStore64);
|
||||
FUNCTOR_TEMPLATE(VLoadStore128Aligned);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
template<typename T, class Op, class VOp>
|
||||
void vBinOp(const T* src1, size_t step1, const T* src2, size_t step2, T* dst, size_t step, Size sz)
|
||||
{
|
||||
#if CV_SSE2
|
||||
#if CV_SSE2 || CV_NEON
|
||||
VOp vop;
|
||||
#endif
|
||||
Op op;
|
||||
@@ -79,9 +81,11 @@ void vBinOp(const T* src1, size_t step1, const T* src2, size_t step2, T* dst, si
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
#if CV_NEON || CV_SSE2
|
||||
#if CV_SSE2
|
||||
if( USE_SSE2 )
|
||||
{
|
||||
#endif
|
||||
for( ; x <= sz.width - 32/(int)sizeof(T); x += 32/sizeof(T) )
|
||||
{
|
||||
typename VLoadStore128<T>::reg_type r0 = VLoadStore128<T>::load(src1 + x );
|
||||
@@ -91,8 +95,10 @@ void vBinOp(const T* src1, size_t step1, const T* src2, size_t step2, T* dst, si
|
||||
VLoadStore128<T>::store(dst + x , r0);
|
||||
VLoadStore128<T>::store(dst + x + 16/sizeof(T), r1);
|
||||
}
|
||||
#if CV_SSE2
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if CV_SSE2
|
||||
if( USE_SSE2 )
|
||||
{
|
||||
@@ -125,7 +131,7 @@ template<typename T, class Op, class Op32>
|
||||
void vBinOp32(const T* src1, size_t step1, const T* src2, size_t step2,
|
||||
T* dst, size_t step, Size sz)
|
||||
{
|
||||
#if CV_SSE2
|
||||
#if CV_SSE2 || CV_NEON
|
||||
Op32 op32;
|
||||
#endif
|
||||
Op op;
|
||||
@@ -153,9 +159,11 @@ void vBinOp32(const T* src1, size_t step1, const T* src2, size_t step2,
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if CV_NEON || CV_SSE2
|
||||
#if CV_SSE2
|
||||
if( USE_SSE2 )
|
||||
{
|
||||
#endif
|
||||
for( ; x <= sz.width - 8; x += 8 )
|
||||
{
|
||||
typename VLoadStore128<T>::reg_type r0 = VLoadStore128<T>::load(src1 + x );
|
||||
@@ -165,8 +173,10 @@ void vBinOp32(const T* src1, size_t step1, const T* src2, size_t step2,
|
||||
VLoadStore128<T>::store(dst + x , r0);
|
||||
VLoadStore128<T>::store(dst + x + 4, r1);
|
||||
}
|
||||
#if CV_SSE2
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; x <= sz.width - 4; x += 4 )
|
||||
{
|
||||
@@ -383,7 +393,98 @@ FUNCTOR_TEMPLATE(VNot);
|
||||
FUNCTOR_CLOSURE_1arg(VNot, uchar, return _mm_xor_si128(_mm_set1_epi32(-1), a));
|
||||
#endif
|
||||
|
||||
#if CV_SSE2
|
||||
#if CV_NEON
|
||||
|
||||
#define FUNCTOR_LOADSTORE(name, template_arg, register_type, load_body, store_body)\
|
||||
template <> \
|
||||
struct name<template_arg>{ \
|
||||
typedef register_type reg_type; \
|
||||
static reg_type load(const template_arg * p) { return load_body (p);}; \
|
||||
static void store(template_arg * p, reg_type v) { store_body (p, v);}; \
|
||||
}
|
||||
|
||||
#define FUNCTOR_CLOSURE_2arg(name, template_arg, body)\
|
||||
template<> \
|
||||
struct name<template_arg> \
|
||||
{ \
|
||||
VLoadStore128<template_arg>::reg_type operator()( \
|
||||
VLoadStore128<template_arg>::reg_type a, \
|
||||
VLoadStore128<template_arg>::reg_type b) const \
|
||||
{ \
|
||||
return body; \
|
||||
}; \
|
||||
}
|
||||
|
||||
#define FUNCTOR_CLOSURE_1arg(name, template_arg, body)\
|
||||
template<> \
|
||||
struct name<template_arg> \
|
||||
{ \
|
||||
VLoadStore128<template_arg>::reg_type operator()( \
|
||||
VLoadStore128<template_arg>::reg_type a, \
|
||||
VLoadStore128<template_arg>::reg_type ) const \
|
||||
{ \
|
||||
return body; \
|
||||
}; \
|
||||
}
|
||||
|
||||
FUNCTOR_LOADSTORE(VLoadStore128, uchar, uint8x16_t, vld1q_u8 , vst1q_u8 );
|
||||
FUNCTOR_LOADSTORE(VLoadStore128, schar, int8x16_t, vld1q_s8 , vst1q_s8 );
|
||||
FUNCTOR_LOADSTORE(VLoadStore128, ushort, uint16x8_t, vld1q_u16, vst1q_u16);
|
||||
FUNCTOR_LOADSTORE(VLoadStore128, short, int16x8_t, vld1q_s16, vst1q_s16);
|
||||
FUNCTOR_LOADSTORE(VLoadStore128, int, int32x4_t, vld1q_s32, vst1q_s32);
|
||||
FUNCTOR_LOADSTORE(VLoadStore128, float, float32x4_t, vld1q_f32, vst1q_f32);
|
||||
|
||||
FUNCTOR_TEMPLATE(VAdd);
|
||||
FUNCTOR_CLOSURE_2arg(VAdd, uchar, vqaddq_u8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAdd, schar, vqaddq_s8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAdd, ushort, vqaddq_u16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAdd, short, vqaddq_s16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAdd, int, vaddq_s32 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAdd, float, vaddq_f32 (a, b));
|
||||
|
||||
FUNCTOR_TEMPLATE(VSub);
|
||||
FUNCTOR_CLOSURE_2arg(VSub, uchar, vqsubq_u8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VSub, schar, vqsubq_s8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VSub, ushort, vqsubq_u16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VSub, short, vqsubq_s16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VSub, int, vsubq_s32 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VSub, float, vsubq_f32 (a, b));
|
||||
|
||||
FUNCTOR_TEMPLATE(VMin);
|
||||
FUNCTOR_CLOSURE_2arg(VMin, uchar, vminq_u8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMin, schar, vminq_s8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMin, ushort, vminq_u16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMin, short, vminq_s16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMin, int, vminq_s32(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMin, float, vminq_f32(a, b));
|
||||
|
||||
FUNCTOR_TEMPLATE(VMax);
|
||||
FUNCTOR_CLOSURE_2arg(VMax, uchar, vmaxq_u8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMax, schar, vmaxq_s8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMax, ushort, vmaxq_u16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMax, short, vmaxq_s16(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMax, int, vmaxq_s32(a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VMax, float, vmaxq_f32(a, b));
|
||||
|
||||
FUNCTOR_TEMPLATE(VAbsDiff);
|
||||
FUNCTOR_CLOSURE_2arg(VAbsDiff, uchar, vabdq_u8 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAbsDiff, schar, vqabsq_s8 (vqsubq_s8(a, b)));
|
||||
FUNCTOR_CLOSURE_2arg(VAbsDiff, ushort, vabdq_u16 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAbsDiff, short, vqabsq_s16(vqsubq_s16(a, b)));
|
||||
FUNCTOR_CLOSURE_2arg(VAbsDiff, int, vabdq_s32 (a, b));
|
||||
FUNCTOR_CLOSURE_2arg(VAbsDiff, float, vabdq_f32 (a, b));
|
||||
|
||||
FUNCTOR_TEMPLATE(VAnd);
|
||||
FUNCTOR_CLOSURE_2arg(VAnd, uchar, vandq_u8(a, b));
|
||||
FUNCTOR_TEMPLATE(VOr);
|
||||
FUNCTOR_CLOSURE_2arg(VOr , uchar, vorrq_u8(a, b));
|
||||
FUNCTOR_TEMPLATE(VXor);
|
||||
FUNCTOR_CLOSURE_2arg(VXor, uchar, veorq_u8(a, b));
|
||||
FUNCTOR_TEMPLATE(VNot);
|
||||
FUNCTOR_CLOSURE_1arg(VNot, uchar, vmvnq_u8(a ));
|
||||
#endif
|
||||
|
||||
#if CV_SSE2 || CV_NEON
|
||||
#define IF_SIMD(op) op
|
||||
#else
|
||||
#define IF_SIMD(op) NOP
|
||||
@@ -1390,6 +1491,9 @@ static bool ocl_arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst,
|
||||
if (!doubleSupport && (depth2 == CV_64F || depth1 == CV_64F))
|
||||
return false;
|
||||
|
||||
if( (oclop == OCL_OP_MUL_SCALE || oclop == OCL_OP_DIV_SCALE) && (depth1 >= CV_32F || depth2 >= CV_32F || ddepth >= CV_32F) )
|
||||
return false;
|
||||
|
||||
int kercn = haveMask || haveScalar ? cn : ocl::predictOptimalVectorWidth(_src1, _src2, _dst);
|
||||
int scalarcn = kercn == 3 ? 4 : kercn, rowsPerWI = d.isIntel() ? 4 : 1;
|
||||
|
||||
@@ -2980,8 +3084,187 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
|
||||
namespace cv
|
||||
{
|
||||
|
||||
template<typename T> static void
|
||||
inRange_(const T* src1, size_t step1, const T* src2, size_t step2,
|
||||
template <typename T>
|
||||
struct InRange_SSE
|
||||
{
|
||||
int operator () (const T *, const T *, const T *, uchar *, int) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#if CV_SSE2
|
||||
|
||||
template <>
|
||||
struct InRange_SSE<uchar>
|
||||
{
|
||||
int operator () (const uchar * src1, const uchar * src2, const uchar * src3,
|
||||
uchar * dst, int len) const
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (USE_SSE2)
|
||||
{
|
||||
__m128i v_full = _mm_set1_epi8(-1), v_128 = _mm_set1_epi8(-128);
|
||||
|
||||
for ( ; x <= len - 16; x += 16 )
|
||||
{
|
||||
__m128i v_src = _mm_add_epi8(_mm_loadu_si128((const __m128i *)(src1 + x)), v_128);
|
||||
__m128i v_mask1 = _mm_cmpgt_epi8(_mm_add_epi8(_mm_loadu_si128((const __m128i *)(src2 + x)), v_128), v_src);
|
||||
__m128i v_mask2 = _mm_cmpgt_epi8(v_src, _mm_add_epi8(_mm_loadu_si128((const __m128i *)(src3 + x)), v_128));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), _mm_andnot_si128(_mm_or_si128(v_mask1, v_mask2), v_full));
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct InRange_SSE<schar>
|
||||
{
|
||||
int operator () (const schar * src1, const schar * src2, const schar * src3,
|
||||
uchar * dst, int len) const
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (USE_SSE2)
|
||||
{
|
||||
__m128i v_full = _mm_set1_epi8(-1);
|
||||
|
||||
for ( ; x <= len - 16; x += 16 )
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((const __m128i *)(src1 + x));
|
||||
__m128i v_mask1 = _mm_cmpgt_epi8(_mm_loadu_si128((const __m128i *)(src2 + x)), v_src);
|
||||
__m128i v_mask2 = _mm_cmpgt_epi8(v_src, _mm_loadu_si128((const __m128i *)(src3 + x)));
|
||||
_mm_storeu_si128((__m128i *)(dst + x), _mm_andnot_si128(_mm_or_si128(v_mask1, v_mask2), v_full));
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct InRange_SSE<ushort>
|
||||
{
|
||||
int operator () (const ushort * src1, const ushort * src2, const ushort * src3,
|
||||
uchar * dst, int len) const
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (USE_SSE2)
|
||||
{
|
||||
__m128i v_zero = _mm_setzero_si128(), v_full = _mm_set1_epi16(-1), v_32768 = _mm_set1_epi16(-32768);
|
||||
|
||||
for ( ; x <= len - 8; x += 8 )
|
||||
{
|
||||
__m128i v_src = _mm_add_epi16(_mm_loadu_si128((const __m128i *)(src1 + x)), v_32768);
|
||||
__m128i v_mask1 = _mm_cmpgt_epi16(_mm_add_epi16(_mm_loadu_si128((const __m128i *)(src2 + x)), v_32768), v_src);
|
||||
__m128i v_mask2 = _mm_cmpgt_epi16(v_src, _mm_add_epi16(_mm_loadu_si128((const __m128i *)(src3 + x)), v_32768));
|
||||
__m128i v_res = _mm_andnot_si128(_mm_or_si128(v_mask1, v_mask2), v_full);
|
||||
_mm_storel_epi64((__m128i *)(dst + x), _mm_packus_epi16(_mm_srli_epi16(v_res, 8), v_zero));
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct InRange_SSE<short>
|
||||
{
|
||||
int operator () (const short * src1, const short * src2, const short * src3,
|
||||
uchar * dst, int len) const
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (USE_SSE2)
|
||||
{
|
||||
__m128i v_zero = _mm_setzero_si128(), v_full = _mm_set1_epi16(-1);
|
||||
|
||||
for ( ; x <= len - 8; x += 8 )
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((const __m128i *)(src1 + x));
|
||||
__m128i v_mask1 = _mm_cmpgt_epi16(_mm_loadu_si128((const __m128i *)(src2 + x)), v_src);
|
||||
__m128i v_mask2 = _mm_cmpgt_epi16(v_src, _mm_loadu_si128((const __m128i *)(src3 + x)));
|
||||
__m128i v_res = _mm_andnot_si128(_mm_or_si128(v_mask1, v_mask2), v_full);
|
||||
_mm_storel_epi64((__m128i *)(dst + x), _mm_packus_epi16(_mm_srli_epi16(v_res, 8), v_zero));
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct InRange_SSE<int>
|
||||
{
|
||||
int operator () (const int * src1, const int * src2, const int * src3,
|
||||
uchar * dst, int len) const
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (USE_SSE2)
|
||||
{
|
||||
__m128i v_zero = _mm_setzero_si128(), v_full = _mm_set1_epi32(-1);
|
||||
|
||||
for ( ; x <= len - 8; x += 8 )
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((const __m128i *)(src1 + x));
|
||||
__m128i v_res1 = _mm_or_si128(_mm_cmpgt_epi32(_mm_loadu_si128((const __m128i *)(src2 + x)), v_src),
|
||||
_mm_cmpgt_epi32(v_src, _mm_loadu_si128((const __m128i *)(src3 + x))));
|
||||
|
||||
v_src = _mm_loadu_si128((const __m128i *)(src1 + x + 4));
|
||||
__m128i v_res2 = _mm_or_si128(_mm_cmpgt_epi32(_mm_loadu_si128((const __m128i *)(src2 + x + 4)), v_src),
|
||||
_mm_cmpgt_epi32(v_src, _mm_loadu_si128((const __m128i *)(src3 + x + 4))));
|
||||
|
||||
__m128i v_res = _mm_packs_epi32(_mm_srli_epi32(_mm_andnot_si128(v_res1, v_full), 16),
|
||||
_mm_srli_epi32(_mm_andnot_si128(v_res2, v_full), 16));
|
||||
_mm_storel_epi64((__m128i *)(dst + x), _mm_packus_epi16(v_res, v_zero));
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct InRange_SSE<float>
|
||||
{
|
||||
int operator () (const float * src1, const float * src2, const float * src3,
|
||||
uchar * dst, int len) const
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
if (USE_SSE2)
|
||||
{
|
||||
__m128i v_zero = _mm_setzero_si128();
|
||||
|
||||
for ( ; x <= len - 8; x += 8 )
|
||||
{
|
||||
__m128 v_src = _mm_loadu_ps(src1 + x);
|
||||
__m128 v_res1 = _mm_and_ps(_mm_cmple_ps(_mm_loadu_ps(src2 + x), v_src),
|
||||
_mm_cmple_ps(v_src, _mm_loadu_ps(src3 + x)));
|
||||
|
||||
v_src = _mm_loadu_ps(src1 + x + 4);
|
||||
__m128 v_res2 = _mm_and_ps(_mm_cmple_ps(_mm_loadu_ps(src2 + x + 4), v_src),
|
||||
_mm_cmple_ps(v_src, _mm_loadu_ps(src3 + x + 4)));
|
||||
|
||||
__m128i v_res1i = _mm_cvtps_epi32(v_res1), v_res2i = _mm_cvtps_epi32(v_res2);
|
||||
__m128i v_res = _mm_packs_epi32(_mm_srli_epi32(v_res1i, 16), _mm_srli_epi32(v_res2i, 16));
|
||||
_mm_storel_epi64((__m128i *)(dst + x), _mm_packus_epi16(v_res, v_zero));
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
static void inRange_(const T* src1, size_t step1, const T* src2, size_t step2,
|
||||
const T* src3, size_t step3, uchar* dst, size_t step,
|
||||
Size size)
|
||||
{
|
||||
@@ -2989,9 +3272,11 @@ inRange_(const T* src1, size_t step1, const T* src2, size_t step2,
|
||||
step2 /= sizeof(src2[0]);
|
||||
step3 /= sizeof(src3[0]);
|
||||
|
||||
InRange_SSE<T> vop;
|
||||
|
||||
for( ; size.height--; src1 += step1, src2 += step2, src3 += step3, dst += step )
|
||||
{
|
||||
int x = 0;
|
||||
int x = vop(src1, src2, src3, dst, size.width);
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; x <= size.width - 4; x += 4 )
|
||||
{
|
||||
|
||||
@@ -1541,7 +1541,7 @@ static bool ocl_convertScaleAbs( InputArray _src, OutputArray _dst, double alpha
|
||||
kercn = ocl::predictOptimalVectorWidth(_src, _dst), rowsPerWI = d.isIntel() ? 4 : 1;
|
||||
bool doubleSupport = d.doubleFPConfig() > 0;
|
||||
|
||||
if (!doubleSupport && depth == CV_64F)
|
||||
if (depth == CV_32F || depth == CV_64F)
|
||||
return false;
|
||||
|
||||
char cvt[2][50];
|
||||
@@ -1729,22 +1729,18 @@ static bool ocl_LUT(InputArray _src, InputArray _lut, OutputArray _dst)
|
||||
UMat src = _src.getUMat(), lut = _lut.getUMat();
|
||||
_dst.create(src.size(), CV_MAKETYPE(ddepth, dcn));
|
||||
UMat dst = _dst.getUMat();
|
||||
bool bAligned = (1 == lcn) && (0 == (src.offset % 4)) && (0 == ((dcn * src.cols) % 4));
|
||||
// dst.cols == src.cols by params of dst.create
|
||||
int kercn = lcn == 1 ? std::min(4, ocl::predictOptimalVectorWidth(_dst)) : dcn;
|
||||
|
||||
ocl::Kernel k("LUT", ocl::core::lut_oclsrc,
|
||||
format("-D dcn=%d -D lcn=%d -D srcT=%s -D dstT=%s", bAligned ? 4 : dcn, lcn,
|
||||
ocl::typeToStr(src.depth()), ocl::memopTypeToStr(ddepth)
|
||||
));
|
||||
format("-D dcn=%d -D lcn=%d -D srcT=%s -D dstT=%s", kercn, lcn,
|
||||
ocl::typeToStr(src.depth()), ocl::memopTypeToStr(ddepth)));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
int cols = bAligned ? dcn * dst.cols / 4 : dst.cols;
|
||||
|
||||
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::ReadOnlyNoSize(lut),
|
||||
ocl::KernelArg::WriteOnlyNoSize(dst), dst.rows, cols);
|
||||
ocl::KernelArg::WriteOnly(dst, dcn, kercn));
|
||||
|
||||
size_t globalSize[2] = { cols, (dst.rows + 3) / 4 };
|
||||
size_t globalSize[2] = { dst.cols * dcn / kercn, (dst.rows + 3) / 4 };
|
||||
return k.run(2, globalSize, NULL, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ Mat& Mat::setTo(InputArray _value, InputArray _mask)
|
||||
|
||||
IppStatus status = (IppStatus)-1;
|
||||
IppiSize roisize = { cols, rows };
|
||||
int mstep = (int)mask.step, dstep = (int)step;
|
||||
int mstep = (int)mask.step[0], dstep = (int)step[0];
|
||||
|
||||
if (isContinuous() && mask.isContinuous())
|
||||
{
|
||||
@@ -616,7 +616,7 @@ static bool ocl_flip(InputArray _src, OutputArray _dst, int flipCode )
|
||||
{
|
||||
CV_Assert(flipCode >= -1 && flipCode <= 1);
|
||||
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type),
|
||||
flipType, kercn = std::min(ocl::predictOptimalVectorWidth(_src, _dst), 4);;
|
||||
flipType, kercn = std::min(ocl::predictOptimalVectorWidth(_src, _dst), 4);
|
||||
|
||||
if (cn > 4)
|
||||
return false;
|
||||
@@ -631,7 +631,7 @@ static bool ocl_flip(InputArray _src, OutputArray _dst, int flipCode )
|
||||
|
||||
ocl::Device dev = ocl::Device::getDefault();
|
||||
int pxPerWIy = (dev.isIntel() && (dev.type() & ocl::Device::TYPE_GPU)) ? 4 : 1;
|
||||
kercn = std::max(kercn, cn);
|
||||
kercn = (cn!=3 || flipType == FLIP_ROWS) ? std::max(kercn, cn) : cn;
|
||||
|
||||
ocl::Kernel k(kernelName, ocl::core::flip_oclsrc,
|
||||
format( "-D T=%s -D T1=%s -D cn=%d -D PIX_PER_WI_Y=%d -D kercn=%d",
|
||||
@@ -762,7 +762,7 @@ void flip( InputArray _src, OutputArray _dst, int flip_mode )
|
||||
flipHoriz( dst.data, dst.step, dst.data, dst.step, dst.size(), esz );
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
/*#ifdef HAVE_OPENCL
|
||||
|
||||
static bool ocl_repeat(InputArray _src, int ny, int nx, OutputArray _dst)
|
||||
{
|
||||
@@ -790,7 +790,7 @@ static bool ocl_repeat(InputArray _src, int ny, int nx, OutputArray _dst)
|
||||
return k.run(2, globalsize, NULL, false);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif*/
|
||||
|
||||
void repeat(InputArray _src, int ny, int nx, OutputArray _dst)
|
||||
{
|
||||
@@ -800,8 +800,8 @@ void repeat(InputArray _src, int ny, int nx, OutputArray _dst)
|
||||
Size ssize = _src.size();
|
||||
_dst.create(ssize.height*ny, ssize.width*nx, _src.type());
|
||||
|
||||
CV_OCL_RUN(_dst.isUMat(),
|
||||
ocl_repeat(_src, ny, nx, _dst))
|
||||
/*CV_OCL_RUN(_dst.isUMat(),
|
||||
ocl_repeat(_src, ny, nx, _dst))*/
|
||||
|
||||
Mat src = _src.getMat(), dst = _dst.getMat();
|
||||
Size dsize = dst.size();
|
||||
|
||||
@@ -207,7 +207,6 @@ namespace
|
||||
MemoryStack* MemoryPool::getFreeMemStack()
|
||||
{
|
||||
AutoLock lock(mtx_);
|
||||
|
||||
if (!initialized_)
|
||||
initilizeImpl();
|
||||
|
||||
@@ -256,22 +255,31 @@ namespace
|
||||
|
||||
namespace
|
||||
{
|
||||
Mutex mtx_;
|
||||
bool memory_pool_manager_initialized;
|
||||
|
||||
class MemoryPoolManager
|
||||
{
|
||||
public:
|
||||
MemoryPoolManager();
|
||||
~MemoryPoolManager();
|
||||
void Init();
|
||||
|
||||
MemoryPool* getPool(int deviceId);
|
||||
|
||||
private:
|
||||
std::vector<MemoryPool> pools_;
|
||||
};
|
||||
} manager;
|
||||
|
||||
//MemoryPoolManager ;
|
||||
|
||||
MemoryPoolManager::MemoryPoolManager()
|
||||
{
|
||||
int deviceCount = getCudaEnabledDeviceCount();
|
||||
}
|
||||
|
||||
void MemoryPoolManager::Init()
|
||||
{
|
||||
int deviceCount = getCudaEnabledDeviceCount();
|
||||
if (deviceCount > 0)
|
||||
pools_.resize(deviceCount);
|
||||
}
|
||||
@@ -280,7 +288,7 @@ namespace
|
||||
{
|
||||
for (size_t i = 0; i < pools_.size(); ++i)
|
||||
{
|
||||
cudaSetDevice(i);
|
||||
cudaSetDevice(static_cast<int>(i));
|
||||
pools_[i].release();
|
||||
}
|
||||
}
|
||||
@@ -293,7 +301,14 @@ namespace
|
||||
|
||||
MemoryPool* memPool(int deviceId)
|
||||
{
|
||||
static MemoryPoolManager manager;
|
||||
{
|
||||
AutoLock lock(mtx_);
|
||||
if (!memory_pool_manager_initialized)
|
||||
{
|
||||
memory_pool_manager_initialized = true;
|
||||
manager.Init();
|
||||
}
|
||||
}
|
||||
return manager.getPool(deviceId);
|
||||
}
|
||||
}
|
||||
@@ -311,8 +326,10 @@ cv::cuda::StackAllocator::StackAllocator(cudaStream_t stream) : stream_(stream),
|
||||
if (enableMemoryPool)
|
||||
{
|
||||
const int deviceId = getDevice();
|
||||
memStack_ = memPool(deviceId)->getFreeMemStack();
|
||||
|
||||
{
|
||||
AutoLock lock(mtx_);
|
||||
memStack_ = memPool(deviceId)->getFreeMemStack();
|
||||
}
|
||||
DeviceInfo devInfo(deviceId);
|
||||
alignment_ = devInfo.textureAlignment();
|
||||
}
|
||||
|
||||
@@ -190,10 +190,22 @@ void cv::cuda::Stream::enqueueHostCallback(StreamCallback callback, void* userDa
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
bool default_stream_is_initialized;
|
||||
Mutex mtx;
|
||||
Ptr<Stream> default_stream;
|
||||
}
|
||||
|
||||
Stream& cv::cuda::Stream::Null()
|
||||
{
|
||||
static Stream s(Ptr<Impl>(new Impl(0)));
|
||||
return s;
|
||||
AutoLock lock(mtx);
|
||||
if (!default_stream_is_initialized)
|
||||
{
|
||||
default_stream = Ptr<Stream>(new Stream(Ptr<Impl>(new Impl(0))));
|
||||
default_stream_is_initialized = true;
|
||||
}
|
||||
return *default_stream;
|
||||
}
|
||||
|
||||
cv::cuda::Stream::operator bool_type() const
|
||||
|
||||
@@ -1584,6 +1584,24 @@ void line( InputOutputArray _img, Point pt1, Point pt2, const Scalar& color,
|
||||
ThickLine( img, pt1, pt2, buf, thickness, line_type, 3, shift );
|
||||
}
|
||||
|
||||
void arrowedLine(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
|
||||
int thickness, int line_type, int shift, double tipLength)
|
||||
{
|
||||
const double tipSize = norm(pt1-pt2)*tipLength; // Factor to normalize the size of the tip depending on the length of the arrow
|
||||
|
||||
line(img, pt1, pt2, color, thickness, line_type, shift);
|
||||
|
||||
const double angle = atan2( (double) pt1.y - pt2.y, (double) pt1.x - pt2.x );
|
||||
|
||||
Point p(cvRound(pt2.x + tipSize * cos(angle + CV_PI / 4)),
|
||||
cvRound(pt2.y + tipSize * sin(angle + CV_PI / 4)));
|
||||
line(img, p, pt2, color, thickness, line_type, shift);
|
||||
|
||||
p.x = cvRound(pt2.x + tipSize * cos(angle - CV_PI / 4));
|
||||
p.y = cvRound(pt2.y + tipSize * sin(angle - CV_PI / 4));
|
||||
line(img, p, pt2, color, thickness, line_type, shift);
|
||||
}
|
||||
|
||||
void rectangle( InputOutputArray _img, Point pt1, Point pt2,
|
||||
const Scalar& color, int thickness,
|
||||
int lineType, int shift )
|
||||
|
||||
+387
-25
@@ -43,6 +43,7 @@
|
||||
#include "opencv2/core/opencl/runtime/opencl_clamdfft.hpp"
|
||||
#include "opencv2/core/opencl/runtime/opencl_core.hpp"
|
||||
#include "opencl_kernels.hpp"
|
||||
#include <map>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -1781,6 +1782,375 @@ static bool ippi_DFT_R_32F(const Mat& src, Mat& dst, bool inv, int norm_flag)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
enum FftType
|
||||
{
|
||||
R2R = 0, // real to CCS in case forward transform, CCS to real otherwise
|
||||
C2R = 1, // complex to real in case inverse transform
|
||||
R2C = 2, // real to complex in case forward transform
|
||||
C2C = 3 // complex to complex
|
||||
};
|
||||
|
||||
struct OCL_FftPlan
|
||||
{
|
||||
private:
|
||||
UMat twiddles;
|
||||
String buildOptions;
|
||||
int thread_count;
|
||||
bool status;
|
||||
int dft_size;
|
||||
|
||||
public:
|
||||
OCL_FftPlan(int _size): dft_size(_size), status(true)
|
||||
{
|
||||
int min_radix;
|
||||
std::vector<int> radixes, blocks;
|
||||
ocl_getRadixes(dft_size, radixes, blocks, min_radix);
|
||||
thread_count = dft_size / min_radix;
|
||||
|
||||
if (thread_count > (int) ocl::Device::getDefault().maxWorkGroupSize())
|
||||
{
|
||||
status = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// generate string with radix calls
|
||||
String radix_processing;
|
||||
int n = 1, twiddle_size = 0;
|
||||
for (size_t i=0; i<radixes.size(); i++)
|
||||
{
|
||||
int radix = radixes[i], block = blocks[i];
|
||||
if (block > 1)
|
||||
radix_processing += format("fft_radix%d_B%d(smem,twiddles+%d,ind,%d,%d);", radix, block, twiddle_size, n, dft_size/radix);
|
||||
else
|
||||
radix_processing += format("fft_radix%d(smem,twiddles+%d,ind,%d,%d);", radix, twiddle_size, n, dft_size/radix);
|
||||
twiddle_size += (radix-1)*n;
|
||||
n *= radix;
|
||||
}
|
||||
|
||||
Mat tw(1, twiddle_size, CV_32FC2);
|
||||
float* ptr = tw.ptr<float>();
|
||||
int ptr_index = 0;
|
||||
|
||||
n = 1;
|
||||
for (size_t i=0; i<radixes.size(); i++)
|
||||
{
|
||||
int radix = radixes[i];
|
||||
n *= radix;
|
||||
|
||||
for (int j=1; j<radix; j++)
|
||||
{
|
||||
double theta = -CV_2PI*j/n;
|
||||
|
||||
for (int k=0; k<(n/radix); k++)
|
||||
{
|
||||
ptr[ptr_index++] = (float) cos(k*theta);
|
||||
ptr[ptr_index++] = (float) sin(k*theta);
|
||||
}
|
||||
}
|
||||
}
|
||||
twiddles = tw.getUMat(ACCESS_READ);
|
||||
|
||||
buildOptions = format("-D LOCAL_SIZE=%d -D kercn=%d -D RADIX_PROCESS=%s",
|
||||
dft_size, min_radix, radix_processing.c_str());
|
||||
}
|
||||
|
||||
bool enqueueTransform(InputArray _src, OutputArray _dst, int num_dfts, int flags, int fftType, bool rows = true) const
|
||||
{
|
||||
if (!status)
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
UMat dst = _dst.getUMat();
|
||||
|
||||
size_t globalsize[2];
|
||||
size_t localsize[2];
|
||||
String kernel_name;
|
||||
|
||||
bool is1d = (flags & DFT_ROWS) != 0 || num_dfts == 1;
|
||||
bool inv = (flags & DFT_INVERSE) != 0;
|
||||
String options = buildOptions;
|
||||
|
||||
if (rows)
|
||||
{
|
||||
globalsize[0] = thread_count; globalsize[1] = src.rows;
|
||||
localsize[0] = thread_count; localsize[1] = 1;
|
||||
kernel_name = !inv ? "fft_multi_radix_rows" : "ifft_multi_radix_rows";
|
||||
if ((is1d || inv) && (flags & DFT_SCALE))
|
||||
options += " -D DFT_SCALE";
|
||||
}
|
||||
else
|
||||
{
|
||||
globalsize[0] = num_dfts; globalsize[1] = thread_count;
|
||||
localsize[0] = 1; localsize[1] = thread_count;
|
||||
kernel_name = !inv ? "fft_multi_radix_cols" : "ifft_multi_radix_cols";
|
||||
if (flags & DFT_SCALE)
|
||||
options += " -D DFT_SCALE";
|
||||
}
|
||||
|
||||
options += src.channels() == 1 ? " -D REAL_INPUT" : " -D COMPLEX_INPUT";
|
||||
options += dst.channels() == 1 ? " -D REAL_OUTPUT" : " -D COMPLEX_OUTPUT";
|
||||
options += is1d ? " -D IS_1D" : "";
|
||||
|
||||
if (!inv)
|
||||
{
|
||||
if ((is1d && src.channels() == 1) || (rows && (fftType == R2R)))
|
||||
options += " -D NO_CONJUGATE";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rows && (fftType == C2R || fftType == R2R))
|
||||
options += " -D NO_CONJUGATE";
|
||||
if (dst.cols % 2 == 0)
|
||||
options += " -D EVEN";
|
||||
}
|
||||
|
||||
ocl::Kernel k(kernel_name.c_str(), ocl::core::fft_oclsrc, options);
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
k.args(ocl::KernelArg::ReadOnly(src), ocl::KernelArg::WriteOnly(dst), ocl::KernelArg::PtrReadOnly(twiddles), thread_count, num_dfts);
|
||||
return k.run(2, globalsize, localsize, false);
|
||||
}
|
||||
|
||||
private:
|
||||
static void ocl_getRadixes(int cols, std::vector<int>& radixes, std::vector<int>& blocks, int& min_radix)
|
||||
{
|
||||
int factors[34];
|
||||
int nf = DFTFactorize(cols, factors);
|
||||
|
||||
int n = 1;
|
||||
int factor_index = 0;
|
||||
min_radix = INT_MAX;
|
||||
|
||||
// 2^n transforms
|
||||
if ((factors[factor_index] & 1) == 0)
|
||||
{
|
||||
for( ; n < factors[factor_index];)
|
||||
{
|
||||
int radix = 2, block = 1;
|
||||
if (8*n <= factors[0])
|
||||
radix = 8;
|
||||
else if (4*n <= factors[0])
|
||||
{
|
||||
radix = 4;
|
||||
if (cols % 12 == 0)
|
||||
block = 3;
|
||||
else if (cols % 8 == 0)
|
||||
block = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cols % 10 == 0)
|
||||
block = 5;
|
||||
else if (cols % 8 == 0)
|
||||
block = 4;
|
||||
else if (cols % 6 == 0)
|
||||
block = 3;
|
||||
else if (cols % 4 == 0)
|
||||
block = 2;
|
||||
}
|
||||
|
||||
radixes.push_back(radix);
|
||||
blocks.push_back(block);
|
||||
min_radix = min(min_radix, block*radix);
|
||||
n *= radix;
|
||||
}
|
||||
factor_index++;
|
||||
}
|
||||
|
||||
// all the other transforms
|
||||
for( ; factor_index < nf; factor_index++)
|
||||
{
|
||||
int radix = factors[factor_index], block = 1;
|
||||
if (radix == 3)
|
||||
{
|
||||
if (cols % 12 == 0)
|
||||
block = 4;
|
||||
else if (cols % 9 == 0)
|
||||
block = 3;
|
||||
else if (cols % 6 == 0)
|
||||
block = 2;
|
||||
}
|
||||
else if (radix == 5)
|
||||
{
|
||||
if (cols % 10 == 0)
|
||||
block = 2;
|
||||
}
|
||||
radixes.push_back(radix);
|
||||
blocks.push_back(block);
|
||||
min_radix = min(min_radix, block*radix);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class OCL_FftPlanCache
|
||||
{
|
||||
public:
|
||||
static OCL_FftPlanCache & getInstance()
|
||||
{
|
||||
static OCL_FftPlanCache planCache;
|
||||
return planCache;
|
||||
}
|
||||
|
||||
Ptr<OCL_FftPlan> getFftPlan(int dft_size)
|
||||
{
|
||||
std::map<int, Ptr<OCL_FftPlan> >::iterator f = planStorage.find(dft_size);
|
||||
if (f != planStorage.end())
|
||||
{
|
||||
return f->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
Ptr<OCL_FftPlan> newPlan = Ptr<OCL_FftPlan>(new OCL_FftPlan(dft_size));
|
||||
planStorage[dft_size] = newPlan;
|
||||
return newPlan;
|
||||
}
|
||||
}
|
||||
|
||||
~OCL_FftPlanCache()
|
||||
{
|
||||
planStorage.clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
OCL_FftPlanCache() :
|
||||
planStorage()
|
||||
{
|
||||
}
|
||||
std::map<int, Ptr<OCL_FftPlan> > planStorage;
|
||||
};
|
||||
|
||||
static bool ocl_dft_rows(InputArray _src, OutputArray _dst, int nonzero_rows, int flags, int fftType)
|
||||
{
|
||||
Ptr<OCL_FftPlan> plan = OCL_FftPlanCache::getInstance().getFftPlan(_src.cols());
|
||||
return plan->enqueueTransform(_src, _dst, nonzero_rows, flags, fftType, true);
|
||||
}
|
||||
|
||||
static bool ocl_dft_cols(InputArray _src, OutputArray _dst, int nonzero_cols, int flags, int fftType)
|
||||
{
|
||||
Ptr<OCL_FftPlan> plan = OCL_FftPlanCache::getInstance().getFftPlan(_src.rows());
|
||||
return plan->enqueueTransform(_src, _dst, nonzero_cols, flags, fftType, false);
|
||||
}
|
||||
|
||||
static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_rows)
|
||||
{
|
||||
int type = _src.type(), cn = CV_MAT_CN(type);
|
||||
Size ssize = _src.size();
|
||||
if ( !(type == CV_32FC1 || type == CV_32FC2) )
|
||||
return false;
|
||||
|
||||
// if is not a multiplication of prime numbers { 2, 3, 5 }
|
||||
if (ssize.area() != getOptimalDFTSize(ssize.area()))
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
int complex_input = cn == 2 ? 1 : 0;
|
||||
int complex_output = (flags & DFT_COMPLEX_OUTPUT) != 0;
|
||||
int real_input = cn == 1 ? 1 : 0;
|
||||
int real_output = (flags & DFT_REAL_OUTPUT) != 0;
|
||||
bool inv = (flags & DFT_INVERSE) != 0 ? 1 : 0;
|
||||
|
||||
if( nonzero_rows <= 0 || nonzero_rows > _src.rows() )
|
||||
nonzero_rows = _src.rows();
|
||||
bool is1d = (flags & DFT_ROWS) != 0 || nonzero_rows == 1;
|
||||
|
||||
// if output format is not specified
|
||||
if (complex_output + real_output == 0)
|
||||
{
|
||||
if (real_input)
|
||||
real_output = 1;
|
||||
else
|
||||
complex_output = 1;
|
||||
}
|
||||
|
||||
FftType fftType = (FftType)(complex_input << 0 | complex_output << 1);
|
||||
|
||||
// Forward Complex to CCS not supported
|
||||
if (fftType == C2R && !inv)
|
||||
fftType = C2C;
|
||||
|
||||
// Inverse CCS to Complex not supported
|
||||
if (fftType == R2C && inv)
|
||||
fftType = R2R;
|
||||
|
||||
UMat output;
|
||||
if (fftType == C2C || fftType == R2C)
|
||||
{
|
||||
// complex output
|
||||
_dst.create(src.size(), CV_32FC2);
|
||||
output = _dst.getUMat();
|
||||
}
|
||||
else
|
||||
{
|
||||
// real output
|
||||
if (is1d)
|
||||
{
|
||||
_dst.create(src.size(), CV_32FC1);
|
||||
output = _dst.getUMat();
|
||||
}
|
||||
else
|
||||
{
|
||||
_dst.create(src.size(), CV_32FC1);
|
||||
output.create(src.size(), CV_32FC2);
|
||||
}
|
||||
}
|
||||
|
||||
if (!inv)
|
||||
{
|
||||
if (!ocl_dft_rows(src, output, nonzero_rows, flags, fftType))
|
||||
return false;
|
||||
|
||||
if (!is1d)
|
||||
{
|
||||
int nonzero_cols = fftType == R2R ? output.cols/2 + 1 : output.cols;
|
||||
if (!ocl_dft_cols(output, _dst, nonzero_cols, flags, fftType))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fftType == C2C)
|
||||
{
|
||||
// complex output
|
||||
if (!ocl_dft_rows(src, output, nonzero_rows, flags, fftType))
|
||||
return false;
|
||||
|
||||
if (!is1d)
|
||||
{
|
||||
if (!ocl_dft_cols(output, output, output.cols, flags, fftType))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is1d)
|
||||
{
|
||||
if (!ocl_dft_rows(src, output, nonzero_rows, flags, fftType))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int nonzero_cols = src.cols/2 + 1;
|
||||
if (!ocl_dft_cols(src, output, nonzero_cols, flags, fftType))
|
||||
return false;
|
||||
|
||||
if (!ocl_dft_rows(output, _dst, nonzero_rows, flags, fftType))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace cv;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CLAMDFFT
|
||||
|
||||
namespace cv {
|
||||
@@ -1791,14 +2161,6 @@ namespace cv {
|
||||
CV_Assert(s == CLFFT_SUCCESS); \
|
||||
}
|
||||
|
||||
enum FftType
|
||||
{
|
||||
R2R = 0, // real to real
|
||||
C2R = 1, // opencl HERMITIAN_INTERLEAVED to real
|
||||
R2C = 2, // real to opencl HERMITIAN_INTERLEAVED
|
||||
C2C = 3 // complex to complex
|
||||
};
|
||||
|
||||
class PlanCache
|
||||
{
|
||||
struct FftPlan
|
||||
@@ -1923,7 +2285,7 @@ public:
|
||||
}
|
||||
|
||||
// no baked plan is found, so let's create a new one
|
||||
FftPlan * newPlan = new FftPlan(dft_size, src_step, dst_step, doubleFP, inplace, flags, fftType);
|
||||
Ptr<FftPlan> newPlan = Ptr<FftPlan>(new FftPlan(dft_size, src_step, dst_step, doubleFP, inplace, flags, fftType));
|
||||
planStorage.push_back(newPlan);
|
||||
|
||||
return newPlan->plHandle;
|
||||
@@ -1931,8 +2293,6 @@ public:
|
||||
|
||||
~PlanCache()
|
||||
{
|
||||
for (std::vector<FftPlan *>::iterator i = planStorage.begin(), end = planStorage.end(); i != end; ++i)
|
||||
delete (*i);
|
||||
planStorage.clear();
|
||||
}
|
||||
|
||||
@@ -1942,7 +2302,7 @@ protected:
|
||||
{
|
||||
}
|
||||
|
||||
std::vector<FftPlan *> planStorage;
|
||||
std::vector<Ptr<FftPlan> > planStorage;
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
@@ -1960,7 +2320,7 @@ static void CL_CALLBACK oclCleanupCallback(cl_event e, cl_int, void *p)
|
||||
|
||||
}
|
||||
|
||||
static bool ocl_dft(InputArray _src, OutputArray _dst, int flags)
|
||||
static bool ocl_dft_amdfft(InputArray _src, OutputArray _dst, int flags)
|
||||
{
|
||||
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
|
||||
Size ssize = _src.size();
|
||||
@@ -2019,7 +2379,6 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags)
|
||||
|
||||
tmpBuffer.addref();
|
||||
clSetEventCallback(e, CL_COMPLETE, oclCleanupCallback, tmpBuffer.u);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2034,7 +2393,12 @@ void cv::dft( InputArray _src0, OutputArray _dst, int flags, int nonzero_rows )
|
||||
#ifdef HAVE_CLAMDFFT
|
||||
CV_OCL_RUN(ocl::haveAmdFft() && ocl::Device::getDefault().type() != ocl::Device::TYPE_CPU &&
|
||||
_dst.isUMat() && _src0.dims() <= 2 && nonzero_rows == 0,
|
||||
ocl_dft(_src0, _dst, flags))
|
||||
ocl_dft_amdfft(_src0, _dst, flags))
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
CV_OCL_RUN(_dst.isUMat() && _src0.dims() <= 2,
|
||||
ocl_dft(_src0, _dst, flags, nonzero_rows))
|
||||
#endif
|
||||
|
||||
static DFTFunc dft_tbl[6] =
|
||||
@@ -2046,10 +2410,8 @@ void cv::dft( InputArray _src0, OutputArray _dst, int flags, int nonzero_rows )
|
||||
(DFTFunc)RealDFT_64f,
|
||||
(DFTFunc)CCSIDFT_64f
|
||||
};
|
||||
|
||||
AutoBuffer<uchar> buf;
|
||||
void *spec = 0;
|
||||
|
||||
Mat src0 = _src0.getMat(), src = src0;
|
||||
int prev_len = 0, stage = 0;
|
||||
bool inv = (flags & DFT_INVERSE) != 0;
|
||||
@@ -2080,32 +2442,32 @@ void cv::dft( InputArray _src0, OutputArray _dst, int flags, int nonzero_rows )
|
||||
{
|
||||
if ((flags & DFT_ROWS) == 0)
|
||||
{
|
||||
if (!real_transform)
|
||||
if (src.channels() == 2 && !(inv && (flags & DFT_REAL_OUTPUT)))
|
||||
{
|
||||
if (ippi_DFT_C_32F(src,dst, inv, ipp_norm_flag))
|
||||
if (ippi_DFT_C_32F(src, dst, inv, ipp_norm_flag))
|
||||
return;
|
||||
setIppErrorStatus();
|
||||
}
|
||||
else if (inv || !(flags & DFT_COMPLEX_OUTPUT))
|
||||
if (src.channels() == 1 && (inv || !(flags & DFT_COMPLEX_OUTPUT)))
|
||||
{
|
||||
if (ippi_DFT_R_32F(src,dst, inv, ipp_norm_flag))
|
||||
if (ippi_DFT_R_32F(src, dst, inv, ipp_norm_flag))
|
||||
return;
|
||||
setIppErrorStatus();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!real_transform)
|
||||
if (src.channels() == 2 && !(inv && (flags & DFT_REAL_OUTPUT)))
|
||||
{
|
||||
ippiDFT_C_Func ippiFunc = inv ? (ippiDFT_C_Func)ippiDFTInv_CToC_32fc_C1R : (ippiDFT_C_Func)ippiDFTFwd_CToC_32fc_C1R;
|
||||
if (Dft_C_IPPLoop(src,dst, IPPDFT_C_Functor(ippiFunc),ipp_norm_flag))
|
||||
if (Dft_C_IPPLoop(src, dst, IPPDFT_C_Functor(ippiFunc),ipp_norm_flag))
|
||||
return;
|
||||
setIppErrorStatus();
|
||||
}
|
||||
else if (inv || !(flags & DFT_COMPLEX_OUTPUT))
|
||||
if (src.channels() == 1 && (inv || !(flags & DFT_COMPLEX_OUTPUT)))
|
||||
{
|
||||
ippiDFT_R_Func ippiFunc = inv ? (ippiDFT_R_Func)ippiDFTInv_PackToR_32f_C1R : (ippiDFT_R_Func)ippiDFTFwd_RToPack_32f_C1R;
|
||||
if (Dft_R_IPPLoop(src,dst, IPPDFT_R_Functor(ippiFunc),ipp_norm_flag))
|
||||
if (Dft_R_IPPLoop(src, dst, IPPDFT_R_Functor(ippiFunc),ipp_norm_flag))
|
||||
return;
|
||||
setIppErrorStatus();
|
||||
}
|
||||
|
||||
@@ -348,7 +348,18 @@ static void InvSqrt_32f(const float* src, float* dst, int len)
|
||||
|
||||
static void InvSqrt_64f(const double* src, double* dst, int len)
|
||||
{
|
||||
for( int i = 0; i < len; i++ )
|
||||
int i = 0;
|
||||
|
||||
#if CV_SSE2
|
||||
if (USE_SSE2)
|
||||
{
|
||||
__m128d v_1 = _mm_set1_pd(1.0);
|
||||
for ( ; i <= len - 2; i += 2)
|
||||
_mm_storeu_pd(dst + i, _mm_div_pd(v_1, _mm_sqrt_pd(_mm_loadu_pd(src + i))));
|
||||
}
|
||||
#endif
|
||||
|
||||
for( ; i < len; i++ )
|
||||
dst[i] = 1/std::sqrt(src[i]);
|
||||
}
|
||||
|
||||
@@ -2543,12 +2554,33 @@ void patchNaNs( InputOutputArray _a, double _val )
|
||||
NAryMatIterator it(arrays, (uchar**)ptrs);
|
||||
size_t len = it.size*a.channels();
|
||||
Cv32suf val;
|
||||
val.f = (float)_val;
|
||||
float fval = (float)_val;
|
||||
val.f = fval;
|
||||
|
||||
#if CV_SSE2
|
||||
__m128i v_mask1 = _mm_set1_epi32(0x7fffffff), v_mask2 = _mm_set1_epi32(0x7f800000);
|
||||
__m128i v_val = _mm_set1_epi32(val.i);
|
||||
#endif
|
||||
|
||||
for( size_t i = 0; i < it.nplanes; i++, ++it )
|
||||
{
|
||||
int* tptr = ptrs[0];
|
||||
for( size_t j = 0; j < len; j++ )
|
||||
size_t j = 0;
|
||||
|
||||
#if CV_SSE2
|
||||
if (USE_SSE2)
|
||||
{
|
||||
for ( ; j < len; j += 4)
|
||||
{
|
||||
__m128i v_src = _mm_loadu_si128((__m128i const *)(tptr + j));
|
||||
__m128i v_cmp_mask = _mm_cmplt_epi32(v_mask2, _mm_and_si128(v_src, v_mask1));
|
||||
__m128i v_res = _mm_or_si128(_mm_andnot_si128(v_cmp_mask, v_src), _mm_and_si128(v_cmp_mask, v_val));
|
||||
_mm_storeu_si128((__m128i *)(tptr + j), v_res);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
for( ; j < len; j++ )
|
||||
if( (tptr[j] & 0x7fffffff) > 0x7f800000 )
|
||||
tptr[j] = val.i;
|
||||
}
|
||||
|
||||
+82
-65
@@ -2758,21 +2758,30 @@ namespace cv {
|
||||
|
||||
static bool ocl_setIdentity( InputOutputArray _m, const Scalar& s )
|
||||
{
|
||||
int type = _m.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type),
|
||||
sctype = CV_MAKE_TYPE(depth, cn == 3 ? 4 : cn),
|
||||
int type = _m.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type), kercn = cn;
|
||||
if (cn == 1)
|
||||
{
|
||||
kercn = std::min(ocl::predictOptimalVectorWidth(_m), 4);
|
||||
if (kercn != 4)
|
||||
kercn = 1;
|
||||
}
|
||||
int sctype = CV_MAKE_TYPE(depth, cn == 3 ? 4 : cn),
|
||||
rowsPerWI = ocl::Device::getDefault().isIntel() ? 4 : 1;
|
||||
|
||||
ocl::Kernel k("setIdentity", ocl::core::set_identity_oclsrc,
|
||||
format("-D T=%s -D T1=%s -D cn=%d -D ST=%s", ocl::memopTypeToStr(type),
|
||||
ocl::memopTypeToStr(depth), cn, ocl::memopTypeToStr(sctype)));
|
||||
format("-D T=%s -D T1=%s -D cn=%d -D ST=%s -D kercn=%d -D rowsPerWI=%d",
|
||||
ocl::memopTypeToStr(CV_MAKE_TYPE(depth, kercn)),
|
||||
ocl::memopTypeToStr(depth), cn,
|
||||
ocl::memopTypeToStr(sctype),
|
||||
kercn, rowsPerWI));
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
UMat m = _m.getUMat();
|
||||
k.args(ocl::KernelArg::WriteOnly(m), ocl::KernelArg::Constant(Mat(1, 1, sctype, s)),
|
||||
rowsPerWI);
|
||||
k.args(ocl::KernelArg::WriteOnly(m, cn, kercn),
|
||||
ocl::KernelArg::Constant(Mat(1, 1, sctype, s)));
|
||||
|
||||
size_t globalsize[2] = { m.cols, (m.rows + rowsPerWI - 1) / rowsPerWI };
|
||||
size_t globalsize[2] = { m.cols * cn / kercn, (m.rows + rowsPerWI - 1) / rowsPerWI };
|
||||
return k.run(2, globalsize, NULL, false);
|
||||
}
|
||||
|
||||
@@ -3327,7 +3336,7 @@ static inline void reduceSumC_8u16u16s32f_64f(const cv::Mat& srcmat, cv::Mat& ds
|
||||
stype == CV_32FC3 ? (ippiSumHint)ippiSum_32f_C3R :
|
||||
stype == CV_32FC4 ? (ippiSumHint)ippiSum_32f_C4R : 0;
|
||||
func =
|
||||
sdepth == CV_8U ? (cv::ReduceFunc)cv::reduceC_<uchar, double, cv::OpAdd<double> > :
|
||||
sdepth == CV_8U ? (cv::ReduceFunc)cv::reduceC_<uchar, double, cv::OpAdd<double> > :
|
||||
sdepth == CV_16U ? (cv::ReduceFunc)cv::reduceC_<ushort, double, cv::OpAdd<double> > :
|
||||
sdepth == CV_16S ? (cv::ReduceFunc)cv::reduceC_<short, double, cv::OpAdd<double> > :
|
||||
sdepth == CV_32F ? (cv::ReduceFunc)cv::reduceC_<float, double, cv::OpAdd<double> > : 0;
|
||||
@@ -3441,12 +3450,18 @@ static bool ocl_reduce(InputArray _src, OutputArray _dst,
|
||||
const int min_opt_cols = 128, buf_cols = 32;
|
||||
int sdepth = CV_MAT_DEPTH(stype), cn = CV_MAT_CN(stype),
|
||||
ddepth = CV_MAT_DEPTH(dtype), ddepth0 = ddepth;
|
||||
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0,
|
||||
useOptimized = 1 == dim && _src.cols() > min_opt_cols;
|
||||
const ocl::Device &defDev = ocl::Device::getDefault();
|
||||
bool doubleSupport = defDev.doubleFPConfig() > 0;
|
||||
|
||||
size_t wgs = defDev.maxWorkGroupSize();
|
||||
bool useOptimized = 1 == dim && _src.cols() > min_opt_cols && (wgs >= buf_cols);
|
||||
|
||||
if (!doubleSupport && (sdepth == CV_64F || ddepth == CV_64F))
|
||||
return false;
|
||||
|
||||
if ((op == CV_REDUCE_SUM && sdepth == CV_32F) || op == CV_REDUCE_MIN || op == CV_REDUCE_MAX)
|
||||
return false;
|
||||
|
||||
if (op == CV_REDUCE_AVG)
|
||||
{
|
||||
if (sdepth < CV_32S && ddepth < CV_32S)
|
||||
@@ -3455,78 +3470,80 @@ static bool ocl_reduce(InputArray _src, OutputArray _dst,
|
||||
|
||||
const char * const ops[4] = { "OCL_CV_REDUCE_SUM", "OCL_CV_REDUCE_AVG",
|
||||
"OCL_CV_REDUCE_MAX", "OCL_CV_REDUCE_MIN" };
|
||||
char cvt[2][40];
|
||||
|
||||
int wdepth = std::max(ddepth, CV_32F);
|
||||
cv::String build_opt = format("-D %s -D dim=%d -D cn=%d -D ddepth=%d"
|
||||
" -D srcT=%s -D dstT=%s -D dstT0=%s -D convertToWT=%s"
|
||||
" -D convertToDT=%s -D convertToDT0=%s%s",
|
||||
ops[op], dim, cn, ddepth, ocl::typeToStr(useOptimized ? ddepth : sdepth),
|
||||
ocl::typeToStr(ddepth), ocl::typeToStr(ddepth0),
|
||||
ocl::convertTypeStr(ddepth, wdepth, 1, cvt[0]),
|
||||
ocl::convertTypeStr(sdepth, ddepth, 1, cvt[0]),
|
||||
ocl::convertTypeStr(wdepth, ddepth0, 1, cvt[1]),
|
||||
doubleSupport ? " -D DOUBLE_SUPPORT" : "");
|
||||
|
||||
if (useOptimized)
|
||||
{
|
||||
cv::String build_opt_pre = format("-D OP_REDUCE_PRE -D BUF_COLS=%d -D %s -D dim=1"
|
||||
" -D cn=%d -D ddepth=%d -D srcT=%s -D dstT=%s -D convertToDT=%s%s",
|
||||
buf_cols, ops[op], cn, ddepth, ocl::typeToStr(sdepth), ocl::typeToStr(ddepth),
|
||||
ocl::convertTypeStr(sdepth, ddepth, 1, cvt[0]),
|
||||
doubleSupport ? " -D DOUBLE_SUPPORT" : "");
|
||||
ocl::Kernel kpre("reduce_horz_pre", ocl::core::reduce2_oclsrc, build_opt_pre);
|
||||
if (kpre.empty())
|
||||
size_t tileHeight = (size_t)(wgs / buf_cols);
|
||||
if (defDev.isIntel())
|
||||
{
|
||||
static const size_t maxItemInGroupCount = 16;
|
||||
tileHeight = min(tileHeight, defDev.localMemSize() / buf_cols / CV_ELEM_SIZE(CV_MAKETYPE(wdepth, cn)) / maxItemInGroupCount);
|
||||
}
|
||||
char cvt[3][40];
|
||||
cv::String build_opt = format("-D OP_REDUCE_PRE -D BUF_COLS=%d -D TILE_HEIGHT=%d -D %s -D dim=1"
|
||||
" -D cn=%d -D ddepth=%d"
|
||||
" -D srcT=%s -D bufT=%s -D dstT=%s"
|
||||
" -D convertToWT=%s -D convertToBufT=%s -D convertToDT=%s%s",
|
||||
buf_cols, tileHeight, ops[op], cn, ddepth,
|
||||
ocl::typeToStr(sdepth),
|
||||
ocl::typeToStr(ddepth),
|
||||
ocl::typeToStr(ddepth0),
|
||||
ocl::convertTypeStr(ddepth, wdepth, 1, cvt[0]),
|
||||
ocl::convertTypeStr(sdepth, ddepth, 1, cvt[1]),
|
||||
ocl::convertTypeStr(wdepth, ddepth0, 1, cvt[2]),
|
||||
doubleSupport ? " -D DOUBLE_SUPPORT" : "");
|
||||
ocl::Kernel k("reduce_horz_opt", ocl::core::reduce2_oclsrc, build_opt);
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
ocl::Kernel kmain("reduce", ocl::core::reduce2_oclsrc, build_opt);
|
||||
if (kmain.empty())
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
Size dsize(1, src.rows);
|
||||
_dst.create(dsize, dtype);
|
||||
UMat dst = _dst.getUMat();
|
||||
|
||||
UMat buf(src.rows, buf_cols, dst.type());
|
||||
|
||||
kpre.args(ocl::KernelArg::ReadOnly(src),
|
||||
ocl::KernelArg::WriteOnlyNoSize(buf));
|
||||
if (op0 == CV_REDUCE_AVG)
|
||||
k.args(ocl::KernelArg::ReadOnly(src),
|
||||
ocl::KernelArg::WriteOnlyNoSize(dst), 1.0f / src.cols);
|
||||
else
|
||||
k.args(ocl::KernelArg::ReadOnly(src),
|
||||
ocl::KernelArg::WriteOnlyNoSize(dst));
|
||||
|
||||
size_t localSize[2] = { buf_cols, tileHeight};
|
||||
size_t globalSize[2] = { buf_cols, src.rows };
|
||||
if (!kpre.run(2, globalSize, NULL, false))
|
||||
return k.run(2, globalSize, localSize, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
char cvt[2][40];
|
||||
cv::String build_opt = format("-D %s -D dim=%d -D cn=%d -D ddepth=%d"
|
||||
" -D srcT=%s -D dstT=%s -D dstT0=%s -D convertToWT=%s"
|
||||
" -D convertToDT=%s -D convertToDT0=%s%s",
|
||||
ops[op], dim, cn, ddepth, ocl::typeToStr(useOptimized ? ddepth : sdepth),
|
||||
ocl::typeToStr(ddepth), ocl::typeToStr(ddepth0),
|
||||
ocl::convertTypeStr(ddepth, wdepth, 1, cvt[0]),
|
||||
ocl::convertTypeStr(sdepth, ddepth, 1, cvt[0]),
|
||||
ocl::convertTypeStr(wdepth, ddepth0, 1, cvt[1]),
|
||||
doubleSupport ? " -D DOUBLE_SUPPORT" : "");
|
||||
|
||||
ocl::Kernel k("reduce", ocl::core::reduce2_oclsrc, build_opt);
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
Size dsize(dim == 0 ? src.cols : 1, dim == 0 ? 1 : src.rows);
|
||||
_dst.create(dsize, dtype);
|
||||
UMat dst = _dst.getUMat();
|
||||
|
||||
ocl::KernelArg srcarg = ocl::KernelArg::ReadOnly(src),
|
||||
temparg = ocl::KernelArg::WriteOnlyNoSize(dst);
|
||||
|
||||
if (op0 == CV_REDUCE_AVG)
|
||||
kmain.args(ocl::KernelArg::ReadOnly(buf),
|
||||
ocl::KernelArg::WriteOnlyNoSize(dst), 1.0f / src.cols);
|
||||
k.args(srcarg, temparg, 1.0f / (dim == 0 ? src.rows : src.cols));
|
||||
else
|
||||
kmain.args(ocl::KernelArg::ReadOnly(buf),
|
||||
ocl::KernelArg::WriteOnlyNoSize(dst));
|
||||
k.args(srcarg, temparg);
|
||||
|
||||
globalSize[0] = src.rows;
|
||||
return kmain.run(1, globalSize, NULL, false);
|
||||
size_t globalsize = std::max(dsize.width, dsize.height);
|
||||
return k.run(1, &globalsize, NULL, false);
|
||||
}
|
||||
|
||||
ocl::Kernel k("reduce", ocl::core::reduce2_oclsrc, build_opt);
|
||||
if (k.empty())
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
Size dsize(dim == 0 ? src.cols : 1, dim == 0 ? 1 : src.rows);
|
||||
_dst.create(dsize, dtype);
|
||||
UMat dst = _dst.getUMat();
|
||||
|
||||
ocl::KernelArg srcarg = ocl::KernelArg::ReadOnly(src),
|
||||
temparg = ocl::KernelArg::WriteOnlyNoSize(dst);
|
||||
|
||||
if (op0 == CV_REDUCE_AVG)
|
||||
k.args(srcarg, temparg, 1.0f / (dim == 0 ? src.rows : src.cols));
|
||||
else
|
||||
k.args(srcarg, temparg);
|
||||
|
||||
size_t globalsize = std::max(dsize.width, dsize.height);
|
||||
return k.run(1, &globalsize, NULL, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3494,9 +3494,8 @@ public:
|
||||
OpenCLBufferPoolImpl()
|
||||
: currentReservedSize(0), maxReservedSize(0)
|
||||
{
|
||||
// Note: Buffer pool is disabled by default,
|
||||
// because we didn't receive significant performance improvement
|
||||
maxReservedSize = getConfigurationParameterForSize("OPENCV_OPENCL_BUFFERPOOL_LIMIT", 0);
|
||||
int poolSize = ocl::Device::getDefault().isIntel() ? 1 << 27 : 0;
|
||||
maxReservedSize = getConfigurationParameterForSize("OPENCV_OPENCL_BUFFERPOOL_LIMIT", poolSize);
|
||||
}
|
||||
virtual ~OpenCLBufferPoolImpl()
|
||||
{
|
||||
@@ -3739,6 +3738,7 @@ public:
|
||||
u->handle = clCreateBuffer(ctx_handle, CL_MEM_COPY_HOST_PTR|CL_MEM_READ_WRITE|createFlags,
|
||||
u->size, u->origdata, &retval);
|
||||
tempUMatFlags = UMatData::TEMP_COPIED_UMAT;
|
||||
|
||||
}
|
||||
if(!u->handle || retval != CL_SUCCESS)
|
||||
return false;
|
||||
@@ -3880,6 +3880,7 @@ public:
|
||||
if(u->data && retval == CL_SUCCESS)
|
||||
{
|
||||
u->markHostCopyObsolete(false);
|
||||
u->markDeviceMemMapped(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3908,6 +3909,7 @@ public:
|
||||
if(!u)
|
||||
return;
|
||||
|
||||
|
||||
CV_Assert(u->handle != 0);
|
||||
|
||||
UMatDataAutoLock autolock(u);
|
||||
@@ -3918,8 +3920,10 @@ public:
|
||||
|
||||
cl_command_queue q = (cl_command_queue)Queue::getDefault().ptr();
|
||||
cl_int retval = 0;
|
||||
if( !u->copyOnMap() && u->data )
|
||||
if( !u->copyOnMap() && u->deviceMemMapped() )
|
||||
{
|
||||
CV_Assert(u->data != NULL);
|
||||
u->markDeviceMemMapped(false);
|
||||
CV_Assert( (retval = clEnqueueUnmapMemObject(q,
|
||||
(cl_mem)u->handle, u->data, 0, 0, 0)) == CL_SUCCESS );
|
||||
CV_OclDbgAssert(clFinish(q) == CL_SUCCESS);
|
||||
|
||||
@@ -0,0 +1,864 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
// Copyright (C) 2014, Itseez, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
|
||||
#define SQRT_2 0.707106781188f
|
||||
#define sin_120 0.866025403784f
|
||||
#define fft5_2 0.559016994374f
|
||||
#define fft5_3 -0.951056516295f
|
||||
#define fft5_4 -1.538841768587f
|
||||
#define fft5_5 0.363271264002f
|
||||
|
||||
__attribute__((always_inline))
|
||||
float2 mul_float2(float2 a, float2 b) {
|
||||
return (float2)(fma(a.x, b.x, -a.y * b.y), fma(a.x, b.y, a.y * b.x));
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
float2 twiddle(float2 a) {
|
||||
return (float2)(a.y, -a.x);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void butterfly2(float2 a0, float2 a1, __local float2* smem, __global const float2* twiddles,
|
||||
const int x, const int block_size)
|
||||
{
|
||||
const int k = x & (block_size - 1);
|
||||
a1 = mul_float2(twiddles[k], a1);
|
||||
const int dst_ind = (x << 1) - k;
|
||||
|
||||
smem[dst_ind] = a0 + a1;
|
||||
smem[dst_ind+block_size] = a0 - a1;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void butterfly4(float2 a0, float2 a1, float2 a2, float2 a3, __local float2* smem, __global const float2* twiddles,
|
||||
const int x, const int block_size)
|
||||
{
|
||||
const int k = x & (block_size - 1);
|
||||
a1 = mul_float2(twiddles[k], a1);
|
||||
a2 = mul_float2(twiddles[k + block_size], a2);
|
||||
a3 = mul_float2(twiddles[k + 2*block_size], a3);
|
||||
|
||||
const int dst_ind = ((x - k) << 2) + k;
|
||||
|
||||
float2 b0 = a0 + a2;
|
||||
a2 = a0 - a2;
|
||||
float2 b1 = a1 + a3;
|
||||
a3 = twiddle(a1 - a3);
|
||||
|
||||
smem[dst_ind] = b0 + b1;
|
||||
smem[dst_ind + block_size] = a2 + a3;
|
||||
smem[dst_ind + 2*block_size] = b0 - b1;
|
||||
smem[dst_ind + 3*block_size] = a2 - a3;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void butterfly3(float2 a0, float2 a1, float2 a2, __local float2* smem, __global const float2* twiddles,
|
||||
const int x, const int block_size)
|
||||
{
|
||||
const int k = x % block_size;
|
||||
a1 = mul_float2(twiddles[k], a1);
|
||||
a2 = mul_float2(twiddles[k+block_size], a2);
|
||||
const int dst_ind = ((x - k) * 3) + k;
|
||||
|
||||
float2 b1 = a1 + a2;
|
||||
a2 = twiddle(sin_120*(a1 - a2));
|
||||
float2 b0 = a0 - (float2)(0.5f)*b1;
|
||||
|
||||
smem[dst_ind] = a0 + b1;
|
||||
smem[dst_ind + block_size] = b0 + a2;
|
||||
smem[dst_ind + 2*block_size] = b0 - a2;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void butterfly5(float2 a0, float2 a1, float2 a2, float2 a3, float2 a4, __local float2* smem, __global const float2* twiddles,
|
||||
const int x, const int block_size)
|
||||
{
|
||||
const int k = x % block_size;
|
||||
a1 = mul_float2(twiddles[k], a1);
|
||||
a2 = mul_float2(twiddles[k + block_size], a2);
|
||||
a3 = mul_float2(twiddles[k+2*block_size], a3);
|
||||
a4 = mul_float2(twiddles[k+3*block_size], a4);
|
||||
|
||||
const int dst_ind = ((x - k) * 5) + k;
|
||||
__local float2* dst = smem + dst_ind;
|
||||
|
||||
float2 b0, b1, b5;
|
||||
|
||||
b1 = a1 + a4;
|
||||
a1 -= a4;
|
||||
|
||||
a4 = a3 + a2;
|
||||
a3 -= a2;
|
||||
|
||||
a2 = b1 + a4;
|
||||
b0 = a0 - (float2)0.25f * a2;
|
||||
|
||||
b1 = fft5_2 * (b1 - a4);
|
||||
a4 = fft5_3 * (float2)(-a1.y - a3.y, a1.x + a3.x);
|
||||
b5 = (float2)(a4.x - fft5_5 * a1.y, a4.y + fft5_5 * a1.x);
|
||||
|
||||
a4.x += fft5_4 * a3.y;
|
||||
a4.y -= fft5_4 * a3.x;
|
||||
|
||||
a1 = b0 + b1;
|
||||
b0 -= b1;
|
||||
|
||||
dst[0] = a0 + a2;
|
||||
dst[block_size] = a1 + a4;
|
||||
dst[2 * block_size] = b0 + b5;
|
||||
dst[3 * block_size] = b0 - b5;
|
||||
dst[4 * block_size] = a1 - a4;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix2(__local float2* smem, __global const float2* twiddles, const int x, const int block_size, const int t)
|
||||
{
|
||||
float2 a0, a1;
|
||||
|
||||
if (x < t)
|
||||
{
|
||||
a0 = smem[x];
|
||||
a1 = smem[x+t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x < t)
|
||||
butterfly2(a0, a1, smem, twiddles, x, block_size);
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix2_B2(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int x2 = x1 + t/2;
|
||||
float2 a0, a1, a2, a3;
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t];
|
||||
a2 = smem[x2]; a3 = smem[x2+t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
butterfly2(a0, a1, smem, twiddles, x1, block_size);
|
||||
butterfly2(a2, a3, smem, twiddles, x2, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix2_B3(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int x2 = x1 + t/3;
|
||||
const int x3 = x1 + 2*t/3;
|
||||
float2 a0, a1, a2, a3, a4, a5;
|
||||
|
||||
if (x1 < t/3)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t];
|
||||
a2 = smem[x2]; a3 = smem[x2+t];
|
||||
a4 = smem[x3]; a5 = smem[x3+t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/3)
|
||||
{
|
||||
butterfly2(a0, a1, smem, twiddles, x1, block_size);
|
||||
butterfly2(a2, a3, smem, twiddles, x2, block_size);
|
||||
butterfly2(a4, a5, smem, twiddles, x3, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix2_B4(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int thread_block = t/4;
|
||||
const int x2 = x1 + thread_block;
|
||||
const int x3 = x1 + 2*thread_block;
|
||||
const int x4 = x1 + 3*thread_block;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7;
|
||||
|
||||
if (x1 < t/4)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t];
|
||||
a2 = smem[x2]; a3 = smem[x2+t];
|
||||
a4 = smem[x3]; a5 = smem[x3+t];
|
||||
a6 = smem[x4]; a7 = smem[x4+t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/4)
|
||||
{
|
||||
butterfly2(a0, a1, smem, twiddles, x1, block_size);
|
||||
butterfly2(a2, a3, smem, twiddles, x2, block_size);
|
||||
butterfly2(a4, a5, smem, twiddles, x3, block_size);
|
||||
butterfly2(a6, a7, smem, twiddles, x4, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix2_B5(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int thread_block = t/5;
|
||||
const int x2 = x1 + thread_block;
|
||||
const int x3 = x1 + 2*thread_block;
|
||||
const int x4 = x1 + 3*thread_block;
|
||||
const int x5 = x1 + 4*thread_block;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9;
|
||||
|
||||
if (x1 < t/5)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t];
|
||||
a2 = smem[x2]; a3 = smem[x2+t];
|
||||
a4 = smem[x3]; a5 = smem[x3+t];
|
||||
a6 = smem[x4]; a7 = smem[x4+t];
|
||||
a8 = smem[x5]; a9 = smem[x5+t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/5)
|
||||
{
|
||||
butterfly2(a0, a1, smem, twiddles, x1, block_size);
|
||||
butterfly2(a2, a3, smem, twiddles, x2, block_size);
|
||||
butterfly2(a4, a5, smem, twiddles, x3, block_size);
|
||||
butterfly2(a6, a7, smem, twiddles, x4, block_size);
|
||||
butterfly2(a8, a9, smem, twiddles, x5, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix4(__local float2* smem, __global const float2* twiddles, const int x, const int block_size, const int t)
|
||||
{
|
||||
float2 a0, a1, a2, a3;
|
||||
|
||||
if (x < t)
|
||||
{
|
||||
a0 = smem[x]; a1 = smem[x+t]; a2 = smem[x+2*t]; a3 = smem[x+3*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x < t)
|
||||
butterfly4(a0, a1, a2, a3, smem, twiddles, x, block_size);
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix4_B2(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int x2 = x1 + t/2;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7;
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t]; a3 = smem[x1+3*t];
|
||||
a4 = smem[x2]; a5 = smem[x2+t]; a6 = smem[x2+2*t]; a7 = smem[x2+3*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
butterfly4(a0, a1, a2, a3, smem, twiddles, x1, block_size);
|
||||
butterfly4(a4, a5, a6, a7, smem, twiddles, x2, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix4_B3(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int x2 = x1 + t/3;
|
||||
const int x3 = x2 + t/3;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11;
|
||||
|
||||
if (x1 < t/3)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t]; a3 = smem[x1+3*t];
|
||||
a4 = smem[x2]; a5 = smem[x2+t]; a6 = smem[x2+2*t]; a7 = smem[x2+3*t];
|
||||
a8 = smem[x3]; a9 = smem[x3+t]; a10 = smem[x3+2*t]; a11 = smem[x3+3*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/3)
|
||||
{
|
||||
butterfly4(a0, a1, a2, a3, smem, twiddles, x1, block_size);
|
||||
butterfly4(a4, a5, a6, a7, smem, twiddles, x2, block_size);
|
||||
butterfly4(a8, a9, a10, a11, smem, twiddles, x3, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix8(__local float2* smem, __global const float2* twiddles, const int x, const int block_size, const int t)
|
||||
{
|
||||
const int k = x % block_size;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7;
|
||||
|
||||
if (x < t)
|
||||
{
|
||||
int tw_ind = block_size / 8;
|
||||
|
||||
a0 = smem[x];
|
||||
a1 = mul_float2(twiddles[k], smem[x + t]);
|
||||
a2 = mul_float2(twiddles[k + block_size],smem[x+2*t]);
|
||||
a3 = mul_float2(twiddles[k+2*block_size],smem[x+3*t]);
|
||||
a4 = mul_float2(twiddles[k+3*block_size],smem[x+4*t]);
|
||||
a5 = mul_float2(twiddles[k+4*block_size],smem[x+5*t]);
|
||||
a6 = mul_float2(twiddles[k+5*block_size],smem[x+6*t]);
|
||||
a7 = mul_float2(twiddles[k+6*block_size],smem[x+7*t]);
|
||||
|
||||
float2 b0, b1, b6, b7;
|
||||
|
||||
b0 = a0 + a4;
|
||||
a4 = a0 - a4;
|
||||
b1 = a1 + a5;
|
||||
a5 = a1 - a5;
|
||||
a5 = (float2)(SQRT_2) * (float2)(a5.x + a5.y, -a5.x + a5.y);
|
||||
b6 = twiddle(a2 - a6);
|
||||
a2 = a2 + a6;
|
||||
b7 = a3 - a7;
|
||||
b7 = (float2)(SQRT_2) * (float2)(-b7.x + b7.y, -b7.x - b7.y);
|
||||
a3 = a3 + a7;
|
||||
|
||||
a0 = b0 + a2;
|
||||
a2 = b0 - a2;
|
||||
a1 = b1 + a3;
|
||||
a3 = twiddle(b1 - a3);
|
||||
a6 = a4 - b6;
|
||||
a4 = a4 + b6;
|
||||
a7 = twiddle(a5 - b7);
|
||||
a5 = a5 + b7;
|
||||
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x < t)
|
||||
{
|
||||
const int dst_ind = ((x - k) << 3) + k;
|
||||
__local float2* dst = smem + dst_ind;
|
||||
|
||||
dst[0] = a0 + a1;
|
||||
dst[block_size] = a4 + a5;
|
||||
dst[2 * block_size] = a2 + a3;
|
||||
dst[3 * block_size] = a6 + a7;
|
||||
dst[4 * block_size] = a0 - a1;
|
||||
dst[5 * block_size] = a4 - a5;
|
||||
dst[6 * block_size] = a2 - a3;
|
||||
dst[7 * block_size] = a6 - a7;
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix3(__local float2* smem, __global const float2* twiddles, const int x, const int block_size, const int t)
|
||||
{
|
||||
float2 a0, a1, a2;
|
||||
|
||||
if (x < t)
|
||||
{
|
||||
a0 = smem[x]; a1 = smem[x+t]; a2 = smem[x+2*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x < t)
|
||||
butterfly3(a0, a1, a2, smem, twiddles, x, block_size);
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix3_B2(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int x2 = x1 + t/2;
|
||||
float2 a0, a1, a2, a3, a4, a5;
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t];
|
||||
a3 = smem[x2]; a4 = smem[x2+t]; a5 = smem[x2+2*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
butterfly3(a0, a1, a2, smem, twiddles, x1, block_size);
|
||||
butterfly3(a3, a4, a5, smem, twiddles, x2, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix3_B3(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int x2 = x1 + t/3;
|
||||
const int x3 = x2 + t/3;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7, a8;
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t];
|
||||
a3 = smem[x2]; a4 = smem[x2+t]; a5 = smem[x2+2*t];
|
||||
a6 = smem[x3]; a7 = smem[x3+t]; a8 = smem[x3+2*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
butterfly3(a0, a1, a2, smem, twiddles, x1, block_size);
|
||||
butterfly3(a3, a4, a5, smem, twiddles, x2, block_size);
|
||||
butterfly3(a6, a7, a8, smem, twiddles, x3, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix3_B4(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int thread_block = t/4;
|
||||
const int x2 = x1 + thread_block;
|
||||
const int x3 = x1 + 2*thread_block;
|
||||
const int x4 = x1 + 3*thread_block;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11;
|
||||
|
||||
if (x1 < t/4)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1+t]; a2 = smem[x1+2*t];
|
||||
a3 = smem[x2]; a4 = smem[x2+t]; a5 = smem[x2+2*t];
|
||||
a6 = smem[x3]; a7 = smem[x3+t]; a8 = smem[x3+2*t];
|
||||
a9 = smem[x4]; a10 = smem[x4+t]; a11 = smem[x4+2*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/4)
|
||||
{
|
||||
butterfly3(a0, a1, a2, smem, twiddles, x1, block_size);
|
||||
butterfly3(a3, a4, a5, smem, twiddles, x2, block_size);
|
||||
butterfly3(a6, a7, a8, smem, twiddles, x3, block_size);
|
||||
butterfly3(a9, a10, a11, smem, twiddles, x4, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix5(__local float2* smem, __global const float2* twiddles, const int x, const int block_size, const int t)
|
||||
{
|
||||
const int k = x % block_size;
|
||||
float2 a0, a1, a2, a3, a4;
|
||||
|
||||
if (x < t)
|
||||
{
|
||||
a0 = smem[x]; a1 = smem[x + t]; a2 = smem[x+2*t]; a3 = smem[x+3*t]; a4 = smem[x+4*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x < t)
|
||||
butterfly5(a0, a1, a2, a3, a4, smem, twiddles, x, block_size);
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
void fft_radix5_B2(__local float2* smem, __global const float2* twiddles, const int x1, const int block_size, const int t)
|
||||
{
|
||||
const int x2 = x1+t/2;
|
||||
float2 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9;
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
a0 = smem[x1]; a1 = smem[x1 + t]; a2 = smem[x1+2*t]; a3 = smem[x1+3*t]; a4 = smem[x1+4*t];
|
||||
a5 = smem[x2]; a6 = smem[x2 + t]; a7 = smem[x2+2*t]; a8 = smem[x2+3*t]; a9 = smem[x2+4*t];
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x1 < t/2)
|
||||
{
|
||||
butterfly5(a0, a1, a2, a3, a4, smem, twiddles, x1, block_size);
|
||||
butterfly5(a5, a6, a7, a8, a9, smem, twiddles, x2, block_size);
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
}
|
||||
|
||||
#ifdef DFT_SCALE
|
||||
#define SCALE_VAL(x, scale) x*scale
|
||||
#else
|
||||
#define SCALE_VAL(x, scale) x
|
||||
#endif
|
||||
|
||||
__kernel void fft_multi_radix_rows(__global const uchar* src_ptr, int src_step, int src_offset, int src_rows, int src_cols,
|
||||
__global uchar* dst_ptr, int dst_step, int dst_offset, int dst_rows, int dst_cols,
|
||||
__global float2* twiddles_ptr, const int t, const int nz)
|
||||
{
|
||||
const int x = get_global_id(0);
|
||||
const int y = get_group_id(1);
|
||||
const int block_size = LOCAL_SIZE/kercn;
|
||||
if (y < nz)
|
||||
{
|
||||
__local float2 smem[LOCAL_SIZE];
|
||||
__global const float2* twiddles = (__global float2*) twiddles_ptr;
|
||||
const int ind = x;
|
||||
#ifdef IS_1D
|
||||
float scale = 1.f/dst_cols;
|
||||
#else
|
||||
float scale = 1.f/(dst_cols*dst_rows);
|
||||
#endif
|
||||
|
||||
#ifdef COMPLEX_INPUT
|
||||
__global const float2* src = (__global const float2*)(src_ptr + mad24(y, src_step, mad24(x, (int)(sizeof(float)*2), src_offset)));
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
smem[x+i*block_size] = src[i*block_size];
|
||||
#else
|
||||
__global const float* src = (__global const float*)(src_ptr + mad24(y, src_step, mad24(x, (int)sizeof(float), src_offset)));
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
smem[x+i*block_size] = (float2)(src[i*block_size], 0.f);
|
||||
#endif
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
RADIX_PROCESS;
|
||||
|
||||
#ifdef COMPLEX_OUTPUT
|
||||
#ifdef NO_CONJUGATE
|
||||
// copy result without complex conjugate
|
||||
const int cols = dst_cols/2 + 1;
|
||||
#else
|
||||
const int cols = dst_cols;
|
||||
#endif
|
||||
|
||||
__global float2* dst = (__global float2*)(dst_ptr + mad24(y, dst_step, dst_offset));
|
||||
#pragma unroll
|
||||
for (int i=x; i<cols; i+=block_size)
|
||||
dst[i] = SCALE_VAL(smem[i], scale);
|
||||
#else
|
||||
// pack row to CCS
|
||||
__local float* smem_1cn = (__local float*) smem;
|
||||
__global float* dst = (__global float*)(dst_ptr + mad24(y, dst_step, dst_offset));
|
||||
for (int i=x; i<dst_cols-1; i+=block_size)
|
||||
dst[i+1] = SCALE_VAL(smem_1cn[i+2], scale);
|
||||
if (x == 0)
|
||||
dst[0] = SCALE_VAL(smem_1cn[0], scale);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// fill with zero other rows
|
||||
#ifdef COMPLEX_OUTPUT
|
||||
__global float2* dst = (__global float2*)(dst_ptr + mad24(y, dst_step, dst_offset));
|
||||
#else
|
||||
__global float* dst = (__global float*)(dst_ptr + mad24(y, dst_step, dst_offset));
|
||||
#endif
|
||||
#pragma unroll
|
||||
for (int i=x; i<dst_cols; i+=block_size)
|
||||
dst[i] = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
__kernel void fft_multi_radix_cols(__global const uchar* src_ptr, int src_step, int src_offset, int src_rows, int src_cols,
|
||||
__global uchar* dst_ptr, int dst_step, int dst_offset, int dst_rows, int dst_cols,
|
||||
__global float2* twiddles_ptr, const int t, const int nz)
|
||||
{
|
||||
const int x = get_group_id(0);
|
||||
const int y = get_global_id(1);
|
||||
|
||||
if (x < nz)
|
||||
{
|
||||
__local float2 smem[LOCAL_SIZE];
|
||||
__global const uchar* src = src_ptr + mad24(y, src_step, mad24(x, (int)(sizeof(float)*2), src_offset));
|
||||
__global const float2* twiddles = (__global float2*) twiddles_ptr;
|
||||
const int ind = y;
|
||||
const int block_size = LOCAL_SIZE/kercn;
|
||||
float scale = 1.f/(dst_rows*dst_cols);
|
||||
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
smem[y+i*block_size] = *((__global const float2*)(src + i*block_size*src_step));
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
RADIX_PROCESS;
|
||||
|
||||
#ifdef COMPLEX_OUTPUT
|
||||
__global uchar* dst = dst_ptr + mad24(y, dst_step, mad24(x, (int)(sizeof(float)*2), dst_offset));
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
*((__global float2*)(dst + i*block_size*dst_step)) = SCALE_VAL(smem[y + i*block_size], scale);
|
||||
#else
|
||||
if (x == 0)
|
||||
{
|
||||
// pack first column to CCS
|
||||
__local float* smem_1cn = (__local float*) smem;
|
||||
__global uchar* dst = dst_ptr + mad24(y+1, dst_step, dst_offset);
|
||||
for (int i=y; i<dst_rows-1; i+=block_size, dst+=dst_step*block_size)
|
||||
*((__global float*) dst) = SCALE_VAL(smem_1cn[i+2], scale);
|
||||
if (y == 0)
|
||||
*((__global float*) (dst_ptr + dst_offset)) = SCALE_VAL(smem_1cn[0], scale);
|
||||
}
|
||||
else if (x == (dst_cols+1)/2)
|
||||
{
|
||||
// pack last column to CCS (if needed)
|
||||
__local float* smem_1cn = (__local float*) smem;
|
||||
__global uchar* dst = dst_ptr + mad24(dst_cols-1, (int)sizeof(float), mad24(y+1, dst_step, dst_offset));
|
||||
for (int i=y; i<dst_rows-1; i+=block_size, dst+=dst_step*block_size)
|
||||
*((__global float*) dst) = SCALE_VAL(smem_1cn[i+2], scale);
|
||||
if (y == 0)
|
||||
*((__global float*) (dst_ptr + mad24(dst_cols-1, (int)sizeof(float), dst_offset))) = SCALE_VAL(smem_1cn[0], scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
__global uchar* dst = dst_ptr + mad24(x, (int)sizeof(float)*2, mad24(y, dst_step, dst_offset - (int)sizeof(float)));
|
||||
#pragma unroll
|
||||
for (int i=y; i<dst_rows; i+=block_size, dst+=block_size*dst_step)
|
||||
vstore2(SCALE_VAL(smem[i], scale), 0, (__global float*) dst);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__kernel void ifft_multi_radix_rows(__global const uchar* src_ptr, int src_step, int src_offset, int src_rows, int src_cols,
|
||||
__global uchar* dst_ptr, int dst_step, int dst_offset, int dst_rows, int dst_cols,
|
||||
__global float2* twiddles_ptr, const int t, const int nz)
|
||||
{
|
||||
const int x = get_global_id(0);
|
||||
const int y = get_group_id(1);
|
||||
const int block_size = LOCAL_SIZE/kercn;
|
||||
#ifdef IS_1D
|
||||
const float scale = 1.f/dst_cols;
|
||||
#else
|
||||
const float scale = 1.f/(dst_cols*dst_rows);
|
||||
#endif
|
||||
|
||||
if (y < nz)
|
||||
{
|
||||
__local float2 smem[LOCAL_SIZE];
|
||||
__global const float2* twiddles = (__global float2*) twiddles_ptr;
|
||||
const int ind = x;
|
||||
|
||||
#if defined(COMPLEX_INPUT) && !defined(NO_CONJUGATE)
|
||||
__global const float2* src = (__global const float2*)(src_ptr + mad24(y, src_step, mad24(x, (int)(sizeof(float)*2), src_offset)));
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
{
|
||||
smem[x+i*block_size].x = src[i*block_size].x;
|
||||
smem[x+i*block_size].y = -src[i*block_size].y;
|
||||
}
|
||||
#else
|
||||
|
||||
#if !defined(REAL_INPUT) && defined(NO_CONJUGATE)
|
||||
__global const float2* src = (__global const float2*)(src_ptr + mad24(y, src_step, mad24(2, (int)sizeof(float), src_offset)));
|
||||
|
||||
#pragma unroll
|
||||
for (int i=x; i<(LOCAL_SIZE-1)/2; i+=block_size)
|
||||
{
|
||||
smem[i+1].x = src[i].x;
|
||||
smem[i+1].y = -src[i].y;
|
||||
smem[LOCAL_SIZE-i-1] = src[i];
|
||||
}
|
||||
#else
|
||||
|
||||
#pragma unroll
|
||||
for (int i=x; i<(LOCAL_SIZE-1)/2; i+=block_size)
|
||||
{
|
||||
float2 src = vload2(0, (__global const float*)(src_ptr + mad24(y, src_step, mad24(2*i+1, (int)sizeof(float), src_offset))));
|
||||
|
||||
smem[i+1].x = src.x;
|
||||
smem[i+1].y = -src.y;
|
||||
smem[LOCAL_SIZE-i-1] = src;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (x==0)
|
||||
{
|
||||
smem[0].x = *(__global const float*)(src_ptr + mad24(y, src_step, src_offset));
|
||||
smem[0].y = 0.f;
|
||||
|
||||
if(LOCAL_SIZE % 2 ==0)
|
||||
{
|
||||
#if !defined(REAL_INPUT) && defined(NO_CONJUGATE)
|
||||
smem[LOCAL_SIZE/2].x = src[LOCAL_SIZE/2-1].x;
|
||||
#else
|
||||
smem[LOCAL_SIZE/2].x = *(__global const float*)(src_ptr + mad24(y, src_step, mad24(LOCAL_SIZE-1, (int)sizeof(float), src_offset)));
|
||||
#endif
|
||||
smem[LOCAL_SIZE/2].y = 0.f;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
RADIX_PROCESS;
|
||||
|
||||
// copy data to dst
|
||||
#ifdef COMPLEX_OUTPUT
|
||||
__global float2* dst = (__global float*)(dst_ptr + mad24(y, dst_step, mad24(x, (int)(sizeof(float)*2), dst_offset)));
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
{
|
||||
dst[i*block_size].x = SCALE_VAL(smem[x + i*block_size].x, scale);
|
||||
dst[i*block_size].y = SCALE_VAL(-smem[x + i*block_size].y, scale);
|
||||
}
|
||||
#else
|
||||
__global float* dst = (__global float*)(dst_ptr + mad24(y, dst_step, mad24(x, (int)(sizeof(float)), dst_offset)));
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
{
|
||||
dst[i*block_size] = SCALE_VAL(smem[x + i*block_size].x, scale);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// fill with zero other rows
|
||||
#ifdef COMPLEX_OUTPUT
|
||||
__global float2* dst = (__global float2*)(dst_ptr + mad24(y, dst_step, dst_offset));
|
||||
#else
|
||||
__global float* dst = (__global float*)(dst_ptr + mad24(y, dst_step, dst_offset));
|
||||
#endif
|
||||
#pragma unroll
|
||||
for (int i=x; i<dst_cols; i+=block_size)
|
||||
dst[i] = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
__kernel void ifft_multi_radix_cols(__global const uchar* src_ptr, int src_step, int src_offset, int src_rows, int src_cols,
|
||||
__global uchar* dst_ptr, int dst_step, int dst_offset, int dst_rows, int dst_cols,
|
||||
__global float2* twiddles_ptr, const int t, const int nz)
|
||||
{
|
||||
const int x = get_group_id(0);
|
||||
const int y = get_global_id(1);
|
||||
|
||||
#ifdef COMPLEX_INPUT
|
||||
if (x < nz)
|
||||
{
|
||||
__local float2 smem[LOCAL_SIZE];
|
||||
__global const uchar* src = src_ptr + mad24(y, src_step, mad24(x, (int)(sizeof(float)*2), src_offset));
|
||||
__global uchar* dst = dst_ptr + mad24(y, dst_step, mad24(x, (int)(sizeof(float)*2), dst_offset));
|
||||
__global const float2* twiddles = (__global float2*) twiddles_ptr;
|
||||
const int ind = y;
|
||||
const int block_size = LOCAL_SIZE/kercn;
|
||||
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
{
|
||||
float2 temp = *((__global const float2*)(src + i*block_size*src_step));
|
||||
smem[y+i*block_size].x = temp.x;
|
||||
smem[y+i*block_size].y = -temp.y;
|
||||
}
|
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
RADIX_PROCESS;
|
||||
|
||||
// copy data to dst
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
{
|
||||
__global float2* res = (__global float2*)(dst + i*block_size*dst_step);
|
||||
res[0].x = smem[y + i*block_size].x;
|
||||
res[0].y = -smem[y + i*block_size].y;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (x < nz)
|
||||
{
|
||||
__global const float2* twiddles = (__global float2*) twiddles_ptr;
|
||||
const int ind = y;
|
||||
const int block_size = LOCAL_SIZE/kercn;
|
||||
|
||||
__local float2 smem[LOCAL_SIZE];
|
||||
#ifdef EVEN
|
||||
if (x!=0 && (x!=(nz-1)))
|
||||
#else
|
||||
if (x!=0)
|
||||
#endif
|
||||
{
|
||||
__global const uchar* src = src_ptr + mad24(y, src_step, mad24(2*x-1, (int)sizeof(float), src_offset));
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
{
|
||||
float2 temp = vload2(0, (__global const float*)(src + i*block_size*src_step));
|
||||
smem[y+i*block_size].x = temp.x;
|
||||
smem[y+i*block_size].y = -temp.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int ind = x==0 ? 0: 2*x-1;
|
||||
__global const float* src = (__global const float*)(src_ptr + mad24(1, src_step, mad24(ind, (int)sizeof(float), src_offset)));
|
||||
int step = src_step/(int)sizeof(float);
|
||||
|
||||
#pragma unroll
|
||||
for (int i=y; i<(LOCAL_SIZE-1)/2; i+=block_size)
|
||||
{
|
||||
smem[i+1].x = src[2*i*step];
|
||||
smem[i+1].y = -src[(2*i+1)*step];
|
||||
|
||||
smem[LOCAL_SIZE-i-1].x = src[2*i*step];;
|
||||
smem[LOCAL_SIZE-i-1].y = src[(2*i+1)*step];
|
||||
}
|
||||
if (y==0)
|
||||
{
|
||||
smem[0].x = *(__global const float*)(src_ptr + mad24(ind, (int)sizeof(float), src_offset));
|
||||
smem[0].y = 0.f;
|
||||
|
||||
if(LOCAL_SIZE % 2 ==0)
|
||||
{
|
||||
smem[LOCAL_SIZE/2].x = src[(LOCAL_SIZE-2)*step];
|
||||
smem[LOCAL_SIZE/2].y = 0.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
RADIX_PROCESS;
|
||||
|
||||
// copy data to dst
|
||||
__global uchar* dst = dst_ptr + mad24(y, dst_step, mad24(x, (int)(sizeof(float2)), dst_offset));
|
||||
|
||||
#pragma unroll
|
||||
for (int i=0; i<kercn; i++)
|
||||
{
|
||||
__global float2* res = (__global float2*)(dst + i*block_size*dst_step);
|
||||
res[0].x = smem[y + i*block_size].x;
|
||||
res[0].y = -smem[y + i*block_size].y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -36,114 +36,118 @@
|
||||
|
||||
#if lcn == 1
|
||||
#if dcn == 4
|
||||
#define LUT_OP(num)\
|
||||
int idx = *(__global const int *)(srcptr + mad24(num, src_step, src_index));\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
dst[0] = lut_l[idx & 0xff];\
|
||||
dst[1] = lut_l[(idx >> 8) & 0xff];\
|
||||
dst[2] = lut_l[(idx >> 16) & 0xff];\
|
||||
#define LUT_OP \
|
||||
int idx = *(__global const int *)(srcptr + src_index); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx & 0xff]; \
|
||||
dst[1] = lut_l[(idx >> 8) & 0xff]; \
|
||||
dst[2] = lut_l[(idx >> 16) & 0xff]; \
|
||||
dst[3] = lut_l[(idx >> 24) & 0xff];
|
||||
#elif dcn == 3
|
||||
#define LUT_OP(num)\
|
||||
uchar3 idx = vload3(0, srcptr + mad24(num, src_step, src_index));\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
dst[0] = lut_l[idx.x];\
|
||||
dst[1] = lut_l[idx.y];\
|
||||
#define LUT_OP \
|
||||
uchar3 idx = vload3(0, srcptr + src_index); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx.x]; \
|
||||
dst[1] = lut_l[idx.y]; \
|
||||
dst[2] = lut_l[idx.z];
|
||||
#elif dcn == 2
|
||||
#define LUT_OP(num)\
|
||||
short idx = *(__global const short *)(srcptr + mad24(num, src_step, src_index));\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
dst[0] = lut_l[idx & 0xff];\
|
||||
#define LUT_OP \
|
||||
short idx = *(__global const short *)(srcptr + src_index); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx & 0xff]; \
|
||||
dst[1] = lut_l[(idx >> 8) & 0xff];
|
||||
#elif dcn == 1
|
||||
#define LUT_OP(num)\
|
||||
uchar idx = (srcptr + mad24(num, src_step, src_index))[0];\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
#define LUT_OP \
|
||||
uchar idx = (srcptr + src_index)[0]; \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx];
|
||||
#else
|
||||
#define LUT_OP(num)\
|
||||
__global const srcT * src = (__global const srcT *)(srcptr + mad24(num, src_step, src_index));\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
for (int cn = 0; cn < dcn; ++cn)\
|
||||
#define LUT_OP \
|
||||
__global const srcT * src = (__global const srcT *)(srcptr + src_index); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
for (int cn = 0; cn < dcn; ++cn) \
|
||||
dst[cn] = lut_l[src[cn]];
|
||||
#endif
|
||||
#else
|
||||
#if dcn == 4
|
||||
#define LUT_OP(num)\
|
||||
__global const uchar4 *src_pixel = (__global const uchar4 *)(srcptr + mad24(num, src_step, src_index));\
|
||||
int4 idx = convert_int4(src_pixel[0]) * lcn + (int4)(0, 1, 2, 3);\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
dst[0] = lut_l[idx.x];\
|
||||
dst[1] = lut_l[idx.y];\
|
||||
dst[2] = lut_l[idx.z];\
|
||||
#define LUT_OP \
|
||||
__global const uchar4 * src_pixel = (__global const uchar4 *)(srcptr + src_index); \
|
||||
int4 idx = mad24(convert_int4(src_pixel[0]), (int4)(lcn), (int4)(0, 1, 2, 3)); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx.x]; \
|
||||
dst[1] = lut_l[idx.y]; \
|
||||
dst[2] = lut_l[idx.z]; \
|
||||
dst[3] = lut_l[idx.w];
|
||||
#elif dcn == 3
|
||||
#define LUT_OP(num)\
|
||||
uchar3 src_pixel = vload3(0, srcptr + mad24(num, src_step, src_index));\
|
||||
int3 idx = convert_int3(src_pixel) * lcn + (int3)(0, 1, 2);\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
dst[0] = lut_l[idx.x];\
|
||||
dst[1] = lut_l[idx.y];\
|
||||
#define LUT_OP \
|
||||
uchar3 src_pixel = vload3(0, srcptr + src_index); \
|
||||
int3 idx = mad24(convert_int3(src_pixel), (int3)(lcn), (int3)(0, 1, 2)); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx.x]; \
|
||||
dst[1] = lut_l[idx.y]; \
|
||||
dst[2] = lut_l[idx.z];
|
||||
#elif dcn == 2
|
||||
#define LUT_OP(num)\
|
||||
__global const uchar2 *src_pixel = (__global const uchar2 *)(srcptr + mad24(num, src_step, src_index));\
|
||||
int2 idx = convert_int2(src_pixel[0]) * lcn + (int2)(0, 1);\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
dst[0] = lut_l[idx.x];\
|
||||
#define LUT_OP \
|
||||
__global const uchar2 * src_pixel = (__global const uchar2 *)(srcptr + src_index); \
|
||||
int2 idx = mad24(convert_int2(src_pixel[0]), lcn, (int2)(0, 1)); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx.x]; \
|
||||
dst[1] = lut_l[idx.y];
|
||||
#elif dcn == 1 //error case (1 < lcn) ==> lcn == scn == dcn
|
||||
#define LUT_OP(num)\
|
||||
uchar idx = (srcptr + mad24(num, src_step, src_index))[0];\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
#define LUT_OP \
|
||||
uchar idx = (srcptr + src_index)[0]; \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
dst[0] = lut_l[idx];
|
||||
#else
|
||||
#define LUT_OP(num)\
|
||||
__global const srcT *src = (__global const srcT *)(srcptr + mad24(num, src_step, src_index));\
|
||||
dst = (__global dstT *)(dstptr + mad24(num, dst_step, dst_index));\
|
||||
for (int cn = 0; cn < dcn; ++cn)\
|
||||
#define LUT_OP \
|
||||
__global const srcT * src = (__global const srcT *)(srcptr + src_index); \
|
||||
dst = (__global dstT *)(dstptr + dst_index); \
|
||||
for (int cn = 0; cn < dcn; ++cn) \
|
||||
dst[cn] = lut_l[mad24(src[cn], lcn, cn)];
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define LOCAL_LUT_INIT\
|
||||
{\
|
||||
__global const dstT * lut = (__global const dstT *)(lutptr + lut_offset);\
|
||||
int init = mad24((int)get_local_id(1), (int)get_local_size(0), (int)get_local_id(0));\
|
||||
int step = get_local_size(0) * get_local_size(1);\
|
||||
for (int i = init; i < 256 * lcn; i += step)\
|
||||
{\
|
||||
lut_l[i] = lut[i];\
|
||||
}\
|
||||
barrier(CLK_LOCAL_MEM_FENCE);\
|
||||
}
|
||||
|
||||
__kernel void LUT(__global const uchar * srcptr, int src_step, int src_offset,
|
||||
__global const uchar * lutptr, int lut_step, int lut_offset,
|
||||
__global uchar * dstptr, int dst_step, int dst_offset, int rows, int cols)
|
||||
{
|
||||
__local dstT lut_l[256 * lcn];
|
||||
LOCAL_LUT_INIT;
|
||||
|
||||
int x = get_global_id(0);
|
||||
int y = 4 * get_global_id(1);
|
||||
int y = get_global_id(1) << 2;
|
||||
|
||||
__local dstT lut_l[256 * lcn];
|
||||
__global const dstT * lut = (__global const dstT *)(lutptr + lut_offset);
|
||||
|
||||
for (int i = mad24((int)get_local_id(1), (int)get_local_size(0), (int)get_local_id(0)),
|
||||
step = get_local_size(0) * get_local_size(1); i < 256 * lcn; i += step)
|
||||
lut_l[i] = lut[i];
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
if (x < cols && y < rows)
|
||||
{
|
||||
int src_index = mad24(y, src_step, mad24(x, (int)sizeof(srcT) * dcn, src_offset));
|
||||
int dst_index = mad24(y, dst_step, mad24(x, (int)sizeof(dstT) * dcn, dst_offset));
|
||||
|
||||
__global dstT * dst;
|
||||
LUT_OP(0);
|
||||
|
||||
LUT_OP;
|
||||
|
||||
if (y < rows - 1)
|
||||
{
|
||||
LUT_OP(1);
|
||||
src_index += src_step;
|
||||
dst_index += dst_step;
|
||||
LUT_OP;
|
||||
|
||||
if (y < rows - 2)
|
||||
{
|
||||
LUT_OP(2);
|
||||
src_index += src_step;
|
||||
dst_index += dst_step;
|
||||
LUT_OP;
|
||||
|
||||
if (y < rows - 3)
|
||||
{
|
||||
LUT_OP(3);
|
||||
src_index += src_step;
|
||||
dst_index += dst_step;
|
||||
LUT_OP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,9 +42,13 @@
|
||||
#if wdepth <= 4
|
||||
#define MIN_ABS(a) convertFromU(abs(a))
|
||||
#define MIN_ABS2(a, b) convertFromU(abs_diff(a, b))
|
||||
#define MIN(a, b) min(a, b)
|
||||
#define MAX(a, b) max(a, b)
|
||||
#else
|
||||
#define MIN_ABS(a) fabs(a)
|
||||
#define MIN_ABS2(a, b) fabs(a - b)
|
||||
#define MIN(a, b) fmin(a, b)
|
||||
#define MAX(a, b) fmax(a, b)
|
||||
#endif
|
||||
|
||||
#if kercn != 3
|
||||
@@ -60,44 +64,41 @@
|
||||
#define srcTSIZE (int)sizeof(srcT1)
|
||||
#endif
|
||||
|
||||
#ifdef NEED_MINLOC
|
||||
#define CALC_MINLOC(inc) minloc = id + inc
|
||||
#else
|
||||
#define CALC_MINLOC(inc)
|
||||
#endif
|
||||
|
||||
#ifdef NEED_MAXLOC
|
||||
#define CALC_MAXLOC(inc) maxloc = id + inc
|
||||
#else
|
||||
#define CALC_MAXLOC(inc)
|
||||
#endif
|
||||
|
||||
#ifdef NEED_MINVAL
|
||||
#ifdef NEED_MINLOC
|
||||
#define CALC_MIN(p, inc) \
|
||||
if (minval > temp.p) \
|
||||
{ \
|
||||
minval = temp.p; \
|
||||
CALC_MINLOC(inc); \
|
||||
minloc = id + inc; \
|
||||
}
|
||||
#else
|
||||
#define CALC_MIN(p, inc) \
|
||||
minval = MIN(minval, temp.p);
|
||||
#endif
|
||||
#else
|
||||
#define CALC_MIN(p, inc)
|
||||
#endif
|
||||
|
||||
#ifdef NEED_MAXVAL
|
||||
#ifdef NEED_MAXLOC
|
||||
#define CALC_MAX(p, inc) \
|
||||
if (maxval < temp.p) \
|
||||
{ \
|
||||
maxval = temp.p; \
|
||||
CALC_MAXLOC(inc); \
|
||||
maxloc = id + inc; \
|
||||
}
|
||||
#else
|
||||
#define CALC_MAX(p, inc) \
|
||||
maxval = MAX(maxval, temp.p);
|
||||
#endif
|
||||
#else
|
||||
#define CALC_MAX(p, inc)
|
||||
#endif
|
||||
|
||||
#ifdef OP_CALC2
|
||||
#define CALC_MAX2(p) \
|
||||
if (maxval2 < temp.p) \
|
||||
maxval2 = temp.p;
|
||||
maxval2 = MAX(maxval2, temp.p);
|
||||
#else
|
||||
#define CALC_MAX2(p)
|
||||
#endif
|
||||
@@ -208,25 +209,28 @@ __kernel void minmaxloc(__global const uchar * srcptr, int src_step, int src_off
|
||||
|
||||
#if kercn == 1
|
||||
#ifdef NEED_MINVAL
|
||||
#ifdef NEED_MINLOC
|
||||
if (minval > temp)
|
||||
{
|
||||
minval = temp;
|
||||
#ifdef NEED_MINLOC
|
||||
minloc = id;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
minval = MIN(minval, temp);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NEED_MAXVAL
|
||||
#ifdef NEED_MAXLOC
|
||||
if (maxval < temp)
|
||||
{
|
||||
maxval = temp;
|
||||
#ifdef NEED_MAXLOC
|
||||
maxloc = id;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
maxval = MAX(maxval, temp);
|
||||
#endif
|
||||
#ifdef OP_CALC2
|
||||
if (maxval2 < temp2)
|
||||
maxval2 = temp2;
|
||||
maxval2 = MAX(maxval2, temp2);
|
||||
#endif
|
||||
#endif
|
||||
#elif kercn >= 2
|
||||
@@ -282,32 +286,35 @@ __kernel void minmaxloc(__global const uchar * srcptr, int src_step, int src_off
|
||||
{
|
||||
int lid3 = lid - WGS2_ALIGNED;
|
||||
#ifdef NEED_MINVAL
|
||||
#ifdef NEED_MINLOC
|
||||
if (localmem_min[lid3] >= minval)
|
||||
{
|
||||
#ifdef NEED_MINLOC
|
||||
if (localmem_min[lid3] == minval)
|
||||
localmem_minloc[lid3] = min(localmem_minloc[lid3], minloc);
|
||||
else
|
||||
localmem_minloc[lid3] = minloc,
|
||||
#endif
|
||||
localmem_min[lid3] = minval;
|
||||
localmem_min[lid3] = minval;
|
||||
}
|
||||
#else
|
||||
localmem_min[lid3] = MIN(localmem_min[lid3], minval);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NEED_MAXVAL
|
||||
#ifdef NEED_MAXLOC
|
||||
if (localmem_max[lid3] <= maxval)
|
||||
{
|
||||
#ifdef NEED_MAXLOC
|
||||
if (localmem_max[lid3] == maxval)
|
||||
localmem_maxloc[lid3] = min(localmem_maxloc[lid3], maxloc);
|
||||
else
|
||||
localmem_maxloc[lid3] = maxloc,
|
||||
#endif
|
||||
localmem_max[lid3] = maxval;
|
||||
localmem_max[lid3] = maxval;
|
||||
}
|
||||
#else
|
||||
localmem_max[lid3] = MAX(localmem_max[lid3], maxval);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef OP_CALC2
|
||||
if (localmem_max2[lid3] < maxval2)
|
||||
localmem_max2[lid3] = maxval2;
|
||||
localmem_max2[lid3] = MAX(localmem_max2[lid3], maxval2);
|
||||
#endif
|
||||
}
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
@@ -319,32 +326,35 @@ __kernel void minmaxloc(__global const uchar * srcptr, int src_step, int src_off
|
||||
int lid2 = lsize + lid;
|
||||
|
||||
#ifdef NEED_MINVAL
|
||||
#ifdef NEED_MINLOC
|
||||
if (localmem_min[lid] >= localmem_min[lid2])
|
||||
{
|
||||
#ifdef NEED_MINLOC
|
||||
if (localmem_min[lid] == localmem_min[lid2])
|
||||
localmem_minloc[lid] = min(localmem_minloc[lid2], localmem_minloc[lid]);
|
||||
else
|
||||
localmem_minloc[lid] = localmem_minloc[lid2],
|
||||
#endif
|
||||
localmem_min[lid] = localmem_min[lid2];
|
||||
localmem_min[lid] = localmem_min[lid2];
|
||||
}
|
||||
#else
|
||||
localmem_min[lid] = MIN(localmem_min[lid], localmem_min[lid2]);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef NEED_MAXVAL
|
||||
#ifdef NEED_MAXLOC
|
||||
if (localmem_max[lid] <= localmem_max[lid2])
|
||||
{
|
||||
#ifdef NEED_MAXLOC
|
||||
if (localmem_max[lid] == localmem_max[lid2])
|
||||
localmem_maxloc[lid] = min(localmem_maxloc[lid2], localmem_maxloc[lid]);
|
||||
else
|
||||
localmem_maxloc[lid] = localmem_maxloc[lid2],
|
||||
#endif
|
||||
localmem_max[lid] = localmem_max[lid2];
|
||||
localmem_max[lid] = localmem_max[lid2];
|
||||
}
|
||||
#else
|
||||
localmem_max[lid] = MAX(localmem_max[lid], localmem_max[lid2]);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef OP_CALC2
|
||||
if (localmem_max2[lid] < localmem_max2[lid2])
|
||||
localmem_max2[lid] = localmem_max2[lid2];
|
||||
localmem_max2[lid] = MAX(localmem_max2[lid], localmem_max2[lid2]);
|
||||
#endif
|
||||
}
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
|
||||
@@ -379,7 +379,7 @@
|
||||
#define REDUCE_GLOBAL \
|
||||
dstTK temp = convertToDT(loadpix(srcptr + src_index)); \
|
||||
dstTK temp2 = convertToDT(loadpix(src2ptr + src2_index)); \
|
||||
temp = SUM_ABS2(temp, temp2)); \
|
||||
temp = SUM_ABS2(temp, temp2); \
|
||||
FUNC(accumulator, temp.s0); \
|
||||
FUNC(accumulator, temp.s1); \
|
||||
FUNC(accumulator, temp.s2); \
|
||||
|
||||
@@ -81,29 +81,34 @@
|
||||
#define PROCESS_ELEM(acc, value) acc += value
|
||||
#elif defined OCL_CV_REDUCE_MAX
|
||||
#define INIT_VALUE MIN_VAL
|
||||
#define PROCESS_ELEM(acc, value) acc = value > acc ? value : acc
|
||||
#define PROCESS_ELEM(acc, value) acc = max(value, acc)
|
||||
#elif defined OCL_CV_REDUCE_MIN
|
||||
#define INIT_VALUE MAX_VAL
|
||||
#define PROCESS_ELEM(acc, value) acc = value < acc ? value : acc
|
||||
#define PROCESS_ELEM(acc, value) acc = min(value, acc)
|
||||
#else
|
||||
#error "No operation is specified"
|
||||
#endif
|
||||
|
||||
#ifdef OP_REDUCE_PRE
|
||||
|
||||
__kernel void reduce_horz_pre(__global const uchar * srcptr, int src_step, int src_offset, int rows, int cols,
|
||||
__global uchar * bufptr, int buf_step, int buf_offset)
|
||||
__kernel void reduce_horz_opt(__global const uchar * srcptr, int src_step, int src_offset, int rows, int cols,
|
||||
__global uchar * dstptr, int dst_step, int dst_offset
|
||||
#ifdef OCL_CV_REDUCE_AVG
|
||||
, float fscale
|
||||
#endif
|
||||
)
|
||||
{
|
||||
__local bufT lsmem[TILE_HEIGHT][BUF_COLS][cn];
|
||||
|
||||
int x = get_global_id(0);
|
||||
int y = get_global_id(1);
|
||||
if (x < BUF_COLS)
|
||||
int liy = get_local_id(1);
|
||||
if ((x < BUF_COLS) && (y < rows))
|
||||
{
|
||||
int src_index = mad24(y, src_step, mad24(x, (int)sizeof(srcT) * cn, src_offset));
|
||||
int buf_index = mad24(y, buf_step, mad24(x, (int)sizeof(dstT) * cn, buf_offset));
|
||||
|
||||
__global const srcT * src = (__global const srcT *)(srcptr + src_index);
|
||||
__global dstT * buf = (__global dstT *)(bufptr + buf_index);
|
||||
dstT tmp[cn] = { INIT_VALUE };
|
||||
bufT tmp[cn] = { INIT_VALUE };
|
||||
|
||||
int src_step_mul = BUF_COLS * cn;
|
||||
for (int idx = x; idx < cols; idx += BUF_COLS, src += src_step_mul)
|
||||
@@ -111,14 +116,49 @@ __kernel void reduce_horz_pre(__global const uchar * srcptr, int src_step, int s
|
||||
#pragma unroll
|
||||
for (int c = 0; c < cn; ++c)
|
||||
{
|
||||
dstT value = convertToDT(src[c]);
|
||||
bufT value = convertToBufT(src[c]);
|
||||
PROCESS_ELEM(tmp[c], value);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma unroll
|
||||
for (int c = 0; c < cn; ++c)
|
||||
buf[c] = tmp[c];
|
||||
lsmem[liy][x][c] = tmp[c];
|
||||
}
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
if ((x < BUF_COLS / 2) && (y < rows))
|
||||
{
|
||||
#pragma unroll
|
||||
for (int c = 0; c < cn; ++c)
|
||||
{
|
||||
PROCESS_ELEM(lsmem[liy][x][c], lsmem[liy][x + BUF_COLS / 2][c]);
|
||||
}
|
||||
}
|
||||
barrier(CLK_LOCAL_MEM_FENCE);
|
||||
if ((x == 0) && (y < rows))
|
||||
{
|
||||
int dst_index = mad24(y, dst_step, dst_offset);
|
||||
|
||||
__global dstT * dst = (__global dstT *)(dstptr + dst_index);
|
||||
bufT tmp[cn] = { INIT_VALUE };
|
||||
|
||||
#pragma unroll
|
||||
for (int xin = 0; xin < BUF_COLS / 2; xin ++)
|
||||
{
|
||||
#pragma unroll
|
||||
for (int c = 0; c < cn; ++c)
|
||||
{
|
||||
PROCESS_ELEM(tmp[c], lsmem[liy][xin][c]);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma unroll
|
||||
for (int c = 0; c < cn; ++c)
|
||||
#ifdef OCL_CV_REDUCE_AVG
|
||||
dst[c] = convertToDT(convertToWT(tmp[c]) * fscale);
|
||||
#else
|
||||
dst[c] = convertToDT(tmp[c]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,20 +43,18 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#if cn != 3
|
||||
#define loadpix(addr) *(__global const T *)(addr)
|
||||
#if kercn != 3
|
||||
#define storepix(val, addr) *(__global T *)(addr) = val
|
||||
#define TSIZE (int)sizeof(T)
|
||||
#define scalar scalar_
|
||||
#else
|
||||
#define loadpix(addr) vload3(0, (__global const T1 *)(addr))
|
||||
#define storepix(val, addr) vstore3(val, 0, (__global T1 *)(addr))
|
||||
#define TSIZE ((int)sizeof(T1)*3)
|
||||
#define scalar (T)(scalar_.x, scalar_.y, scalar_.z)
|
||||
#endif
|
||||
|
||||
__kernel void setIdentity(__global uchar * srcptr, int src_step, int src_offset, int rows, int cols,
|
||||
ST scalar_, int rowsPerWI)
|
||||
ST scalar_)
|
||||
{
|
||||
int x = get_global_id(0);
|
||||
int y0 = get_global_id(1) * rowsPerWI;
|
||||
@@ -65,7 +63,35 @@ __kernel void setIdentity(__global uchar * srcptr, int src_step, int src_offset,
|
||||
{
|
||||
int src_index = mad24(y0, src_step, mad24(x, TSIZE, src_offset));
|
||||
|
||||
for (int y = y0, y1 = min(rows, y0 + rowsPerWI); y < y1; ++y, src_index += src_step)
|
||||
storepix(x == y ? scalar : (T)(0), srcptr + src_index);
|
||||
#if kercn == cn
|
||||
#pragma unroll
|
||||
for (int y = y0, i = 0, y1 = min(rows, y0 + rowsPerWI); i < rowsPerWI; ++y, ++i, src_index += src_step)
|
||||
if (y < y1)
|
||||
storepix(x == y ? scalar : (T)(0), srcptr + src_index);
|
||||
#elif kercn == 4 && cn == 1
|
||||
if (y0 < rows)
|
||||
{
|
||||
storepix(x == y0 >> 2 ? (T)(scalar, 0, 0, 0) : (T)(0), srcptr + src_index);
|
||||
if (++y0 < rows)
|
||||
{
|
||||
src_index += src_step;
|
||||
storepix(x == y0 >> 2 ? (T)(0, scalar, 0, 0) : (T)(0), srcptr + src_index);
|
||||
|
||||
if (++y0 < rows)
|
||||
{
|
||||
src_index += src_step;
|
||||
storepix(x == y0 >> 2 ? (T)(0, 0, scalar, 0) : (T)(0), srcptr + src_index);
|
||||
|
||||
if (++y0 < rows)
|
||||
{
|
||||
src_index += src_step;
|
||||
storepix(x == y0 >> 2 ? (T)(0, 0, 0, scalar) : (T)(0), srcptr + src_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "Incorrect combination of cn && kercn"
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
+23
-10
@@ -479,9 +479,10 @@ static bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask
|
||||
haveMask = _mask.kind() != _InputArray::NONE,
|
||||
haveSrc2 = _src2.kind() != _InputArray::NONE;
|
||||
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type),
|
||||
kercn = cn == 1 && !haveMask ? ocl::predictOptimalVectorWidth(_src) : 1,
|
||||
kercn = cn == 1 && !haveMask ? ocl::predictOptimalVectorWidth(_src, _src2) : 1,
|
||||
mcn = std::max(cn, kercn);
|
||||
CV_Assert(!haveSrc2 || _src2.type() == type);
|
||||
int convert_cn = haveSrc2 ? mcn : cn;
|
||||
|
||||
if ( (!doubleSupport && depth == CV_64F) || cn > 4 )
|
||||
return false;
|
||||
@@ -513,7 +514,7 @@ static bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask
|
||||
haveMask && _mask.isContinuous() ? " -D HAVE_MASK_CONT" : "", kercn,
|
||||
haveSrc2 ? " -D HAVE_SRC2" : "", calc2 ? " -D OP_CALC2" : "",
|
||||
haveSrc2 && _src2.isContinuous() ? " -D HAVE_SRC2_CONT" : "",
|
||||
depth <= CV_32S && ddepth == CV_32S ? ocl::convertTypeStr(CV_8U, ddepth, mcn, cvt[1]) : "noconvert");
|
||||
depth <= CV_32S && ddepth == CV_32S ? ocl::convertTypeStr(CV_8U, ddepth, convert_cn, cvt[1]) : "noconvert");
|
||||
|
||||
ocl::Kernel k("reduce", ocl::core::reduce_oclsrc, opts);
|
||||
if (k.empty())
|
||||
@@ -918,8 +919,14 @@ static bool ocl_meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv
|
||||
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type);
|
||||
bool doubleSupport = ocl::Device::getDefault().doubleFPConfig() > 0,
|
||||
isContinuous = _src.isContinuous();
|
||||
int groups = ocl::Device::getDefault().maxComputeUnits();
|
||||
size_t wgs = ocl::Device::getDefault().maxWorkGroupSize();
|
||||
const ocl::Device &defDev = ocl::Device::getDefault();
|
||||
int groups = defDev.maxComputeUnits();
|
||||
if (defDev.isIntel())
|
||||
{
|
||||
static const int subSliceEUCount = 10;
|
||||
groups = (groups / subSliceEUCount) * 2;
|
||||
}
|
||||
size_t wgs = defDev.maxWorkGroupSize();
|
||||
|
||||
int ddepth = std::max(CV_32S, depth), sqddepth = std::max(CV_32F, depth),
|
||||
dtype = CV_MAKE_TYPE(ddepth, cn),
|
||||
@@ -1445,6 +1452,9 @@ static bool ocl_minMaxIdx( InputArray _src, double* minVal, double* maxVal, int*
|
||||
|
||||
CV_Assert(!haveSrc2 || _src2.type() == type);
|
||||
|
||||
if (depth == CV_32S || depth == CV_32F)
|
||||
return false;
|
||||
|
||||
if ((depth == CV_64F || ddepth == CV_64F) && !doubleSupport)
|
||||
return false;
|
||||
|
||||
@@ -2178,6 +2188,9 @@ static bool ocl_norm( InputArray _src, int normType, InputArray _mask, double &
|
||||
(!doubleSupport && depth == CV_64F))
|
||||
return false;
|
||||
|
||||
if( depth == CV_32F && (!_mask.empty() || normType == NORM_INF) )
|
||||
return false;
|
||||
|
||||
UMat src = _src.getUMat();
|
||||
|
||||
if (normType == NORM_INF)
|
||||
@@ -2270,7 +2283,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
|
||||
setIppErrorStatus();
|
||||
}
|
||||
typedef IppStatus (CV_STDCALL* ippiMaskNormFuncC3)(const void *, int, const void *, int, IppiSize, int, Ipp64f *);
|
||||
/*typedef IppStatus (CV_STDCALL* ippiMaskNormFuncC3)(const void *, int, const void *, int, IppiSize, int, Ipp64f *);
|
||||
ippiMaskNormFuncC3 ippFuncC3 =
|
||||
normType == NORM_INF ?
|
||||
(type == CV_8UC3 ? (ippiMaskNormFuncC3)ippiNorm_Inf_8u_C3CMR :
|
||||
@@ -2305,7 +2318,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask )
|
||||
return normType == NORM_L2SQR ? (double)(norm * norm) : (double)norm;
|
||||
}
|
||||
setIppErrorStatus();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2533,7 +2546,7 @@ static bool ocl_norm( InputArray _src1, InputArray _src2, int normType, InputArr
|
||||
normType &= ~NORM_RELATIVE;
|
||||
bool normsum = normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR;
|
||||
|
||||
if ( !(normType == NORM_INF || normsum) )
|
||||
if ( !normsum || !_mask.empty() )
|
||||
return false;
|
||||
|
||||
if (normsum)
|
||||
@@ -2711,7 +2724,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
0) :
|
||||
normType == NORM_L1 ?
|
||||
(type == CV_8UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_8u_C1MR :
|
||||
type == CV_8SC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_8s_C1MR :
|
||||
//type == CV_8SC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_8s_C1MR :
|
||||
type == CV_16UC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_16u_C1MR :
|
||||
type == CV_32FC1 ? (ippiMaskNormDiffFuncC1)ippiNormDiff_L1_32f_C1MR :
|
||||
0) :
|
||||
@@ -2728,7 +2741,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
return normType == NORM_L2SQR ? (double)(norm * norm) : (double)norm;
|
||||
setIppErrorStatus();
|
||||
}
|
||||
typedef IppStatus (CV_STDCALL* ippiMaskNormDiffFuncC3)(const void *, int, const void *, int, const void *, int, IppiSize, int, Ipp64f *);
|
||||
/*typedef IppStatus (CV_STDCALL* ippiMaskNormDiffFuncC3)(const void *, int, const void *, int, const void *, int, IppiSize, int, Ipp64f *);
|
||||
ippiMaskNormDiffFuncC3 ippFuncC3 =
|
||||
normType == NORM_INF ?
|
||||
(type == CV_8UC3 ? (ippiMaskNormDiffFuncC3)ippiNormDiff_Inf_8u_C3CMR :
|
||||
@@ -2763,7 +2776,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m
|
||||
return normType == NORM_L2SQR ? (double)(norm * norm) : (double)norm;
|
||||
}
|
||||
setIppErrorStatus();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -829,7 +829,7 @@ OCL_TEST_P(Pow, Mat)
|
||||
{
|
||||
static const double pows[] = { -4, -1, -2.5, 0, 1, 2, 3.7, 4 };
|
||||
|
||||
for (int j = 0; j < test_loop_times; j++)
|
||||
for (int j = 0; j < 1/*test_loop_times*/; j++)
|
||||
for (int k = 0, size = sizeof(pows) / sizeof(double); k < size; ++k)
|
||||
{
|
||||
SCOPED_TRACE(pows[k]);
|
||||
@@ -1203,7 +1203,7 @@ OCL_TEST_P(MinMaxIdx_Mask, Mat)
|
||||
|
||||
static bool relativeError(double actual, double expected, double eps)
|
||||
{
|
||||
return std::abs(actual - expected) / actual < eps;
|
||||
return std::abs(actual - expected) < eps*(1 + std::abs(actual));
|
||||
}
|
||||
|
||||
typedef ArithmTestBase Norm;
|
||||
@@ -1230,7 +1230,7 @@ OCL_TEST_P(Norm, NORM_INF_1arg_mask)
|
||||
OCL_OFF(const double cpuRes = cv::norm(src1_roi, NORM_INF, mask_roi));
|
||||
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, NORM_INF, umask_roi));
|
||||
|
||||
EXPECT_NEAR(cpuRes, gpuRes, 0.1);
|
||||
EXPECT_NEAR(cpuRes, gpuRes, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1302,7 +1302,7 @@ OCL_TEST_P(Norm, NORM_INF_2args)
|
||||
OCL_OFF(const double cpuRes = cv::norm(src1_roi, src2_roi, type));
|
||||
OCL_ON(const double gpuRes = cv::norm(usrc1_roi, usrc2_roi, type));
|
||||
|
||||
EXPECT_NEAR(cpuRes, gpuRes, 0.1);
|
||||
EXPECT_NEAR(cpuRes, gpuRes, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,17 +48,26 @@
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
enum OCL_FFT_TYPE
|
||||
{
|
||||
R2R = 0,
|
||||
C2R = 1,
|
||||
R2C = 2,
|
||||
C2C = 3
|
||||
};
|
||||
|
||||
namespace cvtest {
|
||||
namespace ocl {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Dft
|
||||
|
||||
PARAM_TEST_CASE(Dft, cv::Size, MatDepth, bool, bool, bool, bool)
|
||||
PARAM_TEST_CASE(Dft, cv::Size, OCL_FFT_TYPE, bool, bool, bool, bool)
|
||||
{
|
||||
cv::Size dft_size;
|
||||
int dft_flags, depth;
|
||||
bool inplace;
|
||||
int dft_flags, depth, cn, dft_type;
|
||||
bool hint;
|
||||
bool is1d;
|
||||
|
||||
TEST_DECLARE_INPUT_PARAMETER(src);
|
||||
TEST_DECLARE_OUTPUT_PARAMETER(dst);
|
||||
@@ -66,34 +75,50 @@ PARAM_TEST_CASE(Dft, cv::Size, MatDepth, bool, bool, bool, bool)
|
||||
virtual void SetUp()
|
||||
{
|
||||
dft_size = GET_PARAM(0);
|
||||
depth = GET_PARAM(1);
|
||||
inplace = GET_PARAM(2);
|
||||
dft_type = GET_PARAM(1);
|
||||
depth = CV_32F;
|
||||
|
||||
dft_flags = 0;
|
||||
switch (dft_type)
|
||||
{
|
||||
case R2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 1; break;
|
||||
case C2R: dft_flags |= cv::DFT_REAL_OUTPUT; cn = 2; break;
|
||||
case R2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 1; break;
|
||||
case C2C: dft_flags |= cv::DFT_COMPLEX_OUTPUT; cn = 2; break;
|
||||
}
|
||||
|
||||
if (GET_PARAM(2))
|
||||
dft_flags |= cv::DFT_INVERSE;
|
||||
if (GET_PARAM(3))
|
||||
dft_flags |= cv::DFT_ROWS;
|
||||
if (GET_PARAM(4))
|
||||
dft_flags |= cv::DFT_SCALE;
|
||||
if (GET_PARAM(5))
|
||||
dft_flags |= cv::DFT_INVERSE;
|
||||
hint = GET_PARAM(5);
|
||||
is1d = (dft_flags & DFT_ROWS) != 0 || dft_size.height == 1;
|
||||
}
|
||||
|
||||
void generateTestData(int cn = 2)
|
||||
void generateTestData()
|
||||
{
|
||||
src = randomMat(dft_size, CV_MAKE_TYPE(depth, cn), 0.0, 100.0);
|
||||
usrc = src.getUMat(ACCESS_READ);
|
||||
|
||||
if (inplace)
|
||||
dst = src, udst = usrc;
|
||||
}
|
||||
};
|
||||
|
||||
OCL_TEST_P(Dft, C2C)
|
||||
OCL_TEST_P(Dft, Mat)
|
||||
{
|
||||
generateTestData();
|
||||
|
||||
OCL_OFF(cv::dft(src, dst, dft_flags | cv::DFT_COMPLEX_OUTPUT));
|
||||
OCL_ON(cv::dft(usrc, udst, dft_flags | cv::DFT_COMPLEX_OUTPUT));
|
||||
int nonzero_rows = hint ? src.cols - randomInt(1, src.rows-1) : 0;
|
||||
OCL_OFF(cv::dft(src, dst, dft_flags, nonzero_rows));
|
||||
OCL_ON(cv::dft(usrc, udst, dft_flags, nonzero_rows));
|
||||
|
||||
// In case forward R2C 1d tranform dst contains only half of output
|
||||
// without complex conjugate
|
||||
if (dft_type == R2C && is1d && (dft_flags & cv::DFT_INVERSE) == 0)
|
||||
{
|
||||
dst = dst(cv::Range(0, dst.rows), cv::Range(0, dst.cols/2 + 1));
|
||||
udst = udst(cv::Range(0, udst.rows), cv::Range(0, udst.cols/2 + 1));
|
||||
}
|
||||
|
||||
double eps = src.size().area() * 1e-4;
|
||||
EXPECT_MAT_NEAR(dst, udst, eps);
|
||||
@@ -150,15 +175,15 @@ OCL_TEST_P(MulSpectrums, Mat)
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(OCL_ImgProc, MulSpectrums, testing::Combine(Bool(), Bool()));
|
||||
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Core, Dft, Combine(Values(cv::Size(2, 3), cv::Size(5, 4), cv::Size(25, 20),
|
||||
cv::Size(512, 1), cv::Size(1024, 768)),
|
||||
Values(CV_32F, CV_64F),
|
||||
Bool(), // inplace
|
||||
OCL_INSTANTIATE_TEST_CASE_P(Core, Dft, Combine(Values(cv::Size(10, 10), cv::Size(36, 36), cv::Size(512, 1), cv::Size(1280, 768)),
|
||||
Values((OCL_FFT_TYPE) R2C, (OCL_FFT_TYPE) C2C, (OCL_FFT_TYPE) R2R, (OCL_FFT_TYPE) C2R),
|
||||
Bool(), // DFT_INVERSE
|
||||
Bool(), // DFT_ROWS
|
||||
Bool(), // DFT_SCALE
|
||||
Bool()) // DFT_INVERSE
|
||||
Bool() // hint
|
||||
)
|
||||
);
|
||||
|
||||
} } // namespace cvtest::ocl
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
#endif // HAVE_OPENCL
|
||||
@@ -6,4 +6,4 @@ set(the_description "CUDA-accelerated Background Segmentation")
|
||||
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations)
|
||||
|
||||
ocv_define_module(cudabgsegm opencv_video OPTIONAL opencv_legacy opencv_imgproc opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)
|
||||
ocv_define_module(cudabgsegm opencv_video OPTIONAL opencv_imgproc opencv_cudaarithm opencv_cudafilters opencv_cudaimgproc)
|
||||
|
||||
@@ -42,10 +42,6 @@
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_LEGACY
|
||||
# include "opencv2/legacy.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCV_CUDAIMGPROC
|
||||
# include "opencv2/cudaimgproc.hpp"
|
||||
#endif
|
||||
@@ -72,18 +68,6 @@ using namespace perf;
|
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT
|
||||
|
||||
#ifdef HAVE_OPENCV_LEGACY
|
||||
|
||||
namespace cv
|
||||
{
|
||||
template<> void DefaultDeleter<CvBGStatModel>::operator ()(CvBGStatModel* obj) const
|
||||
{
|
||||
cvReleaseBGStatModel(&obj);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DEF_PARAM_TEST_1(Video, string);
|
||||
|
||||
PERF_TEST_P(Video, FGDStatModel,
|
||||
@@ -150,48 +134,7 @@ PERF_TEST_P(Video, FGDStatModel,
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_OPENCV_LEGACY
|
||||
IplImage ipl_frame = frame;
|
||||
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
|
||||
|
||||
int i = 0;
|
||||
|
||||
// collect performance data
|
||||
for (; i < numIters; ++i)
|
||||
{
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
ipl_frame = frame;
|
||||
|
||||
startTimer();
|
||||
if(!next())
|
||||
break;
|
||||
|
||||
cvUpdateBGStatModel(&ipl_frame, model);
|
||||
|
||||
stopTimer();
|
||||
}
|
||||
|
||||
// process last frame in sequence to get data for sanity test
|
||||
for (; i < numIters; ++i)
|
||||
{
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
ipl_frame = frame;
|
||||
|
||||
cvUpdateBGStatModel(&ipl_frame, model);
|
||||
}
|
||||
|
||||
const cv::Mat background = cv::cvarrToMat(model->background);
|
||||
const cv::Mat foreground = cv::cvarrToMat(model->foreground);
|
||||
|
||||
CPU_SANITY_CHECK(background);
|
||||
CPU_SANITY_CHECK(foreground);
|
||||
#else
|
||||
FAIL_NO_CPU();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,6 @@
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_LEGACY
|
||||
# include "opencv2/legacy.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
|
||||
using namespace cvtest;
|
||||
@@ -63,80 +59,6 @@ using namespace cvtest;
|
||||
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// FGDStatModel
|
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && defined(HAVE_OPENCV_LEGACY)
|
||||
|
||||
namespace cv
|
||||
{
|
||||
template<> void DefaultDeleter<CvBGStatModel>::operator ()(CvBGStatModel* obj) const
|
||||
{
|
||||
cvReleaseBGStatModel(&obj);
|
||||
}
|
||||
}
|
||||
|
||||
PARAM_TEST_CASE(FGDStatModel, cv::cuda::DeviceInfo, std::string)
|
||||
{
|
||||
cv::cuda::DeviceInfo devInfo;
|
||||
std::string inputFile;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
cv::cuda::setDevice(devInfo.deviceID());
|
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
|
||||
}
|
||||
};
|
||||
|
||||
CUDA_TEST_P(FGDStatModel, Update)
|
||||
{
|
||||
cv::VideoCapture cap(inputFile);
|
||||
ASSERT_TRUE(cap.isOpened());
|
||||
|
||||
cv::Mat frame;
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
IplImage ipl_frame = frame;
|
||||
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
|
||||
|
||||
cv::cuda::GpuMat d_frame(frame);
|
||||
cv::Ptr<cv::cuda::BackgroundSubtractorFGD> d_fgd = cv::cuda::createBackgroundSubtractorFGD();
|
||||
cv::cuda::GpuMat d_foreground, d_background;
|
||||
std::vector< std::vector<cv::Point> > foreground_regions;
|
||||
d_fgd->apply(d_frame, d_foreground);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
{
|
||||
cap >> frame;
|
||||
ASSERT_FALSE(frame.empty());
|
||||
|
||||
ipl_frame = frame;
|
||||
int gold_count = cvUpdateBGStatModel(&ipl_frame, model);
|
||||
|
||||
d_frame.upload(frame);
|
||||
d_fgd->apply(d_frame, d_foreground);
|
||||
d_fgd->getBackgroundImage(d_background);
|
||||
d_fgd->getForegroundRegions(foreground_regions);
|
||||
int count = (int) foreground_regions.size();
|
||||
|
||||
cv::Mat gold_background = cv::cvarrToMat(model->background);
|
||||
cv::Mat gold_foreground = cv::cvarrToMat(model->foreground);
|
||||
|
||||
ASSERT_MAT_NEAR(gold_background, d_background, 1.0);
|
||||
ASSERT_MAT_NEAR(gold_foreground, d_foreground, 0.0);
|
||||
ASSERT_EQ(gold_count, count);
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(CUDA_BgSegm, FGDStatModel, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
testing::Values(std::string("768x576.avi"))));
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// MOG
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ set(the_description "CUDA-accelerated Video Encoding/Decoding")
|
||||
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef)
|
||||
|
||||
ocv_add_module(cudacodec opencv_highgui OPTIONAL opencv_cudev)
|
||||
ocv_add_module(cudacodec opencv_core opencv_videoio OPTIONAL opencv_cudev)
|
||||
|
||||
ocv_module_include_directories()
|
||||
ocv_glob_module_sources()
|
||||
|
||||
@@ -45,34 +45,12 @@
|
||||
#include "opencv2/core/cuda/common.hpp"
|
||||
#include "opencv2/core/cuda/limits.hpp"
|
||||
|
||||
#include "cuda/disparity_bilateral_filter.hpp"
|
||||
|
||||
namespace cv { namespace cuda { namespace device
|
||||
{
|
||||
namespace disp_bilateral_filter
|
||||
{
|
||||
__constant__ float* ctable_color;
|
||||
__constant__ float* ctable_space;
|
||||
__constant__ size_t ctable_space_step;
|
||||
|
||||
__constant__ int cndisp;
|
||||
__constant__ int cradius;
|
||||
|
||||
__constant__ short cedge_disc;
|
||||
__constant__ short cmax_disc;
|
||||
|
||||
void disp_load_constants(float* table_color, PtrStepSzf table_space, int ndisp, int radius, short edge_disc, short max_disc)
|
||||
{
|
||||
cudaSafeCall( cudaMemcpyToSymbol(ctable_color, &table_color, sizeof(table_color)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(ctable_space, &table_space.data, sizeof(table_space.data)) );
|
||||
size_t table_space_step = table_space.step / sizeof(float);
|
||||
cudaSafeCall( cudaMemcpyToSymbol(ctable_space_step, &table_space_step, sizeof(size_t)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cndisp, &ndisp, sizeof(int)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cradius, &radius, sizeof(int)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cedge_disc, &edge_disc, sizeof(short)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmax_disc, &max_disc, sizeof(short)) );
|
||||
}
|
||||
|
||||
template <int channels>
|
||||
struct DistRgbMax
|
||||
{
|
||||
@@ -95,7 +73,11 @@ namespace cv { namespace cuda { namespace device
|
||||
};
|
||||
|
||||
template <int channels, typename T>
|
||||
__global__ void disp_bilateral_filter(int t, T* disp, size_t disp_step, const uchar* img, size_t img_step, int h, int w)
|
||||
__global__ void disp_bilateral_filter(int t, T* disp, size_t disp_step,
|
||||
const uchar* img, size_t img_step, int h, int w,
|
||||
const float* ctable_color, const float * ctable_space, size_t ctable_space_step,
|
||||
int cradius,
|
||||
short cedge_disc, short cmax_disc)
|
||||
{
|
||||
const int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
const int x = ((blockIdx.x * blockDim.x + threadIdx.x) << 1) + ((y + t) & 1);
|
||||
@@ -178,7 +160,7 @@ namespace cv { namespace cuda { namespace device
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void disp_bilateral_filter(PtrStepSz<T> disp, PtrStepSzb img, int channels, int iters, cudaStream_t stream)
|
||||
void disp_bilateral_filter(PtrStepSz<T> disp, PtrStepSzb img, int channels, int iters, const float *table_color, const float* table_space, size_t table_step, int radius, short edge_disc, short max_disc, cudaStream_t stream)
|
||||
{
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
@@ -190,20 +172,20 @@ namespace cv { namespace cuda { namespace device
|
||||
case 1:
|
||||
for (int i = 0; i < iters; ++i)
|
||||
{
|
||||
disp_bilateral_filter<1><<<grid, threads, 0, stream>>>(0, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);
|
||||
disp_bilateral_filter<1><<<grid, threads, 0, stream>>>(0, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols, table_color, table_space, table_step, radius, edge_disc, max_disc);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
disp_bilateral_filter<1><<<grid, threads, 0, stream>>>(1, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);
|
||||
disp_bilateral_filter<1><<<grid, threads, 0, stream>>>(1, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols, table_color, table_space, table_step, radius, edge_disc, max_disc);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
for (int i = 0; i < iters; ++i)
|
||||
{
|
||||
disp_bilateral_filter<3><<<grid, threads, 0, stream>>>(0, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);
|
||||
disp_bilateral_filter<3><<<grid, threads, 0, stream>>>(0, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols, table_color, table_space, table_step, radius, edge_disc, max_disc);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
disp_bilateral_filter<3><<<grid, threads, 0, stream>>>(1, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols);
|
||||
disp_bilateral_filter<3><<<grid, threads, 0, stream>>>(1, disp.data, disp.step/sizeof(T), img.data, img.step, disp.rows, disp.cols, table_color, table_space, table_step, radius, edge_disc, max_disc);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
}
|
||||
break;
|
||||
@@ -215,8 +197,8 @@ namespace cv { namespace cuda { namespace device
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
template void disp_bilateral_filter<uchar>(PtrStepSz<uchar> disp, PtrStepSzb img, int channels, int iters, cudaStream_t stream);
|
||||
template void disp_bilateral_filter<short>(PtrStepSz<short> disp, PtrStepSzb img, int channels, int iters, cudaStream_t stream);
|
||||
template void disp_bilateral_filter<uchar>(PtrStepSz<uchar> disp, PtrStepSzb img, int channels, int iters, const float *table_color, const float *table_space, size_t table_step, int radius, short, short, cudaStream_t stream);
|
||||
template void disp_bilateral_filter<short>(PtrStepSz<short> disp, PtrStepSzb img, int channels, int iters, const float *table_color, const float *table_space, size_t table_step, int radius, short, short, cudaStream_t stream);
|
||||
} // namespace bilateral_filter
|
||||
}}} // namespace cv { namespace cuda { namespace cudev
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace cv { namespace cuda { namespace device
|
||||
{
|
||||
namespace disp_bilateral_filter
|
||||
{
|
||||
template<typename T>
|
||||
void disp_bilateral_filter(PtrStepSz<T> disp, PtrStepSzb img, int channels, int iters, const float *, const float *, size_t, int radius, short edge_disc, short max_disc, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
@@ -48,109 +48,61 @@
|
||||
#include "opencv2/core/cuda/reduce.hpp"
|
||||
#include "opencv2/core/cuda/functional.hpp"
|
||||
|
||||
#include "cuda/stereocsbp.hpp"
|
||||
|
||||
namespace cv { namespace cuda { namespace device
|
||||
{
|
||||
namespace stereocsbp
|
||||
{
|
||||
///////////////////////////////////////////////////////////////
|
||||
/////////////////////// load constants ////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
__constant__ int cndisp;
|
||||
|
||||
__constant__ float cmax_data_term;
|
||||
__constant__ float cdata_weight;
|
||||
__constant__ float cmax_disc_term;
|
||||
__constant__ float cdisc_single_jump;
|
||||
|
||||
__constant__ int cth;
|
||||
|
||||
__constant__ size_t cimg_step;
|
||||
__constant__ size_t cmsg_step;
|
||||
__constant__ size_t cdisp_step1;
|
||||
__constant__ size_t cdisp_step2;
|
||||
|
||||
__constant__ uchar* cleft;
|
||||
__constant__ uchar* cright;
|
||||
__constant__ uchar* ctemp;
|
||||
|
||||
|
||||
void load_constants(int ndisp, float max_data_term, float data_weight, float max_disc_term, float disc_single_jump, int min_disp_th,
|
||||
const PtrStepSzb& left, const PtrStepSzb& right, const PtrStepSzb& temp)
|
||||
{
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cndisp, &ndisp, sizeof(int)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmax_data_term, &max_data_term, sizeof(float)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdata_weight, &data_weight, sizeof(float)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmax_disc_term, &max_disc_term, sizeof(float)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisc_single_jump, &disc_single_jump, sizeof(float)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cth, &min_disp_th, sizeof(int)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cimg_step, &left.step, sizeof(size_t)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cleft, &left.data, sizeof(left.data)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cright, &right.data, sizeof(right.data)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(ctemp, &temp.data, sizeof(temp.data)) );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
/////////////////////// init data cost ////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
template <int channels> struct DataCostPerPixel;
|
||||
template <> struct DataCostPerPixel<1>
|
||||
template <int channels> static float __device__ pixeldiff(const uchar* left, const uchar* right, float max_data_term);
|
||||
template<> __device__ __forceinline__ static float pixeldiff<1>(const uchar* left, const uchar* right, float max_data_term)
|
||||
{
|
||||
static __device__ __forceinline__ float compute(const uchar* left, const uchar* right)
|
||||
{
|
||||
return fmin(cdata_weight * ::abs((int)*left - *right), cdata_weight * cmax_data_term);
|
||||
}
|
||||
};
|
||||
template <> struct DataCostPerPixel<3>
|
||||
return fmin( ::abs((int)*left - *right), max_data_term);
|
||||
}
|
||||
template<> __device__ __forceinline__ static float pixeldiff<3>(const uchar* left, const uchar* right, float max_data_term)
|
||||
{
|
||||
static __device__ __forceinline__ float compute(const uchar* left, const uchar* right)
|
||||
{
|
||||
float tb = 0.114f * ::abs((int)left[0] - right[0]);
|
||||
float tg = 0.587f * ::abs((int)left[1] - right[1]);
|
||||
float tr = 0.299f * ::abs((int)left[2] - right[2]);
|
||||
float tb = 0.114f * ::abs((int)left[0] - right[0]);
|
||||
float tg = 0.587f * ::abs((int)left[1] - right[1]);
|
||||
float tr = 0.299f * ::abs((int)left[2] - right[2]);
|
||||
|
||||
return fmin(cdata_weight * (tr + tg + tb), cdata_weight * cmax_data_term);
|
||||
}
|
||||
};
|
||||
template <> struct DataCostPerPixel<4>
|
||||
return fmin(tr + tg + tb, max_data_term);
|
||||
}
|
||||
template<> __device__ __forceinline__ static float pixeldiff<4>(const uchar* left, const uchar* right, float max_data_term)
|
||||
{
|
||||
static __device__ __forceinline__ float compute(const uchar* left, const uchar* right)
|
||||
{
|
||||
uchar4 l = *((const uchar4*)left);
|
||||
uchar4 r = *((const uchar4*)right);
|
||||
uchar4 l = *((const uchar4*)left);
|
||||
uchar4 r = *((const uchar4*)right);
|
||||
|
||||
float tb = 0.114f * ::abs((int)l.x - r.x);
|
||||
float tg = 0.587f * ::abs((int)l.y - r.y);
|
||||
float tr = 0.299f * ::abs((int)l.z - r.z);
|
||||
float tb = 0.114f * ::abs((int)l.x - r.x);
|
||||
float tg = 0.587f * ::abs((int)l.y - r.y);
|
||||
float tr = 0.299f * ::abs((int)l.z - r.z);
|
||||
|
||||
return fmin(cdata_weight * (tr + tg + tb), cdata_weight * cmax_data_term);
|
||||
}
|
||||
};
|
||||
return fmin(tr + tg + tb, max_data_term);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__global__ void get_first_k_initial_global(T* data_cost_selected_, T *selected_disp_pyr, int h, int w, int nr_plane)
|
||||
__global__ void get_first_k_initial_global(uchar *ctemp, T* data_cost_selected_, T *selected_disp_pyr, int h, int w, int nr_plane, int ndisp,
|
||||
size_t msg_step, size_t disp_step)
|
||||
{
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if (y < h && x < w)
|
||||
{
|
||||
T* selected_disparity = selected_disp_pyr + y * cmsg_step + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step + x;
|
||||
T* selected_disparity = selected_disp_pyr + y * msg_step + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * msg_step + x;
|
||||
T* data_cost = (T*)ctemp + y * msg_step + x;
|
||||
|
||||
for(int i = 0; i < nr_plane; i++)
|
||||
{
|
||||
T minimum = device::numeric_limits<T>::max();
|
||||
int id = 0;
|
||||
for(int d = 0; d < cndisp; d++)
|
||||
for(int d = 0; d < ndisp; d++)
|
||||
{
|
||||
T cur = data_cost[d * cdisp_step1];
|
||||
T cur = data_cost[d * disp_step];
|
||||
if(cur < minimum)
|
||||
{
|
||||
minimum = cur;
|
||||
@@ -158,46 +110,47 @@ namespace cv { namespace cuda { namespace device
|
||||
}
|
||||
}
|
||||
|
||||
data_cost_selected[i * cdisp_step1] = minimum;
|
||||
selected_disparity[i * cdisp_step1] = id;
|
||||
data_cost [id * cdisp_step1] = numeric_limits<T>::max();
|
||||
data_cost_selected[i * disp_step] = minimum;
|
||||
selected_disparity[i * disp_step] = id;
|
||||
data_cost [id * disp_step] = numeric_limits<T>::max();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
__global__ void get_first_k_initial_local(T* data_cost_selected_, T* selected_disp_pyr, int h, int w, int nr_plane)
|
||||
__global__ void get_first_k_initial_local(uchar *ctemp, T* data_cost_selected_, T* selected_disp_pyr, int h, int w, int nr_plane, int ndisp,
|
||||
size_t msg_step, size_t disp_step)
|
||||
{
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if (y < h && x < w)
|
||||
{
|
||||
T* selected_disparity = selected_disp_pyr + y * cmsg_step + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step + x;
|
||||
T* selected_disparity = selected_disp_pyr + y * msg_step + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * msg_step + x;
|
||||
T* data_cost = (T*)ctemp + y * msg_step + x;
|
||||
|
||||
int nr_local_minimum = 0;
|
||||
|
||||
T prev = data_cost[0 * cdisp_step1];
|
||||
T cur = data_cost[1 * cdisp_step1];
|
||||
T next = data_cost[2 * cdisp_step1];
|
||||
T prev = data_cost[0 * disp_step];
|
||||
T cur = data_cost[1 * disp_step];
|
||||
T next = data_cost[2 * disp_step];
|
||||
|
||||
for (int d = 1; d < cndisp - 1 && nr_local_minimum < nr_plane; d++)
|
||||
for (int d = 1; d < ndisp - 1 && nr_local_minimum < nr_plane; d++)
|
||||
{
|
||||
if (cur < prev && cur < next)
|
||||
{
|
||||
data_cost_selected[nr_local_minimum * cdisp_step1] = cur;
|
||||
selected_disparity[nr_local_minimum * cdisp_step1] = d;
|
||||
data_cost_selected[nr_local_minimum * disp_step] = cur;
|
||||
selected_disparity[nr_local_minimum * disp_step] = d;
|
||||
|
||||
data_cost[d * cdisp_step1] = numeric_limits<T>::max();
|
||||
data_cost[d * disp_step] = numeric_limits<T>::max();
|
||||
|
||||
nr_local_minimum++;
|
||||
}
|
||||
prev = cur;
|
||||
cur = next;
|
||||
next = data_cost[(d + 1) * cdisp_step1];
|
||||
next = data_cost[(d + 1) * disp_step];
|
||||
}
|
||||
|
||||
for (int i = nr_local_minimum; i < nr_plane; i++)
|
||||
@@ -205,25 +158,27 @@ namespace cv { namespace cuda { namespace device
|
||||
T minimum = numeric_limits<T>::max();
|
||||
int id = 0;
|
||||
|
||||
for (int d = 0; d < cndisp; d++)
|
||||
for (int d = 0; d < ndisp; d++)
|
||||
{
|
||||
cur = data_cost[d * cdisp_step1];
|
||||
cur = data_cost[d * disp_step];
|
||||
if (cur < minimum)
|
||||
{
|
||||
minimum = cur;
|
||||
id = d;
|
||||
}
|
||||
}
|
||||
data_cost_selected[i * cdisp_step1] = minimum;
|
||||
selected_disparity[i * cdisp_step1] = id;
|
||||
data_cost_selected[i * disp_step] = minimum;
|
||||
selected_disparity[i * disp_step] = id;
|
||||
|
||||
data_cost[id * cdisp_step1] = numeric_limits<T>::max();
|
||||
data_cost[id * disp_step] = numeric_limits<T>::max();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, int channels>
|
||||
__global__ void init_data_cost(int h, int w, int level)
|
||||
__global__ void init_data_cost(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step,
|
||||
int h, int w, int level, int ndisp, float data_weight, float max_data_term,
|
||||
int min_disp, size_t msg_step, size_t disp_step)
|
||||
{
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
@@ -236,9 +191,9 @@ namespace cv { namespace cuda { namespace device
|
||||
int x0 = x << level;
|
||||
int xt = (x + 1) << level;
|
||||
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step + x;
|
||||
T* data_cost = (T*)ctemp + y * msg_step + x;
|
||||
|
||||
for(int d = 0; d < cndisp; ++d)
|
||||
for(int d = 0; d < ndisp; ++d)
|
||||
{
|
||||
float val = 0.0f;
|
||||
for(int yi = y0; yi < yt; yi++)
|
||||
@@ -246,24 +201,26 @@ namespace cv { namespace cuda { namespace device
|
||||
for(int xi = x0; xi < xt; xi++)
|
||||
{
|
||||
int xr = xi - d;
|
||||
if(d < cth || xr < 0)
|
||||
val += cdata_weight * cmax_data_term;
|
||||
if(d < min_disp || xr < 0)
|
||||
val += data_weight * max_data_term;
|
||||
else
|
||||
{
|
||||
const uchar* lle = cleft + yi * cimg_step + xi * channels;
|
||||
const uchar* lri = cright + yi * cimg_step + xr * channels;
|
||||
|
||||
val += DataCostPerPixel<channels>::compute(lle, lri);
|
||||
val += data_weight * pixeldiff<channels>(lle, lri, max_data_term);
|
||||
}
|
||||
}
|
||||
}
|
||||
data_cost[cdisp_step1 * d] = saturate_cast<T>(val);
|
||||
data_cost[disp_step * d] = saturate_cast<T>(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, int winsz, int channels>
|
||||
__global__ void init_data_cost_reduce(int level, int rows, int cols, int h)
|
||||
__global__ void init_data_cost_reduce(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step,
|
||||
int level, int rows, int cols, int h, int ndisp, float data_weight, float max_data_term,
|
||||
int min_disp, size_t msg_step, size_t disp_step)
|
||||
{
|
||||
int x_out = blockIdx.x;
|
||||
int y_out = blockIdx.y % h;
|
||||
@@ -271,7 +228,7 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
int tid = threadIdx.x;
|
||||
|
||||
if (d < cndisp)
|
||||
if (d < ndisp)
|
||||
{
|
||||
int x0 = x_out << level;
|
||||
int y0 = y_out << level;
|
||||
@@ -281,8 +238,8 @@ namespace cv { namespace cuda { namespace device
|
||||
float val = 0.0f;
|
||||
if (x0 + tid < cols)
|
||||
{
|
||||
if (x0 + tid - d < 0 || d < cth)
|
||||
val = cdata_weight * cmax_data_term * len;
|
||||
if (x0 + tid - d < 0 || d < min_disp)
|
||||
val = data_weight * max_data_term * len;
|
||||
else
|
||||
{
|
||||
const uchar* lle = cleft + y0 * cimg_step + channels * (x0 + tid );
|
||||
@@ -290,7 +247,7 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
for(int y = 0; y < len; ++y)
|
||||
{
|
||||
val += DataCostPerPixel<channels>::compute(lle, lri);
|
||||
val += data_weight * pixeldiff<channels>(lle, lri, max_data_term);
|
||||
|
||||
lle += cimg_step;
|
||||
lri += cimg_step;
|
||||
@@ -302,16 +259,16 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
reduce<winsz>(smem + winsz * threadIdx.z, val, tid, plus<float>());
|
||||
|
||||
T* data_cost = (T*)ctemp + y_out * cmsg_step + x_out;
|
||||
T* data_cost = (T*)ctemp + y_out * msg_step + x_out;
|
||||
|
||||
if (tid == 0)
|
||||
data_cost[cdisp_step1 * d] = saturate_cast<T>(val);
|
||||
data_cost[disp_step * d] = saturate_cast<T>(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void init_data_cost_caller_(int /*rows*/, int /*cols*/, int h, int w, int level, int /*ndisp*/, int channels, cudaStream_t stream)
|
||||
void init_data_cost_caller_(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step, int /*rows*/, int /*cols*/, int h, int w, int level, int ndisp, int channels, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step, cudaStream_t stream)
|
||||
{
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
@@ -321,15 +278,15 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
switch (channels)
|
||||
{
|
||||
case 1: init_data_cost<T, 1><<<grid, threads, 0, stream>>>(h, w, level); break;
|
||||
case 3: init_data_cost<T, 3><<<grid, threads, 0, stream>>>(h, w, level); break;
|
||||
case 4: init_data_cost<T, 4><<<grid, threads, 0, stream>>>(h, w, level); break;
|
||||
case 1: init_data_cost<T, 1><<<grid, threads, 0, stream>>>(cleft, cright, ctemp, cimg_step, h, w, level, ndisp, data_weight, max_data_term, min_disp, msg_step, disp_step); break;
|
||||
case 3: init_data_cost<T, 3><<<grid, threads, 0, stream>>>(cleft, cright, ctemp, cimg_step, h, w, level, ndisp, data_weight, max_data_term, min_disp, msg_step, disp_step); break;
|
||||
case 4: init_data_cost<T, 4><<<grid, threads, 0, stream>>>(cleft, cright, ctemp, cimg_step, h, w, level, ndisp, data_weight, max_data_term, min_disp, msg_step, disp_step); break;
|
||||
default: CV_Error(cv::Error::BadNumChannels, "Unsupported channels count");
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, int winsz>
|
||||
void init_data_cost_reduce_caller_(int rows, int cols, int h, int w, int level, int ndisp, int channels, cudaStream_t stream)
|
||||
void init_data_cost_reduce_caller_(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step, int rows, int cols, int h, int w, int level, int ndisp, int channels, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step, cudaStream_t stream)
|
||||
{
|
||||
const int threadsNum = 256;
|
||||
const size_t smem_size = threadsNum * sizeof(float);
|
||||
@@ -340,19 +297,19 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
switch (channels)
|
||||
{
|
||||
case 1: init_data_cost_reduce<T, winsz, 1><<<grid, threads, smem_size, stream>>>(level, rows, cols, h); break;
|
||||
case 3: init_data_cost_reduce<T, winsz, 3><<<grid, threads, smem_size, stream>>>(level, rows, cols, h); break;
|
||||
case 4: init_data_cost_reduce<T, winsz, 4><<<grid, threads, smem_size, stream>>>(level, rows, cols, h); break;
|
||||
case 1: init_data_cost_reduce<T, winsz, 1><<<grid, threads, smem_size, stream>>>(cleft, cright, ctemp, cimg_step, level, rows, cols, h, ndisp, data_weight, max_data_term, min_disp, msg_step, disp_step); break;
|
||||
case 3: init_data_cost_reduce<T, winsz, 3><<<grid, threads, smem_size, stream>>>(cleft, cright, ctemp, cimg_step, level, rows, cols, h, ndisp, data_weight, max_data_term, min_disp, msg_step, disp_step); break;
|
||||
case 4: init_data_cost_reduce<T, winsz, 4><<<grid, threads, smem_size, stream>>>(cleft, cright, ctemp, cimg_step, level, rows, cols, h, ndisp, data_weight, max_data_term, min_disp, msg_step, disp_step); break;
|
||||
default: CV_Error(cv::Error::BadNumChannels, "Unsupported channels count");
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void init_data_cost(int rows, int cols, T* disp_selected_pyr, T* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, bool use_local_init_data_cost, cudaStream_t stream)
|
||||
void init_data_cost(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step, int rows, int cols, T* disp_selected_pyr, T* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, float data_weight, float max_data_term, int min_disp, bool use_local_init_data_cost, cudaStream_t stream)
|
||||
{
|
||||
|
||||
typedef void (*InitDataCostCaller)(int cols, int rows, int w, int h, int level, int ndisp, int channels, cudaStream_t stream);
|
||||
typedef void (*InitDataCostCaller)(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step, int cols, int rows, int w, int h, int level, int ndisp, int channels, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step, cudaStream_t stream);
|
||||
|
||||
static const InitDataCostCaller init_data_cost_callers[] =
|
||||
{
|
||||
@@ -362,10 +319,8 @@ namespace cv { namespace cuda { namespace device
|
||||
};
|
||||
|
||||
size_t disp_step = msg_step * h;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
init_data_cost_callers[level](rows, cols, h, w, level, ndisp, channels, stream);
|
||||
init_data_cost_callers[level](cleft, cright, ctemp, cimg_step, rows, cols, h, w, level, ndisp, channels, data_weight, max_data_term, min_disp, msg_step, disp_step, stream);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
@@ -378,9 +333,9 @@ namespace cv { namespace cuda { namespace device
|
||||
grid.y = divUp(h, threads.y);
|
||||
|
||||
if (use_local_init_data_cost == true)
|
||||
get_first_k_initial_local<<<grid, threads, 0, stream>>> (data_cost_selected, disp_selected_pyr, h, w, nr_plane);
|
||||
get_first_k_initial_local<<<grid, threads, 0, stream>>> (ctemp, data_cost_selected, disp_selected_pyr, h, w, nr_plane, ndisp, msg_step, disp_step);
|
||||
else
|
||||
get_first_k_initial_global<<<grid, threads, 0, stream>>>(data_cost_selected, disp_selected_pyr, h, w, nr_plane);
|
||||
get_first_k_initial_global<<<grid, threads, 0, stream>>>(ctemp, data_cost_selected, disp_selected_pyr, h, w, nr_plane, ndisp, msg_step, disp_step);
|
||||
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
@@ -388,18 +343,18 @@ namespace cv { namespace cuda { namespace device
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
template void init_data_cost(int rows, int cols, short* disp_selected_pyr, short* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, bool use_local_init_data_cost, cudaStream_t stream);
|
||||
template void init_data_cost<short>(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step, int rows, int cols, short* disp_selected_pyr, short* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, float data_weight, float max_data_term, int min_disp, bool use_local_init_data_cost, cudaStream_t stream);
|
||||
|
||||
template void init_data_cost(int rows, int cols, float* disp_selected_pyr, float* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, bool use_local_init_data_cost, cudaStream_t stream);
|
||||
template void init_data_cost<float>(const uchar *cleft, const uchar *cright, uchar *ctemp, size_t cimg_step, int rows, int cols, float* disp_selected_pyr, float* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, float data_weight, float max_data_term, int min_disp, bool use_local_init_data_cost, cudaStream_t stream);
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
////////////////////// compute data cost //////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
template <typename T, int channels>
|
||||
__global__ void compute_data_cost(const T* selected_disp_pyr, T* data_cost_, int h, int w, int level, int nr_plane)
|
||||
__global__ void compute_data_cost(const uchar *cleft, const uchar *cright, size_t cimg_step, const T* selected_disp_pyr, T* data_cost_, int h, int w, int level, int nr_plane, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step1, size_t disp_step2)
|
||||
{
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
@@ -412,8 +367,8 @@ namespace cv { namespace cuda { namespace device
|
||||
int x0 = x << level;
|
||||
int xt = (x + 1) << level;
|
||||
|
||||
const T* selected_disparity = selected_disp_pyr + y/2 * cmsg_step + x/2;
|
||||
T* data_cost = data_cost_ + y * cmsg_step + x;
|
||||
const T* selected_disparity = selected_disp_pyr + y/2 * msg_step + x/2;
|
||||
T* data_cost = data_cost_ + y * msg_step + x;
|
||||
|
||||
for(int d = 0; d < nr_plane; d++)
|
||||
{
|
||||
@@ -422,27 +377,27 @@ namespace cv { namespace cuda { namespace device
|
||||
{
|
||||
for(int xi = x0; xi < xt; xi++)
|
||||
{
|
||||
int sel_disp = selected_disparity[d * cdisp_step2];
|
||||
int sel_disp = selected_disparity[d * disp_step2];
|
||||
int xr = xi - sel_disp;
|
||||
|
||||
if (xr < 0 || sel_disp < cth)
|
||||
val += cdata_weight * cmax_data_term;
|
||||
if (xr < 0 || sel_disp < min_disp)
|
||||
val += data_weight * max_data_term;
|
||||
else
|
||||
{
|
||||
const uchar* left_x = cleft + yi * cimg_step + xi * channels;
|
||||
const uchar* right_x = cright + yi * cimg_step + xr * channels;
|
||||
|
||||
val += DataCostPerPixel<channels>::compute(left_x, right_x);
|
||||
val += data_weight * pixeldiff<channels>(left_x, right_x, max_data_term);
|
||||
}
|
||||
}
|
||||
}
|
||||
data_cost[cdisp_step1 * d] = saturate_cast<T>(val);
|
||||
data_cost[disp_step1 * d] = saturate_cast<T>(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, int winsz, int channels>
|
||||
__global__ void compute_data_cost_reduce(const T* selected_disp_pyr, T* data_cost_, int level, int rows, int cols, int h, int nr_plane)
|
||||
__global__ void compute_data_cost_reduce(const uchar *cleft, const uchar *cright, size_t cimg_step, const T* selected_disp_pyr, T* data_cost_, int level, int rows, int cols, int h, int nr_plane, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step1, size_t disp_step2)
|
||||
{
|
||||
int x_out = blockIdx.x;
|
||||
int y_out = blockIdx.y % h;
|
||||
@@ -450,12 +405,12 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
int tid = threadIdx.x;
|
||||
|
||||
const T* selected_disparity = selected_disp_pyr + y_out/2 * cmsg_step + x_out/2;
|
||||
T* data_cost = data_cost_ + y_out * cmsg_step + x_out;
|
||||
const T* selected_disparity = selected_disp_pyr + y_out/2 * msg_step + x_out/2;
|
||||
T* data_cost = data_cost_ + y_out * msg_step + x_out;
|
||||
|
||||
if (d < nr_plane)
|
||||
{
|
||||
int sel_disp = selected_disparity[d * cdisp_step2];
|
||||
int sel_disp = selected_disparity[d * disp_step2];
|
||||
|
||||
int x0 = x_out << level;
|
||||
int y0 = y_out << level;
|
||||
@@ -465,8 +420,8 @@ namespace cv { namespace cuda { namespace device
|
||||
float val = 0.0f;
|
||||
if (x0 + tid < cols)
|
||||
{
|
||||
if (x0 + tid - sel_disp < 0 || sel_disp < cth)
|
||||
val = cdata_weight * cmax_data_term * len;
|
||||
if (x0 + tid - sel_disp < 0 || sel_disp < min_disp)
|
||||
val = data_weight * max_data_term * len;
|
||||
else
|
||||
{
|
||||
const uchar* lle = cleft + y0 * cimg_step + channels * (x0 + tid );
|
||||
@@ -474,7 +429,7 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
for(int y = 0; y < len; ++y)
|
||||
{
|
||||
val += DataCostPerPixel<channels>::compute(lle, lri);
|
||||
val += data_weight * pixeldiff<channels>(lle, lri, max_data_term);
|
||||
|
||||
lle += cimg_step;
|
||||
lri += cimg_step;
|
||||
@@ -487,13 +442,13 @@ namespace cv { namespace cuda { namespace device
|
||||
reduce<winsz>(smem + winsz * threadIdx.z, val, tid, plus<float>());
|
||||
|
||||
if (tid == 0)
|
||||
data_cost[cdisp_step1 * d] = saturate_cast<T>(val);
|
||||
data_cost[disp_step1 * d] = saturate_cast<T>(val);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void compute_data_cost_caller_(const T* disp_selected_pyr, T* data_cost, int /*rows*/, int /*cols*/,
|
||||
int h, int w, int level, int nr_plane, int channels, cudaStream_t stream)
|
||||
void compute_data_cost_caller_(const uchar *cleft, const uchar *cright, size_t cimg_step, const T* disp_selected_pyr, T* data_cost, int /*rows*/, int /*cols*/,
|
||||
int h, int w, int level, int nr_plane, int channels, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step1, size_t disp_step2, cudaStream_t stream)
|
||||
{
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
@@ -503,16 +458,16 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
switch(channels)
|
||||
{
|
||||
case 1: compute_data_cost<T, 1><<<grid, threads, 0, stream>>>(disp_selected_pyr, data_cost, h, w, level, nr_plane); break;
|
||||
case 3: compute_data_cost<T, 3><<<grid, threads, 0, stream>>>(disp_selected_pyr, data_cost, h, w, level, nr_plane); break;
|
||||
case 4: compute_data_cost<T, 4><<<grid, threads, 0, stream>>>(disp_selected_pyr, data_cost, h, w, level, nr_plane); break;
|
||||
case 1: compute_data_cost<T, 1><<<grid, threads, 0, stream>>>(cleft, cright, cimg_step, disp_selected_pyr, data_cost, h, w, level, nr_plane, data_weight, max_data_term, min_disp, msg_step, disp_step1, disp_step2); break;
|
||||
case 3: compute_data_cost<T, 3><<<grid, threads, 0, stream>>>(cleft, cright, cimg_step, disp_selected_pyr, data_cost, h, w, level, nr_plane, data_weight, max_data_term, min_disp, msg_step, disp_step1, disp_step2); break;
|
||||
case 4: compute_data_cost<T, 4><<<grid, threads, 0, stream>>>(cleft, cright, cimg_step, disp_selected_pyr, data_cost, h, w, level, nr_plane, data_weight, max_data_term, min_disp, msg_step, disp_step1, disp_step2); break;
|
||||
default: CV_Error(cv::Error::BadNumChannels, "Unsupported channels count");
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, int winsz>
|
||||
void compute_data_cost_reduce_caller_(const T* disp_selected_pyr, T* data_cost, int rows, int cols,
|
||||
int h, int w, int level, int nr_plane, int channels, cudaStream_t stream)
|
||||
void compute_data_cost_reduce_caller_(const uchar *cleft, const uchar *cright, size_t cimg_step, const T* disp_selected_pyr, T* data_cost, int rows, int cols,
|
||||
int h, int w, int level, int nr_plane, int channels, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step1, size_t disp_step2, cudaStream_t stream)
|
||||
{
|
||||
const int threadsNum = 256;
|
||||
const size_t smem_size = threadsNum * sizeof(float);
|
||||
@@ -523,19 +478,20 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
switch (channels)
|
||||
{
|
||||
case 1: compute_data_cost_reduce<T, winsz, 1><<<grid, threads, smem_size, stream>>>(disp_selected_pyr, data_cost, level, rows, cols, h, nr_plane); break;
|
||||
case 3: compute_data_cost_reduce<T, winsz, 3><<<grid, threads, smem_size, stream>>>(disp_selected_pyr, data_cost, level, rows, cols, h, nr_plane); break;
|
||||
case 4: compute_data_cost_reduce<T, winsz, 4><<<grid, threads, smem_size, stream>>>(disp_selected_pyr, data_cost, level, rows, cols, h, nr_plane); break;
|
||||
case 1: compute_data_cost_reduce<T, winsz, 1><<<grid, threads, smem_size, stream>>>(cleft, cright, cimg_step, disp_selected_pyr, data_cost, level, rows, cols, h, nr_plane, data_weight, max_data_term, min_disp, msg_step, disp_step1, disp_step2); break;
|
||||
case 3: compute_data_cost_reduce<T, winsz, 3><<<grid, threads, smem_size, stream>>>(cleft, cright, cimg_step, disp_selected_pyr, data_cost, level, rows, cols, h, nr_plane, data_weight, max_data_term, min_disp, msg_step, disp_step1, disp_step2); break;
|
||||
case 4: compute_data_cost_reduce<T, winsz, 4><<<grid, threads, smem_size, stream>>>(cleft, cright, cimg_step, disp_selected_pyr, data_cost, level, rows, cols, h, nr_plane, data_weight, max_data_term, min_disp, msg_step, disp_step1, disp_step2); break;
|
||||
default: CV_Error(cv::Error::BadNumChannels, "Unsupported channels count");
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream)
|
||||
void compute_data_cost(const uchar *cleft, const uchar *cright, size_t cimg_step, const T* disp_selected_pyr, T* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, float data_weight, float max_data_term,
|
||||
int min_disp, cudaStream_t stream)
|
||||
{
|
||||
typedef void (*ComputeDataCostCaller)(const T* disp_selected_pyr, T* data_cost, int rows, int cols,
|
||||
int h, int w, int level, int nr_plane, int channels, cudaStream_t stream);
|
||||
typedef void (*ComputeDataCostCaller)(const uchar *cleft, const uchar *cright, size_t cimg_step, const T* disp_selected_pyr, T* data_cost, int rows, int cols,
|
||||
int h, int w, int level, int nr_plane, int channels, float data_weight, float max_data_term, int min_disp, size_t msg_step, size_t disp_step1, size_t disp_step2, cudaStream_t stream);
|
||||
|
||||
static const ComputeDataCostCaller callers[] =
|
||||
{
|
||||
@@ -546,22 +502,19 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
size_t disp_step1 = msg_step * h;
|
||||
size_t disp_step2 = msg_step * h2;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step1, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step2, &disp_step2, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
callers[level](disp_selected_pyr, data_cost, rows, cols, h, w, level, nr_plane, channels, stream);
|
||||
callers[level](cleft, cright, cimg_step, disp_selected_pyr, data_cost, rows, cols, h, w, level, nr_plane, channels, data_weight, max_data_term, min_disp, msg_step, disp_step1, disp_step2, stream);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
template void compute_data_cost(const short* disp_selected_pyr, short* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);
|
||||
template void compute_data_cost(const uchar *cleft, const uchar *cright, size_t cimg_step, const short* disp_selected_pyr, short* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, float data_weight, float max_data_term, int min_disp, cudaStream_t stream);
|
||||
|
||||
template void compute_data_cost(const float* disp_selected_pyr, float* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);
|
||||
template void compute_data_cost(const uchar *cleft, const uchar *cright, size_t cimg_step, const float* disp_selected_pyr, float* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, float data_weight, float max_data_term, int min_disp, cudaStream_t stream);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
@@ -574,7 +527,7 @@ namespace cv { namespace cuda { namespace device
|
||||
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,
|
||||
T* data_cost_selected, T* disparity_selected_new, T* data_cost_new,
|
||||
const T* data_cost_cur, const T* disparity_selected_cur,
|
||||
int nr_plane, int nr_plane2)
|
||||
int nr_plane, int nr_plane2, size_t disp_step1, size_t disp_step2)
|
||||
{
|
||||
for(int i = 0; i < nr_plane; i++)
|
||||
{
|
||||
@@ -582,7 +535,7 @@ namespace cv { namespace cuda { namespace device
|
||||
int id = 0;
|
||||
for(int j = 0; j < nr_plane2; j++)
|
||||
{
|
||||
T cur = data_cost_new[j * cdisp_step1];
|
||||
T cur = data_cost_new[j * disp_step1];
|
||||
if(cur < minimum)
|
||||
{
|
||||
minimum = cur;
|
||||
@@ -590,70 +543,72 @@ namespace cv { namespace cuda { namespace device
|
||||
}
|
||||
}
|
||||
|
||||
data_cost_selected[i * cdisp_step1] = data_cost_cur[id * cdisp_step1];
|
||||
disparity_selected_new[i * cdisp_step1] = disparity_selected_cur[id * cdisp_step2];
|
||||
data_cost_selected[i * disp_step1] = data_cost_cur[id * disp_step1];
|
||||
disparity_selected_new[i * disp_step1] = disparity_selected_cur[id * disp_step2];
|
||||
|
||||
u_new[i * cdisp_step1] = u_cur[id * cdisp_step2];
|
||||
d_new[i * cdisp_step1] = d_cur[id * cdisp_step2];
|
||||
l_new[i * cdisp_step1] = l_cur[id * cdisp_step2];
|
||||
r_new[i * cdisp_step1] = r_cur[id * cdisp_step2];
|
||||
u_new[i * disp_step1] = u_cur[id * disp_step2];
|
||||
d_new[i * disp_step1] = d_cur[id * disp_step2];
|
||||
l_new[i * disp_step1] = l_cur[id * disp_step2];
|
||||
r_new[i * disp_step1] = r_cur[id * disp_step2];
|
||||
|
||||
data_cost_new[id * cdisp_step1] = numeric_limits<T>::max();
|
||||
data_cost_new[id * disp_step1] = numeric_limits<T>::max();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__global__ void init_message(T* u_new_, T* d_new_, T* l_new_, T* r_new_,
|
||||
__global__ void init_message(uchar *ctemp, T* u_new_, T* d_new_, T* l_new_, T* r_new_,
|
||||
const T* u_cur_, const T* d_cur_, const T* l_cur_, const T* r_cur_,
|
||||
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,
|
||||
T* data_cost_selected_, const T* data_cost_,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2)
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2,
|
||||
size_t msg_step, size_t disp_step1, size_t disp_step2)
|
||||
{
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if (y < h && x < w)
|
||||
{
|
||||
const T* u_cur = u_cur_ + ::min(h2-1, y/2 + 1) * cmsg_step + x/2;
|
||||
const T* d_cur = d_cur_ + ::max(0, y/2 - 1) * cmsg_step + x/2;
|
||||
const T* l_cur = l_cur_ + (y/2) * cmsg_step + ::min(w2-1, x/2 + 1);
|
||||
const T* r_cur = r_cur_ + (y/2) * cmsg_step + ::max(0, x/2 - 1);
|
||||
const T* u_cur = u_cur_ + ::min(h2-1, y/2 + 1) * msg_step + x/2;
|
||||
const T* d_cur = d_cur_ + ::max(0, y/2 - 1) * msg_step + x/2;
|
||||
const T* l_cur = l_cur_ + (y/2) * msg_step + ::min(w2-1, x/2 + 1);
|
||||
const T* r_cur = r_cur_ + (y/2) * msg_step + ::max(0, x/2 - 1);
|
||||
|
||||
T* data_cost_new = (T*)ctemp + y * cmsg_step + x;
|
||||
T* data_cost_new = (T*)ctemp + y * msg_step + x;
|
||||
|
||||
const T* disparity_selected_cur = selected_disp_pyr_cur + y/2 * cmsg_step + x/2;
|
||||
const T* data_cost = data_cost_ + y * cmsg_step + x;
|
||||
const T* disparity_selected_cur = selected_disp_pyr_cur + y/2 * msg_step + x/2;
|
||||
const T* data_cost = data_cost_ + y * msg_step + x;
|
||||
|
||||
for(int d = 0; d < nr_plane2; d++)
|
||||
{
|
||||
int idx2 = d * cdisp_step2;
|
||||
int idx2 = d * disp_step2;
|
||||
|
||||
T val = data_cost[d * cdisp_step1] + u_cur[idx2] + d_cur[idx2] + l_cur[idx2] + r_cur[idx2];
|
||||
data_cost_new[d * cdisp_step1] = val;
|
||||
T val = data_cost[d * disp_step1] + u_cur[idx2] + d_cur[idx2] + l_cur[idx2] + r_cur[idx2];
|
||||
data_cost_new[d * disp_step1] = val;
|
||||
}
|
||||
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;
|
||||
T* disparity_selected_new = selected_disp_pyr_new + y * cmsg_step + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * msg_step + x;
|
||||
T* disparity_selected_new = selected_disp_pyr_new + y * msg_step + x;
|
||||
|
||||
T* u_new = u_new_ + y * cmsg_step + x;
|
||||
T* d_new = d_new_ + y * cmsg_step + x;
|
||||
T* l_new = l_new_ + y * cmsg_step + x;
|
||||
T* r_new = r_new_ + y * cmsg_step + x;
|
||||
T* u_new = u_new_ + y * msg_step + x;
|
||||
T* d_new = d_new_ + y * msg_step + x;
|
||||
T* l_new = l_new_ + y * msg_step + x;
|
||||
T* r_new = r_new_ + y * msg_step + x;
|
||||
|
||||
u_cur = u_cur_ + y/2 * cmsg_step + x/2;
|
||||
d_cur = d_cur_ + y/2 * cmsg_step + x/2;
|
||||
l_cur = l_cur_ + y/2 * cmsg_step + x/2;
|
||||
r_cur = r_cur_ + y/2 * cmsg_step + x/2;
|
||||
u_cur = u_cur_ + y/2 * msg_step + x/2;
|
||||
d_cur = d_cur_ + y/2 * msg_step + x/2;
|
||||
l_cur = l_cur_ + y/2 * msg_step + x/2;
|
||||
r_cur = r_cur_ + y/2 * msg_step + x/2;
|
||||
|
||||
get_first_k_element_increase(u_new, d_new, l_new, r_new, u_cur, d_cur, l_cur, r_cur,
|
||||
data_cost_selected, disparity_selected_new, data_cost_new,
|
||||
data_cost, disparity_selected_cur, nr_plane, nr_plane2);
|
||||
data_cost, disparity_selected_cur, nr_plane, nr_plane2,
|
||||
disp_step1, disp_step2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void init_message(T* u_new, T* d_new, T* l_new, T* r_new,
|
||||
void init_message(uchar *ctemp, T* u_new, T* d_new, T* l_new, T* r_new,
|
||||
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,
|
||||
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,
|
||||
T* data_cost_selected, const T* data_cost, size_t msg_step,
|
||||
@@ -662,9 +617,6 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
size_t disp_step1 = msg_step * h;
|
||||
size_t disp_step2 = msg_step * h2;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step1, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step2, &disp_step2, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
@@ -672,11 +624,12 @@ namespace cv { namespace cuda { namespace device
|
||||
grid.x = divUp(w, threads.x);
|
||||
grid.y = divUp(h, threads.y);
|
||||
|
||||
init_message<<<grid, threads, 0, stream>>>(u_new, d_new, l_new, r_new,
|
||||
init_message<<<grid, threads, 0, stream>>>(ctemp, u_new, d_new, l_new, r_new,
|
||||
u_cur, d_cur, l_cur, r_cur,
|
||||
selected_disp_pyr_new, selected_disp_pyr_cur,
|
||||
data_cost_selected, data_cost,
|
||||
h, w, nr_plane, h2, w2, nr_plane2);
|
||||
h, w, nr_plane, h2, w2, nr_plane2,
|
||||
msg_step, disp_step1, disp_step2);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
@@ -684,13 +637,13 @@ namespace cv { namespace cuda { namespace device
|
||||
}
|
||||
|
||||
|
||||
template void init_message(short* u_new, short* d_new, short* l_new, short* r_new,
|
||||
template void init_message(uchar *ctemp, short* u_new, short* d_new, short* l_new, short* r_new,
|
||||
const short* u_cur, const short* d_cur, const short* l_cur, const short* r_cur,
|
||||
short* selected_disp_pyr_new, const short* selected_disp_pyr_cur,
|
||||
short* data_cost_selected, const short* data_cost, size_t msg_step,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);
|
||||
|
||||
template void init_message(float* u_new, float* d_new, float* l_new, float* r_new,
|
||||
template void init_message(uchar *ctemp, float* u_new, float* d_new, float* l_new, float* r_new,
|
||||
const float* u_cur, const float* d_cur, const float* l_cur, const float* r_cur,
|
||||
float* selected_disp_pyr_new, const float* selected_disp_pyr_cur,
|
||||
float* data_cost_selected, const float* data_cost, size_t msg_step,
|
||||
@@ -702,13 +655,14 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
template <typename T>
|
||||
__device__ void message_per_pixel(const T* data, T* msg_dst, const T* msg1, const T* msg2, const T* msg3,
|
||||
const T* dst_disp, const T* src_disp, int nr_plane, volatile T* temp)
|
||||
const T* dst_disp, const T* src_disp, int nr_plane, int max_disc_term, float disc_single_jump, volatile T* temp,
|
||||
size_t disp_step)
|
||||
{
|
||||
T minimum = numeric_limits<T>::max();
|
||||
|
||||
for(int d = 0; d < nr_plane; d++)
|
||||
{
|
||||
int idx = d * cdisp_step1;
|
||||
int idx = d * disp_step;
|
||||
T val = data[idx] + msg1[idx] + msg2[idx] + msg3[idx];
|
||||
|
||||
if(val < minimum)
|
||||
@@ -720,55 +674,53 @@ namespace cv { namespace cuda { namespace device
|
||||
float sum = 0;
|
||||
for(int d = 0; d < nr_plane; d++)
|
||||
{
|
||||
float cost_min = minimum + cmax_disc_term;
|
||||
T src_disp_reg = src_disp[d * cdisp_step1];
|
||||
float cost_min = minimum + max_disc_term;
|
||||
T src_disp_reg = src_disp[d * disp_step];
|
||||
|
||||
for(int d2 = 0; d2 < nr_plane; d2++)
|
||||
cost_min = fmin(cost_min, msg_dst[d2 * cdisp_step1] + cdisc_single_jump * ::abs(dst_disp[d2 * cdisp_step1] - src_disp_reg));
|
||||
cost_min = fmin(cost_min, msg_dst[d2 * disp_step] + disc_single_jump * ::abs(dst_disp[d2 * disp_step] - src_disp_reg));
|
||||
|
||||
temp[d * cdisp_step1] = saturate_cast<T>(cost_min);
|
||||
temp[d * disp_step] = saturate_cast<T>(cost_min);
|
||||
sum += cost_min;
|
||||
}
|
||||
sum /= nr_plane;
|
||||
|
||||
for(int d = 0; d < nr_plane; d++)
|
||||
msg_dst[d * cdisp_step1] = saturate_cast<T>(temp[d * cdisp_step1] - sum);
|
||||
msg_dst[d * disp_step] = saturate_cast<T>(temp[d * disp_step] - sum);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__global__ void compute_message(T* u_, T* d_, T* l_, T* r_, const T* data_cost_selected, const T* selected_disp_pyr_cur, int h, int w, int nr_plane, int i)
|
||||
__global__ void compute_message(uchar *ctemp, T* u_, T* d_, T* l_, T* r_, const T* data_cost_selected, const T* selected_disp_pyr_cur, int h, int w, int nr_plane, int i, int max_disc_term, float disc_single_jump, size_t msg_step, size_t disp_step)
|
||||
{
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
int x = ((blockIdx.x * blockDim.x + threadIdx.x) << 1) + ((y + i) & 1);
|
||||
|
||||
if (y > 0 && y < h - 1 && x > 0 && x < w - 1)
|
||||
{
|
||||
const T* data = data_cost_selected + y * cmsg_step + x;
|
||||
const T* data = data_cost_selected + y * msg_step + x;
|
||||
|
||||
T* u = u_ + y * cmsg_step + x;
|
||||
T* d = d_ + y * cmsg_step + x;
|
||||
T* l = l_ + y * cmsg_step + x;
|
||||
T* r = r_ + y * cmsg_step + x;
|
||||
T* u = u_ + y * msg_step + x;
|
||||
T* d = d_ + y * msg_step + x;
|
||||
T* l = l_ + y * msg_step + x;
|
||||
T* r = r_ + y * msg_step + x;
|
||||
|
||||
const T* disp = selected_disp_pyr_cur + y * cmsg_step + x;
|
||||
const T* disp = selected_disp_pyr_cur + y * msg_step + x;
|
||||
|
||||
T* temp = (T*)ctemp + y * cmsg_step + x;
|
||||
T* temp = (T*)ctemp + y * msg_step + x;
|
||||
|
||||
message_per_pixel(data, u, r - 1, u + cmsg_step, l + 1, disp, disp - cmsg_step, nr_plane, temp);
|
||||
message_per_pixel(data, d, d - cmsg_step, r - 1, l + 1, disp, disp + cmsg_step, nr_plane, temp);
|
||||
message_per_pixel(data, l, u + cmsg_step, d - cmsg_step, l + 1, disp, disp - 1, nr_plane, temp);
|
||||
message_per_pixel(data, r, u + cmsg_step, d - cmsg_step, r - 1, disp, disp + 1, nr_plane, temp);
|
||||
message_per_pixel(data, u, r - 1, u + msg_step, l + 1, disp, disp - msg_step, nr_plane, max_disc_term, disc_single_jump, temp, disp_step);
|
||||
message_per_pixel(data, d, d - msg_step, r - 1, l + 1, disp, disp + msg_step, nr_plane, max_disc_term, disc_single_jump, temp, disp_step);
|
||||
message_per_pixel(data, l, u + msg_step, d - msg_step, l + 1, disp, disp - 1, nr_plane, max_disc_term, disc_single_jump, temp, disp_step);
|
||||
message_per_pixel(data, r, u + msg_step, d - msg_step, r - 1, disp, disp + 1, nr_plane, max_disc_term, disc_single_jump, temp, disp_step);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void calc_all_iterations(T* u, T* d, T* l, T* r, const T* data_cost_selected,
|
||||
const T* selected_disp_pyr_cur, size_t msg_step, int h, int w, int nr_plane, int iters, cudaStream_t stream)
|
||||
void calc_all_iterations(uchar *ctemp, T* u, T* d, T* l, T* r, const T* data_cost_selected,
|
||||
const T* selected_disp_pyr_cur, size_t msg_step, int h, int w, int nr_plane, int iters, int max_disc_term, float disc_single_jump, cudaStream_t stream)
|
||||
{
|
||||
size_t disp_step = msg_step * h;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
@@ -778,18 +730,18 @@ namespace cv { namespace cuda { namespace device
|
||||
|
||||
for(int t = 0; t < iters; ++t)
|
||||
{
|
||||
compute_message<<<grid, threads, 0, stream>>>(u, d, l, r, data_cost_selected, selected_disp_pyr_cur, h, w, nr_plane, t & 1);
|
||||
compute_message<<<grid, threads, 0, stream>>>(ctemp, u, d, l, r, data_cost_selected, selected_disp_pyr_cur, h, w, nr_plane, t & 1, max_disc_term, disc_single_jump, msg_step, disp_step);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
}
|
||||
if (stream == 0)
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
};
|
||||
|
||||
template void calc_all_iterations(short* u, short* d, short* l, short* r, const short* data_cost_selected, const short* selected_disp_pyr_cur, size_t msg_step,
|
||||
int h, int w, int nr_plane, int iters, cudaStream_t stream);
|
||||
template void calc_all_iterations(uchar *ctemp, short* u, short* d, short* l, short* r, const short* data_cost_selected, const short* selected_disp_pyr_cur, size_t msg_step,
|
||||
int h, int w, int nr_plane, int iters, int max_disc_term, float disc_single_jump, cudaStream_t stream);
|
||||
|
||||
template void calc_all_iterations(float* u, float* d, float* l, float* r, const float* data_cost_selected, const float* selected_disp_pyr_cur, size_t msg_step,
|
||||
int h, int w, int nr_plane, int iters, cudaStream_t stream);
|
||||
template void calc_all_iterations(uchar *ctemp, float* u, float* d, float* l, float* r, const float* data_cost_selected, const float* selected_disp_pyr_cur, size_t msg_step,
|
||||
int h, int w, int nr_plane, int iters, int max_disc_term, float disc_single_jump, cudaStream_t stream);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
@@ -800,26 +752,26 @@ namespace cv { namespace cuda { namespace device
|
||||
template <typename T>
|
||||
__global__ void compute_disp(const T* u_, const T* d_, const T* l_, const T* r_,
|
||||
const T* data_cost_selected, const T* disp_selected_pyr,
|
||||
PtrStepSz<short> disp, int nr_plane)
|
||||
PtrStepSz<short> disp, int nr_plane, size_t msg_step, size_t disp_step)
|
||||
{
|
||||
int x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
int y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
if (y > 0 && y < disp.rows - 1 && x > 0 && x < disp.cols - 1)
|
||||
{
|
||||
const T* data = data_cost_selected + y * cmsg_step + x;
|
||||
const T* disp_selected = disp_selected_pyr + y * cmsg_step + x;
|
||||
const T* data = data_cost_selected + y * msg_step + x;
|
||||
const T* disp_selected = disp_selected_pyr + y * msg_step + x;
|
||||
|
||||
const T* u = u_ + (y+1) * cmsg_step + (x+0);
|
||||
const T* d = d_ + (y-1) * cmsg_step + (x+0);
|
||||
const T* l = l_ + (y+0) * cmsg_step + (x+1);
|
||||
const T* r = r_ + (y+0) * cmsg_step + (x-1);
|
||||
const T* u = u_ + (y+1) * msg_step + (x+0);
|
||||
const T* d = d_ + (y-1) * msg_step + (x+0);
|
||||
const T* l = l_ + (y+0) * msg_step + (x+1);
|
||||
const T* r = r_ + (y+0) * msg_step + (x-1);
|
||||
|
||||
int best = 0;
|
||||
T best_val = numeric_limits<T>::max();
|
||||
for (int i = 0; i < nr_plane; ++i)
|
||||
{
|
||||
int idx = i * cdisp_step1;
|
||||
int idx = i * disp_step;
|
||||
T val = data[idx]+ u[idx] + d[idx] + l[idx] + r[idx];
|
||||
|
||||
if (val < best_val)
|
||||
@@ -837,8 +789,6 @@ namespace cv { namespace cuda { namespace device
|
||||
const PtrStepSz<short>& disp, int nr_plane, cudaStream_t stream)
|
||||
{
|
||||
size_t disp_step = disp.rows * msg_step;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
@@ -846,7 +796,7 @@ namespace cv { namespace cuda { namespace device
|
||||
grid.x = divUp(disp.cols, threads.x);
|
||||
grid.y = divUp(disp.rows, threads.y);
|
||||
|
||||
compute_disp<<<grid, threads, 0, stream>>>(u, d, l, r, data_cost_selected, disp_selected, disp, nr_plane);
|
||||
compute_disp<<<grid, threads, 0, stream>>>(u, d, l, r, data_cost_selected, disp_selected, disp, nr_plane, msg_step, disp_step);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
if (stream == 0)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace cv { namespace cuda { namespace device
|
||||
{
|
||||
namespace stereocsbp
|
||||
{
|
||||
template<class T>
|
||||
void init_data_cost(const uchar *left, const uchar *right, uchar *ctemp, size_t cimg_step, int rows, int cols, T* disp_selected_pyr, T* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, float data_weight, float max_data_term, int min_disp, bool use_local_init_data_cost, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void compute_data_cost(const uchar *left, const uchar *right, size_t cimg_step, const T* disp_selected_pyr, T* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, float data_weight, float max_data_term,
|
||||
int min_disp, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void init_message(uchar *ctemp, T* u_new, T* d_new, T* l_new, T* r_new,
|
||||
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,
|
||||
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,
|
||||
T* data_cost_selected, const T* data_cost, size_t msg_step,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void calc_all_iterations(uchar *ctemp, T* u, T* d, T* l, T* r, const T* data_cost_selected,
|
||||
const T* selected_disp_pyr_cur, size_t msg_step, int h, int w, int nr_plane, int iters, int max_disc_term, float disc_single_jump, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void compute_disp(const T* u, const T* d, const T* l, const T* r, const T* data_cost_selected, const T* disp_selected, size_t msg_step,
|
||||
const PtrStepSz<short>& disp, int nr_plane, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
@@ -51,16 +51,7 @@ Ptr<cuda::DisparityBilateralFilter> cv::cuda::createDisparityBilateralFilter(int
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
namespace cv { namespace cuda { namespace device
|
||||
{
|
||||
namespace disp_bilateral_filter
|
||||
{
|
||||
void disp_load_constants(float* table_color, PtrStepSzf table_space, int ndisp, int radius, short edge_disc, short max_disc);
|
||||
|
||||
template<typename T>
|
||||
void disp_bilateral_filter(PtrStepSz<T> disp, PtrStepSzb img, int channels, int iters, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
#include "cuda/disparity_bilateral_filter.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -165,7 +156,7 @@ namespace
|
||||
const short edge_disc = std::max<short>(short(1), short(ndisp * edge_threshold + 0.5));
|
||||
const short max_disc = short(ndisp * max_disc_threshold + 0.5);
|
||||
|
||||
disp_load_constants(table_color.ptr<float>(), table_space, ndisp, radius, edge_disc, max_disc);
|
||||
size_t table_space_step = table_space.step / sizeof(float);
|
||||
|
||||
_dst.create(disp.size(), disp.type());
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
@@ -173,7 +164,7 @@ namespace
|
||||
if (dst.data != disp.data)
|
||||
disp.copyTo(dst, stream);
|
||||
|
||||
disp_bilateral_filter<T>(dst, img, img.channels(), iters, StreamAccessor::getStream(stream));
|
||||
disp_bilateral_filter<T>(dst, img, img.channels(), iters, table_color.ptr<float>(), (float *)table_space.data, table_space_step, radius, edge_disc, max_disc, StreamAccessor::getStream(stream));
|
||||
}
|
||||
|
||||
void DispBilateralFilterImpl::apply(InputArray _disp, InputArray _image, OutputArray dst, Stream& stream)
|
||||
|
||||
@@ -53,37 +53,7 @@ Ptr<cuda::StereoConstantSpaceBP> cv::cuda::createStereoConstantSpaceBP(int, int,
|
||||
|
||||
#else /* !defined (HAVE_CUDA) */
|
||||
|
||||
namespace cv { namespace cuda { namespace device
|
||||
{
|
||||
namespace stereocsbp
|
||||
{
|
||||
void load_constants(int ndisp, float max_data_term, float data_weight, float max_disc_term, float disc_single_jump, int min_disp_th,
|
||||
const PtrStepSzb& left, const PtrStepSzb& right, const PtrStepSzb& temp);
|
||||
|
||||
template<class T>
|
||||
void init_data_cost(int rows, int cols, T* disp_selected_pyr, T* data_cost_selected, size_t msg_step,
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, bool use_local_init_data_cost, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void init_message(T* u_new, T* d_new, T* l_new, T* r_new,
|
||||
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,
|
||||
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,
|
||||
T* data_cost_selected, const T* data_cost, size_t msg_step,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void calc_all_iterations(T* u, T* d, T* l, T* r, const T* data_cost_selected,
|
||||
const T* selected_disp_pyr_cur, size_t msg_step, int h, int w, int nr_plane, int iters, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void compute_disp(const T* u, const T* d, const T* l, const T* r, const T* data_cost_selected, const T* disp_selected, size_t msg_step,
|
||||
const PtrStepSz<short>& disp, int nr_plane, cudaStream_t stream);
|
||||
}
|
||||
}}}
|
||||
#include "cuda/stereocsbp.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -252,8 +222,6 @@ namespace
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Compute
|
||||
|
||||
load_constants(ndisp_, max_data_term_, data_weight_, max_disc_term_, disc_single_jump_, min_disp_th_, left, right, temp_);
|
||||
|
||||
l[0].setTo(0, _stream);
|
||||
d[0].setTo(0, _stream);
|
||||
r[0].setTo(0, _stream);
|
||||
@@ -275,17 +243,18 @@ namespace
|
||||
{
|
||||
if (i == levels_ - 1)
|
||||
{
|
||||
init_data_cost(left.rows, left.cols, disp_selected_pyr[cur_idx].ptr<float>(), data_cost_selected.ptr<float>(),
|
||||
elem_step, rows_pyr[i], cols_pyr[i], i, nr_plane_pyr[i], ndisp_, left.channels(), use_local_init_data_cost_, stream);
|
||||
init_data_cost(left.ptr<uchar>(), right.ptr<uchar>(), temp_.ptr<uchar>(), left.step, left.rows, left.cols, disp_selected_pyr[cur_idx].ptr<float>(), data_cost_selected.ptr<float>(),
|
||||
elem_step, rows_pyr[i], cols_pyr[i], i, nr_plane_pyr[i], ndisp_, left.channels(), data_weight_, max_data_term_, min_disp_th_, use_local_init_data_cost_, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
compute_data_cost(disp_selected_pyr[cur_idx].ptr<float>(), data_cost.ptr<float>(), elem_step,
|
||||
left.rows, left.cols, rows_pyr[i], cols_pyr[i], rows_pyr[i+1], i, nr_plane_pyr[i+1], left.channels(), stream);
|
||||
compute_data_cost(left.ptr<uchar>(), right.ptr<uchar>(), left.step, disp_selected_pyr[cur_idx].ptr<float>(), data_cost.ptr<float>(), elem_step,
|
||||
left.rows, left.cols, rows_pyr[i], cols_pyr[i], rows_pyr[i+1], i, nr_plane_pyr[i+1], left.channels(), data_weight_, max_data_term_, min_disp_th_, stream);
|
||||
|
||||
int new_idx = (cur_idx + 1) & 1;
|
||||
|
||||
init_message(u[new_idx].ptr<float>(), d[new_idx].ptr<float>(), l[new_idx].ptr<float>(), r[new_idx].ptr<float>(),
|
||||
init_message(temp_.ptr<uchar>(),
|
||||
u[new_idx].ptr<float>(), d[new_idx].ptr<float>(), l[new_idx].ptr<float>(), r[new_idx].ptr<float>(),
|
||||
u[cur_idx].ptr<float>(), d[cur_idx].ptr<float>(), l[cur_idx].ptr<float>(), r[cur_idx].ptr<float>(),
|
||||
disp_selected_pyr[new_idx].ptr<float>(), disp_selected_pyr[cur_idx].ptr<float>(),
|
||||
data_cost_selected.ptr<float>(), data_cost.ptr<float>(), elem_step, rows_pyr[i],
|
||||
@@ -294,9 +263,9 @@ namespace
|
||||
cur_idx = new_idx;
|
||||
}
|
||||
|
||||
calc_all_iterations(u[cur_idx].ptr<float>(), d[cur_idx].ptr<float>(), l[cur_idx].ptr<float>(), r[cur_idx].ptr<float>(),
|
||||
calc_all_iterations(temp_.ptr<uchar>(), u[cur_idx].ptr<float>(), d[cur_idx].ptr<float>(), l[cur_idx].ptr<float>(), r[cur_idx].ptr<float>(),
|
||||
data_cost_selected.ptr<float>(), disp_selected_pyr[cur_idx].ptr<float>(), elem_step,
|
||||
rows_pyr[i], cols_pyr[i], nr_plane_pyr[i], iters_, stream);
|
||||
rows_pyr[i], cols_pyr[i], nr_plane_pyr[i], iters_, max_disc_term_, disc_single_jump_, stream);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -305,17 +274,18 @@ namespace
|
||||
{
|
||||
if (i == levels_ - 1)
|
||||
{
|
||||
init_data_cost(left.rows, left.cols, disp_selected_pyr[cur_idx].ptr<short>(), data_cost_selected.ptr<short>(),
|
||||
elem_step, rows_pyr[i], cols_pyr[i], i, nr_plane_pyr[i], ndisp_, left.channels(), use_local_init_data_cost_, stream);
|
||||
init_data_cost(left.ptr<uchar>(), right.ptr<uchar>(), temp_.ptr<uchar>(), left.step, left.rows, left.cols, disp_selected_pyr[cur_idx].ptr<short>(), data_cost_selected.ptr<short>(),
|
||||
elem_step, rows_pyr[i], cols_pyr[i], i, nr_plane_pyr[i], ndisp_, left.channels(), data_weight_, max_data_term_, min_disp_th_, use_local_init_data_cost_, stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
compute_data_cost(disp_selected_pyr[cur_idx].ptr<short>(), data_cost.ptr<short>(), elem_step,
|
||||
left.rows, left.cols, rows_pyr[i], cols_pyr[i], rows_pyr[i+1], i, nr_plane_pyr[i+1], left.channels(), stream);
|
||||
compute_data_cost(left.ptr<uchar>(), right.ptr<uchar>(), left.step, disp_selected_pyr[cur_idx].ptr<short>(), data_cost.ptr<short>(), elem_step,
|
||||
left.rows, left.cols, rows_pyr[i], cols_pyr[i], rows_pyr[i+1], i, nr_plane_pyr[i+1], left.channels(), data_weight_, max_data_term_, min_disp_th_, stream);
|
||||
|
||||
int new_idx = (cur_idx + 1) & 1;
|
||||
|
||||
init_message(u[new_idx].ptr<short>(), d[new_idx].ptr<short>(), l[new_idx].ptr<short>(), r[new_idx].ptr<short>(),
|
||||
init_message(temp_.ptr<uchar>(),
|
||||
u[new_idx].ptr<short>(), d[new_idx].ptr<short>(), l[new_idx].ptr<short>(), r[new_idx].ptr<short>(),
|
||||
u[cur_idx].ptr<short>(), d[cur_idx].ptr<short>(), l[cur_idx].ptr<short>(), r[cur_idx].ptr<short>(),
|
||||
disp_selected_pyr[new_idx].ptr<short>(), disp_selected_pyr[cur_idx].ptr<short>(),
|
||||
data_cost_selected.ptr<short>(), data_cost.ptr<short>(), elem_step, rows_pyr[i],
|
||||
@@ -324,9 +294,9 @@ namespace
|
||||
cur_idx = new_idx;
|
||||
}
|
||||
|
||||
calc_all_iterations(u[cur_idx].ptr<short>(), d[cur_idx].ptr<short>(), l[cur_idx].ptr<short>(), r[cur_idx].ptr<short>(),
|
||||
calc_all_iterations(temp_.ptr<uchar>(), u[cur_idx].ptr<short>(), d[cur_idx].ptr<short>(), l[cur_idx].ptr<short>(), r[cur_idx].ptr<short>(),
|
||||
data_cost_selected.ptr<short>(), disp_selected_pyr[cur_idx].ptr<short>(), elem_step,
|
||||
rows_pyr[i], cols_pyr[i], nr_plane_pyr[i], iters_, stream);
|
||||
rows_pyr[i], cols_pyr[i], nr_plane_pyr[i], iters_, max_disc_term_, disc_single_jump_, stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
set(test_deps opencv_cudev opencv_core opencv_imgproc opencv_highgui opencv_ts ${OPENCV_MODULE_opencv_ts_DEPS})
|
||||
set(test_deps opencv_cudev opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui opencv_ts ${OPENCV_MODULE_opencv_ts_DEPS})
|
||||
|
||||
ocv_check_dependencies(${test_deps})
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ Detects corners using the FAST algorithm
|
||||
|
||||
Detects corners using the FAST algorithm by [Rosten06]_.
|
||||
|
||||
..note:: In Python API, types are given as ``cv2.FAST_FEATURE_DETECTOR_TYPE_5_8``, ``cv2.FAST_FEATURE_DETECTOR_TYPE_7_12`` and ``cv2.FAST_FEATURE_DETECTOR_TYPE_9_16``. For corner detection, use ``cv2.FAST.detect()`` method.
|
||||
.. note:: In Python API, types are given as ``cv2.FAST_FEATURE_DETECTOR_TYPE_5_8``, ``cv2.FAST_FEATURE_DETECTOR_TYPE_7_12`` and ``cv2.FAST_FEATURE_DETECTOR_TYPE_9_16``. For corner detection, use ``cv2.FAST.detect()`` method.
|
||||
|
||||
|
||||
.. [Rosten06] E. Rosten. Machine Learning for High-speed Corner Detection, 2006.
|
||||
@@ -254,7 +254,17 @@ KAZE
|
||||
----
|
||||
.. ocv:class:: KAZE : public Feature2D
|
||||
|
||||
Class implementing the KAZE keypoint detector and descriptor extractor, described in [ABD12]_.
|
||||
Class implementing the KAZE keypoint detector and descriptor extractor, described in [ABD12]_. ::
|
||||
|
||||
class CV_EXPORTS_W KAZE : public Feature2D
|
||||
{
|
||||
public:
|
||||
CV_WRAP KAZE();
|
||||
CV_WRAP explicit KAZE(bool extended, bool upright, float threshold = 0.001f,
|
||||
int octaves = 4, int sublevels = 4, int diffusivity = DIFF_PM_G2);
|
||||
};
|
||||
|
||||
.. note:: AKAZE descriptor can only be used with KAZE or AKAZE keypoints
|
||||
|
||||
.. [ABD12] KAZE Features. Pablo F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. In European Conference on Computer Vision (ECCV), Fiorenze, Italy, October 2012.
|
||||
|
||||
@@ -262,12 +272,14 @@ KAZE::KAZE
|
||||
----------
|
||||
The KAZE constructor
|
||||
|
||||
.. ocv:function:: KAZE::KAZE(bool extended, bool upright)
|
||||
.. ocv:function:: KAZE::KAZE(bool extended, bool upright, float threshold, int octaves, int sublevels, int diffusivity)
|
||||
|
||||
:param extended: Set to enable extraction of extended (128-byte) descriptor.
|
||||
:param upright: Set to enable use of upright descriptors (non rotation-invariant).
|
||||
|
||||
|
||||
:param threshold: Detector response threshold to accept point
|
||||
:param octaves: Maximum octave evolution of the image
|
||||
:param sublevels: Default number of sublevels per scale level
|
||||
:param diffusivity: Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or DIFF_CHARBONNIER
|
||||
|
||||
AKAZE
|
||||
-----
|
||||
@@ -278,25 +290,25 @@ Class implementing the AKAZE keypoint detector and descriptor extractor, describ
|
||||
class CV_EXPORTS_W AKAZE : public Feature2D
|
||||
{
|
||||
public:
|
||||
/// AKAZE Descriptor Type
|
||||
enum DESCRIPTOR_TYPE {
|
||||
DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation
|
||||
DESCRIPTOR_KAZE = 3,
|
||||
DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation
|
||||
DESCRIPTOR_MLDB = 5
|
||||
};
|
||||
CV_WRAP AKAZE();
|
||||
explicit AKAZE(DESCRIPTOR_TYPE descriptor_type, int descriptor_size = 0, int descriptor_channels = 3);
|
||||
CV_WRAP explicit AKAZE(int descriptor_type, int descriptor_size = 0, int descriptor_channels = 3,
|
||||
float threshold = 0.001f, int octaves = 4, int sublevels = 4, int diffusivity = DIFF_PM_G2);
|
||||
};
|
||||
|
||||
.. note:: AKAZE descriptor can only be used with KAZE or AKAZE keypoints
|
||||
|
||||
.. [ANB13] Fast Explicit Diffusion for Accelerated Features in Nonlinear Scale Spaces. Pablo F. Alcantarilla, Jesús Nuevo and Adrien Bartoli. In British Machine Vision Conference (BMVC), Bristol, UK, September 2013.
|
||||
|
||||
AKAZE::AKAZE
|
||||
------------
|
||||
The AKAZE constructor
|
||||
|
||||
.. ocv:function:: AKAZE::AKAZE(DESCRIPTOR_TYPE descriptor_type, int descriptor_size = 0, int descriptor_channels = 3)
|
||||
.. ocv:function:: AKAZE::AKAZE(int descriptor_type, int descriptor_size, int descriptor_channels, float threshold, int octaves, int sublevels, int diffusivity)
|
||||
|
||||
:param descriptor_type: Type of the extracted descriptor.
|
||||
:param descriptor_type: Type of the extracted descriptor: DESCRIPTOR_KAZE, DESCRIPTOR_KAZE_UPRIGHT, DESCRIPTOR_MLDB or DESCRIPTOR_MLDB_UPRIGHT.
|
||||
:param descriptor_size: Size of the descriptor in bits. 0 -> Full size
|
||||
:param descriptor_channels: Number of channels in the descriptor (1, 2, 3).
|
||||
:param descriptor_channels: Number of channels in the descriptor (1, 2, 3)
|
||||
:param threshold: Detector response threshold to accept point
|
||||
:param octaves: Maximum octave evolution of the image
|
||||
:param sublevels: Default number of sublevels per scale level
|
||||
:param diffusivity: Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or DIFF_CHARBONNIER
|
||||
|
||||
@@ -895,6 +895,22 @@ protected:
|
||||
PixelTestFn test_fn_;
|
||||
};
|
||||
|
||||
// KAZE/AKAZE diffusivity
|
||||
enum {
|
||||
DIFF_PM_G1 = 0,
|
||||
DIFF_PM_G2 = 1,
|
||||
DIFF_WEICKERT = 2,
|
||||
DIFF_CHARBONNIER = 3
|
||||
};
|
||||
|
||||
// AKAZE descriptor type
|
||||
enum {
|
||||
DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation
|
||||
DESCRIPTOR_KAZE = 3,
|
||||
DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation
|
||||
DESCRIPTOR_MLDB = 5
|
||||
};
|
||||
|
||||
/*!
|
||||
KAZE implementation
|
||||
*/
|
||||
@@ -902,7 +918,8 @@ class CV_EXPORTS_W KAZE : public Feature2D
|
||||
{
|
||||
public:
|
||||
CV_WRAP KAZE();
|
||||
CV_WRAP explicit KAZE(bool extended, bool upright);
|
||||
CV_WRAP explicit KAZE(bool extended, bool upright, float threshold = 0.001f,
|
||||
int octaves = 4, int sublevels = 4, int diffusivity = DIFF_PM_G2);
|
||||
|
||||
virtual ~KAZE();
|
||||
|
||||
@@ -928,6 +945,10 @@ protected:
|
||||
|
||||
CV_PROP bool extended;
|
||||
CV_PROP bool upright;
|
||||
CV_PROP float threshold;
|
||||
CV_PROP int octaves;
|
||||
CV_PROP int sublevels;
|
||||
CV_PROP int diffusivity;
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -936,16 +957,9 @@ AKAZE implementation
|
||||
class CV_EXPORTS_W AKAZE : public Feature2D
|
||||
{
|
||||
public:
|
||||
/// AKAZE Descriptor Type
|
||||
enum DESCRIPTOR_TYPE {
|
||||
DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation
|
||||
DESCRIPTOR_KAZE = 3,
|
||||
DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation
|
||||
DESCRIPTOR_MLDB = 5
|
||||
};
|
||||
|
||||
CV_WRAP AKAZE();
|
||||
explicit AKAZE(DESCRIPTOR_TYPE descriptor_type, int descriptor_size = 0, int descriptor_channels = 3);
|
||||
CV_WRAP explicit AKAZE(int descriptor_type, int descriptor_size = 0, int descriptor_channels = 3,
|
||||
float threshold = 0.001f, int octaves = 4, int sublevels = 4, int diffusivity = DIFF_PM_G2);
|
||||
|
||||
virtual ~AKAZE();
|
||||
|
||||
@@ -973,7 +987,10 @@ protected:
|
||||
CV_PROP int descriptor;
|
||||
CV_PROP int descriptor_channels;
|
||||
CV_PROP int descriptor_size;
|
||||
|
||||
CV_PROP float threshold;
|
||||
CV_PROP int octaves;
|
||||
CV_PROP int sublevels;
|
||||
CV_PROP int diffusivity;
|
||||
};
|
||||
/****************************************************************************************\
|
||||
* Distance *
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#define __OPENCV_PERF_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/features2d.hpp"
|
||||
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
|
||||
@@ -49,7 +49,10 @@ http://www.robesafe.com/personal/pablo.alcantarilla/papers/Alcantarilla13bmvc.pd
|
||||
*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "akaze/AKAZEFeatures.h"
|
||||
#include "kaze/AKAZEFeatures.h"
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -57,13 +60,22 @@ namespace cv
|
||||
: descriptor(DESCRIPTOR_MLDB)
|
||||
, descriptor_channels(3)
|
||||
, descriptor_size(0)
|
||||
, threshold(0.001f)
|
||||
, octaves(4)
|
||||
, sublevels(4)
|
||||
, diffusivity(DIFF_PM_G2)
|
||||
{
|
||||
}
|
||||
|
||||
AKAZE::AKAZE(DESCRIPTOR_TYPE _descriptor_type, int _descriptor_size, int _descriptor_channels)
|
||||
AKAZE::AKAZE(int _descriptor_type, int _descriptor_size, int _descriptor_channels,
|
||||
float _threshold, int _octaves, int _sublevels, int _diffusivity)
|
||||
: descriptor(_descriptor_type)
|
||||
, descriptor_channels(_descriptor_channels)
|
||||
, descriptor_size(_descriptor_size)
|
||||
, threshold(_threshold)
|
||||
, octaves(_octaves)
|
||||
, sublevels(_sublevels)
|
||||
, diffusivity(_diffusivity)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -78,12 +90,12 @@ namespace cv
|
||||
{
|
||||
switch (descriptor)
|
||||
{
|
||||
case cv::AKAZE::DESCRIPTOR_KAZE:
|
||||
case cv::AKAZE::DESCRIPTOR_KAZE_UPRIGHT:
|
||||
case cv::DESCRIPTOR_KAZE:
|
||||
case cv::DESCRIPTOR_KAZE_UPRIGHT:
|
||||
return 64;
|
||||
|
||||
case cv::AKAZE::DESCRIPTOR_MLDB:
|
||||
case cv::AKAZE::DESCRIPTOR_MLDB_UPRIGHT:
|
||||
case cv::DESCRIPTOR_MLDB:
|
||||
case cv::DESCRIPTOR_MLDB_UPRIGHT:
|
||||
// We use the full length binary descriptor -> 486 bits
|
||||
if (descriptor_size == 0)
|
||||
{
|
||||
@@ -106,12 +118,12 @@ namespace cv
|
||||
{
|
||||
switch (descriptor)
|
||||
{
|
||||
case cv::AKAZE::DESCRIPTOR_KAZE:
|
||||
case cv::AKAZE::DESCRIPTOR_KAZE_UPRIGHT:
|
||||
case cv::DESCRIPTOR_KAZE:
|
||||
case cv::DESCRIPTOR_KAZE_UPRIGHT:
|
||||
return CV_32F;
|
||||
|
||||
case cv::AKAZE::DESCRIPTOR_MLDB:
|
||||
case cv::AKAZE::DESCRIPTOR_MLDB_UPRIGHT:
|
||||
case cv::DESCRIPTOR_MLDB:
|
||||
case cv::DESCRIPTOR_MLDB_UPRIGHT:
|
||||
return CV_8U;
|
||||
|
||||
default:
|
||||
@@ -124,12 +136,12 @@ namespace cv
|
||||
{
|
||||
switch (descriptor)
|
||||
{
|
||||
case cv::AKAZE::DESCRIPTOR_KAZE:
|
||||
case cv::AKAZE::DESCRIPTOR_KAZE_UPRIGHT:
|
||||
case cv::DESCRIPTOR_KAZE:
|
||||
case cv::DESCRIPTOR_KAZE_UPRIGHT:
|
||||
return cv::NORM_L2;
|
||||
|
||||
case cv::AKAZE::DESCRIPTOR_MLDB:
|
||||
case cv::AKAZE::DESCRIPTOR_MLDB_UPRIGHT:
|
||||
case cv::DESCRIPTOR_MLDB:
|
||||
case cv::DESCRIPTOR_MLDB_UPRIGHT:
|
||||
return cv::NORM_HAMMING;
|
||||
|
||||
default:
|
||||
@@ -153,11 +165,15 @@ namespace cv
|
||||
cv::Mat& desc = descriptors.getMatRef();
|
||||
|
||||
AKAZEOptions options;
|
||||
options.descriptor = static_cast<DESCRIPTOR_TYPE>(descriptor);
|
||||
options.descriptor = descriptor;
|
||||
options.descriptor_channels = descriptor_channels;
|
||||
options.descriptor_size = descriptor_size;
|
||||
options.img_width = img.cols;
|
||||
options.img_height = img.rows;
|
||||
options.dthreshold = threshold;
|
||||
options.omax = octaves;
|
||||
options.nsublevels = sublevels;
|
||||
options.diffusivity = diffusivity;
|
||||
|
||||
AKAZEFeatures impl(options);
|
||||
impl.Create_Nonlinear_Scale_Space(img1_32);
|
||||
@@ -188,7 +204,7 @@ namespace cv
|
||||
img.convertTo(img1_32, CV_32F, 1.0 / 255.0, 0);
|
||||
|
||||
AKAZEOptions options;
|
||||
options.descriptor = static_cast<DESCRIPTOR_TYPE>(descriptor);
|
||||
options.descriptor = descriptor;
|
||||
options.descriptor_channels = descriptor_channels;
|
||||
options.descriptor_size = descriptor_size;
|
||||
options.img_width = img.cols;
|
||||
@@ -216,7 +232,7 @@ namespace cv
|
||||
cv::Mat& desc = descriptors.getMatRef();
|
||||
|
||||
AKAZEOptions options;
|
||||
options.descriptor = static_cast<DESCRIPTOR_TYPE>(descriptor);
|
||||
options.descriptor = descriptor;
|
||||
options.descriptor_channels = descriptor_channels;
|
||||
options.descriptor_size = descriptor_size;
|
||||
options.img_width = img.cols;
|
||||
@@ -229,4 +245,4 @@ namespace cv
|
||||
CV_Assert((!desc.rows || desc.cols == descriptorSize()));
|
||||
CV_Assert((!desc.rows || (desc.type() == descriptorType())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* @file AKAZE.h
|
||||
* @brief Main class for detecting and computing binary descriptors in an
|
||||
* accelerated nonlinear scale space
|
||||
* @date Mar 27, 2013
|
||||
* @author Pablo F. Alcantarilla, Jesus Nuevo
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/* ************************************************************************* */
|
||||
// Includes
|
||||
#include "precomp.hpp"
|
||||
#include "AKAZEConfig.h"
|
||||
|
||||
/* ************************************************************************* */
|
||||
// AKAZE Class Declaration
|
||||
class AKAZEFeatures {
|
||||
|
||||
private:
|
||||
|
||||
AKAZEOptions options_; ///< Configuration options for AKAZE
|
||||
std::vector<TEvolution> evolution_; ///< Vector of nonlinear diffusion evolution
|
||||
|
||||
/// FED parameters
|
||||
int ncycles_; ///< Number of cycles
|
||||
bool reordering_; ///< Flag for reordering time steps
|
||||
std::vector<std::vector<float > > tsteps_; ///< Vector of FED dynamic time steps
|
||||
std::vector<int> nsteps_; ///< Vector of number of steps per cycle
|
||||
|
||||
/// Matrices for the M-LDB descriptor computation
|
||||
cv::Mat descriptorSamples_; // List of positions in the grids to sample LDB bits from.
|
||||
cv::Mat descriptorBits_;
|
||||
cv::Mat bitMask_;
|
||||
|
||||
public:
|
||||
|
||||
/// Constructor with input arguments
|
||||
AKAZEFeatures(const AKAZEOptions& options);
|
||||
|
||||
/// Scale Space methods
|
||||
void Allocate_Memory_Evolution();
|
||||
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
|
||||
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
|
||||
void Compute_Determinant_Hessian_Response(void);
|
||||
void Compute_Multiscale_Derivatives(void);
|
||||
void Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts);
|
||||
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
|
||||
|
||||
// Feature description methods
|
||||
void Compute_Descriptors(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
|
||||
|
||||
static void Compute_Main_Orientation(cv::KeyPoint& kpt, const std::vector<TEvolution>& evolution_);
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
// Inline functions
|
||||
|
||||
// Inline functions
|
||||
void generateDescriptorSubsample(cv::Mat& sampleList, cv::Mat& comparisons,
|
||||
int nbits, int pattern_size, int nchannels);
|
||||
float get_angle(float x, float y);
|
||||
float gaussian(float x, float y, float sigma);
|
||||
void check_descriptor_limits(int& x, int& y, int width, int height);
|
||||
int fRound(float flt);
|
||||
@@ -55,12 +55,21 @@ namespace cv
|
||||
KAZE::KAZE()
|
||||
: extended(false)
|
||||
, upright(false)
|
||||
, threshold(0.001f)
|
||||
, octaves(4)
|
||||
, sublevels(4)
|
||||
, diffusivity(DIFF_PM_G2)
|
||||
{
|
||||
}
|
||||
|
||||
KAZE::KAZE(bool _extended, bool _upright)
|
||||
KAZE::KAZE(bool _extended, bool _upright, float _threshold, int _octaves,
|
||||
int _sublevels, int _diffusivity)
|
||||
: extended(_extended)
|
||||
, upright(_upright)
|
||||
, threshold(_threshold)
|
||||
, octaves(_octaves)
|
||||
, sublevels(_sublevels)
|
||||
, diffusivity(_diffusivity)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -111,6 +120,10 @@ namespace cv
|
||||
options.img_height = img.rows;
|
||||
options.extended = extended;
|
||||
options.upright = upright;
|
||||
options.dthreshold = threshold;
|
||||
options.omax = octaves;
|
||||
options.nsublevels = sublevels;
|
||||
options.diffusivity = diffusivity;
|
||||
|
||||
KAZEFeatures impl(options);
|
||||
impl.Create_Nonlinear_Scale_Space(img1_32);
|
||||
@@ -180,4 +193,4 @@ namespace cv
|
||||
CV_Assert((!desc.rows || desc.cols == descriptorSize()));
|
||||
CV_Assert((!desc.rows || (desc.type() == descriptorType())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-38
@@ -5,7 +5,8 @@
|
||||
* @author Pablo F. Alcantarilla, Jesus Nuevo
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __OPENCV_FEATURES_2D_AKAZE_CONFIG_H__
|
||||
#define __OPENCV_FEATURES_2D_AKAZE_CONFIG_H__
|
||||
|
||||
/* ************************************************************************* */
|
||||
// OpenCV
|
||||
@@ -28,14 +29,6 @@ const float gauss25[7][7] = {
|
||||
/// AKAZE configuration options structure
|
||||
struct AKAZEOptions {
|
||||
|
||||
/// AKAZE Diffusivities
|
||||
enum DIFFUSIVITY_TYPE {
|
||||
PM_G1 = 0,
|
||||
PM_G2 = 1,
|
||||
WEICKERT = 2,
|
||||
CHARBONNIER = 3
|
||||
};
|
||||
|
||||
AKAZEOptions()
|
||||
: omax(4)
|
||||
, nsublevels(4)
|
||||
@@ -44,12 +37,12 @@ struct AKAZEOptions {
|
||||
, soffset(1.6f)
|
||||
, derivative_factor(1.5f)
|
||||
, sderivatives(1.0)
|
||||
, diffusivity(PM_G2)
|
||||
, diffusivity(cv::DIFF_PM_G2)
|
||||
|
||||
, dthreshold(0.001f)
|
||||
, min_dthreshold(0.00001f)
|
||||
|
||||
, descriptor(cv::AKAZE::DESCRIPTOR_MLDB)
|
||||
, descriptor(cv::DESCRIPTOR_MLDB)
|
||||
, descriptor_size(0)
|
||||
, descriptor_channels(3)
|
||||
, descriptor_pattern_size(10)
|
||||
@@ -67,12 +60,12 @@ struct AKAZEOptions {
|
||||
float soffset; ///< Base scale offset (sigma units)
|
||||
float derivative_factor; ///< Factor for the multiscale derivatives
|
||||
float sderivatives; ///< Smoothing factor for the derivatives
|
||||
DIFFUSIVITY_TYPE diffusivity; ///< Diffusivity type
|
||||
int diffusivity; ///< Diffusivity type
|
||||
|
||||
float dthreshold; ///< Detector response threshold to accept point
|
||||
float min_dthreshold; ///< Minimum detector threshold to accept a point
|
||||
|
||||
cv::AKAZE::DESCRIPTOR_TYPE descriptor; ///< Type of descriptor
|
||||
int descriptor; ///< Type of descriptor
|
||||
int descriptor_size; ///< Size of the descriptor in bits. 0->Full size
|
||||
int descriptor_channels; ///< Number of channels in the descriptor (1, 2, 3)
|
||||
int descriptor_pattern_size; ///< Actual patch size is 2*pattern_size*point.scale
|
||||
@@ -82,28 +75,4 @@ struct AKAZEOptions {
|
||||
int kcontrast_nbins; ///< Number of bins for the contrast factor histogram
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
/// AKAZE nonlinear diffusion filtering evolution
|
||||
struct TEvolution {
|
||||
|
||||
TEvolution() {
|
||||
etime = 0.0f;
|
||||
esigma = 0.0f;
|
||||
octave = 0;
|
||||
sublevel = 0;
|
||||
sigma_size = 0;
|
||||
}
|
||||
|
||||
cv::Mat Lx, Ly; // First order spatial derivatives
|
||||
cv::Mat Lxx, Lxy, Lyy; // Second order spatial derivatives
|
||||
cv::Mat Lflow; // Diffusivity image
|
||||
cv::Mat Lt; // Evolution image
|
||||
cv::Mat Lsmooth; // Smoothed image
|
||||
cv::Mat Lstep; // Evolution step update
|
||||
cv::Mat Ldet; // Detector response
|
||||
float etime; // Evolution time
|
||||
float esigma; // Evolution sigma. For linear diffusion t = sigma^2 / 2
|
||||
size_t octave; // Image octave
|
||||
size_t sublevel; // Image sublevel in each octave
|
||||
size_t sigma_size; // Integer sigma. For computing the feature detector responses
|
||||
};
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @file AKAZE.h
|
||||
* @brief Main class for detecting and computing binary descriptors in an
|
||||
* accelerated nonlinear scale space
|
||||
* @date Mar 27, 2013
|
||||
* @author Pablo F. Alcantarilla, Jesus Nuevo
|
||||
*/
|
||||
|
||||
#ifndef __OPENCV_FEATURES_2D_AKAZE_FEATURES_H__
|
||||
#define __OPENCV_FEATURES_2D_AKAZE_FEATURES_H__
|
||||
|
||||
/* ************************************************************************* */
|
||||
// Includes
|
||||
#include "precomp.hpp"
|
||||
#include "AKAZEConfig.h"
|
||||
#include "TEvolution.h"
|
||||
|
||||
/* ************************************************************************* */
|
||||
// AKAZE Class Declaration
|
||||
class AKAZEFeatures {
|
||||
|
||||
private:
|
||||
|
||||
AKAZEOptions options_; ///< Configuration options for AKAZE
|
||||
std::vector<TEvolution> evolution_; ///< Vector of nonlinear diffusion evolution
|
||||
|
||||
/// FED parameters
|
||||
int ncycles_; ///< Number of cycles
|
||||
bool reordering_; ///< Flag for reordering time steps
|
||||
std::vector<std::vector<float > > tsteps_; ///< Vector of FED dynamic time steps
|
||||
std::vector<int> nsteps_; ///< Vector of number of steps per cycle
|
||||
|
||||
/// Matrices for the M-LDB descriptor computation
|
||||
cv::Mat descriptorSamples_; // List of positions in the grids to sample LDB bits from.
|
||||
cv::Mat descriptorBits_;
|
||||
cv::Mat bitMask_;
|
||||
|
||||
public:
|
||||
|
||||
/// Constructor with input arguments
|
||||
AKAZEFeatures(const AKAZEOptions& options);
|
||||
|
||||
/// Scale Space methods
|
||||
void Allocate_Memory_Evolution();
|
||||
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
|
||||
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
|
||||
void Compute_Determinant_Hessian_Response(void);
|
||||
void Compute_Multiscale_Derivatives(void);
|
||||
void Find_Scale_Space_Extrema(std::vector<cv::KeyPoint>& kpts);
|
||||
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
|
||||
|
||||
/// Feature description methods
|
||||
void Compute_Descriptors(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
|
||||
static void Compute_Main_Orientation(cv::KeyPoint& kpt, const std::vector<TEvolution>& evolution_);
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
/// Inline functions
|
||||
void generateDescriptorSubsample(cv::Mat& sampleList, cv::Mat& comparisons,
|
||||
int nbits, int pattern_size, int nchannels);
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,8 @@
|
||||
* @author Pablo F. Alcantarilla
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef __OPENCV_FEATURES_2D_AKAZE_CONFIG_H__
|
||||
#define __OPENCV_FEATURES_2D_AKAZE_CONFIG_H__
|
||||
|
||||
// OpenCV Includes
|
||||
#include "precomp.hpp"
|
||||
@@ -15,14 +16,8 @@
|
||||
|
||||
struct KAZEOptions {
|
||||
|
||||
enum DIFFUSIVITY_TYPE {
|
||||
PM_G1 = 0,
|
||||
PM_G2 = 1,
|
||||
WEICKERT = 2
|
||||
};
|
||||
|
||||
KAZEOptions()
|
||||
: diffusivity(PM_G2)
|
||||
: diffusivity(cv::DIFF_PM_G2)
|
||||
|
||||
, soffset(1.60f)
|
||||
, omax(4)
|
||||
@@ -33,20 +28,13 @@ struct KAZEOptions {
|
||||
, dthreshold(0.001f)
|
||||
, kcontrast(0.01f)
|
||||
, kcontrast_percentille(0.7f)
|
||||
, kcontrast_bins(300)
|
||||
|
||||
, use_fed(true)
|
||||
, kcontrast_bins(300)
|
||||
, upright(false)
|
||||
, extended(false)
|
||||
|
||||
, use_clipping_normalilzation(false)
|
||||
, clipping_normalization_ratio(1.6f)
|
||||
, clipping_normalization_niter(5)
|
||||
{
|
||||
}
|
||||
|
||||
DIFFUSIVITY_TYPE diffusivity;
|
||||
|
||||
int diffusivity;
|
||||
float soffset;
|
||||
int omax;
|
||||
int nsublevels;
|
||||
@@ -57,27 +45,8 @@ struct KAZEOptions {
|
||||
float kcontrast;
|
||||
float kcontrast_percentille;
|
||||
int kcontrast_bins;
|
||||
|
||||
bool use_fed;
|
||||
bool upright;
|
||||
bool extended;
|
||||
|
||||
bool use_clipping_normalilzation;
|
||||
float clipping_normalization_ratio;
|
||||
int clipping_normalization_niter;
|
||||
};
|
||||
|
||||
struct TEvolution {
|
||||
cv::Mat Lx, Ly; // First order spatial derivatives
|
||||
cv::Mat Lxx, Lxy, Lyy; // Second order spatial derivatives
|
||||
cv::Mat Lflow; // Diffusivity image
|
||||
cv::Mat Lt; // Evolution image
|
||||
cv::Mat Lsmooth; // Smoothed image
|
||||
cv::Mat Lstep; // Evolution step update
|
||||
cv::Mat Ldet; // Detector response
|
||||
float etime; // Evolution time
|
||||
float esigma; // Evolution sigma. For linear diffusion t = sigma^2 / 2
|
||||
float octave; // Image octave
|
||||
float sublevel; // Image sublevel in each octave
|
||||
int sigma_size; // Integer esigma. For computing the feature detector responses
|
||||
};
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,84 +7,53 @@
|
||||
* @author Pablo F. Alcantarilla
|
||||
*/
|
||||
|
||||
#ifndef KAZE_H_
|
||||
#define KAZE_H_
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
#ifndef __OPENCV_FEATURES_2D_KAZE_FEATURES_H__
|
||||
#define __OPENCV_FEATURES_2D_KAZE_FEATURES_H__
|
||||
|
||||
/* ************************************************************************* */
|
||||
// Includes
|
||||
#include "KAZEConfig.h"
|
||||
#include "nldiffusion_functions.h"
|
||||
#include "fed.h"
|
||||
#include "TEvolution.h"
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
/* ************************************************************************* */
|
||||
// KAZE Class Declaration
|
||||
class KAZEFeatures {
|
||||
|
||||
private:
|
||||
|
||||
KAZEOptions options;
|
||||
/// Parameters of the Nonlinear diffusion class
|
||||
KAZEOptions options_; ///< Configuration options for KAZE
|
||||
std::vector<TEvolution> evolution_; ///< Vector of nonlinear diffusion evolution
|
||||
|
||||
// Parameters of the Nonlinear diffusion class
|
||||
std::vector<TEvolution> evolution_; // Vector of nonlinear diffusion evolution
|
||||
|
||||
// Vector of keypoint vectors for finding extrema in multiple threads
|
||||
/// Vector of keypoint vectors for finding extrema in multiple threads
|
||||
std::vector<std::vector<cv::KeyPoint> > kpts_par_;
|
||||
|
||||
// FED parameters
|
||||
int ncycles_; // Number of cycles
|
||||
bool reordering_; // Flag for reordering time steps
|
||||
std::vector<std::vector<float > > tsteps_; // Vector of FED dynamic time steps
|
||||
std::vector<int> nsteps_; // Vector of number of steps per cycle
|
||||
|
||||
// Some auxiliary variables used in the AOS step
|
||||
cv::Mat Ltx_, Lty_, px_, py_, ax_, ay_, bx_, by_, qr_, qc_;
|
||||
/// FED parameters
|
||||
int ncycles_; ///< Number of cycles
|
||||
bool reordering_; ///< Flag for reordering time steps
|
||||
std::vector<std::vector<float > > tsteps_; ///< Vector of FED dynamic time steps
|
||||
std::vector<int> nsteps_; ///< Vector of number of steps per cycle
|
||||
|
||||
public:
|
||||
|
||||
// Constructor
|
||||
/// Constructor
|
||||
KAZEFeatures(KAZEOptions& options);
|
||||
|
||||
// Public methods for KAZE interface
|
||||
/// Public methods for KAZE interface
|
||||
void Allocate_Memory_Evolution(void);
|
||||
int Create_Nonlinear_Scale_Space(const cv::Mat& img);
|
||||
void Feature_Detection(std::vector<cv::KeyPoint>& kpts);
|
||||
void Feature_Description(std::vector<cv::KeyPoint>& kpts, cv::Mat& desc);
|
||||
|
||||
static void Compute_Main_Orientation(cv::KeyPoint& kpt, const std::vector<TEvolution>& evolution_, const KAZEOptions& options);
|
||||
|
||||
private:
|
||||
|
||||
// Feature Detection Methods
|
||||
/// Feature Detection Methods
|
||||
void Compute_KContrast(const cv::Mat& img, const float& kper);
|
||||
void Compute_Multiscale_Derivatives(void);
|
||||
void Compute_Detector_Response(void);
|
||||
void Determinant_Hessian_Parallel(std::vector<cv::KeyPoint>& kpts);
|
||||
void Find_Extremum_Threading(const int& level);
|
||||
void Determinant_Hessian(std::vector<cv::KeyPoint>& kpts);
|
||||
void Do_Subpixel_Refinement(std::vector<cv::KeyPoint>& kpts);
|
||||
|
||||
// AOS Methods
|
||||
void AOS_Step_Scalar(cv::Mat &Ld, const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void AOS_Rows(const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void AOS_Columns(const cv::Mat &Ldprev, const cv::Mat &c, const float& stepsize);
|
||||
void Thomas(const cv::Mat &a, const cv::Mat &b, const cv::Mat &Ld, cv::Mat &x);
|
||||
|
||||
};
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
// Inline functions
|
||||
float getAngle(const float& x, const float& y);
|
||||
float gaussian(const float& x, const float& y, const float& sig);
|
||||
void checkDescriptorLimits(int &x, int &y, const int& width, const int& height);
|
||||
void clippingDescriptor(float *desc, const int& dsize, const int& niter, const float& ratio);
|
||||
int fRound(const float& flt);
|
||||
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
#endif // KAZE_H_
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file TEvolution.h
|
||||
* @brief Header file with the declaration of the TEvolution struct
|
||||
* @date Jun 02, 2014
|
||||
* @author Pablo F. Alcantarilla
|
||||
*/
|
||||
|
||||
#ifndef __OPENCV_FEATURES_2D_TEVOLUTION_H__
|
||||
#define __OPENCV_FEATURES_2D_TEVOLUTION_H__
|
||||
|
||||
/* ************************************************************************* */
|
||||
/// KAZE/A-KAZE nonlinear diffusion filtering evolution
|
||||
struct TEvolution {
|
||||
|
||||
TEvolution() {
|
||||
etime = 0.0f;
|
||||
esigma = 0.0f;
|
||||
octave = 0;
|
||||
sublevel = 0;
|
||||
sigma_size = 0;
|
||||
}
|
||||
|
||||
cv::Mat Lx, Ly; ///< First order spatial derivatives
|
||||
cv::Mat Lxx, Lxy, Lyy; ///< Second order spatial derivatives
|
||||
cv::Mat Lt; ///< Evolution image
|
||||
cv::Mat Lsmooth; ///< Smoothed image
|
||||
cv::Mat Ldet; ///< Detector response
|
||||
float etime; ///< Evolution time
|
||||
float esigma; ///< Evolution sigma. For linear diffusion t = sigma^2 / 2
|
||||
int octave; ///< Image octave
|
||||
int sublevel; ///< Image sublevel in each octave
|
||||
int sigma_size; ///< Integer esigma. For computing the feature detector responses
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef FED_H
|
||||
#define FED_H
|
||||
#ifndef __OPENCV_FEATURES_2D_FED_H__
|
||||
#define __OPENCV_FEATURES_2D_FED_H__
|
||||
|
||||
//******************************************************************************
|
||||
//******************************************************************************
|
||||
@@ -22,4 +22,4 @@ bool fed_is_prime_internal(const int& number);
|
||||
//*************************************************************************************
|
||||
//*************************************************************************************
|
||||
|
||||
#endif // FED_H
|
||||
#endif // __OPENCV_FEATURES_2D_FED_H__
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* @author Pablo F. Alcantarilla
|
||||
*/
|
||||
|
||||
#ifndef KAZE_NLDIFFUSION_FUNCTIONS_H
|
||||
#define KAZE_NLDIFFUSION_FUNCTIONS_H
|
||||
#ifndef __OPENCV_FEATURES_2D_NLDIFFUSION_FUNCTIONS_H__
|
||||
#define __OPENCV_FEATURES_2D_NLDIFFUSION_FUNCTIONS_H__
|
||||
|
||||
/* ************************************************************************* */
|
||||
// Includes
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
#ifndef __OPENCV_FEATURES_2D_KAZE_UTILS_H__
|
||||
#define __OPENCV_FEATURES_2D_KAZE_UTILS_H__
|
||||
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* @brief This function computes the angle from the vector given by (X Y). From 0 to 2*Pi
|
||||
*/
|
||||
inline float getAngle(float x, float y) {
|
||||
|
||||
if (x >= 0 && y >= 0) {
|
||||
return atanf(y / x);
|
||||
}
|
||||
|
||||
if (x < 0 && y >= 0) {
|
||||
return static_cast<float>(CV_PI)-atanf(-y / x);
|
||||
}
|
||||
|
||||
if (x < 0 && y < 0) {
|
||||
return static_cast<float>(CV_PI)+atanf(y / x);
|
||||
}
|
||||
|
||||
if (x >= 0 && y < 0) {
|
||||
return static_cast<float>(2.0 * CV_PI) - atanf(-y / x);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* @brief This function computes the value of a 2D Gaussian function
|
||||
* @param x X Position
|
||||
* @param y Y Position
|
||||
* @param sig Standard Deviation
|
||||
*/
|
||||
inline float gaussian(float x, float y, float sigma) {
|
||||
return expf(-(x*x + y*y) / (2.0f*sigma*sigma));
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* @brief This function checks descriptor limits
|
||||
* @param x X Position
|
||||
* @param y Y Position
|
||||
* @param width Image width
|
||||
* @param height Image height
|
||||
*/
|
||||
inline void checkDescriptorLimits(int &x, int &y, int width, int height) {
|
||||
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
}
|
||||
|
||||
if (x > width - 1) {
|
||||
x = width - 1;
|
||||
}
|
||||
|
||||
if (y > height - 1) {
|
||||
y = height - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* @brief This funtion rounds float to nearest integer
|
||||
* @param flt Input float
|
||||
* @return dst Nearest integer
|
||||
*/
|
||||
inline int fRound(float flt) {
|
||||
return (int)(flt + 0.5f);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -40,7 +40,6 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -102,8 +101,14 @@ public:
|
||||
typedef typename Distance::ResultType DistanceType;
|
||||
|
||||
CV_DescriptorExtractorTest( const string _name, DistanceType _maxDist, const Ptr<DescriptorExtractor>& _dextractor,
|
||||
Distance d = Distance() ):
|
||||
name(_name), maxDist(_maxDist), dextractor(_dextractor), distance(d) {}
|
||||
Distance d = Distance(), Ptr<FeatureDetector> _detector = Ptr<FeatureDetector>()):
|
||||
name(_name), maxDist(_maxDist), dextractor(_dextractor), distance(d) , detector(_detector) {}
|
||||
|
||||
~CV_DescriptorExtractorTest()
|
||||
{
|
||||
if(!detector.empty())
|
||||
detector.release();
|
||||
}
|
||||
protected:
|
||||
virtual void createDescriptorExtractor() {}
|
||||
|
||||
@@ -190,7 +195,6 @@ protected:
|
||||
|
||||
// Read the test image.
|
||||
string imgFilename = string(ts->get_data_path()) + FEATURES2D_DIR + "/" + IMAGE_FILENAME;
|
||||
|
||||
Mat img = imread( imgFilename );
|
||||
if( img.empty() )
|
||||
{
|
||||
@@ -198,13 +202,15 @@ protected:
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
return;
|
||||
}
|
||||
|
||||
vector<KeyPoint> keypoints;
|
||||
FileStorage fs( string(ts->get_data_path()) + FEATURES2D_DIR + "/keypoints.xml.gz", FileStorage::READ );
|
||||
if( fs.isOpened() )
|
||||
{
|
||||
if(!detector.empty()) {
|
||||
detector->detect(img, keypoints);
|
||||
} else {
|
||||
read( fs.getFirstTopLevelNode(), keypoints );
|
||||
|
||||
}
|
||||
if(!keypoints.empty())
|
||||
{
|
||||
Mat calcDescriptors;
|
||||
double t = (double)getTickCount();
|
||||
dextractor->compute( img, keypoints, calcDescriptors );
|
||||
@@ -245,7 +251,7 @@ protected:
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if(!fs.isOpened())
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "Compute and write keypoints.\n" );
|
||||
fs.open( string(ts->get_data_path()) + FEATURES2D_DIR + "/keypoints.xml.gz", FileStorage::WRITE );
|
||||
@@ -296,6 +302,7 @@ protected:
|
||||
const DistanceType maxDist;
|
||||
Ptr<DescriptorExtractor> dextractor;
|
||||
Distance distance;
|
||||
Ptr<FeatureDetector> detector;
|
||||
|
||||
private:
|
||||
CV_DescriptorExtractorTest& operator=(const CV_DescriptorExtractorTest&) { return *this; }
|
||||
@@ -341,3 +348,19 @@ TEST( Features2d_DescriptorExtractor_OpponentBRIEF, regression )
|
||||
DescriptorExtractor::create("OpponentBRIEF") );
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
TEST( Features2d_DescriptorExtractor_KAZE, regression )
|
||||
{
|
||||
CV_DescriptorExtractorTest< L2<float> > test( "descriptor-kaze", 0.03f,
|
||||
DescriptorExtractor::create("KAZE"),
|
||||
L2<float>(), FeatureDetector::create("KAZE"));
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
TEST( Features2d_DescriptorExtractor_AKAZE, regression )
|
||||
{
|
||||
CV_DescriptorExtractorTest<Hamming> test( "descriptor-akaze", (CV_DescriptorExtractorTest<Hamming>::DistanceType)12.f,
|
||||
DescriptorExtractor::create("AKAZE"),
|
||||
Hamming(), FeatureDetector::create("AKAZE"));
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
@@ -289,6 +289,18 @@ TEST( Features2d_Detector_ORB, regression )
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
TEST( Features2d_Detector_KAZE, regression )
|
||||
{
|
||||
CV_FeatureDetectorTest test( "detector-kaze", FeatureDetector::create("KAZE") );
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
TEST( Features2d_Detector_AKAZE, regression )
|
||||
{
|
||||
CV_FeatureDetectorTest test( "detector-akaze", FeatureDetector::create("AKAZE") );
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
TEST( Features2d_Detector_GridFAST, regression )
|
||||
{
|
||||
CV_FeatureDetectorTest test( "detector-grid-fast", FeatureDetector::create("GridFAST") );
|
||||
|
||||
@@ -167,19 +167,17 @@ TEST(Features2d_Detector_Keypoints_Dense, validation)
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
// FIXIT #2807 Crash on Windows 7 x64 MSVS 2012, Linux Fedora 19 x64 with GCC 4.8.2, Linux Ubuntu 14.04 LTS x64 with GCC 4.8.2
|
||||
TEST(Features2d_Detector_Keypoints_KAZE, DISABLED_validation)
|
||||
TEST(Features2d_Detector_Keypoints_KAZE, validation)
|
||||
{
|
||||
CV_FeatureDetectorKeypointsTest test(Algorithm::create<FeatureDetector>("Feature2D.KAZE"));
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
// FIXIT #2807 Crash on Windows 7 x64 MSVS 2012, Linux Fedora 19 x64 with GCC 4.8.2, Linux Ubuntu 14.04 LTS x64 with GCC 4.8.2
|
||||
TEST(Features2d_Detector_Keypoints_AKAZE, DISABLED_validation)
|
||||
TEST(Features2d_Detector_Keypoints_AKAZE, validation)
|
||||
{
|
||||
CV_FeatureDetectorKeypointsTest test_kaze(cv::Ptr<FeatureDetector>(new cv::AKAZE(cv::AKAZE::DESCRIPTOR_KAZE)));
|
||||
CV_FeatureDetectorKeypointsTest test_kaze(cv::Ptr<FeatureDetector>(new cv::AKAZE(cv::DESCRIPTOR_KAZE)));
|
||||
test_kaze.safe_run();
|
||||
|
||||
CV_FeatureDetectorKeypointsTest test_mldb(cv::Ptr<FeatureDetector>(new cv::AKAZE(cv::AKAZE::DESCRIPTOR_MLDB)));
|
||||
CV_FeatureDetectorKeypointsTest test_mldb(cv::Ptr<FeatureDetector>(new cv::AKAZE(cv::DESCRIPTOR_MLDB)));
|
||||
test_mldb.safe_run();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/features2d.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -652,8 +652,7 @@ TEST(Features2d_ScaleInvariance_Detector_BRISK, regression)
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
// FIXIT #2807 Crash on Windows 7 x64 MSVS 2012, Linux Fedora 19 x64 with GCC 4.8.2, Linux Ubuntu 14.04 LTS x64 with GCC 4.8.2
|
||||
TEST(Features2d_ScaleInvariance_Detector_KAZE, DISABLED_regression)
|
||||
TEST(Features2d_ScaleInvariance_Detector_KAZE, regression)
|
||||
{
|
||||
DetectorScaleInvarianceTest test(Algorithm::create<FeatureDetector>("Feature2D.KAZE"),
|
||||
0.08f,
|
||||
@@ -661,8 +660,7 @@ TEST(Features2d_ScaleInvariance_Detector_KAZE, DISABLED_regression)
|
||||
test.safe_run();
|
||||
}
|
||||
|
||||
// FIXIT #2807 Crash on Windows 7 x64 MSVS 2012, Linux Fedora 19 x64 with GCC 4.8.2, Linux Ubuntu 14.04 LTS x64 with GCC 4.8.2
|
||||
TEST(Features2d_ScaleInvariance_Detector_AKAZE, DISABLED_regression)
|
||||
TEST(Features2d_ScaleInvariance_Detector_AKAZE, regression)
|
||||
{
|
||||
DetectorScaleInvarianceTest test(Algorithm::create<FeatureDetector>("Feature2D.AKAZE"),
|
||||
0.08f,
|
||||
|
||||
@@ -595,7 +595,7 @@ struct HellingerDistance
|
||||
typedef typename Accumulator<T>::Type ResultType;
|
||||
|
||||
/**
|
||||
* Compute the histogram intersection distance
|
||||
* Compute the Hellinger distance
|
||||
*/
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const
|
||||
@@ -628,7 +628,8 @@ struct HellingerDistance
|
||||
template <typename U, typename V>
|
||||
inline ResultType accum_dist(const U& a, const V& b, int) const
|
||||
{
|
||||
return sqrt(static_cast<ResultType>(a)) - sqrt(static_cast<ResultType>(b));
|
||||
ResultType diff = sqrt(static_cast<ResultType>(a)) - sqrt(static_cast<ResultType>(b));
|
||||
return diff * diff;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -729,9 +730,11 @@ struct KL_Divergence
|
||||
inline ResultType accum_dist(const U& a, const V& b, int) const
|
||||
{
|
||||
ResultType result = ResultType();
|
||||
ResultType ratio = (ResultType)(a / b);
|
||||
if (ratio>0) {
|
||||
result = a * log(ratio);
|
||||
if( *b != 0 ) {
|
||||
ResultType ratio = (ResultType)(a / b);
|
||||
if (ratio>0) {
|
||||
result = a * log(ratio);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
set(the_description "High-level GUI and Media I/O")
|
||||
ocv_add_module(highgui opencv_imgproc OPTIONAL opencv_androidcamera)
|
||||
ocv_add_module(highgui opencv_imgproc opencv_imgcodecs opencv_videoio OPTIONAL opencv_androidcamera)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for highgui. See root CMakeLists.txt
|
||||
@@ -7,70 +7,20 @@ ocv_add_module(highgui opencv_imgproc OPTIONAL opencv_androidcamera)
|
||||
# Jose Luis Blanco, 2008
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
ocv_clear_vars(GRFMT_LIBS)
|
||||
|
||||
if(HAVE_WINRT_CX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
|
||||
endif()
|
||||
|
||||
if(HAVE_PNG OR HAVE_TIFF OR HAVE_OPENEXR)
|
||||
if(APPLE)
|
||||
ocv_include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES})
|
||||
list(APPEND HIGHGUI_LIBRARIES ${ZLIB_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_JPEG)
|
||||
ocv_include_directories(${JPEG_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(WITH_WEBP)
|
||||
add_definitions(-DHAVE_WEBP)
|
||||
ocv_include_directories(${WEBP_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${WEBP_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_PNG)
|
||||
add_definitions(${PNG_DEFINITIONS})
|
||||
ocv_include_directories(${PNG_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_TIFF)
|
||||
ocv_include_directories(${TIFF_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_JASPER)
|
||||
ocv_include_directories(${JASPER_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${JASPER_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_OPENEXR)
|
||||
include_directories(SYSTEM ${OPENEXR_INCLUDE_PATHS})
|
||||
list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES})
|
||||
endif()
|
||||
|
||||
file(GLOB grfmt_hdrs src/grfmt*.hpp)
|
||||
file(GLOB grfmt_srcs src/grfmt*.cpp)
|
||||
list(APPEND grfmt_hdrs src/bitstrm.hpp)
|
||||
list(APPEND grfmt_srcs src/bitstrm.cpp)
|
||||
list(APPEND grfmt_hdrs src/rgbe.hpp)
|
||||
list(APPEND grfmt_srcs src/rgbe.cpp)
|
||||
|
||||
source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs})
|
||||
|
||||
set(highgui_hdrs
|
||||
src/precomp.hpp
|
||||
src/utils.hpp
|
||||
src/cap_ffmpeg_impl.hpp
|
||||
)
|
||||
|
||||
set(highgui_srcs
|
||||
src/cap.cpp
|
||||
src/cap_images.cpp
|
||||
src/cap_ffmpeg.cpp
|
||||
src/loadsave.cpp
|
||||
src/utils.cpp
|
||||
src/window.cpp
|
||||
)
|
||||
|
||||
@@ -122,128 +72,6 @@ elseif(HAVE_COCOA)
|
||||
list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
|
||||
endif()
|
||||
|
||||
if(WIN32 AND NOT ARM)
|
||||
list(APPEND highgui_srcs src/cap_cmu.cpp)
|
||||
endif()
|
||||
|
||||
if (WIN32 AND HAVE_DSHOW)
|
||||
list(APPEND highgui_srcs src/cap_dshow.cpp)
|
||||
endif()
|
||||
|
||||
if (WIN32 AND HAVE_MSMF)
|
||||
list(APPEND highgui_srcs src/cap_msmf.cpp)
|
||||
endif()
|
||||
|
||||
if (WIN32 AND HAVE_VFW)
|
||||
list(APPEND highgui_srcs src/cap_vfw.cpp)
|
||||
endif()
|
||||
|
||||
if(HAVE_XINE)
|
||||
list(APPEND highgui_srcs src/cap_xine.cpp)
|
||||
endif(HAVE_XINE)
|
||||
|
||||
if(HAVE_DC1394_2)
|
||||
list(APPEND highgui_srcs src/cap_dc1394_v2.cpp)
|
||||
endif(HAVE_DC1394_2)
|
||||
|
||||
if(HAVE_DC1394)
|
||||
list(APPEND highgui_srcs src/cap_dc1394.cpp)
|
||||
endif(HAVE_DC1394)
|
||||
|
||||
if(HAVE_GSTREAMER)
|
||||
list(APPEND highgui_srcs src/cap_gstreamer.cpp)
|
||||
endif(HAVE_GSTREAMER)
|
||||
|
||||
if(HAVE_UNICAP)
|
||||
list(APPEND highgui_srcs src/cap_unicap.cpp)
|
||||
endif(HAVE_UNICAP)
|
||||
|
||||
if(HAVE_LIBV4L)
|
||||
list(APPEND highgui_srcs src/cap_libv4l.cpp)
|
||||
elseif(HAVE_CAMV4L OR HAVE_CAMV4L2 OR HAVE_VIDEOIO)
|
||||
list(APPEND highgui_srcs src/cap_v4l.cpp)
|
||||
endif()
|
||||
|
||||
if(HAVE_OPENNI)
|
||||
list(APPEND highgui_srcs src/cap_openni.cpp)
|
||||
ocv_include_directories(${OPENNI_INCLUDE_DIR})
|
||||
list(APPEND HIGHGUI_LIBRARIES ${OPENNI_LIBRARY})
|
||||
endif(HAVE_OPENNI)
|
||||
|
||||
if(HAVE_opencv_androidcamera)
|
||||
list(APPEND highgui_srcs src/cap_android.cpp)
|
||||
add_definitions(-DHAVE_ANDROID_NATIVE_CAMERA)#TODO: remove this line
|
||||
endif(HAVE_opencv_androidcamera)
|
||||
|
||||
if(HAVE_XIMEA)
|
||||
list(APPEND highgui_srcs src/cap_ximea.cpp)
|
||||
ocv_include_directories(${XIMEA_PATH})
|
||||
if(XIMEA_LIBRARY_DIR)
|
||||
link_directories("${XIMEA_LIBRARY_DIR}")
|
||||
endif()
|
||||
if(X86_64)
|
||||
list(APPEND HIGHGUI_LIBRARIES m3apiX64)
|
||||
else()
|
||||
list(APPEND HIGHGUI_LIBRARIES m3api)
|
||||
endif()
|
||||
endif(HAVE_XIMEA)
|
||||
|
||||
if(HAVE_FFMPEG)
|
||||
if(UNIX AND BZIP2_LIBRARIES)
|
||||
list(APPEND HIGHGUI_LIBRARIES ${BZIP2_LIBRARIES})
|
||||
endif()
|
||||
if(APPLE)
|
||||
list(APPEND HIGHGUI_LIBRARIES "-framework VideoDecodeAcceleration" bz2)
|
||||
endif()
|
||||
endif(HAVE_FFMPEG)
|
||||
|
||||
if(HAVE_PVAPI)
|
||||
add_definitions(-DHAVE_PVAPI)
|
||||
add_definitions(${PVAPI_DEFINITIONS})
|
||||
ocv_include_directories(${PVAPI_INCLUDE_PATH})
|
||||
set(highgui_srcs src/cap_pvapi.cpp ${highgui_srcs})
|
||||
list(APPEND HIGHGUI_LIBRARIES ${PVAPI_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(HAVE_GIGE_API)
|
||||
add_definitions(-DHAVE_GIGE_API)
|
||||
ocv_include_directories(${GIGEAPI_INCLUDE_PATH})
|
||||
set(highgui_srcs src/cap_giganetix.cpp ${highgui_srcs})
|
||||
list(APPEND HIGHGUI_LIBRARIES ${GIGEAPI_LIBRARIES})
|
||||
list(APPEND highgui_srcs src/cap_giganetix.cpp)
|
||||
endif(HAVE_GIGE_API)
|
||||
|
||||
if(HAVE_AVFOUNDATION)
|
||||
list(APPEND highgui_srcs src/cap_avfoundation.mm)
|
||||
list(APPEND HIGHGUI_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
|
||||
endif()
|
||||
|
||||
if(HAVE_QUICKTIME)
|
||||
list(APPEND highgui_srcs src/cap_qt.cpp)
|
||||
list(APPEND HIGHGUI_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore")
|
||||
elseif(HAVE_QTKIT)
|
||||
list(APPEND highgui_srcs src/cap_qtkit.mm)
|
||||
list(APPEND HIGHGUI_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit")
|
||||
endif()
|
||||
|
||||
if(HAVE_INTELPERC)
|
||||
list(APPEND highgui_srcs src/cap_intelperc.cpp)
|
||||
ocv_include_directories(${INTELPERC_INCLUDE_DIR})
|
||||
list(APPEND HIGHGUI_LIBRARIES ${INTELPERC_LIBRARIES})
|
||||
endif(HAVE_INTELPERC)
|
||||
|
||||
if(IOS)
|
||||
add_definitions(-DHAVE_IOS=1)
|
||||
list(APPEND highgui_srcs src/ios_conversions.mm src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm)
|
||||
list(APPEND HIGHGUI_LIBRARIES "-framework Accelerate" "-framework AVFoundation" "-framework CoreGraphics" "-framework CoreImage" "-framework CoreMedia" "-framework CoreVideo" "-framework QuartzCore" "-framework AssetsLibrary")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
link_directories("${OpenCV_SOURCE_DIR}/3rdparty/lib") # for ffmpeg wrapper only
|
||||
include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include") # for directshow in VS2005 and multi-monitor support on MinGW
|
||||
include_directories(AFTER SYSTEM "${OpenCV_SOURCE_DIR}/3rdparty/include/ffmpeg_") # for tests
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
#these variables are set by CHECK_MODULE macro
|
||||
foreach(P ${HIGHGUI_INCLUDE_DIRS})
|
||||
@@ -257,10 +85,10 @@ endif()
|
||||
|
||||
source_group("Src" FILES ${highgui_srcs} ${highgui_hdrs})
|
||||
source_group("Include" FILES ${highgui_ext_hdrs})
|
||||
ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs} ${grfmt_srcs} ${grfmt_hdrs})
|
||||
ocv_set_module_sources(HEADERS ${highgui_ext_hdrs} SOURCES ${highgui_srcs} ${highgui_hdrs})
|
||||
ocv_module_include_directories()
|
||||
|
||||
ocv_create_module(${GRFMT_LIBS} ${HIGHGUI_LIBRARIES})
|
||||
ocv_create_module(${HIGHGUI_LIBRARIES})
|
||||
|
||||
if(APPLE)
|
||||
ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS)
|
||||
@@ -294,33 +122,5 @@ set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
|
||||
ocv_add_precompiled_headers(${the_module})
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
|
||||
|
||||
if(WIN32 AND WITH_FFMPEG)
|
||||
#copy ffmpeg dll to the output folder
|
||||
if(MSVC64 OR MINGW64)
|
||||
set(FFMPEG_SUFFIX _64)
|
||||
endif()
|
||||
|
||||
set(ffmpeg_bare_name "opencv_ffmpeg${FFMPEG_SUFFIX}.dll")
|
||||
set(ffmpeg_bare_name_ver "opencv_ffmpeg${OPENCV_DLLVERSION}${FFMPEG_SUFFIX}.dll")
|
||||
set(ffmpeg_path "${OpenCV_SOURCE_DIR}/3rdparty/ffmpeg/${ffmpeg_bare_name}")
|
||||
|
||||
if(MSVC_IDE)
|
||||
add_custom_command(TARGET ${the_module} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Release/${ffmpeg_bare_name_ver}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/Debug/${ffmpeg_bare_name_ver}"
|
||||
COMMENT "Copying ${ffmpeg_path} to the output directory")
|
||||
elseif(MSVC AND (CMAKE_GENERATOR MATCHES "Visual"))
|
||||
add_custom_command(TARGET ${the_module} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}/${ffmpeg_bare_name_ver}"
|
||||
COMMENT "Copying ${ffmpeg_path} to the output directory")
|
||||
else()
|
||||
add_custom_command(TARGET ${the_module} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${ffmpeg_path}" "${EXECUTABLE_OUTPUT_PATH}/${ffmpeg_bare_name_ver}"
|
||||
COMMENT "Copying ${ffmpeg_path} to the output directory")
|
||||
endif()
|
||||
|
||||
install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs RENAME "${ffmpeg_bare_name_ver}")
|
||||
endif()
|
||||
|
||||
ocv_add_accuracy_tests()
|
||||
ocv_add_perf_tests()
|
||||
|
||||
@@ -9,12 +9,9 @@ It provides easy interface to:
|
||||
|
||||
* Create and manipulate windows that can display images and "remember" their content (no need to handle repaint events from OS).
|
||||
* Add trackbars to the windows, handle simple mouse events as well as keyboard commands.
|
||||
* Read and write images to/from disk or memory.
|
||||
* Read video from camera or file and write video to a file.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
user_interface
|
||||
reading_and_writing_images_and_video
|
||||
qt_new_functions
|
||||
|
||||
@@ -83,6 +83,9 @@ If window was created with OpenGL support, ``imshow`` also support :ocv:class:`o
|
||||
|
||||
.. note:: This function should be followed by ``waitKey`` function which displays the image for specified milliseconds. Otherwise, it won't display the image. For example, ``waitKey(0)`` will display the window infinitely until any keypress (it is suitable for image display). ``waitKey(25)`` will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame)
|
||||
|
||||
.. note::
|
||||
|
||||
[Windows Backend Only] Pressing Ctrl+C will copy the image to the clipboard.
|
||||
|
||||
namedWindow
|
||||
---------------
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
#define __OPENCV_HIGHGUI_HPP__
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/videoio.hpp"
|
||||
|
||||
|
||||
///////////////////////// graphical user interface //////////////////////////
|
||||
@@ -201,392 +203,4 @@ CV_EXPORTS int createButton( const String& bar_name, ButtonCallback on_change,
|
||||
bool initial_button_state = false);
|
||||
|
||||
} // cv
|
||||
|
||||
|
||||
|
||||
//////////////////////////////// image codec ////////////////////////////////
|
||||
namespace cv
|
||||
{
|
||||
|
||||
enum { IMREAD_UNCHANGED = -1, // 8bit, color or not
|
||||
IMREAD_GRAYSCALE = 0, // 8bit, gray
|
||||
IMREAD_COLOR = 1, // ?, color
|
||||
IMREAD_ANYDEPTH = 2, // any depth, ?
|
||||
IMREAD_ANYCOLOR = 4 // ?, any color
|
||||
};
|
||||
|
||||
enum { IMWRITE_JPEG_QUALITY = 1,
|
||||
IMWRITE_JPEG_PROGRESSIVE = 2,
|
||||
IMWRITE_JPEG_OPTIMIZE = 3,
|
||||
IMWRITE_PNG_COMPRESSION = 16,
|
||||
IMWRITE_PNG_STRATEGY = 17,
|
||||
IMWRITE_PNG_BILEVEL = 18,
|
||||
IMWRITE_PXM_BINARY = 32,
|
||||
IMWRITE_WEBP_QUALITY = 64
|
||||
};
|
||||
|
||||
enum { IMWRITE_PNG_STRATEGY_DEFAULT = 0,
|
||||
IMWRITE_PNG_STRATEGY_FILTERED = 1,
|
||||
IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2,
|
||||
IMWRITE_PNG_STRATEGY_RLE = 3,
|
||||
IMWRITE_PNG_STRATEGY_FIXED = 4
|
||||
};
|
||||
|
||||
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );
|
||||
|
||||
CV_EXPORTS_W bool imwrite( const String& filename, InputArray img,
|
||||
const std::vector<int>& params = std::vector<int>());
|
||||
|
||||
CV_EXPORTS_W Mat imdecode( InputArray buf, int flags );
|
||||
|
||||
CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst);
|
||||
|
||||
CV_EXPORTS_W bool imencode( const String& ext, InputArray img,
|
||||
CV_OUT std::vector<uchar>& buf,
|
||||
const std::vector<int>& params = std::vector<int>());
|
||||
|
||||
} // cv
|
||||
|
||||
|
||||
|
||||
////////////////////////////////// video io /////////////////////////////////
|
||||
|
||||
typedef struct CvCapture CvCapture;
|
||||
typedef struct CvVideoWriter CvVideoWriter;
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
// Camera API
|
||||
enum { CAP_ANY = 0, // autodetect
|
||||
CAP_VFW = 200, // platform native
|
||||
CAP_V4L = 200,
|
||||
CAP_V4L2 = CAP_V4L,
|
||||
CAP_FIREWARE = 300, // IEEE 1394 drivers
|
||||
CAP_FIREWIRE = CAP_FIREWARE,
|
||||
CAP_IEEE1394 = CAP_FIREWARE,
|
||||
CAP_DC1394 = CAP_FIREWARE,
|
||||
CAP_CMU1394 = CAP_FIREWARE,
|
||||
CAP_QT = 500, // QuickTime
|
||||
CAP_UNICAP = 600, // Unicap drivers
|
||||
CAP_DSHOW = 700, // DirectShow (via videoInput)
|
||||
CAP_PVAPI = 800, // PvAPI, Prosilica GigE SDK
|
||||
CAP_OPENNI = 900, // OpenNI (for Kinect)
|
||||
CAP_OPENNI_ASUS = 910, // OpenNI (for Asus Xtion)
|
||||
CAP_ANDROID = 1000, // Android
|
||||
CAP_XIAPI = 1100, // XIMEA Camera API
|
||||
CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API)
|
||||
CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK
|
||||
CAP_MSMF = 1400, // Microsoft Media Foundation (via videoInput)
|
||||
CAP_INTELPERC = 1500 // Intel Perceptual Computing SDK
|
||||
};
|
||||
|
||||
// generic properties (based on DC1394 properties)
|
||||
enum { CAP_PROP_POS_MSEC =0,
|
||||
CAP_PROP_POS_FRAMES =1,
|
||||
CAP_PROP_POS_AVI_RATIO =2,
|
||||
CAP_PROP_FRAME_WIDTH =3,
|
||||
CAP_PROP_FRAME_HEIGHT =4,
|
||||
CAP_PROP_FPS =5,
|
||||
CAP_PROP_FOURCC =6,
|
||||
CAP_PROP_FRAME_COUNT =7,
|
||||
CAP_PROP_FORMAT =8,
|
||||
CAP_PROP_MODE =9,
|
||||
CAP_PROP_BRIGHTNESS =10,
|
||||
CAP_PROP_CONTRAST =11,
|
||||
CAP_PROP_SATURATION =12,
|
||||
CAP_PROP_HUE =13,
|
||||
CAP_PROP_GAIN =14,
|
||||
CAP_PROP_EXPOSURE =15,
|
||||
CAP_PROP_CONVERT_RGB =16,
|
||||
CAP_PROP_WHITE_BALANCE_BLUE_U =17,
|
||||
CAP_PROP_RECTIFICATION =18,
|
||||
CAP_PROP_MONOCROME =19,
|
||||
CAP_PROP_SHARPNESS =20,
|
||||
CAP_PROP_AUTO_EXPOSURE =21, // DC1394: exposure control done by camera, user can adjust refernce level using this feature
|
||||
CAP_PROP_GAMMA =22,
|
||||
CAP_PROP_TEMPERATURE =23,
|
||||
CAP_PROP_TRIGGER =24,
|
||||
CAP_PROP_TRIGGER_DELAY =25,
|
||||
CAP_PROP_WHITE_BALANCE_RED_V =26,
|
||||
CAP_PROP_ZOOM =27,
|
||||
CAP_PROP_FOCUS =28,
|
||||
CAP_PROP_GUID =29,
|
||||
CAP_PROP_ISO_SPEED =30,
|
||||
CAP_PROP_BACKLIGHT =32,
|
||||
CAP_PROP_PAN =33,
|
||||
CAP_PROP_TILT =34,
|
||||
CAP_PROP_ROLL =35,
|
||||
CAP_PROP_IRIS =36,
|
||||
CAP_PROP_SETTINGS =37
|
||||
};
|
||||
|
||||
|
||||
// DC1394 only
|
||||
// modes of the controlling registers (can be: auto, manual, auto single push, absolute Latter allowed with any other mode)
|
||||
// every feature can have only one mode turned on at a time
|
||||
enum { CAP_PROP_DC1394_OFF = -4, //turn the feature off (not controlled manually nor automatically)
|
||||
CAP_PROP_DC1394_MODE_MANUAL = -3, //set automatically when a value of the feature is set by the user
|
||||
CAP_PROP_DC1394_MODE_AUTO = -2,
|
||||
CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1,
|
||||
CAP_PROP_DC1394_MAX = 31
|
||||
};
|
||||
|
||||
|
||||
// OpenNI map generators
|
||||
enum { CAP_OPENNI_DEPTH_GENERATOR = 1 << 31,
|
||||
CAP_OPENNI_IMAGE_GENERATOR = 1 << 30,
|
||||
CAP_OPENNI_GENERATORS_MASK = CAP_OPENNI_DEPTH_GENERATOR + CAP_OPENNI_IMAGE_GENERATOR
|
||||
};
|
||||
|
||||
// Properties of cameras available through OpenNI interfaces
|
||||
enum { CAP_PROP_OPENNI_OUTPUT_MODE = 100,
|
||||
CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm
|
||||
CAP_PROP_OPENNI_BASELINE = 102, // in mm
|
||||
CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels
|
||||
CAP_PROP_OPENNI_REGISTRATION = 104, // flag that synchronizes the remapping depth map to image map
|
||||
// by changing depth generator's view point (if the flag is "on") or
|
||||
// sets this view point to its normal one (if the flag is "off").
|
||||
CAP_PROP_OPENNI_REGISTRATION_ON = CAP_PROP_OPENNI_REGISTRATION,
|
||||
CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105,
|
||||
CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106,
|
||||
CAP_PROP_OPENNI_CIRCLE_BUFFER = 107,
|
||||
CAP_PROP_OPENNI_MAX_TIME_DURATION = 108,
|
||||
CAP_PROP_OPENNI_GENERATOR_PRESENT = 109
|
||||
};
|
||||
|
||||
// OpenNI shortcats
|
||||
enum { CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_GENERATOR_PRESENT,
|
||||
CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CAP_OPENNI_IMAGE_GENERATOR + CAP_PROP_OPENNI_OUTPUT_MODE,
|
||||
CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_BASELINE,
|
||||
CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_FOCAL_LENGTH,
|
||||
CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CAP_OPENNI_DEPTH_GENERATOR + CAP_PROP_OPENNI_REGISTRATION,
|
||||
CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION
|
||||
};
|
||||
|
||||
// OpenNI data given from depth generator
|
||||
enum { CAP_OPENNI_DEPTH_MAP = 0, // Depth values in mm (CV_16UC1)
|
||||
CAP_OPENNI_POINT_CLOUD_MAP = 1, // XYZ in meters (CV_32FC3)
|
||||
CAP_OPENNI_DISPARITY_MAP = 2, // Disparity in pixels (CV_8UC1)
|
||||
CAP_OPENNI_DISPARITY_MAP_32F = 3, // Disparity in pixels (CV_32FC1)
|
||||
CAP_OPENNI_VALID_DEPTH_MASK = 4, // CV_8UC1
|
||||
|
||||
// Data given from RGB image generator
|
||||
CAP_OPENNI_BGR_IMAGE = 5,
|
||||
CAP_OPENNI_GRAY_IMAGE = 6
|
||||
};
|
||||
|
||||
// Supported output modes of OpenNI image generator
|
||||
enum { CAP_OPENNI_VGA_30HZ = 0,
|
||||
CAP_OPENNI_SXGA_15HZ = 1,
|
||||
CAP_OPENNI_SXGA_30HZ = 2,
|
||||
CAP_OPENNI_QVGA_30HZ = 3,
|
||||
CAP_OPENNI_QVGA_60HZ = 4
|
||||
};
|
||||
|
||||
|
||||
// GStreamer
|
||||
enum { CAP_PROP_GSTREAMER_QUEUE_LENGTH = 200 // default is 1
|
||||
};
|
||||
|
||||
|
||||
// PVAPI
|
||||
enum { CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast
|
||||
CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE = 301 // FrameStartTriggerMode: Determines how a frame is initiated
|
||||
};
|
||||
|
||||
// PVAPI: FrameStartTriggerMode
|
||||
enum { CAP_PVAPI_FSTRIGMODE_FREERUN = 0, // Freerun
|
||||
CAP_PVAPI_FSTRIGMODE_SYNCIN1 = 1, // SyncIn1
|
||||
CAP_PVAPI_FSTRIGMODE_SYNCIN2 = 2, // SyncIn2
|
||||
CAP_PVAPI_FSTRIGMODE_FIXEDRATE = 3, // FixedRate
|
||||
CAP_PVAPI_FSTRIGMODE_SOFTWARE = 4 // Software
|
||||
};
|
||||
|
||||
// Properties of cameras available through XIMEA SDK interface
|
||||
enum { CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping.
|
||||
CAP_PROP_XI_DATA_FORMAT = 401, // Output data format.
|
||||
CAP_PROP_XI_OFFSET_X = 402, // Horizontal offset from the origin to the area of interest (in pixels).
|
||||
CAP_PROP_XI_OFFSET_Y = 403, // Vertical offset from the origin to the area of interest (in pixels).
|
||||
CAP_PROP_XI_TRG_SOURCE = 404, // Defines source of trigger.
|
||||
CAP_PROP_XI_TRG_SOFTWARE = 405, // Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE.
|
||||
CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input
|
||||
CAP_PROP_XI_GPI_MODE = 407, // Set general purpose input mode
|
||||
CAP_PROP_XI_GPI_LEVEL = 408, // Get general purpose level
|
||||
CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output
|
||||
CAP_PROP_XI_GPO_MODE = 410, // Set general purpose output mode
|
||||
CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED
|
||||
CAP_PROP_XI_LED_MODE = 412, // Define camera signalling LED functionality
|
||||
CAP_PROP_XI_MANUAL_WB = 413, // Calculates White Balance(must be called during acquisition)
|
||||
CAP_PROP_XI_AUTO_WB = 414, // Automatic white balance
|
||||
CAP_PROP_XI_AEAG = 415, // Automatic exposure/gain
|
||||
CAP_PROP_XI_EXP_PRIORITY = 416, // Exposure priority (0.5 - exposure 50%, gain 50%).
|
||||
CAP_PROP_XI_AE_MAX_LIMIT = 417, // Maximum limit of exposure in AEAG procedure
|
||||
CAP_PROP_XI_AG_MAX_LIMIT = 418, // Maximum limit of gain in AEAG procedure
|
||||
CAP_PROP_XI_AEAG_LEVEL = 419, // Average intensity of output signal AEAG should achieve(in %)
|
||||
CAP_PROP_XI_TIMEOUT = 420 // Image capture timeout in milliseconds
|
||||
};
|
||||
|
||||
|
||||
// Properties for Android cameras
|
||||
enum { CAP_PROP_ANDROID_AUTOGRAB = 1024,
|
||||
CAP_PROP_ANDROID_PREVIEW_SIZES_STRING = 1025, // readonly, tricky property, returns const char* indeed
|
||||
CAP_PROP_ANDROID_PREVIEW_FORMAT = 1026, // readonly, tricky property, returns const char* indeed
|
||||
CAP_PROP_ANDROID_FLASH_MODE = 8001,
|
||||
CAP_PROP_ANDROID_FOCUS_MODE = 8002,
|
||||
CAP_PROP_ANDROID_WHITE_BALANCE = 8003,
|
||||
CAP_PROP_ANDROID_ANTIBANDING = 8004,
|
||||
CAP_PROP_ANDROID_FOCAL_LENGTH = 8005,
|
||||
CAP_PROP_ANDROID_FOCUS_DISTANCE_NEAR = 8006,
|
||||
CAP_PROP_ANDROID_FOCUS_DISTANCE_OPTIMAL = 8007,
|
||||
CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR = 8008
|
||||
};
|
||||
|
||||
|
||||
// Android camera output formats
|
||||
enum { CAP_ANDROID_COLOR_FRAME_BGR = 0, //BGR
|
||||
CAP_ANDROID_COLOR_FRAME = CAP_ANDROID_COLOR_FRAME_BGR,
|
||||
CAP_ANDROID_GREY_FRAME = 1, //Y
|
||||
CAP_ANDROID_COLOR_FRAME_RGB = 2,
|
||||
CAP_ANDROID_COLOR_FRAME_BGRA = 3,
|
||||
CAP_ANDROID_COLOR_FRAME_RGBA = 4
|
||||
};
|
||||
|
||||
|
||||
// Android camera flash modes
|
||||
enum { CAP_ANDROID_FLASH_MODE_AUTO = 0,
|
||||
CAP_ANDROID_FLASH_MODE_OFF = 1,
|
||||
CAP_ANDROID_FLASH_MODE_ON = 2,
|
||||
CAP_ANDROID_FLASH_MODE_RED_EYE = 3,
|
||||
CAP_ANDROID_FLASH_MODE_TORCH = 4
|
||||
};
|
||||
|
||||
|
||||
// Android camera focus modes
|
||||
enum { CAP_ANDROID_FOCUS_MODE_AUTO = 0,
|
||||
CAP_ANDROID_FOCUS_MODE_CONTINUOUS_VIDEO = 1,
|
||||
CAP_ANDROID_FOCUS_MODE_EDOF = 2,
|
||||
CAP_ANDROID_FOCUS_MODE_FIXED = 3,
|
||||
CAP_ANDROID_FOCUS_MODE_INFINITY = 4,
|
||||
CAP_ANDROID_FOCUS_MODE_MACRO = 5
|
||||
};
|
||||
|
||||
|
||||
// Android camera white balance modes
|
||||
enum { CAP_ANDROID_WHITE_BALANCE_AUTO = 0,
|
||||
CAP_ANDROID_WHITE_BALANCE_CLOUDY_DAYLIGHT = 1,
|
||||
CAP_ANDROID_WHITE_BALANCE_DAYLIGHT = 2,
|
||||
CAP_ANDROID_WHITE_BALANCE_FLUORESCENT = 3,
|
||||
CAP_ANDROID_WHITE_BALANCE_INCANDESCENT = 4,
|
||||
CAP_ANDROID_WHITE_BALANCE_SHADE = 5,
|
||||
CAP_ANDROID_WHITE_BALANCE_TWILIGHT = 6,
|
||||
CAP_ANDROID_WHITE_BALANCE_WARM_FLUORESCENT = 7
|
||||
};
|
||||
|
||||
|
||||
// Android camera antibanding modes
|
||||
enum { CAP_ANDROID_ANTIBANDING_50HZ = 0,
|
||||
CAP_ANDROID_ANTIBANDING_60HZ = 1,
|
||||
CAP_ANDROID_ANTIBANDING_AUTO = 2,
|
||||
CAP_ANDROID_ANTIBANDING_OFF = 3
|
||||
};
|
||||
|
||||
|
||||
// Properties of cameras available through AVFOUNDATION interface
|
||||
enum { CAP_PROP_IOS_DEVICE_FOCUS = 9001,
|
||||
CAP_PROP_IOS_DEVICE_EXPOSURE = 9002,
|
||||
CAP_PROP_IOS_DEVICE_FLASH = 9003,
|
||||
CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004,
|
||||
CAP_PROP_IOS_DEVICE_TORCH = 9005
|
||||
};
|
||||
|
||||
|
||||
// Properties of cameras available through Smartek Giganetix Ethernet Vision interface
|
||||
/* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */
|
||||
enum { CAP_PROP_GIGA_FRAME_OFFSET_X = 10001,
|
||||
CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002,
|
||||
CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003,
|
||||
CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004,
|
||||
CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005,
|
||||
CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006
|
||||
};
|
||||
|
||||
enum { CAP_PROP_INTELPERC_PROFILE_COUNT = 11001,
|
||||
CAP_PROP_INTELPERC_PROFILE_IDX = 11002,
|
||||
CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE = 11003,
|
||||
CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE = 11004,
|
||||
CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD = 11005,
|
||||
CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ = 11006,
|
||||
CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT = 11007
|
||||
};
|
||||
|
||||
// Intel PerC streams
|
||||
enum { CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29,
|
||||
CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28,
|
||||
CAP_INTELPERC_GENERATORS_MASK = CAP_INTELPERC_DEPTH_GENERATOR + CAP_INTELPERC_IMAGE_GENERATOR
|
||||
};
|
||||
|
||||
enum { CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth.
|
||||
CAP_INTELPERC_UVDEPTH_MAP = 1, // Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates.
|
||||
CAP_INTELPERC_IR_MAP = 2, // Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam.
|
||||
CAP_INTELPERC_IMAGE = 3
|
||||
};
|
||||
|
||||
|
||||
class IVideoCapture;
|
||||
class CV_EXPORTS_W VideoCapture
|
||||
{
|
||||
public:
|
||||
CV_WRAP VideoCapture();
|
||||
CV_WRAP VideoCapture(const String& filename);
|
||||
CV_WRAP VideoCapture(int device);
|
||||
|
||||
virtual ~VideoCapture();
|
||||
CV_WRAP virtual bool open(const String& filename);
|
||||
CV_WRAP virtual bool open(int device);
|
||||
CV_WRAP virtual bool isOpened() const;
|
||||
CV_WRAP virtual void release();
|
||||
|
||||
CV_WRAP virtual bool grab();
|
||||
CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0);
|
||||
virtual VideoCapture& operator >> (CV_OUT Mat& image);
|
||||
virtual VideoCapture& operator >> (CV_OUT UMat& image);
|
||||
CV_WRAP virtual bool read(OutputArray image);
|
||||
|
||||
CV_WRAP virtual bool set(int propId, double value);
|
||||
CV_WRAP virtual double get(int propId);
|
||||
|
||||
protected:
|
||||
Ptr<CvCapture> cap;
|
||||
Ptr<IVideoCapture> icap;
|
||||
private:
|
||||
static Ptr<IVideoCapture> createCameraCapture(int index);
|
||||
};
|
||||
|
||||
class CV_EXPORTS_W VideoWriter
|
||||
{
|
||||
public:
|
||||
CV_WRAP VideoWriter();
|
||||
CV_WRAP VideoWriter(const String& filename, int fourcc, double fps,
|
||||
Size frameSize, bool isColor = true);
|
||||
|
||||
virtual ~VideoWriter();
|
||||
CV_WRAP virtual bool open(const String& filename, int fourcc, double fps,
|
||||
Size frameSize, bool isColor = true);
|
||||
CV_WRAP virtual bool isOpened() const;
|
||||
CV_WRAP virtual void release();
|
||||
virtual VideoWriter& operator << (const Mat& image);
|
||||
CV_WRAP virtual void write(const Mat& image);
|
||||
|
||||
CV_WRAP static int fourcc(char c1, char c2, char c3, char c4);
|
||||
|
||||
protected:
|
||||
Ptr<CvVideoWriter> writer;
|
||||
};
|
||||
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvCapture>::operator ()(CvCapture* obj) const;
|
||||
template<> CV_EXPORTS void DefaultDeleter<CvVideoWriter>::operator ()(CvVideoWriter* obj) const;
|
||||
|
||||
} // cv
|
||||
|
||||
#endif
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
#define __OPENCV_HIGHGUI_H__
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/imgcodecs/imgcodecs_c.h"
|
||||
#include "opencv2/videoio/videoio_c.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -194,67 +196,6 @@ typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, vo
|
||||
CVAPI(void) cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse,
|
||||
void* param CV_DEFAULT(NULL));
|
||||
|
||||
enum
|
||||
{
|
||||
/* 8bit, color or not */
|
||||
CV_LOAD_IMAGE_UNCHANGED =-1,
|
||||
/* 8bit, gray */
|
||||
CV_LOAD_IMAGE_GRAYSCALE =0,
|
||||
/* ?, color */
|
||||
CV_LOAD_IMAGE_COLOR =1,
|
||||
/* any depth, ? */
|
||||
CV_LOAD_IMAGE_ANYDEPTH =2,
|
||||
/* ?, any color */
|
||||
CV_LOAD_IMAGE_ANYCOLOR =4
|
||||
};
|
||||
|
||||
/* load image from file
|
||||
iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
|
||||
overrides the other flags
|
||||
using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
|
||||
unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
|
||||
*/
|
||||
CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
|
||||
enum
|
||||
{
|
||||
CV_IMWRITE_JPEG_QUALITY =1,
|
||||
CV_IMWRITE_JPEG_PROGRESSIVE =2,
|
||||
CV_IMWRITE_JPEG_OPTIMIZE =3,
|
||||
CV_IMWRITE_PNG_COMPRESSION =16,
|
||||
CV_IMWRITE_PNG_STRATEGY =17,
|
||||
CV_IMWRITE_PNG_BILEVEL =18,
|
||||
CV_IMWRITE_PNG_STRATEGY_DEFAULT =0,
|
||||
CV_IMWRITE_PNG_STRATEGY_FILTERED =1,
|
||||
CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2,
|
||||
CV_IMWRITE_PNG_STRATEGY_RLE =3,
|
||||
CV_IMWRITE_PNG_STRATEGY_FIXED =4,
|
||||
CV_IMWRITE_PXM_BINARY =32,
|
||||
CV_IMWRITE_WEBP_QUALITY =64
|
||||
};
|
||||
|
||||
/* save image to file */
|
||||
CVAPI(int) cvSaveImage( const char* filename, const CvArr* image,
|
||||
const int* params CV_DEFAULT(0) );
|
||||
|
||||
/* decode image stored in the buffer */
|
||||
CVAPI(IplImage*) cvDecodeImage( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
CVAPI(CvMat*) cvDecodeImageM( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
|
||||
/* encode image and store the result as a byte vector (single-row 8uC1 matrix) */
|
||||
CVAPI(CvMat*) cvEncodeImage( const char* ext, const CvArr* image,
|
||||
const int* params CV_DEFAULT(0) );
|
||||
|
||||
enum
|
||||
{
|
||||
CV_CVTIMG_FLIP =1,
|
||||
CV_CVTIMG_SWAP_RB =2
|
||||
};
|
||||
|
||||
/* utility function: convert one image to another with optional vertical flip */
|
||||
CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
|
||||
|
||||
/* wait for key event infinitely (delay<=0) or for "delay" milliseconds */
|
||||
CVAPI(int) cvWaitKey(int delay CV_DEFAULT(0));
|
||||
|
||||
@@ -268,363 +209,10 @@ CVAPI(void) cvUpdateWindow(const char* window_name);
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* Working with Video Files and Cameras *
|
||||
\****************************************************************************************/
|
||||
|
||||
/* "black box" capture structure */
|
||||
typedef struct CvCapture CvCapture;
|
||||
|
||||
/* start capturing frames from video file */
|
||||
CVAPI(CvCapture*) cvCreateFileCapture( const char* filename );
|
||||
|
||||
enum
|
||||
{
|
||||
CV_CAP_ANY =0, // autodetect
|
||||
|
||||
CV_CAP_MIL =100, // MIL proprietary drivers
|
||||
|
||||
CV_CAP_VFW =200, // platform native
|
||||
CV_CAP_V4L =200,
|
||||
CV_CAP_V4L2 =200,
|
||||
|
||||
CV_CAP_FIREWARE =300, // IEEE 1394 drivers
|
||||
CV_CAP_FIREWIRE =300,
|
||||
CV_CAP_IEEE1394 =300,
|
||||
CV_CAP_DC1394 =300,
|
||||
CV_CAP_CMU1394 =300,
|
||||
|
||||
CV_CAP_STEREO =400, // TYZX proprietary drivers
|
||||
CV_CAP_TYZX =400,
|
||||
CV_TYZX_LEFT =400,
|
||||
CV_TYZX_RIGHT =401,
|
||||
CV_TYZX_COLOR =402,
|
||||
CV_TYZX_Z =403,
|
||||
|
||||
CV_CAP_QT =500, // QuickTime
|
||||
|
||||
CV_CAP_UNICAP =600, // Unicap drivers
|
||||
|
||||
CV_CAP_DSHOW =700, // DirectShow (via videoInput)
|
||||
CV_CAP_MSMF =1400, // Microsoft Media Foundation (via videoInput)
|
||||
|
||||
CV_CAP_PVAPI =800, // PvAPI, Prosilica GigE SDK
|
||||
|
||||
CV_CAP_OPENNI =900, // OpenNI (for Kinect)
|
||||
CV_CAP_OPENNI_ASUS =910, // OpenNI (for Asus Xtion)
|
||||
|
||||
CV_CAP_ANDROID =1000, // Android
|
||||
CV_CAP_ANDROID_BACK =CV_CAP_ANDROID+99, // Android back camera
|
||||
CV_CAP_ANDROID_FRONT =CV_CAP_ANDROID+98, // Android front camera
|
||||
|
||||
CV_CAP_XIAPI =1100, // XIMEA Camera API
|
||||
|
||||
CV_CAP_AVFOUNDATION = 1200, // AVFoundation framework for iOS (OS X Lion will have the same API)
|
||||
|
||||
CV_CAP_GIGANETIX = 1300, // Smartek Giganetix GigEVisionSDK
|
||||
|
||||
CV_CAP_INTELPERC = 1500 // Intel Perceptual Computing SDK
|
||||
};
|
||||
|
||||
/* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */
|
||||
CVAPI(CvCapture*) cvCreateCameraCapture( int index );
|
||||
|
||||
/* grab a frame, return 1 on success, 0 on fail.
|
||||
this function is thought to be fast */
|
||||
CVAPI(int) cvGrabFrame( CvCapture* capture );
|
||||
|
||||
/* get the frame grabbed with cvGrabFrame(..)
|
||||
This function may apply some frame processing like
|
||||
frame decompression, flipping etc.
|
||||
!!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
|
||||
CVAPI(IplImage*) cvRetrieveFrame( CvCapture* capture, int streamIdx CV_DEFAULT(0) );
|
||||
|
||||
/* Just a combination of cvGrabFrame and cvRetrieveFrame
|
||||
!!!DO NOT RELEASE or MODIFY the retrieved frame!!! */
|
||||
CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
|
||||
|
||||
/* stop capturing/reading and free resources */
|
||||
CVAPI(void) cvReleaseCapture( CvCapture** capture );
|
||||
|
||||
enum
|
||||
{
|
||||
// modes of the controlling registers (can be: auto, manual, auto single push, absolute Latter allowed with any other mode)
|
||||
// every feature can have only one mode turned on at a time
|
||||
CV_CAP_PROP_DC1394_OFF = -4, //turn the feature off (not controlled manually nor automatically)
|
||||
CV_CAP_PROP_DC1394_MODE_MANUAL = -3, //set automatically when a value of the feature is set by the user
|
||||
CV_CAP_PROP_DC1394_MODE_AUTO = -2,
|
||||
CV_CAP_PROP_DC1394_MODE_ONE_PUSH_AUTO = -1,
|
||||
CV_CAP_PROP_POS_MSEC =0,
|
||||
CV_CAP_PROP_POS_FRAMES =1,
|
||||
CV_CAP_PROP_POS_AVI_RATIO =2,
|
||||
CV_CAP_PROP_FRAME_WIDTH =3,
|
||||
CV_CAP_PROP_FRAME_HEIGHT =4,
|
||||
CV_CAP_PROP_FPS =5,
|
||||
CV_CAP_PROP_FOURCC =6,
|
||||
CV_CAP_PROP_FRAME_COUNT =7,
|
||||
CV_CAP_PROP_FORMAT =8,
|
||||
CV_CAP_PROP_MODE =9,
|
||||
CV_CAP_PROP_BRIGHTNESS =10,
|
||||
CV_CAP_PROP_CONTRAST =11,
|
||||
CV_CAP_PROP_SATURATION =12,
|
||||
CV_CAP_PROP_HUE =13,
|
||||
CV_CAP_PROP_GAIN =14,
|
||||
CV_CAP_PROP_EXPOSURE =15,
|
||||
CV_CAP_PROP_CONVERT_RGB =16,
|
||||
CV_CAP_PROP_WHITE_BALANCE_BLUE_U =17,
|
||||
CV_CAP_PROP_RECTIFICATION =18,
|
||||
CV_CAP_PROP_MONOCROME =19,
|
||||
CV_CAP_PROP_SHARPNESS =20,
|
||||
CV_CAP_PROP_AUTO_EXPOSURE =21, // exposure control done by camera,
|
||||
// user can adjust refernce level
|
||||
// using this feature
|
||||
CV_CAP_PROP_GAMMA =22,
|
||||
CV_CAP_PROP_TEMPERATURE =23,
|
||||
CV_CAP_PROP_TRIGGER =24,
|
||||
CV_CAP_PROP_TRIGGER_DELAY =25,
|
||||
CV_CAP_PROP_WHITE_BALANCE_RED_V =26,
|
||||
CV_CAP_PROP_ZOOM =27,
|
||||
CV_CAP_PROP_FOCUS =28,
|
||||
CV_CAP_PROP_GUID =29,
|
||||
CV_CAP_PROP_ISO_SPEED =30,
|
||||
CV_CAP_PROP_MAX_DC1394 =31,
|
||||
CV_CAP_PROP_BACKLIGHT =32,
|
||||
CV_CAP_PROP_PAN =33,
|
||||
CV_CAP_PROP_TILT =34,
|
||||
CV_CAP_PROP_ROLL =35,
|
||||
CV_CAP_PROP_IRIS =36,
|
||||
CV_CAP_PROP_SETTINGS =37,
|
||||
|
||||
CV_CAP_PROP_AUTOGRAB =1024, // property for highgui class CvCapture_Android only
|
||||
CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING=1025, // readonly, tricky property, returns cpnst char* indeed
|
||||
CV_CAP_PROP_PREVIEW_FORMAT=1026, // readonly, tricky property, returns cpnst char* indeed
|
||||
|
||||
// OpenNI map generators
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR = 1 << 31,
|
||||
CV_CAP_OPENNI_IMAGE_GENERATOR = 1 << 30,
|
||||
CV_CAP_OPENNI_GENERATORS_MASK = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_OPENNI_IMAGE_GENERATOR,
|
||||
|
||||
// Properties of cameras available through OpenNI interfaces
|
||||
CV_CAP_PROP_OPENNI_OUTPUT_MODE = 100,
|
||||
CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH = 101, // in mm
|
||||
CV_CAP_PROP_OPENNI_BASELINE = 102, // in mm
|
||||
CV_CAP_PROP_OPENNI_FOCAL_LENGTH = 103, // in pixels
|
||||
CV_CAP_PROP_OPENNI_REGISTRATION = 104, // flag
|
||||
CV_CAP_PROP_OPENNI_REGISTRATION_ON = CV_CAP_PROP_OPENNI_REGISTRATION, // flag that synchronizes the remapping depth map to image map
|
||||
// by changing depth generator's view point (if the flag is "on") or
|
||||
// sets this view point to its normal one (if the flag is "off").
|
||||
CV_CAP_PROP_OPENNI_APPROX_FRAME_SYNC = 105,
|
||||
CV_CAP_PROP_OPENNI_MAX_BUFFER_SIZE = 106,
|
||||
CV_CAP_PROP_OPENNI_CIRCLE_BUFFER = 107,
|
||||
CV_CAP_PROP_OPENNI_MAX_TIME_DURATION = 108,
|
||||
|
||||
CV_CAP_PROP_OPENNI_GENERATOR_PRESENT = 109,
|
||||
|
||||
CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_GENERATOR_PRESENT,
|
||||
CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE = CV_CAP_OPENNI_IMAGE_GENERATOR + CV_CAP_PROP_OPENNI_OUTPUT_MODE,
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_BASELINE,
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_FOCAL_LENGTH,
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION = CV_CAP_OPENNI_DEPTH_GENERATOR + CV_CAP_PROP_OPENNI_REGISTRATION,
|
||||
CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION_ON = CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION,
|
||||
|
||||
// Properties of cameras available through GStreamer interface
|
||||
CV_CAP_GSTREAMER_QUEUE_LENGTH = 200, // default is 1
|
||||
|
||||
// PVAPI
|
||||
CV_CAP_PROP_PVAPI_MULTICASTIP = 300, // ip for anable multicast master mode. 0 for disable multicast
|
||||
CV_CAP_PROP_PVAPI_FRAMESTARTTRIGGERMODE = 301, // FrameStartTriggerMode: Determines how a frame is initiated
|
||||
|
||||
// Properties of cameras available through XIMEA SDK interface
|
||||
CV_CAP_PROP_XI_DOWNSAMPLING = 400, // Change image resolution by binning or skipping.
|
||||
CV_CAP_PROP_XI_DATA_FORMAT = 401, // Output data format.
|
||||
CV_CAP_PROP_XI_OFFSET_X = 402, // Horizontal offset from the origin to the area of interest (in pixels).
|
||||
CV_CAP_PROP_XI_OFFSET_Y = 403, // Vertical offset from the origin to the area of interest (in pixels).
|
||||
CV_CAP_PROP_XI_TRG_SOURCE = 404, // Defines source of trigger.
|
||||
CV_CAP_PROP_XI_TRG_SOFTWARE = 405, // Generates an internal trigger. PRM_TRG_SOURCE must be set to TRG_SOFTWARE.
|
||||
CV_CAP_PROP_XI_GPI_SELECTOR = 406, // Selects general purpose input
|
||||
CV_CAP_PROP_XI_GPI_MODE = 407, // Set general purpose input mode
|
||||
CV_CAP_PROP_XI_GPI_LEVEL = 408, // Get general purpose level
|
||||
CV_CAP_PROP_XI_GPO_SELECTOR = 409, // Selects general purpose output
|
||||
CV_CAP_PROP_XI_GPO_MODE = 410, // Set general purpose output mode
|
||||
CV_CAP_PROP_XI_LED_SELECTOR = 411, // Selects camera signalling LED
|
||||
CV_CAP_PROP_XI_LED_MODE = 412, // Define camera signalling LED functionality
|
||||
CV_CAP_PROP_XI_MANUAL_WB = 413, // Calculates White Balance(must be called during acquisition)
|
||||
CV_CAP_PROP_XI_AUTO_WB = 414, // Automatic white balance
|
||||
CV_CAP_PROP_XI_AEAG = 415, // Automatic exposure/gain
|
||||
CV_CAP_PROP_XI_EXP_PRIORITY = 416, // Exposure priority (0.5 - exposure 50%, gain 50%).
|
||||
CV_CAP_PROP_XI_AE_MAX_LIMIT = 417, // Maximum limit of exposure in AEAG procedure
|
||||
CV_CAP_PROP_XI_AG_MAX_LIMIT = 418, // Maximum limit of gain in AEAG procedure
|
||||
CV_CAP_PROP_XI_AEAG_LEVEL = 419, // Average intensity of output signal AEAG should achieve(in %)
|
||||
CV_CAP_PROP_XI_TIMEOUT = 420, // Image capture timeout in milliseconds
|
||||
|
||||
// Properties for Android cameras
|
||||
CV_CAP_PROP_ANDROID_FLASH_MODE = 8001,
|
||||
CV_CAP_PROP_ANDROID_FOCUS_MODE = 8002,
|
||||
CV_CAP_PROP_ANDROID_WHITE_BALANCE = 8003,
|
||||
CV_CAP_PROP_ANDROID_ANTIBANDING = 8004,
|
||||
CV_CAP_PROP_ANDROID_FOCAL_LENGTH = 8005,
|
||||
CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_NEAR = 8006,
|
||||
CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_OPTIMAL = 8007,
|
||||
CV_CAP_PROP_ANDROID_FOCUS_DISTANCE_FAR = 8008,
|
||||
CV_CAP_PROP_ANDROID_EXPOSE_LOCK = 8009,
|
||||
CV_CAP_PROP_ANDROID_WHITEBALANCE_LOCK = 8010,
|
||||
|
||||
// Properties of cameras available through AVFOUNDATION interface
|
||||
CV_CAP_PROP_IOS_DEVICE_FOCUS = 9001,
|
||||
CV_CAP_PROP_IOS_DEVICE_EXPOSURE = 9002,
|
||||
CV_CAP_PROP_IOS_DEVICE_FLASH = 9003,
|
||||
CV_CAP_PROP_IOS_DEVICE_WHITEBALANCE = 9004,
|
||||
CV_CAP_PROP_IOS_DEVICE_TORCH = 9005,
|
||||
|
||||
// Properties of cameras available through Smartek Giganetix Ethernet Vision interface
|
||||
/* --- Vladimir Litvinenko (litvinenko.vladimir@gmail.com) --- */
|
||||
CV_CAP_PROP_GIGA_FRAME_OFFSET_X = 10001,
|
||||
CV_CAP_PROP_GIGA_FRAME_OFFSET_Y = 10002,
|
||||
CV_CAP_PROP_GIGA_FRAME_WIDTH_MAX = 10003,
|
||||
CV_CAP_PROP_GIGA_FRAME_HEIGH_MAX = 10004,
|
||||
CV_CAP_PROP_GIGA_FRAME_SENS_WIDTH = 10005,
|
||||
CV_CAP_PROP_GIGA_FRAME_SENS_HEIGH = 10006,
|
||||
|
||||
CV_CAP_PROP_INTELPERC_PROFILE_COUNT = 11001,
|
||||
CV_CAP_PROP_INTELPERC_PROFILE_IDX = 11002,
|
||||
CV_CAP_PROP_INTELPERC_DEPTH_LOW_CONFIDENCE_VALUE = 11003,
|
||||
CV_CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE = 11004,
|
||||
CV_CAP_PROP_INTELPERC_DEPTH_CONFIDENCE_THRESHOLD = 11005,
|
||||
CV_CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_HORZ = 11006,
|
||||
CV_CAP_PROP_INTELPERC_DEPTH_FOCAL_LENGTH_VERT = 11007,
|
||||
|
||||
// Intel PerC streams
|
||||
CV_CAP_INTELPERC_DEPTH_GENERATOR = 1 << 29,
|
||||
CV_CAP_INTELPERC_IMAGE_GENERATOR = 1 << 28,
|
||||
CV_CAP_INTELPERC_GENERATORS_MASK = CV_CAP_INTELPERC_DEPTH_GENERATOR + CV_CAP_INTELPERC_IMAGE_GENERATOR
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
// Data given from depth generator.
|
||||
CV_CAP_OPENNI_DEPTH_MAP = 0, // Depth values in mm (CV_16UC1)
|
||||
CV_CAP_OPENNI_POINT_CLOUD_MAP = 1, // XYZ in meters (CV_32FC3)
|
||||
CV_CAP_OPENNI_DISPARITY_MAP = 2, // Disparity in pixels (CV_8UC1)
|
||||
CV_CAP_OPENNI_DISPARITY_MAP_32F = 3, // Disparity in pixels (CV_32FC1)
|
||||
CV_CAP_OPENNI_VALID_DEPTH_MASK = 4, // CV_8UC1
|
||||
|
||||
// Data given from RGB image generator.
|
||||
CV_CAP_OPENNI_BGR_IMAGE = 5,
|
||||
CV_CAP_OPENNI_GRAY_IMAGE = 6
|
||||
};
|
||||
|
||||
// Supported output modes of OpenNI image generator
|
||||
enum
|
||||
{
|
||||
CV_CAP_OPENNI_VGA_30HZ = 0,
|
||||
CV_CAP_OPENNI_SXGA_15HZ = 1,
|
||||
CV_CAP_OPENNI_SXGA_30HZ = 2,
|
||||
CV_CAP_OPENNI_QVGA_30HZ = 3,
|
||||
CV_CAP_OPENNI_QVGA_60HZ = 4
|
||||
};
|
||||
|
||||
//supported by Android camera output formats
|
||||
enum
|
||||
{
|
||||
CV_CAP_ANDROID_COLOR_FRAME_BGR = 0, //BGR
|
||||
CV_CAP_ANDROID_COLOR_FRAME = CV_CAP_ANDROID_COLOR_FRAME_BGR,
|
||||
CV_CAP_ANDROID_GREY_FRAME = 1, //Y
|
||||
CV_CAP_ANDROID_COLOR_FRAME_RGB = 2,
|
||||
CV_CAP_ANDROID_COLOR_FRAME_BGRA = 3,
|
||||
CV_CAP_ANDROID_COLOR_FRAME_RGBA = 4
|
||||
};
|
||||
|
||||
// supported Android camera flash modes
|
||||
enum
|
||||
{
|
||||
CV_CAP_ANDROID_FLASH_MODE_AUTO = 0,
|
||||
CV_CAP_ANDROID_FLASH_MODE_OFF,
|
||||
CV_CAP_ANDROID_FLASH_MODE_ON,
|
||||
CV_CAP_ANDROID_FLASH_MODE_RED_EYE,
|
||||
CV_CAP_ANDROID_FLASH_MODE_TORCH
|
||||
};
|
||||
|
||||
// supported Android camera focus modes
|
||||
enum
|
||||
{
|
||||
CV_CAP_ANDROID_FOCUS_MODE_AUTO = 0,
|
||||
CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_PICTURE,
|
||||
CV_CAP_ANDROID_FOCUS_MODE_CONTINUOUS_VIDEO,
|
||||
CV_CAP_ANDROID_FOCUS_MODE_EDOF,
|
||||
CV_CAP_ANDROID_FOCUS_MODE_FIXED,
|
||||
CV_CAP_ANDROID_FOCUS_MODE_INFINITY,
|
||||
CV_CAP_ANDROID_FOCUS_MODE_MACRO
|
||||
};
|
||||
|
||||
// supported Android camera white balance modes
|
||||
enum
|
||||
{
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_AUTO = 0,
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_CLOUDY_DAYLIGHT,
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_DAYLIGHT,
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_FLUORESCENT,
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_INCANDESCENT,
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_SHADE,
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_TWILIGHT,
|
||||
CV_CAP_ANDROID_WHITE_BALANCE_WARM_FLUORESCENT
|
||||
};
|
||||
|
||||
// supported Android camera antibanding modes
|
||||
enum
|
||||
{
|
||||
CV_CAP_ANDROID_ANTIBANDING_50HZ = 0,
|
||||
CV_CAP_ANDROID_ANTIBANDING_60HZ,
|
||||
CV_CAP_ANDROID_ANTIBANDING_AUTO,
|
||||
CV_CAP_ANDROID_ANTIBANDING_OFF
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CV_CAP_INTELPERC_DEPTH_MAP = 0, // Each pixel is a 16-bit integer. The value indicates the distance from an object to the camera's XY plane or the Cartesian depth.
|
||||
CV_CAP_INTELPERC_UVDEPTH_MAP = 1, // Each pixel contains two 32-bit floating point values in the range of 0-1, representing the mapping of depth coordinates to the color coordinates.
|
||||
CV_CAP_INTELPERC_IR_MAP = 2, // Each pixel is a 16-bit integer. The value indicates the intensity of the reflected laser beam.
|
||||
CV_CAP_INTELPERC_IMAGE = 3
|
||||
};
|
||||
|
||||
/* retrieve or set capture properties */
|
||||
CVAPI(double) cvGetCaptureProperty( CvCapture* capture, int property_id );
|
||||
CVAPI(int) cvSetCaptureProperty( CvCapture* capture, int property_id, double value );
|
||||
|
||||
// Return the type of the capturer (eg, CV_CAP_V4W, CV_CAP_UNICAP), which is unknown if created with CV_CAP_ANY
|
||||
CVAPI(int) cvGetCaptureDomain( CvCapture* capture);
|
||||
|
||||
/* "black box" video file writer structure */
|
||||
typedef struct CvVideoWriter CvVideoWriter;
|
||||
|
||||
#define CV_FOURCC_MACRO(c1, c2, c3, c4) (((c1) & 255) + (((c2) & 255) << 8) + (((c3) & 255) << 16) + (((c4) & 255) << 24))
|
||||
|
||||
CV_INLINE int CV_FOURCC(char c1, char c2, char c3, char c4)
|
||||
{
|
||||
return CV_FOURCC_MACRO(c1, c2, c3, c4);
|
||||
}
|
||||
|
||||
#define CV_FOURCC_PROMPT -1 /* Open Codec Selection Dialog (Windows only) */
|
||||
#define CV_FOURCC_DEFAULT CV_FOURCC('I', 'Y', 'U', 'V') /* Use default codec for specified filename (Linux only) */
|
||||
|
||||
/* initialize video file writer */
|
||||
CVAPI(CvVideoWriter*) cvCreateVideoWriter( const char* filename, int fourcc,
|
||||
double fps, CvSize frame_size,
|
||||
int is_color CV_DEFAULT(1));
|
||||
|
||||
/* write frame to video file */
|
||||
CVAPI(int) cvWriteFrame( CvVideoWriter* writer, const IplImage* image );
|
||||
|
||||
/* close video file writer */
|
||||
CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
|
||||
|
||||
/****************************************************************************************\
|
||||
* Obsolete functions/synonyms *
|
||||
\****************************************************************************************/
|
||||
|
||||
#define cvCaptureFromFile cvCreateFileCapture
|
||||
#define cvCaptureFromCAM cvCreateCameraCapture
|
||||
#define cvCaptureFromAVI cvCaptureFromFile
|
||||
#define cvCreateAVIWriter cvCreateVideoWriter
|
||||
#define cvWriteToAVI cvWriteFrame
|
||||
#define cvAddSearchPath(path)
|
||||
#define cvvInitSystem cvInitSystem
|
||||
#define cvvNamedWindow cvNamedWindow
|
||||
@@ -632,12 +220,9 @@ CVAPI(void) cvReleaseVideoWriter( CvVideoWriter** writer );
|
||||
#define cvvResizeWindow cvResizeWindow
|
||||
#define cvvDestroyWindow cvDestroyWindow
|
||||
#define cvvCreateTrackbar cvCreateTrackbar
|
||||
#define cvvLoadImage(name) cvLoadImage((name),1)
|
||||
#define cvvSaveImage cvSaveImage
|
||||
#define cvvAddSearchPath cvAddSearchPath
|
||||
#define cvvWaitKey(name) cvWaitKey(0)
|
||||
#define cvvWaitKeyEx(name,delay) cvWaitKey(delay)
|
||||
#define cvvConvertImage cvConvertImage
|
||||
#define HG_AUTOSIZE CV_WINDOW_AUTOSIZE
|
||||
#define set_preprocess_func cvSetPreprocessFuncWin32
|
||||
#define set_postprocess_func cvSetPostprocessFuncWin32
|
||||
|
||||
@@ -47,7 +47,10 @@
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/core/private.hpp"
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/imgcodecs/imgcodecs_c.h"
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -92,90 +95,6 @@
|
||||
#define CV_WINDOW_MAGIC_VAL 0x00420042
|
||||
#define CV_TRACKBAR_MAGIC_VAL 0x00420043
|
||||
|
||||
/***************************** CvCapture structure ******************************/
|
||||
|
||||
struct CvCapture
|
||||
{
|
||||
virtual ~CvCapture() {}
|
||||
virtual double getProperty(int) { return 0; }
|
||||
virtual bool setProperty(int, double) { return 0; }
|
||||
virtual bool grabFrame() { return true; }
|
||||
virtual IplImage* retrieveFrame(int) { return 0; }
|
||||
virtual int getCaptureDomain() { return CV_CAP_ANY; } // Return the type of the capture object: CV_CAP_VFW, etc...
|
||||
};
|
||||
|
||||
/*************************** CvVideoWriter structure ****************************/
|
||||
|
||||
struct CvVideoWriter
|
||||
{
|
||||
virtual ~CvVideoWriter() {}
|
||||
virtual bool writeFrame(const IplImage*) { return false; }
|
||||
};
|
||||
|
||||
CvCapture * cvCreateCameraCapture_V4L( int index );
|
||||
CvCapture * cvCreateCameraCapture_DC1394( int index );
|
||||
CvCapture * cvCreateCameraCapture_DC1394_2( int index );
|
||||
CvCapture* cvCreateCameraCapture_MIL( int index );
|
||||
CvCapture* cvCreateCameraCapture_Giganetix( int index );
|
||||
CvCapture * cvCreateCameraCapture_CMU( int index );
|
||||
CV_IMPL CvCapture * cvCreateCameraCapture_TYZX( int index );
|
||||
CvCapture* cvCreateFileCapture_Win32( const char* filename );
|
||||
CvCapture* cvCreateCameraCapture_VFW( int index );
|
||||
CvCapture* cvCreateFileCapture_VFW( const char* filename );
|
||||
CvVideoWriter* cvCreateVideoWriter_Win32( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color );
|
||||
CvVideoWriter* cvCreateVideoWriter_VFW( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color );
|
||||
CvCapture* cvCreateCameraCapture_DShow( int index );
|
||||
CvCapture* cvCreateCameraCapture_MSMF( int index );
|
||||
CvCapture* cvCreateFileCapture_MSMF (const char* filename);
|
||||
CvVideoWriter* cvCreateVideoWriter_MSMF( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color );
|
||||
CvCapture* cvCreateCameraCapture_OpenNI( int index );
|
||||
CvCapture* cvCreateFileCapture_OpenNI( const char* filename );
|
||||
CvCapture* cvCreateCameraCapture_Android( int index );
|
||||
CvCapture* cvCreateCameraCapture_XIMEA( int index );
|
||||
CvCapture* cvCreateCameraCapture_AVFoundation(int index);
|
||||
|
||||
CVAPI(int) cvHaveImageReader(const char* filename);
|
||||
CVAPI(int) cvHaveImageWriter(const char* filename);
|
||||
|
||||
CvCapture* cvCreateFileCapture_Images(const char* filename);
|
||||
CvVideoWriter* cvCreateVideoWriter_Images(const char* filename);
|
||||
|
||||
CvCapture* cvCreateFileCapture_XINE (const char* filename);
|
||||
|
||||
|
||||
|
||||
|
||||
#define CV_CAP_GSTREAMER_1394 0
|
||||
#define CV_CAP_GSTREAMER_V4L 1
|
||||
#define CV_CAP_GSTREAMER_V4L2 2
|
||||
#define CV_CAP_GSTREAMER_FILE 3
|
||||
|
||||
CvCapture* cvCreateCapture_GStreamer(int type, const char *filename);
|
||||
CvCapture* cvCreateFileCapture_FFMPEG_proxy(const char* filename);
|
||||
|
||||
|
||||
CvVideoWriter* cvCreateVideoWriter_FFMPEG_proxy( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color );
|
||||
|
||||
CvCapture * cvCreateFileCapture_QT (const char * filename);
|
||||
CvCapture * cvCreateCameraCapture_QT (const int index);
|
||||
|
||||
CvVideoWriter* cvCreateVideoWriter_QT ( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color );
|
||||
|
||||
CvCapture* cvCreateFileCapture_AVFoundation (const char * filename);
|
||||
CvVideoWriter* cvCreateVideoWriter_AVFoundation( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color );
|
||||
|
||||
|
||||
CvCapture * cvCreateCameraCapture_Unicap (const int index);
|
||||
CvCapture * cvCreateCameraCapture_PvAPI (const int index);
|
||||
CvVideoWriter* cvCreateVideoWriter_GStreamer( const char* filename, int fourcc,
|
||||
double fps, CvSize frameSize, int is_color );
|
||||
|
||||
//Yannick Verdie 2010
|
||||
void cvSetModeWindow_W32(const char* name, double prop_value);
|
||||
void cvSetModeWindow_GTK(const char* name, double prop_value);
|
||||
@@ -196,20 +115,6 @@ double cvGetRatioWindow_GTK(const char* name);
|
||||
double cvGetOpenGlProp_W32(const char* name);
|
||||
double cvGetOpenGlProp_GTK(const char* name);
|
||||
|
||||
namespace cv
|
||||
{
|
||||
class IVideoCapture
|
||||
{
|
||||
public:
|
||||
virtual ~IVideoCapture() {}
|
||||
virtual double getProperty(int) { return 0; }
|
||||
virtual bool setProperty(int, double) { return 0; }
|
||||
virtual bool grabFrame() = 0;
|
||||
virtual bool retrieveFrame(int, cv::OutputArray) = 0;
|
||||
virtual int getCaptureDomain() { return CAP_ANY; } // Return the type of the capture object: CAP_VFW, etc...
|
||||
};
|
||||
};
|
||||
|
||||
//for QT
|
||||
#if defined (HAVE_QT)
|
||||
double cvGetModeWindow_QT(const char* name);
|
||||
|
||||
@@ -1286,6 +1286,10 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
|
||||
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_COPY:
|
||||
::WindowProc(hwnd, uMsg, wParam, lParam); // call highgui proc. There may be a better way to do this.
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
|
||||
icvRemoveWindow(window);
|
||||
@@ -1448,6 +1452,81 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
|
||||
// Process the message
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_COPY:
|
||||
{
|
||||
if (!::OpenClipboard(hwnd) )
|
||||
break;
|
||||
|
||||
HDC hDC = 0;
|
||||
HDC memDC = 0;
|
||||
HBITMAP memBM = 0;
|
||||
|
||||
// We'll use a do-while(0){} scope as a single-run breakable scope
|
||||
// Upon any error we can jump out of the single-time while scope to clean up the resources.
|
||||
do
|
||||
{
|
||||
if (!::EmptyClipboard())
|
||||
break;
|
||||
|
||||
if(!window->image)
|
||||
break;
|
||||
|
||||
// Get window device context
|
||||
if (0 == (hDC = ::GetDC(hwnd)))
|
||||
break;
|
||||
|
||||
// Create another DC compatible with hDC
|
||||
if (0 == (memDC = ::CreateCompatibleDC( hDC )))
|
||||
break;
|
||||
|
||||
// Determine the bitmap's dimensions
|
||||
int nchannels = 3;
|
||||
SIZE size = {0,0};
|
||||
icvGetBitmapData( window, &size, &nchannels, 0 );
|
||||
|
||||
// Create bitmap to draw on and it in the new DC
|
||||
if (0 == (memBM = ::CreateCompatibleBitmap ( hDC, size.cx, size.cy)))
|
||||
break;
|
||||
|
||||
if (!::SelectObject( memDC, memBM ))
|
||||
break;
|
||||
|
||||
// Begin drawing to DC
|
||||
if (!::SetStretchBltMode(memDC, COLORONCOLOR))
|
||||
break;
|
||||
|
||||
RGBQUAD table[256];
|
||||
if( 1 == nchannels )
|
||||
{
|
||||
for(int i = 0; i < 256; ++i)
|
||||
{
|
||||
table[i].rgbBlue = (unsigned char)i;
|
||||
table[i].rgbGreen = (unsigned char)i;
|
||||
table[i].rgbRed = (unsigned char)i;
|
||||
}
|
||||
if (!::SetDIBColorTable(window->dc, 0, 255, table))
|
||||
break;
|
||||
}
|
||||
|
||||
// The image copied to the clipboard will be in its original size, regardless if the window itself was resized.
|
||||
|
||||
// Render the image to the dc/bitmap (at original size).
|
||||
if (!::BitBlt( memDC, 0, 0, size.cx, size.cy, window->dc, 0, 0, SRCCOPY ))
|
||||
break;
|
||||
|
||||
// Finally, set bitmap to clipboard
|
||||
::SetClipboardData(CF_BITMAP, memBM);
|
||||
} while (0,0); // (0,0) instead of (0) to avoid MSVC compiler warning C4127: "conditional expression is constant"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// if handle is allocated (i.e. != 0) then clean-up.
|
||||
if (memBM) ::DeleteObject(memBM);
|
||||
if (memDC) ::DeleteDC(memDC);
|
||||
if (hDC) ::ReleaseDC(hwnd, hDC);
|
||||
::CloseClipboard();
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_WINDOWPOSCHANGING:
|
||||
{
|
||||
LPWINDOWPOS pos = (LPWINDOWPOS)lParam;
|
||||
@@ -1798,6 +1877,11 @@ cvWaitKey( int delay )
|
||||
is_processed = 1;
|
||||
return (int)(message.wParam << 16);
|
||||
}
|
||||
|
||||
// Intercept Ctrl+C for copy to clipboard
|
||||
if ('C' == message.wParam && (::GetKeyState(VK_CONTROL)>>15))
|
||||
::PostMessage(message.hwnd, WM_COPY, 0, 0);
|
||||
|
||||
default:
|
||||
DispatchMessage(&message);
|
||||
is_processed = 1;
|
||||
|
||||
@@ -11,80 +11,11 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
//#include "opencv2/imgproc.hpp"
|
||||
//#include "opencv2/imgcodecs.hpp"
|
||||
//#include "opencv2/highgui.hpp"
|
||||
//#include "opencv2/imgproc/imgproc_c.h"
|
||||
|
||||
#include "opencv2/core/private.hpp"
|
||||
|
||||
#if defined(HAVE_DSHOW) || \
|
||||
defined(HAVE_TYZX) || \
|
||||
defined(HAVE_VFW) || \
|
||||
defined(HAVE_LIBV4L) || \
|
||||
(defined(HAVE_CAMV4L) && defined(HAVE_CAMV4L2)) || \
|
||||
defined(HAVE_GSTREAMER) || \
|
||||
defined(HAVE_DC1394_2) || \
|
||||
defined(HAVE_DC1394) || \
|
||||
defined(HAVE_CMU1394) || \
|
||||
defined(HAVE_MIL) || \
|
||||
defined(HAVE_QUICKTIME) || \
|
||||
defined(HAVE_QTKIT) || \
|
||||
defined(HAVE_UNICAP) || \
|
||||
defined(HAVE_PVAPI) || \
|
||||
defined(HAVE_OPENNI) || \
|
||||
defined(HAVE_XIMEA) || \
|
||||
defined(HAVE_AVFOUNDATION) || \
|
||||
defined(HAVE_GIGE_API) || \
|
||||
defined(HAVE_INTELPERC) || \
|
||||
(0)
|
||||
//defined(HAVE_ANDROID_NATIVE_CAMERA) || - enable after #1193
|
||||
# define BUILD_WITH_CAMERA_SUPPORT 1
|
||||
#else
|
||||
# define BUILD_WITH_CAMERA_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_XINE) || \
|
||||
defined(HAVE_GSTREAMER) || \
|
||||
defined(HAVE_QUICKTIME) || \
|
||||
defined(HAVE_QTKIT) || \
|
||||
defined(HAVE_AVFOUNDATION) || \
|
||||
/*defined(HAVE_OPENNI) || too specialized */ \
|
||||
defined(HAVE_FFMPEG) || \
|
||||
defined(HAVE_MSMF)
|
||||
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 1
|
||||
#else
|
||||
# define BUILD_WITH_VIDEO_INPUT_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#if /*defined(HAVE_XINE) || */\
|
||||
defined(HAVE_GSTREAMER) || \
|
||||
defined(HAVE_QUICKTIME) || \
|
||||
defined(HAVE_QTKIT) || \
|
||||
defined(HAVE_AVFOUNDATION) || \
|
||||
defined(HAVE_FFMPEG) || \
|
||||
defined(HAVE_MSMF)
|
||||
# define BUILD_WITH_VIDEO_OUTPUT_SUPPORT 1
|
||||
#else
|
||||
# define BUILD_WITH_VIDEO_OUTPUT_SUPPORT 0
|
||||
#endif
|
||||
|
||||
namespace cvtest
|
||||
{
|
||||
|
||||
string fourccToString(int fourcc);
|
||||
|
||||
struct VideoFormat
|
||||
{
|
||||
VideoFormat() { fourcc = -1; }
|
||||
VideoFormat(const string& _ext, int _fourcc) : ext(_ext), fourcc(_fourcc) {}
|
||||
bool empty() const { return ext.empty(); }
|
||||
|
||||
string ext;
|
||||
int fourcc;
|
||||
};
|
||||
|
||||
extern const VideoFormat g_specific_fmt_list[];
|
||||
|
||||
}
|
||||
//#include "opencv2/core/private.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
set(the_description "Image codecs")
|
||||
ocv_add_module(imgcodecs opencv_imgproc)
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for imgcodecs. See root CMakeLists.txt
|
||||
# Some parts taken from version of Hartmut Seichter, HIT Lab NZ.
|
||||
# Jose Luis Blanco, 2008
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
ocv_clear_vars(GRFMT_LIBS)
|
||||
|
||||
if(HAVE_WINRT_CX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
|
||||
endif()
|
||||
|
||||
if(HAVE_PNG OR HAVE_TIFF OR HAVE_OPENEXR)
|
||||
ocv_include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_JPEG)
|
||||
ocv_include_directories(${JPEG_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(WITH_WEBP)
|
||||
add_definitions(-DHAVE_WEBP)
|
||||
ocv_include_directories(${WEBP_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${WEBP_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_PNG)
|
||||
add_definitions(${PNG_DEFINITIONS})
|
||||
ocv_include_directories(${PNG_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${PNG_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_TIFF)
|
||||
ocv_include_directories(${TIFF_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${TIFF_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_JASPER)
|
||||
ocv_include_directories(${JASPER_INCLUDE_DIR})
|
||||
list(APPEND GRFMT_LIBS ${JASPER_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(HAVE_OPENEXR)
|
||||
include_directories(SYSTEM ${OPENEXR_INCLUDE_PATHS})
|
||||
list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES})
|
||||
endif()
|
||||
|
||||
file(GLOB grfmt_hdrs src/grfmt*.hpp)
|
||||
file(GLOB grfmt_srcs src/grfmt*.cpp)
|
||||
list(APPEND grfmt_hdrs src/bitstrm.hpp)
|
||||
list(APPEND grfmt_srcs src/bitstrm.cpp)
|
||||
list(APPEND grfmt_hdrs src/rgbe.hpp)
|
||||
list(APPEND grfmt_srcs src/rgbe.cpp)
|
||||
|
||||
source_group("Src\\grfmts" FILES ${grfmt_hdrs} ${grfmt_srcs})
|
||||
|
||||
set(imgcodecs_hdrs
|
||||
src/precomp.hpp
|
||||
src/utils.hpp
|
||||
)
|
||||
|
||||
set(imgcodecs_srcs
|
||||
src/loadsave.cpp
|
||||
src/utils.cpp
|
||||
)
|
||||
|
||||
file(GLOB imgcodecs_ext_hdrs "include/opencv2/*.hpp" "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h")
|
||||
|
||||
if(IOS)
|
||||
add_definitions(-DHAVE_IOS=1)
|
||||
list(APPEND imgcodecs_srcs src/ios_conversions.mm)
|
||||
list(APPEND IMGCODECS_LIBRARIES "-framework Accelerate" "-framework CoreGraphics" "-framework CoreImage" "-framework QuartzCore" "-framework AssetsLibrary")
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
#these variables are set by CHECK_MODULE macro
|
||||
foreach(P ${IMGCODECS_INCLUDE_DIRS})
|
||||
ocv_include_directories(${P})
|
||||
endforeach()
|
||||
|
||||
foreach(P ${IMGCODECS_LIBRARY_DIRS})
|
||||
link_directories(${P})
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
source_group("Src" FILES ${imgcodecs_srcs} ${imgcodecs_hdrs})
|
||||
source_group("Include" FILES ${imgcodecs_ext_hdrs})
|
||||
ocv_set_module_sources(HEADERS ${imgcodecs_ext_hdrs} SOURCES ${imgcodecs_srcs} ${imgcodecs_hdrs} ${grfmt_srcs} ${grfmt_hdrs})
|
||||
ocv_module_include_directories()
|
||||
|
||||
ocv_create_module(${GRFMT_LIBS} ${IMGCODECS_LIBRARIES})
|
||||
|
||||
if(APPLE)
|
||||
ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS)
|
||||
if(HAVE_OBJC_EXCEPTIONS)
|
||||
foreach(source ${OPENCV_MODULE_${the_module}_SOURCES})
|
||||
if("${source}" MATCHES "\\.mm$")
|
||||
get_source_file_property(flags "${source}" COMPILE_FLAGS)
|
||||
if(flags)
|
||||
set(flags "${_flags} -fobjc-exceptions")
|
||||
else()
|
||||
set(flags "-fobjc-exceptions")
|
||||
endif()
|
||||
|
||||
set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_SHARED_LIBS)
|
||||
add_definitions(-DIMGCODECS_EXPORTS)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(${the_module} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /NODEFAULTLIB:libcmt.lib /DEBUG")
|
||||
endif()
|
||||
|
||||
#stop automatic dependencies propagation for this module
|
||||
set_target_properties(${the_module} PROPERTIES LINK_INTERFACE_LIBRARIES "")
|
||||
|
||||
ocv_add_precompiled_headers(${the_module})
|
||||
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
|
||||
|
||||
ocv_add_accuracy_tests()
|
||||
ocv_add_perf_tests()
|
||||
@@ -0,0 +1,10 @@
|
||||
*****************************************
|
||||
imgcodecs. Image file reading and writing
|
||||
*****************************************
|
||||
|
||||
This module of the OpenCV help you read and write images to/from disk or memory.
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
reading_and_writing_images
|
||||
@@ -0,0 +1,187 @@
|
||||
Reading and Writing Images
|
||||
==========================
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
imdecode
|
||||
--------
|
||||
Reads an image from a buffer in memory.
|
||||
|
||||
.. ocv:function:: Mat imdecode( InputArray buf, int flags )
|
||||
|
||||
.. ocv:function:: Mat imdecode( InputArray buf, int flags, Mat* dst )
|
||||
|
||||
.. ocv:cfunction:: IplImage* cvDecodeImage( const CvMat* buf, int iscolor=CV_LOAD_IMAGE_COLOR)
|
||||
|
||||
.. ocv:cfunction:: CvMat* cvDecodeImageM( const CvMat* buf, int iscolor=CV_LOAD_IMAGE_COLOR)
|
||||
|
||||
.. ocv:pyfunction:: cv2.imdecode(buf, flags) -> retval
|
||||
|
||||
:param buf: Input array or vector of bytes.
|
||||
|
||||
:param flags: The same flags as in :ocv:func:`imread` .
|
||||
|
||||
:param dst: The optional output placeholder for the decoded matrix. It can save the image reallocations when the function is called repeatedly for images of the same size.
|
||||
|
||||
The function reads an image from the specified buffer in the memory.
|
||||
If the buffer is too short or contains invalid data, the empty matrix/image is returned.
|
||||
|
||||
See
|
||||
:ocv:func:`imread` for the list of supported formats and flags description.
|
||||
|
||||
.. note:: In the case of color images, the decoded images will have the channels stored in ``B G R`` order.
|
||||
|
||||
imencode
|
||||
--------
|
||||
Encodes an image into a memory buffer.
|
||||
|
||||
.. ocv:function:: bool imencode( const String& ext, InputArray img, vector<uchar>& buf, const vector<int>& params=vector<int>())
|
||||
|
||||
.. ocv:cfunction:: CvMat* cvEncodeImage( const char* ext, const CvArr* image, const int* params=0 )
|
||||
|
||||
.. ocv:pyfunction:: cv2.imencode(ext, img[, params]) -> retval, buf
|
||||
|
||||
:param ext: File extension that defines the output format.
|
||||
|
||||
:param img: Image to be written.
|
||||
|
||||
:param buf: Output buffer resized to fit the compressed image.
|
||||
|
||||
:param params: Format-specific parameters. See :ocv:func:`imwrite` .
|
||||
|
||||
The function compresses the image and stores it in the memory buffer that is resized to fit the result.
|
||||
See
|
||||
:ocv:func:`imwrite` for the list of supported formats and flags description.
|
||||
|
||||
.. note:: ``cvEncodeImage`` returns single-row matrix of type ``CV_8UC1`` that contains encoded image as array of bytes.
|
||||
|
||||
imread
|
||||
------
|
||||
Loads an image from a file.
|
||||
|
||||
.. ocv:function:: Mat imread( const String& filename, int flags=IMREAD_COLOR )
|
||||
|
||||
.. ocv:pyfunction:: cv2.imread(filename[, flags]) -> retval
|
||||
|
||||
.. ocv:cfunction:: IplImage* cvLoadImage( const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
|
||||
|
||||
.. ocv:cfunction:: CvMat* cvLoadImageM( const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR )
|
||||
|
||||
:param filename: Name of file to be loaded.
|
||||
|
||||
:param flags: Flags specifying the color type of a loaded image:
|
||||
|
||||
* CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
|
||||
|
||||
* CV_LOAD_IMAGE_COLOR - If set, always convert image to the color one
|
||||
|
||||
* CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one
|
||||
|
||||
* **>0** Return a 3-channel color image.
|
||||
.. note:: In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.
|
||||
|
||||
* **=0** Return a grayscale image.
|
||||
|
||||
* **<0** Return the loaded image as is (with alpha channel).
|
||||
|
||||
The function ``imread`` loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( ``Mat::data==NULL`` ). Currently, the following file formats are supported:
|
||||
|
||||
* Windows bitmaps - ``*.bmp, *.dib`` (always supported)
|
||||
|
||||
* JPEG files - ``*.jpeg, *.jpg, *.jpe`` (see the *Notes* section)
|
||||
|
||||
* JPEG 2000 files - ``*.jp2`` (see the *Notes* section)
|
||||
|
||||
* Portable Network Graphics - ``*.png`` (see the *Notes* section)
|
||||
|
||||
* WebP - ``*.webp`` (see the *Notes* section)
|
||||
|
||||
* Portable image format - ``*.pbm, *.pgm, *.ppm`` (always supported)
|
||||
|
||||
* Sun rasters - ``*.sr, *.ras`` (always supported)
|
||||
|
||||
* TIFF files - ``*.tiff, *.tif`` (see the *Notes* section)
|
||||
|
||||
.. note::
|
||||
|
||||
* The function determines the type of an image by the content, not by the file extension.
|
||||
|
||||
* On Microsoft Windows* OS and MacOSX*, the codecs shipped with an OpenCV image (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware that currently these native image loaders give images with different pixel values because of the color management embedded into MacOSX.
|
||||
|
||||
* On Linux*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with an OS image. Install the relevant packages (do not forget the development files, for example, "libjpeg-dev", in Debian* and Ubuntu*) to get the codec support or turn on the ``OPENCV_BUILD_3RDPARTY_LIBS`` flag in CMake.
|
||||
|
||||
.. note:: In the case of color images, the decoded images will have the channels stored in ``B G R`` order.
|
||||
|
||||
imwrite
|
||||
-----------
|
||||
Saves an image to a specified file.
|
||||
|
||||
.. ocv:function:: bool imwrite( const String& filename, InputArray img, const vector<int>& params=vector<int>() )
|
||||
|
||||
.. ocv:pyfunction:: cv2.imwrite(filename, img[, params]) -> retval
|
||||
|
||||
.. ocv:cfunction:: int cvSaveImage( const char* filename, const CvArr* image, const int* params=0 )
|
||||
|
||||
:param filename: Name of the file.
|
||||
|
||||
:param image: Image to be saved.
|
||||
|
||||
:param params: Format-specific save parameters encoded as pairs ``paramId_1, paramValue_1, paramId_2, paramValue_2, ...`` . The following parameters are currently supported:
|
||||
|
||||
* For JPEG, it can be a quality ( ``CV_IMWRITE_JPEG_QUALITY`` ) from 0 to 100 (the higher is the better). Default value is 95.
|
||||
|
||||
* For WEBP, it can be a quality ( CV_IMWRITE_WEBP_QUALITY ) from 1 to 100 (the higher is the better).
|
||||
By default (without any parameter) and for quality above 100 the lossless compression is used.
|
||||
|
||||
* For PNG, it can be the compression level ( ``CV_IMWRITE_PNG_COMPRESSION`` ) from 0 to 9. A higher value means a smaller size and longer compression time. Default value is 3.
|
||||
|
||||
* For PPM, PGM, or PBM, it can be a binary format flag ( ``CV_IMWRITE_PXM_BINARY`` ), 0 or 1. Default value is 1.
|
||||
|
||||
The function ``imwrite`` saves the image to the specified file. The image format is chosen based on the ``filename`` extension (see
|
||||
:ocv:func:`imread` for the list of extensions). Only 8-bit (or 16-bit unsigned (``CV_16U``) in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. If the format, depth or channel order is different, use
|
||||
:ocv:func:`Mat::convertTo` , and
|
||||
:ocv:func:`cvtColor` to convert it before saving. Or, use the universal :ocv:class:`FileStorage` I/O functions to save the image to XML or YAML format.
|
||||
|
||||
It is possible to store PNG images with an alpha channel using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535. The sample below shows how to create such a BGRA image and store to PNG file. It also demonstrates how to set custom compression parameters ::
|
||||
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
void createAlphaMat(Mat &mat)
|
||||
{
|
||||
for (int i = 0; i < mat.rows; ++i) {
|
||||
for (int j = 0; j < mat.cols; ++j) {
|
||||
Vec4b& rgba = mat.at<Vec4b>(i, j);
|
||||
rgba[0] = UCHAR_MAX;
|
||||
rgba[1] = saturate_cast<uchar>((float (mat.cols - j)) / ((float)mat.cols) * UCHAR_MAX);
|
||||
rgba[2] = saturate_cast<uchar>((float (mat.rows - i)) / ((float)mat.rows) * UCHAR_MAX);
|
||||
rgba[3] = saturate_cast<uchar>(0.5 * (rgba[1] + rgba[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argv, char **argc)
|
||||
{
|
||||
// Create mat with alpha channel
|
||||
Mat mat(480, 640, CV_8UC4);
|
||||
createAlphaMat(mat);
|
||||
|
||||
vector<int> compression_params;
|
||||
compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
|
||||
compression_params.push_back(9);
|
||||
|
||||
try {
|
||||
imwrite("alpha.png", mat, compression_params);
|
||||
}
|
||||
catch (runtime_error& ex) {
|
||||
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Saved PNG file with alpha data.\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*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*/
|
||||
|
||||
#ifndef __OPENCV_IMGCODECS_HPP__
|
||||
#define __OPENCV_IMGCODECS_HPP__
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
//////////////////////////////// image codec ////////////////////////////////
|
||||
namespace cv
|
||||
{
|
||||
|
||||
enum { IMREAD_UNCHANGED = -1, // 8bit, color or not
|
||||
IMREAD_GRAYSCALE = 0, // 8bit, gray
|
||||
IMREAD_COLOR = 1, // ?, color
|
||||
IMREAD_ANYDEPTH = 2, // any depth, ?
|
||||
IMREAD_ANYCOLOR = 4 // ?, any color
|
||||
};
|
||||
|
||||
enum { IMWRITE_JPEG_QUALITY = 1,
|
||||
IMWRITE_JPEG_PROGRESSIVE = 2,
|
||||
IMWRITE_JPEG_OPTIMIZE = 3,
|
||||
IMWRITE_JPEG_RST_INTERVAL = 4,
|
||||
IMWRITE_JPEG_LUMA_QUALITY = 5,
|
||||
IMWRITE_JPEG_CHROMA_QUALITY = 6,
|
||||
IMWRITE_PNG_COMPRESSION = 16,
|
||||
IMWRITE_PNG_STRATEGY = 17,
|
||||
IMWRITE_PNG_BILEVEL = 18,
|
||||
IMWRITE_PXM_BINARY = 32,
|
||||
IMWRITE_WEBP_QUALITY = 64
|
||||
};
|
||||
|
||||
enum { IMWRITE_PNG_STRATEGY_DEFAULT = 0,
|
||||
IMWRITE_PNG_STRATEGY_FILTERED = 1,
|
||||
IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = 2,
|
||||
IMWRITE_PNG_STRATEGY_RLE = 3,
|
||||
IMWRITE_PNG_STRATEGY_FIXED = 4
|
||||
};
|
||||
|
||||
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );
|
||||
|
||||
CV_EXPORTS_W bool imwrite( const String& filename, InputArray img,
|
||||
const std::vector<int>& params = std::vector<int>());
|
||||
|
||||
CV_EXPORTS_W Mat imdecode( InputArray buf, int flags );
|
||||
|
||||
CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst);
|
||||
|
||||
CV_EXPORTS_W bool imencode( const String& ext, InputArray img,
|
||||
CV_OUT std::vector<uchar>& buf,
|
||||
const std::vector<int>& params = std::vector<int>());
|
||||
|
||||
} // cv
|
||||
|
||||
#endif //__OPENCV_IMGCODECS_HPP__
|
||||
@@ -0,0 +1,48 @@
|
||||
/*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.
|
||||
// Copyright (C) 2013, OpenCV Foundation, 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*/
|
||||
|
||||
#ifdef __OPENCV_BUILD
|
||||
#error this is a compatibility header which should not be used inside the OpenCV library
|
||||
#endif
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
@@ -0,0 +1,132 @@
|
||||
/*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 __OPENCV_IMGCODECS_H__
|
||||
#define __OPENCV_IMGCODECS_H__
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
enum
|
||||
{
|
||||
/* 8bit, color or not */
|
||||
CV_LOAD_IMAGE_UNCHANGED =-1,
|
||||
/* 8bit, gray */
|
||||
CV_LOAD_IMAGE_GRAYSCALE =0,
|
||||
/* ?, color */
|
||||
CV_LOAD_IMAGE_COLOR =1,
|
||||
/* any depth, ? */
|
||||
CV_LOAD_IMAGE_ANYDEPTH =2,
|
||||
/* ?, any color */
|
||||
CV_LOAD_IMAGE_ANYCOLOR =4
|
||||
};
|
||||
|
||||
/* load image from file
|
||||
iscolor can be a combination of above flags where CV_LOAD_IMAGE_UNCHANGED
|
||||
overrides the other flags
|
||||
using CV_LOAD_IMAGE_ANYCOLOR alone is equivalent to CV_LOAD_IMAGE_UNCHANGED
|
||||
unless CV_LOAD_IMAGE_ANYDEPTH is specified images are converted to 8bit
|
||||
*/
|
||||
CVAPI(IplImage*) cvLoadImage( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
CVAPI(CvMat*) cvLoadImageM( const char* filename, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
|
||||
enum
|
||||
{
|
||||
CV_IMWRITE_JPEG_QUALITY =1,
|
||||
CV_IMWRITE_JPEG_PROGRESSIVE =2,
|
||||
CV_IMWRITE_JPEG_OPTIMIZE =3,
|
||||
CV_IMWRITE_JPEG_RST_INTERVAL =4,
|
||||
CV_IMWRITE_JPEG_LUMA_QUALITY =5,
|
||||
CV_IMWRITE_JPEG_CHROMA_QUALITY =6,
|
||||
CV_IMWRITE_PNG_COMPRESSION =16,
|
||||
CV_IMWRITE_PNG_STRATEGY =17,
|
||||
CV_IMWRITE_PNG_BILEVEL =18,
|
||||
CV_IMWRITE_PNG_STRATEGY_DEFAULT =0,
|
||||
CV_IMWRITE_PNG_STRATEGY_FILTERED =1,
|
||||
CV_IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY =2,
|
||||
CV_IMWRITE_PNG_STRATEGY_RLE =3,
|
||||
CV_IMWRITE_PNG_STRATEGY_FIXED =4,
|
||||
CV_IMWRITE_PXM_BINARY =32,
|
||||
CV_IMWRITE_WEBP_QUALITY =64
|
||||
};
|
||||
|
||||
/* save image to file */
|
||||
CVAPI(int) cvSaveImage( const char* filename, const CvArr* image,
|
||||
const int* params CV_DEFAULT(0) );
|
||||
|
||||
/* decode image stored in the buffer */
|
||||
CVAPI(IplImage*) cvDecodeImage( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
CVAPI(CvMat*) cvDecodeImageM( const CvMat* buf, int iscolor CV_DEFAULT(CV_LOAD_IMAGE_COLOR));
|
||||
|
||||
/* encode image and store the result as a byte vector (single-row 8uC1 matrix) */
|
||||
CVAPI(CvMat*) cvEncodeImage( const char* ext, const CvArr* image,
|
||||
const int* params CV_DEFAULT(0) );
|
||||
|
||||
enum
|
||||
{
|
||||
CV_CVTIMG_FLIP =1,
|
||||
CV_CVTIMG_SWAP_RB =2
|
||||
};
|
||||
|
||||
/* utility function: convert one image to another with optional vertical flip */
|
||||
CVAPI(void) cvConvertImage( const CvArr* src, CvArr* dst, int flags CV_DEFAULT(0));
|
||||
|
||||
CVAPI(int) cvHaveImageReader(const char* filename);
|
||||
CVAPI(int) cvHaveImageWriter(const char* filename);
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* Obsolete functions/synonyms *
|
||||
\****************************************************************************************/
|
||||
|
||||
#define cvvLoadImage(name) cvLoadImage((name),1)
|
||||
#define cvvSaveImage cvSaveImage
|
||||
#define cvvConvertImage cvConvertImage
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __OPENCV_IMGCODECS_H__
|
||||
+4
-1
@@ -41,8 +41,11 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Accelerate/Accelerate.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <ImageIO/ImageIO.h>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#import "opencv2/highgui/cap_ios.h"
|
||||
|
||||
UIImage* MatToUIImage(const cv::Mat& image);
|
||||
void UIImageToMat(const UIImage* image,
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
CV_PERF_TEST_MAIN(imgcodecs)
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations"
|
||||
# if defined __clang__ || defined __APPLE__
|
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
|
||||
# pragma GCC diagnostic ignored "-Wextra"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__
|
||||
#define __OPENCV_PERF_PRECOMP_HPP__
|
||||
|
||||
#include "opencv2/ts.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY
|
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -600,6 +600,9 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
int quality = 95;
|
||||
int progressive = 0;
|
||||
int optimize = 0;
|
||||
int rst_interval = 0;
|
||||
int luma_quality = -1;
|
||||
int chroma_quality = -1;
|
||||
|
||||
for( size_t i = 0; i < params.size(); i += 2 )
|
||||
{
|
||||
@@ -618,15 +621,64 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
{
|
||||
optimize = params[i+1];
|
||||
}
|
||||
|
||||
if( params[i] == CV_IMWRITE_JPEG_LUMA_QUALITY )
|
||||
{
|
||||
if (params[i+1] >= 0)
|
||||
{
|
||||
luma_quality = MIN(MAX(params[i+1], 0), 100);
|
||||
|
||||
quality = luma_quality;
|
||||
|
||||
if (chroma_quality < 0)
|
||||
{
|
||||
chroma_quality = luma_quality;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( params[i] == CV_IMWRITE_JPEG_CHROMA_QUALITY )
|
||||
{
|
||||
if (params[i+1] >= 0)
|
||||
{
|
||||
chroma_quality = MIN(MAX(params[i+1], 0), 100);
|
||||
}
|
||||
}
|
||||
|
||||
if( params[i] == CV_IMWRITE_JPEG_RST_INTERVAL )
|
||||
{
|
||||
rst_interval = params[i+1];
|
||||
rst_interval = MIN(MAX(rst_interval, 0), 65535L);
|
||||
}
|
||||
}
|
||||
|
||||
jpeg_set_defaults( &cinfo );
|
||||
cinfo.restart_interval = rst_interval;
|
||||
|
||||
jpeg_set_quality( &cinfo, quality,
|
||||
TRUE /* limit to baseline-JPEG values */ );
|
||||
if( progressive )
|
||||
jpeg_simple_progression( &cinfo );
|
||||
if( optimize )
|
||||
cinfo.optimize_coding = TRUE;
|
||||
|
||||
#if JPEG_LIB_VERSION >= 70
|
||||
if (luma_quality >= 0 && chroma_quality >= 0)
|
||||
{
|
||||
cinfo.q_scale_factor[0] = jpeg_quality_scaling(luma_quality);
|
||||
cinfo.q_scale_factor[1] = jpeg_quality_scaling(chroma_quality);
|
||||
if ( luma_quality != chroma_quality )
|
||||
{
|
||||
/* disable subsampling - ref. Libjpeg.txt */
|
||||
cinfo.comp_info[0].v_samp_factor = 1;
|
||||
cinfo.comp_info[0].h_samp_factor = 1;
|
||||
cinfo.comp_info[1].v_samp_factor = 1;
|
||||
cinfo.comp_info[1].h_samp_factor = 1;
|
||||
}
|
||||
jpeg_default_qtables( &cinfo, TRUE );
|
||||
}
|
||||
#endif // #if JPEG_LIB_VERSION >= 70
|
||||
|
||||
jpeg_start_compress( &cinfo, TRUE );
|
||||
|
||||
if( channels > 1 )
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user