Skip to content

Commit

Permalink
Merge pull request opencv#11630 from alalek:c_api_eliminate_constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Sep 6, 2018
2 parents 80b62a4 + 8a3c394 commit f1f1584
Show file tree
Hide file tree
Showing 71 changed files with 969 additions and 689 deletions.
2 changes: 1 addition & 1 deletion apps/traincascade/boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void CvCascadeBoostTrainData::setData( const CvFeatureEvaluator* _featureEvaluat
featureEvaluator = _featureEvaluator;

max_c_count = MAX( 2, featureEvaluator->getMaxCatCount() );
_resp = featureEvaluator->getCls();
_resp = cvMat(featureEvaluator->getCls());
responses = &_resp;
// TODO: check responses: elements must be 0 or 1

Expand Down
8 changes: 4 additions & 4 deletions apps/traincascade/old_ml_boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2122,12 +2122,12 @@ CvBoost::train( const Mat& _train_data, int _tflag,
const Mat& _missing_mask,
CvBoostParams _params, bool _update )
{
train_data_hdr = _train_data;
train_data_hdr = cvMat(_train_data);
train_data_mat = _train_data;
responses_hdr = _responses;
responses_hdr = cvMat(_responses);
responses_mat = _responses;

CvMat vidx = _var_idx, sidx = _sample_idx, vtype = _var_type, mmask = _missing_mask;
CvMat vidx = cvMat(_var_idx), sidx = cvMat(_sample_idx), vtype = cvMat(_var_type), mmask = cvMat(_missing_mask);

return train(&train_data_hdr, _tflag, &responses_hdr, vidx.data.ptr ? &vidx : 0,
sidx.data.ptr ? &sidx : 0, vtype.data.ptr ? &vtype : 0,
Expand All @@ -2138,7 +2138,7 @@ float
CvBoost::predict( const Mat& _sample, const Mat& _missing,
const Range& slice, bool raw_mode, bool return_sum ) const
{
CvMat sample = _sample, mmask = _missing;
CvMat sample = cvMat(_sample), mmask = cvMat(_missing);
/*if( weak_responses )
{
int weak_count = cvSliceLength( slice, weak );
Expand Down
8 changes: 4 additions & 4 deletions apps/traincascade/old_ml_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,12 +1592,12 @@ bool CvDTree::train( const Mat& _train_data, int _tflag,
const Mat& _sample_idx, const Mat& _var_type,
const Mat& _missing_mask, CvDTreeParams _params )
{
train_data_hdr = _train_data;
train_data_hdr = cvMat(_train_data);
train_data_mat = _train_data;
responses_hdr = _responses;
responses_hdr = cvMat(_responses);
responses_mat = _responses;

CvMat vidx=_var_idx, sidx=_sample_idx, vtype=_var_type, mmask=_missing_mask;
CvMat vidx=cvMat(_var_idx), sidx=cvMat(_sample_idx), vtype=cvMat(_var_type), mmask=cvMat(_missing_mask);

return train(&train_data_hdr, _tflag, &responses_hdr, vidx.data.ptr ? &vidx : 0, sidx.data.ptr ? &sidx : 0,
vtype.data.ptr ? &vtype : 0, mmask.data.ptr ? &mmask : 0, _params);
Expand Down Expand Up @@ -3734,7 +3734,7 @@ CvDTreeNode* CvDTree::predict( const CvMat* _sample,

CvDTreeNode* CvDTree::predict( const Mat& _sample, const Mat& _missing, bool preprocessed_input ) const
{
CvMat sample = _sample, mmask = _missing;
CvMat sample = cvMat(_sample), mmask = cvMat(_missing);
return predict(&sample, mmask.data.ptr ? &mmask : 0, preprocessed_input);
}

Expand Down
200 changes: 106 additions & 94 deletions modules/calib3d/src/calibration.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions modules/calib3d/src/compat_stereo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ void cvFindStereoCorrespondenceBM( const CvArr* leftarr, const CvArr* rightarr,
CvRect cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
int numberOfDisparities, int SADWindowSize )
{
return (CvRect)cv::getValidDisparityROI( roi1, roi2, minDisparity,
numberOfDisparities, SADWindowSize );
return cvRect(cv::getValidDisparityROI( roi1, roi2, minDisparity,
numberOfDisparities, SADWindowSize));
}

void cvValidateDisparity( CvArr* _disp, const CvArr* _cost, int minDisparity,
Expand Down
6 changes: 3 additions & 3 deletions modules/calib3d/src/solvepnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ bool solvePnP( InputArray _opoints, InputArray _ipoints,
}
else if (flags == SOLVEPNP_ITERATIVE)
{
CvMat c_objectPoints = opoints, c_imagePoints = ipoints;
CvMat c_cameraMatrix = cameraMatrix, c_distCoeffs = distCoeffs;
CvMat c_rvec = rvec, c_tvec = tvec;
CvMat c_objectPoints = cvMat(opoints), c_imagePoints = cvMat(ipoints);
CvMat c_cameraMatrix = cvMat(cameraMatrix), c_distCoeffs = cvMat(distCoeffs);
CvMat c_rvec = cvMat(rvec), c_tvec = cvMat(tvec);
cvFindExtrinsicCameraParams2(&c_objectPoints, &c_imagePoints, &c_cameraMatrix,
(c_distCoeffs.rows && c_distCoeffs.cols) ? &c_distCoeffs : 0,
&c_rvec, &c_tvec, useExtrinsicGuess );
Expand Down
14 changes: 8 additions & 6 deletions modules/calib3d/src/triangulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,12 @@ void cv::triangulatePoints( InputArray _projMatr1, InputArray _projMatr2,
if((points2.rows == 1 || points2.cols == 1) && points2.channels() == 2)
points2 = points2.reshape(1, static_cast<int>(points2.total())).t();

CvMat cvMatr1 = matr1, cvMatr2 = matr2;
CvMat cvPoints1 = points1, cvPoints2 = points2;
CvMat cvMatr1 = cvMat(matr1), cvMatr2 = cvMat(matr2);
CvMat cvPoints1 = cvMat(points1), cvPoints2 = cvMat(points2);

_points4D.create(4, points1.cols, points1.type());
CvMat cvPoints4D = _points4D.getMat();
Mat cvPoints4D_ = _points4D.getMat();
CvMat cvPoints4D = cvMat(cvPoints4D_);

cvTriangulatePoints(&cvMatr1, &cvMatr2, &cvPoints1, &cvPoints2, &cvPoints4D);
}
Expand All @@ -375,12 +376,13 @@ void cv::correctMatches( InputArray _F, InputArray _points1, InputArray _points2
Mat F = _F.getMat();
Mat points1 = _points1.getMat(), points2 = _points2.getMat();

CvMat cvPoints1 = points1, cvPoints2 = points2;
CvMat cvF = F;
CvMat cvPoints1 = cvMat(points1), cvPoints2 = cvMat(points2);
CvMat cvF = cvMat(F);

_newPoints1.create(points1.size(), points1.type());
_newPoints2.create(points2.size(), points2.type());
CvMat cvNewPoints1 = _newPoints1.getMat(), cvNewPoints2 = _newPoints2.getMat();
Mat cvNewPoints1_ = _newPoints1.getMat(), cvNewPoints2_ = _newPoints2.getMat();
CvMat cvNewPoints1 = cvMat(cvNewPoints1_), cvNewPoints2 = cvMat(cvNewPoints2_);

cvCorrectMatches(&cvF, &cvPoints1, &cvPoints2, &cvNewPoints1, &cvNewPoints2);
}
54 changes: 27 additions & 27 deletions modules/calib3d/test/test_cameracalibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ void CV_CameraCalibrationTest::run( int start_from )
cv::String filepath;
cv::String filename;

CvSize imageSize;
CvSize etalonSize;
Size imageSize;
Size etalonSize;
int numImages;

CvPoint2D64f* imagePoints;
Expand Down Expand Up @@ -531,7 +531,7 @@ void CV_CameraCalibrationTest::run( int start_from )
/* Now we can calibrate camera */
calibrate( numImages,
numbers,
imageSize,
cvSize(imageSize),
imagePoints,
objectPoints,
distortion,
Expand Down Expand Up @@ -1009,9 +1009,9 @@ void CV_CalibrationMatrixValuesTest_C::calibMatrixValues( const Mat& _cameraMatr
double& fovx, double& fovy, double& focalLength,
Point2d& principalPoint, double& aspectRatio )
{
CvMat cameraMatrix = _cameraMatrix;
CvPoint2D64f pp;
cvCalibrationMatrixValues( &cameraMatrix, imageSize, apertureWidth, apertureHeight,
CvMat cameraMatrix = cvMat(_cameraMatrix);
CvPoint2D64f pp = {0, 0};
cvCalibrationMatrixValues( &cameraMatrix, cvSize(imageSize), apertureWidth, apertureHeight,
&fovx, &fovy, &focalLength, &pp, &aspectRatio );
principalPoint.x = pp.x;
principalPoint.y = pp.y;
Expand Down Expand Up @@ -1305,9 +1305,9 @@ void CV_ProjectPointsTest_C::project( const Mat& opoints, const Mat& rvec, const
dpdc.create(npoints*2, 2, CV_64F);
dpddist.create(npoints*2, distCoeffs.rows + distCoeffs.cols - 1, CV_64F);
Mat imagePoints(ipoints);
CvMat _objectPoints = opoints, _imagePoints = imagePoints;
CvMat _rvec = rvec, _tvec = tvec, _cameraMatrix = cameraMatrix, _distCoeffs = distCoeffs;
CvMat _dpdrot = dpdrot, _dpdt = dpdt, _dpdf = dpdf, _dpdc = dpdc, _dpddist = dpddist;
CvMat _objectPoints = cvMat(opoints), _imagePoints = cvMat(imagePoints);
CvMat _rvec = cvMat(rvec), _tvec = cvMat(tvec), _cameraMatrix = cvMat(cameraMatrix), _distCoeffs = cvMat(distCoeffs);
CvMat _dpdrot = cvMat(dpdrot), _dpdt = cvMat(dpdt), _dpdf = cvMat(dpdf), _dpdc = cvMat(dpdc), _dpddist = cvMat(dpddist);

cvProjectPoints2( &_objectPoints, &_rvec, &_tvec, &_cameraMatrix, &_distCoeffs,
&_imagePoints, &_dpdrot, &_dpdt, &_dpdf, &_dpdc, &_dpddist, aspectRatio );
Expand Down Expand Up @@ -1925,14 +1925,14 @@ double CV_StereoCalibrationTest_C::calibrateStereoCamera( const vector<vector<Po
std::copy(imagePoints1[i].begin(), imagePoints1[i].end(), imgPtData + j);
std::copy(imagePoints2[i].begin(), imagePoints2[i].end(), imgPtData2 + j);
}
CvMat _objPt = objPt, _imgPt = imgPt, _imgPt2 = imgPt2, _npoints = npoints;
CvMat _cameraMatrix1 = cameraMatrix1, _distCoeffs1 = distCoeffs1;
CvMat _cameraMatrix2 = cameraMatrix2, _distCoeffs2 = distCoeffs2;
CvMat matR = R, matT = T, matE = E, matF = F;
CvMat _objPt = cvMat(objPt), _imgPt = cvMat(imgPt), _imgPt2 = cvMat(imgPt2), _npoints = cvMat(npoints);
CvMat _cameraMatrix1 = cvMat(cameraMatrix1), _distCoeffs1 = cvMat(distCoeffs1);
CvMat _cameraMatrix2 = cvMat(cameraMatrix2), _distCoeffs2 = cvMat(distCoeffs2);
CvMat matR = cvMat(R), matT = cvMat(T), matE = cvMat(E), matF = cvMat(F);

return cvStereoCalibrate(&_objPt, &_imgPt, &_imgPt2, &_npoints, &_cameraMatrix1,
&_distCoeffs1, &_cameraMatrix2, &_distCoeffs2, imageSize,
&matR, &matT, &matE, &matF, flags, criteria );
&_distCoeffs1, &_cameraMatrix2, &_distCoeffs2, cvSize(imageSize),
&matR, &matT, &matE, &matF, flags, cvTermCriteria(criteria));
}

void CV_StereoCalibrationTest_C::rectify( const Mat& cameraMatrix1, const Mat& distCoeffs1,
Expand All @@ -1948,43 +1948,43 @@ void CV_StereoCalibrationTest_C::rectify( const Mat& cameraMatrix1, const Mat& d
P1.create(3, 4, rtype);
P2.create(3, 4, rtype);
Q.create(4, 4, rtype);
CvMat _cameraMatrix1 = cameraMatrix1, _distCoeffs1 = distCoeffs1;
CvMat _cameraMatrix2 = cameraMatrix2, _distCoeffs2 = distCoeffs2;
CvMat matR = R, matT = T, _R1 = R1, _R2 = R2, _P1 = P1, _P2 = P2, matQ = Q;
CvMat _cameraMatrix1 = cvMat(cameraMatrix1), _distCoeffs1 = cvMat(distCoeffs1);
CvMat _cameraMatrix2 = cvMat(cameraMatrix2), _distCoeffs2 = cvMat(distCoeffs2);
CvMat matR = cvMat(R), matT = cvMat(T), _R1 = cvMat(R1), _R2 = cvMat(R2), _P1 = cvMat(P1), _P2 = cvMat(P2), matQ = cvMat(Q);
cvStereoRectify( &_cameraMatrix1, &_cameraMatrix2, &_distCoeffs1, &_distCoeffs2,
imageSize, &matR, &matT, &_R1, &_R2, &_P1, &_P2, &matQ, flags,
alpha, newImageSize, (CvRect*)validPixROI1, (CvRect*)validPixROI2);
cvSize(imageSize), &matR, &matT, &_R1, &_R2, &_P1, &_P2, &matQ, flags,
alpha, cvSize(newImageSize), (CvRect*)validPixROI1, (CvRect*)validPixROI2);
}

bool CV_StereoCalibrationTest_C::rectifyUncalibrated( const Mat& points1,
const Mat& points2, const Mat& F, Size imgSize, Mat& H1, Mat& H2, double threshold )
{
H1.create(3, 3, CV_64F);
H2.create(3, 3, CV_64F);
CvMat _pt1 = points1, _pt2 = points2, matF, *pF=0, _H1 = H1, _H2 = H2;
CvMat _pt1 = cvMat(points1), _pt2 = cvMat(points2), matF, *pF=0, _H1 = cvMat(H1), _H2 = cvMat(H2);
if( F.size() == Size(3, 3) )
pF = &(matF = F);
return cvStereoRectifyUncalibrated(&_pt1, &_pt2, pF, imgSize, &_H1, &_H2, threshold) > 0;
pF = &(matF = cvMat(F));
return cvStereoRectifyUncalibrated(&_pt1, &_pt2, pF, cvSize(imgSize), &_H1, &_H2, threshold) > 0;
}

void CV_StereoCalibrationTest_C::triangulate( const Mat& P1, const Mat& P2,
const Mat &points1, const Mat &points2,
Mat &points4D )
{
CvMat _P1 = P1, _P2 = P2, _points1 = points1, _points2 = points2;
CvMat _P1 = cvMat(P1), _P2 = cvMat(P2), _points1 = cvMat(points1), _points2 = cvMat(points2);
points4D.create(4, points1.cols, points1.type());
CvMat _points4D = points4D;
CvMat _points4D = cvMat(points4D);
cvTriangulatePoints(&_P1, &_P2, &_points1, &_points2, &_points4D);
}

void CV_StereoCalibrationTest_C::correct( const Mat& F,
const Mat &points1, const Mat &points2,
Mat &newPoints1, Mat &newPoints2 )
{
CvMat _F = F, _points1 = points1, _points2 = points2;
CvMat _F = cvMat(F), _points1 = cvMat(points1), _points2 = cvMat(points2);
newPoints1.create(1, points1.cols, points1.type());
newPoints2.create(1, points2.cols, points2.type());
CvMat _newPoints1 = newPoints1, _newPoints2 = newPoints2;
CvMat _newPoints1 = cvMat(newPoints1), _newPoints2 = cvMat(newPoints2);
cvCorrectMatches(&_F, &_points1, &_points2, &_newPoints1, &_newPoints2);
}

Expand Down
Loading

0 comments on commit f1f1584

Please sign in to comment.