Move C API of opencv_calib3d to separate file

This commit is contained in:
Andrey Kamaev
2013-04-11 19:27:54 +04:00
parent 199a35a105
commit e5a33723fc
70 changed files with 836 additions and 792 deletions

View File

@@ -61,6 +61,7 @@
#include "precomp.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/calib3d/calib3d_c.h"
#include "circlesgrid.hpp"
#include <stdarg.h>

View File

@@ -42,6 +42,7 @@
#include "precomp.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/calib3d/calib3d_c.h"
#include <stdio.h>
#include <iterator>
@@ -825,7 +826,7 @@ CV_IMPL void cvProjectPoints2( const CvMat* objectPoints,
dpdk_p[dpdk_step+7] = fy*y*cdist*(-icdist2)*icdist2*r6;
if( _dpdk->cols > 8 )
{
dpdk_p[8] = fx*r2; //s1
dpdk_p[8] = fx*r2; //s1
dpdk_p[9] = fx*r4; //s2
dpdk_p[10] = 0;//s3
dpdk_p[11] = 0;//s4
@@ -1255,7 +1256,7 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
//when the thin prism model is used the distortion coefficients matrix must have 12 parameters
if((flags & CV_CALIB_THIN_PRISM_MODEL) && (distCoeffs->cols*distCoeffs->rows != 12))
CV_Error( CV_StsBadArg, "Thin prism model must have 12 parameters in the distortion matrix" );
nimages = npoints->rows*npoints->cols;
npstep = npoints->rows == 1 ? 1 : npoints->step/CV_ELEM_SIZE(npoints->type);

View File

@@ -41,6 +41,7 @@
#include "precomp.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/calib3d/calib3d_c.h"
#include <vector>
#include <algorithm>

View File

@@ -202,12 +202,12 @@ void CirclesGridClusterFinder::findCorners(const std::vector<cv::Point2f> &hull2
//corners are the most sharp angles (6)
Mat anglesMat = Mat(angles);
Mat sortedIndices;
sortIdx(anglesMat, sortedIndices, CV_SORT_EVERY_COLUMN + CV_SORT_DESCENDING);
sortIdx(anglesMat, sortedIndices, SORT_EVERY_COLUMN + SORT_DESCENDING);
CV_Assert(sortedIndices.type() == CV_32SC1);
CV_Assert(sortedIndices.cols == 1);
const int cornersCount = isAsymmetricGrid ? 6 : 4;
Mat cornersIndices;
cv::sort(sortedIndices.rowRange(0, cornersCount), cornersIndices, CV_SORT_EVERY_COLUMN + CV_SORT_ASCENDING);
cv::sort(sortedIndices.rowRange(0, cornersCount), cornersIndices, SORT_EVERY_COLUMN + SORT_ASCENDING);
corners.clear();
for(int i=0; i<cornersCount; i++)
{
@@ -438,15 +438,15 @@ bool Graph::doesVertexExist(size_t id) const
void Graph::addVertex(size_t id)
{
assert( !doesVertexExist( id ) );
CV_Assert( !doesVertexExist( id ) );
vertices.insert(std::pair<size_t, Vertex> (id, Vertex()));
}
void Graph::addEdge(size_t id1, size_t id2)
{
assert( doesVertexExist( id1 ) );
assert( doesVertexExist( id2 ) );
CV_Assert( doesVertexExist( id1 ) );
CV_Assert( doesVertexExist( id2 ) );
vertices[id1].neighbors.insert(id2);
vertices[id2].neighbors.insert(id1);
@@ -454,8 +454,8 @@ void Graph::addEdge(size_t id1, size_t id2)
void Graph::removeEdge(size_t id1, size_t id2)
{
assert( doesVertexExist( id1 ) );
assert( doesVertexExist( id2 ) );
CV_Assert( doesVertexExist( id1 ) );
CV_Assert( doesVertexExist( id2 ) );
vertices[id1].neighbors.erase(id2);
vertices[id2].neighbors.erase(id1);
@@ -463,8 +463,8 @@ void Graph::removeEdge(size_t id1, size_t id2)
bool Graph::areVerticesAdjacent(size_t id1, size_t id2) const
{
assert( doesVertexExist( id1 ) );
assert( doesVertexExist( id2 ) );
CV_Assert( doesVertexExist( id1 ) );
CV_Assert( doesVertexExist( id2 ) );
Vertices::const_iterator it = vertices.find(id1);
return it->second.neighbors.find(id2) != it->second.neighbors.end();
@@ -477,7 +477,7 @@ size_t Graph::getVerticesCount() const
size_t Graph::getDegree(size_t id) const
{
assert( doesVertexExist(id) );
CV_Assert( doesVertexExist(id) );
Vertices::const_iterator it = vertices.find(id);
return it->second.neighbors.size();
@@ -495,7 +495,7 @@ void Graph::floydWarshall(cv::Mat &distanceMatrix, int infinity) const
distanceMatrix.at<int> ((int)it1->first, (int)it1->first) = 0;
for (Neighbors::const_iterator it2 = it1->second.neighbors.begin(); it2 != it1->second.neighbors.end(); it2++)
{
assert( it1->first != *it2 );
CV_Assert( it1->first != *it2 );
distanceMatrix.at<int> ((int)it1->first, (int)*it2) = edgeWeight;
}
}
@@ -524,7 +524,7 @@ void Graph::floydWarshall(cv::Mat &distanceMatrix, int infinity) const
const Graph::Neighbors& Graph::getNeighbors(size_t id) const
{
assert( doesVertexExist(id) );
CV_Assert( doesVertexExist(id) );
Vertices::const_iterator it = vertices.find(id);
return it->second.neighbors;
@@ -604,7 +604,7 @@ bool CirclesGridFinder::findHoles()
}
default:
CV_Error(CV_StsBadArg, "Unkown pattern type");
CV_Error(Error::StsBadArg, "Unkown pattern type");
}
return (isDetectionCorrect());
//CV_Error( 0, "Detection is not correct" );
@@ -813,7 +813,7 @@ void CirclesGridFinder::findMCS(const std::vector<Point2f> &basis, std::vector<G
Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Point2f>& centers,
const std::vector<Point2f> &keypoints, std::vector<Point2f> &warpedKeypoints)
{
assert( !centers.empty() );
CV_Assert( !centers.empty() );
const float edgeLength = 30;
const Point2f offset(150, 150);
@@ -832,7 +832,7 @@ Mat CirclesGridFinder::rectifyGrid(Size detectedGridSize, const std::vector<Poin
}
}
Mat H = findHomography(Mat(centers), Mat(dstPoints), CV_RANSAC);
Mat H = findHomography(Mat(centers), Mat(dstPoints), RANSAC);
//Mat H = findHomography( Mat( corners ), Mat( dstPoints ) );
std::vector<Point2f> srcKeypoints;
@@ -912,7 +912,7 @@ void CirclesGridFinder::findCandidateLine(std::vector<size_t> &line, size_t seed
}
}
assert( line.size() == seeds.size() );
CV_Assert( line.size() == seeds.size() );
}
void CirclesGridFinder::findCandidateHoles(std::vector<size_t> &above, std::vector<size_t> &below, bool addRow, Point2f basisVec,
@@ -927,9 +927,9 @@ void CirclesGridFinder::findCandidateHoles(std::vector<size_t> &above, std::vect
size_t lastIdx = addRow ? holes.size() - 1 : holes[0].size() - 1;
findCandidateLine(below, lastIdx, addRow, basisVec, belowSeeds);
assert( below.size() == above.size() );
assert( belowSeeds.size() == aboveSeeds.size() );
assert( below.size() == belowSeeds.size() );
CV_Assert( below.size() == above.size() );
CV_Assert( belowSeeds.size() == aboveSeeds.size() );
CV_Assert( below.size() == belowSeeds.size() );
}
bool CirclesGridFinder::areCentersNew(const std::vector<size_t> &newCenters, const std::vector<std::vector<size_t> > &holes)
@@ -1000,10 +1000,10 @@ void CirclesGridFinder::insertWinner(float aboveConfidence, float belowConfidenc
float CirclesGridFinder::computeGraphConfidence(const std::vector<Graph> &basisGraphs, bool addRow,
const std::vector<size_t> &points, const std::vector<size_t> &seeds)
{
assert( points.size() == seeds.size() );
CV_Assert( points.size() == seeds.size() );
float confidence = 0;
const size_t vCount = basisGraphs[0].getVerticesCount();
assert( basisGraphs[0].getVerticesCount() == basisGraphs[1].getVerticesCount() );
CV_Assert( basisGraphs[0].getVerticesCount() == basisGraphs[1].getVerticesCount() );
for (size_t i = 0; i < seeds.size(); i++)
{
@@ -1087,7 +1087,7 @@ void CirclesGridFinder::findBasis(const std::vector<Point2f> &samples, std::vect
const int clustersCount = 4;
kmeans(Mat(samples).reshape(1, 0), clustersCount, bestLabels, termCriteria, parameters.kmeansAttempts,
KMEANS_RANDOM_CENTERS, centers);
assert( centers.type() == CV_32FC1 );
CV_Assert( centers.type() == CV_32FC1 );
std::vector<int> basisIndices;
//TODO: only remove duplicate
@@ -1204,7 +1204,7 @@ void CirclesGridFinder::computeRNG(Graph &rng, std::vector<cv::Point2f> &vectors
void computePredecessorMatrix(const Mat &dm, int verticesCount, Mat &predecessorMatrix)
{
assert( dm.type() == CV_32SC1 );
CV_Assert( dm.type() == CV_32SC1 );
predecessorMatrix.create(verticesCount, verticesCount, CV_32SC1);
predecessorMatrix = -1;
for (int i = 0; i < predecessorMatrix.rows; i++)
@@ -1253,7 +1253,6 @@ size_t CirclesGridFinder::findLongestPath(std::vector<Graph> &basisGraphs, Path
double maxVal;
Point maxLoc;
assert (infinity < 0);
minMaxLoc(distanceMatrix, 0, &maxVal, 0, &maxLoc);
if (maxVal > longestPaths[0].length)
@@ -1594,9 +1593,3 @@ size_t CirclesGridFinder::getFirstCorner(std::vector<Point> &largeCornerIndices,
return cornerIdx;
}
bool cv::findCirclesGridDefault( InputArray image, Size patternSize,
OutputArray centers, int flags )
{
return findCirclesGrid(image, patternSize, centers, flags);
}

View File

@@ -41,6 +41,7 @@
//M*/
#include "precomp.hpp"
#include "opencv2/calib3d/calib3d_c.h"
/************************************************************************************\
Some backward compatibility stuff, to be moved to legacy or compat module

View File

@@ -41,6 +41,7 @@
//M*/
#include "precomp.hpp"
#include "opencv2/calib3d/calib3d_c.h"
CvStereoBMState* cvCreateStereoBMState( int /*preset*/, int numberOfDisparities )
{
@@ -83,10 +84,6 @@ void cvReleaseStereoBMState( CvStereoBMState** state )
cvFree( state );
}
template<> void cv::Ptr<CvStereoBMState>::delete_obj()
{ cvReleaseStereoBMState(&obj); }
void cvFindStereoCorrespondenceBM( const CvArr* leftarr, const CvArr* rightarr,
CvArr* disparr, CvStereoBMState* state )
{

View File

@@ -2,6 +2,7 @@
#define epnp_h
#include "precomp.hpp"
#include "opencv2/core/core_c.h"
class epnp {
public:

View File

@@ -435,7 +435,7 @@ cv::Mat cv::findEssentialMat( InputArray _points1, InputArray _points2, double f
threshold /= focal;
Mat E;
if( method == CV_RANSAC )
if( method == RANSAC )
createRANSACPointSetRegistrator(new EMEstimatorCallback, 5, threshold, prob)->run(points1, points2, E, _mask);
else
createLMeDSPointSetRegistrator(new EMEstimatorCallback, 5, prob)->run(points1, points2, E, _mask);

View File

@@ -181,12 +181,12 @@ public:
LtL[j][k] += Lx[j]*Lx[k] + Ly[j]*Ly[k];
}
completeSymm( _LtL );
eigen( _LtL, matW, matV );
_Htemp = _invHnorm*_H0;
_H0 = _Htemp*_Hnorm2;
_H0.convertTo(_model, _H0.type(), 1./_H0.at<double>(2,2) );
return 1;
}
@@ -292,7 +292,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
{
npoints = p.checkVector(3, -1, false);
if( npoints < 0 )
CV_Error(CV_StsBadArg, "The input arrays should be 2D or 3D point sets");
CV_Error(Error::StsBadArg, "The input arrays should be 2D or 3D point sets");
if( npoints == 0 )
return Mat();
convertPointsFromHomogeneous(p, p);
@@ -317,7 +317,7 @@ cv::Mat cv::findHomography( InputArray _points1, InputArray _points2,
else if( method == LMEDS )
result = createLMeDSPointSetRegistrator(cb, 4, confidence, maxIters)->run(src, dst, H, tempMask);
else
CV_Error(CV_StsBadArg, "Unknown estimation method");
CV_Error(Error::StsBadArg, "Unknown estimation method");
if( result && npoints > 4 )
{
@@ -475,7 +475,7 @@ static int run7Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix )
return n;
}
static int run8Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix )
{
double a[9*9], w[9], v[9*9];
@@ -585,11 +585,11 @@ static int run8Point( const Mat& _m1, const Mat& _m2, Mat& _fmatrix )
gemm( T2, F0, 1., 0, 0., TF, GEMM_1_T );
F0 = Mat(3, 3, CV_64F, fmatrix);
gemm( TF, T1, 1., 0, 0., F0, 0 );
// make F(3,3) = 1
if( fabs(F0.at<double>(2,2)) > FLT_EPSILON )
F0 *= 1./F0.at<double>(2,2);
return 1;
}
@@ -671,7 +671,7 @@ cv::Mat cv::findFundamentalMat( InputArray _points1, InputArray _points2,
{
npoints = p.checkVector(3, -1, false);
if( npoints < 0 )
CV_Error(CV_StsBadArg, "The input arrays should be 2D or 3D point sets");
CV_Error(Error::StsBadArg, "The input arrays should be 2D or 3D point sets");
if( npoints == 0 )
return Mat();
convertPointsFromHomogeneous(p, p);
@@ -739,7 +739,7 @@ void cv::computeCorrespondEpilines( InputArray _points, int whichImage,
{
npoints = points.checkVector(3);
if( npoints < 0 )
CV_Error( CV_StsBadArg, "The input should be a 2D or 3D point set");
CV_Error( Error::StsBadArg, "The input should be a 2D or 3D point set");
Mat temp;
convertPointsFromHomogeneous(points, temp);
points = temp;
@@ -893,7 +893,7 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
}
}
else
CV_Error(CV_StsUnsupportedFormat, "");
CV_Error(Error::StsUnsupportedFormat, "");
}
@@ -974,7 +974,7 @@ void cv::convertPointsToHomogeneous( InputArray _src, OutputArray _dst )
}
}
else
CV_Error(CV_StsUnsupportedFormat, "");
CV_Error(Error::StsUnsupportedFormat, "");
}

View File

@@ -39,6 +39,7 @@
//
//M*/
#include "precomp.hpp"
#include "opencv2/calib3d/calib3d_c.h"
/* POSIT structure */
struct CvPOSITObject

View File

@@ -53,7 +53,7 @@ namespace cv
int RANSACUpdateNumIters( double p, double ep, int modelPoints, int maxIters )
{
if( modelPoints <= 0 )
CV_Error( CV_StsOutOfRange, "the number of model points should be positive" );
CV_Error( Error::StsOutOfRange, "the number of model points should be positive" );
p = MAX(p, 0.);
p = MIN(p, 1.);

View File

@@ -108,7 +108,7 @@ static void findCorner(const std::vector<Point2f>& contour, Point2f point, Point
min_idx = (int)i;
}
}
assert(min_idx >= 0);
CV_Assert(min_idx >= 0);
// temporary solution, have to make something more precise
corner = contour[min_idx];

View File

@@ -43,6 +43,8 @@
#include "precomp.hpp"
#include "epnp.h"
#include "p3p.h"
#include "opencv2/calib3d/calib3d_c.h"
#include <iostream>
using namespace cv;
@@ -57,7 +59,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
_tvec.create(3, 1, CV_64F);
Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();
if (flags == CV_EPNP)
if (flags == EPNP)
{
cv::Mat undistortedPoints;
cv::undistortPoints(ipoints, undistortedPoints, cameraMatrix, distCoeffs);
@@ -68,7 +70,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
cv::Rodrigues(R, rvec);
return true;
}
else if (flags == CV_P3P)
else if (flags == P3P)
{
CV_Assert( npoints == 4);
cv::Mat undistortedPoints;
@@ -81,7 +83,7 @@ bool cv::solvePnP( InputArray _opoints, InputArray _ipoints,
cv::Rodrigues(R, rvec);
return result;
}
else if (flags == CV_ITERATIVE)
else if (flags == ITERATIVE)
{
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
@@ -342,7 +344,7 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
if (localInliers.size() >= (size_t)pnpransac::MIN_POINTS_COUNT)
{
if (flags != CV_P3P)
if (flags != P3P)
{
int i, pointsCount = (int)localInliers.size();
Mat inlierObjectPoints(1, pointsCount, CV_32FC3), inlierImagePoints(1, pointsCount, CV_32FC2);

View File

@@ -84,7 +84,7 @@ struct StereoBMParams
int disp12MaxDiff;
int dispType;
};
static void prefilterNorm( const Mat& src, Mat& dst, int winsize, int ftzero, uchar* buf )
{
@@ -783,46 +783,46 @@ public:
{
params = StereoBMParams(_numDisparities, _SADWindowSize);
}
void compute( InputArray leftarr, InputArray rightarr, OutputArray disparr )
{
Mat left0 = leftarr.getMat(), right0 = rightarr.getMat();
int dtype = disparr.fixedType() ? disparr.type() : params.dispType;
if (left0.size() != right0.size())
CV_Error( CV_StsUnmatchedSizes, "All the images must have the same size" );
CV_Error( Error::StsUnmatchedSizes, "All the images must have the same size" );
if (left0.type() != CV_8UC1 || right0.type() != CV_8UC1)
CV_Error( CV_StsUnsupportedFormat, "Both input images must have CV_8UC1" );
CV_Error( Error::StsUnsupportedFormat, "Both input images must have CV_8UC1" );
if (dtype != CV_16SC1 && dtype != CV_32FC1)
CV_Error( CV_StsUnsupportedFormat, "Disparity image must have CV_16SC1 or CV_32FC1 format" );
CV_Error( Error::StsUnsupportedFormat, "Disparity image must have CV_16SC1 or CV_32FC1 format" );
disparr.create(left0.size(), dtype);
Mat disp0 = disparr.getMat();
if( params.preFilterType != PREFILTER_NORMALIZED_RESPONSE &&
params.preFilterType != PREFILTER_XSOBEL )
CV_Error( CV_StsOutOfRange, "preFilterType must be = CV_STEREO_BM_NORMALIZED_RESPONSE" );
CV_Error( Error::StsOutOfRange, "preFilterType must be = CV_STEREO_BM_NORMALIZED_RESPONSE" );
if( params.preFilterSize < 5 || params.preFilterSize > 255 || params.preFilterSize % 2 == 0 )
CV_Error( CV_StsOutOfRange, "preFilterSize must be odd and be within 5..255" );
CV_Error( Error::StsOutOfRange, "preFilterSize must be odd and be within 5..255" );
if( params.preFilterCap < 1 || params.preFilterCap > 63 )
CV_Error( CV_StsOutOfRange, "preFilterCap must be within 1..63" );
CV_Error( Error::StsOutOfRange, "preFilterCap must be within 1..63" );
if( params.SADWindowSize < 5 || params.SADWindowSize > 255 || params.SADWindowSize % 2 == 0 ||
params.SADWindowSize >= std::min(left0.cols, left0.rows) )
CV_Error( CV_StsOutOfRange, "SADWindowSize must be odd, be within 5..255 and be not larger than image width or height" );
CV_Error( Error::StsOutOfRange, "SADWindowSize must be odd, be within 5..255 and be not larger than image width or height" );
if( params.numDisparities <= 0 || params.numDisparities % 16 != 0 )
CV_Error( CV_StsOutOfRange, "numDisparities must be positive and divisble by 16" );
CV_Error( Error::StsOutOfRange, "numDisparities must be positive and divisble by 16" );
if( params.textureThreshold < 0 )
CV_Error( CV_StsOutOfRange, "texture threshold must be non-negative" );
CV_Error( Error::StsOutOfRange, "texture threshold must be non-negative" );
if( params.uniquenessRatio < 0 )
CV_Error( CV_StsOutOfRange, "uniqueness ratio must be non-negative" );
CV_Error( Error::StsOutOfRange, "uniqueness ratio must be non-negative" );
preFilteredImg0.create( left0.size(), CV_8U );
preFilteredImg1.create( left0.size(), CV_8U );
@@ -887,15 +887,15 @@ public:
R2.area() > 0 ? Rect(0, 0, width, height) : validDisparityRect,
params.minDisparity, params.numDisparities,
params.SADWindowSize);
parallel_for_(Range(0, nstripes),
FindStereoCorrespInvoker(left, right, disp, &params, nstripes,
bufSize0, useShorts, validDisparityRect,
slidingSumBuf, cost));
if( params.speckleRange >= 0 && params.speckleWindowSize > 0 )
filterSpeckles(disp, FILTERED, params.speckleWindowSize, params.speckleRange, slidingSumBuf);
if (disp0.data != disp.data)
disp.convertTo(disp0, disp0.type(), 1./(1 << DISPARITY_SHIFT), 0);
}
@@ -963,7 +963,7 @@ public:
void read(const FileNode& fn)
{
FileNode n = fn["name"];
CV_Assert( n.isString() && strcmp(n.node->data.str.ptr, name_) == 0 );
CV_Assert( n.isString() && String(n) == name_ );
params.minDisparity = (int)fn["minDisparity"];
params.numDisparities = (int)fn["numDisparities"];
params.SADWindowSize = (int)fn["blockSize"];

View File

@@ -919,7 +919,7 @@ public:
void read(const FileNode& fn)
{
FileNode n = fn["name"];
CV_Assert( n.isString() && strcmp(n.node->data.str.ptr, name_) == 0 );
CV_Assert( n.isString() && String(n) == name_ );
params.minDisparity = (int)fn["minDisparity"];
params.numDisparities = (int)fn["numDisparities"];
params.SADWindowSize = (int)fn["blockSize"];

View File

@@ -40,6 +40,7 @@
//M*/
#include "precomp.hpp"
#include "opencv2/calib3d/calib3d_c.h"
// cvCorrectMatches function is Copyright (C) 2009, Jostein Austvik Jacobsen.
// cvTriangulatePoints function is derived from icvReconstructPointsFor3View, originally by Valery Mosyagin.