some more bugfixed in 2.3 propagated to trunk

This commit is contained in:
Vadim Pisarevsky
2011-07-07 11:43:21 +00:00
parent 58b5256e05
commit 5649f35757
8 changed files with 33 additions and 239 deletions

View File

@@ -205,207 +205,8 @@ CV_WRAP void calcBackProject( const vector<Mat>& images, const vector<int>& chan
}
static void addChildContour(const vector<Mat>& contours,
const Mat& hierarchy,
int i, vector<CvSeq>& seq,
vector<CvSeqBlock>& block)
{
size_t count = contours.size();
for( ; i >= 0; i = ((const Vec4i*)hierarchy.data)[i][0] )
{
const vector<Point>& ci = contours[i];
cvMakeSeqHeaderForArray(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point),
!ci.empty() ? (void*)&ci[0] : 0, (int)ci.size(),
&seq[i], &block[i] );
const Vec4i h_i = ((const Vec4i*)hierarchy.data)[i];
int h_next = h_i[0], h_prev = h_i[1], v_next = h_i[2], v_prev = h_i[3];
seq[i].h_next = (size_t)h_next < count ? &seq[h_next] : 0;
seq[i].h_prev = (size_t)h_prev < count ? &seq[h_prev] : 0;
seq[i].v_next = (size_t)v_next < count ? &seq[v_next] : 0;
seq[i].v_prev = (size_t)v_prev < count ? &seq[v_prev] : 0;
if( v_next >= 0 )
addChildContour(contours, hierarchy, v_next, seq, block);
}
}
//! draws contours in the image
CV_WRAP static inline void drawContours( Mat& image, const vector<Mat>& contours,
int contourIdx, const Scalar& color,
int thickness=1, int lineType=8,
const Mat& hierarchy=Mat(),
int maxLevel=INT_MAX, Point offset=Point() )
{
CvMat _image = image;
size_t i = 0, first = 0, last = contours.size();
vector<CvSeq> seq;
vector<CvSeqBlock> block;
if( !last )
return;
seq.resize(last);
block.resize(last);
for( i = first; i < last; i++ )
seq[i].first = 0;
if( contourIdx >= 0 )
{
CV_Assert( 0 <= contourIdx && contourIdx < (int)last );
first = contourIdx;
last = contourIdx + 1;
}
for( i = first; i < last; i++ )
{
const Mat& ci = contours[i];
int ci_size = ci.checkVector(2, CV_32S);
CV_Assert( ci_size >= 0 );
cvMakeSeqHeaderForArray(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point),
ci_size > 0 ? ci.data : 0, ci_size, &seq[i], &block[i] );
}
if( hierarchy.empty() || maxLevel == 0 )
for( i = first; i < last; i++ )
{
seq[i].h_next = i < last-1 ? &seq[i+1] : 0;
seq[i].h_prev = i > first ? &seq[i-1] : 0;
}
else
{
int hsz = hierarchy.checkVector(4, CV_32S);
size_t count = last - first;
CV_Assert((size_t)hsz == contours.size());
if( count == contours.size() )
{
for( i = first; i < last; i++ )
{
const Vec4i& h_i = ((const Vec4i*)hierarchy.data)[i];
int h_next = h_i[0], h_prev = h_i[1], v_next = h_i[2], v_prev = h_i[3];
seq[i].h_next = (size_t)h_next < count ? &seq[h_next] : 0;
seq[i].h_prev = (size_t)h_prev < count ? &seq[h_prev] : 0;
seq[i].v_next = (size_t)v_next < count ? &seq[v_next] : 0;
seq[i].v_prev = (size_t)v_prev < count ? &seq[v_prev] : 0;
}
}
else
{
int child = ((const Vec4i*)hierarchy.data)[first][2];
if( child >= 0 )
{
addChildContour(contours, hierarchy, child, seq, block);
seq[first].v_next = &seq[child];
}
}
}
cvDrawContours( &_image, &seq[first], color, color, contourIdx >= 0 ?
-maxLevel : maxLevel, thickness, lineType, offset );
}
CV_WRAP static inline void approxPolyDP( const Mat& curve,
CV_OUT Mat& approxCurve,
double epsilon, bool closed )
{
if( curve.depth() == CV_32S )
{
vector<Point> result;
approxPolyDP(curve, result, epsilon, closed);
Mat(result).copyTo(approxCurve);
}
else if( curve.depth() == CV_32F )
{
vector<Point2f> result;
approxPolyDP(curve, result, epsilon, closed);
Mat(result).copyTo(approxCurve);
}
else
CV_Error(CV_StsUnsupportedFormat, "");
}
CV_WRAP static inline void convexHull( const Mat& points, CV_OUT Mat& hull, bool returnPoints=true, bool clockwise=false )
{
if( !returnPoints )
{
vector<int> h;
convexHull(points, h, clockwise);
Mat(h).copyTo(hull);
}
else if( points.depth() == CV_32S )
{
vector<Point> h;
convexHull(points, h, clockwise);
Mat(h).copyTo(hull);
}
else if( points.depth() == CV_32F )
{
vector<Point2f> h;
convexHull(points, h, clockwise);
Mat(h).copyTo(hull);
}
}
CV_WRAP static inline void fitLine( const Mat& points, CV_OUT vector<float>& line,
int distType, double param, double reps, double aeps )
{
if(points.channels() == 2 || points.cols == 2)
{
line.resize(4);
fitLine(points, *(Vec4f*)&line[0], distType, param, reps, aeps);
}
else
{
line.resize(6);
fitLine(points, *(Vec6f*)&line[0], distType, param, reps, aeps);
}
}
CV_WRAP static inline int estimateAffine3D( const Mat& from, const Mat& to,
CV_OUT Mat& dst, CV_OUT Mat& outliers,
double param1 = 3.0, double param2 = 0.99 )
{
vector<uchar> outliers_vec;
int res = estimateAffine3D(from, to, dst, outliers_vec, param1, param2);
Mat(outliers_vec).copyTo(outliers);
return res;
}
CV_WRAP static inline void cornerSubPix( const Mat& image, Mat& corners,
Size winSize, Size zeroZone,
TermCriteria criteria )
{
int n = corners.checkVector(2, CV_32F);
CV_Assert(n >= 0);
if( n == 0 )
return;
CvMat _image = image;
cvFindCornerSubPix(&_image, (CvPoint2D32f*)corners.data, n, winSize, zeroZone, criteria);
}
/////////////////////////////// calib3d ///////////////////////////////////////////
CV_WRAP static inline void convertPointsHomogeneous( const Mat& src, CV_OUT Mat& dst )
{
int n;
if( (n = src.checkVector(2)) >= 0 )
dst.create(n, 2, src.depth());
else if( (n = src.checkVector(3)) >= 0 )
dst.create(n, 3, src.depth());
else
CV_Error(CV_StsBadSize, "");
CvMat _src = src, _dst = dst;
cvConvertPointsHomogeneous(&_src, &_dst);
}
//! 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 )