eliminated opencv_extra_api.hpp (all the functionality is moved to the regular OpenCV headers)

This commit is contained in:
Vadim Pisarevsky 2011-07-18 16:31:30 +00:00
parent 72541721a1
commit 1badec0b2d
15 changed files with 322 additions and 286 deletions

View File

@ -536,6 +536,9 @@ CV_EXPORTS bool findCirclesGrid( InputArray image, Size patternSize,
OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID,
const Ptr<FeatureDetector> &blobDetector = new SimpleBlobDetector());
CV_EXPORTS_W bool findCirclesGridDefault( InputArray image, Size patternSize,
OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID );
enum
{
CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS,

View File

@ -1524,3 +1524,10 @@ size_t CirclesGridFinder::getFirstCorner(vector<Point> &largeCornerIndices, vect
return cornerIdx;
}
bool cv::findCirclesGridDefault( InputArray image, Size patternSize,
OutputArray centers, int flags )
{
return findCirclesGrid(image, patternSize, centers, flags);
}

View File

@ -216,7 +216,7 @@ CV_EXPORTS int getThreadNum();
before and after the function call. The granularity of ticks depends on the hardware and OS used. Use
cv::getTickFrequency() to convert ticks to seconds.
*/
CV_EXPORTS int64 getTickCount();
CV_EXPORTS_W int64 getTickCount();
/*!
Returns the number of ticks per seconds.
@ -240,7 +240,7 @@ CV_EXPORTS_W double getTickFrequency();
one can accurately measure the execution time of very small code fragments,
for which cv::getTickCount() granularity is not enough.
*/
CV_EXPORTS int64 getCPUTickCount();
CV_EXPORTS_W int64 getCPUTickCount();
/*!
Returns SSE etc. support status
@ -1327,6 +1327,7 @@ typedef InputArray InputArrayOfArrays;
typedef const _OutputArray& OutputArray;
typedef OutputArray OutputArrayOfArrays;
typedef OutputArray InputOutputArray;
typedef OutputArray InputOutputArrayOfArrays;
CV_EXPORTS OutputArray noArray();
@ -2038,6 +2039,8 @@ CV_EXPORTS void mixChannels(const Mat* src, size_t nsrcs, Mat* dst, size_t ndsts
const int* fromTo, size_t npairs);
CV_EXPORTS void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
const int* fromTo, size_t npairs);
CV_EXPORTS_W void mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
const vector<int>& fromTo);
//! extracts a single channel from src (coi is 0-based index)
CV_EXPORTS_W void extractChannel(InputArray src, OutputArray dst, int coi);
@ -2162,6 +2165,9 @@ CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues, int lowindex=-1,
CV_EXPORTS bool eigen(InputArray src, OutputArray eigenvalues,
OutputArray eigenvectors,
int lowindex=-1, int highindex=-1);
CV_EXPORTS_W bool eigen(InputArray src, bool computeEigenvectors,
OutputArray eigenvalues, OutputArray eigenvectors);
//! computes covariation matrix of a set of samples
CV_EXPORTS void calcCovarMatrix( const Mat* samples, int nsamples, Mat& covar, Mat& mean,
int flags, int ctype=CV_64F);
@ -2246,6 +2252,16 @@ public:
Mat mean; //!< mean value subtracted before the projection and added after the back projection
};
CV_EXPORTS_W void PCACompute(InputArray data, CV_OUT InputOutputArray mean,
OutputArray eigenvectors, int maxComponents=0);
CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean,
InputArray eigenvectors, OutputArray result);
CV_EXPORTS_W void PCABackProject(InputArray data, InputArray mean,
InputArray eigenvectors, OutputArray result);
/*!
Singular Value Decomposition class
@ -2295,6 +2311,14 @@ public:
Mat u, w, vt;
};
//! computes SVD of src
CV_EXPORTS_W void SVDecomp( InputArray src, CV_OUT OutputArray w,
CV_OUT OutputArray u, CV_OUT OutputArray vt, int flags=0 );
//! performs back substitution for the previously computed SVD
CV_EXPORTS_W void SVBackSubst( InputArray w, InputArray u, InputArray vt,
InputArray rhs, CV_OUT OutputArray dst );
//! computes Mahalanobis distance between two vectors: sqrt((v1-v2)'*icovar*(v1-v2)), where icovar is the inverse covariation matrix
CV_EXPORTS_W double Mahalanobis(InputArray v1, InputArray v2, InputArray icovar);
//! a synonym for Mahalanobis
@ -2342,6 +2366,7 @@ CV_EXPORTS_W void randn(InputOutputArray dst, InputArray mean, InputArray stddev
//! shuffles the input array elements
CV_EXPORTS void randShuffle(InputOutputArray dst, double iterFactor=1., RNG* rng=0);
CV_EXPORTS_AS(randShuffle) void randShuffle_(InputOutputArray dst, double iterFactor=1.);
//! draws the line segment (pt1, pt2) in the image
CV_EXPORTS_W void line(Mat& img, Point pt1, Point pt2, const Scalar& color,
@ -2376,6 +2401,9 @@ CV_EXPORTS_W void ellipse(Mat& img, const RotatedRect& box, const Scalar& color,
CV_EXPORTS void fillConvexPoly(Mat& img, const Point* pts, int npts,
const Scalar& color, int lineType=8,
int shift=0);
CV_EXPORTS_W void fillConvexPoly(InputOutputArray img, InputArray points,
const Scalar& color, int lineType=8,
int shift=0);
//! fills an area bounded by one or more polygons
CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
@ -2383,11 +2411,19 @@ CV_EXPORTS void fillPoly(Mat& img, const Point** pts,
const Scalar& color, int lineType=8, int shift=0,
Point offset=Point() );
CV_EXPORTS_W void fillPoly(InputOutputArray img, InputArrayOfArrays pts,
const Scalar& color, int lineType=8, int shift=0,
Point offset=Point() );
//! draws one or more polygonal curves
CV_EXPORTS void polylines(Mat& img, const Point** pts, const int* npts,
int ncontours, bool isClosed, const Scalar& color,
int thickness=1, int lineType=8, int shift=0 );
CV_EXPORTS_W void polylines(InputOutputArray, InputArrayOfArrays pts,
bool isClosed, const Scalar& color,
int thickness=1, int lineType=8, int shift=0 );
//! clips the line segment by the rectangle Rect(0, 0, imgSize.width, imgSize.height)
CV_EXPORTS bool clipLine(Size imgSize, CV_IN_OUT Point& pt1, CV_IN_OUT Point& pt2);

View File

@ -503,6 +503,22 @@ void cv::mixChannels(const vector<Mat>& src, vector<Mat>& dst,
!dst.empty() ? &dst[0] : 0, dst.size(), fromTo, npairs);
}
void cv::mixChannels(InputArrayOfArrays src, InputOutputArrayOfArrays dst,
const vector<int>& fromTo)
{
if(fromTo.empty())
return;
size_t i, nsrc = src.total(), ndst = dst.total();
CV_Assert(fromTo.size()%2 == 0 && nsrc > 0 && ndst > 0);
cv::AutoBuffer<Mat> _buf(nsrc + ndst);
Mat* buf = _buf;
for( i = 0; i < nsrc; i++ )
buf[i] = src.getMat(i);
for( i = 0; i < ndst; i++ )
buf[nsrc + i] = dst.getMat(i);
mixChannels(&buf[0], (int)nsrc, &buf[nsrc], (int)ndst, &fromTo[0], (int)(fromTo.size()/2));
}
void cv::extractChannel(InputArray _src, OutputArray _dst, int coi)
{
Mat src = _src.getMat();

View File

@ -2012,6 +2012,63 @@ Size getTextSize( const string& text, int fontFace, double fontScale, int thickn
}
void cv::fillConvexPoly(InputOutputArray _img, InputArray _points,
const Scalar& color, int lineType, int shift)
{
Mat img = _img.getMat(), points = _points.getMat();
CV_Assert(points.checkVector(2, CV_32S) >= 0);
fillConvexPoly(img, (const Point*)points.data, points.rows*points.cols*points.channels()/2, color, lineType, shift);
}
void cv::fillPoly(InputOutputArray _img, InputArrayOfArrays pts,
const Scalar& color, int lineType, int shift, Point offset)
{
Mat img = _img.getMat();
size_t i, ncontours = pts.total();
if( ncontours == 0 )
return;
AutoBuffer<Point*> _ptsptr(ncontours);
AutoBuffer<int> _npts(ncontours);
Point** ptsptr = _ptsptr;
int* npts = _npts;
for( i = 0; i < ncontours; i++ )
{
Mat p = pts.getMat(i);
CV_Assert(p.checkVector(2, CV_32S) >= 0);
ptsptr[i] = (Point*)p.data;
npts[i] = p.rows*p.cols*p.channels()/2;
}
fillPoly(img, (const Point**)ptsptr, npts, (int)ncontours, color, lineType, shift, offset);
}
void cv::polylines(InputOutputArray _img, InputArrayOfArrays pts,
bool isClosed, const Scalar& color,
int thickness, int lineType, int shift )
{
Mat img = _img.getMat();
size_t i, ncontours = pts.total();
if( ncontours == 0 )
return;
AutoBuffer<Point*> _ptsptr(ncontours);
AutoBuffer<int> _npts(ncontours);
Point** ptsptr = _ptsptr;
int* npts = _npts;
for( i = 0; i < ncontours; i++ )
{
Mat p = pts.getMat(i);
CV_Assert(p.checkVector(2, CV_32S) >= 0);
ptsptr[i] = (Point*)p.data;
npts[i] = p.rows*p.cols*p.channels()/2;
}
polylines(img, (const Point**)ptsptr, npts, (int)ncontours, isClosed, color, thickness, lineType, shift);
}
static const int CodeDeltas[8][2] =
{ {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1} };

View File

@ -1398,10 +1398,7 @@ bool cv::solve( InputArray _src, InputArray _src2arg, OutputArray _dst, int meth
/////////////////// finding eigenvalues and eigenvectors of a symmetric matrix ///////////////
namespace cv
{
static bool eigen( InputArray _src, OutputArray _evals, OutputArray _evects, bool computeEvects, int, int )
bool cv::eigen( InputArray _src, bool computeEvects, OutputArray _evals, OutputArray _evects )
{
Mat src = _src.getMat();
int type = src.type();
@ -1431,17 +1428,14 @@ static bool eigen( InputArray _src, OutputArray _evals, OutputArray _evects, boo
return ok;
}
}
bool cv::eigen( InputArray src, OutputArray evals, int lowindex, int highindex )
bool cv::eigen( InputArray src, OutputArray evals, int, int )
{
return eigen(src, evals, noArray(), false, lowindex, highindex);
return eigen(src, false, evals, noArray());
}
bool cv::eigen( InputArray src, OutputArray evals, OutputArray evects,
int lowindex, int highindex )
bool cv::eigen( InputArray src, OutputArray evals, OutputArray evects, int, int)
{
return eigen(src, evals, evects, true, lowindex, highindex);
return eigen(src, true, evals, evects);
}
namespace cv
@ -1568,6 +1562,17 @@ void SVD::backSubst( InputArray rhs, OutputArray dst ) const
}
void cv::SVDecomp(InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags)
{
SVD::compute(src, w, u, vt, flags);
}
void cv::SVBackSubst(InputArray w, InputArray u, InputArray vt, InputArray rhs, OutputArray dst)
{
SVD::backSubst(w, u, vt, rhs, dst);
}
CV_IMPL double
cvDet( const CvArr* arr )
{

View File

@ -2884,6 +2884,34 @@ Mat PCA::backProject(InputArray data) const
}
void cv::PCACompute(InputArray data, InputOutputArray mean,
OutputArray eigenvectors, int maxComponents)
{
PCA pca;
pca(data, mean, 0, maxComponents);
pca.mean.copyTo(mean);
pca.eigenvectors.copyTo(eigenvectors);
}
void cv::PCAProject(InputArray data, InputArray mean,
InputArray eigenvectors, OutputArray result)
{
PCA pca;
pca.mean = mean.getMat();
pca.eigenvectors = eigenvectors.getMat();
pca.project(data, result);
}
void cv::PCABackProject(InputArray data, InputArray mean,
InputArray eigenvectors, OutputArray result)
{
PCA pca;
pca.mean = mean.getMat();
pca.eigenvectors = eigenvectors.getMat();
pca.backProject(data, result);
}
/****************************************************************************************\
* Earlier API *
\****************************************************************************************/

View File

@ -812,6 +812,11 @@ void cv::randShuffle( InputOutputArray _dst, double iterFactor, RNG* _rng )
func( dst, rng, iterFactor );
}
void cv::randShuffle_( InputOutputArray _dst, double iterFactor )
{
randShuffle(_dst, iterFactor);
}
CV_IMPL void
cvRandArr( CvRNG* _rng, CvArr* arr, int disttype, CvScalar param1, CvScalar param2 )
{

View File

@ -558,6 +558,9 @@ CV_EXPORTS Mat getAffineTransform( const Point2f src[], const Point2f dst[] );
//! computes 2x3 affine transformation matrix that is inverse to the specified 2x3 affine transformation.
CV_EXPORTS_W void invertAffineTransform( InputArray M, OutputArray iM );
CV_EXPORTS_W Mat getPerspectiveTransform( InputArray src, InputArray dst );
CV_EXPORTS_W Mat getAffineTransform( InputArray src, InputArray dst );
//! extracts rectangle from the image at sub-pixel location
CV_EXPORTS_W void getRectSubPix( InputArray image, Size patchSize,
Point2f center, OutputArray patch, int patchType=-1 );
@ -660,6 +663,13 @@ CV_EXPORTS void calcHist( const Mat* images, int nimages,
SparseMat& hist, int dims,
const int* histSize, const float** ranges,
bool uniform=true, bool accumulate=false );
CV_EXPORTS_W void calcHist( InputArrayOfArrays images,
const vector<int>& channels,
InputArray mask, OutputArray hist,
const vector<int>& histSize,
const vector<float>& ranges,
bool accumulate=false );
//! computes back projection for the set of images
CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
@ -673,6 +683,11 @@ CV_EXPORTS void calcBackProject( const Mat* images, int nimages,
OutputArray backProject, const float** ranges,
double scale=1, bool uniform=true );
CV_EXPORTS_W void calcBackProject( InputArrayOfArrays images, const vector<int>& channels,
InputArray hist, OutputArray dst,
const vector<float>& ranges,
double scale );
//! compares two histograms stored in dense arrays
CV_EXPORTS_W double compareHist( InputArray H1, InputArray H2, int method );
@ -922,6 +937,7 @@ CV_EXPORTS_W Moments moments( InputArray array, bool binaryImage=false );
//! computes 7 Hu invariants from the moments
CV_EXPORTS void HuMoments( const Moments& moments, double hu[7] );
CV_EXPORTS_W void HuMoments( const Moments& m, CV_OUT OutputArray hu );
//! type of the template matching operation
enum { TM_SQDIFF=0, TM_SQDIFF_NORMED=1, TM_CCORR=2, TM_CCORR_NORMED=3, TM_CCOEFF=4, TM_CCOEFF_NORMED=5 };

View File

@ -634,6 +634,7 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels,
ihist.convertTo(hist, CV_32F);
}
namespace cv
{
@ -824,7 +825,36 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels,
ranges, uniform, accumulate, false );
}
void cv::calcHist( InputArrayOfArrays images, const vector<int>& channels,
InputArray mask, OutputArray hist,
const vector<int>& histSize,
const vector<float>& ranges,
bool accumulate )
{
int i, dims = (int)histSize.size(), rsz = (int)ranges.size(), csz = (int)channels.size();
int nimages = (int)images.total();
CV_Assert(nimages > 0 && dims > 0);
CV_Assert(rsz == dims*2 || (rsz == 0 && images.depth(0) == CV_8U));
CV_Assert(csz == 0 || csz == dims);
float* _ranges[CV_MAX_DIM];
if( rsz > 0 )
{
for( i = 0; i < rsz/2; i++ )
_ranges[i] = (float*)&ranges[i*2];
}
AutoBuffer<Mat> buf(nimages);
for( i = 0; i < nimages; i++ )
buf[i] = images.getMat(i);
calcHist(&buf[0], nimages, csz ? &channels[0] : 0,
mask, hist, dims, &histSize[0], rsz ? (const float**)_ranges : 0,
true, accumulate);
}
/////////////////////////////////////// B A C K P R O J E C T ////////////////////////////////////
namespace cv
@ -1314,6 +1344,32 @@ void cv::calcBackProject( const Mat* images, int nimages, const int* channels,
CV_Error(CV_StsUnsupportedFormat, "");
}
void cv::calcBackProject( InputArrayOfArrays images, const vector<int>& channels,
InputArray hist, OutputArray dst,
const vector<float>& ranges,
double scale )
{
int i, dims = hist.getMat().dims, rsz = (int)ranges.size(), csz = (int)channels.size();
int nimages = (int)images.total();
CV_Assert(nimages > 0);
CV_Assert(rsz == dims*2 || (rsz == 0 && images.depth(0) == CV_8U));
CV_Assert(csz == 0 || csz == dims);
float* _ranges[CV_MAX_DIM];
if( rsz > 0 )
{
for( i = 0; i < rsz/2; i++ )
_ranges[i] = (float*)&ranges[i*2];
}
AutoBuffer<Mat> buf(nimages);
for( i = 0; i < nimages; i++ )
buf[i] = images.getMat(i);
calcBackProject(&buf[0], nimages, csz ? &channels[0] : 0,
hist, dst, rsz ? (const float**)_ranges : 0, scale, true);
}
////////////////// C O M P A R E H I S T O G R A M S ////////////////////////

