mirror of https://github.com/opencv/opencv.git
parent
3f1c6d7357
commit
d5a0088bbe
194 changed files with 10073 additions and 8140 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,44 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
After Width: | Height: | Size: 4.5 KiB |
@ -1,161 +1,161 @@ |
||||
/*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 GpuMaterials 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_CORE_DevMem2D_HPP__ |
||||
#define __OPENCV_CORE_DevMem2D_HPP__ |
||||
|
||||
#ifdef __cplusplus |
||||
|
||||
#ifdef __CUDACC__ |
||||
#define __CV_GPU_HOST_DEVICE__ __host__ __device__ __forceinline__ |
||||
#else |
||||
#define __CV_GPU_HOST_DEVICE__ |
||||
#endif |
||||
|
||||
namespace cv |
||||
{
|
||||
namespace gpu |
||||
{ |
||||
// Simple lightweight structures that encapsulates information about an image on device.
|
||||
// It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile
|
||||
|
||||
template <bool expr> struct StaticAssert; |
||||
template <> struct StaticAssert<true> {static __CV_GPU_HOST_DEVICE__ void check(){}}; |
||||
|
||||
template<typename T> struct DevPtr |
||||
{ |
||||
typedef T elem_type; |
||||
typedef int index_type; |
||||
|
||||
enum { elem_size = sizeof(elem_type) }; |
||||
|
||||
T* data; |
||||
|
||||
__CV_GPU_HOST_DEVICE__ DevPtr() : data(0) {} |
||||
__CV_GPU_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {} |
||||
|
||||
__CV_GPU_HOST_DEVICE__ size_t elemSize() const { return elem_size; } |
||||
__CV_GPU_HOST_DEVICE__ operator T*() { return data; } |
||||
__CV_GPU_HOST_DEVICE__ operator const T*() const { return data; } |
||||
}; |
||||
|
||||
template<typename T> struct PtrSz : public DevPtr<T> |
||||
{
|
||||
__CV_GPU_HOST_DEVICE__ PtrSz() : size(0) {} |
||||
__CV_GPU_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr<T>(data_), size(size_) {} |
||||
|
||||
size_t size; |
||||
}; |
||||
|
||||
template<typename T> struct PtrStep : public DevPtr<T> |
||||
{
|
||||
__CV_GPU_HOST_DEVICE__ PtrStep() : step(0) {} |
||||
__CV_GPU_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr<T>(data_), step(step_) {} |
||||
|
||||
/** \brief stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! */ |
||||
size_t step;
|
||||
|
||||
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); } |
||||
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); } |
||||
|
||||
__CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } |
||||
__CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } |
||||
}; |
||||
|
||||
template <typename T> struct PtrStepSz : public PtrStep<T> |
||||
{
|
||||
__CV_GPU_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {} |
||||
__CV_GPU_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_)
|
||||
: PtrStep<T>(data_, step_), cols(cols_), rows(rows_) {} |
||||
|
||||
int cols; |
||||
int rows;
|
||||
}; |
||||
|
||||
template <typename T> struct DevMem2D_ : public PtrStepSz<T> |
||||
{
|
||||
DevMem2D_() {} |
||||
DevMem2D_(int rows_, int cols_, T* data_, size_t step_) : PtrStepSz<T>(rows_, cols_, data_, step_) {} |
||||
|
||||
template <typename U>
|
||||
explicit DevMem2D_(const DevMem2D_<U>& d) : PtrStepSz<T>(d.rows, d.cols, (T*)d.data, d.step) {}
|
||||
}; |
||||
|
||||
template<typename T> struct PtrElemStep_ : public PtrStep<T> |
||||
{
|
||||
PtrElemStep_(const DevMem2D_<T>& mem) : PtrStep<T>(mem.data, mem.step)
|
||||
{ |
||||
StaticAssert<256 % sizeof(T) == 0>::check(); |
||||
|
||||
PtrStep<T>::step /= PtrStep<T>::elem_size;
|
||||
} |
||||
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return PtrStep<T>::data + y * PtrStep<T>::step; } |
||||
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return PtrStep<T>::data + y * PtrStep<T>::step; }
|
||||
|
||||
__CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } |
||||
__CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }
|
||||
}; |
||||
|
||||
template<typename T> struct PtrStep_ : public PtrStep<T> |
||||
{
|
||||
PtrStep_() {} |
||||
PtrStep_(const DevMem2D_<T>& mem) : PtrStep<T>(mem.data, mem.step) {}
|
||||
}; |
||||
|
||||
typedef DevMem2D_<unsigned char> DevMem2Db; |
||||
typedef DevMem2Db DevMem2D; |
||||
typedef DevMem2D_<float> DevMem2Df; |
||||
typedef DevMem2D_<int> DevMem2Di; |
||||
|
||||
typedef PtrStep<unsigned char> PtrStepb; |
||||
typedef PtrStep<float> PtrStepf; |
||||
typedef PtrStep<int> PtrStepi; |
||||
|
||||
typedef PtrElemStep_<unsigned char> PtrElemStep; |
||||
typedef PtrElemStep_<float> PtrElemStepf; |
||||
typedef PtrElemStep_<int> PtrElemStepi;
|
||||
}
|
||||
} |
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* __OPENCV_GPU_DevMem2D_HPP__ */ |
||||
/*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 GpuMaterials 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_CORE_DevMem2D_HPP__ |
||||
#define __OPENCV_CORE_DevMem2D_HPP__ |
||||
|
||||
#ifdef __cplusplus |
||||
|
||||
#ifdef __CUDACC__ |
||||
#define __CV_GPU_HOST_DEVICE__ __host__ __device__ __forceinline__ |
||||
#else |
||||
#define __CV_GPU_HOST_DEVICE__ |
||||
#endif |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace gpu |
||||
{ |
||||
// Simple lightweight structures that encapsulates information about an image on device.
|
||||
// It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile
|
||||
|
||||
template <bool expr> struct StaticAssert; |
||||
template <> struct StaticAssert<true> {static __CV_GPU_HOST_DEVICE__ void check(){}}; |
||||
|
||||
template<typename T> struct DevPtr |
||||
{ |
||||
typedef T elem_type; |
||||
typedef int index_type; |
||||
|
||||
enum { elem_size = sizeof(elem_type) }; |
||||
|
||||
T* data; |
||||
|
||||
__CV_GPU_HOST_DEVICE__ DevPtr() : data(0) {} |
||||
__CV_GPU_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {} |
||||
|
||||
__CV_GPU_HOST_DEVICE__ size_t elemSize() const { return elem_size; } |
||||
__CV_GPU_HOST_DEVICE__ operator T*() { return data; } |
||||
__CV_GPU_HOST_DEVICE__ operator const T*() const { return data; } |
||||
}; |
||||
|
||||
template<typename T> struct PtrSz : public DevPtr<T> |
||||
{ |
||||
__CV_GPU_HOST_DEVICE__ PtrSz() : size(0) {} |
||||
__CV_GPU_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr<T>(data_), size(size_) {} |
||||
|
||||
size_t size; |
||||
}; |
||||
|
||||
template<typename T> struct PtrStep : public DevPtr<T> |
||||
{ |
||||
__CV_GPU_HOST_DEVICE__ PtrStep() : step(0) {} |
||||
__CV_GPU_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr<T>(data_), step(step_) {} |
||||
|
||||
/** \brief stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! */ |
||||
size_t step; |
||||
|
||||
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); } |
||||
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); } |
||||
|
||||
__CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } |
||||
__CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } |
||||
}; |
||||
|
||||
template <typename T> struct PtrStepSz : public PtrStep<T> |
||||
{ |
||||
__CV_GPU_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {} |
||||
__CV_GPU_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_) |
||||
: PtrStep<T>(data_, step_), cols(cols_), rows(rows_) {} |
||||
|
||||
int cols; |
||||
int rows; |
||||
}; |
||||
|
||||
template <typename T> struct DevMem2D_ : public PtrStepSz<T> |
||||
{ |
||||
DevMem2D_() {} |
||||
DevMem2D_(int rows_, int cols_, T* data_, size_t step_) : PtrStepSz<T>(rows_, cols_, data_, step_) {} |
||||
|
||||
template <typename U> |
||||
explicit DevMem2D_(const DevMem2D_<U>& d) : PtrStepSz<T>(d.rows, d.cols, (T*)d.data, d.step) {} |
||||
}; |
||||
|
||||
template<typename T> struct PtrElemStep_ : public PtrStep<T> |
||||
{ |
||||
PtrElemStep_(const DevMem2D_<T>& mem) : PtrStep<T>(mem.data, mem.step) |
||||
{ |
||||
StaticAssert<256 % sizeof(T) == 0>::check(); |
||||
|
||||
PtrStep<T>::step /= PtrStep<T>::elem_size; |
||||
} |
||||
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return PtrStep<T>::data + y * PtrStep<T>::step; } |
||||
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return PtrStep<T>::data + y * PtrStep<T>::step; } |
||||
|
||||
__CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } |
||||
__CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } |
||||
}; |
||||
|
||||
template<typename T> struct PtrStep_ : public PtrStep<T> |
||||
{ |
||||
PtrStep_() {} |
||||
PtrStep_(const DevMem2D_<T>& mem) : PtrStep<T>(mem.data, mem.step) {} |
||||
}; |
||||
|
||||
typedef DevMem2D_<unsigned char> DevMem2Db; |
||||
typedef DevMem2Db DevMem2D; |
||||
typedef DevMem2D_<float> DevMem2Df; |
||||
typedef DevMem2D_<int> DevMem2Di; |
||||
|
||||
typedef PtrStep<unsigned char> PtrStepb; |
||||
typedef PtrStep<float> PtrStepf; |
||||
typedef PtrStep<int> PtrStepi; |
||||
|
||||
typedef PtrElemStep_<unsigned char> PtrElemStep; |
||||
typedef PtrElemStep_<float> PtrElemStepf; |
||||
typedef PtrElemStep_<int> PtrElemStepi; |
||||
} |
||||
} |
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* __OPENCV_GPU_DevMem2D_HPP__ */ |
||||
|
@ -0,0 +1,263 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
/////////////////////// AlgorithmInfo for various detector & descriptors ////////////////////////////
|
||||
|
||||
/* NOTE!!!
|
||||
All the AlgorithmInfo-related stuff should be in the same file as initModule_features2d(). |
||||
Otherwise, linker may throw away some seemingly unused stuff. |
||||
*/ |
||||
|
||||
static Algorithm* createBRIEF() { return new BriefDescriptorExtractor; } |
||||
static AlgorithmInfo& brief_info() |
||||
{ |
||||
static AlgorithmInfo brief_info_var("Feature2D.BRIEF", createBRIEF); |
||||
return brief_info_var; |
||||
} |
||||
|
||||
static AlgorithmInfo& brief_info_auto = brief_info(); |
||||
|
||||
AlgorithmInfo* BriefDescriptorExtractor::info() const |
||||
{ |
||||
static volatile bool initialized = false; |
||||
if( !initialized ) |
||||
{ |
||||
BriefDescriptorExtractor brief; |
||||
brief_info().addParam(brief, "bytes", brief.bytes_); |
||||
|
||||
initialized = true; |
||||
} |
||||
return &brief_info(); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Algorithm* createFAST() { return new FastFeatureDetector; } |
||||
static AlgorithmInfo& fast_info() |
||||
{ |
||||
static AlgorithmInfo fast_info_var("Feature2D.FAST", createFAST); |
||||
return fast_info_var; |
||||
} |
||||
|
||||
static AlgorithmInfo& fast_info_auto = fast_info(); |
||||
|
||||
AlgorithmInfo* FastFeatureDetector::info() const |
||||
{ |
||||
static volatile bool initialized = false; |
||||
if( !initialized ) |
||||
{ |
||||
FastFeatureDetector obj; |
||||
fast_info().addParam(obj, "threshold", obj.threshold); |
||||
fast_info().addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression); |
||||
|
||||
initialized = true; |
||||
} |
||||
return &fast_info(); |
||||
} |
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Algorithm* createStarDetector() { return new StarDetector; } |
||||
static AlgorithmInfo& star_info() |
||||
{ |
||||
static AlgorithmInfo star_info_var("Feature2D.STAR", createStarDetector); |
||||
return star_info_var; |
||||
} |
||||
|
||||
static AlgorithmInfo& star_info_auto = star_info(); |
||||
|
||||
AlgorithmInfo* StarDetector::info() const |
||||
{ |
||||
static volatile bool initialized = false; |
||||
if( !initialized ) |
||||
{ |
||||
StarDetector obj; |
||||
star_info().addParam(obj, "maxSize", obj.maxSize); |
||||
star_info().addParam(obj, "responseThreshold", obj.responseThreshold); |
||||
star_info().addParam(obj, "lineThresholdProjected", obj.lineThresholdProjected); |
||||
star_info().addParam(obj, "lineThresholdBinarized", obj.lineThresholdBinarized); |
||||
star_info().addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize); |
||||
|
||||
initialized = true; |
||||
} |
||||
return &star_info(); |
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Algorithm* createMSER() { return new MSER; } |
||||
static AlgorithmInfo& mser_info() |
||||
{ |
||||
static AlgorithmInfo mser_info_var("Feature2D.MSER", createMSER); |
||||
return mser_info_var; |
||||
} |
||||
|
||||
static AlgorithmInfo& mser_info_auto = mser_info(); |
||||
|
||||
AlgorithmInfo* MSER::info() const |
||||
{ |
||||
static volatile bool initialized = false; |
||||
if( !initialized ) |
||||
{ |
||||
MSER obj; |
||||
mser_info().addParam(obj, "delta", obj.delta); |
||||
mser_info().addParam(obj, "minArea", obj.minArea); |
||||
mser_info().addParam(obj, "maxArea", obj.maxArea); |
||||
mser_info().addParam(obj, "maxVariation", obj.maxVariation); |
||||
mser_info().addParam(obj, "minDiversity", obj.minDiversity); |
||||
mser_info().addParam(obj, "maxEvolution", obj.maxEvolution); |
||||
mser_info().addParam(obj, "areaThreshold", obj.areaThreshold); |
||||
mser_info().addParam(obj, "minMargin", obj.minMargin); |
||||
mser_info().addParam(obj, "edgeBlurSize", obj.edgeBlurSize); |
||||
|
||||
initialized = true; |
||||
} |
||||
return &mser_info(); |
||||
} |
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static Algorithm* createORB() { return new ORB; } |
||||
static AlgorithmInfo& orb_info() |
||||
{ |
||||
static AlgorithmInfo orb_info_var("Feature2D.ORB", createORB); |
||||
return orb_info_var; |
||||
} |
||||
|
||||
static AlgorithmInfo& orb_info_auto = orb_info(); |
||||
|
||||
AlgorithmInfo* ORB::info() const |
||||
{ |
||||
static volatile bool initialized = false; |
||||
if( !initialized ) |
||||
{ |
||||
ORB obj; |
||||
orb_info().addParam(obj, "nFeatures", obj.nfeatures); |
||||
orb_info().addParam(obj, "scaleFactor", obj.scaleFactor); |
||||
orb_info().addParam(obj, "nLevels", obj.nlevels); |
||||
orb_info().addParam(obj, "firstLevel", obj.firstLevel); |
||||
orb_info().addParam(obj, "edgeThreshold", obj.edgeThreshold); |
||||
orb_info().addParam(obj, "patchSize", obj.patchSize); |
||||
orb_info().addParam(obj, "WTA_K", obj.WTA_K); |
||||
orb_info().addParam(obj, "scoreType", obj.scoreType); |
||||
|
||||
initialized = true; |
||||
} |
||||
return &orb_info(); |
||||
} |
||||
|
||||
static Algorithm* createGFTT() { return new GFTTDetector; } |
||||
static Algorithm* createHarris() |
||||
{ |
||||
GFTTDetector* d = new GFTTDetector; |
||||
d->set("useHarris", true); |
||||
return d; |
||||
} |
||||
|
||||
static AlgorithmInfo gftt_info("Feature2D.GFTT", createGFTT); |
||||
static AlgorithmInfo harris_info("Feature2D.HARRIS", createHarris); |
||||
|
||||
AlgorithmInfo* GFTTDetector::info() const |
||||
{ |
||||
static volatile bool initialized = false; |
||||
if( !initialized ) |
||||
{ |
||||
GFTTDetector obj; |
||||
gftt_info.addParam(obj, "nfeatures", obj.nfeatures); |
||||
gftt_info.addParam(obj, "qualityLevel", obj.qualityLevel); |
||||
gftt_info.addParam(obj, "minDistance", obj.minDistance); |
||||
gftt_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector); |
||||
gftt_info.addParam(obj, "k", obj.k); |
||||
|
||||
harris_info.addParam(obj, "nfeatures", obj.nfeatures); |
||||
harris_info.addParam(obj, "qualityLevel", obj.qualityLevel); |
||||
harris_info.addParam(obj, "minDistance", obj.minDistance); |
||||
harris_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector); |
||||
harris_info.addParam(obj, "k", obj.k); |
||||
|
||||
initialized = true; |
||||
} |
||||
return &gftt_info; |
||||
} |
||||
|
||||
static Algorithm* createDense() { return new DenseFeatureDetector; } |
||||
static AlgorithmInfo dense_info("Feature2D.Dense", createDense); |
||||
|
||||
AlgorithmInfo* DenseFeatureDetector::info() const |
||||
{ |
||||
static volatile bool initialized = false; |
||||
if( !initialized ) |
||||
{ |
||||
DenseFeatureDetector obj; |
||||
dense_info.addParam(obj, "initFeatureScale", obj.initFeatureScale); |
||||
dense_info.addParam(obj, "featureScaleLevels", obj.featureScaleLevels); |
||||
dense_info.addParam(obj, "featureScaleMul", obj.featureScaleMul); |
||||
dense_info.addParam(obj, "initXyStep", obj.initXyStep); |
||||
dense_info.addParam(obj, "initImgBound", obj.initImgBound); |
||||
dense_info.addParam(obj, "varyXyStepWithScale", obj.varyXyStepWithScale); |
||||
dense_info.addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale); |
||||
|
||||
initialized = true; |
||||
} |
||||
return &dense_info; |
||||
}
|
||||
|
||||
bool initModule_features2d(void) |
||||
{ |
||||
Ptr<Algorithm> brief = createBRIEF(), orb = createORB(), |
||||
star = createStarDetector(), fastd = createFAST(), mser = createMSER(), |
||||
dense = createDense(), gftt = createGFTT(), harris = createHarris(); |
||||
|
||||
return brief->info() != 0 && orb->info() != 0 && star->info() != 0 && |
||||
fastd->info() != 0 && mser->info() != 0 && dense->info() != 0 && |
||||
gftt->info() != 0 && harris->info() != 0; |
||||
} |
||||
|
||||
} |
||||
|
@ -1,122 +0,0 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
#if 0 |
||||
using namespace cv; |
||||
|
||||
class BruteForceMatcherTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
BruteForceMatcherTest(); |
||||
protected: |
||||
void run( int ); |
||||
}; |
||||
|
||||
struct CV_EXPORTS L2Fake : public L2<float> |
||||
{ |
||||
}; |
||||
|
||||
BruteForceMatcherTest::BruteForceMatcherTest() : cvtest::BaseTest( "BruteForceMatcher", "BruteForceMatcher::matchImpl") |
||||
{ |
||||
support_testing_modes = cvtest::TS::TIMING_MODE; |
||||
} |
||||
|
||||
void BruteForceMatcherTest::run( int ) |
||||
{ |
||||
const int dimensions = 64; |
||||
const int descriptorsNumber = 5000; |
||||
|
||||
Mat train = Mat( descriptorsNumber, dimensions, CV_32FC1); |
||||
Mat query = Mat( descriptorsNumber, dimensions, CV_32FC1); |
||||
|
||||
Mat permutation( 1, descriptorsNumber, CV_32SC1 ); |
||||
for( int i=0;i<descriptorsNumber;i++ ) |
||||
permutation.at<int>( 0, i ) = i; |
||||
|
||||
//RNG rng = RNG( cvGetTickCount() );
|
||||
RNG rng = RNG( *ts->get_rng() ); |
||||
randShuffle( permutation, 1, &rng ); |
||||
|
||||
float boundary = 500.f; |
||||
for( int row=0;row<descriptorsNumber;row++ ) |
||||
{ |
||||
for( int col=0;col<dimensions;col++ ) |
||||
{ |
||||
int bit = rng( 2 ); |
||||
train.at<float>( permutation.at<int>( 0, row ), col ) = bit*boundary + rng.uniform( 0.f, boundary ); |
||||
query.at<float>( row, col ) = bit*boundary + rng.uniform( 0.f, boundary ); |
||||
} |
||||
} |
||||
|
||||
vector<DMatch> specMatches, genericMatches; |
||||
BruteForceMatcher<L2<float> > specMatcher; |
||||
BruteForceMatcher<L2Fake > genericMatcher; |
||||
|
||||
int64 time0 = cvGetTickCount(); |
||||
specMatcher.match( query, train, specMatches ); |
||||
int64 time1 = cvGetTickCount(); |
||||
genericMatcher.match( query, train, genericMatches ); |
||||
int64 time2 = cvGetTickCount(); |
||||
|
||||
float specMatcherTime = float(time1 - time0)/(float)cvGetTickFrequency(); |
||||
ts->printf( cvtest::TS::LOG, "Matching by matrix multiplication time s: %f, us per pair: %f\n", |
||||
specMatcherTime*1e-6, specMatcherTime/( descriptorsNumber*descriptorsNumber ) ); |
||||
|
||||
float genericMatcherTime = float(time2 - time1)/(float)cvGetTickFrequency(); |
||||
ts->printf( cvtest::TS::LOG, "Matching without matrix multiplication time s: %f, us per pair: %f\n", |
||||
genericMatcherTime*1e-6, genericMatcherTime/( descriptorsNumber*descriptorsNumber ) ); |
||||
|
||||
if( (int)specMatches.size() != descriptorsNumber || (int)genericMatches.size() != descriptorsNumber ) |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
for( int i=0;i<descriptorsNumber;i++ ) |
||||
{ |
||||
float epsilon = 0.01f; |
||||
bool isEquiv = fabs( specMatches[i].distance - genericMatches[i].distance ) < epsilon && |
||||
specMatches[i].queryIdx == genericMatches[i].queryIdx && |
||||
specMatches[i].trainIdx == genericMatches[i].trainIdx; |
||||
if( !isEquiv || specMatches[i].trainIdx != permutation.at<int>( 0, i ) ) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
|
||||
//Test mask
|
||||
Mat mask( query.rows, train.rows, CV_8UC1 ); |
||||
rng.fill( mask, RNG::UNIFORM, 0, 2 ); |
||||
|
||||
|
||||
time0 = cvGetTickCount(); |
||||
specMatcher.match( query, train, specMatches, mask ); |
||||
time1 = cvGetTickCount(); |
||||
genericMatcher.match( query, train, genericMatches, mask ); |
||||
time2 = cvGetTickCount(); |
||||
|
||||
specMatcherTime = float(time1 - time0)/(float)cvGetTickFrequency(); |
||||
ts->printf( cvtest::TS::LOG, "Matching by matrix multiplication time with mask s: %f, us per pair: %f\n", |
||||
specMatcherTime*1e-6, specMatcherTime/( descriptorsNumber*descriptorsNumber ) ); |
||||
|
||||
genericMatcherTime = float(time2 - time1)/(float)cvGetTickFrequency(); |
||||
ts->printf( cvtest::TS::LOG, "Matching without matrix multiplication time with mask s: %f, us per pair: %f\n", |
||||
genericMatcherTime*1e-6, genericMatcherTime/( descriptorsNumber*descriptorsNumber ) ); |
||||
|
||||
if( specMatches.size() != genericMatches.size() ) |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); |
||||
|
||||
for( size_t i=0;i<specMatches.size();i++ ) |
||||
{ |
||||
//float epsilon = 1e-2;
|
||||
float epsilon = 10000000; |
||||
bool isEquiv = fabs( specMatches[i].distance - genericMatches[i].distance ) < epsilon && |
||||
specMatches[i].queryIdx == genericMatches[i].queryIdx && |
||||
specMatches[i].trainIdx == genericMatches[i].trainIdx; |
||||
if( !isEquiv ) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
BruteForceMatcherTest taBruteForceMatcherTest; |
||||
#endif |
@ -1,499 +1,416 @@ |
||||
/*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*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace { |
||||
|
||||
//#define DUMP
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BroxOpticalFlow
|
||||
|
||||
#define BROX_OPTICAL_FLOW_DUMP_FILE "opticalflow/brox_optical_flow.bin" |
||||
#define BROX_OPTICAL_FLOW_DUMP_FILE_CC20 "opticalflow/brox_optical_flow_cc20.bin" |
||||
|
||||
struct BroxOpticalFlow : testing::TestWithParam<cv::gpu::DeviceInfo> |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GetParam(); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(BroxOpticalFlow, Regression) |
||||
{ |
||||
cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1); |
||||
ASSERT_FALSE(frame0.empty()); |
||||
|
||||
cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1); |
||||
ASSERT_FALSE(frame1.empty()); |
||||
|
||||
cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, |
||||
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); |
||||
|
||||
cv::gpu::GpuMat u; |
||||
cv::gpu::GpuMat v; |
||||
brox(loadMat(frame0), loadMat(frame1), u, v); |
||||
|
||||
#ifndef DUMP |
||||
std::string fname(cvtest::TS::ptr()->get_data_path()); |
||||
if (devInfo.majorVersion() >= 2) |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE_CC20; |
||||
else |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE; |
||||
|
||||
std::ifstream f(fname.c_str(), std::ios_base::binary); |
||||
|
||||
int rows, cols; |
||||
|
||||
f.read((char*)&rows, sizeof(rows)); |
||||
f.read((char*)&cols, sizeof(cols)); |
||||
|
||||
cv::Mat u_gold(rows, cols, CV_32FC1); |
||||
|
||||
for (int i = 0; i < u_gold.rows; ++i) |
||||
f.read(u_gold.ptr<char>(i), u_gold.cols * sizeof(float)); |
||||
|
||||
cv::Mat v_gold(rows, cols, CV_32FC1); |
||||
|
||||
for (int i = 0; i < v_gold.rows; ++i) |
||||
f.read(v_gold.ptr<char>(i), v_gold.cols * sizeof(float)); |
||||
|
||||
EXPECT_MAT_NEAR(u_gold, u, 0); |
||||
EXPECT_MAT_NEAR(v_gold, v, 0); |
||||
#else |
||||
std::string fname(cvtest::TS::ptr()->get_data_path()); |
||||
if (devInfo.majorVersion() >= 2) |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE_CC20; |
||||
else |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE; |
||||
|
||||
std::ofstream f(fname.c_str(), std::ios_base::binary); |
||||
|
||||
f.write((char*)&u.rows, sizeof(u.rows)); |
||||
f.write((char*)&u.cols, sizeof(u.cols)); |
||||
|
||||
cv::Mat h_u(u); |
||||
cv::Mat h_v(v); |
||||
|
||||
for (int i = 0; i < u.rows; ++i) |
||||
f.write(h_u.ptr<char>(i), u.cols * sizeof(float)); |
||||
|
||||
for (int i = 0; i < v.rows; ++i) |
||||
f.write(h_v.ptr<char>(i), v.cols * sizeof(float)); |
||||
|
||||
#endif |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, BroxOpticalFlow, ALL_DEVICES); |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GoodFeaturesToTrack
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(MinDistance, double) |
||||
|
||||
PARAM_TEST_CASE(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
double minDistance; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
minDistance = GET_PARAM(1); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(GoodFeaturesToTrack, Accuracy) |
||||
{ |
||||
cv::Mat image = readImage("opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(image.empty()); |
||||
|
||||
int maxCorners = 1000; |
||||
double qualityLevel = 0.01; |
||||
|
||||
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance); |
||||
|
||||
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS)) |
||||
{ |
||||
try |
||||
{ |
||||
cv::gpu::GpuMat d_pts; |
||||
detector(loadMat(image), d_pts); |
||||
} |
||||
catch (const cv::Exception& e) |
||||
{ |
||||
ASSERT_EQ(CV_StsNotImplemented, e.code); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
cv::gpu::GpuMat d_pts; |
||||
detector(loadMat(image), d_pts); |
||||
|
||||
std::vector<cv::Point2f> pts(d_pts.cols); |
||||
cv::Mat pts_mat(1, d_pts.cols, CV_32FC2, (void*)&pts[0]); |
||||
d_pts.download(pts_mat); |
||||
|
||||
std::vector<cv::Point2f> pts_gold; |
||||
cv::goodFeaturesToTrack(image, pts_gold, maxCorners, qualityLevel, minDistance); |
||||
|
||||
ASSERT_EQ(pts_gold.size(), pts.size()); |
||||
|
||||
size_t mistmatch = 0; |
||||
for (size_t i = 0; i < pts.size(); ++i) |
||||
{ |
||||
cv::Point2i a = pts_gold[i]; |
||||
cv::Point2i b = pts[i]; |
||||
|
||||
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1; |
||||
|
||||
if (!eq) |
||||
++mistmatch; |
||||
} |
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / pts.size(); |
||||
|
||||
ASSERT_LE(bad_ratio, 0.01); |
||||
} |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, GoodFeaturesToTrack, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(MinDistance(0.0), MinDistance(3.0)))); |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PyrLKOpticalFlow
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(UseGray, bool) |
||||
|
||||
PARAM_TEST_CASE(PyrLKOpticalFlow, cv::gpu::DeviceInfo, UseGray) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
bool useGray; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
useGray = GET_PARAM(1); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(PyrLKOpticalFlow, Sparse) |
||||
{ |
||||
cv::Mat frame0 = readImage("opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); |
||||
ASSERT_FALSE(frame0.empty()); |
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/frame1.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); |
||||
ASSERT_FALSE(frame1.empty()); |
||||
|
||||
cv::Mat gray_frame; |
||||
if (useGray) |
||||
gray_frame = frame0; |
||||
else |
||||
cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY); |
||||
|
||||
std::vector<cv::Point2f> pts; |
||||
cv::goodFeaturesToTrack(gray_frame, pts, 1000, 0.01, 0.0); |
||||
|
||||
cv::gpu::GpuMat d_pts; |
||||
cv::Mat pts_mat(1, (int)pts.size(), CV_32FC2, (void*)&pts[0]); |
||||
d_pts.upload(pts_mat); |
||||
|
||||
cv::gpu::PyrLKOpticalFlow pyrLK; |
||||
|
||||
cv::gpu::GpuMat d_nextPts; |
||||
cv::gpu::GpuMat d_status; |
||||
cv::gpu::GpuMat d_err; |
||||
pyrLK.sparse(loadMat(frame0), loadMat(frame1), d_pts, d_nextPts, d_status, &d_err); |
||||
|
||||
std::vector<cv::Point2f> nextPts(d_nextPts.cols); |
||||
cv::Mat nextPts_mat(1, d_nextPts.cols, CV_32FC2, (void*)&nextPts[0]); |
||||
d_nextPts.download(nextPts_mat); |
||||
|
||||
std::vector<unsigned char> status(d_status.cols); |
||||
cv::Mat status_mat(1, d_status.cols, CV_8UC1, (void*)&status[0]); |
||||
d_status.download(status_mat); |
||||
|
||||
std::vector<float> err(d_err.cols); |
||||
cv::Mat err_mat(1, d_err.cols, CV_32FC1, (void*)&err[0]); |
||||
d_err.download(err_mat); |
||||
|
||||
std::vector<cv::Point2f> nextPts_gold; |
||||
std::vector<unsigned char> status_gold; |
||||
std::vector<float> err_gold; |
||||
cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts_gold, status_gold, err_gold); |
||||
|
||||
ASSERT_EQ(nextPts_gold.size(), nextPts.size()); |
||||
ASSERT_EQ(status_gold.size(), status.size()); |
||||
ASSERT_EQ(err_gold.size(), err.size()); |
||||
|
||||
size_t mistmatch = 0; |
||||
for (size_t i = 0; i < nextPts.size(); ++i) |
||||
{ |
||||
if (status[i] != status_gold[i]) |
||||
{ |
||||
++mistmatch; |
||||
continue; |
||||
} |
||||
|
||||
if (status[i]) |
||||
{ |
||||
cv::Point2i a = nextPts[i]; |
||||
cv::Point2i b = nextPts_gold[i]; |
||||
|
||||
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1; |
||||
float errdiff = std::abs(err[i] - err_gold[i]); |
||||
|
||||
if (!eq || errdiff > 1e-1) |
||||
++mistmatch; |
||||
} |
||||
} |
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / nextPts.size(); |
||||
|
||||
ASSERT_LE(bad_ratio, 0.01); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, PyrLKOpticalFlow, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(UseGray(true), UseGray(false)))); |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FarnebackOpticalFlow
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(PyrScale, double) |
||||
IMPLEMENT_PARAM_CLASS(PolyN, int) |
||||
CV_FLAGS(FarnebackOptFlowFlags, 0, cv::OPTFLOW_FARNEBACK_GAUSSIAN) |
||||
IMPLEMENT_PARAM_CLASS(UseInitFlow, bool) |
||||
|
||||
PARAM_TEST_CASE(FarnebackOpticalFlow, cv::gpu::DeviceInfo, PyrScale, PolyN, FarnebackOptFlowFlags, UseInitFlow) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
double pyrScale; |
||||
int polyN; |
||||
int flags; |
||||
bool useInitFlow; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
pyrScale = GET_PARAM(1); |
||||
polyN = GET_PARAM(2); |
||||
flags = GET_PARAM(3); |
||||
useInitFlow = GET_PARAM(4); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(FarnebackOpticalFlow, Accuracy) |
||||
{ |
||||
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(frame0.empty()); |
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(frame1.empty()); |
||||
|
||||
double polySigma = polyN <= 5 ? 1.1 : 1.5; |
||||
|
||||
cv::gpu::FarnebackOpticalFlow calc; |
||||
calc.pyrScale = pyrScale; |
||||
calc.polyN = polyN; |
||||
calc.polySigma = polySigma; |
||||
calc.flags = flags; |
||||
|
||||
cv::gpu::GpuMat d_flowx, d_flowy; |
||||
calc(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy); |
||||
|
||||
cv::Mat flow; |
||||
if (useInitFlow) |
||||
{ |
||||
cv::Mat flowxy[] = {cv::Mat(d_flowx), cv::Mat(d_flowy)}; |
||||
cv::merge(flowxy, 2, flow); |
||||
} |
||||
|
||||
if (useInitFlow) |
||||
{ |
||||
calc.flags |= cv::OPTFLOW_USE_INITIAL_FLOW; |
||||
calc(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy); |
||||
} |
||||
|
||||
cv::calcOpticalFlowFarneback( |
||||
frame0, frame1, flow, calc.pyrScale, calc.numLevels, calc.winSize, |
||||
calc.numIters, calc.polyN, calc.polySigma, calc.flags); |
||||
|
||||
std::vector<cv::Mat> flowxy; |
||||
cv::split(flow, flowxy); |
||||
|
||||
EXPECT_MAT_SIMILAR(flowxy[0], d_flowx, 0.1); |
||||
EXPECT_MAT_SIMILAR(flowxy[1], d_flowy, 0.1); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, FarnebackOpticalFlow, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(PyrScale(0.3), PyrScale(0.5), PyrScale(0.8)), |
||||
testing::Values(PolyN(5), PolyN(7)), |
||||
testing::Values(FarnebackOptFlowFlags(0), FarnebackOptFlowFlags(cv::OPTFLOW_FARNEBACK_GAUSSIAN)), |
||||
testing::Values(UseInitFlow(false), UseInitFlow(true)))); |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// VideoWriter
|
||||
|
||||
#ifdef WIN32 |
||||
|
||||
PARAM_TEST_CASE(VideoWriter, cv::gpu::DeviceInfo, std::string) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
std::string inputFile; |
||||
|
||||
std::string outputFile; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
inputFile = GET_PARAM(1); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + inputFile; |
||||
outputFile = inputFile.substr(0, inputFile.find('.')) + "_test.avi"; |
||||
} |
||||
}; |
||||
|
||||
TEST_P(VideoWriter, Regression) |
||||
{ |
||||
const double FPS = 25.0; |
||||
|
||||
cv::VideoCapture reader(inputFile); |
||||
ASSERT_TRUE( reader.isOpened() ); |
||||
|
||||
cv::gpu::VideoWriter_GPU d_writer; |
||||
|
||||
cv::Mat frame; |
||||
std::vector<cv::Mat> frames; |
||||
cv::gpu::GpuMat d_frame; |
||||
|
||||
for (int i = 1; i < 10; ++i) |
||||
{ |
||||
reader >> frame; |
||||
|
||||
if (frame.empty()) |
||||
break; |
||||
|
||||
frames.push_back(frame.clone()); |
||||
d_frame.upload(frame); |
||||
|
||||
if (!d_writer.isOpened()) |
||||
d_writer.open(outputFile, frame.size(), FPS); |
||||
|
||||
d_writer.write(d_frame); |
||||
} |
||||
|
||||
reader.release(); |
||||
d_writer.close(); |
||||
|
||||
reader.open(outputFile); |
||||
ASSERT_TRUE( reader.isOpened() ); |
||||
|
||||
for (int i = 0; i < 5; ++i) |
||||
{ |
||||
reader >> frame; |
||||
ASSERT_FALSE( frame.empty() ); |
||||
} |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoWriter, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(std::string("VID00003-20100701-2204.mpg"), std::string("big_buck_bunny.mpg")))); |
||||
|
||||
#endif // WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// VideoReader
|
||||
|
||||
PARAM_TEST_CASE(VideoReader, cv::gpu::DeviceInfo, std::string) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
std::string inputFile; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
inputFile = GET_PARAM(1); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
|
||||
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + inputFile; |
||||
} |
||||
}; |
||||
|
||||
TEST_P(VideoReader, Regression) |
||||
{ |
||||
cv::gpu::VideoReader_GPU reader(inputFile); |
||||
ASSERT_TRUE( reader.isOpened() ); |
||||
|
||||
cv::gpu::GpuMat frame; |
||||
|
||||
for (int i = 0; i < 5; ++i) |
||||
{ |
||||
ASSERT_TRUE( reader.read(frame) ); |
||||
ASSERT_FALSE( frame.empty() ); |
||||
} |
||||
|
||||
reader.close(); |
||||
ASSERT_FALSE( reader.isOpened() ); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoReader, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(std::string("VID00003-20100701-2204.mpg")))); |
||||
|
||||
} // namespace
|
||||
/*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*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
namespace { |
||||
|
||||
//#define DUMP
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// BroxOpticalFlow
|
||||
|
||||
#define BROX_OPTICAL_FLOW_DUMP_FILE "opticalflow/brox_optical_flow.bin" |
||||
#define BROX_OPTICAL_FLOW_DUMP_FILE_CC20 "opticalflow/brox_optical_flow_cc20.bin" |
||||
|
||||
struct BroxOpticalFlow : testing::TestWithParam<cv::gpu::DeviceInfo> |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GetParam(); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(BroxOpticalFlow, Regression) |
||||
{ |
||||
cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1); |
||||
ASSERT_FALSE(frame0.empty()); |
||||
|
||||
cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1); |
||||
ASSERT_FALSE(frame1.empty()); |
||||
|
||||
cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, |
||||
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); |
||||
|
||||
cv::gpu::GpuMat u; |
||||
cv::gpu::GpuMat v; |
||||
brox(loadMat(frame0), loadMat(frame1), u, v); |
||||
|
||||
#ifndef DUMP |
||||
std::string fname(cvtest::TS::ptr()->get_data_path()); |
||||
if (devInfo.majorVersion() >= 2) |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE_CC20; |
||||
else |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE; |
||||
|
||||
std::ifstream f(fname.c_str(), std::ios_base::binary); |
||||
|
||||
int rows, cols; |
||||
|
||||
f.read((char*)&rows, sizeof(rows)); |
||||
f.read((char*)&cols, sizeof(cols)); |
||||
|
||||
cv::Mat u_gold(rows, cols, CV_32FC1); |
||||
|
||||
for (int i = 0; i < u_gold.rows; ++i) |
||||
f.read(u_gold.ptr<char>(i), u_gold.cols * sizeof(float)); |
||||
|
||||
cv::Mat v_gold(rows, cols, CV_32FC1); |
||||
|
||||
for (int i = 0; i < v_gold.rows; ++i) |
||||
f.read(v_gold.ptr<char>(i), v_gold.cols * sizeof(float)); |
||||
|
||||
EXPECT_MAT_NEAR(u_gold, u, 0); |
||||
EXPECT_MAT_NEAR(v_gold, v, 0); |
||||
#else |
||||
std::string fname(cvtest::TS::ptr()->get_data_path()); |
||||
if (devInfo.majorVersion() >= 2) |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE_CC20; |
||||
else |
||||
fname += BROX_OPTICAL_FLOW_DUMP_FILE; |
||||
|
||||
std::ofstream f(fname.c_str(), std::ios_base::binary); |
||||
|
||||
f.write((char*)&u.rows, sizeof(u.rows)); |
||||
f.write((char*)&u.cols, sizeof(u.cols)); |
||||
|
||||
cv::Mat h_u(u); |
||||
cv::Mat h_v(v); |
||||
|
||||
for (int i = 0; i < u.rows; ++i) |
||||
f.write(h_u.ptr<char>(i), u.cols * sizeof(float)); |
||||
|
||||
for (int i = 0; i < v.rows; ++i) |
||||
f.write(h_v.ptr<char>(i), v.cols * sizeof(float)); |
||||
|
||||
#endif |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, BroxOpticalFlow, ALL_DEVICES); |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// GoodFeaturesToTrack
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(MinDistance, double) |
||||
|
||||
PARAM_TEST_CASE(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
double minDistance; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
minDistance = GET_PARAM(1); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(GoodFeaturesToTrack, Accuracy) |
||||
{ |
||||
cv::Mat image = readImage("opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(image.empty()); |
||||
|
||||
int maxCorners = 1000; |
||||
double qualityLevel = 0.01; |
||||
|
||||
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance); |
||||
|
||||
if (!supportFeature(devInfo, cv::gpu::GLOBAL_ATOMICS)) |
||||
{ |
||||
try |
||||
{ |
||||
cv::gpu::GpuMat d_pts; |
||||
detector(loadMat(image), d_pts); |
||||
} |
||||
catch (const cv::Exception& e) |
||||
{ |
||||
ASSERT_EQ(CV_StsNotImplemented, e.code); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
cv::gpu::GpuMat d_pts; |
||||
detector(loadMat(image), d_pts); |
||||
|
||||
std::vector<cv::Point2f> pts(d_pts.cols); |
||||
cv::Mat pts_mat(1, d_pts.cols, CV_32FC2, (void*)&pts[0]); |
||||
d_pts.download(pts_mat); |
||||
|
||||
std::vector<cv::Point2f> pts_gold; |
||||
cv::goodFeaturesToTrack(image, pts_gold, maxCorners, qualityLevel, minDistance); |
||||
|
||||
ASSERT_EQ(pts_gold.size(), pts.size()); |
||||
|
||||
size_t mistmatch = 0; |
||||
for (size_t i = 0; i < pts.size(); ++i) |
||||
{ |
||||
cv::Point2i a = pts_gold[i]; |
||||
cv::Point2i b = pts[i]; |
||||
|
||||
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1; |
||||
|
||||
if (!eq) |
||||
++mistmatch; |
||||
} |
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / pts.size(); |
||||
|
||||
ASSERT_LE(bad_ratio, 0.01); |
||||
} |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, GoodFeaturesToTrack, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(MinDistance(0.0), MinDistance(3.0)))); |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PyrLKOpticalFlow
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(UseGray, bool) |
||||
|
||||
PARAM_TEST_CASE(PyrLKOpticalFlow, cv::gpu::DeviceInfo, UseGray) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
bool useGray; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
useGray = GET_PARAM(1); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(PyrLKOpticalFlow, Sparse) |
||||
{ |
||||
cv::Mat frame0 = readImage("opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); |
||||
ASSERT_FALSE(frame0.empty()); |
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/frame1.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); |
||||
ASSERT_FALSE(frame1.empty()); |
||||
|
||||
cv::Mat gray_frame; |
||||
if (useGray) |
||||
gray_frame = frame0; |
||||
else |
||||
cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY); |
||||
|
||||
std::vector<cv::Point2f> pts; |
||||
cv::goodFeaturesToTrack(gray_frame, pts, 1000, 0.01, 0.0); |
||||
|
||||
cv::gpu::GpuMat d_pts; |
||||
cv::Mat pts_mat(1, (int)pts.size(), CV_32FC2, (void*)&pts[0]); |
||||
d_pts.upload(pts_mat); |
||||
|
||||
cv::gpu::PyrLKOpticalFlow pyrLK; |
||||
|
||||
cv::gpu::GpuMat d_nextPts; |
||||
cv::gpu::GpuMat d_status; |
||||
cv::gpu::GpuMat d_err; |
||||
pyrLK.sparse(loadMat(frame0), loadMat(frame1), d_pts, d_nextPts, d_status, &d_err); |
||||
|
||||
std::vector<cv::Point2f> nextPts(d_nextPts.cols); |
||||
cv::Mat nextPts_mat(1, d_nextPts.cols, CV_32FC2, (void*)&nextPts[0]); |
||||
d_nextPts.download(nextPts_mat); |
||||
|
||||
std::vector<unsigned char> status(d_status.cols); |
||||
cv::Mat status_mat(1, d_status.cols, CV_8UC1, (void*)&status[0]); |
||||
d_status.download(status_mat); |
||||
|
||||
std::vector<float> err(d_err.cols); |
||||
cv::Mat err_mat(1, d_err.cols, CV_32FC1, (void*)&err[0]); |
||||
d_err.download(err_mat); |
||||
|
||||
std::vector<cv::Point2f> nextPts_gold; |
||||
std::vector<unsigned char> status_gold; |
||||
std::vector<float> err_gold; |
||||
cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts_gold, status_gold, err_gold); |
||||
|
||||
ASSERT_EQ(nextPts_gold.size(), nextPts.size()); |
||||
ASSERT_EQ(status_gold.size(), status.size()); |
||||
ASSERT_EQ(err_gold.size(), err.size()); |
||||
|
||||
size_t mistmatch = 0; |
||||
for (size_t i = 0; i < nextPts.size(); ++i) |
||||
{ |
||||
if (status[i] != status_gold[i]) |
||||
{ |
||||
++mistmatch; |
||||
continue; |
||||
} |
||||
|
||||
if (status[i]) |
||||
{ |
||||
cv::Point2i a = nextPts[i]; |
||||
cv::Point2i b = nextPts_gold[i]; |
||||
|
||||
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1; |
||||
float errdiff = std::abs(err[i] - err_gold[i]); |
||||
|
||||
if (!eq || errdiff > 1e-1) |
||||
++mistmatch; |
||||
} |
||||
} |
||||
|
||||
double bad_ratio = static_cast<double>(mistmatch) / nextPts.size(); |
||||
|
||||
ASSERT_LE(bad_ratio, 0.01); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, PyrLKOpticalFlow, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(UseGray(true), UseGray(false)))); |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// FarnebackOpticalFlow
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(PyrScale, double) |
||||
IMPLEMENT_PARAM_CLASS(PolyN, int) |
||||
CV_FLAGS(FarnebackOptFlowFlags, 0, cv::OPTFLOW_FARNEBACK_GAUSSIAN) |
||||
IMPLEMENT_PARAM_CLASS(UseInitFlow, bool) |
||||
|
||||
PARAM_TEST_CASE(FarnebackOpticalFlow, cv::gpu::DeviceInfo, PyrScale, PolyN, FarnebackOptFlowFlags, UseInitFlow) |
||||
{ |
||||
cv::gpu::DeviceInfo devInfo; |
||||
double pyrScale; |
||||
int polyN; |
||||
int flags; |
||||
bool useInitFlow; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
devInfo = GET_PARAM(0); |
||||
pyrScale = GET_PARAM(1); |
||||
polyN = GET_PARAM(2); |
||||
flags = GET_PARAM(3); |
||||
useInitFlow = GET_PARAM(4); |
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID()); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(FarnebackOpticalFlow, Accuracy) |
||||
{ |
||||
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(frame0.empty()); |
||||
|
||||
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(frame1.empty()); |
||||
|
||||
double polySigma = polyN <= 5 ? 1.1 : 1.5; |
||||
|
||||
cv::gpu::FarnebackOpticalFlow calc; |
||||
calc.pyrScale = pyrScale; |
||||
calc.polyN = polyN; |
||||
calc.polySigma = polySigma; |
||||
calc.flags = flags; |
||||
|
||||
cv::gpu::GpuMat d_flowx, d_flowy; |
||||
calc(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy); |
||||
|
||||
cv::Mat flow; |
||||
if (useInitFlow) |
||||
{ |
||||
cv::Mat flowxy[] = {cv::Mat(d_flowx), cv::Mat(d_flowy)}; |
||||
cv::merge(flowxy, 2, flow); |
||||
} |
||||
|
||||
if (useInitFlow) |
||||
{ |
||||
calc.flags |= cv::OPTFLOW_USE_INITIAL_FLOW; |
||||
calc(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy); |
||||
} |
||||
|
||||
cv::calcOpticalFlowFarneback( |
||||
frame0, frame1, flow, calc.pyrScale, calc.numLevels, calc.winSize, |
||||
calc.numIters, calc.polyN, calc.polySigma, calc.flags); |
||||
|
||||
std::vector<cv::Mat> flowxy; |
||||
cv::split(flow, flowxy); |
||||
|
||||
EXPECT_MAT_SIMILAR(flowxy[0], d_flowx, 0.1); |
||||
EXPECT_MAT_SIMILAR(flowxy[1], d_flowy, 0.1); |
||||
}; |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, FarnebackOpticalFlow, testing::Combine( |
||||
ALL_DEVICES, |
||||
testing::Values(PyrScale(0.3), PyrScale(0.5), PyrScale(0.8)), |
||||
testing::Values(PolyN(5), PolyN(7)), |
||||
testing::Values(FarnebackOptFlowFlags(0), FarnebackOptFlowFlags(cv::OPTFLOW_FARNEBACK_GAUSSIAN)), |
||||
testing::Values(UseInitFlow(false), UseInitFlow(true)))); |
||||
|
||||
struct OpticalFlowNan : public BroxOpticalFlow {}; |
||||
|
||||
TEST_P(OpticalFlowNan, Regression) |
||||
{ |
||||
cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1); |
||||
ASSERT_FALSE(frame0.empty()); |
||||
cv::Mat r_frame0, r_frame1; |
||||
cv::resize(frame0, r_frame0, cv::Size(1380,1000)); |
||||
|
||||
cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1); |
||||
ASSERT_FALSE(frame1.empty()); |
||||
cv::resize(frame1, r_frame1, cv::Size(1380,1000)); |
||||
|
||||
cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, |
||||
5 /*inner_iterations*/, 150 /*outer_iterations*/, 10 /*solver_iterations*/); |
||||
|
||||
cv::gpu::GpuMat u; |
||||
cv::gpu::GpuMat v; |
||||
brox(loadMat(r_frame0), loadMat(r_frame1), u, v); |
||||
|
||||
cv::Mat h_u, h_v; |
||||
u.download(h_u); |
||||
v.download(h_v); |
||||
EXPECT_TRUE(cv::checkRange(h_u)); |
||||
EXPECT_TRUE(cv::checkRange(h_v)); |
||||
}; |
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Video, OpticalFlowNan, ALL_DEVICES); |
||||
|
||||
} // namespace
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,147 +1,176 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include "opencv2/highgui/highgui.hpp" |
||||
|
||||
#ifdef HAVE_FFMPEG |
||||
|
||||
#include "ffmpeg_codecs.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
class CV_FFmpegWriteBigVideoTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
void run(int) |
||||
{ |
||||
const int img_r = 4096; |
||||
const int img_c = 4096; |
||||
const double fps0 = 15; |
||||
const double time_sec = 1; |
||||
|
||||
const size_t n = sizeof(codec_bmp_tags)/sizeof(codec_bmp_tags[0]); |
||||
|
||||
bool created = false; |
||||
|
||||
for (size_t j = 0; j < n; ++j) |
||||
{ |
||||
stringstream s; s << codec_bmp_tags[j].tag; |
||||
int tag = codec_bmp_tags[j].tag; |
||||
|
||||
if( tag != MKTAG('H', '2', '6', '3') && |
||||
tag != MKTAG('H', '2', '6', '1') && |
||||
tag != MKTAG('D', 'I', 'V', 'X') && |
||||
tag != MKTAG('D', 'X', '5', '0') && |
||||
tag != MKTAG('X', 'V', 'I', 'D') && |
||||
tag != MKTAG('m', 'p', '4', 'v') && |
||||
tag != MKTAG('D', 'I', 'V', '3') && |
||||
tag != MKTAG('W', 'M', 'V', '1') && |
||||
tag != MKTAG('W', 'M', 'V', '2') && |
||||
tag != MKTAG('M', 'P', 'E', 'G') && |
||||
tag != MKTAG('M', 'J', 'P', 'G') && |
||||
tag != MKTAG('j', 'p', 'e', 'g') && |
||||
tag != 0 && |
||||
tag != MKTAG('I', '4', '2', '0') && |
||||
tag != MKTAG('Y', 'U', 'Y', '2') && |
||||
tag != MKTAG('F', 'L', 'V', '1') ) |
||||
continue; |
||||
|
||||
const string filename = "output_"+s.str()+".avi"; |
||||
|
||||
try |
||||
{ |
||||
double fps = fps0; |
||||
Size frame_s = Size(img_c, img_r); |
||||
|
||||
if( tag == CV_FOURCC('H', '2', '6', '1') ) |
||||
frame_s = Size(352, 288); |
||||
else if( tag == CV_FOURCC('H', '2', '6', '3') ) |
||||
frame_s = Size(704, 576); |
||||
/*else if( tag == CV_FOURCC('M', 'J', 'P', 'G') ||
|
||||
tag == CV_FOURCC('j', 'p', 'e', 'g') ) |
||||
frame_s = Size(1920, 1080);*/ |
||||
|
||||
if( tag == CV_FOURCC('M', 'P', 'E', 'G') ) |
||||
fps = 25; |
||||
|
||||
VideoWriter writer(filename, tag, fps, frame_s); |
||||
|
||||
if (writer.isOpened() == false) |
||||
{ |
||||
ts->printf(ts->LOG, "\n\nFile name: %s\n", filename.c_str()); |
||||
ts->printf(ts->LOG, "Codec id: %d Codec tag: %c%c%c%c\n", j, |
||||
tag & 255, (tag >> 8) & 255, (tag >> 16) & 255, (tag >> 24) & 255); |
||||
ts->printf(ts->LOG, "Error: cannot create video file."); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
} |
||||
else |
||||
{ |
||||
Mat img(frame_s, CV_8UC3, Scalar::all(0)); |
||||
const int coeff = cvRound(cv::min(frame_s.width, frame_s.height)/(fps0 * time_sec)); |
||||
|
||||
for (int i = 0 ; i < static_cast<int>(fps * time_sec); i++ ) |
||||
{ |
||||
//circle(img, Point2i(img_c / 2, img_r / 2), cv::min(img_r, img_c) / 2 * (i + 1), Scalar(255, 0, 0, 0), 2);
|
||||
rectangle(img, Point2i(coeff * i, coeff * i), Point2i(coeff * (i + 1), coeff * (i + 1)), |
||||
Scalar::all(255 * (1.0 - static_cast<double>(i) / (fps * time_sec * 2) )), -1); |
||||
writer << img; |
||||
} |
||||
|
||||
if (!created) created = true; |
||||
else remove(filename.c_str()); |
||||
} |
||||
} |
||||
catch(...) |
||||
{ |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
} |
||||
ts->set_failed_test_info(cvtest::TS::OK); |
||||
|
||||
} |
||||
} |
||||
}; |
||||
|
||||
TEST(Highgui_FFmpeg_WriteBigVideo, regression) { CV_FFmpegWriteBigVideoTest test; test.safe_run(); } |
||||
|
||||
#endif |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include "opencv2/highgui/highgui.hpp" |
||||
|
||||
#ifdef HAVE_FFMPEG |
||||
|
||||
#include "ffmpeg_codecs.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
class CV_FFmpegWriteBigVideoTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
void run(int) |
||||
{ |
||||
const int img_r = 4096; |
||||
const int img_c = 4096; |
||||
const double fps0 = 15; |
||||
const double time_sec = 1; |
||||
|
||||
const size_t n = sizeof(codec_bmp_tags)/sizeof(codec_bmp_tags[0]); |
||||
|
||||
bool created = false; |
||||
|
||||
for (size_t j = 0; j < n; ++j) |
||||
{ |
||||
stringstream s; s << codec_bmp_tags[j].tag; |
||||
int tag = codec_bmp_tags[j].tag; |
||||
|
||||
if( tag != MKTAG('H', '2', '6', '3') && |
||||
tag != MKTAG('H', '2', '6', '1') && |
||||
//tag != MKTAG('D', 'I', 'V', 'X') &&
|
||||
tag != MKTAG('D', 'X', '5', '0') && |
||||
tag != MKTAG('X', 'V', 'I', 'D') && |
||||
tag != MKTAG('m', 'p', '4', 'v') && |
||||
//tag != MKTAG('D', 'I', 'V', '3') &&
|
||||
//tag != MKTAG('W', 'M', 'V', '1') &&
|
||||
//tag != MKTAG('W', 'M', 'V', '2') &&
|
||||
tag != MKTAG('M', 'P', 'E', 'G') && |
||||
tag != MKTAG('M', 'J', 'P', 'G') && |
||||
//tag != MKTAG('j', 'p', 'e', 'g') &&
|
||||
tag != 0 && |
||||
tag != MKTAG('I', '4', '2', '0') && |
||||
//tag != MKTAG('Y', 'U', 'Y', '2') &&
|
||||
tag != MKTAG('F', 'L', 'V', '1') ) |
||||
continue; |
||||
|
||||
const string filename = "output_"+s.str()+".avi"; |
||||
|
||||
try |
||||
{ |
||||
double fps = fps0; |
||||
Size frame_s = Size(img_c, img_r); |
||||
|
||||
if( tag == CV_FOURCC('H', '2', '6', '1') ) |
||||
frame_s = Size(352, 288); |
||||
else if( tag == CV_FOURCC('H', '2', '6', '3') ) |
||||
frame_s = Size(704, 576); |
||||
/*else if( tag == CV_FOURCC('M', 'J', 'P', 'G') ||
|
||||
tag == CV_FOURCC('j', 'p', 'e', 'g') ) |
||||
frame_s = Size(1920, 1080);*/ |
||||
|
||||
if( tag == CV_FOURCC('M', 'P', 'E', 'G') ) |
||||
fps = 25; |
||||
|
||||
VideoWriter writer(filename, tag, fps, frame_s); |
||||
|
||||
if (writer.isOpened() == false) |
||||
{ |
||||
ts->printf(ts->LOG, "\n\nFile name: %s\n", filename.c_str()); |
||||
ts->printf(ts->LOG, "Codec id: %d Codec tag: %c%c%c%c\n", j, |
||||
tag & 255, (tag >> 8) & 255, (tag >> 16) & 255, (tag >> 24) & 255); |
||||
ts->printf(ts->LOG, "Error: cannot create video file."); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
} |
||||
else |
||||
{ |
||||
Mat img(frame_s, CV_8UC3, Scalar::all(0)); |
||||
const int coeff = cvRound(cv::min(frame_s.width, frame_s.height)/(fps0 * time_sec)); |
||||
|
||||
for (int i = 0 ; i < static_cast<int>(fps * time_sec); i++ ) |
||||
{ |
||||
//circle(img, Point2i(img_c / 2, img_r / 2), cv::min(img_r, img_c) / 2 * (i + 1), Scalar(255, 0, 0, 0), 2);
|
||||
rectangle(img, Point2i(coeff * i, coeff * i), Point2i(coeff * (i + 1), coeff * (i + 1)), |
||||
Scalar::all(255 * (1.0 - static_cast<double>(i) / (fps * time_sec * 2) )), -1); |
||||
writer << img; |
||||
} |
||||
|
||||
if (!created) created = true; |
||||
else remove(filename.c_str()); |
||||
} |
||||
} |
||||
catch(...) |
||||
{ |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
} |
||||
ts->set_failed_test_info(cvtest::TS::OK); |
||||
|
||||
} |
||||
} |
||||
}; |
||||
|
||||
TEST(Highgui_Video, ffmpeg_writebig) { CV_FFmpegWriteBigVideoTest test; test.safe_run(); } |
||||
|
||||
class CV_FFmpegReadImageTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
void run(int) |
||||
{ |
||||
try |
||||
{ |
||||
string filename = ts->get_data_path() + "../cv/features2d/tsukuba.png"; |
||||
VideoCapture cap(filename); |
||||
Mat img0 = imread(filename, 1); |
||||
Mat img, img_next; |
||||
cap >> img; |
||||
cap >> img_next; |
||||
|
||||
CV_Assert( !img0.empty() && !img.empty() && img_next.empty() ); |
||||
|
||||
double diff = norm(img0, img, CV_C); |
||||
CV_Assert( diff == 0 ); |
||||
} |
||||
catch(...) |
||||
{ |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
} |
||||
ts->set_failed_test_info(cvtest::TS::OK); |
||||
} |
||||
}; |
||||
|
||||
TEST(Highgui_Video, ffmpeg_image) { CV_FFmpegReadImageTest test; test.safe_run(); } |
||||
|
||||
#endif |
||||
|
@ -1,229 +1,180 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include "opencv2/highgui/highgui.hpp" |
||||
|
||||
#ifdef HAVE_FFMPEG |
||||
|
||||
#include "ffmpeg_codecs.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
class CV_PositioningTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
void CreateTestVideo(const string& format, int codec, int framecount = 125); |
||||
void run(int); |
||||
}; |
||||
|
||||
void CV_PositioningTest::CreateTestVideo(const string& format, int codec, int framecount) |
||||
{ |
||||
stringstream s; s << codec; |
||||
|
||||
//if( format == "mov" && codec == CV_FOURCC('m', 'p', 'e', 'g')
|
||||
// putchar('$');
|
||||
|
||||
cv::VideoWriter writer("test_video_"+s.str()+"."+format, codec, 25, cv::Size(640, 480), false); |
||||
|
||||
for (int i = 0; i < framecount; ++i) |
||||
{ |
||||
cv::Mat mat(480, 640, CV_8UC1); |
||||
size_t n = 8, tmp = i; |
||||
|
||||
vector<char> tmp_code; tmp_code.clear(); |
||||
|
||||
while ( tmp > 1 ) |
||||
{ |
||||
tmp_code.push_back(tmp%2); |
||||
tmp /= 2; |
||||
} |
||||
tmp_code.push_back(tmp); |
||||
|
||||
vector<char> i_code; |
||||
|
||||
for (size_t j = 0; j < n; ++j) |
||||
{ |
||||
char val = j < n - tmp_code.size() ? 0 : tmp_code.at(n-1-j); |
||||
i_code.push_back(val); |
||||
} |
||||
|
||||
const size_t w = 480/n; |
||||
|
||||
for (size_t j = 0; j < n; ++j) |
||||
{ |
||||
cv::Scalar color = i_code[j] ? 255 : 0; |
||||
rectangle(mat, Rect(0, w*j, 640, w), color, -1); |
||||
} |
||||
|
||||
writer << mat; |
||||
} |
||||
} |
||||
|
||||
void CV_PositioningTest::run(int) |
||||
{ |
||||
#if defined WIN32 || (defined __linux__ && !defined ANDROID) || (defined __APPLE__ && defined HAVE_FFMPEG) |
||||
#if !defined HAVE_GSTREAMER || defined HAVE_GSTREAMER_APP |
||||
|
||||
const string format[] = {"avi", "mov", "mp4", "mpg", "wmv", "3gp"}; |
||||
|
||||
const char codec[][4] = { {'X', 'V', 'I', 'D'}, |
||||
{'m', 'p', 'e', 'g'}, |
||||
{'M', 'J', 'P', 'G'} }; |
||||
|
||||
size_t n_format = sizeof(format)/sizeof(format[0]), |
||||
n_codec = sizeof(codec)/sizeof(codec[0]); |
||||
|
||||
int n_frames = 256; |
||||
|
||||
for (size_t i = 0; i < n_format; ++i) |
||||
for (size_t j = 0; j < n_codec; ++j) |
||||
{ |
||||
CreateTestVideo(format[i], CV_FOURCC(codec[j][0], codec[j][1], codec[j][2], codec[j][3]), n_frames); |
||||
|
||||
stringstream s; s << CV_FOURCC(codec[j][0], codec[j][1], codec[j][2], codec[j][3]); //codec_bmp_tags[j].tag;
|
||||
|
||||
const string file_path = "test_video_"+s.str()+"."+format[i]; |
||||
|
||||
bool error = false; int failed = 0; |
||||
|
||||
cv::VideoCapture cap(file_path); |
||||
|
||||
if (!cap.isOpened()) |
||||
{ |
||||
ts->printf(ts->LOG, "\n\nFile: %s\n", file_path.c_str()); |
||||
ts->printf(ts->LOG, "\nVideo codec: %s\n", string(&codec[j][0], 4).c_str()); |
||||
ts->printf(ts->LOG, "\nError: cannot read video file."); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA); |
||||
error = true; |
||||
} |
||||
|
||||
cap.set(CV_CAP_PROP_POS_FRAMES, 0); |
||||
|
||||
int N = cap.get(CV_CAP_PROP_FRAME_COUNT); |
||||
|
||||
if (N != n_frames) |
||||
{ |
||||
if (!error) |
||||
{ |
||||
ts->printf(ts->LOG, "\n\nFile: %s\n", file_path.c_str()); |
||||
ts->printf(ts->LOG, "\nVideo codec: %s\n", string(&codec[j][0], 4).c_str()); |
||||
error = true; |
||||
} |
||||
ts->printf(ts->LOG, "\nError: returned frame count in clip is incorrect.\n"); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
} |
||||
|
||||
vector <int> idx; |
||||
|
||||
RNG rng(N); |
||||
idx.clear(); |
||||
for( int k = 0; k < N-1; k++ ) |
||||
idx.push_back(rng.uniform(0, N)); |
||||
idx.push_back(N-1); |
||||
std::swap(idx.at(rng.uniform(0, N-1)), idx.at(N-1)); |
||||
|
||||
for (int k = 0; k < N; ++k) |
||||
{ |
||||
cap.set(CV_CAP_PROP_POS_FRAMES, (double)idx[k]); |
||||
|
||||
cv::Mat img; cap.retrieve(img); |
||||
|
||||
if (img.empty()) |
||||
{ |
||||
if (!error) |
||||
{ |
||||
ts->printf(ts->LOG, "\n\nFile: %s\n", file_path.c_str()); |
||||
ts->printf(ts->LOG, "\nVideo codec: %s\n", string(&codec[j][0], 4).c_str()); |
||||
error = true; |
||||
} |
||||
ts->printf(ts->LOG, "\nError: cannot read a frame in position %d.\n", idx[k]); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
} |
||||
|
||||
const double thresh = 100; |
||||
|
||||
const size_t n = 8, w = img.rows/n; |
||||
|
||||
int index = 0, deg = n-1; |
||||
|
||||
for (size_t l = 0; l < n; ++l) |
||||
{ |
||||
cv::Mat mat = img.rowRange(w*l, w*(l+1)-1); |
||||
|
||||
Scalar mat_mean = cv::mean(mat); |
||||
|
||||
if (mat_mean[0] > thresh) index += (int)std::pow(2.0, 1.0*deg); |
||||
|
||||
deg--; |
||||
} |
||||
|
||||
if (index != idx[k]) |
||||
{ |
||||
if (!error) |
||||
{ |
||||
ts->printf(ts->LOG, "\n\nFile: %s\n", file_path.c_str()); |
||||
ts->printf(ts->LOG, "\nVideo codec: %s\n\n", string(&codec[j][0], 4).c_str()); |
||||
error = true; |
||||
} |
||||
ts->printf(ts->LOG, "Required position: %d Returned position: %d\n", idx[k], index); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
failed++; |
||||
} |
||||
} |
||||
|
||||
if (!error) { ts->printf(ts->LOG, "\n\nFile: %s\n", file_path.c_str()); |
||||
ts->printf(ts->LOG, "\nVideo codec: %s\n", string(&codec[j][0], 4).c_str()); } |
||||
|
||||
const string status = failed ? "FAILED" : "OK"; |
||||
ts->printf(ts->LOG, "\nSuccessfull iterations: %d(%d%%) Failed iterations: %d(%d%%) %s\n", N-failed, (N-failed)*100/N, failed, failed*100/N, status.c_str()); |
||||
if( i < n_format-1 || j < n_codec-1 ) ts->printf(ts->LOG, "\n----------"); |
||||
} |
||||
|
||||
#endif |
||||
#endif |
||||
} |
||||
|
||||
TEST(Highgui_Positioning, regression) { CV_PositioningTest test; test.safe_run(); } |
||||
|
||||
#endif |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
#include "opencv2/highgui/highgui.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace std; |
||||
|
||||
class CV_PositioningTest : public cvtest::BaseTest |
||||
{ |
||||
public: |
||||
CV_PositioningTest() |
||||
{ |
||||
framesize = Size(640, 480); |
||||
} |
||||
|
||||
Mat drawFrame(int i) |
||||
{ |
||||
Mat mat = Mat::zeros(framesize, CV_8UC3); |
||||
|
||||
mat = Scalar(fabs(cos(i*0.08)*255), fabs(sin(i*0.05)*255), i); |
||||
putText(mat, format("%03d", i), Point(10, 350), 0, 10, Scalar(128, 255, 255), 15); |
||||
return mat; |
||||
} |
||||
|
||||
string getFilename(const cvtest::VideoFormat& fmt) |
||||
{ |
||||
return format("test_video_%s.%s", cvtest::fourccToString(fmt.fourcc).c_str(), fmt.ext.c_str()); |
||||
} |
||||
|
||||
bool CreateTestVideo(const cvtest::VideoFormat& fmt, int framecount) |
||||
{ |
||||
string filename = getFilename(fmt); |
||||
|
||||
VideoWriter writer(filename, fmt.fourcc, 25, framesize, true); |
||||
if( !writer.isOpened() ) |
||||
return false; |
||||
|
||||
for (int i = 0; i < framecount; ++i) |
||||
{ |
||||
Mat img = drawFrame(i); |
||||
writer << img; |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void run(int) |
||||
{ |
||||
int n_frames = 100; |
||||
|
||||
for( int testcase = 0; ; testcase++ ) |
||||
{ |
||||
const cvtest::VideoFormat& fmt = cvtest::g_specific_fmt_list[testcase]; |
||||
if( fmt.empty() ) |
||||
break; |
||||
string filename = getFilename(fmt); |
||||
ts->printf(ts->LOG, "\nFile: %s\n", filename.c_str()); |
||||
|
||||
if( !CreateTestVideo(fmt, n_frames) ) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot create video file"); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
VideoCapture cap(filename); |
||||
|
||||
if (!cap.isOpened()) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot read video file."); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_TEST_DATA); |
||||
return; |
||||
} |
||||
|
||||
int N0 = cap.get(CV_CAP_PROP_FRAME_COUNT); |
||||
cap.set(CV_CAP_PROP_POS_FRAMES, 0); |
||||
int N = cap.get(CV_CAP_PROP_FRAME_COUNT); |
||||
|
||||
if (N != n_frames || N != N0) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: returned frame count (N0=%d, N=%d) is different from the reference number %d\n", N0, N, n_frames); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
for (int k = 0; k < N; ++k) |
||||
{ |
||||
int idx = theRNG().uniform(0, N); |
||||
|
||||
if( !cap.set(CV_CAP_PROP_POS_FRAMES, idx) ) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot seek to frame %d.\n", idx); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
int idx1 = (int)cap.get(CV_CAP_PROP_POS_FRAMES); |
||||
|
||||
Mat img; cap >> img; |
||||
Mat img0 = drawFrame(idx); |
||||
|
||||
if( idx != idx1 ) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: the current position (%d) after seek is different from specified (%d)\n", |
||||
idx1, idx); |
||||
ts->printf(ts->LOG, "Saving both frames ...\n"); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
imwrite("opencv_test_highgui_postest_actual.png", img); |
||||
imwrite("opencv_test_highgui_postest_expected.png", img0); |
||||
return; |
||||
} |
||||
|
||||
if (img.empty()) |
||||
{ |
||||
ts->printf(ts->LOG, "\nError: cannot read a frame at position %d.\n", idx); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
return; |
||||
} |
||||
|
||||
double err = PSNR(img, img0); |
||||
|
||||
if( err < 20 ) |
||||
{ |
||||
ts->printf(ts->LOG, "The frame read after positioning to %d is incorrect (PSNR=%g)\n", idx, err); |
||||
ts->printf(ts->LOG, "Saving both frames ...\n"); |
||||
ts->set_failed_test_info(ts->FAIL_INVALID_OUTPUT); |
||||
imwrite("opencv_test_highgui_postest_actual.png", img); |
||||
imwrite("opencv_test_highgui_postest_expected.png", img0); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
Size framesize; |
||||
}; |
||||
|
||||
#if BUILD_WITH_VIDEO_INPUT_SUPPORT && BUILD_WITH_VIDEO_OUTPUT_SUPPORT |
||||
TEST(Highgui_Video, seek_random_synthetic) { CV_PositioningTest test; test.safe_run(); } |
||||
#endif |
||||
|
@ -1,6 +1,6 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
||||
package="org.opencv" |
||||
android:versionCode="1" |
||||
android:versionName="1.0"> |
||||
android:versionCode="240" |
||||
android:versionName="2.4.0"> |
||||
</manifest> |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue