Skip to content

Commit

Permalink
Merge pull request opencv#3094 from Adil-Ibragimov:minor_fixes_in_Mat…
Browse files Browse the repository at this point in the history
…-data
  • Loading branch information
vpisarev committed Aug 13, 2014
2 parents 71ff228 + 9ac06a9 commit 5f590eb
Show file tree
Hide file tree
Showing 134 changed files with 988 additions and 986 deletions.
16 changes: 8 additions & 8 deletions apps/traincascade/HOGfeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ void CvHOGEvaluator::integralHistogram(const Mat &img, vector<Mat> &histogram, M

for( y = 0; y < gradSize.height; y++ )
{
const uchar* currPtr = img.data + img.step*ymap[y];
const uchar* prevPtr = img.data + img.step*ymap[y-1];
const uchar* nextPtr = img.data + img.step*ymap[y+1];
float* gradPtr = (float*)grad.ptr(y);
uchar* qanglePtr = (uchar*)qangle.ptr(y);
const uchar* currPtr = img.ptr(ymap[y]);
const uchar* prevPtr = img.ptr(ymap[y-1]);
const uchar* nextPtr = img.ptr(ymap[y+1]);
float* gradPtr = grad.ptr<float>(y);
uchar* qanglePtr = qangle.ptr(y);

for( x = 0; x < width; x++ )
{
Expand Down Expand Up @@ -226,9 +226,9 @@ void CvHOGEvaluator::integralHistogram(const Mat &img, vector<Mat> &histogram, M
int magStep = (int)( grad.step / sizeof(float) );
for( binIdx = 0; binIdx < nbins; binIdx++ )
{
histBuf = (float*)histogram[binIdx].data;
magBuf = (const float*)grad.data;
binsBuf = (const uchar*)qangle.data;
histBuf = histogram[binIdx].ptr<float>();
magBuf = grad.ptr<float>();
binsBuf = qangle.ptr();

memset( histBuf, 0, histSize.width * sizeof(histBuf[0]) );
histBuf += histStep + 1;
Expand Down
4 changes: 2 additions & 2 deletions apps/traincascade/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ float calcNormFactor( const Mat& sum, const Mat& sqSum )
size_t p0, p1, p2, p3;
CV_SUM_OFFSETS( p0, p1, p2, p3, normrect, sum.step1() )
double area = normrect.width * normrect.height;
const int *sp = (const int*)sum.data;
const int *sp = sum.ptr<int>();
int valSum = sp[p0] - sp[p1] - sp[p2] + sp[p3];
const double *sqp = (const double *)sqSum.data;
const double *sqp = sqSum.ptr<double>();
double valSqSum = sqp[p0] - sqp[p1] - sqp[p2] + sqp[p3];
return (float) sqrt( (double) (area * valSqSum - (double)valSum * valSum) );
}
Expand Down
2 changes: 1 addition & 1 deletion apps/traincascade/imagestorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool CvCascadeImageReader::NegReader::get( Mat& _img )
return false;

Mat mat( winSize.height, winSize.width, CV_8UC1,
(void*)(img.data + point.y * img.step + point.x * img.elemSize()), img.step );
(void*)(img.ptr(point.y) + point.x * img.elemSize()), img.step );
mat.copyTo(_img);

if( (int)( point.x + (1.0F + stepFactor ) * winSize.width ) < img.cols )
Expand Down
2 changes: 1 addition & 1 deletion modules/calib3d/src/calibinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ void cv::drawChessboardCorners( InputOutputArray _image, Size patternSize,
Mat image = _image.getMat(); CvMat c_image = _image.getMat();
int nelems = corners.checkVector(2, CV_32F, true);
CV_Assert(nelems >= 0);
cvDrawChessboardCorners( &c_image, patternSize, (CvPoint2D32f*)corners.data,
cvDrawChessboardCorners( &c_image, patternSize, corners.ptr<CvPoint2D32f>(),
nelems, patternWasFound );
}

Expand Down
12 changes: 6 additions & 6 deletions modules/calib3d/src/calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2998,15 +2998,15 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints,
int ni1 = imgpt1.checkVector(2, CV_32F);
CV_Assert( ni > 0 && ni == ni1 );
npoints.at<int>(i) = ni;
memcpy( objPtData + j, objpt.data, ni*sizeof(objPtData[0]) );
memcpy( imgPtData1 + j, imgpt1.data, ni*sizeof(imgPtData1[0]) );
memcpy( objPtData + j, objpt.ptr(), ni*sizeof(objPtData[0]) );
memcpy( imgPtData1 + j, imgpt1.ptr(), ni*sizeof(imgPtData1[0]) );

if( imgPtData2 )
{
Mat imgpt2 = imagePoints2.getMat(i);
int ni2 = imgpt2.checkVector(2, CV_32F);
CV_Assert( ni == ni2 );
memcpy( imgPtData2 + j, imgpt2.data, ni*sizeof(imgPtData2[0]) );
memcpy( imgPtData2 + j, imgpt2.ptr(), ni*sizeof(imgPtData2[0]) );
}
}
}
Expand Down Expand Up @@ -3245,13 +3245,13 @@ double cv::calibrateCamera( InputArrayOfArrays _objectPoints,
{
_rvecs.create(3, 1, CV_64F, i, true);
Mat rv = _rvecs.getMat(i);
memcpy(rv.data, rvecM.ptr<double>(i), 3*sizeof(double));
memcpy(rv.ptr(), rvecM.ptr<double>(i), 3*sizeof(double));
}
if( tvecs_needed )
{
_tvecs.create(3, 1, CV_64F, i, true);
Mat tv = _tvecs.getMat(i);
memcpy(tv.data, tvecM.ptr<double>(i), 3*sizeof(double));
memcpy(tv.ptr(), tvecM.ptr<double>(i), 3*sizeof(double));
}
}
cameraMatrix.copyTo(_cameraMatrix);
Expand Down Expand Up @@ -3472,7 +3472,7 @@ void cv::decomposeProjectionMatrix( InputArray _projMatrix, OutputArray _cameraM
if( _eulerAngles.needed() )
{
_eulerAngles.create(3, 1, CV_64F, -1, true);
p_eulerAngles = (CvPoint3D64f*)_eulerAngles.getMat().data;
p_eulerAngles = _eulerAngles.getMat().ptr<CvPoint3D64f>();
}

cvDecomposeProjectionMatrix(&c_projMatrix, &c_cameraMatrix, &c_rotMatrix,
Expand Down
4 changes: 2 additions & 2 deletions modules/calib3d/src/five-point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class EMEstimatorCallback : public PointSetRegistrator::Callback
Mat EE = Mat(Vt.t()).colRange(5, 9) * 1.0;
Mat A(10, 20, CV_64F);
EE = EE.t();
getCoeffMat((double*)EE.data, (double*)A.data);
getCoeffMat(EE.ptr<double>(), A.ptr<double>());
EE = EE.t();

A = A.colRange(0, 10).inv() * A.colRange(10, 20);
Expand Down Expand Up @@ -137,7 +137,7 @@ class EMEstimatorCallback : public PointSetRegistrator::Callback
cv::Mat Evec = EE.col(0) * xs.back() + EE.col(1) * ys.back() + EE.col(2) * zs.back() + EE.col(3);
Evec /= norm(Evec);

memcpy(e + count * 9, Evec.data, 9 * sizeof(double));
memcpy(e + count * 9, Evec.ptr(), 9 * sizeof(double));
count++;
}

Expand Down
54 changes: 27 additions & 27 deletions modules/calib3d/src/fundam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ void cv::computeCorrespondEpilines( InputArray _points, int whichImage,

if( depth == CV_32S || depth == CV_32F )
{
const Point* ptsi = (const Point*)points.data;
const Point2f* ptsf = (const Point2f*)points.data;
const Point* ptsi = points.ptr<Point>();
const Point2f* ptsf = points.ptr<Point2f>();
Point3f* dstf = lines.ptr<Point3f>();
for( int i = 0; i < npoints; i++ )
{
Expand All @@ -784,7 +784,7 @@ void cv::computeCorrespondEpilines( InputArray _points, int whichImage,
}
else
{
const Point2d* ptsd = (const Point2d*)points.data;
const Point2d* ptsd = points.ptr<Point2d>();
Point3d* dstd = lines.ptr<Point3d>();
for( int i = 0; i < npoints; i++ )
{
Expand Down Expand Up @@ -829,8 +829,8 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
{
if( cn == 3 )
{
const Point3i* sptr = (const Point3i*)src.data;
Point2f* dptr = (Point2f*)dst.data;
const Point3i* sptr = src.ptr<Point3i>();
Point2f* dptr = dst.ptr<Point2f>();
for( i = 0; i < npoints; i++ )
{
float scale = sptr[i].z != 0 ? 1.f/sptr[i].z : 1.f;
Expand All @@ -839,8 +839,8 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
}
else
{
const Vec4i* sptr = (const Vec4i*)src.data;
Point3f* dptr = (Point3f*)dst.data;
const Vec4i* sptr = src.ptr<Vec4i>();
Point3f* dptr = dst.ptr<Point3f>();
for( i = 0; i < npoints; i++ )
{
float scale = sptr[i][3] != 0 ? 1.f/sptr[i][3] : 1.f;
Expand All @@ -852,8 +852,8 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
{
if( cn == 3 )
{
const Point3f* sptr = (const Point3f*)src.data;
Point2f* dptr = (Point2f*)dst.data;
const Point3f* sptr = src.ptr<Point3f>();
Point2f* dptr = dst.ptr<Point2f>();
for( i = 0; i < npoints; i++ )
{
float scale = sptr[i].z != 0.f ? 1.f/sptr[i].z : 1.f;
Expand All @@ -862,8 +862,8 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
}
else
{
const Vec4f* sptr = (const Vec4f*)src.data;
Point3f* dptr = (Point3f*)dst.data;
const Vec4f* sptr = src.ptr<Vec4f>();
Point3f* dptr = dst.ptr<Point3f>();
for( i = 0; i < npoints; i++ )
{
float scale = sptr[i][3] != 0.f ? 1.f/sptr[i][3] : 1.f;
Expand All @@ -875,8 +875,8 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
{
if( cn == 3 )
{
const Point3d* sptr = (const Point3d*)src.data;
Point2d* dptr = (Point2d*)dst.data;
const Point3d* sptr = src.ptr<Point3d>();
Point2d* dptr = dst.ptr<Point2d>();
for( i = 0; i < npoints; i++ )
{
double scale = sptr[i].z != 0. ? 1./sptr[i].z : 1.;
Expand All @@ -885,8 +885,8 @@ void cv::convertPointsFromHomogeneous( InputArray _src, OutputArray _dst )
}
else
{
const Vec4d* sptr = (const Vec4d*)src.data;
Point3d* dptr = (Point3d*)dst.data;
const Vec4d* sptr = src.ptr<Vec4d>();
Point3d* dptr = dst.ptr<Point3d>();
for( i = 0; i < npoints; i++ )
{
double scale = sptr[i][3] != 0.f ? 1./sptr[i][3] : 1.;
Expand Down Expand Up @@ -928,15 +928,15 @@ void cv::convertPointsToHomogeneous( InputArray _src, OutputArray _dst )
{
if( cn == 2 )
{
const Point2i* sptr = (const Point2i*)src.data;
Point3i* dptr = (Point3i*)dst.data;
const Point2i* sptr = src.ptr<Point2i>();
Point3i* dptr = dst.ptr<Point3i>();
for( i = 0; i < npoints; i++ )
dptr[i] = Point3i(sptr[i].x, sptr[i].y, 1);
}
else
{
const Point3i* sptr = (const Point3i*)src.data;
Vec4i* dptr = (Vec4i*)dst.data;
const Point3i* sptr = src.ptr<Point3i>();
Vec4i* dptr = dst.ptr<Vec4i>();
for( i = 0; i < npoints; i++ )
dptr[i] = Vec4i(sptr[i].x, sptr[i].y, sptr[i].z, 1);
}
Expand All @@ -945,15 +945,15 @@ void cv::convertPointsToHomogeneous( InputArray _src, OutputArray _dst )
{
if( cn == 2 )
{
const Point2f* sptr = (const Point2f*)src.data;
Point3f* dptr = (Point3f*)dst.data;
const Point2f* sptr = src.ptr<Point2f>();
Point3f* dptr = dst.ptr<Point3f>();
for( i = 0; i < npoints; i++ )
dptr[i] = Point3f(sptr[i].x, sptr[i].y, 1.f);
}
else
{
const Point3f* sptr = (const Point3f*)src.data;
Vec4f* dptr = (Vec4f*)dst.data;
const Point3f* sptr = src.ptr<Point3f>();
Vec4f* dptr = dst.ptr<Vec4f>();
for( i = 0; i < npoints; i++ )
dptr[i] = Vec4f(sptr[i].x, sptr[i].y, sptr[i].z, 1.f);
}
Expand All @@ -962,15 +962,15 @@ void cv::convertPointsToHomogeneous( InputArray _src, OutputArray _dst )
{
if( cn == 2 )
{
const Point2d* sptr = (const Point2d*)src.data;
Point3d* dptr = (Point3d*)dst.data;
const Point2d* sptr = src.ptr<Point2d>();
Point3d* dptr = dst.ptr<Point3d>();
for( i = 0; i < npoints; i++ )
dptr[i] = Point3d(sptr[i].x, sptr[i].y, 1.);
}
else
{
const Point3d* sptr = (const Point3d*)src.data;
Vec4d* dptr = (Vec4d*)dst.data;
const Point3d* sptr = src.ptr<Point3d>();
Vec4d* dptr = dst.ptr<Vec4d>();
for( i = 0; i < npoints; i++ )
dptr[i] = Vec4d(sptr[i].x, sptr[i].y, sptr[i].z, 1.);
}
Expand Down
6 changes: 3 additions & 3 deletions modules/calib3d/src/ptsetreg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class RANSACPointSetRegistrator : public PointSetRegistrator
int d1 = m1.channels() > 1 ? m1.channels() : m1.cols;
int d2 = m2.channels() > 1 ? m2.channels() : m2.cols;
int count = m1.checkVector(d1), count2 = m2.checkVector(d2);
const int *m1ptr = (const int*)m1.data, *m2ptr = (const int*)m2.data;
const int *m1ptr = m1.ptr<int>(), *m2ptr = m2.ptr<int>();

ms1.create(modelPoints, 1, CV_MAKETYPE(m1.depth(), d1));
ms2.create(modelPoints, 1, CV_MAKETYPE(m2.depth(), d2));

int *ms1ptr = (int*)ms1.data, *ms2ptr = (int*)ms2.data;
int *ms1ptr = ms1.ptr<int>(), *ms2ptr = ms2.ptr<int>();

CV_Assert( count >= modelPoints && count == count2 );
CV_Assert( (esz1 % sizeof(int)) == 0 && (esz2 % sizeof(int)) == 0 );
Expand Down Expand Up @@ -343,7 +343,7 @@ class LMeDSPointSetRegistrator : public RANSACPointSetRegistrator
else
errf = err;
CV_Assert( errf.isContinuous() && errf.type() == CV_32F && (int)errf.total() == count );
std::sort((int*)errf.data, (int*)errf.data + count);
std::sort(errf.ptr<int>(), errf.ptr<int>() + count);

double median = count % 2 != 0 ?
errf.at<float>(count/2) : (errf.at<float>(count/2-1) + errf.at<float>(count/2))*0.5;
Expand Down
22 changes: 11 additions & 11 deletions modules/calib3d/src/stereobm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void prefilterNorm( const Mat& src, Mat& dst, int winsize, int ftzero, uc
int scale_g = winsize*winsize/8, scale_s = (1024 + scale_g)/(scale_g*2);
const int OFS = 256*5, TABSZ = OFS*2 + 256;
uchar tab[TABSZ];
const uchar* sptr = src.data;
const uchar* sptr = src.ptr();
int srcstep = (int)src.step;
Size size = src.size();

Expand Down Expand Up @@ -294,10 +294,10 @@ static void findStereoCorrespondenceBM_SSE2( const Mat& left, const Mat& right,
ushort *sad, *hsad0, *hsad, *hsad_sub;
int *htext;
uchar *cbuf0, *cbuf;
const uchar* lptr0 = left.data + lofs;
const uchar* rptr0 = right.data + rofs;
const uchar* lptr0 = left.ptr() + lofs;
const uchar* rptr0 = right.ptr() + rofs;
const uchar *lptr, *lptr_sub, *rptr;
short* dptr = (short*)disp.data;
short* dptr = disp.ptr<short>();
int sstep = (int)left.step;
int dstep = (int)(disp.step/sizeof(dptr[0]));
int cstep = (height + dy0 + dy1)*ndisp;
Expand Down Expand Up @@ -357,7 +357,7 @@ static void findStereoCorrespondenceBM_SSE2( const Mat& left, const Mat& right,

for( x = 0; x < width1; x++, dptr++ )
{
short* costptr = cost.data ? (short*)cost.data + lofs + x : &costbuf;
short* costptr = cost.data ? cost.ptr<short>() + lofs + x : &costbuf;
int x0 = x - wsz2 - 1, x1 = x + wsz2;
const uchar* cbuf_sub = cbuf0 + ((x0 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
cbuf = cbuf0 + ((x1 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
Expand Down Expand Up @@ -542,10 +542,10 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right,

int *sad, *hsad0, *hsad, *hsad_sub, *htext;
uchar *cbuf0, *cbuf;
const uchar* lptr0 = left.data + lofs;
const uchar* rptr0 = right.data + rofs;
const uchar* lptr0 = left.ptr() + lofs;
const uchar* rptr0 = right.ptr() + rofs;
const uchar *lptr, *lptr_sub, *rptr;
short* dptr = (short*)disp.data;
short* dptr = disp.ptr<short>();
int sstep = (int)left.step;
int dstep = (int)(disp.step/sizeof(dptr[0]));
int cstep = (height+dy0+dy1)*ndisp;
Expand Down Expand Up @@ -596,7 +596,7 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right,

for( x = 0; x < width1; x++, dptr++ )
{
int* costptr = cost.data ? (int*)cost.data + lofs + x : &costbuf;
int* costptr = cost.data ? cost.ptr<int>() + lofs + x : &costbuf;
int x0 = x - wsz2 - 1, x1 = x + wsz2;
const uchar* cbuf_sub = cbuf0 + ((x0 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
cbuf = cbuf0 + ((x1 + wsz2 + 1) % (wsz + 1))*cstep - dy0*ndisp;
Expand Down Expand Up @@ -803,7 +803,7 @@ struct FindStereoCorrespInvoker : public ParallelLoopBody
int cols = left->cols, rows = left->rows;
int _row0 = std::min(cvRound(range.start * rows / nstripes), rows);
int _row1 = std::min(cvRound(range.end * rows / nstripes), rows);
uchar *ptr = slidingSumBuf->data + range.start * stripeBufSize;
uchar *ptr = slidingSumBuf->ptr() + range.start * stripeBufSize;
int FILTERED = (state->minDisparity - 1)*16;

Rect roi = validDisparityRect & Rect(0, _row0, cols, _row1 - _row0);
Expand Down Expand Up @@ -988,7 +988,7 @@ class StereoBMImpl : public StereoBM
if( slidingSumBuf.cols < bufSize )
slidingSumBuf.create( 1, bufSize, CV_8U );

uchar *_buf = slidingSumBuf.data;
uchar *_buf = slidingSumBuf.ptr();

parallel_for_(Range(0, 2), PrefilterInvoker(left0, right0, left, right, _buf, _buf + bufSize1, &params), 1);

Expand Down
Loading

0 comments on commit 5f590eb

Please sign in to comment.