View File

@ -3187,6 +3187,22 @@ void cv::invertAffineTransform(InputArray _matM, OutputArray __iM)
CV_Error( CV_StsUnsupportedFormat, "" );
}
cv::Mat cv::getPerspectiveTransform(InputArray _src, InputArray _dst)
{
Mat src = _src.getMat(), dst = _dst.getMat();
CV_Assert(src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4);
return getPerspectiveTransform((const Point2f*)src.data, (const Point2f*)dst.data);
}
cv::Mat cv::getAffineTransform(InputArray _src, InputArray _dst)
{
Mat src = _src.getMat(), dst = _dst.getMat();
CV_Assert(src.checkVector(2, CV_32F) == 3 && dst.checkVector(2, CV_32F) == 3);
return getAffineTransform((const Point2f*)src.data, (const Point2f*)dst.data);
}
CV_IMPL void
cvResize( const CvArr* srcarr, CvArr* dstarr, int method )
{

View File

@ -199,16 +199,16 @@ static void icvContourMoments( CvSeq* contour, CvMoments* moments )
template<typename T, typename WT, typename MT>
static void momentsInTile( const cv::Mat& img, double* moments )
{
cv::Size size = img.size();
cv::Size size = img.size();
int x, y;
MT mom[10] = {0,0,0,0,0,0,0,0,0,0};
for( y = 0; y < size.height; y++ )
{
const T* ptr = (const T*)(img.data + y*img.step);
WT x0 = 0, x1 = 0, x2 = 0;
MT x3 = 0;
const T* ptr = (const T*)(img.data + y*img.step);
WT x0 = 0, x1 = 0, x2 = 0;
MT x3 = 0;
for( x = 0; x < size.width; x++ )
{
WT p = ptr[x];
@ -216,7 +216,7 @@ static void momentsInTile( const cv::Mat& img, double* moments )
x0 += p;
x1 += xp;
xxp = xp * x;
xxp = xp * x;
x2 += xxp;
x3 += xxp * x;
}
@ -244,7 +244,7 @@ static void momentsInTile( const cv::Mat& img, double* moments )
template<> void momentsInTile<uchar, int, int>( const cv::Mat& img, double* moments )
{
typedef uchar T;
typedef uchar T;
typedef int WT;
typedef int MT;
cv::Size size = img.size();
@ -254,8 +254,8 @@ template<> void momentsInTile<uchar, int, int>( const cv::Mat& img, double* mome
for( y = 0; y < size.height; y++ )
{
const T* ptr = img.ptr<T>(y);
int x0 = 0, x1 = 0, x2 = 0, x3 = 0, x = 0;
const T* ptr = img.ptr<T>(y);
int x0 = 0, x1 = 0, x2 = 0, x3 = 0, x = 0;
if( useSIMD )
{
@ -285,7 +285,7 @@ template<> void momentsInTile<uchar, int, int>( const cv::Mat& img, double* mome
_mm_store_si128((__m128i*)buf, qx3);
x3 = buf[0] + buf[1] + buf[2] + buf[3];
}
for( ; x < size.width; x++ )
{
WT p = ptr[x];
@ -293,7 +293,7 @@ template<> void momentsInTile<uchar, int, int>( const cv::Mat& img, double* mome
x0 += p;
x1 += xp;
xxp = xp * x;
xxp = xp * x;
x2 += xxp;
x3 += xxp * x;
}
@ -322,15 +322,15 @@ typedef void (*CvMomentsInTileFunc)(const cv::Mat& img, double* moments);
CV_IMPL void cvMoments( const void* array, CvMoments* moments, int binary )
{
const int TILE_SIZE = 32;
int type, depth, cn, coi = 0;
const int TILE_SIZE = 32;
int type, depth, cn, coi = 0;
CvMat stub, *mat = (CvMat*)array;
CvMomentsInTileFunc func = 0;
CvContour contourHeader;
CvSeq* contour = 0;
CvSeqBlock block;
double buf[TILE_SIZE*TILE_SIZE];
uchar nzbuf[TILE_SIZE*TILE_SIZE];
double buf[TILE_SIZE*TILE_SIZE];
uchar nzbuf[TILE_SIZE*TILE_SIZE];
if( CV_IS_SEQ( array ))
{
@ -375,47 +375,47 @@ CV_IMPL void cvMoments( const void* array, CvMoments* moments, int binary )
if( size.width <= 0 || size.height <= 0 )
return;
if( binary || depth == CV_8U )
func = momentsInTile<uchar, int, int>;
else if( depth == CV_16U )
func = momentsInTile<ushort, int, int64>;
else if( depth == CV_16S )
func = momentsInTile<short, int, int64>;
else if( depth == CV_32F )
func = momentsInTile<float, double, double>;
else if( depth == CV_64F )
func = momentsInTile<double, double, double>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
cv::Mat src0(mat);
if( binary || depth == CV_8U )
func = momentsInTile<uchar, int, int>;
else if( depth == CV_16U )
func = momentsInTile<ushort, int, int64>;
else if( depth == CV_16S )
func = momentsInTile<short, int, int64>;
else if( depth == CV_32F )
func = momentsInTile<float, double, double>;
else if( depth == CV_64F )
func = momentsInTile<double, double, double>;
else
CV_Error( CV_StsUnsupportedFormat, "" );
cv::Mat src0(mat);
for( int y = 0; y < size.height; y += TILE_SIZE )
{
cv::Size tileSize;
tileSize.height = std::min(TILE_SIZE, size.height - y);
tileSize.height = std::min(TILE_SIZE, size.height - y);
for( int x = 0; x < size.width; x += TILE_SIZE )
{
tileSize.width = std::min(TILE_SIZE, size.width - x);
cv::Mat src(src0, cv::Rect(x, y, tileSize.width, tileSize.height));
cv::Mat src(src0, cv::Rect(x, y, tileSize.width, tileSize.height));
if( coi > 0 )
{
cv::Mat tmp(tileSize, depth, buf);
int pairs[] = {coi-1, 0};
cv::mixChannels(&src, 1, &tmp, 1, pairs, 1);
src = tmp;
}
if( binary )
{
cv::Mat tmp(tileSize, CV_8U, nzbuf);
cv::compare( src, 0, tmp, CV_CMP_NE );
if( coi > 0 )
{
cv::Mat tmp(tileSize, depth, buf);
int pairs[] = {coi-1, 0};
cv::mixChannels(&src, 1, &tmp, 1, pairs, 1);
src = tmp;
}
double mom[10];
func( src, mom );
}
if( binary )
{
cv::Mat tmp(tileSize, CV_8U, nzbuf);
cv::compare( src, 0, tmp, CV_CMP_NE );
src = tmp;
}
double mom[10];
func( src, mom );
if(binary)
{
@ -423,10 +423,10 @@ CV_IMPL void cvMoments( const void* array, CvMoments* moments, int binary )
for( int k = 0; k < 10; k++ )
mom[k] *= s;
}
double xm = x * mom[0], ym = y * mom[0];
// accumulate moments computed in each tile
// accumulate moments computed in each tile
// + m00 ( = m00' )
moments->m00 += mom[0];
@ -460,7 +460,7 @@ CV_IMPL void cvMoments( const void* array, CvMoments* moments, int binary )
}
}
icvCompleteMomentState( moments );
icvCompleteMomentState( moments );
}
@ -526,7 +526,7 @@ CV_IMPL double cvGetCentralMoment( CvMoments * moments, int x_order, int y_order
CV_Error( CV_StsOutOfRange, "" );
return order >= 2 ? (&(moments->m00))[4 + order * 3 + y_order] :
order == 0 ? moments->m00 : 0;
order == 0 ? moments->m00 : 0;
}
@ -640,5 +640,12 @@ void cv::HuMoments( const Moments& m, double hu[7] )
hu[6] = q1 * t0 - q0 * t1;
}
void cv::HuMoments( const Moments& m, OutputArray _hu )
{
_hu.create(7, 1, CV_64F);
Mat hu = _hu.getMat();
CV_Assert( hu.isContinuous() );
HuMoments(m, (double*)hu.data);
}
/* End of file. */

View File

@ -31,8 +31,7 @@ set(opencv_hdrs "${OpenCV_SOURCE_DIR}/modules/core/include/opencv2/core/core.hpp
"${OpenCV_SOURCE_DIR}/modules/ml/include/opencv2/ml/ml.hpp"
"${OpenCV_SOURCE_DIR}/modules/features2d/include/opencv2/features2d/features2d.hpp"
"${OpenCV_SOURCE_DIR}/modules/calib3d/include/opencv2/calib3d/calib3d.hpp"
"${OpenCV_SOURCE_DIR}/modules/objdetect/include/opencv2/objdetect/objdetect.hpp"
"${OpenCV_SOURCE_DIR}/modules/python/src2/opencv_extra_api.hpp")
"${OpenCV_SOURCE_DIR}/modules/objdetect/include/opencv2/objdetect/objdetect.hpp")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
@ -62,7 +61,7 @@ add_custom_command(
DEPENDS ${opencv_hdrs})
set(cv2_target "opencv_python")
add_library(${cv2_target} SHARED src2/cv2.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i src2/opencv_extra_api.hpp ${cv2_generated_hdrs} src2/cv2.cv.hpp)
add_library(${cv2_target} SHARED src2/cv2.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i ${cv2_generated_hdrs} src2/cv2.cv.hpp)
target_link_libraries(${cv2_target} ${PYTHON_LIBRARIES} opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_objdetect opencv_legacy opencv_contrib)
set_target_properties(${cv2_target} PROPERTIES PREFIX "")

View File

@ -18,7 +18,6 @@
#include "opencv2/video/tracking.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv_extra_api.hpp"
using cv::flann::IndexParams;
using cv::flann::SearchParams;
@ -356,6 +355,11 @@ static bool pyopencv_to(PyObject* obj, float& value, const char* name = "<unknow
return !PyErr_Occurred();
}
static PyObject* pyopencv_from(int64 value)
{
return PyFloat_FromDouble((double)value);
}
static PyObject* pyopencv_from(const string& value)
{
return PyString_FromString(value.empty() ? "" : value.c_str());

View File

@ -1,219 +0,0 @@
#ifndef _OPENCV_API_EXTRA_HPP_
#define _OPENCV_API_EXTRA_HPP_
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/calib3d/calib3d.hpp"
namespace cv
{
template<typename _Tp>
static inline void mv2vv(const vector<Mat>& src, vector<vector<_Tp> >& dst)
{
size_t i, n = src.size();
dst.resize(src.size());
for( i = 0; i < n; i++ )
src[i].copyTo(dst[i]);
}
///////////////////////////// core /////////////////////////////
CV_WRAP_AS(getTickCount) static inline double getTickCount_()
{
return (double)getTickCount();
}
CV_WRAP_AS(getCPUTickCount) static inline double getCPUTickCount_()
{
return (double)getCPUTickCount();
}
CV_WRAP void randShuffle(const Mat& src, CV_OUT Mat& dst, double iterFactor=1.)
{
src.copyTo(dst);
randShuffle(dst, iterFactor, 0);
}
CV_WRAP static inline void SVDecomp(const Mat& src, CV_OUT Mat& w, CV_OUT Mat& u, CV_OUT Mat& vt, int flags=0 )
{
SVD::compute(src, w, u, vt, flags);
}
CV_WRAP static inline void SVBackSubst( const Mat& w, const Mat& u, const Mat& vt,
const Mat& rhs, CV_OUT Mat& dst )
{
SVD::backSubst(w, u, vt, rhs, dst);
}
CV_WRAP static inline void mixChannels(const vector<Mat>& src, vector<Mat>& dst,
const vector<int>& fromTo)
{
if(fromTo.empty())
return;
CV_Assert(fromTo.size()%2 == 0);
mixChannels(&src[0], (int)src.size(), &dst[0], (int)dst.size(), &fromTo[0], (int)(fromTo.size()/2));
}
CV_WRAP static inline bool eigen(const Mat& src, bool computeEigenvectors,
CV_OUT Mat& eigenvalues, CV_OUT Mat& eigenvectors,
int lowindex=-1, int highindex=-1)
{
return computeEigenvectors ? eigen(src, eigenvalues, eigenvectors, lowindex, highindex) :
eigen(src, eigenvalues, lowindex, highindex);
}
CV_WRAP static inline void fillConvexPoly(Mat& img, const Mat& points,
const Scalar& color, int lineType=8,
int shift=0)
{
CV_Assert(points.checkVector(2, CV_32S) >= 0);
fillConvexPoly(img, (const Point*)points.data, points.rows*points.cols*points.channels()/2, color, lineType, shift);
}
CV_WRAP static inline void fillPoly(Mat& img, const vector<Mat>& pts,
const Scalar& color, int lineType=8, int shift=0,
Point offset=Point() )
{
if( pts.empty() )
return;
AutoBuffer<Point*> _ptsptr(pts.size());
AutoBuffer<int> _npts(pts.size());
Point** ptsptr = _ptsptr;
int* npts = _npts;
for( size_t i = 0; i < pts.size(); i++ )
{
const Mat& p = pts[i];
CV_Assert(p.checkVector(2, CV_32S) >= 0);
ptsptr[i] = (Point*)p.data;
npts[i] = p.rows*p.cols*p.channels()/2;
}
fillPoly(img, (const Point**)ptsptr, npts, (int)pts.size(), color, lineType, shift, offset);
}
CV_WRAP static inline void polylines(Mat& img, const vector<Mat>& pts,
bool isClosed, const Scalar& color,
int thickness=1, int lineType=8, int shift=0 )
{
if( pts.empty() )
return;
AutoBuffer<Point*> _ptsptr(pts.size());
AutoBuffer<int> _npts(pts.size());
Point** ptsptr = _ptsptr;
int* npts = _npts;
for( size_t i = 0; i < pts.size(); i++ )
{
const Mat& p = pts[i];
CV_Assert(p.checkVector(2, CV_32S) >= 0);
ptsptr[i] = (Point*)p.data;
npts[i] = p.rows*p.cols*p.channels()/2;
}
polylines(img, (const Point**)ptsptr, npts, (int)pts.size(), isClosed, color, thickness, lineType, shift);
}
CV_WRAP static inline void PCACompute(const Mat& data, CV_OUT Mat& mean,
CV_OUT Mat& eigenvectors, int maxComponents=0)
{
PCA pca;
pca.mean = mean;
pca.eigenvectors = eigenvectors;
pca(data, Mat(), 0, maxComponents);
pca.mean.copyTo(mean);
pca.eigenvectors.copyTo(eigenvectors);
}
CV_WRAP static inline void PCAProject(const Mat& data, const Mat& mean,
const Mat& eigenvectors, CV_OUT Mat& result)
{
PCA pca;
pca.mean = mean;
pca.eigenvectors = eigenvectors;
pca.project(data, result);
}
CV_WRAP static inline void PCABackProject(const Mat& data, const Mat& mean,
const Mat& eigenvectors, CV_OUT Mat& result)
{
PCA pca;
pca.mean = mean;
pca.eigenvectors = eigenvectors;
pca.backProject(data, result);
}
/////////////////////////// imgproc /////////////////////////////////
CV_WRAP static inline void HuMoments(const Moments& m, CV_OUT vector<double>& hu)
{
hu.resize(7);
HuMoments(m, &hu[0]);
}
CV_WRAP static inline Mat getPerspectiveTransform(const vector<Point2f>& src, const vector<Point2f>& dst)
{
CV_Assert(src.size() == 4 && dst.size() == 4);
return getPerspectiveTransform(&src[0], &dst[0]);
}
CV_WRAP static inline Mat getAffineTransform(const vector<Point2f>& src, const vector<Point2f>& dst)
{
CV_Assert(src.size() == 3 && dst.size() == 3);
return getAffineTransform(&src[0], &dst[0]);
}
CV_WRAP static inline void calcHist( const vector<Mat>& images, const vector<int>& channels,
const Mat& mask, CV_OUT Mat& hist,
const vector<int>& histSize,
const vector<float>& ranges,
bool accumulate=false)
{
int i, dims = (int)histSize.size(), rsz = (int)ranges.size(), csz = (int)channels.size();
CV_Assert(images.size() > 0 && dims > 0);
CV_Assert(rsz == dims*2 || (rsz == 0 && images[0].depth() == CV_8U));
CV_Assert(csz == 0 || csz == dims);
float* _ranges[CV_MAX_DIM];
if( rsz > 0 )
{
for( i = 0; i < rsz/2; i++ )
_ranges[i] = (float*)&ranges[i*2];
}
calcHist(&images[0], (int)images.size(), csz ? &channels[0] : 0,
mask, hist, dims, &histSize[0], rsz ? (const float**)_ranges : 0,
true, accumulate);
}
CV_WRAP void calcBackProject( const vector<Mat>& images, const vector<int>& channels,
const Mat& hist, CV_OUT Mat& dst,
const vector<float>& ranges,
double scale=1 )
{
int i, dims = hist.dims, rsz = (int)ranges.size(), csz = (int)channels.size();
CV_Assert(images.size() > 0);
CV_Assert(rsz == dims*2 || (rsz == 0 && images[0].depth() == CV_8U));
CV_Assert(csz == 0 || csz == dims);
float* _ranges[CV_MAX_DIM];
if( rsz > 0 )
{
for( i = 0; i < rsz/2; i++ )
_ranges[i] = (float*)&ranges[i*2];
}
calcBackProject(&images[0], (int)images.size(), csz ? &channels[0] : 0,
hist, dst, rsz ? (const float**)_ranges : 0, scale, true);
}
/////////////////////////////// calib3d ///////////////////////////////////////////
//! finds circles' grid pattern of the specified size in the image
CV_WRAP static inline void findCirclesGridDefault( InputArray image, Size patternSize,
OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID )
{
findCirclesGrid(image, patternSize, centers, flags);
}
}
#endif