1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merged with HEAD and removed C interface to rotatedRectangleIntersection

This commit is contained in:
Nghia Ho
2013-09-04 20:45:10 +10:00
899 changed files with 11911 additions and 11198 deletions
+58 -8
View File
@@ -41,6 +41,50 @@
#include "precomp.hpp"
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
#define USE_IPP_CANNY 1
#else
#undef USE_IPP_CANNY
#endif
#ifdef USE_IPP_CANNY
namespace cv
{
static bool ippCanny(const Mat& _src, Mat& _dst, float low, float high)
{
int size = 0, size1 = 0;
IppiSize roi = { _src.cols, _src.rows };
ippiFilterSobelNegVertGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size);
ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roi, ippMskSize3x3, &size1);
size = std::max(size, size1);
ippiCannyGetSize(roi, &size1);
size = std::max(size, size1);
AutoBuffer<uchar> buf(size + 64);
uchar* buffer = alignPtr((uchar*)buf, 32);
Mat _dx(_src.rows, _src.cols, CV_16S);
if( ippiFilterSobelNegVertBorder_8u16s_C1R(_src.data, (int)_src.step,
_dx.ptr<short>(), (int)_dx.step, roi,
ippMskSize3x3, ippBorderRepl, 0, buffer) < 0 )
return false;
Mat _dy(_src.rows, _src.cols, CV_16S);
if( ippiFilterSobelHorizBorder_8u16s_C1R(_src.data, (int)_src.step,
_dy.ptr<short>(), (int)_dy.step, roi,
ippMskSize3x3, ippBorderRepl, 0, buffer) < 0 )
return false;
if( ippiCanny_16s8u_C1R(_dx.ptr<short>(), (int)_dx.step,
_dy.ptr<short>(), (int)_dy.step,
_dst.data, (int)_dst.step, roi, low, high, buffer) < 0 )
return false;
return true;
}
}
#endif
void cv::Canny( InputArray _src, OutputArray _dst,
double low_thresh, double high_thresh,
int aperture_size, bool L2gradient )
@@ -61,20 +105,26 @@ void cv::Canny( InputArray _src, OutputArray _dst,
if ((aperture_size & 1) == 0 || (aperture_size != -1 && (aperture_size < 3 || aperture_size > 7)))
CV_Error(CV_StsBadFlag, "");
if (low_thresh > high_thresh)
std::swap(low_thresh, high_thresh);
#ifdef HAVE_TEGRA_OPTIMIZATION
if (tegra::canny(src, dst, low_thresh, high_thresh, aperture_size, L2gradient))
return;
#endif
#ifdef USE_IPP_CANNY
if( aperture_size == 3 && !L2gradient &&
ippCanny(src, dst, low_thresh, high_thresh) >= 0 )
return;
#endif
const int cn = src.channels();
cv::Mat dx(src.rows, src.cols, CV_16SC(cn));
cv::Mat dy(src.rows, src.cols, CV_16SC(cn));
Mat dx(src.rows, src.cols, CV_16SC(cn));
Mat dy(src.rows, src.cols, CV_16SC(cn));
cv::Sobel(src, dx, CV_16S, 1, 0, aperture_size, 1, 0, cv::BORDER_REPLICATE);
cv::Sobel(src, dy, CV_16S, 0, 1, aperture_size, 1, 0, cv::BORDER_REPLICATE);
if (low_thresh > high_thresh)
std::swap(low_thresh, high_thresh);
Sobel(src, dx, CV_16S, 1, 0, aperture_size, 1, 0, cv::BORDER_REPLICATE);
Sobel(src, dy, CV_16S, 0, 1, aperture_size, 1, 0, cv::BORDER_REPLICATE);
if (L2gradient)
{
@@ -88,7 +138,7 @@ void cv::Canny( InputArray _src, OutputArray _dst,
int high = cvFloor(high_thresh);
ptrdiff_t mapstep = src.cols + 2;
cv::AutoBuffer<uchar> buffer((src.cols+2)*(src.rows+2) + cn * mapstep * 3 * sizeof(int));
AutoBuffer<uchar> buffer((src.cols+2)*(src.rows+2) + cn * mapstep * 3 * sizeof(int));
int* mag_buf[3];
mag_buf[0] = (int*)(uchar*)buffer;
+510
View File
@@ -94,6 +94,13 @@
#define CV_DESCALE(x,n) (((x) + (1 << ((n)-1))) >> (n))
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
#define MAX_IPP8u 255
#define MAX_IPP16u 65535
#define MAX_IPP32f 1.0
static IppStatus sts = ippInit();
#endif
namespace cv
{
@@ -191,6 +198,301 @@ void CvtColorLoop(const Mat& src, Mat& dst, const Cvt& cvt)
parallel_for_(Range(0, src.rows), CvtColorLoop_Invoker<Cvt>(src, dst, cvt), src.total()/(double)(1<<16) );
}
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
typedef IppStatus (CV_STDCALL* ippiReorderFunc)(const void *, int, void *, int, IppiSize, const int *);
typedef IppStatus (CV_STDCALL* ippiGeneralFunc)(const void *, int, void *, int, IppiSize);
typedef IppStatus (CV_STDCALL* ippiColor2GrayFunc)(const void *, int, void *, int, IppiSize, const Ipp32f *);
template <typename Cvt>
class CvtColorIPPLoop_Invoker : public ParallelLoopBody
{
public:
CvtColorIPPLoop_Invoker(const Mat& _src, Mat& _dst, const Cvt& _cvt, bool *_ok) :
ParallelLoopBody(), src(_src), dst(_dst), cvt(_cvt), ok(_ok)
{
*ok = true;
}
virtual void operator()(const Range& range) const
{
const void *yS = src.ptr<uchar>(range.start);
void *yD = dst.ptr<uchar>(range.start);
if( cvt(yS, (int)src.step[0], yD, (int)dst.step[0], src.cols, range.end - range.start) < 0 )
*ok = false;
}
private:
const Mat& src;
Mat& dst;
const Cvt& cvt;
bool *ok;
const CvtColorIPPLoop_Invoker& operator= (const CvtColorIPPLoop_Invoker&);
};
template <typename Cvt>
bool CvtColorIPPLoop(const Mat& src, Mat& dst, const Cvt& cvt)
{
bool ok;
parallel_for_(Range(0, src.rows), CvtColorIPPLoop_Invoker<Cvt>(src, dst, cvt, &ok), src.total()/(double)(1<<16) );
return ok;
}
template <typename Cvt>
bool CvtColorIPPLoopCopy(Mat& src, Mat& dst, const Cvt& cvt)
{
Mat temp;
Mat &source = src;
if( src.data == dst.data )
{
src.copyTo(temp);
source = temp;
}
bool ok;
parallel_for_(Range(0, source.rows), CvtColorIPPLoop_Invoker<Cvt>(source, dst, cvt, &ok), source.total()/(double)(1<<16) );
return ok;
}
IppStatus __stdcall ippiSwapChannels_8u_C3C4Rf(const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep,
IppiSize roiSize, const int *dstOrder)
{
return ippiSwapChannels_8u_C3C4R(pSrc, srcStep, pDst, dstStep, roiSize, dstOrder, MAX_IPP8u);
}
IppStatus __stdcall ippiSwapChannels_16u_C3C4Rf(const Ipp16u* pSrc, int srcStep, Ipp16u* pDst, int dstStep,
IppiSize roiSize, const int *dstOrder)
{
return ippiSwapChannels_16u_C3C4R(pSrc, srcStep, pDst, dstStep, roiSize, dstOrder, MAX_IPP16u);
}
IppStatus __stdcall ippiSwapChannels_32f_C3C4Rf(const Ipp32f* pSrc, int srcStep, Ipp32f* pDst, int dstStep,
IppiSize roiSize, const int *dstOrder)
{
return ippiSwapChannels_32f_C3C4R(pSrc, srcStep, pDst, dstStep, roiSize, dstOrder, MAX_IPP32f);
}
static ippiReorderFunc ippiSwapChannelsC3C4RTab[] =
{
(ippiReorderFunc)ippiSwapChannels_8u_C3C4Rf, 0, (ippiReorderFunc)ippiSwapChannels_16u_C3C4Rf, 0,
0, (ippiReorderFunc)ippiSwapChannels_32f_C3C4Rf, 0, 0
};
static ippiGeneralFunc ippiCopyAC4C3RTab[] =
{
(ippiGeneralFunc)ippiCopy_8u_AC4C3R, 0, (ippiGeneralFunc)ippiCopy_16u_AC4C3R, 0,
0, (ippiGeneralFunc)ippiCopy_32f_AC4C3R, 0, 0
};
static ippiReorderFunc ippiSwapChannelsC4C3RTab[] =
{
(ippiReorderFunc)ippiSwapChannels_8u_C4C3R, 0, (ippiReorderFunc)ippiSwapChannels_16u_C4C3R, 0,
0, (ippiReorderFunc)ippiSwapChannels_32f_C4C3R, 0, 0
};
static ippiReorderFunc ippiSwapChannelsC3RTab[] =
{
(ippiReorderFunc)ippiSwapChannels_8u_C3R, 0, (ippiReorderFunc)ippiSwapChannels_16u_C3R, 0,
0, (ippiReorderFunc)ippiSwapChannels_32f_C3R, 0, 0
};
static ippiReorderFunc ippiSwapChannelsC4RTab[] =
{
(ippiReorderFunc)ippiSwapChannels_8u_AC4R, 0, (ippiReorderFunc)ippiSwapChannels_16u_AC4R, 0,
0, (ippiReorderFunc)ippiSwapChannels_32f_AC4R, 0, 0
};
static ippiColor2GrayFunc ippiColor2GrayC3Tab[] =
{
(ippiColor2GrayFunc)ippiColorToGray_8u_C3C1R, 0, (ippiColor2GrayFunc)ippiColorToGray_16u_C3C1R, 0,
0, (ippiColor2GrayFunc)ippiColorToGray_32f_C3C1R, 0, 0
};
static ippiColor2GrayFunc ippiColor2GrayC4Tab[] =
{
(ippiColor2GrayFunc)ippiColorToGray_8u_AC4C1R, 0, (ippiColor2GrayFunc)ippiColorToGray_16u_AC4C1R, 0,
0, (ippiColor2GrayFunc)ippiColorToGray_32f_AC4C1R, 0, 0
};
static ippiGeneralFunc ippiRGB2GrayC3Tab[] =
{
(ippiGeneralFunc)ippiRGBToGray_8u_C3C1R, 0, (ippiGeneralFunc)ippiRGBToGray_16u_C3C1R, 0,
0, (ippiGeneralFunc)ippiRGBToGray_32f_C3C1R, 0, 0
};
static ippiGeneralFunc ippiRGB2GrayC4Tab[] =
{
(ippiGeneralFunc)ippiRGBToGray_8u_AC4C1R, 0, (ippiGeneralFunc)ippiRGBToGray_16u_AC4C1R, 0,
0, (ippiGeneralFunc)ippiRGBToGray_32f_AC4C1R, 0, 0
};
static ippiGeneralFunc ippiCopyP3C3RTab[] =
{
(ippiGeneralFunc)ippiCopy_8u_P3C3R, 0, (ippiGeneralFunc)ippiCopy_16u_P3C3R, 0,
0, (ippiGeneralFunc)ippiCopy_32f_P3C3R, 0, 0
};
static ippiGeneralFunc ippiRGB2XYZTab[] =
{
(ippiGeneralFunc)ippiRGBToXYZ_8u_C3R, 0, (ippiGeneralFunc)ippiRGBToXYZ_16u_C3R, 0,
0, (ippiGeneralFunc)ippiRGBToXYZ_32f_C3R, 0, 0
};
static ippiGeneralFunc ippiXYZ2RGBTab[] =
{
(ippiGeneralFunc)ippiXYZToRGB_8u_C3R, 0, (ippiGeneralFunc)ippiXYZToRGB_16u_C3R, 0,
0, (ippiGeneralFunc)ippiXYZToRGB_32f_C3R, 0, 0
};
static ippiGeneralFunc ippiRGB2HSVTab[] =
{
(ippiGeneralFunc)ippiRGBToHSV_8u_C3R, 0, (ippiGeneralFunc)ippiRGBToHSV_16u_C3R, 0,
0, 0, 0, 0
};
static ippiGeneralFunc ippiHSV2RGBTab[] =
{
(ippiGeneralFunc)ippiHSVToRGB_8u_C3R, 0, (ippiGeneralFunc)ippiHSVToRGB_16u_C3R, 0,
0, 0, 0, 0
};
static ippiGeneralFunc ippiRGB2HLSTab[] =
{
(ippiGeneralFunc)ippiRGBToHLS_8u_C3R, 0, (ippiGeneralFunc)ippiRGBToHLS_16u_C3R, 0,
0, (ippiGeneralFunc)ippiRGBToHLS_32f_C3R, 0, 0
};
static ippiGeneralFunc ippiHLS2RGBTab[] =
{
(ippiGeneralFunc)ippiHLSToRGB_8u_C3R, 0, (ippiGeneralFunc)ippiHLSToRGB_16u_C3R, 0,
0, (ippiGeneralFunc)ippiHLSToRGB_32f_C3R, 0, 0
};
struct IPPGeneralFunctor
{
IPPGeneralFunctor(ippiGeneralFunc _func) : func(_func){}
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{
return func(src, srcStep, dst, dstStep, ippiSize(cols, rows)) >= 0;
}
private:
ippiGeneralFunc func;
};
struct IPPReorderFunctor
{
IPPReorderFunctor(ippiReorderFunc _func, int _order0, int _order1, int _order2) : func(_func)
{
order[0] = _order0;
order[1] = _order1;
order[2] = _order2;
order[3] = 3;
}
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{
return func(src, srcStep, dst, dstStep, ippiSize(cols, rows), order) >= 0;
}
private:
ippiReorderFunc func;
int order[4];
};
struct IPPColor2GrayFunctor
{
IPPColor2GrayFunctor(ippiColor2GrayFunc _func) : func(_func)
{
coeffs[0] = 0.114f;
coeffs[1] = 0.587f;
coeffs[2] = 0.299f;
}
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{
return func(src, srcStep, dst, dstStep, ippiSize(cols, rows), coeffs) >= 0;
}
private:
ippiColor2GrayFunc func;
Ipp32f coeffs[3];
};
struct IPPGray2BGRFunctor
{
IPPGray2BGRFunctor(ippiGeneralFunc _func) : func(_func){}
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{
const void* srcarray[3] = { src, src, src };
return func(srcarray, srcStep, dst, dstStep, ippiSize(cols, rows)) >= 0;
}
private:
ippiGeneralFunc func;
};
struct IPPGray2BGRAFunctor
{
IPPGray2BGRAFunctor(ippiGeneralFunc _func1, ippiReorderFunc _func2, int _depth) : func1(_func1), func2(_func2), depth(_depth){}
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{
const void* srcarray[3] = { src, src, src };
Mat temp(rows, cols, CV_MAKETYPE(depth, 3));
if(func1(srcarray, srcStep, temp.data, (int)temp.step[0], ippiSize(cols, rows)) < 0)
return false;
int order[4] = {0, 1, 2, 3};
return func2(temp.data, (int)temp.step[0], dst, dstStep, ippiSize(cols, rows), order) >= 0;
}
private:
ippiGeneralFunc func1;
ippiReorderFunc func2;
int depth;
};
struct IPPReorderGeneralFunctor
{
IPPReorderGeneralFunctor(ippiReorderFunc _func1, ippiGeneralFunc _func2, int _order0, int _order1, int _order2, int _depth) : func1(_func1), func2(_func2), depth(_depth)
{
order[0] = _order0;
order[1] = _order1;
order[2] = _order2;
order[3] = 3;
}
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{
Mat temp;
temp.create(rows, cols, CV_MAKETYPE(depth, 3));
if(func1(src, srcStep, temp.data, (int)temp.step[0], ippiSize(cols, rows), order) < 0)
return false;
return func2(temp.data, (int)temp.step[0], dst, dstStep, ippiSize(cols, rows)) >= 0;
}
private:
ippiReorderFunc func1;
ippiGeneralFunc func2;
int order[4];
int depth;
};
struct IPPGeneralReorderFunctor
{
IPPGeneralReorderFunctor(ippiGeneralFunc _func1, ippiReorderFunc _func2, int _order0, int _order1, int _order2, int _depth) : func1(_func1), func2(_func2), depth(_depth)
{
order[0] = _order0;
order[1] = _order1;
order[2] = _order2;
order[3] = 3;
}
bool operator()(const void *src, int srcStep, void *dst, int dstStep, int cols, int rows) const
{
Mat temp;
temp.create(rows, cols, CV_MAKETYPE(depth, 3));
if(func1(src, srcStep, temp.data, (int)temp.step[0], ippiSize(cols, rows)) < 0)
return false;
return func2(temp.data, (int)temp.step[0], dst, dstStep, ippiSize(cols, rows), order) >= 0;
}
private:
ippiGeneralFunc func1;
ippiReorderFunc func2;
int order[4];
int depth;
};
#endif
////////////////// Various 3/4-channel to 3/4-channel RGB transformations /////////////////
template<typename _Tp> struct RGB2RGB
@@ -2410,6 +2712,39 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst.create( sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( code == CV_BGR2BGRA || code == CV_RGB2RGBA)
{
if ( CvtColorIPPLoop(src, dst, IPPReorderFunctor(ippiSwapChannelsC3C4RTab[depth], 0, 1, 2)) )
return;
}
else if( code == CV_BGRA2BGR )
{
if ( CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiCopyAC4C3RTab[depth])) )
return;
}
else if( code == CV_BGR2RGBA )
{
if( CvtColorIPPLoop(src, dst, IPPReorderFunctor(ippiSwapChannelsC3C4RTab[depth], 2, 1, 0)) )
return;
}
else if( code == CV_RGBA2BGR )
{
if( CvtColorIPPLoop(src, dst, IPPReorderFunctor(ippiSwapChannelsC4C3RTab[depth], 2, 1, 0)) )
return;
}
else if( code == CV_RGB2BGR )
{
if( CvtColorIPPLoopCopy(src, dst, IPPReorderFunctor(ippiSwapChannelsC3RTab[depth], 2, 1, 0)) )
return;
}
else if( code == CV_RGBA2BGRA )
{
if( CvtColorIPPLoopCopy(src, dst, IPPReorderFunctor(ippiSwapChannelsC4RTab[depth], 2, 1, 0)) )
return;
}
#endif
if( depth == CV_8U )
{
#ifdef HAVE_TEGRA_OPTIMIZATION
@@ -2463,6 +2798,29 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst.create(sz, CV_MAKETYPE(depth, 1));
dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( code == CV_BGR2GRAY )
{
if( CvtColorIPPLoop(src, dst, IPPColor2GrayFunctor(ippiColor2GrayC3Tab[depth])) )
return;
}
else if( code == CV_RGB2GRAY )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiRGB2GrayC3Tab[depth])) )
return;
}
else if( code == CV_BGRA2GRAY )
{
if( CvtColorIPPLoop(src, dst, IPPColor2GrayFunctor(ippiColor2GrayC4Tab[depth])) )
return;
}
else if( code == CV_RGBA2GRAY )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiRGB2GrayC4Tab[depth])) )
return;
}
#endif
bidx = code == CV_BGR2GRAY || code == CV_BGRA2GRAY ? 0 : 2;
if( depth == CV_8U )
@@ -2492,6 +2850,20 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( code == CV_GRAY2BGR )
{
if( CvtColorIPPLoop(src, dst, IPPGray2BGRFunctor(ippiCopyP3C3RTab[depth])) )
return;
}
else if( code == CV_GRAY2BGRA )
{
if( CvtColorIPPLoop(src, dst, IPPGray2BGRAFunctor(ippiCopyP3C3RTab[depth], ippiSwapChannelsC3C4RTab[depth], depth)) )
return;
}
#endif
if( depth == CV_8U )
{
#ifdef HAVE_TEGRA_OPTIMIZATION
@@ -2571,6 +2943,29 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst.create(sz, CV_MAKETYPE(depth, 3));
dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( code == CV_BGR2XYZ && scn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth], ippiRGB2XYZTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_BGR2XYZ && scn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth], ippiRGB2XYZTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_RGB2XYZ && scn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralFunctor(ippiRGB2XYZTab[depth])) )
return;
}
else if( code == CV_RGB2XYZ && scn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth], ippiRGB2XYZTab[depth], 0, 1, 2, depth)) )
return;
}
#endif
if( depth == CV_8U )
CvtColorLoop(src, dst, RGB2XYZ_i<uchar>(scn, bidx, 0));
else if( depth == CV_16U )
@@ -2587,6 +2982,29 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( code == CV_XYZ2BGR && dcn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralReorderFunctor(ippiXYZ2RGBTab[depth], ippiSwapChannelsC3RTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_XYZ2BGR && dcn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiXYZ2RGBTab[depth], ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)) )
return;
}
if( code == CV_XYZ2RGB && dcn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralFunctor(ippiXYZ2RGBTab[depth])) )
return;
}
else if( code == CV_XYZ2RGB && dcn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiXYZ2RGBTab[depth], ippiSwapChannelsC3C4RTab[depth], 0, 1, 2, depth)) )
return;
}
#endif
if( depth == CV_8U )
CvtColorLoop(src, dst, XYZ2RGB_i<uchar>(dcn, bidx, 0));
else if( depth == CV_16U )
@@ -2607,6 +3025,52 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst.create(sz, CV_MAKETYPE(depth, 3));
dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( depth == CV_8U || depth == CV_16U )
{
if( code == CV_BGR2HSV_FULL && scn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth], ippiRGB2HSVTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_BGR2HSV_FULL && scn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth], ippiRGB2HSVTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_RGB2HSV_FULL && scn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralFunctor(ippiRGB2HSVTab[depth])) )
return;
}
else if( code == CV_RGB2HSV_FULL && scn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth], ippiRGB2HSVTab[depth], 0, 1, 2, depth)) )
return;
}
else if( code == CV_BGR2HLS_FULL && scn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC3RTab[depth], ippiRGB2HLSTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_BGR2HLS_FULL && scn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth], ippiRGB2HLSTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_RGB2HLS_FULL && scn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralFunctor(ippiRGB2HLSTab[depth])) )
return;
}
else if( code == CV_RGB2HLS_FULL && scn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPReorderGeneralFunctor(ippiSwapChannelsC4C3RTab[depth], ippiRGB2HLSTab[depth], 0, 1, 2, depth)) )
return;
}
}
#endif
if( code == CV_BGR2HSV || code == CV_RGB2HSV ||
code == CV_BGR2HSV_FULL || code == CV_RGB2HSV_FULL )
{
@@ -2642,6 +3106,52 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
_dst.create(sz, CV_MAKETYPE(depth, dcn));
dst = _dst.getMat();
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( depth == CV_8U || depth == CV_16U )
{
if( code == CV_HSV2BGR_FULL && dcn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralReorderFunctor(ippiHSV2RGBTab[depth], ippiSwapChannelsC3RTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_HSV2BGR_FULL && dcn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiHSV2RGBTab[depth], ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_HSV2RGB_FULL && dcn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralFunctor(ippiHSV2RGBTab[depth])) )
return;
}
else if( code == CV_HSV2RGB_FULL && dcn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiHSV2RGBTab[depth], ippiSwapChannelsC3C4RTab[depth], 0, 1, 2, depth)) )
return;
}
else if( code == CV_HLS2BGR_FULL && dcn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralReorderFunctor(ippiHLS2RGBTab[depth], ippiSwapChannelsC3RTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_HLS2BGR_FULL && dcn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiHLS2RGBTab[depth], ippiSwapChannelsC3C4RTab[depth], 2, 1, 0, depth)) )
return;
}
else if( code == CV_HLS2RGB_FULL && dcn == 3 )
{
if( CvtColorIPPLoopCopy(src, dst, IPPGeneralFunctor(ippiHLS2RGBTab[depth])) )
return;
}
else if( code == CV_HLS2RGB_FULL && dcn == 4 )
{
if( CvtColorIPPLoop(src, dst, IPPGeneralReorderFunctor(ippiHLS2RGBTab[depth], ippiSwapChannelsC3C4RTab[depth], 0, 1, 2, depth)) )
return;
}
}
#endif
if( code == CV_HSV2BGR || code == CV_HSV2RGB ||
code == CV_HSV2BGR_FULL || code == CV_HSV2RGB_FULL )
{
+5 -17
View File
@@ -92,20 +92,10 @@ namespace cv{
}
void operator()(int r, int c, int l){
int *row = &statsv.at<int>(l, 0);
if(c > row[CC_STAT_WIDTH]){
row[CC_STAT_WIDTH] = c;
}else{
if(c < row[CC_STAT_LEFT]){
row[CC_STAT_LEFT] = c;
}
}
if(r > row[CC_STAT_HEIGHT]){
row[CC_STAT_HEIGHT] = r;
}else{
if(r < row[CC_STAT_TOP]){
row[CC_STAT_TOP] = r;
}
}
row[CC_STAT_LEFT] = MIN(row[CC_STAT_LEFT], c);
row[CC_STAT_WIDTH] = MAX(row[CC_STAT_WIDTH], c);
row[CC_STAT_TOP] = MIN(row[CC_STAT_TOP], r);
row[CC_STAT_HEIGHT] = MAX(row[CC_STAT_HEIGHT], r);
row[CC_STAT_AREA]++;
Point2ui64 &integral = integrals[l];
integral.x += c;
@@ -114,9 +104,7 @@ namespace cv{
void finish(){
for(int l = 0; l < statsv.rows; ++l){
int *row = &statsv.at<int>(l, 0);
row[CC_STAT_LEFT] = std::min(row[CC_STAT_LEFT], row[CC_STAT_WIDTH]);
row[CC_STAT_WIDTH] = row[CC_STAT_WIDTH] - row[CC_STAT_LEFT] + 1;
row[CC_STAT_TOP] = std::min(row[CC_STAT_TOP], row[CC_STAT_HEIGHT]);
row[CC_STAT_HEIGHT] = row[CC_STAT_HEIGHT] - row[CC_STAT_TOP] + 1;
Point2ui64 &integral = integrals[l];
@@ -399,7 +387,7 @@ int cv::connectedComponentsWithStats(InputArray _img, OutputArray _labels, Outpu
const cv::Mat img = _img.getMat();
_labels.create(img.size(), CV_MAT_DEPTH(ltype));
cv::Mat labels = _labels.getMat();
connectedcomponents::CCStatsOp sop(statsv, centroids);
connectedcomponents::CCStatsOp sop(statsv, centroids);
if(ltype == CV_16U){
return connectedComponents_sub1(img, labels, connectivity, sop);
}else if(ltype == CV_32S){
+17 -9
View File
@@ -1990,12 +1990,12 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
const float* h2 = (const float*)it.planes[1].data;
len = it.planes[0].rows*it.planes[0].cols*H1.channels();
if( method == CV_COMP_CHISQR )
if( (method == CV_COMP_CHISQR) || (method == CV_COMP_CHISQR_ALT))
{
for( j = 0; j < len; j++ )
{
double a = h1[j] - h2[j];
double b = h1[j];
double b = (method == CV_COMP_CHISQR) ? h1[j] : h1[j] + h2[j];
if( fabs(b) > DBL_EPSILON )
result += a*a/b;
}
@@ -2034,7 +2034,9 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
CV_Error( CV_StsBadArg, "Unknown comparison method" );
}
if( method == CV_COMP_CORREL )
if( method == CV_COMP_CHISQR_ALT )
result *= 2;
else if( method == CV_COMP_CORREL )
{
size_t total = H1.total();
double scale = 1./total;
@@ -2063,13 +2065,13 @@ double cv::compareHist( const SparseMat& H1, const SparseMat& H2, int method )
CV_Assert( H1.size(i) == H2.size(i) );
const SparseMat *PH1 = &H1, *PH2 = &H2;
if( PH1->nzcount() > PH2->nzcount() && method != CV_COMP_CHISQR )
if( PH1->nzcount() > PH2->nzcount() && method != CV_COMP_CHISQR && method != CV_COMP_CHISQR_ALT)
std::swap(PH1, PH2);
SparseMatConstIterator it = PH1->begin();
int N1 = (int)PH1->nzcount(), N2 = (int)PH2->nzcount();
if( method == CV_COMP_CHISQR )
if( (method == CV_COMP_CHISQR) || (method == CV_COMP_CHISQR_ALT) )
{
for( i = 0; i < N1; i++, ++it )
{
@@ -2077,7 +2079,7 @@ double cv::compareHist( const SparseMat& H1, const SparseMat& H2, int method )
const SparseMat::Node* node = it.node();
float v2 = PH2->value<float>(node->idx, (size_t*)&node->hashval);
double a = v1 - v2;
double b = v1;
double b = (method == CV_COMP_CHISQR) ? v1 : v1 + v2;
if( fabs(b) > DBL_EPSILON )
result += a*a/b;
}
@@ -2146,6 +2148,9 @@ double cv::compareHist( const SparseMat& H1, const SparseMat& H2, int method )
else
CV_Error( CV_StsBadArg, "Unknown comparison method" );
if( method == CV_COMP_CHISQR_ALT )
result *= 2;
return result;
}
@@ -2485,13 +2490,13 @@ cvCompareHist( const CvHistogram* hist1,
CvSparseMatIterator iterator;
CvSparseNode *node1, *node2;
if( mat1->heap->active_count > mat2->heap->active_count && method != CV_COMP_CHISQR )
if( mat1->heap->active_count > mat2->heap->active_count && method != CV_COMP_CHISQR && method != CV_COMP_CHISQR_ALT)
{
CvSparseMat* t;
CV_SWAP( mat1, mat2, t );
}
if( method == CV_COMP_CHISQR )
if( (method == CV_COMP_CHISQR) || (method == CV_COMP_CHISQR_ALT) )
{
for( node1 = cvInitSparseMatIterator( mat1, &iterator );
node1 != 0; node1 = cvGetNextSparseNode( &iterator ))
@@ -2500,7 +2505,7 @@ cvCompareHist( const CvHistogram* hist1,
uchar* node2_data = cvPtrND( mat2, CV_NODE_IDX(mat1,node1), 0, 0, &node1->hashval );
double v2 = node2_data ? *(float*)node2_data : 0.f;
double a = v1 - v2;
double b = v1;
double b = (method == CV_COMP_CHISQR) ? v1 : v1 + v2;
if( fabs(b) > DBL_EPSILON )
result += a*a/b;
}
@@ -2590,6 +2595,9 @@ cvCompareHist( const CvHistogram* hist1,
else
CV_Error( CV_StsBadArg, "Unknown comparison method" );
if( method == CV_COMP_CHISQR_ALT )
result *= 2;
return result;
}
-16
View File
@@ -250,19 +250,3 @@ int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& r
}
} // end namespace
int cvRotatedRectangleIntersection( const CvBox2D* rect1, const CvBox2D* rect2, CvPoint2D32f intersectingRegion[8], int* pointCount )
{
std::vector <cv::Point2f> pts;
int ret = cv::rotatedRectangleIntersection( *rect1, *rect2, pts );
for( size_t i=0; i < pts.size(); i++ )
{
intersectingRegion[i] = pts[i];
}
*pointCount = (int)pts.size();
return ret;
}
+8 -8
View File
@@ -571,14 +571,14 @@ static void fitLine3D( Point3f * points, int count, int dist,
for( j = 0; j < count; j++ )
w[j] = 1.f;
}
/* save the line parameters */
memcpy( _lineprev, _line, 6 * sizeof( float ));
/* Run again... */
fitLine3D_wods( points, count, w, _line );
}
if( err < min_err )
{
min_err = err;
@@ -595,27 +595,27 @@ void cv::fitLine( InputArray _points, OutputArray _line, int distType,
double param, double reps, double aeps )
{
Mat points = _points.getMat();
float linebuf[6]={0.f};
int npoints2 = points.checkVector(2, -1, false);
int npoints3 = points.checkVector(3, -1, false);
CV_Assert( npoints2 >= 0 || npoints3 >= 0 );
if( points.depth() != CV_32F || !points.isContinuous() )
{
Mat temp;
points.convertTo(temp, CV_32F);
points = temp;
}
if( npoints2 >= 0 )
fitLine2D( points.ptr<Point2f>(), npoints2, distType,
(float)param, (float)reps, (float)aeps, linebuf);
else
fitLine3D( points.ptr<Point3f>(), npoints3, distType,
(float)param, (float)reps, (float)aeps, linebuf);
Mat(npoints2 >= 0 ? 4 : 6, 1, CV_32F, linebuf).copyTo(_line);
}
+1 -1
View File
@@ -142,7 +142,7 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
default:
CV_Error( CV_StsBadArg, "Unknown comparison method" );
}
return result;
}
+2 -2
View File
@@ -159,7 +159,7 @@ static Moments contourMoments( const Mat& contour )
if( fabs(a00) > FLT_EPSILON )
{
double db1_2, db1_6, db1_12, db1_24, db1_20, db1_60;
if( a00 > 0 )
{
db1_2 = 0.5;
@@ -464,7 +464,7 @@ cv::Moments cv::moments( InputArray _src, bool binary )
m.m03 += mom[9] + y * (3. * mom[5] + y * (3. * mom[2] + ym));
}
}
completeMomentState( &m );
return m;
}
+139 -122
View File
@@ -1137,136 +1137,153 @@ private:
};
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kernel, const Point &anchor)
static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kernel,
const Size& ksize, const Point &anchor, bool rectKernel)
{
int type = src.type();
const Mat* _src = &src;
Mat temp;
if( src.data == dst.data )
{
src.copyTo(temp);
_src = &temp;
}
//DEPRECATED. Allocates and initializes morphology state structure for erosion or dilation operation.
typedef IppStatus (CV_STDCALL* ippiMorphologyInitAllocFunc)(int, const void*, IppiSize, IppiPoint, IppiMorphState **);
ippiMorphologyInitAllocFunc ippInitAllocFunc =
type == CV_8UC1 ? (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_8u_C1R :
type == CV_8UC3 ? (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_8u_C3R :
type == CV_8UC4 ? (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_8u_C4R :
type == CV_32FC1 ? (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_32f_C1R :
type == CV_32FC3 ? (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_32f_C3R :
type == CV_32FC4 ? (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_32f_C4R :
0;
typedef IppStatus (CV_STDCALL* ippiMorphologyBorderReplicateFunc)(const void*, int, void *, int, IppiSize, IppiBorderType, IppiMorphState *);
ippiMorphologyBorderReplicateFunc ippFunc = 0;
switch( op )
{
case MORPH_DILATE:
{
ippFunc =
type == CV_8UC1 ? (ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_8u_C1R :
type == CV_8UC3 ? (ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_8u_C3R :
type == CV_8UC4 ? (ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_8u_C4R :
type == CV_32FC1 ? (ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_32f_C1R :
type == CV_32FC3 ? (ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_32f_C3R :
type == CV_32FC4 ? (ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_32f_C4R :
0;
break;
}
case MORPH_ERODE:
{
ippFunc =
type == CV_8UC1 ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_8u_C1R :
type == CV_8UC3 ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_8u_C3R :
type == CV_8UC4 ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_8u_C4R :
type == CV_32FC1 ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_32f_C1R :
type == CV_32FC3 ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_32f_C3R :
type == CV_32FC4 ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_32f_C4R :
0;
break;
}
}
if( ippFunc && ippInitAllocFunc)
{
IppiMorphState* pState;
IppiSize roiSize = {src.cols, src.rows};
IppiSize kernelSize = {kernel.cols, kernel.rows};
IppiPoint point = {anchor.x, anchor.y};
if( ippInitAllocFunc( roiSize.width, kernel.data, kernelSize, point, &pState ) < 0 )
return false;
bool is_ok = ippFunc( _src->data, _src->step[0], dst.data, dst.step[0], roiSize, ippBorderRepl, pState ) >= 0;
ippiMorphologyFree(pState);
return is_ok;
}
return false;
int type = src.type();
const Mat* _src = &src;
Mat temp;
if( src.data == dst.data )
{
src.copyTo(temp);
_src = &temp;
}
//DEPRECATED. Allocates and initializes morphology state structure for erosion or dilation operation.
typedef IppStatus (CV_STDCALL* ippiMorphologyInitAllocFunc)(int, const void*, IppiSize, IppiPoint, IppiMorphState **);
typedef IppStatus (CV_STDCALL* ippiMorphologyBorderReplicateFunc)(const void*, int, void *, int,
IppiSize, IppiBorderType, IppiMorphState *);
typedef IppStatus (CV_STDCALL* ippiFilterMinMaxGetBufferSizeFunc)(int, IppiSize, int*);
typedef IppStatus (CV_STDCALL* ippiFilterMinMaxBorderReplicateFunc)(const void*, int, void*, int,
IppiSize, IppiSize, IppiPoint, void*);
ippiMorphologyInitAllocFunc initAllocFunc = 0;
ippiMorphologyBorderReplicateFunc morphFunc = 0;
ippiFilterMinMaxGetBufferSizeFunc getBufSizeFunc = 0;
ippiFilterMinMaxBorderReplicateFunc morphRectFunc = 0;
#define IPP_MORPH_CASE(type, flavor) \
case type: \
initAllocFunc = (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_##flavor; \
morphFunc = op == MORPH_ERODE ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_##flavor : \
(ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_##flavor; \
getBufSizeFunc = (ippiFilterMinMaxGetBufferSizeFunc)ippiFilterMinGetBufferSize_##flavor; \
morphRectFunc = op == MORPH_ERODE ? (ippiFilterMinMaxBorderReplicateFunc)ippiFilterMinBorderReplicate_##flavor : \
(ippiFilterMinMaxBorderReplicateFunc)ippiFilterMaxBorderReplicate_##flavor; \
break
switch( type )
{
IPP_MORPH_CASE(CV_8UC1, 8u_C1R);
IPP_MORPH_CASE(CV_8UC3, 8u_C3R);
IPP_MORPH_CASE(CV_8UC4, 8u_C4R);
IPP_MORPH_CASE(CV_32FC1, 32f_C1R);
IPP_MORPH_CASE(CV_32FC3, 32f_C3R);
IPP_MORPH_CASE(CV_32FC4, 32f_C4R);
default:
return false;
}
#undef IPP_MORPH_CASE
IppiSize roiSize = {src.cols, src.rows};
IppiSize kernelSize = {ksize.width, ksize.height};
IppiPoint point = {anchor.x, anchor.y};
if( !rectKernel && morphFunc && initAllocFunc )
{
IppiMorphState* pState;
if( initAllocFunc( roiSize.width, kernel.data, kernelSize, point, &pState ) < 0 )
return false;
bool is_ok = morphFunc( _src->data, (int)_src->step[0],
dst.data, (int)dst.step[0],
roiSize, ippBorderRepl, pState ) >= 0;
ippiMorphologyFree(pState);
return is_ok;
}
else if( rectKernel && morphRectFunc && getBufSizeFunc )
{
int bufSize = 0;
if( getBufSizeFunc( src.cols, kernelSize, &bufSize) < 0 )
return false;
AutoBuffer<uchar> buf(bufSize + 64);
uchar* buffer = alignPtr((uchar*)buf, 32);
return morphRectFunc(_src->data, (int)_src->step[0], dst.data, (int)dst.step[0],
roiSize, kernelSize, point, buffer) >= 0;
}
return false;
}
static bool IPPMorphOp(int op, InputArray _src, OutputArray _dst,
InputArray _kernel,
const Point &anchor, int iterations,
int borderType, const Scalar &borderValue)
InputArray _kernel,
const Point &anchor, int iterations,
int borderType, const Scalar &borderValue)
{
Mat src = _src.getMat(), kernel = _kernel.getMat();
if( !( src.depth() == CV_8U || src.depth() == CV_32F ) || ( iterations > 1 ) ||
!( borderType == cv::BORDER_REPLICATE || (borderType == cv::BORDER_CONSTANT && borderValue == morphologyDefaultBorderValue()) )
|| !( op == MORPH_DILATE || op == MORPH_ERODE) )
return false;
if( borderType == cv::BORDER_CONSTANT )
{
int x, y;
for( y = 0; y < kernel.rows; y++ )
{
if( kernel.at<uchar>(y, anchor.x) != 0 )
continue;
for( x = 0; x < kernel.cols; x++ )
{
if( kernel.at<uchar>(y,x) != 0 )
return false;
}
}
for( x = 0; y < kernel.cols; x++ )
{
if( kernel.at<uchar>(anchor.y, x) != 0 )
continue;
for( y = 0; y < kernel.rows; y++ )
{
if( kernel.at<uchar>(y,x) != 0 )
return false;
}
}
Mat src = _src.getMat(), kernel = _kernel.getMat();
if( !( src.depth() == CV_8U || src.depth() == CV_32F ) || ( iterations > 1 ) ||
!( borderType == cv::BORDER_REPLICATE || (borderType == cv::BORDER_CONSTANT && borderValue == morphologyDefaultBorderValue()) )
|| !( op == MORPH_DILATE || op == MORPH_ERODE) )
return false;
if( borderType == cv::BORDER_CONSTANT && kernel.data )
{
int x, y;
for( y = 0; y < kernel.rows; y++ )
{
if( kernel.at<uchar>(y, anchor.x) != 0 )
continue;
for( x = 0; x < kernel.cols; x++ )
{
if( kernel.at<uchar>(y,x) != 0 )
return false;
}
}
for( x = 0; y < kernel.cols; x++ )
{
if( kernel.at<uchar>(anchor.y, x) != 0 )
continue;
for( y = 0; y < kernel.rows; y++ )
{
if( kernel.at<uchar>(y,x) != 0 )
return false;
}
}
}
Size ksize = kernel.data ? kernel.size() : Size(3,3);
Point normanchor = normalizeAnchor(anchor, ksize);
}
Size ksize = kernel.data ? kernel.size() : Size(3,3);
Point normanchor = normalizeAnchor(anchor, ksize);
CV_Assert( normanchor.inside(Rect(0, 0, ksize.width, ksize.height)) );
CV_Assert( normanchor.inside(Rect(0, 0, ksize.width, ksize.height)) );
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
if( iterations == 0 || kernel.rows*kernel.cols == 1 )
{
src.copyTo(dst);
return true;
}
if( iterations == 0 || kernel.rows*kernel.cols == 1 )
{
src.copyTo(dst);
return true;
}
if( !kernel.data )
{
kernel = getStructuringElement(MORPH_RECT, Size(1+iterations*2,1+iterations*2));
normanchor = Point(iterations, iterations);
iterations = 1;
}
else if( iterations > 1 && countNonZero(kernel) == kernel.rows*kernel.cols )
{
normanchor = Point(normanchor.x*iterations, normanchor.y*iterations);
kernel = getStructuringElement(MORPH_RECT,
Size(ksize.width + (iterations-1)*(ksize.width-1),
ksize.height + (iterations-1)*(ksize.height-1)),
normanchor);
iterations = 1;
}
bool rectKernel = false;
if( !kernel.data )
{
ksize = Size(1+iterations*2,1+iterations*2);
normanchor = Point(iterations, iterations);
rectKernel = true;
iterations = 1;
}
else if( iterations >= 1 && countNonZero(kernel) == kernel.rows*kernel.cols )
{
ksize = Size(ksize.width + (iterations-1)*(ksize.width-1),
ksize.height + (iterations-1)*(ksize.height-1)),
normanchor = Point(normanchor.x*iterations, normanchor.y*iterations);
kernel = Mat();
rectKernel = true;
iterations = 1;
}
return IPPMorphReplicate( op, src, dst, kernel, normanchor );
// TODO: implement the case of iterations > 1.
if( iterations > 1 )
return false;
return IPPMorphReplicate( op, src, dst, kernel, ksize, normanchor, rectKernel );
}
#endif
@@ -1277,8 +1294,8 @@ static void morphOp( int op, InputArray _src, OutputArray _dst,
{
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( IPPMorphOp(op, _src, _dst, _kernel, anchor, iterations, borderType, borderValue) )
return;
if( IPPMorphOp(op, _src, _dst, _kernel, anchor, iterations, borderType, borderValue) )
return;
#endif
Mat src = _src.getMat(), kernel = _kernel.getMat();
@@ -1456,7 +1473,7 @@ static void convertConvKernel( const IplConvKernel* src, cv::Mat& dst, cv::Point
int i, size = src->nRows*src->nCols;
for( i = 0; i < size; i++ )
dst.data[i] = (uchar)src->values[i];
dst.data[i] = (uchar)(src->values[i] != 0);
}
-44
View File
@@ -1,44 +0,0 @@
/*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"
/* End of file. */
+2 -1
View File
@@ -191,6 +191,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType )
typedef typename CastOp::type1 WT;
typedef typename CastOp::rtype T;
CV_Assert( !_src.empty() );
Size ssize = _src.size(), dsize = _dst.size();
int cn = _src.channels();
int bufstep = (int)alignSize(dsize.width*cn, 16);
@@ -203,7 +204,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType )
CastOp castOp;
VecOp vecOp;
CV_Assert( ssize.width > 0 && ssize.height > 0 &&
CV_Assert( ssize.width > 0 && ssize.height > 0 &&
std::abs(dsize.width*2 - ssize.width) <= 2 &&
std::abs(dsize.height*2 - ssize.height) <= 2 );
int k, x, sy0 = -PD_SZ/2, sy = sy0, width0 = std::min((ssize.width-PD_SZ/2-1)/2 + 1, dsize.width);
-1
View File
@@ -404,4 +404,3 @@ void cv::boxPoints(cv::RotatedRect box, OutputArray _pts)
Mat pts = _pts.getMat();
box.points((Point2f*)pts.data);
}
+1 -2
View File
@@ -327,7 +327,7 @@ void cv::pyrMeanShiftFiltering( InputArray _src, OutputArray _dst,
double sr2 = sr * sr;
int isr2 = cvRound(sr2), isr22 = MAX(isr2,16);
int tab[768];
if( src0.type() != CV_8UC3 )
CV_Error( CV_StsUnsupportedFormat, "Only 8-bit, 3-channel images are supported" );
@@ -534,4 +534,3 @@ cvPyrMeanShiftFiltering( const CvArr* srcarr, CvArr* dstarr,
cv::pyrMeanShiftFiltering(src, dst, sp0, sr, max_level, termcrit);
}
+43 -43
View File
@@ -239,49 +239,49 @@ void cv::integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, Output
sdepth = CV_MAT_DEPTH(sdepth);
#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7)
if( ( depth == CV_8U ) && ( !_tilted.needed() ) )
{
if( sdepth == CV_32F )
{
if( cn == 1 )
{
IppiSize srcRoiSize = ippiSize( src.cols, src.rows );
_sum.create( isize, CV_MAKETYPE( sdepth, cn ) );
sum = _sum.getMat();
if( _sqsum.needed() )
{
_sqsum.create( isize, CV_MAKETYPE( CV_64F, cn ) );
sqsum = _sqsum.getMat();
ippiSqrIntegral_8u32f64f_C1R( (const Ipp8u*)src.data, src.step, (Ipp32f*)sum.data, sum.step, (Ipp64f*)sqsum.data, sqsum.step, srcRoiSize, 0, 0 );
}
else
{
ippiIntegral_8u32f_C1R( (const Ipp8u*)src.data, src.step, (Ipp32f*)sum.data, sum.step, srcRoiSize, 0 );
}
return;
}
}
if( sdepth == CV_32S )
{
if( cn == 1 )
{
IppiSize srcRoiSize = ippiSize( src.cols, src.rows );
_sum.create( isize, CV_MAKETYPE( sdepth, cn ) );
sum = _sum.getMat();
if( _sqsum.needed() )
{
_sqsum.create( isize, CV_MAKETYPE( CV_64F, cn ) );
sqsum = _sqsum.getMat();
ippiSqrIntegral_8u32s64f_C1R( (const Ipp8u*)src.data, src.step, (Ipp32s*)sum.data, sum.step, (Ipp64f*)sqsum.data, sqsum.step, srcRoiSize, 0, 0 );
}
else
{
ippiIntegral_8u32s_C1R( (const Ipp8u*)src.data, src.step, (Ipp32s*)sum.data, sum.step, srcRoiSize, 0 );
}
return;
}
}
}
if( ( depth == CV_8U ) && ( !_tilted.needed() ) )
{
if( sdepth == CV_32F )
{
if( cn == 1 )
{
IppiSize srcRoiSize = ippiSize( src.cols, src.rows );
_sum.create( isize, CV_MAKETYPE( sdepth, cn ) );
sum = _sum.getMat();
if( _sqsum.needed() )
{
_sqsum.create( isize, CV_MAKETYPE( CV_64F, cn ) );
sqsum = _sqsum.getMat();
ippiSqrIntegral_8u32f64f_C1R( (const Ipp8u*)src.data, src.step, (Ipp32f*)sum.data, sum.step, (Ipp64f*)sqsum.data, sqsum.step, srcRoiSize, 0, 0 );
}
else
{
ippiIntegral_8u32f_C1R( (const Ipp8u*)src.data, src.step, (Ipp32f*)sum.data, sum.step, srcRoiSize, 0 );
}
return;
}
}
if( sdepth == CV_32S )
{
if( cn == 1 )
{
IppiSize srcRoiSize = ippiSize( src.cols, src.rows );
_sum.create( isize, CV_MAKETYPE( sdepth, cn ) );
sum = _sum.getMat();
if( _sqsum.needed() )
{
_sqsum.create( isize, CV_MAKETYPE( CV_64F, cn ) );
sqsum = _sqsum.getMat();
ippiSqrIntegral_8u32s64f_C1R( (const Ipp8u*)src.data, src.step, (Ipp32s*)sum.data, sum.step, (Ipp64f*)sqsum.data, sqsum.step, srcRoiSize, 0, 0 );
}
else
{
ippiIntegral_8u32s_C1R( (const Ipp8u*)src.data, src.step, (Ipp32s*)sum.data, sum.step, srcRoiSize, 0 );
}
return;
}
}
}
#endif
_sum.create( isize, CV_MAKETYPE(sdepth, cn) );