diff --git a/apps/traincascade/HOGfeatures.cpp b/apps/traincascade/HOGfeatures.cpp index e479777df..bb435c4b0 100644 --- a/apps/traincascade/HOGfeatures.cpp +++ b/apps/traincascade/HOGfeatures.cpp @@ -187,11 +187,11 @@ void CvHOGEvaluator::integralHistogram(const Mat &img, vector &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(y); + uchar* qanglePtr = qangle.ptr(y); for( x = 0; x < width; x++ ) { @@ -226,9 +226,9 @@ void CvHOGEvaluator::integralHistogram(const Mat &img, vector &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(); + magBuf = grad.ptr(); + binsBuf = qangle.ptr(); memset( histBuf, 0, histSize.width * sizeof(histBuf[0]) ); histBuf += histStep + 1; diff --git a/apps/traincascade/features.cpp b/apps/traincascade/features.cpp index be0fe5f7f..09e08ac24 100644 --- a/apps/traincascade/features.cpp +++ b/apps/traincascade/features.cpp @@ -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 valSum = sp[p0] - sp[p1] - sp[p2] + sp[p3]; - const double *sqp = (const double *)sqSum.data; + const double *sqp = sqSum.ptr(); double valSqSum = sqp[p0] - sqp[p1] - sqp[p2] + sqp[p3]; return (float) sqrt( (double) (area * valSqSum - (double)valSum * valSum) ); } diff --git a/apps/traincascade/imagestorage.cpp b/apps/traincascade/imagestorage.cpp index 2f791240e..7a004c610 100644 --- a/apps/traincascade/imagestorage.cpp +++ b/apps/traincascade/imagestorage.cpp @@ -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 ) diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index ca2121ba2..b85b3fcae 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -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(), nelems, patternWasFound ); } diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 05ae60b99..43a4cd147 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -2998,15 +2998,15 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints, int ni1 = imgpt1.checkVector(2, CV_32F); CV_Assert( ni > 0 && ni == ni1 ); npoints.at(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]) ); } } } @@ -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(i), 3*sizeof(double)); + memcpy(rv.ptr(), rvecM.ptr(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(i), 3*sizeof(double)); + memcpy(tv.ptr(), tvecM.ptr(i), 3*sizeof(double)); } } cameraMatrix.copyTo(_cameraMatrix); @@ -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(); } cvDecomposeProjectionMatrix(&c_projMatrix, &c_cameraMatrix, &c_rotMatrix, diff --git a/modules/calib3d/src/five-point.cpp b/modules/calib3d/src/five-point.cpp index 992224700..f575b02a9 100644 --- a/modules/calib3d/src/five-point.cpp +++ b/modules/calib3d/src/five-point.cpp @@ -61,7 +61,7 @@ public: 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(), A.ptr()); EE = EE.t(); A = A.colRange(0, 10).inv() * A.colRange(10, 20); @@ -137,7 +137,7 @@ public: 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++; } diff --git a/modules/calib3d/src/fundam.cpp b/modules/calib3d/src/fundam.cpp index d1c6e8cd0..3c112a72a 100644 --- a/modules/calib3d/src/fundam.cpp +++ b/modules/calib3d/src/fundam.cpp @@ -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(); + const Point2f* ptsf = points.ptr(); Point3f* dstf = lines.ptr(); for( int i = 0; i < npoints; i++ ) { @@ -784,7 +784,7 @@ void cv::computeCorrespondEpilines( InputArray _points, int whichImage, } else { - const Point2d* ptsd = (const Point2d*)points.data; + const Point2d* ptsd = points.ptr(); Point3d* dstd = lines.ptr(); for( int i = 0; i < npoints; i++ ) { @@ -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(); + Point2f* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) { float scale = sptr[i].z != 0 ? 1.f/sptr[i].z : 1.f; @@ -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(); + Point3f* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) { float scale = sptr[i][3] != 0 ? 1.f/sptr[i][3] : 1.f; @@ -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(); + Point2f* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) { float scale = sptr[i].z != 0.f ? 1.f/sptr[i].z : 1.f; @@ -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(); + Point3f* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) { float scale = sptr[i][3] != 0.f ? 1.f/sptr[i][3] : 1.f; @@ -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(); + Point2d* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) { double scale = sptr[i].z != 0. ? 1./sptr[i].z : 1.; @@ -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(); + Point3d* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) { double scale = sptr[i][3] != 0.f ? 1./sptr[i][3] : 1.; @@ -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(); + Point3i* dptr = dst.ptr(); 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(); + Vec4i* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) dptr[i] = Vec4i(sptr[i].x, sptr[i].y, sptr[i].z, 1); } @@ -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(); + Point3f* dptr = dst.ptr(); 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(); + Vec4f* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) dptr[i] = Vec4f(sptr[i].x, sptr[i].y, sptr[i].z, 1.f); } @@ -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(); + Point3d* dptr = dst.ptr(); 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(); + Vec4d* dptr = dst.ptr(); for( i = 0; i < npoints; i++ ) dptr[i] = Vec4d(sptr[i].x, sptr[i].y, sptr[i].z, 1.); } diff --git a/modules/calib3d/src/ptsetreg.cpp b/modules/calib3d/src/ptsetreg.cpp index 3c43624e7..96c69d0c9 100644 --- a/modules/calib3d/src/ptsetreg.cpp +++ b/modules/calib3d/src/ptsetreg.cpp @@ -113,12 +113,12 @@ public: 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(), *m2ptr = m2.ptr(); 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(), *ms2ptr = ms2.ptr(); CV_Assert( count >= modelPoints && count == count2 ); CV_Assert( (esz1 % sizeof(int)) == 0 && (esz2 % sizeof(int)) == 0 ); @@ -343,7 +343,7 @@ public: 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(), errf.ptr() + count); double median = count % 2 != 0 ? errf.at(count/2) : (errf.at(count/2-1) + errf.at(count/2))*0.5; diff --git a/modules/calib3d/src/stereobm.cpp b/modules/calib3d/src/stereobm.cpp index 676202d12..c476b8973 100644 --- a/modules/calib3d/src/stereobm.cpp +++ b/modules/calib3d/src/stereobm.cpp @@ -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(); @@ -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(); int sstep = (int)left.step; int dstep = (int)(disp.step/sizeof(dptr[0])); int cstep = (height + dy0 + dy1)*ndisp; @@ -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() + 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; @@ -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(); int sstep = (int)left.step; int dstep = (int)(disp.step/sizeof(dptr[0])); int cstep = (height+dy0+dy1)*ndisp; @@ -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() + 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; @@ -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); @@ -988,7 +988,7 @@ public: 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, ¶ms), 1); diff --git a/modules/calib3d/src/stereosgbm.cpp b/modules/calib3d/src/stereosgbm.cpp index f96a6ad83..ab718ff29 100644 --- a/modules/calib3d/src/stereosgbm.cpp +++ b/modules/calib3d/src/stereosgbm.cpp @@ -383,12 +383,12 @@ static void computeDisparitySGBM( const Mat& img1, const Mat& img2, width*16*img1.channels()*sizeof(PixType) + // temp buffer for computing per-pixel cost width*(sizeof(CostType) + sizeof(DispType)) + 1024; // disp2cost + disp2 - if( !buffer.data || !buffer.isContinuous() || + if( buffer.empty() || !buffer.isContinuous() || buffer.cols*buffer.rows*buffer.elemSize() < totalBufSize ) buffer.create(1, (int)totalBufSize, CV_8U); // summary cost over different (nDirs) directions - CostType* Cbuf = (CostType*)alignPtr(buffer.data, ALIGN); + CostType* Cbuf = (CostType*)alignPtr(buffer.ptr(), ALIGN); CostType* Sbuf = Cbuf + CSBufSize; CostType* hsumBuf = Sbuf + CSBufSize; CostType* pixDiff = hsumBuf + costBufSize*hsumBufNRows; @@ -982,10 +982,10 @@ void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDif int width = img.cols, height = img.rows, npixels = width*height; size_t bufSize = npixels*(int)(sizeof(Point2s) + sizeof(int) + sizeof(uchar)); - if( !_buf.isContinuous() || !_buf.data || _buf.cols*_buf.rows*_buf.elemSize() < bufSize ) + if( !_buf.isContinuous() || _buf.empty() || _buf.cols*_buf.rows*_buf.elemSize() < bufSize ) _buf.create(1, (int)bufSize, CV_8U); - uchar* buf = _buf.data; + uchar* buf = _buf.ptr(); int i, j, dstep = (int)(img.step/sizeof(T)); int* labels = (int*)buf; buf += npixels*sizeof(labels[0]); @@ -1097,10 +1097,10 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi if ((int)status >= 0) { if (type == CV_8UC1) - status = ippiMarkSpeckles_8u_C1IR((Ipp8u *)img.data, (int)img.step, roisize, + status = ippiMarkSpeckles_8u_C1IR(img.ptr(), (int)img.step, roisize, (Ipp8u)newVal, maxSpeckleSize, (Ipp8u)maxDiff, ippiNormL1, buffer); else - status = ippiMarkSpeckles_16s_C1IR((Ipp16s *)img.data, (int)img.step, roisize, + status = ippiMarkSpeckles_16s_C1IR(img.ptr(), (int)img.step, roisize, (Ipp16s)newVal, maxSpeckleSize, (Ipp16s)maxDiff, ippiNormL1, buffer); } diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index 5b4b72cca..bbd363cdf 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -773,10 +773,10 @@ void CV_CameraCalibrationTest_CPP::calibrate( int imageCount, int* pointCounts, flags ); assert( cameraMatrix.type() == CV_64FC1 ); - memcpy( _cameraMatrix, cameraMatrix.data, 9*sizeof(double) ); + memcpy( _cameraMatrix, cameraMatrix.ptr(), 9*sizeof(double) ); assert( cameraMatrix.type() == CV_64FC1 ); - memcpy( _distortionCoeffs, distCoeffs.data, 4*sizeof(double) ); + memcpy( _distortionCoeffs, distCoeffs.ptr(), 4*sizeof(double) ); vector::iterator rvecsIt = rvecs.begin(); vector::iterator tvecsIt = tvecs.begin(); @@ -788,8 +788,8 @@ void CV_CameraCalibrationTest_CPP::calibrate( int imageCount, int* pointCounts, { Mat r9( 3, 3, CV_64FC1 ); Rodrigues( *rvecsIt, r9 ); - memcpy( rm, r9.data, 9*sizeof(double) ); - memcpy( tm, tvecsIt->data, 3*sizeof(double) ); + memcpy( rm, r9.ptr(), 9*sizeof(double) ); + memcpy( tm, tvecsIt->ptr(), 3*sizeof(double) ); } } @@ -1430,7 +1430,7 @@ void CV_StereoCalibrationTest::run( int ) { Mat left = imread(imglist[i*2]); Mat right = imread(imglist[i*2+1]); - if(!left.data || !right.data) + if(left.empty() || right.empty()) { ts->printf( cvtest::TS::LOG, "Can not load images %s and %s, testcase %d\n", imglist[i*2].c_str(), imglist[i*2+1].c_str(), testcase ); @@ -1722,7 +1722,7 @@ double CV_StereoCalibrationTest_C::calibrateStereoCamera( const vector()[i] = ni; std::copy(objectPoints[i].begin(), objectPoints[i].end(), objPtData + j); std::copy(imagePoints1[i].begin(), imagePoints1[i].end(), imgPtData + j); std::copy(imagePoints2[i].begin(), imagePoints2[i].end(), imgPtData2 + j); diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index e2245c12b..7eb12ad24 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -1021,12 +1021,12 @@ void CV_FundamentalMatTest::prepare_to_validation( int test_case_idx ) cv::gemm( T, invA2, 1, Mat(), 0, F0 ); F0 *= 1./f0[8]; - uchar* status = test_mat[TEMP][1].data; + uchar* status = test_mat[TEMP][1].ptr(); double err_level = method <= CV_FM_8POINT ? 1 : get_success_error_level( test_case_idx, OUTPUT, 1 ); - uchar* mtfm1 = test_mat[REF_OUTPUT][1].data; - uchar* mtfm2 = test_mat[OUTPUT][1].data; - double* f_prop1 = (double*)test_mat[REF_OUTPUT][0].data; - double* f_prop2 = (double*)test_mat[OUTPUT][0].data; + uchar* mtfm1 = test_mat[REF_OUTPUT][1].ptr(); + uchar* mtfm2 = test_mat[OUTPUT][1].ptr(); + double* f_prop1 = test_mat[REF_OUTPUT][0].ptr(); + double* f_prop2 = test_mat[OUTPUT][0].ptr(); int i, pt_count = test_mat[INPUT][2].cols; Mat p1( 1, pt_count, CV_64FC2 ); @@ -1357,12 +1357,12 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx ) cv::gemm( T1, T2, 1, Mat(), 0, F0 ); F0 *= 1./f0[8]; - uchar* status = test_mat[TEMP][1].data; + uchar* status = test_mat[TEMP][1].ptr(); double err_level = get_success_error_level( test_case_idx, OUTPUT, 1 ); - uchar* mtfm1 = test_mat[REF_OUTPUT][1].data; - uchar* mtfm2 = test_mat[OUTPUT][1].data; - double* e_prop1 = (double*)test_mat[REF_OUTPUT][0].data; - double* e_prop2 = (double*)test_mat[OUTPUT][0].data; + uchar* mtfm1 = test_mat[REF_OUTPUT][1].ptr(); + uchar* mtfm2 = test_mat[OUTPUT][1].ptr(); + double* e_prop1 = test_mat[REF_OUTPUT][0].ptr(); + double* e_prop2 = test_mat[OUTPUT][0].ptr(); Mat E_prop2 = Mat(3, 1, CV_64F, e_prop2); int i, pt_count = test_mat[INPUT][2].cols; @@ -1407,8 +1407,8 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx ) - double* pose_prop1 = (double*)test_mat[REF_OUTPUT][2].data; - double* pose_prop2 = (double*)test_mat[OUTPUT][2].data; + double* pose_prop1 = test_mat[REF_OUTPUT][2].ptr(); + double* pose_prop2 = test_mat[OUTPUT][2].ptr(); double terr1 = cvtest::norm(Rt0.col(3) / norm(Rt0.col(3)) + test_mat[TEMP][3], NORM_L2); double terr2 = cvtest::norm(Rt0.col(3) / norm(Rt0.col(3)) - test_mat[TEMP][3], NORM_L2); Mat rvec; diff --git a/modules/calib3d/test/test_reproject_image_to_3d.cpp b/modules/calib3d/test/test_reproject_image_to_3d.cpp index daf89e0f0..3e77a290c 100644 --- a/modules/calib3d/test/test_reproject_image_to_3d.cpp +++ b/modules/calib3d/test/test_reproject_image_to_3d.cpp @@ -142,7 +142,7 @@ protected: Mat_ res = Q * Mat_(4, 1, from); res /= res(3, 0); - out3d_t pixel_exp = *(Vec3d*)res.data; + out3d_t pixel_exp = *res.ptr(); out3d_t pixel_out = _3dImg(y, x); const int largeZValue = 10000; /* see documentation */ diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 5bc67edaa..4f383686f 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -2121,7 +2121,7 @@ MatConstIterator::MatConstIterator(const Mat* _m) { if( m && m->isContinuous() ) { - sliceStart = m->data; + sliceStart = m->ptr(); sliceEnd = sliceStart + m->total()*elemSize; } seek((const int*)0); @@ -2134,7 +2134,7 @@ MatConstIterator::MatConstIterator(const Mat* _m, int _row, int _col) CV_Assert(m && m->dims <= 2); if( m->isContinuous() ) { - sliceStart = m->data; + sliceStart = m->ptr(); sliceEnd = sliceStart + m->total()*elemSize; } int idx[] = {_row, _col}; @@ -2148,7 +2148,7 @@ MatConstIterator::MatConstIterator(const Mat* _m, Point _pt) CV_Assert(m && m->dims <= 2); if( m->isContinuous() ) { - sliceStart = m->data; + sliceStart = m->ptr(); sliceEnd = sliceStart + m->total()*elemSize; } int idx[] = {_pt.y, _pt.x}; diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 277270d14..fe157f868 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1076,7 +1076,7 @@ void convertAndUnrollScalar( const Mat& sc, int buftype, uchar* scbuf, size_t bl { int scn = (int)sc.total(), cn = CV_MAT_CN(buftype); size_t esz = CV_ELEM_SIZE(buftype); - getConvertFunc(sc.depth(), buftype)(sc.data, 1, 0, 1, scbuf, 1, Size(std::min(cn, scn), 1), 0); + getConvertFunc(sc.depth(), buftype)(sc.ptr(), 1, 0, 1, scbuf, 1, Size(std::min(cn, scn), 1), 0); // unroll the scalar if( scn < cn ) { @@ -1215,7 +1215,7 @@ static void binary_op( InputArray _src1, InputArray _src2, OutputArray _dst, if( len == (size_t)(int)len ) { sz.width = (int)len; - func(src1.data, src1.step, src2.data, src2.step, dst.data, dst.step, sz, 0); + func(src1.ptr(), src1.step, src2.ptr(), src2.step, dst.ptr(), dst.step, sz, 0); return; } } @@ -1622,7 +1622,7 @@ static void arithm_op(InputArray _src1, InputArray _src2, OutputArray _dst, Mat src1 = psrc1->getMat(), src2 = psrc2->getMat(), dst = _dst.getMat(); Size sz = getContinuousSize(src1, src2, dst, src1.channels()); - tab[depth1](src1.data, src1.step, src2.data, src2.step, dst.data, dst.step, sz, usrdata); + tab[depth1](src1.ptr(), src1.step, src2.ptr(), src2.step, dst.ptr(), dst.step, sz, usrdata); return; } @@ -2985,7 +2985,7 @@ static bool ocl_compare(InputArray _src1, InputArray _src2, OutputArray _dst, in else { double fval = 0; - getConvertFunc(depth2, CV_64F)(src2.data, 1, 0, 1, (uchar *)&fval, 1, Size(1, 1), 0); + getConvertFunc(depth2, CV_64F)(src2.ptr(), 1, 0, 1, (uchar *)&fval, 1, Size(1, 1), 0); if( fval < getMinVal(depth1) ) return dst.setTo(Scalar::all(op == CMP_GT || op == CMP_GE || op == CMP_NE ? 255 : 0)), true; @@ -3065,7 +3065,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) _dst.create(src1.size(), CV_8UC(cn)); Mat dst = _dst.getMat(); Size sz = getContinuousSize(src1, src2, dst, src1.channels()); - getCmpFunc(src1.depth())(src1.data, src1.step, src2.data, src2.step, dst.data, dst.step, sz, &op); + getCmpFunc(src1.depth())(src1.ptr(), src1.step, src2.ptr(), src2.step, dst.ptr(), dst.step, sz, &op); return; } @@ -3106,7 +3106,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) else { double fval=0; - getConvertFunc(depth2, CV_64F)(src2.data, 1, 0, 1, (uchar*)&fval, 1, Size(1,1), 0); + getConvertFunc(depth2, CV_64F)(src2.ptr(), 1, 0, 1, (uchar*)&fval, 1, Size(1,1), 0); if( fval < getMinVal(depth1) ) { dst = Scalar::all(op == CMP_GT || op == CMP_GE || op == CMP_NE ? 255 : 0); @@ -3676,8 +3676,8 @@ static bool ocl_inRange( InputArray _src, InputArray _lowerb, int* iubuf = ilbuf + cn; BinaryFunc sccvtfunc = getConvertFunc(ldepth, CV_32S); - sccvtfunc(lscalar.data, 1, 0, 1, (uchar*)ilbuf, 1, Size(cn, 1), 0); - sccvtfunc(uscalar.data, 1, 0, 1, (uchar*)iubuf, 1, Size(cn, 1), 0); + sccvtfunc(lscalar.ptr(), 1, 0, 1, (uchar*)ilbuf, 1, Size(cn, 1), 0); + sccvtfunc(uscalar.ptr(), 1, 0, 1, (uchar*)iubuf, 1, Size(cn, 1), 0); int minval = cvRound(getMinVal(sdepth)), maxval = cvRound(getMaxVal(sdepth)); for( int k = 0; k < cn; k++ ) @@ -3787,8 +3787,8 @@ void cv::inRange(InputArray _src, InputArray _lowerb, int* iubuf = ilbuf + cn; BinaryFunc sccvtfunc = getConvertFunc(scdepth, CV_32S); - sccvtfunc(lb.data, 1, 0, 1, (uchar*)ilbuf, 1, Size(cn, 1), 0); - sccvtfunc(ub.data, 1, 0, 1, (uchar*)iubuf, 1, Size(cn, 1), 0); + sccvtfunc(lb.ptr(), 1, 0, 1, (uchar*)ilbuf, 1, Size(cn, 1), 0); + sccvtfunc(ub.ptr(), 1, 0, 1, (uchar*)iubuf, 1, Size(cn, 1), 0); int minval = cvRound(getMinVal(depth)), maxval = cvRound(getMaxVal(depth)); for( int k = 0; k < cn; k++ ) diff --git a/modules/core/src/convert.cpp b/modules/core/src/convert.cpp index 61499b39a..051f863d6 100644 --- a/modules/core/src/convert.cpp +++ b/modules/core/src/convert.cpp @@ -1815,7 +1815,7 @@ void cv::convertScaleAbs( InputArray _src, OutputArray _dst, double alpha, doubl if( src.dims <= 2 ) { Size sz = getContinuousSize(src, dst, cn); - func( src.data, src.step, 0, 0, dst.data, dst.step, sz, scale ); + func( src.ptr(), src.step, 0, 0, dst.ptr(), dst.step, sz, scale ); } else { @@ -2054,7 +2054,7 @@ public: CV_DbgAssert(lutcn == 3 || lutcn == 4); if (lutcn == 3) { - IppStatus status = ippiCopy_8u_C3P3R(lut.data, (int)lut.step[0], lutTable, (int)lut.step[0], sz256); + IppStatus status = ippiCopy_8u_C3P3R(lut.ptr(), (int)lut.step[0], lutTable, (int)lut.step[0], sz256); if (status < 0) { setIppErrorStatus(); @@ -2063,7 +2063,7 @@ public: } else if (lutcn == 4) { - IppStatus status = ippiCopy_8u_C4P4R(lut.data, (int)lut.step[0], lutTable, (int)lut.step[0], sz256); + IppStatus status = ippiCopy_8u_C4P4R(lut.ptr(), (int)lut.step[0], lutTable, (int)lut.step[0], sz256); if (status < 0) { setIppErrorStatus(); @@ -2096,14 +2096,14 @@ public: if (lutcn == 3) { if (ippiLUTPalette_8u_C3R( - src.data, (int)src.step[0], dst.data, (int)dst.step[0], + src.ptr(), (int)src.step[0], dst.ptr(), (int)dst.step[0], ippiSize(dst.size()), lutTable, 8) >= 0) return; } else if (lutcn == 4) { if (ippiLUTPalette_8u_C4R( - src.data, (int)src.step[0], dst.data, (int)dst.step[0], + src.ptr(), (int)src.step[0], dst.ptr(), (int)dst.step[0], ippiSize(dst.size()), lutTable, 8) >= 0) return; } @@ -2153,7 +2153,7 @@ public: int len = (int)it.size; for( size_t i = 0; i < it.nplanes; i++, ++it ) - func(ptrs[0], lut_.data, ptrs[1], len, cn, lutcn); + func(ptrs[0], lut_.ptr(), ptrs[1], len, cn, lutcn); } private: LUTParallelBody(const LUTParallelBody&); @@ -2225,7 +2225,7 @@ void cv::LUT( InputArray _src, InputArray _lut, OutputArray _dst ) int len = (int)it.size; for( size_t i = 0; i < it.nplanes; i++, ++it ) - func(ptrs[0], lut.data, ptrs[1], len, cn, lutcn); + func(ptrs[0], lut.ptr(), ptrs[1], len, cn, lutcn); } namespace cv { diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 3003c8115..82b20005a 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -741,25 +741,25 @@ void flip( InputArray _src, OutputArray _dst, int flip_mode ) if (ippFunc != 0) { - if (ippFunc(src.data, (int)src.step, dst.data, (int)dst.step, ippiSize(src.cols, src.rows), axis) >= 0) + if (ippFunc(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), axis) >= 0) return; setIppErrorStatus(); } else if (ippFuncI != 0) { - if (ippFuncI(dst.data, (int)dst.step, roisize, axis) >= 0) + if (ippFuncI(dst.ptr(), (int)dst.step, roisize, axis) >= 0) return; setIppErrorStatus(); } #endif if( flip_mode <= 0 ) - flipVert( src.data, src.step, dst.data, dst.step, src.size(), esz ); + flipVert( src.ptr(), src.step, dst.ptr(), dst.step, src.size(), esz ); else - flipHoriz( src.data, src.step, dst.data, dst.step, src.size(), esz ); + flipHoriz( src.ptr(), src.step, dst.ptr(), dst.step, src.size(), esz ); if( flip_mode < 0 ) - flipHoriz( dst.data, dst.step, dst.data, dst.step, dst.size(), esz ); + flipHoriz( dst.ptr(), dst.step, dst.ptr(), dst.step, dst.size(), esz ); } #if defined HAVE_OPENCL && !defined __APPLE__ @@ -814,11 +814,11 @@ void repeat(InputArray _src, int ny, int nx, OutputArray _dst) for( y = 0; y < ssize.height; y++ ) { for( x = 0; x < dsize.width; x += ssize.width ) - memcpy( dst.data + y*dst.step + x, src.data + y*src.step, ssize.width ); + memcpy( dst.ptr(y) + x, src.ptr(y), ssize.width ); } for( ; y < dsize.height; y++ ) - memcpy( dst.data + y*dst.step, dst.data + (y - ssize.height)*dst.step, dsize.width ); + memcpy( dst.ptr(y), dst.ptr(y - ssize.height), dsize.width ); } Mat repeat(const Mat& src, int ny, int nx) @@ -1220,8 +1220,8 @@ void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom, #endif if( borderType != BORDER_CONSTANT ) - copyMakeBorder_8u( src.data, src.step, src.size(), - dst.data, dst.step, dst.size(), + copyMakeBorder_8u( src.ptr(), src.step, src.size(), + dst.ptr(), dst.step, dst.size(), top, left, (int)src.elemSize(), borderType ); else { @@ -1233,8 +1233,8 @@ void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom, cn1 = 1; } scalarToRawData(value, buf, CV_MAKETYPE(src.depth(), cn1), cn); - copyMakeConstBorder_8u( src.data, src.step, src.size(), - dst.data, dst.step, dst.size(), + copyMakeConstBorder_8u( src.ptr(), src.step, src.size(), + dst.ptr(), dst.step, dst.size(), top, left, (int)src.elemSize(), (uchar*)(double*)buf ); } } diff --git a/modules/core/src/datastructs.cpp b/modules/core/src/datastructs.cpp index ae2375ad6..dcc897945 100644 --- a/modules/core/src/datastructs.cpp +++ b/modules/core/src/datastructs.cpp @@ -3672,7 +3672,7 @@ void KDTree::build(InputArray __points, InputArray __labels, bool _copyData) { int nlabels = _labels.checkVector(1, CV_32S, true); CV_Assert(nlabels == n); - _labels_data = (const int*)_labels.data; + _labels_data = _labels.ptr(); } Mat sumstack(MAX_TREE_DEPTH*2, ptdims*2, CV_64F); @@ -3992,7 +3992,7 @@ void KDTree::getPoints(InputArray _idx, OutputArray _pts, OutputArray _labels) c int k = idx[i]; CV_Assert( (unsigned)k < (unsigned)points.rows ); const float* src = points.ptr(k); - if( pts.data ) + if( !pts.empty() ) std::copy(src, src + ptdims, pts.ptr(i)); if( dstlabels ) dstlabels[i] = srclabels ? srclabels[k] : k; diff --git a/modules/core/src/drawing.cpp b/modules/core/src/drawing.cpp index 0b11aea7e..7e917eff7 100644 --- a/modules/core/src/drawing.cpp +++ b/modules/core/src/drawing.cpp @@ -228,7 +228,7 @@ LineIterator::LineIterator(const Mat& img, Point pt1, Point pt2, count = dx + dy + 1; } - this->ptr0 = img.data; + this->ptr0 = img.ptr(); this->step = (int)img.step; this->elemSize = bt_pix0; } @@ -291,7 +291,7 @@ LineAA( Mat& img, Point pt1, Point pt2, const void* color ) int cb = ((uchar*)color)[0], cg = ((uchar*)color)[1], cr = ((uchar*)color)[2]; int _cb, _cg, _cr; int nch = img.channels(); - uchar* ptr = img.data; + uchar* ptr = img.ptr(); size_t step = img.step; Size size = img.size(); @@ -558,7 +558,7 @@ Line2( Mat& img, Point pt1, Point pt2, const void* color ) int cg = ((uchar*)color)[1]; int cr = ((uchar*)color)[2]; int pix_size = (int)img.elemSize(); - uchar *ptr = img.data, *tptr; + uchar *ptr = img.ptr(), *tptr; size_t step = img.step; Size size = img.size(), sizeScaled(size.width*XY_ONE, size.height*XY_ONE); @@ -961,7 +961,7 @@ FillConvexPoly( Mat& img, const Point* v, int npts, const void* color, int line_ int i, y, imin = 0, left = 0, right = 1, x1, x2; int edges = npts; int xmin, xmax, ymin, ymax; - uchar* ptr = img.data; + uchar* ptr = img.ptr(); Size size = img.size(); int pix_size = (int)img.elemSize(); Point p0; @@ -1251,7 +1251,7 @@ FillEdgeCollection( Mat& img, std::vector& edges, const void* color ) if( !clipline ) { // convert x's from fixed-point to image coordinates - uchar *timg = img.data + y * img.step; + uchar *timg = img.ptr(y); int x1 = keep_prelast->x; int x2 = prelast->x; @@ -1323,7 +1323,7 @@ Circle( Mat& img, Point center, int radius, const void* color, int fill ) Size size = img.size(); size_t step = img.step; int pix_size = (int)img.elemSize(); - uchar* ptr = img.data; + uchar* ptr = img.ptr(); int err = 0, dx = radius, dy = 0, plus = 1, minus = (radius << 1) - 1; int inside = center.x >= radius && center.x < size.width - radius && center.y >= radius && center.y < size.height - radius; @@ -2048,7 +2048,7 @@ void cv::fillConvexPoly(InputOutputArray _img, InputArray _points, { 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); + fillConvexPoly(img, points.ptr(), points.rows*points.cols*points.channels()/2, color, lineType, shift); } @@ -2068,7 +2068,7 @@ void cv::fillPoly(InputOutputArray _img, InputArrayOfArrays pts, { Mat p = pts.getMat(i); CV_Assert(p.checkVector(2, CV_32S) >= 0); - ptsptr[i] = (Point*)p.data; + ptsptr[i] = p.ptr(); npts[i] = p.rows*p.cols*p.channels()/2; } fillPoly(img, (const Point**)ptsptr, npts, (int)ncontours, color, lineType, shift, offset); @@ -2096,7 +2096,7 @@ void cv::polylines(InputOutputArray _img, InputArrayOfArrays pts, if( p.total() == 0 ) continue; CV_Assert(p.checkVector(2, CV_32S) >= 0); - ptsptr[i] = (Point*)p.data; + ptsptr[i] = p.ptr(); npts[i] = p.rows*p.cols*p.channels()/2; } polylines(img, (const Point**)ptsptr, npts, (int)ncontours, isClosed, color, thickness, lineType, shift); @@ -2116,7 +2116,7 @@ static void addChildContour(InputArrayOfArrays contours, { Mat ci = contours.getMat(i); cvMakeSeqHeaderForArray(CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point), - !ci.empty() ? (void*)ci.data : 0, (int)ci.total(), + !ci.empty() ? (void*)ci.ptr() : 0, (int)ci.total(), &seq[i], &block[i] ); int h_next = hierarchy[i][0], h_prev = hierarchy[i][1], @@ -2169,7 +2169,7 @@ void cv::drawContours( InputOutputArray _image, InputArrayOfArrays _contours, int npoints = ci.checkVector(2, CV_32S); CV_Assert( npoints > 0 ); cvMakeSeqHeaderForArray( CV_SEQ_POLYGON, sizeof(CvSeq), sizeof(Point), - ci.data, npoints, &seq[i], &block[i] ); + ci.ptr(), npoints, &seq[i], &block[i] ); } if( hierarchy.empty() || maxLevel == 0 ) diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index ed96a0b80..25eda3959 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -1547,7 +1547,7 @@ public: } for( int i = range.start; i < range.end; ++i) - if(!ippidft((Ipp32fc*)(src.data+i*src.step), (int)src.step,(Ipp32fc*)(dst.data+i*dst.step), (int)dst.step, pDFTSpec, (Ipp8u*)pBuffer)) + if(!ippidft(src.ptr(i), (int)src.step,dst.ptr(i), (int)dst.step, pDFTSpec, (Ipp8u*)pBuffer)) { *ok = false; } @@ -1718,9 +1718,9 @@ static bool ippi_DFT_C_32F(const Mat& src, Mat& dst, bool inv, int norm_flag) } if (!inv) - status = ippiDFTFwd_CToC_32fc_C1R( (Ipp32fc*)src.data, (int)src.step, (Ipp32fc*)dst.data, (int)dst.step, pDFTSpec, pBuffer ); + status = ippiDFTFwd_CToC_32fc_C1R( src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, pDFTSpec, pBuffer ); else - status = ippiDFTInv_CToC_32fc_C1R( (Ipp32fc*)src.data, (int)src.step, (Ipp32fc*)dst.data, (int)dst.step, pDFTSpec, pBuffer ); + status = ippiDFTInv_CToC_32fc_C1R( src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, pDFTSpec, pBuffer ); if ( sizeBuffer > 0 ) ippFree( pBuffer ); @@ -2661,8 +2661,8 @@ void cv::dft( InputArray _src0, OutputArray _dst, int flags, int nonzero_rows ) { int a = 0, b = count; uchar *buf0, *buf1, *dbuf0, *dbuf1; - const uchar* sptr0 = src.data; - uchar* dptr0 = dst.data; + const uchar* sptr0 = src.ptr(); + uchar* dptr0 = dst.ptr(); buf0 = ptr; ptr += len*complex_elem_size; buf1 = ptr; @@ -2911,9 +2911,9 @@ void cv::mulSpectrums( InputArray _srcA, InputArray _srcB, if( depth == CV_32F ) { - const float* dataA = (const float*)srcA.data; - const float* dataB = (const float*)srcB.data; - float* dataC = (float*)dst.data; + const float* dataA = srcA.ptr(); + const float* dataB = srcB.ptr(); + float* dataC = dst.ptr(); size_t stepA = srcA.step/sizeof(dataA[0]); size_t stepB = srcB.step/sizeof(dataB[0]); @@ -2978,9 +2978,9 @@ void cv::mulSpectrums( InputArray _srcA, InputArray _srcB, } else { - const double* dataA = (const double*)srcA.data; - const double* dataB = (const double*)srcB.data; - double* dataC = (double*)dst.data; + const double* dataA = srcA.ptr(); + const double* dataB = srcB.ptr(); + double* dataC = dst.ptr(); size_t stepA = srcA.step/sizeof(dataA[0]); size_t stepB = srcB.step/sizeof(dataB[0]); @@ -3299,7 +3299,7 @@ public: pBuffer = (uchar*)buf; for( int i = range.start; i < range.end; ++i) - if(!(*ippidct)((float*)(src->data+i*src->step), (int)src->step,(float*)(dst->data+i*dst->step), (int)dst->step, pDCTSpec, (Ipp8u*)pBuffer)) + if(!(*ippidct)(src->ptr(i), (int)src->step,dst->ptr(i), (int)dst->step, pDCTSpec, (Ipp8u*)pBuffer)) *ok = false; } else @@ -3368,7 +3368,7 @@ static bool ippi_DCT_32f(const Mat& src, Mat& dst, bool inv, bool row) buf.allocate( bufSize ); pBuffer = (uchar*)buf; - status = ippFunc((float*)src.data, (int)src.step, (float*)dst.data, (int)dst.step, pDCTSpec, (Ipp8u*)pBuffer); + status = ippFunc(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, pDCTSpec, (Ipp8u*)pBuffer); } if (pDCTSpec) @@ -3438,7 +3438,8 @@ void cv::dct( InputArray _src0, OutputArray _dst, int flags ) for( ; stage <= end_stage; stage++ ) { - uchar *sptr = src.data, *dptr = dst.data; + const uchar* sptr = src.ptr(); + uchar* dptr = dst.ptr(); size_t sstep0, sstep1, dstep0, dstep1; if( stage == 0 ) diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index 45881c3d5..6cfd5baa8 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -859,7 +859,7 @@ double cv::determinant( InputArray _mat ) double result = 0; int type = mat.type(), rows = mat.rows; size_t step = mat.step; - const uchar* m = mat.data; + const uchar* m = mat.ptr(); CV_Assert( !mat.empty() ); CV_Assert( mat.rows == mat.cols && (type == CV_32F || type == CV_64F)); @@ -882,11 +882,11 @@ double cv::determinant( InputArray _mat ) Mat a(rows, rows, CV_32F, (uchar*)buffer); mat.copyTo(a); - result = LU((float*)a.data, a.step, rows, 0, 0, 0); + result = LU(a.ptr(), a.step, rows, 0, 0, 0); if( result ) { for( int i = 0; i < rows; i++ ) - result *= ((const float*)(a.data + a.step*i))[i]; + result *= a.at(i,i); result = 1./result; } } @@ -906,11 +906,11 @@ double cv::determinant( InputArray _mat ) Mat a(rows, rows, CV_64F, (uchar*)buffer); mat.copyTo(a); - result = LU((double*)a.data, a.step, rows, 0, 0, 0); + result = LU(a.ptr(), a.step, rows, 0, 0, 0); if( result ) { for( int i = 0; i < rows; i++ ) - result *= ((const double*)(a.data + a.step*i))[i]; + result *= a.at(i,i); result = 1./result; } } @@ -949,8 +949,8 @@ double cv::invert( InputArray _src, OutputArray _dst, int method ) AutoBuffer _buf((m*nm + nm + nm*n)*esz + sizeof(double)); uchar* buf = alignPtr((uchar*)_buf, (int)esz); Mat u(m, nm, type, buf); - Mat w(nm, 1, type, u.data + m*nm*esz); - Mat vt(nm, n, type, w.data + nm*esz); + Mat w(nm, 1, type, u.ptr() + m*nm*esz); + Mat vt(nm, n, type, w.ptr() + nm*esz); SVD::compute(src, w, u, vt); SVD::backSubst(w, u, vt, Mat(), _dst); @@ -968,8 +968,8 @@ double cv::invert( InputArray _src, OutputArray _dst, int method ) AutoBuffer _buf((n*n*2 + n)*esz + sizeof(double)); uchar* buf = alignPtr((uchar*)_buf, (int)esz); Mat u(n, n, type, buf); - Mat w(n, 1, type, u.data + n*n*esz); - Mat vt(n, n, type, w.data + n*esz); + Mat w(n, 1, type, u.ptr() + n*n*esz); + Mat vt(n, n, type, w.ptr() + n*esz); eigen(src, w, vt); transpose(vt, u); @@ -988,8 +988,8 @@ double cv::invert( InputArray _src, OutputArray _dst, int method ) if( n <= 3 ) { - const uchar* srcdata = src.data; - uchar* dstdata = dst.data; + const uchar* srcdata = src.ptr(); + uchar* dstdata = dst.ptr(); size_t srcstep = src.step; size_t dststep = dst.step; @@ -1169,13 +1169,13 @@ double cv::invert( InputArray _src, OutputArray _dst, int method ) setIdentity(dst); if( method == DECOMP_LU && type == CV_32F ) - result = LU((float*)src1.data, src1.step, n, (float*)dst.data, dst.step, n) != 0; + result = LU(src1.ptr(), src1.step, n, dst.ptr(), dst.step, n) != 0; else if( method == DECOMP_LU && type == CV_64F ) - result = LU((double*)src1.data, src1.step, n, (double*)dst.data, dst.step, n) != 0; + result = LU(src1.ptr(), src1.step, n, dst.ptr(), dst.step, n) != 0; else if( method == DECOMP_CHOLESKY && type == CV_32F ) - result = Cholesky((float*)src1.data, src1.step, n, (float*)dst.data, dst.step, n); + result = Cholesky(src1.ptr(), src1.step, n, dst.ptr(), dst.step, n); else - result = Cholesky((double*)src1.data, src1.step, n, (double*)dst.data, dst.step, n); + result = Cholesky(src1.ptr(), src1.step, n, dst.ptr(), dst.step, n); if( !result ) dst = Scalar(0); @@ -1212,9 +1212,9 @@ bool cv::solve( InputArray _src, InputArray _src2arg, OutputArray _dst, int meth #define bf(y) ((float*)(bdata + y*src2step))[0] #define bd(y) ((double*)(bdata + y*src2step))[0] - const uchar* srcdata = src.data; - const uchar* bdata = _src2.data; - uchar* dstdata = dst.data; + const uchar* srcdata = src.ptr(); + const uchar* bdata = _src2.ptr(); + uchar* dstdata = dst.ptr(); size_t srcstep = src.step; size_t src2step = _src2.step; size_t dststep = dst.step; @@ -1709,23 +1709,23 @@ cvEigenVV( CvArr* srcarr, CvArr* evectsarr, CvArr* evalsarr, double, eigen(src, evals, evects); if( evects0.data != evects.data ) { - const uchar* p = evects0.data; + const uchar* p = evects0.ptr(); evects.convertTo(evects0, evects0.type()); - CV_Assert( p == evects0.data ); + CV_Assert( p == evects0.ptr() ); } } else eigen(src, evals); if( evals0.data != evals.data ) { - const uchar* p = evals0.data; + const uchar* p = evals0.ptr(); if( evals0.size() == evals.size() ) evals.convertTo(evals0, evals0.type()); else if( evals0.type() == evals.type() ) cv::transpose(evals, evals0); else cv::Mat(evals.t()).convertTo(evals0, evals0.type()); - CV_Assert( p == evals0.data ); + CV_Assert( p == evals0.ptr() ); } } @@ -1743,7 +1743,7 @@ cvSVD( CvArr* aarr, CvArr* warr, CvArr* uarr, CvArr* varr, int flags ) cv::SVD svd; if( w.size() == cv::Size(nm, 1) ) - svd.w = cv::Mat(nm, 1, type, w.data ); + svd.w = cv::Mat(nm, 1, type, w.ptr() ); else if( w.isContinuous() ) svd.w = w; @@ -1766,7 +1766,7 @@ cvSVD( CvArr* aarr, CvArr* warr, CvArr* uarr, CvArr* varr, int flags ) ((m != n && (svd.u.size() == cv::Size(mn, mn) || svd.vt.size() == cv::Size(mn, mn))) ? cv::SVD::FULL_UV : 0)); - if( u.data ) + if( !u.empty() ) { if( flags & CV_SVD_U_T ) cv::transpose( svd.u, u ); @@ -1777,7 +1777,7 @@ cvSVD( CvArr* aarr, CvArr* warr, CvArr* uarr, CvArr* varr, int flags ) } } - if( v.data ) + if( !v.empty() ) { if( !(flags & CV_SVD_V_T) ) cv::transpose( svd.vt, v ); diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 6c6ed6b1c..45161f9d5 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -786,7 +786,7 @@ void polarToCart( InputArray src1, InputArray src2, depth == CV_64F ? (ippsPolarToCart)ippsPolarToCart_64f : 0; CV_Assert(ippFunc != 0); - IppStatus status = ippFunc(Mag.data, Angle.data, X.data, Y.data, static_cast(cn * X.total())); + IppStatus status = ippFunc(Mag.ptr(), Angle.ptr(), X.ptr(), Y.ptr(), static_cast(cn * X.total())); if (status >= 0) return; setIppErrorStatus(); @@ -2220,7 +2220,7 @@ void pow( InputArray _src, double power, OutputArray _dst ) } size.width *= cn; - IppStatus status = ippiSqr_32f_C1R((const Ipp32f *)src.data, srcstep, (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height)); + IppStatus status = ippiSqr_32f_C1R(src.ptr(), srcstep, dst.ptr(), dststep, ippiSize(size.width, size.height)); if (status >= 0) return; @@ -2278,8 +2278,8 @@ void pow( InputArray _src, double power, OutputArray _dst ) if (src.isContinuous() && dst.isContinuous()) { IppStatus status = depth == CV_32F ? - ippsPowx_32f_A21((const Ipp32f *)src.data, (Ipp32f)power, (Ipp32f*)dst.data, (Ipp32s)(src.total() * cn)) : - ippsPowx_64f_A50((const Ipp64f *)src.data, power, (Ipp64f*)dst.data, (Ipp32s)(src.total() * cn)); + ippsPowx_32f_A21(src.ptr(), (Ipp32f)power, dst.ptr(), (Ipp32s)(src.total() * cn)) : + ippsPowx_64f_A50(src.ptr(), power, dst.ptr(), (Ipp32s)(src.total() * cn)); if (status >= 0) return; @@ -2451,7 +2451,7 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma { Cv32suf a, b; int ia, ib; - const int* isrc = (const int*)src.data; + const int* isrc = src.ptr(); size_t step = src.step/sizeof(isrc[0]); a.f = (float)std::max(minVal, (double)-FLT_MAX); @@ -2480,7 +2480,7 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma { Cv64suf a, b; int64 ia, ib; - const int64* isrc = (const int64*)src.data; + const int64* isrc = src.ptr(); size_t step = src.step/sizeof(isrc[0]); a.f = minVal; diff --git a/modules/core/src/matmul.cpp b/modules/core/src/matmul.cpp index 5f5e43896..c897774ab 100644 --- a/modules/core/src/matmul.cpp +++ b/modules/core/src/matmul.cpp @@ -822,7 +822,7 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, break; } - if( C.data ) + if( !C.empty() ) { CV_Assert( C.type() == type && (((flags&GEMM_3_T) == 0 && C.rows == d_size.height && C.cols == d_size.width) || @@ -841,9 +841,9 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, { if( type == CV_32F ) { - float* d = (float*)D.data; - const float *a = (const float*)A.data, - *b = (const float*)B.data, + float* d = D.ptr(); + const float *a = A.ptr(), + *b = B.ptr(), *c = (const float*)C.data; size_t d_step = D.step/sizeof(d[0]), a_step = A.step/sizeof(a[0]), @@ -969,9 +969,9 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, if( type == CV_64F ) { - double* d = (double*)D.data; - const double *a = (const double*)A.data, - *b = (const double*)B.data, + double* d = D.ptr(); + const double *a = A.ptr(), + *b = B.ptr(), *c = (const double*)C.data; size_t d_step = D.step/sizeof(d[0]), a_step = A.step/sizeof(a[0]), @@ -1211,8 +1211,8 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, (d_size.width <= block_lin_size && d_size.height <= block_lin_size && len <= block_lin_size) ) { - singleMulFunc( A.data, A.step, B.data, b_step, Cdata, Cstep, - matD->data, matD->step, a_size, d_size, alpha, beta, flags ); + singleMulFunc( A.ptr(), A.step, B.ptr(), b_step, Cdata, Cstep, + matD->ptr(), matD->step, a_size, d_size, alpha, beta, flags ); } else { @@ -1239,7 +1239,7 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, else b_step0 = elem_size, b_step1 = b_step; - if( !C.data ) + if( C.empty() ) { c_step0 = c_step1 = 0; flags &= ~GEMM_3_T; @@ -1285,7 +1285,7 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, for( j = 0; j < d_size.width; j += dj ) { - uchar* _d = matD->data + i*matD->step + j*elem_size; + uchar* _d = matD->ptr() + i*matD->step + j*elem_size; const uchar* _c = Cdata + i*c_step0 + j*c_step1; size_t _d_step = matD->step; dj = dn0; @@ -1302,9 +1302,9 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, for( k = 0; k < len; k += dk ) { - const uchar* _a = A.data + i*a_step0 + k*a_step1; + const uchar* _a = A.ptr() + i*a_step0 + k*a_step1; size_t _a_step = A.step; - const uchar* _b = B.data + k*b_step0 + j*b_step1; + const uchar* _b = B.ptr() + k*b_step0 + j*b_step1; size_t _b_step = b_step; Size a_bl_size; @@ -1349,7 +1349,7 @@ void cv::gemm( InputArray matA, InputArray matB, double alpha, if( dk0 < len ) storeFunc( _c, Cstep, _d, _d_step, - matD->data + i*matD->step + j*elem_size, + matD->ptr(i) + j*elem_size, matD->step, Size(dj,di), alpha, beta, flags ); } } @@ -1858,7 +1858,7 @@ void cv::transform( InputArray _src, OutputArray _dst, InputArray _mtx ) _mbuf.allocate(dcn*(scn+1)); mbuf = (double*)_mbuf; Mat tmp(dcn, scn+1, mtype, mbuf); - memset(tmp.data, 0, tmp.total()*tmp.elemSize()); + memset(tmp.ptr(), 0, tmp.total()*tmp.elemSize()); if( m.cols == scn+1 ) m.convertTo(tmp, mtype); else @@ -1869,7 +1869,7 @@ void cv::transform( InputArray _src, OutputArray _dst, InputArray _mtx ) m = tmp; } else - mbuf = (double*)m.data; + mbuf = m.ptr(); if( scn == dcn ) { @@ -2039,7 +2039,7 @@ void cv::perspectiveTransform( InputArray _src, OutputArray _dst, InputArray _mt m = tmp; } else - mbuf = (double*)m.data; + mbuf = m.ptr(); TransformFunc func = depth == CV_32F ? (TransformFunc)perspectiveTransform_32f : @@ -2227,7 +2227,7 @@ void cv::scaleAdd( InputArray _src1, double alpha, InputArray _src2, OutputArray if (src1.isContinuous() && src2.isContinuous() && dst.isContinuous()) { size_t len = src1.total()*cn; - func(src1.data, src2.data, dst.data, (int)len, palpha); + func(src1.ptr(), src2.ptr(), dst.ptr(), (int)len, palpha); return; } @@ -2271,7 +2271,7 @@ void cv::calcCovarMatrix( const Mat* data, int nsamples, Mat& covar, Mat& _mean, { CV_Assert( data[i].size() == size && data[i].type() == type ); if( data[i].isContinuous() ) - memcpy( _data.ptr(i), data[i].data, sz*esz ); + memcpy( _data.ptr(i), data[i].ptr(), sz*esz ); else { Mat dataRow(size.height, size.width, type, _data.ptr(i)); @@ -2392,12 +2392,12 @@ double cv::Mahalanobis( InputArray _v1, InputArray _v2, InputArray _icovar ) if( depth == CV_32F ) { - const float* src1 = (const float*)v1.data; - const float* src2 = (const float*)v2.data; + const float* src1 = v1.ptr(); + const float* src2 = v2.ptr(); size_t step1 = v1.step/sizeof(src1[0]); size_t step2 = v2.step/sizeof(src2[0]); double* diff = buf; - const float* mat = (const float*)icovar.data; + const float* mat = icovar.ptr(); size_t matstep = icovar.step/sizeof(mat[0]); for( ; sz.height--; src1 += step1, src2 += step2, diff += sz.width ) @@ -2423,12 +2423,12 @@ double cv::Mahalanobis( InputArray _v1, InputArray _v2, InputArray _icovar ) } else if( depth == CV_64F ) { - const double* src1 = (const double*)v1.data; - const double* src2 = (const double*)v2.data; + const double* src1 = v1.ptr(); + const double* src2 = v2.ptr(); size_t step1 = v1.step/sizeof(src1[0]); size_t step2 = v2.step/sizeof(src2[0]); double* diff = buf; - const double* mat = (const double*)icovar.data; + const double* mat = icovar.ptr(); size_t matstep = icovar.step/sizeof(mat[0]); for( ; sz.height--; src1 += step1, src2 += step2, diff += sz.width ) @@ -2469,9 +2469,9 @@ template static void MulTransposedR( const Mat& srcmat, Mat& dstmat, const Mat& deltamat, double scale ) { int i, j, k; - const sT* src = (const sT*)srcmat.data; - dT* dst = (dT*)dstmat.data; - const dT* delta = (const dT*)deltamat.data; + const sT* src = srcmat.ptr(); + dT* dst = dstmat.ptr
(); + const dT* delta = deltamat.ptr
(); size_t srcstep = srcmat.step/sizeof(src[0]); size_t dststep = dstmat.step/sizeof(dst[0]); size_t deltastep = deltamat.rows > 1 ? deltamat.step/sizeof(delta[0]) : 0; @@ -2588,9 +2588,9 @@ template static void MulTransposedL( const Mat& srcmat, Mat& dstmat, const Mat& deltamat, double scale ) { int i, j, k; - const sT* src = (const sT*)srcmat.data; - dT* dst = (dT*)dstmat.data; - const dT* delta = (const dT*)deltamat.data; + const sT* src = srcmat.ptr(); + dT* dst = dstmat.ptr
(); + const dT* delta = deltamat.ptr
(); size_t srcstep = srcmat.step/sizeof(src[0]); size_t dststep = dstmat.step/sizeof(dst[0]); size_t deltastep = deltamat.rows > 1 ? deltamat.step/sizeof(delta[0]) : 0; @@ -2669,7 +2669,7 @@ void cv::mulTransposed( InputArray _src, OutputArray _dst, bool ata, dtype = std::max(std::max(CV_MAT_DEPTH(dtype >= 0 ? dtype : stype), delta.depth()), CV_32F); CV_Assert( src.channels() == 1 ); - if( delta.data ) + if( !delta.empty() ) { CV_Assert( delta.channels() == 1 && (delta.rows == src.rows || delta.rows == 1) && @@ -2688,7 +2688,7 @@ void cv::mulTransposed( InputArray _src, OutputArray _dst, bool ata, { Mat src2; const Mat* tsrc = &src; - if( delta.data ) + if( !delta.empty() ) { if( delta.size() == src.size() ) subtract( src, delta, src2 ); @@ -3012,7 +3012,7 @@ PCA& PCA::operator()(InputArray _data, InputArray __mean, int flags, int maxComp Mat covar( count, count, ctype ); - if( _mean.data ) + if( !_mean.empty() ) { CV_Assert( _mean.size() == mean_sz ); _mean.convertTo(mean, ctype); @@ -3148,7 +3148,7 @@ PCA& PCA::operator()(InputArray _data, InputArray __mean, int flags, double reta Mat covar( count, count, ctype ); - if( _mean.data ) + if( !_mean.empty() ) { CV_Assert( _mean.size() == mean_sz ); _mean.convertTo(mean, ctype); @@ -3203,7 +3203,7 @@ PCA& PCA::operator()(InputArray _data, InputArray __mean, int flags, double reta void PCA::project(InputArray _data, OutputArray result) const { Mat data = _data.getMat(); - CV_Assert( mean.data && eigenvectors.data && + CV_Assert( !mean.empty() && !eigenvectors.empty() && ((mean.rows == 1 && mean.cols == data.cols) || (mean.cols == 1 && mean.rows == data.rows))); Mat tmp_data, tmp_mean = repeat(mean, data.rows/mean.rows, data.cols/mean.cols); int ctype = mean.type(); @@ -3233,7 +3233,7 @@ Mat PCA::project(InputArray data) const void PCA::backProject(InputArray _data, OutputArray result) const { Mat data = _data.getMat(); - CV_Assert( mean.data && eigenvectors.data && + CV_Assert( !mean.empty() && !eigenvectors.empty() && ((mean.rows == 1 && eigenvectors.rows == data.cols) || (mean.cols == 1 && eigenvectors.rows == data.rows))); @@ -3427,7 +3427,7 @@ cvCalcPCA( const CvArr* data_arr, CvArr* avg_arr, CvArr* eigenvals, CvArr* eigen pca.eigenvectors = evects; pca(data, (flags & CV_PCA_USE_AVG) ? mean : cv::Mat(), - flags, evals.data ? evals.rows + evals.cols - 1 : 0); + flags, !evals.empty() ? evals.rows + evals.cols - 1 : 0); if( pca.mean.size() == mean.size() ) pca.mean.convertTo( mean, mean.type() ); diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 392b6ad2e..b29dee8b7 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -352,7 +352,7 @@ static void finalizeHdr(Mat& m) m.datalimit = m.datastart + m.size[0]*m.step[0]; if( m.size[0] > 0 ) { - m.dataend = m.data + m.size[d-1]*m.step[d-1]; + m.dataend = m.ptr() + m.size[d-1]*m.step[d-1]; for( int i = 0; i < d-1; i++ ) m.dataend += (m.size[i] - 1)*m.step[i]; } @@ -871,7 +871,7 @@ Mat cvarrToMat(const CvArr* arr, bool copyData, } Mat buf(total, 1, type); - cvCvtSeqToArray(seq, buf.data, CV_WHOLE_SEQ); + cvCvtSeqToArray(seq, buf.ptr(), CV_WHOLE_SEQ); return buf; } CV_Error(CV_StsBadArg, "Unknown array type"); @@ -1941,7 +1941,7 @@ size_t _InputArray::offset(int i) const { CV_Assert( i < 0 ); const Mat * const m = ((const Mat*)obj); - return (size_t)(m->data - m->datastart); + return (size_t)(m->ptr() - m->datastart); } if( k == UMAT ) @@ -1960,7 +1960,7 @@ size_t _InputArray::offset(int i) const return 1; CV_Assert( i < (int)vv.size() ); - return (size_t)(vv[i].data - vv[i].datastart); + return (size_t)(vv[i].ptr() - vv[i].datastart); } if( k == STD_VECTOR_UMAT ) @@ -2618,7 +2618,7 @@ void _OutputArray::setTo(const _InputArray& arr, const _InputArray & mask) const { Mat value = arr.getMat(); CV_Assert( checkScalar(value, type(), arr.kind(), _InputArray::GPU_MAT) ); - ((cuda::GpuMat*)obj)->setTo(Scalar(Vec((double *)value.data)), mask); + ((cuda::GpuMat*)obj)->setTo(Scalar(Vec(value.ptr())), mask); } else CV_Error(Error::StsNotImplemented, ""); @@ -2804,7 +2804,7 @@ void cv::setIdentity( InputOutputArray _m, const Scalar& s ) if( type == CV_32FC1 ) { - float* data = (float*)m.data; + float* data = m.ptr(); float val = (float)s[0]; size_t step = m.step/sizeof(data[0]); @@ -2818,7 +2818,7 @@ void cv::setIdentity( InputOutputArray _m, const Scalar& s ) } else if( type == CV_64FC1 ) { - double* data = (double*)m.data; + double* data = m.ptr(); double val = s[0]; size_t step = m.step/sizeof(data[0]); @@ -2846,7 +2846,7 @@ cv::Scalar cv::trace( InputArray _m ) if( type == CV_32FC1 ) { - const float* ptr = (const float*)m.data; + const float* ptr = m.ptr(); size_t step = m.step/sizeof(ptr[0]) + 1; double _s = 0; for( i = 0; i < nm; i++ ) @@ -2856,7 +2856,7 @@ cv::Scalar cv::trace( InputArray _m ) if( type == CV_64FC1 ) { - const double* ptr = (const double*)m.data; + const double* ptr = m.ptr(); size_t step = m.step/sizeof(ptr[0]) + 1; double _s = 0; for( i = 0; i < nm; i++ ) @@ -3115,13 +3115,13 @@ void cv::transpose( InputArray _src, OutputArray _dst ) IppiSize roiSize = { src.cols, src.rows }; if (ippFunc != 0) { - if (ippFunc(src.data, (int)src.step, dst.data, (int)dst.step, roiSize) >= 0) + if (ippFunc(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, roiSize) >= 0) return; setIppErrorStatus(); } else if (ippFuncI != 0) { - if (ippFuncI(dst.data, (int)dst.step, roiSize) >= 0) + if (ippFuncI(dst.ptr(), (int)dst.step, roiSize) >= 0) return; setIppErrorStatus(); } @@ -3132,13 +3132,13 @@ void cv::transpose( InputArray _src, OutputArray _dst ) TransposeInplaceFunc func = transposeInplaceTab[esz]; CV_Assert( func != 0 ); CV_Assert( dst.cols == dst.rows ); - func( dst.data, dst.step, dst.rows ); + func( dst.ptr(), dst.step, dst.rows ); } else { TransposeFunc func = transposeTab[esz]; CV_Assert( func != 0 ); - func( src.data, src.step, dst.data, dst.step, src.size() ); + func( src.ptr(), src.step, dst.ptr(), dst.step, src.size() ); } } @@ -3154,7 +3154,7 @@ void cv::completeSymm( InputOutputArray _m, bool LtoR ) int rows = m.rows; int j0 = 0, j1 = rows; - uchar* data = m.data; + uchar* data = m.ptr(); for( int i = 0; i < rows; i++ ) { if( !LtoR ) j1 = i; else j0 = i+1; @@ -3212,8 +3212,8 @@ reduceR_( const Mat& srcmat, Mat& dstmat ) size.width *= srcmat.channels(); AutoBuffer buffer(size.width); WT* buf = buffer; - ST* dst = (ST*)dstmat.data; - const T* src = (const T*)srcmat.data; + ST* dst = dstmat.ptr(); + const T* src = srcmat.ptr(); size_t srcstep = srcmat.step/sizeof(src[0]); int i; Op op; @@ -3258,8 +3258,8 @@ reduceC_( const Mat& srcmat, Mat& dstmat ) for( int y = 0; y < size.height; y++ ) { - const T* src = (const T*)(srcmat.data + srcmat.step*y); - ST* dst = (ST*)(dstmat.data + dstmat.step*y); + const T* src = srcmat.ptr(y); + ST* dst = dstmat.ptr(y); if( size.width == cn ) for( k = 0; k < cn; k++ ) dst[k] = src[k]; @@ -3356,7 +3356,7 @@ static inline void reduceSumC_8u16u16s32f_64f(const cv::Mat& srcmat, cv::Mat& ds if (ippFunc) { for (int y = 0; y < size.height; ++y) - if (ippFunc(srcmat.data + sstep * y, sstep, roisize, dstmat.ptr(y)) < 0) + if (ippFunc(srcmat.ptr(y), sstep, roisize, dstmat.ptr(y)) < 0) { setIppErrorStatus(); cv::Mat dstroi = dstmat.rowRange(y, y + 1); @@ -3367,7 +3367,7 @@ static inline void reduceSumC_8u16u16s32f_64f(const cv::Mat& srcmat, cv::Mat& ds else if (ippFuncHint) { for (int y = 0; y < size.height; ++y) - if (ippFuncHint(srcmat.data + sstep * y, sstep, roisize, dstmat.ptr(y), ippAlgHintAccurate) < 0) + if (ippFuncHint(srcmat.ptr(y), sstep, roisize, dstmat.ptr(y), ippAlgHintAccurate) < 0) { setIppErrorStatus(); cv::Mat dstroi = dstmat.rowRange(y, y + 1); @@ -3780,10 +3780,10 @@ template static void sort_( const Mat& src, Mat& dst, int flags ) T* ptr = bptr; if( sortRows ) { - T* dptr = (T*)(dst.data + dst.step*i); + T* dptr = dst.ptr(i); if( !inplace ) { - const T* sptr = (const T*)(src.data + src.step*i); + const T* sptr = src.ptr(i); memcpy(dptr, sptr, sizeof(T) * len); } ptr = dptr; @@ -3791,7 +3791,7 @@ template static void sort_( const Mat& src, Mat& dst, int flags ) else { for( j = 0; j < len; j++ ) - ptr[j] = ((const T*)(src.data + src.step*j))[i]; + ptr[j] = src.ptr(j)[i]; } #ifdef USE_IPP_SORT @@ -3820,7 +3820,7 @@ template static void sort_( const Mat& src, Mat& dst, int flags ) if( !sortRows ) for( j = 0; j < len; j++ ) - ((T*)(dst.data + dst.step*j))[i] = ptr[j]; + dst.ptr(j)[i] = ptr[j]; } } @@ -3893,12 +3893,12 @@ template static void sortIdx_( const Mat& src, Mat& dst, int flags ) if( sortRows ) { ptr = (T*)(src.data + src.step*i); - iptr = (int*)(dst.data + dst.step*i); + iptr = dst.ptr(i); } else { for( j = 0; j < len; j++ ) - ptr[j] = ((const T*)(src.data + src.step*j))[i]; + ptr[j] = src.ptr(j)[i]; } for( j = 0; j < len; j++ ) iptr[j] = j; @@ -3928,7 +3928,7 @@ template static void sortIdx_( const Mat& src, Mat& dst, int flags ) if( !sortRows ) for( j = 0; j < len; j++ ) - ((int*)(dst.data + dst.step*j))[i] = iptr[j]; + dst.ptr(j)[i] = iptr[j]; } } @@ -4159,7 +4159,7 @@ double cv::kmeans( InputArray _data, int K, CV_Assert( data0.dims <= 2 && type == CV_32F && K > 0 ); CV_Assert( N >= K ); - Mat data(N, dims, CV_32F, data0.data, isrow ? dims * sizeof(float) : static_cast(data0.step)); + Mat data(N, dims, CV_32F, data0.ptr(), isrow ? dims * sizeof(float) : static_cast(data0.step)); _bestLabels.create(N, 1, CV_32S, -1, true); @@ -4765,7 +4765,7 @@ Point MatConstIterator::pos() const return Point(); CV_DbgAssert(m->dims <= 2); - ptrdiff_t ofs = ptr - m->data; + ptrdiff_t ofs = ptr - m->ptr(); int y = (int)(ofs/m->step[0]); return Point((int)((ofs - y*m->step[0])/elemSize), y); } @@ -4773,7 +4773,7 @@ Point MatConstIterator::pos() const void MatConstIterator::pos(int* _idx) const { CV_Assert(m != 0 && _idx); - ptrdiff_t ofs = ptr - m->data; + ptrdiff_t ofs = ptr - m->ptr(); for( int i = 0; i < m->dims; i++ ) { size_t s = m->step[i], v = ofs/s; @@ -4788,7 +4788,7 @@ ptrdiff_t MatConstIterator::lpos() const return 0; if( m->isContinuous() ) return (ptr - sliceStart)/elemSize; - ptrdiff_t ofs = ptr - m->data; + ptrdiff_t ofs = ptr - m->ptr(); int i, d = m->dims; if( d == 2 ) { @@ -4823,13 +4823,13 @@ void MatConstIterator::seek(ptrdiff_t ofs, bool relative) ptrdiff_t ofs0, y; if( relative ) { - ofs0 = ptr - m->data; + ofs0 = ptr - m->ptr(); y = ofs0/m->step[0]; ofs += y*m->cols + (ofs0 - y*m->step[0])/elemSize; } y = ofs/m->cols; int y1 = std::min(std::max((int)y, 0), m->rows-1); - sliceStart = m->data + y1*m->step[0]; + sliceStart = m->ptr(y1); sliceEnd = sliceStart + m->cols*elemSize; ptr = y < 0 ? sliceStart : y >= m->rows ? sliceEnd : sliceStart + (ofs - y*m->cols)*elemSize; @@ -4846,8 +4846,8 @@ void MatConstIterator::seek(ptrdiff_t ofs, bool relative) ptrdiff_t t = ofs/szi; int v = (int)(ofs - t*szi); ofs = t; - ptr = m->data + v*elemSize; - sliceStart = m->data; + ptr = m->ptr() + v*elemSize; + sliceStart = m->ptr(); for( int i = d-2; i >= 0; i-- ) { @@ -4862,7 +4862,7 @@ void MatConstIterator::seek(ptrdiff_t ofs, bool relative) if( ofs > 0 ) ptr = sliceEnd; else - ptr = sliceStart + (ptr - m->data); + ptr = sliceStart + (ptr - m->ptr()); } void MatConstIterator::seek(const int* _idx, bool relative) @@ -5058,7 +5058,7 @@ SparseMat::SparseMat(const Mat& m) int i, idx[CV_MAX_DIM] = {0}, d = m.dims, lastSize = m.size[d - 1]; size_t esz = m.elemSize(); - uchar* dptr = m.data; + const uchar* dptr = m.ptr(); for(;;) { diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 837d16ee8..bc83bf859 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -2750,7 +2750,7 @@ KernelArg::KernelArg(int _flags, UMat* _m, int _wscale, int _iwscale, const void KernelArg KernelArg::Constant(const Mat& m) { CV_Assert(m.isContinuous()); - return KernelArg(CONSTANT, 0, 0, 0, m.data, m.total()*m.elemSize()); + return KernelArg(CONSTANT, 0, 0, 0, m.ptr(), m.total()*m.elemSize()); } /////////////////////////////////////////// Kernel ///////////////////////////////////////////// @@ -4397,7 +4397,7 @@ template static std::string kerToStr(const Mat & k) { int width = k.cols - 1, depth = k.depth(); - const T * const data = reinterpret_cast(k.data); + const T * const data = k.ptr(); std::ostringstream stream; stream.precision(10); diff --git a/modules/core/src/rand.cpp b/modules/core/src/rand.cpp index 727bbfce5..1b71900ba 100644 --- a/modules/core/src/rand.cpp +++ b/modules/core/src/rand.cpp @@ -511,8 +511,8 @@ void RNG::fill( InputOutputArray _mat, int disttype, { _parambuf.allocate(cn*8 + n1 + n2); double* parambuf = _parambuf; - double* p1 = (double*)_param1.data; - double* p2 = (double*)_param2.data; + double* p1 = _param1.ptr(); + double* p2 = _param2.ptr(); if( !_param1.isContinuous() || _param1.type() != CV_64F || n1 != cn ) { @@ -625,7 +625,7 @@ void RNG::fill( InputOutputArray _mat, int disttype, int esz = (int)CV_ELEM_SIZE(ptype); if( _param1.isContinuous() && _param1.type() == ptype ) - mean = _param1.data; + mean = _param1.ptr(); else { Mat tmp(_param1.size(), ptype, parambuf); @@ -638,7 +638,7 @@ void RNG::fill( InputOutputArray _mat, int disttype, mean[j] = mean[j - n1*esz]; if( _param2.isContinuous() && _param2.type() == ptype ) - stddev = _param2.data; + stddev = _param2.ptr(); else { Mat tmp(_param2.size(), ptype, parambuf + cn); @@ -753,7 +753,7 @@ randShuffle_( Mat& _arr, RNG& rng, double iterFactor ) int sz = _arr.rows*_arr.cols, iters = cvRound(iterFactor*sz); if( _arr.isContinuous() ) { - T* arr = (T*)_arr.data; + T* arr = _arr.ptr(); for( int i = 0; i < iters; i++ ) { int j = (unsigned)rng % sz, k = (unsigned)rng % sz; @@ -762,7 +762,7 @@ randShuffle_( Mat& _arr, RNG& rng, double iterFactor ) } else { - uchar* data = _arr.data; + uchar* data = _arr.ptr(); size_t step = _arr.step; int cols = _arr.cols; for( int i = 0; i < iters; i++ ) diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index e42f8224f..4af8841d2 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -605,8 +605,8 @@ cv::Scalar cv::sum( InputArray _src ) if( ippFuncHint || ippFuncNoHint ) { Ipp64f res[4]; - IppStatus ret = ippFuncHint ? ippFuncHint(src.data, (int)src.step[0], sz, res, ippAlgHintAccurate) : - ippFuncNoHint(src.data, (int)src.step[0], sz, res); + IppStatus ret = ippFuncHint ? ippFuncHint(src.ptr(), (int)src.step[0], sz, res, ippAlgHintAccurate) : + ippFuncNoHint(src.ptr(), (int)src.step[0], sz, res); if( ret >= 0 ) { Scalar sc; @@ -791,7 +791,7 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask ) if( ippFuncC1 ) { Ipp64f res; - if( ippFuncC1(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, &res) >= 0 ) + if( ippFuncC1(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, &res) >= 0 ) return Scalar(res); setIppErrorStatus(); } @@ -804,9 +804,9 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask ) if( ippFuncC3 ) { Ipp64f res1, res2, res3; - if( ippFuncC3(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, 1, &res1) >= 0 && - ippFuncC3(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, 2, &res2) >= 0 && - ippFuncC3(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, 3, &res3) >= 0 ) + if( ippFuncC3(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, 1, &res1) >= 0 && + ippFuncC3(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, 2, &res2) >= 0 && + ippFuncC3(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, 3, &res3) >= 0 ) { return Scalar(res1, res2, res3); } @@ -838,8 +838,8 @@ cv::Scalar cv::mean( InputArray _src, InputArray _mask ) if( ippFuncHint || ippFuncNoHint ) { Ipp64f res[4]; - IppStatus ret = ippFuncHint ? ippFuncHint(src.data, (int)src.step[0], sz, res, ippAlgHintAccurate) : - ippFuncNoHint(src.data, (int)src.step[0], sz, res); + IppStatus ret = ippFuncHint ? ippFuncHint(src.ptr(), (int)src.step[0], sz, res, ippAlgHintAccurate) : + ippFuncNoHint(src.ptr(), (int)src.step[0], sz, res); if( ret >= 0 ) { Scalar sc; @@ -981,11 +981,11 @@ static bool ocl_meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv part_sum funcs[3] = { ocl_part_sum, ocl_part_sum, ocl_part_sum }; Mat dbm = db.getMat(ACCESS_READ); - mean = funcs[ddepth - CV_32S](Mat(1, groups, dtype, dbm.data)); - stddev = funcs[sqddepth - CV_32S](Mat(1, groups, sqdtype, dbm.data + groups * CV_ELEM_SIZE(dtype))); + mean = funcs[ddepth - CV_32S](Mat(1, groups, dtype, dbm.ptr())); + stddev = funcs[sqddepth - CV_32S](Mat(1, groups, sqdtype, dbm.ptr() + groups * CV_ELEM_SIZE(dtype))); if (haveMask) - nz = saturate_cast(funcs[0](Mat(1, groups, CV_32SC1, dbm.data + + nz = saturate_cast(funcs[0](Mat(1, groups, CV_32SC1, dbm.ptr() + groups * (CV_ELEM_SIZE(dtype) + CV_ELEM_SIZE(sqdtype))))[0]); } @@ -1052,7 +1052,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input _mean.create(cn, 1, CV_64F, -1, true); mean = _mean.getMat(); dcn_mean = (int)mean.total(); - pmean = (Ipp64f *)mean.data; + pmean = mean.ptr(); } int dcn_stddev = -1; if( _sdv.needed() ) @@ -1061,7 +1061,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input _sdv.create(cn, 1, CV_64F, -1, true); stddev = _sdv.getMat(); dcn_stddev = (int)stddev.total(); - pstddev = (Ipp64f *)stddev.data; + pstddev = stddev.ptr(); } for( int c = cn; c < dcn_mean; c++ ) pmean[c] = 0; @@ -1079,7 +1079,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input 0; if( ippFuncC1 ) { - if( ippFuncC1(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, pmean, pstddev) >= 0 ) + if( ippFuncC1(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, pmean, pstddev) >= 0 ) return; setIppErrorStatus(); } @@ -1091,9 +1091,9 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input 0; if( ippFuncC3 ) { - if( ippFuncC3(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, 1, &pmean[0], &pstddev[0]) >= 0 && - ippFuncC3(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, 2, &pmean[1], &pstddev[1]) >= 0 && - ippFuncC3(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, 3, &pmean[2], &pstddev[2]) >= 0 ) + if( ippFuncC3(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, 1, &pmean[0], &pstddev[0]) >= 0 && + ippFuncC3(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, 2, &pmean[1], &pstddev[1]) >= 0 && + ippFuncC3(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, 3, &pmean[2], &pstddev[2]) >= 0 ) return; setIppErrorStatus(); } @@ -1110,7 +1110,7 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input 0; if( ippFuncC1 ) { - if( ippFuncC1(src.data, (int)src.step[0], sz, pmean, pstddev) >= 0 ) + if( ippFuncC1(src.ptr(), (int)src.step[0], sz, pmean, pstddev) >= 0 ) return; setIppErrorStatus(); } @@ -1122,9 +1122,9 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input 0; if( ippFuncC3 ) { - if( ippFuncC3(src.data, (int)src.step[0], sz, 1, &pmean[0], &pstddev[0]) >= 0 && - ippFuncC3(src.data, (int)src.step[0], sz, 2, &pmean[1], &pstddev[1]) >= 0 && - ippFuncC3(src.data, (int)src.step[0], sz, 3, &pmean[2], &pstddev[2]) >= 0 ) + if( ippFuncC3(src.ptr(), (int)src.step[0], sz, 1, &pmean[0], &pstddev[0]) >= 0 && + ippFuncC3(src.ptr(), (int)src.step[0], sz, 2, &pmean[1], &pstddev[1]) >= 0 && + ippFuncC3(src.ptr(), (int)src.step[0], sz, 3, &pmean[2], &pstddev[2]) >= 0 ) return; setIppErrorStatus(); } @@ -1358,26 +1358,26 @@ void getMinMaxRes(const Mat & db, double * minVal, double * maxVal, const uint * minlocptr = NULL, * maxlocptr = NULL; if (minVal || minLoc) { - minptr = (const T *)db.data; + minptr = db.ptr(); index += sizeof(T) * groupnum; } if (maxVal || maxLoc) { - maxptr = (const T *)(db.data + index); + maxptr = (const T *)(db.ptr() + index); index += sizeof(T) * groupnum; } if (minLoc) { - minlocptr = (uint *)(db.data + index); + minlocptr = (const uint *)(db.ptr() + index); index += sizeof(uint) * groupnum; } if (maxLoc) { - maxlocptr = (uint *)(db.data + index); + maxlocptr = (const uint *)(db.ptr() + index); index += sizeof(uint) * groupnum; } if (maxVal2) - maxptr2 = (const T *)(db.data + index); + maxptr2 = (const T *)(db.ptr() + index); for (int i = 0; i < groupnum; i++) { @@ -1602,13 +1602,13 @@ void cv::minMaxIdx(InputArray _src, double* minVal, { Ipp32f min, max; IppiPoint minp, maxp; - if( ippFuncC1(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, &min, &max, &minp, &maxp) >= 0 ) + if( ippFuncC1(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, &min, &max, &minp, &maxp) >= 0 ) { if( minVal ) *minVal = (double)min; if( maxVal ) *maxVal = (double)max; - if( !minp.x && !minp.y && !maxp.x && !maxp.y && !mask.data[0] ) + if( !minp.x && !minp.y && !maxp.x && !maxp.y && !mask.ptr()[0] ) minp.x = maxp.x = -1; if( minIdx ) { @@ -1641,7 +1641,7 @@ void cv::minMaxIdx(InputArray _src, double* minVal, { Ipp32f min, max; IppiPoint minp, maxp; - if( ippFuncC1(src.data, (int)src.step[0], sz, &min, &max, &minp, &maxp) >= 0 ) + if( ippFuncC1(src.ptr(), (int)src.step[0], sz, &min, &max, &minp, &maxp) >= 0 ) { if( minVal ) *minVal = (double)min; @@ -2280,7 +2280,7 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) if( ippFuncC1 ) { Ipp64f norm; - if( ippFuncC1(src.data, (int)src.step[0], mask.data, (int)mask.step[0], sz, &norm) >= 0 ) + if( ippFuncC1(src.ptr(), (int)src.step[0], mask.ptr(), (int)mask.step[0], sz, &norm) >= 0 ) return normType == NORM_L2SQR ? (double)(norm * norm) : (double)norm; setIppErrorStatus(); @@ -2381,8 +2381,8 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) if( ippFuncHint || ippFuncNoHint ) { Ipp64f norm_array[4]; - IppStatus ret = ippFuncHint ? ippFuncHint(src.data, (int)src.step[0], sz, norm_array, ippAlgHintAccurate) : - ippFuncNoHint(src.data, (int)src.step[0], sz, norm_array); + IppStatus ret = ippFuncHint ? ippFuncHint(src.ptr(), (int)src.step[0], sz, norm_array, ippAlgHintAccurate) : + ippFuncNoHint(src.ptr(), (int)src.step[0], sz, norm_array); if( ret >= 0 ) { Ipp64f norm = (normType == NORM_L2 || normType == NORM_L2SQR) ? norm_array[0] * norm_array[0] : norm_array[0]; @@ -2643,7 +2643,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m if( ippFuncC1 ) { Ipp64f norm; - if( ippFuncC1(src1.data, (int)src1.step[0], src2.data, (int)src2.step[0], mask.data, (int)mask.step[0], sz, &norm) >= 0 ) + if( ippFuncC1(src1.ptr(), (int)src1.step[0], src2.ptr(), (int)src2.step[0], mask.ptr(), (int)mask.step[0], sz, &norm) >= 0 ) return normType == NORM_L2SQR ? (double)(norm * norm) : (double)norm; setIppErrorStatus(); } @@ -2679,14 +2679,14 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m if (ippFuncNoHint) { Ipp64f norm; - if( ippFuncNoHint(src1.data, (int)src1.step[0], src2.data, (int)src2.step[0], sz, &norm) >= 0 ) + if( ippFuncNoHint(src1.ptr(), (int)src1.step[0], src2.ptr(), (int)src2.step[0], sz, &norm) >= 0 ) return (double)norm; setIppErrorStatus(); } if (ippFuncHint) { Ipp64f norm; - if( ippFuncHint(src1.data, (int)src1.step[0], src2.data, (int)src2.step[0], sz, &norm, ippAlgHintAccurate) >= 0 ) + if( ippFuncHint(src1.ptr(), (int)src1.step[0], src2.ptr(), (int)src2.step[0], sz, &norm, ippAlgHintAccurate) >= 0 ) return (double)norm; setIppErrorStatus(); } @@ -2739,7 +2739,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m if( ippFuncC1 ) { Ipp64f norm; - if( ippFuncC1(src1.data, (int)src1.step[0], src2.data, (int)src2.step[0], mask.data, (int)mask.step[0], sz, &norm) >= 0 ) + if( ippFuncC1(src1.ptr(), (int)src1.step[0], src2.ptr(), (int)src2.step[0], mask.ptr(), (int)mask.step[0], sz, &norm) >= 0 ) return normType == NORM_L2SQR ? (double)(norm * norm) : (double)norm; setIppErrorStatus(); } @@ -2839,8 +2839,8 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m if( ippFuncHint || ippFuncNoHint ) { Ipp64f norm_array[4]; - IppStatus ret = ippFuncHint ? ippFuncHint(src1.data, (int)src1.step[0], src2.data, (int)src2.step[0], sz, norm_array, ippAlgHintAccurate) : - ippFuncNoHint(src1.data, (int)src1.step[0], src2.data, (int)src2.step[0], sz, norm_array); + IppStatus ret = ippFuncHint ? ippFuncHint(src1.ptr(), (int)src1.step[0], src2.ptr(), (int)src2.step[0], sz, norm_array, ippAlgHintAccurate) : + ippFuncNoHint(src1.ptr(), (int)src1.step[0], src2.ptr(), (int)src2.step[0], sz, norm_array); if( ret >= 0 ) { Ipp64f norm = (normType == NORM_L2 || normType == NORM_L2SQR) ? norm_array[0] * norm_array[0] : norm_array[0]; @@ -3322,7 +3322,7 @@ void cv::findNonZero( InputArray _src, OutputArray _idx ) _idx.create(n, 1, CV_32SC2); Mat idx = _idx.getMat(); CV_Assert(idx.isContinuous()); - Point* idx_ptr = (Point*)idx.data; + Point* idx_ptr = idx.ptr(); for( int i = 0; i < src.rows; i++ ) { diff --git a/modules/core/src/umatrix.cpp b/modules/core/src/umatrix.cpp index a128bcd01..f8a411fb5 100644 --- a/modules/core/src/umatrix.cpp +++ b/modules/core/src/umatrix.cpp @@ -658,7 +658,7 @@ void UMat::copyTo(OutputArray _dst) const } Mat dst = _dst.getMat(); - u->currAllocator->download(u, dst.data, dims, sz, srcofs, step.p, dst.step.p); + u->currAllocator->download(u, dst.ptr(), dims, sz, srcofs, step.p, dst.step.p); } void UMat::copyTo(OutputArray _dst, InputArray _mask) const diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index dc5730f60..14c741edc 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -562,10 +562,10 @@ static void inRange(const Mat& src, const Mat& lb, const Mat& rb, Mat& dst) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - const uchar* aptr = planes[1].data; - const uchar* bptr = planes[2].data; - uchar* dptr = planes[3].data; + const uchar* sptr = planes[0].ptr(); + const uchar* aptr = planes[1].ptr(); + const uchar* bptr = planes[2].ptr(); + uchar* dptr = planes[3].ptr(); switch( depth ) { @@ -614,8 +614,8 @@ static void inRangeS(const Mat& src, const Scalar& lb, const Scalar& rb, Mat& ds for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); switch( depth ) { @@ -905,8 +905,8 @@ static void exp(const Mat& src, Mat& dst) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); if( depth == CV_32F ) { @@ -934,8 +934,8 @@ static void log(const Mat& src, Mat& dst) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); if( depth == CV_32F ) { @@ -1027,10 +1027,10 @@ static void cartToPolar(const Mat& mx, const Mat& my, Mat& mmag, Mat& mangle, bo { if( depth == CV_32F ) { - const float* xptr = (const float*)planes[0].data; - const float* yptr = (const float*)planes[1].data; - float* mptr = (float*)planes[2].data; - float* aptr = (float*)planes[3].data; + const float* xptr = planes[0].ptr(); + const float* yptr = planes[1].ptr(); + float* mptr = planes[2].ptr(); + float* aptr = planes[3].ptr(); for( j = 0; j < total; j++ ) { @@ -1042,10 +1042,10 @@ static void cartToPolar(const Mat& mx, const Mat& my, Mat& mmag, Mat& mangle, bo } else { - const double* xptr = (const double*)planes[0].data; - const double* yptr = (const double*)planes[1].data; - double* mptr = (double*)planes[2].data; - double* aptr = (double*)planes[3].data; + const double* xptr = planes[0].ptr(); + const double* yptr = planes[1].ptr(); + double* mptr = planes[2].ptr(); + double* aptr = planes[3].ptr(); for( j = 0; j < total; j++ ) { diff --git a/modules/core/test/test_dxt.cpp b/modules/core/test/test_dxt.cpp index 9fc12c183..2e7bb38ea 100644 --- a/modules/core/test/test_dxt.cpp +++ b/modules/core/test/test_dxt.cpp @@ -39,8 +39,8 @@ static void DFT_1D( const Mat& _src, Mat& _dst, int flags, const Mat& _wave=Mat( double scale = (flags & DFT_SCALE) ? 1./n : 1.; size_t esz = _src.elemSize(); size_t srcstep = esz, dststep = esz; - const uchar* src0 = _src.data; - uchar* dst0 = _dst.data; + const uchar* src0 = _src.ptr(); + uchar* dst0 = _dst.ptr(); CV_Assert( _src.cols + _src.rows - 1 == n ); diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index ba56f76a6..37bff6215 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -126,7 +126,7 @@ protected: CvSeq* seq = cvCreateSeq(test_mat.type(), (int)sizeof(CvSeq), (int)test_mat.elemSize(), storage); - cvSeqPushMulti(seq, test_mat.data, test_mat.cols*test_mat.rows); + cvSeqPushMulti(seq, test_mat.ptr(), test_mat.cols*test_mat.rows); CvGraph* graph = cvCreateGraph( CV_ORIENTED_GRAPH, sizeof(CvGraph), sizeof(CvGraphVtx), diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 18a93cd2b..8cd92dd51 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -323,8 +323,8 @@ protected: evec = svd.vt; eval = svd.w;*/ - Mat subEval( maxComponents, 1, eval.type(), eval.data ), - subEvec( maxComponents, evec.cols, evec.type(), evec.data ); + Mat subEval( maxComponents, 1, eval.type(), eval.ptr() ), + subEvec( maxComponents, evec.cols, evec.type(), evec.ptr() ); #ifdef CHECK_C Mat prjTestPoints, backPrjTestPoints, cPoints = rPoints.t(), cTestPoints = rTestPoints.t(); diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index aeb3f15e6..5d483206e 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -458,7 +458,7 @@ void Core_TraceTest::prepare_to_validation( int ) { Mat& mat = test_mat[INPUT][0]; int count = MIN( mat.rows, mat.cols ); - Mat diag(count, 1, mat.type(), mat.data, mat.step + mat.elemSize()); + Mat diag(count, 1, mat.type(), mat.ptr(), mat.step + mat.elemSize()); Scalar r = cvtest::mean(diag); r *= (double)count; @@ -2698,7 +2698,7 @@ protected: case MAT_1_N_CDIM: data.create(1, N, CV_32FC(dims)); for( i = 0; i < N; i++ ) - memcpy(data.data + i * dims * sizeof(float), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); + memcpy(data.ptr() + i * dims * sizeof(float), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); break; case MAT_N_DIM_C1_NONCONT: diff --git a/modules/core/test/test_rand.cpp b/modules/core/test/test_rand.cpp index a94624b89..fc6c75aac 100644 --- a/modules/core/test/test_rand.cpp +++ b/modules/core/test/test_rand.cpp @@ -37,8 +37,8 @@ bool Core_RandTest::check_pdf(const Mat& hist, double scale, int dist_type, double& refval, double& realval) { Mat hist0(hist.size(), CV_32F); - const int* H = (const int*)hist.data; - float* H0 = ((float*)hist0.data); + const int* H = hist.ptr(); + float* H0 = hist0.ptr(); int i, hsz = hist.cols; double sum = 0; @@ -183,7 +183,7 @@ void Core_RandTest::run( int ) for( c = 0; c < cn; c++ ) { - const uchar* data = arr[0].data; + const uchar* data = arr[0].ptr(); int* H = hist[c].ptr(); int HSZ = hist[c].cols; double minVal = dist_type == CV_RAND_UNI ? A[c] : A[c] - B[c]*4; @@ -255,7 +255,7 @@ void Core_RandTest::run( int ) int SDIM = cvtest::randInt(rng) % (MAX_SDIM-1) + 2; int N0 = (SZ*cn/SDIM), n = 0; double r2 = 0; - const uchar* data = arr[0].data; + const uchar* data = arr[0].ptr(); double scale[4], delta[4]; for( c = 0; c < cn; c++ ) { diff --git a/modules/features2d/src/bagofwords.cpp b/modules/features2d/src/bagofwords.cpp index 525e478d4..0d6d2f42c 100644 --- a/modules/features2d/src/bagofwords.cpp +++ b/modules/features2d/src/bagofwords.cpp @@ -192,7 +192,7 @@ void BOWImgDescriptorExtractor::compute( InputArray keypointDescriptors, OutputA Mat imgDescriptor = _imgDescriptor.getMat(); - float *dptr = (float*)imgDescriptor.data; + float *dptr = imgDescriptor.ptr(); for( size_t i = 0; i < matches.size(); i++ ) { int queryIdx = matches[i].queryIdx; diff --git a/modules/features2d/src/brisk.cpp b/modules/features2d/src/brisk.cpp index 213dd6041..eb832d640 100644 --- a/modules/features2d/src/brisk.cpp +++ b/modules/features2d/src/brisk.cpp @@ -427,7 +427,7 @@ BRISK::smoothedIntensity(const cv::Mat& image, const cv::Mat& integral, const fl if (dx + dy > 2) { // now the calculation: - const uchar* ptr = image.data + x_left + imagecols * y_top; + const uchar* ptr = image.ptr() + x_left + imagecols * y_top; // first the corners: ret_val = A * int(*ptr); ptr += dx + 1; @@ -438,7 +438,7 @@ BRISK::smoothedIntensity(const cv::Mat& image, const cv::Mat& integral, const fl ret_val += D * int(*ptr); // next the edges: - int* ptr_integral = (int*) integral.data + x_left + integralcols * y_top + 1; + const int* ptr_integral = integral.ptr() + x_left + integralcols * y_top + 1; // find a simple path through the different surface corners const int tmp1 = (*ptr_integral); ptr_integral += dx; @@ -475,7 +475,7 @@ BRISK::smoothedIntensity(const cv::Mat& image, const cv::Mat& integral, const fl } // now the calculation: - const uchar* ptr = image.data + x_left + imagecols * y_top; + const uchar* ptr = image.ptr() + x_left + imagecols * y_top; // first row: ret_val = A * int(*ptr); ptr++; @@ -607,7 +607,7 @@ BRISK::computeDescriptorsAndOrOrientation(InputArray _image, InputArray _mask, s int t2; // the feature orientation - const uchar* ptr = descriptors.data; + const uchar* ptr = descriptors.ptr(); for (size_t k = 0; k < ksize; k++) { cv::KeyPoint& kp = keypoints[k]; @@ -1070,7 +1070,7 @@ BriskScaleSpace::isMax2D(const int layer, const int x_layer, const int y_layer) { const cv::Mat& scores = pyramid_[layer].scores(); const int scorescols = scores.cols; - const uchar* data = scores.data + y_layer * scorescols + x_layer; + const uchar* data = scores.ptr() + y_layer * scorescols + x_layer; // decision tree: const uchar center = (*data); data--; @@ -1154,11 +1154,11 @@ BriskScaleSpace::isMax2D(const int layer, const int x_layer, const int y_layer) { // in this case, we have to analyze the situation more carefully: // the values are gaussian blurred and then we really decide - data = scores.data + y_layer * scorescols + x_layer; + data = scores.ptr() + y_layer * scorescols + x_layer; int smoothedcenter = 4 * center + 2 * (s_10 + s10 + s0_1 + s01) + s_1_1 + s1_1 + s_11 + s11; for (unsigned int i = 0; i < deltasize; i += 2) { - data = scores.data + (y_layer - 1 + delta[i + 1]) * scorescols + x_layer + delta[i] - 1; + data = scores.ptr() + (y_layer - 1 + delta[i + 1]) * scorescols + x_layer + delta[i] - 1; int othercenter = *data; data++; othercenter += 2 * (*data); @@ -2140,7 +2140,7 @@ BriskLayer::value(const cv::Mat& mat, float xf, float yf, float scale_in) const const int r_y = (int)((yf - y) * 1024); const int r_x_1 = (1024 - r_x); const int r_y_1 = (1024 - r_y); - const uchar* ptr = image.data + x + y * imagecols; + const uchar* ptr = image.ptr() + x + y * imagecols; // just interpolate: ret_val = (r_x_1 * r_y_1 * int(*ptr)); ptr++; @@ -2186,7 +2186,7 @@ BriskLayer::value(const cv::Mat& mat, float xf, float yf, float scale_in) const const int r_y1_i = (int)(r_y1 * scaling); // now the calculation: - const uchar* ptr = image.data + x_left + imagecols * y_top; + const uchar* ptr = image.ptr() + x_left + imagecols * y_top; // first row: ret_val = A * int(*ptr); ptr++; diff --git a/modules/features2d/test/test_descriptors_regression.cpp b/modules/features2d/test/test_descriptors_regression.cpp index 944f297bb..c09a466b8 100644 --- a/modules/features2d/test/test_descriptors_regression.cpp +++ b/modules/features2d/test/test_descriptors_regression.cpp @@ -62,7 +62,7 @@ static void writeMatInBin( const Mat& mat, const string& filename ) fwrite( (void*)&type, sizeof(int), 1, f ); int dataSize = (int)(mat.step * mat.rows * mat.channels()); fwrite( (void*)&dataSize, sizeof(int), 1, f ); - fwrite( (void*)mat.data, 1, dataSize, f ); + fwrite( (void*)mat.ptr(), 1, dataSize, f ); fclose(f); } } diff --git a/modules/flann/src/miniflann.cpp b/modules/flann/src/miniflann.cpp index efa58927d..7d81438db 100644 --- a/modules/flann/src/miniflann.cpp +++ b/modules/flann/src/miniflann.cpp @@ -470,8 +470,8 @@ void runKnnSearch_(void* index, const Mat& query, Mat& indices, Mat& dists, CV_Assert(query.isContinuous() && indices.isContinuous() && dists.isContinuous()); ::cvflann::Matrix _query((ElementType*)query.data, query.rows, query.cols); - ::cvflann::Matrix _indices((int*)indices.data, indices.rows, indices.cols); - ::cvflann::Matrix _dists((DistanceType*)dists.data, dists.rows, dists.cols); + ::cvflann::Matrix _indices(indices.ptr(), indices.rows, indices.cols); + ::cvflann::Matrix _dists(dists.ptr(), dists.rows, dists.cols); ((IndexType*)index)->knnSearch(_query, _indices, _dists, knn, (const ::cvflann::SearchParams&)get_params(params)); @@ -496,8 +496,8 @@ int runRadiusSearch_(void* index, const Mat& query, Mat& indices, Mat& dists, CV_Assert(query.isContinuous() && indices.isContinuous() && dists.isContinuous()); ::cvflann::Matrix _query((ElementType*)query.data, query.rows, query.cols); - ::cvflann::Matrix _indices((int*)indices.data, indices.rows, indices.cols); - ::cvflann::Matrix _dists((DistanceType*)dists.data, dists.rows, dists.cols); + ::cvflann::Matrix _indices(indices.ptr(), indices.rows, indices.cols); + ::cvflann::Matrix _dists(dists.ptr(), dists.rows, dists.cols); return ((IndexType*)index)->radiusSearch(_query, _indices, _dists, saturate_cast(radius), diff --git a/modules/imgcodecs/src/grfmt_bmp.cpp b/modules/imgcodecs/src/grfmt_bmp.cpp index f7147b5fc..c291a2268 100644 --- a/modules/imgcodecs/src/grfmt_bmp.cpp +++ b/modules/imgcodecs/src/grfmt_bmp.cpp @@ -183,7 +183,7 @@ bool BmpDecoder::readHeader() bool BmpDecoder::readData( Mat& img ) { - uchar* data = img.data; + uchar* data = img.ptr(); int step = (int)img.step; bool color = img.channels() > 1; uchar gray_palette[256]; @@ -553,7 +553,7 @@ bool BmpEncoder::write( const Mat& img, const std::vector& ) width *= channels; for( int y = height - 1; y >= 0; y-- ) { - strm.putBytes( img.data + img.step*y, width ); + strm.putBytes( img.ptr(y), width ); if( fileStep > width ) strm.putBytes( zeropad, fileStep - width ); } diff --git a/modules/imgcodecs/src/grfmt_exr.cpp b/modules/imgcodecs/src/grfmt_exr.cpp index 079de5834..5957549f3 100644 --- a/modules/imgcodecs/src/grfmt_exr.cpp +++ b/modules/imgcodecs/src/grfmt_exr.cpp @@ -187,7 +187,7 @@ bool ExrDecoder::readData( Mat& img ) m_native_depth = CV_MAT_DEPTH(type()) == img.depth(); bool color = img.channels() > 1; - uchar* data = img.data; + uchar* data = img.ptr(); int step = img.step; bool justcopy = m_native_depth; bool chromatorgb = false; @@ -583,8 +583,7 @@ bool ExrEncoder::write( const Mat& img, const std::vector& ) bool issigned = depth == CV_8S || depth == CV_16S || depth == CV_32S; bool isfloat = depth == CV_32F || depth == CV_64F; depth = CV_ELEM_SIZE1(depth)*8; - uchar* data = img.data; - int step = img.step; + const int step = img.step; Header header( width, height ); Imf::PixelType type; @@ -618,7 +617,7 @@ bool ExrEncoder::write( const Mat& img, const std::vector& ) int size; if( type == FLOAT && depth == 32 ) { - buffer = (char *)const_cast(data); + buffer = (char *)const_cast(img.ptr()); bufferstep = step; size = 4; } @@ -674,18 +673,19 @@ bool ExrEncoder::write( const Mat& img, const std::vector& ) if( depth <= 8 ) { + const uchar* sd = img.ptr(line); for(int i = 0; i < width * channels; i++) - buf[i] = data[i] + offset; + buf[i] = sd[i] + offset; } else if( depth <= 16 ) { - unsigned short *sd = (unsigned short *)data; + const unsigned short *sd = img.ptr(line); for(int i = 0; i < width * channels; i++) buf[i] = sd[i] + offset; } else { - int *sd = (int *)data; // FIXME 64-bit problems + const int *sd = img.ptr(line); // FIXME 64-bit problems for(int i = 0; i < width * channels; i++) buf[i] = (unsigned) sd[i] + offset; } @@ -696,12 +696,13 @@ bool ExrEncoder::write( const Mat& img, const std::vector& ) if( depth <= 8 ) { + const uchar* sd = img.ptr(line); for(int i = 0; i < width * channels; i++) - buf[i] = data[i]; + buf[i] = sd[i]; } else if( depth <= 16 ) { - unsigned short *sd = (unsigned short *)data; + const unsigned short *sd = img.ptr(line); for(int i = 0; i < width * channels; i++) buf[i] = sd[i]; } @@ -715,7 +716,6 @@ bool ExrEncoder::write( const Mat& img, const std::vector& ) result = false; break; } - data += step; } delete[] buffer; } diff --git a/modules/imgcodecs/src/grfmt_jpeg.cpp b/modules/imgcodecs/src/grfmt_jpeg.cpp index ec1793287..d6272e00d 100644 --- a/modules/imgcodecs/src/grfmt_jpeg.cpp +++ b/modules/imgcodecs/src/grfmt_jpeg.cpp @@ -228,7 +228,7 @@ bool JpegDecoder::readHeader() if( !m_buf.empty() ) { jpeg_buffer_src(&state->cinfo, &state->source); - state->source.pub.next_input_byte = m_buf.data; + state->source.pub.next_input_byte = m_buf.ptr(); state->source.pub.bytes_in_buffer = m_buf.cols*m_buf.rows*m_buf.elemSize(); } else @@ -449,7 +449,7 @@ bool JpegDecoder::readData( Mat& img ) buffer = (*cinfo->mem->alloc_sarray)((j_common_ptr)cinfo, JPOOL_IMAGE, m_width*4, 1 ); - uchar* data = img.data; + uchar* data = img.ptr(); for( ; m_height--; data += step ) { jpeg_read_scanlines( cinfo, buffer, 1 ); diff --git a/modules/imgcodecs/src/grfmt_png.cpp b/modules/imgcodecs/src/grfmt_png.cpp index 4d5c7793e..19d3f52ca 100644 --- a/modules/imgcodecs/src/grfmt_png.cpp +++ b/modules/imgcodecs/src/grfmt_png.cpp @@ -134,7 +134,7 @@ void PngDecoder::readDataFromBuf( void* _png_ptr, uchar* dst, size_t size ) png_error(png_ptr, "PNG input buffer is incomplete"); return; } - memcpy( dst, &decoder->m_buf.data[decoder->m_buf_pos], size ); + memcpy( dst, decoder->m_buf.ptr() + decoder->m_buf_pos, size ); decoder->m_buf_pos += size; } @@ -228,7 +228,7 @@ bool PngDecoder::readData( Mat& img ) AutoBuffer _buffer(m_height); uchar** buffer = _buffer; int color = img.channels() > 1; - uchar* data = img.data; + uchar* data = img.ptr(); int step = (int)img.step; if( m_png_ptr && m_info_ptr && m_end_info && m_width && m_height ) diff --git a/modules/imgcodecs/src/grfmt_pxm.cpp b/modules/imgcodecs/src/grfmt_pxm.cpp index 425a296cb..7f299099d 100644 --- a/modules/imgcodecs/src/grfmt_pxm.cpp +++ b/modules/imgcodecs/src/grfmt_pxm.cpp @@ -189,7 +189,7 @@ bool PxMDecoder::readHeader() bool PxMDecoder::readData( Mat& img ) { int color = img.channels() > 1; - uchar* data = img.data; + uchar* data = img.ptr(); int step = (int)img.step; PaletteEntry palette[256]; bool result = false; @@ -418,16 +418,16 @@ bool PxMEncoder::write( const Mat& img, const std::vector& params ) for( y = 0; y < height; y++ ) { - uchar* data = img.data + img.step*y; + const uchar* const data = img.ptr(y); if( isBinary ) { if( _channels == 3 ) { if( depth == 8 ) - icvCvt_BGR2RGB_8u_C3R( (uchar*)data, 0, + icvCvt_BGR2RGB_8u_C3R( (const uchar*)data, 0, (uchar*)buffer, 0, cvSize(width,1) ); else - icvCvt_BGR2RGB_16u_C3R( (ushort*)data, 0, + icvCvt_BGR2RGB_16u_C3R( (const ushort*)data, 0, (ushort*)buffer, 0, cvSize(width,1) ); } @@ -443,7 +443,7 @@ bool PxMEncoder::write( const Mat& img, const std::vector& params ) buffer[x + 1] = v; } } - strm.putBytes( (channels > 1 || depth > 8) ? buffer : (char*)data, fileStep ); + strm.putBytes( (channels > 1 || depth > 8) ? buffer : (const char*)data, fileStep ); } else { @@ -469,11 +469,11 @@ bool PxMEncoder::write( const Mat& img, const std::vector& params ) { for( x = 0; x < width*channels; x += channels ) { - sprintf( ptr, "% 6d", ((ushort *)data)[x + 2] ); + sprintf( ptr, "% 6d", ((const ushort *)data)[x + 2] ); ptr += 6; - sprintf( ptr, "% 6d", ((ushort *)data)[x + 1] ); + sprintf( ptr, "% 6d", ((const ushort *)data)[x + 1] ); ptr += 6; - sprintf( ptr, "% 6d", ((ushort *)data)[x] ); + sprintf( ptr, "% 6d", ((const ushort *)data)[x] ); ptr += 6; *ptr++ = ' '; *ptr++ = ' '; @@ -494,7 +494,7 @@ bool PxMEncoder::write( const Mat& img, const std::vector& params ) { for( x = 0; x < width; x++ ) { - sprintf( ptr, "% 6d", ((ushort *)data)[x] ); + sprintf( ptr, "% 6d", ((const ushort *)data)[x] ); ptr += 6; } } diff --git a/modules/imgcodecs/src/grfmt_sunras.cpp b/modules/imgcodecs/src/grfmt_sunras.cpp index b67400f33..6cbefef3c 100644 --- a/modules/imgcodecs/src/grfmt_sunras.cpp +++ b/modules/imgcodecs/src/grfmt_sunras.cpp @@ -155,7 +155,7 @@ bool SunRasterDecoder::readHeader() bool SunRasterDecoder::readData( Mat& img ) { int color = img.channels() > 1; - uchar* data = img.data; + uchar* data = img.ptr(); int step = (int)img.step; uchar gray_palette[256]; bool result = false; @@ -414,7 +414,7 @@ bool SunRasterEncoder::write( const Mat& img, const std::vector& ) strm.putDWord( 0 ); for( y = 0; y < height; y++ ) - strm.putBytes( img.data + img.step*y, fileStep ); + strm.putBytes( img.ptr(y), fileStep ); strm.close(); result = true; diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index 06b2ab6a1..00e1d30f3 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -190,7 +190,7 @@ bool TiffDecoder::readData( Mat& img ) } bool result = false; bool color = img.channels() > 1; - uchar* data = img.data; + uchar* data = img.ptr(); if( img.depth() != CV_8U && img.depth() != CV_16U && img.depth() != CV_32F && img.depth() != CV_64F ) return false; @@ -587,25 +587,25 @@ bool TiffEncoder::writeLibTiff( const Mat& img, const std::vector& params) { case 1: { - memcpy(buffer, img.data + img.step * y, scanlineSize); + memcpy(buffer, img.ptr(y), scanlineSize); break; } case 3: { if (depth == CV_8U) - icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); + icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, cvSize(width,1) ); else - icvCvt_BGR2RGB_16u_C3R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) ); + icvCvt_BGR2RGB_16u_C3R( img.ptr(y), 0, (ushort*)buffer, 0, cvSize(width,1) ); break; } case 4: { if (depth == CV_8U) - icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); + icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, cvSize(width,1) ); else - icvCvt_BGRA2RGBA_16u_C4R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) ); + icvCvt_BGRA2RGBA_16u_C4R( img.ptr(y), 0, (ushort*)buffer, 0, cvSize(width,1) ); break; } @@ -742,22 +742,22 @@ bool TiffEncoder::write( const Mat& img, const std::vector& /*params*/) if( channels == 3 ) { if (depth == CV_8U) - icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); + icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, cvSize(width,1) ); else - icvCvt_BGR2RGB_16u_C3R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) ); + icvCvt_BGR2RGB_16u_C3R( img.ptr(y), 0, (ushort*)buffer, 0, cvSize(width,1) ); } else { if( channels == 4 ) { if (depth == CV_8U) - icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) ); + icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, cvSize(width,1) ); else - icvCvt_BGRA2RGBA_16u_C4R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) ); + icvCvt_BGRA2RGBA_16u_C4R( img.ptr(y), 0, (ushort*)buffer, 0, cvSize(width,1) ); } } - strm.putBytes( channels > 1 ? buffer : img.data + img.step*y, fileStep ); + strm.putBytes( channels > 1 ? buffer : img.ptr(y), fileStep ); } stripCounts[i] = (short)(strm.getPos() - stripOffsets[i]); diff --git a/modules/imgcodecs/src/grfmt_webp.cpp b/modules/imgcodecs/src/grfmt_webp.cpp index 6ef4202ff..68232796f 100644 --- a/modules/imgcodecs/src/grfmt_webp.cpp +++ b/modules/imgcodecs/src/grfmt_webp.cpp @@ -118,7 +118,7 @@ bool WebPDecoder::readHeader() data.create(1, wfile_size, CV_8U); - size_t data_size = fread(data.data, 1, wfile_size, wfile); + size_t data_size = fread(data.ptr(), 1, wfile_size, wfile); if(wfile) { @@ -136,7 +136,7 @@ bool WebPDecoder::readHeader() } WebPBitstreamFeatures features; - if(VP8_STATUS_OK == WebPGetFeatures(data.data, WEBP_HEADER_SIZE, &features)) + if(VP8_STATUS_OK == WebPGetFeatures(data.ptr(), WEBP_HEADER_SIZE, &features)) { m_width = features.width; m_height = features.height; @@ -167,18 +167,18 @@ bool WebPDecoder::readData(Mat &img) img.create(m_height, m_width, m_type); } - uchar* out_data = img.data; + uchar* out_data = img.ptr(); size_t out_data_size = img.cols * img.rows * img.elemSize(); uchar *res_ptr = 0; if (channels == 3) { - res_ptr = WebPDecodeBGRInto(data.data, data.total(), out_data, + res_ptr = WebPDecodeBGRInto(data.ptr(), data.total(), out_data, (int)out_data_size, (int)img.step); } else if (channels == 4) { - res_ptr = WebPDecodeBGRAInto(data.data, data.total(), out_data, + res_ptr = WebPDecodeBGRAInto(data.ptr(), data.total(), out_data, (int)out_data_size, (int)img.step); } @@ -255,22 +255,22 @@ bool WebPEncoder::write(const Mat& img, const std::vector& params) { if(channels == 3) { - size = WebPEncodeLosslessBGR(image->data, width, height, (int)image->step, &out); + size = WebPEncodeLosslessBGR(image->ptr(), width, height, (int)image->step, &out); } else if(channels == 4) { - size = WebPEncodeLosslessBGRA(image->data, width, height, (int)image->step, &out); + size = WebPEncodeLosslessBGRA(image->ptr(), width, height, (int)image->step, &out); } } else { if(channels == 3) { - size = WebPEncodeBGR(image->data, width, height, (int)image->step, quality, &out); + size = WebPEncodeBGR(image->ptr(), width, height, (int)image->step, quality, &out); } else if(channels == 4) { - size = WebPEncodeBGRA(image->data, width, height, (int)image->step, quality, &out); + size = WebPEncodeBGRA(image->ptr(), width, height, (int)image->step, quality, &out); } } diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index a084cd996..6d0bd479d 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -303,7 +303,7 @@ bool imwrite( const String& filename, InputArray _img, static void* imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) { - CV_Assert(buf.data && buf.isContinuous()); + CV_Assert(!buf.empty() && buf.isContinuous()); IplImage* image = 0; CvMat *matrix = 0; Mat temp, *data = &temp; @@ -320,7 +320,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 ) if( !f ) return 0; size_t bufSize = buf.cols*buf.rows*buf.elemSize(); - fwrite( &buf.data[0], 1, bufSize, f ); + fwrite( buf.ptr(), 1, bufSize, f ); fclose(f); decoder->setSource(filename); } diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp index ed991a6f3..79b79eb61 100644 --- a/modules/imgcodecs/test/test_grfmt.cpp +++ b/modules/imgcodecs/test/test_grfmt.cpp @@ -296,7 +296,7 @@ public: ASSERT_TRUE(img.channels() == 4); - unsigned char* img_data = (unsigned char*)img.data; + unsigned char* img_data = img.ptr(); // Verification first pixel is red in BGRA ASSERT_TRUE(img_data[0] == 0x00); @@ -316,7 +316,7 @@ public: ASSERT_TRUE(img.channels() == 3); - img_data = (unsigned char*)img.data; + img_data = img.ptr(); // Verification first pixel is red in BGR ASSERT_TRUE(img_data[0] == 0x00); @@ -334,7 +334,7 @@ public: ASSERT_TRUE(img.channels() == 3); - img_data = (unsigned char*)img.data; + img_data = img.ptr(); // Verification first pixel is red in BGR ASSERT_TRUE(img_data[0] == 0x00); @@ -352,7 +352,7 @@ public: ASSERT_TRUE(img.channels() == 3); - img_data = (unsigned char*)img.data; + img_data = img.ptr(); // Verification first pixel is red in BGR ASSERT_TRUE(img_data[0] == 0x00); diff --git a/modules/imgproc/src/accum.cpp b/modules/imgproc/src/accum.cpp index 1a4b4080e..f2a47e3d3 100644 --- a/modules/imgproc/src/accum.cpp +++ b/modules/imgproc/src/accum.cpp @@ -472,10 +472,10 @@ void cv::accumulate( InputArray _src, InputOutputArray _dst, InputArray _mask ) size.width *= scn; if (mask.empty()) - status = ippFunc(src.data, srcstep, (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height)); + status = ippFunc(src.ptr(), srcstep, dst.ptr(), dststep, ippiSize(size.width, size.height)); else - status = ippFuncMask(src.data, srcstep, (const Ipp8u *)mask.data, maskstep, - (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height)); + status = ippFuncMask(src.ptr(), srcstep, mask.ptr(), maskstep, + dst.ptr(), dststep, ippiSize(size.width, size.height)); if (status >= 0) return; @@ -549,10 +549,10 @@ void cv::accumulateSquare( InputArray _src, InputOutputArray _dst, InputArray _m size.width *= scn; if (mask.empty()) - status = ippFunc(src.data, srcstep, (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height)); + status = ippFunc(src.ptr(), srcstep, dst.ptr(), dststep, ippiSize(size.width, size.height)); else - status = ippFuncMask(src.data, srcstep, (const Ipp8u *)mask.data, maskstep, - (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height)); + status = ippFuncMask(src.ptr(), srcstep, mask.ptr(), maskstep, + dst.ptr(), dststep, ippiSize(size.width, size.height)); if (status >= 0) return; @@ -630,11 +630,11 @@ void cv::accumulateProduct( InputArray _src1, InputArray _src2, size.width *= scn; if (mask.empty()) - status = ippFunc(src1.data, src1step, src2.data, src2step, (Ipp32f *)dst.data, + status = ippFunc(src1.ptr(), src1step, src2.ptr(), src2step, dst.ptr(), dststep, ippiSize(size.width, size.height)); else - status = ippFuncMask(src1.data, src1step, src2.data, src2step, (const Ipp8u *)mask.data, maskstep, - (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height)); + status = ippFuncMask(src1.ptr(), src1step, src2.ptr(), src2step, mask.ptr(), maskstep, + dst.ptr(), dststep, ippiSize(size.width, size.height)); if (status >= 0) return; @@ -711,10 +711,10 @@ void cv::accumulateWeighted( InputArray _src, InputOutputArray _dst, size.width *= scn; if (mask.empty()) - status = ippFunc(src.data, srcstep, (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height), (Ipp32f)alpha); + status = ippFunc(src.ptr(), srcstep, dst.ptr(), dststep, ippiSize(size.width, size.height), (Ipp32f)alpha); else - status = ippFuncMask(src.data, srcstep, (const Ipp8u *)mask.data, maskstep, - (Ipp32f *)dst.data, dststep, ippiSize(size.width, size.height), (Ipp32f)alpha); + status = ippFuncMask(src.ptr(), srcstep, mask.ptr(), maskstep, + dst.ptr(), dststep, ippiSize(size.width, size.height), (Ipp32f)alpha); if (status >= 0) return; diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index 09898a539..eb6860dac 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -73,20 +73,20 @@ static bool ippCanny(const Mat& _src, Mat& _dst, float low, float high) uchar* buffer = alignPtr((uchar*)buf, 32); Mat _dx(_src.rows, _src.cols, CV_16S); - if( ippiFilterSobelNegVertBorder_8u16s_C1R(_src.data, (int)_src.step, + if( ippiFilterSobelNegVertBorder_8u16s_C1R(_src.ptr(), (int)_src.step, _dx.ptr(), (int)_dx.step, roi, ippMskSize3x3, ippBorderRepl, 0, buffer) < 0 ) return false; Mat _dy(_src.rows, _src.cols, CV_16S); - if( ippiFilterSobelHorizBorder_8u16s_C1R(_src.data, (int)_src.step, + if( ippiFilterSobelHorizBorder_8u16s_C1R(_src.ptr(), (int)_src.step, _dy.ptr(), (int)_dy.step, roi, ippMskSize3x3, ippBorderRepl, 0, buffer) < 0 ) return false; if( ippiCanny_16s8u_C1R(_dx.ptr(), (int)_dx.step, _dy.ptr(), (int)_dy.step, - _dst.data, (int)_dst.step, roi, low, high, buffer) < 0 ) + _dst.ptr(), (int)_dst.step, roi, low, high, buffer) < 0 ) return false; return true; } diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index 71f163bba..1f8f73486 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -468,10 +468,10 @@ struct IPPGray2BGRAFunctor const void* srcarray[3] = { src, src, src }; Mat temp(rows, cols, CV_MAKETYPE(depth, 3)); - if(func1(srcarray, srcStep, temp.data, (int)temp.step[0], ippiSize(cols, rows)) < 0) + if(func1(srcarray, srcStep, temp.ptr(), (int)temp.step[0], ippiSize(cols, rows)) < 0) return false; int order[4] = {0, 1, 2, 3}; - return func2(temp.data, (int)temp.step[0], dst, dstStep, ippiSize(cols, rows), order) >= 0; + return func2(temp.ptr(), (int)temp.step[0], dst, dstStep, ippiSize(cols, rows), order) >= 0; } private: ippiGeneralFunc func1; @@ -496,9 +496,9 @@ struct IPPReorderGeneralFunctor Mat temp; temp.create(rows, cols, CV_MAKETYPE(depth, 3)); - if(func1(src, srcStep, temp.data, (int)temp.step[0], ippiSize(cols, rows), order) < 0) + if(func1(src, srcStep, temp.ptr(), (int)temp.step[0], ippiSize(cols, rows), order) < 0) return false; - return func2(temp.data, (int)temp.step[0], dst, dstStep, ippiSize(cols, rows)) >= 0; + return func2(temp.ptr(), (int)temp.step[0], dst, dstStep, ippiSize(cols, rows)) >= 0; } private: ippiReorderFunc func1; @@ -524,9 +524,9 @@ struct IPPGeneralReorderFunctor Mat temp; temp.create(rows, cols, CV_MAKETYPE(depth, 3)); - if(func1(src, srcStep, temp.data, (int)temp.step[0], ippiSize(cols, rows)) < 0) + if(func1(src, srcStep, temp.ptr(), (int)temp.step[0], ippiSize(cols, rows)) < 0) return false; - return func2(temp.data, (int)temp.step[0], dst, dstStep, ippiSize(cols, rows), order) >= 0; + return func2(temp.ptr(), (int)temp.step[0], dst, dstStep, ippiSize(cols, rows), order) >= 0; } private: ippiGeneralFunc func1; diff --git a/modules/imgproc/src/connectedcomponents.cpp b/modules/imgproc/src/connectedcomponents.cpp index 921299273..523eb14c0 100644 --- a/modules/imgproc/src/connectedcomponents.cpp +++ b/modules/imgproc/src/connectedcomponents.cpp @@ -203,10 +203,10 @@ namespace cv{ LabelT lunique = 1; //scanning phase for(int r_i = 0; r_i < rows; ++r_i){ - LabelT *Lrow = (LabelT *)(L.data + L.step.p[0] * r_i); - LabelT *Lrow_prev = (LabelT *)(((char *)Lrow) - L.step.p[0]); - const PixelT *Irow = (PixelT *)(I.data + I.step.p[0] * r_i); - const PixelT *Irow_prev = (const PixelT *)(((char *)Irow) - I.step.p[0]); + LabelT * const Lrow = L.ptr(r_i); + LabelT * const Lrow_prev = (LabelT *)(((char *)Lrow) - L.step.p[0]); + const PixelT * const Irow = I.ptr(r_i); + const PixelT * const Irow_prev = (const PixelT *)(((char *)Irow) - I.step.p[0]); LabelT *Lrows[2] = { Lrow, Lrow_prev @@ -315,7 +315,7 @@ namespace cv{ sop.init(nLabels); for(int r_i = 0; r_i < rows; ++r_i){ - LabelT *Lrow_start = (LabelT *)(L.data + L.step.p[0] * r_i); + LabelT *Lrow_start = L.ptr(r_i); LabelT *Lrow_end = Lrow_start + cols; LabelT *Lrow = Lrow_start; for(int c_i = 0; Lrow != Lrow_end; ++Lrow, ++c_i){ diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index ee7f21ac8..b0a81ed32 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -1732,7 +1732,7 @@ void cv::findContours( InputOutputArray _image, OutputArrayOfArrays _contours, _contours.create((int)c->total, 1, CV_32SC2, i, true); Mat ci = _contours.getMat(i); CV_Assert( ci.isContinuous() ); - cvCvtSeqToArray(c, ci.data); + cvCvtSeqToArray(c, ci.ptr()); } if( _hierarchy.needed() ) diff --git a/modules/imgproc/src/convhull.cpp b/modules/imgproc/src/convhull.cpp index f4f4193e5..35526a90b 100644 --- a/modules/imgproc/src/convhull.cpp +++ b/modules/imgproc/src/convhull.cpp @@ -146,7 +146,7 @@ void convexHull( InputArray _points, OutputArray _hull, bool clockwise, bool ret AutoBuffer _stack(total + 2), _hullbuf(total); Point** pointer = _pointer; Point2f** pointerf = (Point2f**)pointer; - Point* data0 = (Point*)points.data; + Point* data0 = points.ptr(); int* stack = _stack; int* hullbuf = _hullbuf; @@ -257,7 +257,7 @@ void convexHull( InputArray _points, OutputArray _hull, bool clockwise, bool ret Mat hull = _hull.getMat(); size_t step = !hull.isContinuous() ? hull.step[0] : sizeof(Point); for( i = 0; i < nout; i++ ) - *(Point*)(hull.data + i*step) = data0[hullbuf[i]]; + *(Point*)(hull.ptr() + i*step) = data0[hullbuf[i]]; } } @@ -278,7 +278,7 @@ void convexityDefects( InputArray _points, InputArray _hull, OutputArray _defect int hpoints = hull.checkVector(1, CV_32S); CV_Assert( hpoints > 2 ); - const Point* ptr = (const Point*)points.data; + const Point* ptr = points.ptr(); const int* hptr = hull.ptr(); std::vector defects; @@ -385,8 +385,8 @@ bool isContourConvex( InputArray _contour ) return false; return depth == CV_32S ? - isContourConvex_((const Point*)contour.data, total ) : - isContourConvex_((const Point2f*)contour.data, total ); + isContourConvex_(contour.ptr(), total ) : + isContourConvex_(contour.ptr(), total ); } } @@ -487,7 +487,7 @@ cvConvexHull2( const CvArr* array, void* hull_storage, } } else - cvSeqPushMulti(hullseq, h0.data, (int)h0.total()); + cvSeqPushMulti(hullseq, h0.ptr(), (int)h0.total()); if( mat ) { diff --git a/modules/imgproc/src/corner.cpp b/modules/imgproc/src/corner.cpp index 1fdd047cd..631878427 100644 --- a/modules/imgproc/src/corner.cpp +++ b/modules/imgproc/src/corner.cpp @@ -62,8 +62,8 @@ static void calcMinEigenVal( const Mat& _cov, Mat& _dst ) for( i = 0; i < size.height; i++ ) { - const float* cov = (const float*)(_cov.data + _cov.step*i); - float* dst = (float*)(_dst.data + _dst.step*i); + const float* cov = _cov.ptr(i); + float* dst = _dst.ptr(i); j = 0; #if CV_SSE if( simd ) @@ -118,8 +118,8 @@ static void calcHarris( const Mat& _cov, Mat& _dst, double k ) for( i = 0; i < size.height; i++ ) { - const float* cov = (const float*)(_cov.data + _cov.step*i); - float* dst = (float*)(_dst.data + _dst.step*i); + const float* cov = _cov.ptr(i); + float* dst = _dst.ptr(i); j = 0; #if CV_SSE @@ -227,8 +227,8 @@ static void calcEigenValsVecs( const Mat& _cov, Mat& _dst ) for( int i = 0; i < size.height; i++ ) { - const float* cov = (const float*)(_cov.data + _cov.step*i); - float* dst = (float*)(_dst.data + _dst.step*i); + const float* cov = _cov.ptr(i); + float* dst = _dst.ptr(i); eigen2x2(cov, dst, size.width); } @@ -276,9 +276,9 @@ cornerEigenValsVecs( const Mat& src, Mat& eigenv, int block_size, for( i = 0; i < size.height; i++ ) { - float* cov_data = (float*)(cov.data + i*cov.step); - const float* dxdata = (const float*)(Dx.data + i*Dx.step); - const float* dydata = (const float*)(Dy.data + i*Dy.step); + float* cov_data = cov.ptr(i); + const float* dxdata = Dx.ptr(i); + const float* dydata = Dy.ptr(i); for( j = 0; j < size.width; j++ ) { @@ -503,9 +503,9 @@ void cv::cornerMinEigenVal( InputArray _src, OutputArray _dst, int blockSize, in if (ok >= 0) { AutoBuffer buffer(bufferSize); - ok = minEigenValFunc(src.data, (int) src.step, (Ipp32f*) dst.data, (int) dst.step, srcRoi, kerType, kerSize, blockSize, buffer); + ok = minEigenValFunc(src.ptr(), (int) src.step, dst.ptr(), (int) dst.step, srcRoi, kerType, kerSize, blockSize, buffer); CV_SUPPRESS_DEPRECATED_START - if (ok >= 0) ok = ippiMulC_32f_C1IR(norm_coef, (Ipp32f*) dst.data, (int) dst.step, srcRoi); + if (ok >= 0) ok = ippiMulC_32f_C1IR(norm_coef, dst.ptr(), (int) dst.step, srcRoi); CV_SUPPRESS_DEPRECATED_END if (ok >= 0) return; @@ -617,12 +617,12 @@ void cv::preCornerDetect( InputArray _src, OutputArray _dst, int ksize, int bord int i, j; for( i = 0; i < size.height; i++ ) { - float* dstdata = (float*)(dst.data + i*dst.step); - const float* dxdata = (const float*)(Dx.data + i*Dx.step); - const float* dydata = (const float*)(Dy.data + i*Dy.step); - const float* d2xdata = (const float*)(D2x.data + i*D2x.step); - const float* d2ydata = (const float*)(D2y.data + i*D2y.step); - const float* dxydata = (const float*)(Dxy.data + i*Dxy.step); + float* dstdata = dst.ptr(i); + const float* dxdata = Dx.ptr(i); + const float* dydata = Dy.ptr(i); + const float* d2xdata = D2x.ptr(i); + const float* d2ydata = D2y.ptr(i); + const float* dxydata = Dxy.ptr(i); j = 0; diff --git a/modules/imgproc/src/cornersubpix.cpp b/modules/imgproc/src/cornersubpix.cpp index 31ccb3e90..1909bbcbb 100644 --- a/modules/imgproc/src/cornersubpix.cpp +++ b/modules/imgproc/src/cornersubpix.cpp @@ -54,7 +54,7 @@ void cv::cornerSubPix( InputArray _image, InputOutputArray _corners, cv::Mat src = _image.getMat(), cornersmat = _corners.getMat(); int count = cornersmat.checkVector(2, CV_32F); CV_Assert( count >= 0 ); - Point2f* corners = (Point2f*)cornersmat.data; + Point2f* corners = cornersmat.ptr(); if( count == 0 ) return; diff --git a/modules/imgproc/src/demosaicing.cpp b/modules/imgproc/src/demosaicing.cpp index ff730ee94..01a84ee8e 100644 --- a/modules/imgproc/src/demosaicing.cpp +++ b/modules/imgproc/src/demosaicing.cpp @@ -515,7 +515,7 @@ public: const int G2Y = 9617; const int SHIFT = 14; - const T* bayer0 = (const T*)srcmat.data; + const T* bayer0 = srcmat.ptr(); int bayer_step = (int)(srcmat.step/sizeof(T)); T* dst0 = (T*)dstmat.data; int dst_step = (int)(dstmat.step/sizeof(T)); @@ -632,7 +632,7 @@ static void Bayer2Gray_( const Mat& srcmat, Mat& dstmat, int code ) } size = dstmat.size(); - T* dst0 = (T*)dstmat.data; + T* dst0 = dstmat.ptr(); int dst_step = (int)(dstmat.step/sizeof(T)); if( size.height > 2 ) for( int i = 0; i < size.width; i++ ) @@ -676,7 +676,7 @@ public: int dcn2 = dcn << 1; int bayer_step = (int)(srcmat.step/sizeof(T)); - const T* bayer0 = reinterpret_cast(srcmat.data) + bayer_step * range.start; + const T* bayer0 = srcmat.ptr() + bayer_step * range.start; int dst_step = (int)(dstmat.step/sizeof(T)); T* dst0 = reinterpret_cast(dstmat.data) + (range.start + 1) * dst_step + dcn + 1; @@ -893,7 +893,7 @@ static void Bayer2RGB_( const Mat& srcmat, Mat& dstmat, int code ) // filling the first and the last rows size = dstmat.size(); - T* dst0 = (T*)dstmat.data; + T* dst0 = dstmat.ptr(); if( size.height > 2 ) for( int i = 0; i < size.width*dcn; i++ ) { @@ -910,9 +910,9 @@ static void Bayer2RGB_( const Mat& srcmat, Mat& dstmat, int code ) static void Bayer2RGB_VNG_8u( const Mat& srcmat, Mat& dstmat, int code ) { - const uchar* bayer = srcmat.data; + const uchar* bayer = srcmat.ptr(); int bstep = (int)srcmat.step; - uchar* dst = dstmat.data; + uchar* dst = dstmat.ptr(); int dststep = (int)dstmat.step; Size size = srcmat.size(); @@ -1482,7 +1482,7 @@ public: int sstep = int(src.step / src.elemSize1()), dstep = int(dst.step / dst.elemSize1()); SIMDInterpolator vecOp; - const T* S = reinterpret_cast(src.data + (range.start + 1) * src.step) + 1; + const T* S = src.ptr(range.start + 1) + 1; T* D = reinterpret_cast(dst.data + (range.start + 1) * dst.step) + dcn; if (range.start % 2) @@ -1589,8 +1589,8 @@ static void Bayer2RGB_EdgeAware_T(const Mat& src, Mat& dst, int code) size = dst.size(); size.width *= dst.channels(); size_t dstep = dst.step / dst.elemSize1(); - T* firstRow = reinterpret_cast(dst.data); - T* lastRow = reinterpret_cast(dst.data) + (size.height-1) * dstep; + T* firstRow = dst.ptr(); + T* lastRow = dst.ptr() + (size.height-1) * dstep; if (size.height > 2) { diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 80b1e9b33..c3579fee1 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -237,7 +237,7 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx pBuffer = ippsMalloc_8u(bufferSize); if (NULL == pBuffer) IPP_RETURN_ERROR - sts = ippiFilterScharrHorizMaskBorder_8u16s_C1R(src.data, (int)src.step, (Ipp16s *)dst.data, (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); + sts = ippiFilterScharrHorizMaskBorder_8u16s_C1R(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); } else { @@ -246,7 +246,7 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx pBuffer = ippsMalloc_8u(bufferSize); if (NULL == pBuffer) IPP_RETURN_ERROR - sts = ippiFilterScharrVertMaskBorder_8u16s_C1R(src.data, (int)src.step, (Ipp16s *)dst.data, (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); + sts = ippiFilterScharrVertMaskBorder_8u16s_C1R(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); } ippsFree(pBuffer); } @@ -260,7 +260,7 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx pBuffer = ippsMalloc_8u(bufferSize); if (NULL == pBuffer) IPP_RETURN_ERROR - sts = ippiFilterScharrHorizMaskBorder_16s_C1R((Ipp16s *)src.data, (int)src.step, (Ipp16s *)dst.data, (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); + sts = ippiFilterScharrHorizMaskBorder_16s_C1R(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); } else { @@ -269,7 +269,7 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx pBuffer = ippsMalloc_8u(bufferSize); if (NULL == pBuffer) IPP_RETURN_ERROR - sts = ippiFilterScharrVertMaskBorder_16s_C1R((Ipp16s *)src.data, (int)src.step, (Ipp16s *)dst.data, (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); + sts = ippiFilterScharrVertMaskBorder_16s_C1R(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); } ippsFree(pBuffer); } @@ -283,7 +283,7 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx pBuffer = ippsMalloc_8u(bufferSize); if (NULL == pBuffer) IPP_RETURN_ERROR - sts = ippiFilterScharrHorizMaskBorder_32f_C1R((Ipp32f *)src.data, (int)src.step, (Ipp32f *)dst.data, (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); + sts = ippiFilterScharrHorizMaskBorder_32f_C1R(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); } else { @@ -292,14 +292,14 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx pBuffer = ippsMalloc_8u(bufferSize); if (NULL == pBuffer) IPP_RETURN_ERROR - sts = ippiFilterScharrVertMaskBorder_32f_C1R((Ipp32f *)src.data, (int)src.step, (Ipp32f *)dst.data, (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); + sts = ippiFilterScharrVertMaskBorder_32f_C1R(src.ptr(), (int)src.step, dst.ptr(), (int)dst.step, roiSize, ippMskSize3x3, ippiBorderType, 0, pBuffer); } ippsFree(pBuffer); if (sts < 0) IPP_RETURN_ERROR; if (FLT_EPSILON < fabs(scale - 1.0)) - sts = ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, roiSize); + sts = ippiMulC_32f_C1R(dst.ptr(), (int)dst.step, (Ipp32f)scale, dst.ptr(), (int)dst.step, roiSize); } return (0 <= sts); } @@ -340,16 +340,16 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx if (0 > ippiFilterScharrVertGetBufferSize_8u16s_C1R(roi,&bufSize)) return false; buffer.allocate(bufSize); - return (0 <= ippiFilterScharrVertBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + return (0 <= ippiFilterScharrVertBorder_8u16s_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); } if ((dx == 0) && (dy == 1)) { if (0 > ippiFilterScharrHorizGetBufferSize_8u16s_C1R(roi,&bufSize)) return false; buffer.allocate(bufSize); - return (0 <= ippiFilterScharrHorizBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + return (0 <= ippiFilterScharrHorizBorder_8u16s_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); } return false; } @@ -369,8 +369,8 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx return false; buffer.allocate(bufSize); - if (0 > ippiFilterScharrVertBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), + if (0 > ippiFilterScharrVertBorder_32f_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) { return false; @@ -378,8 +378,8 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx if (scale != 1) /* IPP is fast, so MulC produce very little perf degradation.*/ - //ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f*)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); - ippiMulC_32f_C1R((Ipp32f*)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f*)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + //ippiMulC_32f_C1IR((Ipp32f)scale, dst.ptr(), (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + ippiMulC_32f_C1R(dst.ptr(), (int)dst.step, (Ipp32f)scale, dst.ptr(), (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); return true; } if ((dx == 0) && (dy == 1)) @@ -388,13 +388,13 @@ static bool IPPDerivScharr(InputArray _src, OutputArray _dst, int ddepth, int dx return false; buffer.allocate(bufSize); - if (0 > ippiFilterScharrHorizBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), + if (0 > ippiFilterScharrHorizBorder_32f_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) return false; if (scale != 1) - ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + ippiMulC_32f_C1R(dst.ptr(), (int)dst.step, (Ipp32f)scale, dst.ptr(), (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); return true; } } @@ -431,8 +431,8 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelNegVertBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelNegVertBorder_8u16s_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR return true; @@ -444,8 +444,8 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelHorizBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelHorizBorder_8u16s_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR return true; @@ -458,8 +458,8 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelVertSecondBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelVertSecondBorder_8u16s_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR return true; @@ -471,8 +471,8 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelHorizSecondBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelHorizSecondBorder_8u16s_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR return true; @@ -489,12 +489,12 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelNegVertBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelNegVertBorder_32f_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR if(scale != 1) - ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + ippiMulC_32f_C1R(dst.ptr(), (int)dst.step, (Ipp32f)scale, dst.ptr(), (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); return true; } @@ -503,12 +503,12 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, if (0 > ippiFilterSobelHorizGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelHorizBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelHorizBorder_32f_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR if(scale != 1) - ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + ippiMulC_32f_C1R(dst.ptr(), (int)dst.step, (Ipp32f)scale, dst.ptr(), (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); return true; } #endif @@ -519,12 +519,12 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelVertSecondBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelVertSecondBorder_32f_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR if(scale != 1) - ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + ippiMulC_32f_C1R(dst.ptr(), (int)dst.step, (Ipp32f)scale, dst.ptr(), (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); return true; } @@ -534,13 +534,13 @@ static bool IPPDerivSobel(InputArray _src, OutputArray _dst, int ddepth, int dx, IPP_RETURN_ERROR buffer.allocate(bufSize); - if (0 > ippiFilterSobelHorizSecondBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + if (0 > ippiFilterSobelHorizSecondBorder_32f_C1R(src.ptr(), (int)src.step, + dst.ptr(), (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) IPP_RETURN_ERROR if(scale != 1) - ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + ippiMulC_32f_C1R(dst.ptr(), (int)dst.step, (Ipp32f)scale, dst.ptr(), (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); return true; } #endif @@ -724,7 +724,7 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, if (borderTypeIpp >= 0 && ippiFilterLaplacianGetBufferSize_##ippfavor##_C1R(roisize, masksize, &bufsize) >= 0) \ { \ Ipp8u * buffer = ippsMalloc_8u(bufsize); \ - status = ippiFilterLaplacianBorder_##ippfavor##_C1R((const ippsrctype *)src.data, (int)src.step, (ippdsttype *)dst.data, \ + status = ippiFilterLaplacianBorder_##ippfavor##_C1R(src.ptr(), (int)src.step, dst.ptr(), \ (int)dst.step, roisize, masksize, borderTypeIpp, 0, buffer); \ ippsFree(buffer); \ } \ @@ -736,18 +736,18 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, IPP_FILTER_LAPLACIAN(Ipp8u, Ipp16s, 8u16s); if (needScale && status >= 0) - status = ippiMulC_16s_C1IRSfs((Ipp16s)iscale, (Ipp16s *)dst.data, (int)dst.step, roisize, 0); + status = ippiMulC_16s_C1IRSfs((Ipp16s)iscale, dst.ptr(), (int)dst.step, roisize, 0); if (needDelta && status >= 0) - status = ippiAddC_16s_C1IRSfs((Ipp16s)idelta, (Ipp16s *)dst.data, (int)dst.step, roisize, 0); + status = ippiAddC_16s_C1IRSfs((Ipp16s)idelta, dst.ptr(), (int)dst.step, roisize, 0); } else if (sdepth == CV_32F && ddepth == CV_32F) { IPP_FILTER_LAPLACIAN(Ipp32f, Ipp32f, 32f); if (needScale && status >= 0) - status = ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, roisize); + status = ippiMulC_32f_C1IR((Ipp32f)scale, dst.ptr(), (int)dst.step, roisize); if (needDelta && status >= 0) - status = ippiAddC_32f_C1IR((Ipp32f)delta, (Ipp32f *)dst.data, (int)dst.step, roisize); + status = ippiAddC_32f_C1IR((Ipp32f)delta, dst.ptr(), (int)dst.step, roisize); } CV_SUPPRESS_DEPRECATED_END @@ -805,7 +805,7 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, Mat src = _src.getMat(), dst = _dst.getMat(); int y = fx->start(src), dsty = 0, dy = 0; fy->start(src); - const uchar* sptr = src.data + y*src.step; + const uchar* sptr = src.ptr(y); int dy0 = std::min(std::max((int)(STRIPE_SIZE/(CV_ELEM_SIZE(stype)*src.cols)), 1), src.rows); Mat d2x( dy0 + kd.rows - 1, src.cols, wtype ); @@ -813,8 +813,8 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, for( ; dsty < src.rows; sptr += dy0*src.step, dsty += dy ) { - fx->proceed( sptr, (int)src.step, dy0, d2x.data, (int)d2x.step ); - dy = fy->proceed( sptr, (int)src.step, dy0, d2y.data, (int)d2y.step ); + fx->proceed( sptr, (int)src.step, dy0, d2x.ptr(), (int)d2x.step ); + dy = fy->proceed( sptr, (int)src.step, dy0, d2y.ptr(), (int)d2y.step ); if( dy > 0 ) { Mat dstripe = dst.rowRange(dsty, dsty + dy); diff --git a/modules/imgproc/src/distransform.cpp b/modules/imgproc/src/distransform.cpp index 26f0e1df1..6574471c1 100644 --- a/modules/imgproc/src/distransform.cpp +++ b/modules/imgproc/src/distransform.cpp @@ -75,7 +75,7 @@ distanceTransform_3x3( const Mat& _src, Mat& _temp, Mat& _dist, const float* met const int DIAG_DIST = CV_FLT_TO_FIX( metrics[1], DIST_SHIFT ); const float scale = 1.f/(1 << DIST_SHIFT); - const uchar* src = _src.data; + const uchar* src = _src.ptr(); int* temp = _temp.ptr(); float* dist = _dist.ptr(); int srcstep = (int)(_src.step/sizeof(src[0])); @@ -149,7 +149,7 @@ distanceTransform_5x5( const Mat& _src, Mat& _temp, Mat& _dist, const float* met const int LONG_DIST = CV_FLT_TO_FIX( metrics[2], DIST_SHIFT ); const float scale = 1.f/(1 << DIST_SHIFT); - const uchar* src = _src.data; + const uchar* src = _src.ptr(); int* temp = _temp.ptr(); float* dist = _dist.ptr(); int srcstep = (int)(_src.step/sizeof(src[0])); @@ -240,7 +240,7 @@ distanceTransformEx_5x5( const Mat& _src, Mat& _temp, Mat& _dist, Mat& _labels, const int LONG_DIST = CV_FLT_TO_FIX( metrics[2], DIST_SHIFT ); const float scale = 1.f/(1 << DIST_SHIFT); - const uchar* src = _src.data; + const uchar* src = _src.ptr(); int* temp = _temp.ptr(); float* dist = _dist.ptr(); int* labels = _labels.ptr(); @@ -609,8 +609,8 @@ distanceATS_L1_8u( const Mat& src, Mat& dst ) uchar lut[256]; int x, y; - const uchar *sbase = src.data; - uchar *dbase = dst.data; + const uchar *sbase = src.ptr(); + uchar *dbase = dst.ptr(); int srcstep = (int)src.step; int dststep = (int)dst.step; diff --git a/modules/imgproc/src/featureselect.cpp b/modules/imgproc/src/featureselect.cpp index a50b704e8..769624cb9 100644 --- a/modules/imgproc/src/featureselect.cpp +++ b/modules/imgproc/src/featureselect.cpp @@ -329,7 +329,7 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners, for( i = 0; i < total; i++ ) { - int ofs = (int)((const uchar*)tmpCorners[i] - eig.data); + int ofs = (int)((const uchar*)tmpCorners[i] - eig.ptr()); int y = (int)(ofs / eig.step); int x = (int)((ofs - y*eig.step)/sizeof(float)); @@ -388,7 +388,7 @@ void cv::goodFeaturesToTrack( InputArray _image, OutputArray _corners, { for( i = 0; i < total; i++ ) { - int ofs = (int)((const uchar*)tmpCorners[i] - eig.data); + int ofs = (int)((const uchar*)tmpCorners[i] - eig.ptr()); int y = (int)(ofs / eig.step); int x = (int)((ofs - y*eig.step)/sizeof(float)); diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 4928a16d2..bb2040bf8 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -410,10 +410,10 @@ void FilterEngine::apply(const Mat& src, Mat& dst, dstOfs.y + srcRoi.height <= dst.rows ); int y = start(src, srcRoi, isolated); - proceed( src.data + y*src.step + proceed( src.ptr(y) + srcRoi.x*src.elemSize(), (int)src.step, endY - startY, - dst.data + dstOfs.y*dst.step + + dst.ptr(dstOfs.y) + dstOfs.x*dst.elemSize(), (int)dst.step ); } @@ -432,7 +432,7 @@ int cv::getKernelType(InputArray filter_kernel, Point anchor) Mat kernel; _kernel.convertTo(kernel, CV_64F); - const double* coeffs = (double*)kernel.data; + const double* coeffs = kernel.ptr(); double sum = 0; int type = KERNEL_SMOOTH + KERNEL_INTEGER; if( (_kernel.rows == 1 || _kernel.cols == 1) && @@ -513,7 +513,7 @@ struct RowVec_8u32s int k, ksize = kernel.rows + kernel.cols - 1; for( k = 0; k < ksize; k++ ) { - int v = ((const int*)kernel.data)[k]; + int v = kernel.ptr()[k]; if( v < SHRT_MIN || v > SHRT_MAX ) { smallValues = false; @@ -529,7 +529,7 @@ struct RowVec_8u32s int i = 0, k, _ksize = kernel.rows + kernel.cols - 1; int* dst = (int*)_dst; - const int* _kx = (const int*)kernel.data; + const int* _kx = kernel.ptr(); width *= cn; if( smallValues ) @@ -605,7 +605,7 @@ struct SymmRowSmallVec_8u32s int k, ksize = kernel.rows + kernel.cols - 1; for( k = 0; k < ksize; k++ ) { - int v = ((const int*)kernel.data)[k]; + int v = kernel.ptr()[k]; if( v < SHRT_MIN || v > SHRT_MAX ) { smallValues = false; @@ -622,7 +622,7 @@ struct SymmRowSmallVec_8u32s int i = 0, j, k, _ksize = kernel.rows + kernel.cols - 1; int* dst = (int*)_dst; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; - const int* kx = (const int*)kernel.data + _ksize/2; + const int* kx = kernel.ptr() + _ksize/2; if( !smallValues ) return 0; @@ -941,7 +941,7 @@ struct SymmColumnVec_32s8u return 0; int ksize2 = (kernel.rows + kernel.cols - 1)/2; - const float* ky = (const float*)kernel.data + ksize2; + const float* ky = kernel.ptr() + ksize2; int i = 0, k; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; const int** src = (const int**)_src; @@ -1089,7 +1089,7 @@ struct SymmColumnSmallVec_32s16s return 0; int ksize2 = (kernel.rows + kernel.cols - 1)/2; - const float* ky = (const float*)kernel.data + ksize2; + const float* ky = kernel.ptr() + ksize2; int i = 0; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; const int** src = (const int**)_src; @@ -1222,7 +1222,7 @@ struct RowVec_16s32f int i = 0, k, _ksize = kernel.rows + kernel.cols - 1; float* dst = (float*)_dst; - const float* _kx = (const float*)kernel.data; + const float* _kx = kernel.ptr(); width *= cn; for( ; i <= width - 8; i += 8 ) @@ -1271,7 +1271,7 @@ struct SymmColumnVec_32f16s return 0; int ksize2 = (kernel.rows + kernel.cols - 1)/2; - const float* ky = (const float*)kernel.data + ksize2; + const float* ky = kernel.ptr() + ksize2; int i = 0, k; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; const float** src = (const float**)_src; @@ -1431,7 +1431,7 @@ struct RowVec_32f int _ksize = kernel.rows + kernel.cols - 1; const float* src0 = (const float*)_src; float* dst = (float*)_dst; - const float* _kx = (const float*)kernel.data; + const float* _kx = kernel.ptr(); if( !haveSSE ) return 0; @@ -1519,7 +1519,7 @@ struct SymmRowSmallVec_32f float* dst = (float*)_dst; const float* src = (const float*)_src + (_ksize/2)*cn; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; - const float* kx = (const float*)kernel.data + _ksize/2; + const float* kx = kernel.ptr() + _ksize/2; width *= cn; if( symmetrical ) @@ -1711,7 +1711,7 @@ struct SymmColumnVec_32f return 0; int ksize2 = (kernel.rows + kernel.cols - 1)/2; - const float* ky = (const float*)kernel.data + ksize2; + const float* ky = kernel.ptr() + ksize2; int i = 0, k; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; const float** src = (const float**)_src; @@ -1851,7 +1851,7 @@ struct SymmColumnSmallVec_32f return 0; int ksize2 = (kernel.rows + kernel.cols - 1)/2; - const float* ky = (const float*)kernel.data + ksize2; + const float* ky = kernel.ptr() + ksize2; int i = 0; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; const float** src = (const float**)_src; @@ -2241,7 +2241,7 @@ template struct RowFilter : public BaseRo void operator()(const uchar* src, uchar* dst, int width, int cn) { int _ksize = ksize; - const DT* kx = (const DT*)kernel.data; + const DT* kx = kernel.ptr
(); const ST* S; DT* D = (DT*)dst; int i, k; @@ -2299,7 +2299,7 @@ template struct SymmRowSmallFilter : void operator()(const uchar* src, uchar* dst, int width, int cn) { int ksize2 = this->ksize/2, ksize2n = ksize2*cn; - const DT* kx = (const DT*)this->kernel.data + ksize2; + const DT* kx = this->kernel.template ptr
() + ksize2; bool symmetrical = (this->symmetryType & KERNEL_SYMMETRICAL) != 0; DT* D = (DT*)dst; int i = this->vecOp(src, dst, width, cn), j, k; @@ -2437,7 +2437,7 @@ template struct ColumnFilter : public BaseColumnFilte void operator()(const uchar** src, uchar* dst, int dststep, int count, int width) { - const ST* ky = (const ST*)kernel.data; + const ST* ky = kernel.template ptr(); ST _delta = delta; int _ksize = ksize; int i, k; @@ -2501,7 +2501,7 @@ template struct SymmColumnFilter : public ColumnFilte void operator()(const uchar** src, uchar* dst, int dststep, int count, int width) { int ksize2 = this->ksize/2; - const ST* ky = (const ST*)this->kernel.data + ksize2; + const ST* ky = this->kernel.template ptr() + ksize2; int i, k; bool symmetrical = (symmetryType & KERNEL_SYMMETRICAL) != 0; ST _delta = this->delta; @@ -2607,7 +2607,7 @@ struct SymmColumnSmallFilter : public SymmColumnFilter void operator()(const uchar** src, uchar* dst, int dststep, int count, int width) { int ksize2 = this->ksize/2; - const ST* ky = (const ST*)this->kernel.data + ksize2; + const ST* ky = this->kernel.template ptr() + ksize2; int i; bool symmetrical = (this->symmetryType & KERNEL_SYMMETRICAL) != 0; bool is_1_2_1 = ky[0] == 1 && ky[1] == 2; @@ -3021,7 +3021,7 @@ void preprocess2DKernel( const Mat& kernel, std::vector& coords, std::vec for( i = k = 0; i < kernel.rows; i++ ) { - const uchar* krow = kernel.data + kernel.step*i; + const uchar* krow = kernel.ptr(i); for( j = 0; j < kernel.cols; j++ ) { if( ktype == CV_8U ) diff --git a/modules/imgproc/src/floodfill.cpp b/modules/imgproc/src/floodfill.cpp index 9e5067a87..70a8d1eb9 100644 --- a/modules/imgproc/src/floodfill.cpp +++ b/modules/imgproc/src/floodfill.cpp @@ -131,7 +131,7 @@ floodFill_CnIR( Mat& image, Point seed, _Tp newVal, ConnectedComp* region, int flags, std::vector* buffer ) { - _Tp* img = (_Tp*)(image.data + image.step * seed.y); + _Tp* img = image.ptr<_Tp>(seed.y); Size roi = image.size(); int i, L, R; int area = 0; @@ -180,7 +180,7 @@ floodFill_CnIR( Mat& image, Point seed, for( k = 0; k < 3; k++ ) { dir = data[k][0]; - img = (_Tp*)(image.data + (YC + dir) * image.step); + img = image.ptr<_Tp>(YC + dir); int left = data[k][1]; int right = data[k][2]; @@ -283,9 +283,9 @@ floodFillGrad_CnIR( Mat& image, Mat& msk, std::vector* buffer ) { int step = (int)image.step, maskStep = (int)msk.step; - uchar* pImage = image.data; + uchar* pImage = image.ptr(); _Tp* img = (_Tp*)(pImage + step*seed.y); - uchar* pMask = msk.data + maskStep + sizeof(_MTp); + uchar* pMask = msk.ptr() + maskStep + sizeof(_MTp); _MTp* mask = (_MTp*)(pMask + maskStep*seed.y); int i, L, R; int area = 0; @@ -508,7 +508,7 @@ int cv::floodFill( InputOutputArray _image, InputOutputArray _mask, if( is_simple ) { size_t elem_size = img.elemSize(); - const uchar* seed_ptr = img.data + img.step*seedPoint.y + elem_size*seedPoint.x; + const uchar* seed_ptr = img.ptr(seedPoint.y) + elem_size*seedPoint.x; size_t k = 0; for(; k < elem_size; k++) @@ -549,8 +549,8 @@ int cv::floodFill( InputOutputArray _image, InputOutputArray _mask, CV_Assert( mask.type() == CV_8U ); } - memset( mask.data, 1, mask.cols ); - memset( mask.data + mask.step*(mask.rows-1), 1, mask.cols ); + memset( mask.ptr(), 1, mask.cols ); + memset( mask.ptr(mask.rows-1), 1, mask.cols ); for( i = 1; i <= size.height; i++ ) { diff --git a/modules/imgproc/src/geometry.cpp b/modules/imgproc/src/geometry.cpp index 5d1fa789b..2d95853c8 100644 --- a/modules/imgproc/src/geometry.cpp +++ b/modules/imgproc/src/geometry.cpp @@ -107,7 +107,7 @@ double cv::pointPolygonTest( InputArray _contour, Point2f pt, bool measureDist ) if( total == 0 ) return measureDist ? -DBL_MAX : -1; - const Point* cnt = (const Point*)contour.data; + const Point* cnt = contour.ptr(); const Point2f* cntf = (const Point2f*)cnt; if( !is_float && !measureDist && ip.x == pt.x && ip.y == pt.y ) diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index 1006897e4..4171770c3 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -154,7 +154,7 @@ static void histPrepareImages( const Mat* images, int nimages, const int* channe deltas[i*2+1] = (int)(images[j].step/esz1 - imsize.width*deltas[i*2]); } - if( mask.data ) + if( !mask.empty() ) { CV_Assert( mask.size() == imsize && mask.channels() == 1 ); isContinuous = isContinuous && mask.isContinuous(); @@ -753,7 +753,7 @@ calcHist_( std::vector& _ptrs, const std::vector& _deltas, { T** ptrs = (T**)&_ptrs[0]; const int* deltas = &_deltas[0]; - uchar* H = hist.data; + uchar* H = hist.ptr(); int i, x; const uchar* mask = _ptrs[dims]; int mstep = _deltas[dims*2 + 1]; @@ -988,7 +988,7 @@ calcHist_8u( std::vector& _ptrs, const std::vector& _deltas, { uchar** ptrs = &_ptrs[0]; const int* deltas = &_deltas[0]; - uchar* H = hist.data; + uchar* H = hist.ptr(); int x; const uchar* mask = _ptrs[dims]; int mstep = _deltas[dims*2 + 1]; @@ -1192,8 +1192,8 @@ public: Mat phist(hist->size(), hist->type(), Scalar::all(0)); IppStatus status = ippiHistogramEven_8u_C1R( - src->data + src->step * range.start, (int)src->step, ippiSize(src->cols, range.end - range.start), - (Ipp32s *)phist.data, (Ipp32s *)*levels, histSize, low, high); + src->ptr(range.start), (int)src->step, ippiSize(src->cols, range.end - range.start), + phist.ptr(), (Ipp32s *)*levels, histSize, low, high); if (status < 0) { @@ -1227,7 +1227,7 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels, CV_Assert(dims > 0 && histSize); - uchar* histdata = _hist.getMat().data; + const uchar* const histdata = _hist.getMat().ptr(); _hist.create(dims, histSize, CV_32F); Mat hist = _hist.getMat(), ihist = hist; ihist.flags = (ihist.flags & ~CV_MAT_TYPE_MASK)|CV_32S; @@ -1269,7 +1269,7 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels, std::vector uniranges; Size imsize; - CV_Assert( !mask.data || mask.type() == CV_8UC1 ); + CV_Assert( mask.empty() || mask.type() == CV_8UC1 ); histPrepareImages( images, nimages, channels, mask, dims, hist.size, ranges, uniform, ptrs, deltas, imsize, uniranges ); const double* _uniranges = uniform ? &uniranges[0] : 0; @@ -1442,7 +1442,7 @@ static void calcHist( const Mat* images, int nimages, const int* channels, std::vector uniranges; Size imsize; - CV_Assert( !mask.data || mask.type() == CV_8UC1 ); + CV_Assert( mask.empty() || mask.type() == CV_8UC1 ); histPrepareImages( images, nimages, channels, mask, dims, hist.hdr->size, ranges, uniform, ptrs, deltas, imsize, uniranges ); const double* _uniranges = uniform ? &uniranges[0] : 0; @@ -1586,7 +1586,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, { T** ptrs = (T**)&_ptrs[0]; const int* deltas = &_deltas[0]; - uchar* H = hist.data; + const uchar* H = hist.ptr(); int i, x; BT* bproj = (BT*)_ptrs[dims]; int bpstep = _deltas[dims*2 + 1]; @@ -1614,7 +1614,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, for( x = 0; x < imsize.width; x++, p0 += d0 ) { int idx = cvFloor(*p0*a + b); - bproj[x] = (unsigned)idx < (unsigned)sz ? saturate_cast(((float*)H)[idx]*scale) : 0; + bproj[x] = (unsigned)idx < (unsigned)sz ? saturate_cast(((const float*)H)[idx]*scale) : 0; } } } @@ -1637,7 +1637,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, int idx1 = cvFloor(*p1*a1 + b1); bproj[x] = (unsigned)idx0 < (unsigned)sz0 && (unsigned)idx1 < (unsigned)sz1 ? - saturate_cast(((float*)(H + hstep0*idx0))[idx1]*scale) : 0; + saturate_cast(((const float*)(H + hstep0*idx0))[idx1]*scale) : 0; } } } @@ -1665,7 +1665,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, bproj[x] = (unsigned)idx0 < (unsigned)sz0 && (unsigned)idx1 < (unsigned)sz1 && (unsigned)idx2 < (unsigned)sz2 ? - saturate_cast(((float*)(H + hstep0*idx0 + hstep1*idx1))[idx2]*scale) : 0; + saturate_cast(((const float*)(H + hstep0*idx0 + hstep1*idx1))[idx2]*scale) : 0; } } } @@ -1675,7 +1675,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, { for( x = 0; x < imsize.width; x++ ) { - uchar* Hptr = H; + const uchar* Hptr = H; for( i = 0; i < dims; i++ ) { int idx = cvFloor(*ptrs[i]*uniranges[i*2] + uniranges[i*2+1]); @@ -1686,7 +1686,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, } if( i == dims ) - bproj[x] = saturate_cast(*(float*)Hptr*scale); + bproj[x] = saturate_cast(*(const float*)Hptr*scale); else { bproj[x] = 0; @@ -1710,7 +1710,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, { for( x = 0; x < imsize.width; x++ ) { - uchar* Hptr = H; + const uchar* Hptr = H; for( i = 0; i < dims; i++ ) { float v = (float)*ptrs[i]; @@ -1728,7 +1728,7 @@ calcBackProj_( std::vector& _ptrs, const std::vector& _deltas, } if( i == dims ) - bproj[x] = saturate_cast(*(float*)Hptr*scale); + bproj[x] = saturate_cast(*(const float*)Hptr*scale); else { bproj[x] = 0; @@ -1751,7 +1751,7 @@ calcBackProj_8u( std::vector& _ptrs, const std::vector& _deltas, { uchar** ptrs = &_ptrs[0]; const int* deltas = &_deltas[0]; - uchar* H = hist.data; + const uchar* H = hist.ptr(); int i, x; uchar* bproj = _ptrs[dims]; int bpstep = _deltas[dims*2 + 1]; @@ -1813,7 +1813,7 @@ calcBackProj_8u( std::vector& _ptrs, const std::vector& _deltas, for( x = 0; x < imsize.width; x++, p0 += d0, p1 += d1 ) { size_t idx = tab[*p0] + tab[*p1 + 256]; - bproj[x] = idx < OUT_OF_RANGE ? saturate_cast(*(float*)(H + idx)*scale) : 0; + bproj[x] = idx < OUT_OF_RANGE ? saturate_cast(*(const float*)(H + idx)*scale) : 0; } } } @@ -1831,7 +1831,7 @@ calcBackProj_8u( std::vector& _ptrs, const std::vector& _deltas, for( x = 0; x < imsize.width; x++, p0 += d0, p1 += d1, p2 += d2 ) { size_t idx = tab[*p0] + tab[*p1 + 256] + tab[*p2 + 512]; - bproj[x] = idx < OUT_OF_RANGE ? saturate_cast(*(float*)(H + idx)*scale) : 0; + bproj[x] = idx < OUT_OF_RANGE ? saturate_cast(*(const float*)(H + idx)*scale) : 0; } } } @@ -1841,7 +1841,7 @@ calcBackProj_8u( std::vector& _ptrs, const std::vector& _deltas, { for( x = 0; x < imsize.width; x++ ) { - uchar* Hptr = H; + const uchar* Hptr = H; for( i = 0; i < dims; i++ ) { size_t idx = tab[*ptrs[i] + i*256]; @@ -1852,7 +1852,7 @@ calcBackProj_8u( std::vector& _ptrs, const std::vector& _deltas, } if( i == dims ) - bproj[x] = saturate_cast(*(float*)Hptr*scale); + bproj[x] = saturate_cast(*(const float*)Hptr*scale); else { bproj[x] = 0; @@ -1879,7 +1879,7 @@ void cv::calcBackProject( const Mat* images, int nimages, const int* channels, Size imsize; int dims = hist.dims == 2 && hist.size[1] == 1 ? 1 : hist.dims; - CV_Assert( dims > 0 && hist.data ); + CV_Assert( dims > 0 && !hist.empty() ); _backProject.create( images[0].size(), images[0].depth() ); Mat backProject = _backProject.getMat(); histPrepareImages( images, nimages, channels, backProject, dims, hist.size, ranges, @@ -2233,7 +2233,7 @@ void cv::calcBackProject( InputArrayOfArrays images, const std::vector& cha int hsz[CV_CN_MAX+1]; memcpy(hsz, &H0.size[0], H0.dims*sizeof(hsz[0])); hsz[H0.dims] = hcn; - H = Mat(H0.dims+1, hsz, H0.depth(), H0.data); + H = Mat(H0.dims+1, hsz, H0.depth(), H0.ptr()); } else H = H0; @@ -2281,8 +2281,8 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method ) for( size_t i = 0; i < it.nplanes; i++, ++it ) { - const float* h1 = (const float*)it.planes[0].data; - const float* h2 = (const float*)it.planes[1].data; + const float* h1 = it.planes[0].ptr(); + const float* h2 = it.planes[1].ptr(); len = it.planes[0].rows*it.planes[0].cols*H1.channels(); if( (method == CV_COMP_CHISQR) || (method == CV_COMP_CHISQR_ALT)) diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index dc98426b2..5d5dde27d 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -84,7 +84,7 @@ HoughLinesStandard( const Mat& img, float rho, float theta, CV_Assert( img.type() == CV_8UC1 ); - const uchar* image = img.data; + const uchar* image = img.ptr(); int step = (int)img.step; int width = img.cols; int height = img.rows; @@ -224,7 +224,7 @@ HoughLinesSDiv( const Mat& img, threshold = MIN( threshold, 255 ); - const uchar* image_src = img.data; + const uchar* image_src = img.ptr(); int step = (int)img.step; int w = img.cols; int h = img.rows; @@ -462,7 +462,7 @@ HoughLinesProbabilistic( Mat& image, trigtab[n*2+1] = (float)(sin((double)n*theta) * irho); } const float* ttab = &trigtab[0]; - uchar* mdata0 = mask.data; + uchar* mdata0 = mask.ptr(); std::vector nzloc; // stage 1. collect non-zero image points @@ -493,7 +493,7 @@ HoughLinesProbabilistic( Mat& image, Point point = nzloc[idx]; Point line_end[2]; float a, b; - int* adata = (int*)accum.data; + int* adata = accum.ptr(); int i = point.y, j = point.x, k, x0, y0, dx0, dy0, xflag; int good_line; const int shift = 16; @@ -626,7 +626,7 @@ HoughLinesProbabilistic( Mat& image, { if( good_line ) { - adata = (int*)accum.data; + adata = accum.ptr(); for( int n = 0; n < numangle; n++, adata += numrho ) { int r = cvRound( j1 * ttab[n*2] + i1 * ttab[n*2+1] ); @@ -787,7 +787,7 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method, } else { - cvSeqPushMulti(lines, lx.data, nlines); + cvSeqPushMulti(lines, lx.ptr(), nlines); } } @@ -1104,7 +1104,7 @@ static void seqToMat(const CvSeq* seq, OutputArray _arr) { _arr.create(1, seq->total, seq->flags, -1, true); Mat arr = _arr.getMat(); - cvCvtSeqToArray(seq, arr.data); + cvCvtSeqToArray(seq, arr.ptr()); } else _arr.release(); diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index b2619883e..83da00f7e 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -341,7 +341,7 @@ public: { uchar* D = dst.data + dst.step*y; int sy = std::min(cvFloor(y*ify), ssize.height-1); - const uchar* S = src.data + src.step*sy; + const uchar* S = src.ptr(sy); switch( pix_size ) { @@ -1265,7 +1265,7 @@ public: } if( k1 == ksize ) k0 = std::min(k0, k); // remember the first row that needs to be computed - srows[k] = (T*)(src.data + src.step*sy); + srows[k] = src.template ptr(sy); prev_sy[k] = sy; } @@ -1608,10 +1608,10 @@ public: continue; } - dx = vop((const T*)(src.data + src.step * sy0), D, w); + dx = vop(src.template ptr(sy0), D, w); for( ; dx < w; dx++ ) { - const T* S = (const T*)(src.data + src.step * sy0) + xofs[dx]; + const T* S = src.template ptr(sy0) + xofs[dx]; WT sum = 0; k = 0; #if CV_ENABLE_UNROLLED @@ -1635,7 +1635,7 @@ public: { if( sy0 + sy >= ssize.height ) break; - const T* S = (const T*)(src.data + src.step*(sy0 + sy)) + sx0; + const T* S = src.template ptr(sy0 + sy) + sx0; for( int sx = 0; sx < scale_x*cn; sx += cn ) { if( sx0 + sx >= ssize.width ) @@ -1713,7 +1713,7 @@ public: int sy = ytab[j].si; { - const T* S = (const T*)(src->data + src->step*sy); + const T* S = src->template ptr(sy); for( dx = 0; dx < dsize.width; dx++ ) buf[dx] = (WT)0; @@ -1775,7 +1775,7 @@ public: if( dy != prev_dy ) { - T* D = (T*)(dst->data + dst->step*prev_dy); + T* D = dst->template ptr(prev_dy); for( dx = 0; dx < dsize.width; dx++ ) { @@ -1792,7 +1792,7 @@ public: } { - T* D = (T*)(dst->data + dst->step*prev_dy); + T* D = dst->template ptr(prev_dy); for( dx = 0; dx < dsize.width; dx++ ) D[dx] = saturate_cast(sum[dx]); } @@ -1973,8 +1973,8 @@ public: CHECK_IPP_STATUS(getBufferSizeFunc(pSpec, dstSize, cn, &bufsize)); CHECK_IPP_STATUS(getSrcOffsetFunc(pSpec, dstOffset, &srcOffset)); - const Ipp8u* pSrc = (const Ipp8u*)src.data + (int)src.step[0] * srcOffset.y + srcOffset.x * cn * itemSize; - Ipp8u* pDst = (Ipp8u*)dst.data + (int)dst.step[0] * dstOffset.y + dstOffset.x * cn * itemSize; + const Ipp8u* pSrc = src.ptr(srcOffset.y) + srcOffset.x * cn * itemSize; + Ipp8u* pDst = dst.ptr(dstOffset.y) + dstOffset.x * cn * itemSize; AutoBuffer buf(bufsize + 64); uchar* bufptr = alignPtr((uchar*)buf, 32); @@ -2643,7 +2643,7 @@ static void remapNearest( const Mat& _src, Mat& _dst, const Mat& _xy, { Size ssize = _src.size(), dsize = _dst.size(); int cn = _src.channels(); - const T* S0 = (const T*)_src.data; + const T* S0 = _src.ptr(); size_t sstep = _src.step/sizeof(S0[0]); Scalar_ cval(saturate_cast(_borderValue[0]), saturate_cast(_borderValue[1]), @@ -2661,8 +2661,8 @@ static void remapNearest( const Mat& _src, Mat& _dst, const Mat& _xy, for( dy = 0; dy < dsize.height; dy++ ) { - T* D = (T*)(_dst.data + _dst.step*dy); - const short* XY = (const short*)(_xy.data + _xy.step*dy); + T* D = _dst.ptr(dy); + const short* XY = _xy.ptr(dy); if( cn == 1 ) { @@ -2759,7 +2759,7 @@ struct RemapVec_8u sstep > 0x8000 ) return 0; - const uchar *S0 = _src.data, *S1 = _src.data + _src.step; + const uchar *S0 = _src.ptr(), *S1 = _src.ptr(1); const short* wtab = cn == 1 ? (const short*)_wtab : &BilinearTab_iC4[0][0][0]; uchar* D = (uchar*)_dst; __m128i delta = _mm_set1_epi32(INTER_REMAP_COEF_SCALE/2); @@ -2963,7 +2963,7 @@ static void remapBilinear( const Mat& _src, Mat& _dst, const Mat& _xy, Size ssize = _src.size(), dsize = _dst.size(); int cn = _src.channels(); const AT* wtab = (const AT*)_wtab; - const T* S0 = (const T*)_src.data; + const T* S0 = _src.ptr(); size_t sstep = _src.step/sizeof(S0[0]); Scalar_ cval(saturate_cast(_borderValue[0]), saturate_cast(_borderValue[1]), @@ -2982,9 +2982,9 @@ static void remapBilinear( const Mat& _src, Mat& _dst, const Mat& _xy, for( dy = 0; dy < dsize.height; dy++ ) { - T* D = (T*)(_dst.data + _dst.step*dy); - const short* XY = (const short*)(_xy.data + _xy.step*dy); - const ushort* FXY = (const ushort*)(_fxy.data + _fxy.step*dy); + T* D = _dst.ptr(dy); + const short* XY = _xy.ptr(dy); + const ushort* FXY = _fxy.ptr(dy); int X0 = 0; bool prevInlier = false; @@ -3163,7 +3163,7 @@ static void remapBicubic( const Mat& _src, Mat& _dst, const Mat& _xy, Size ssize = _src.size(), dsize = _dst.size(); int cn = _src.channels(); const AT* wtab = (const AT*)_wtab; - const T* S0 = (const T*)_src.data; + const T* S0 = _src.ptr(); size_t sstep = _src.step/sizeof(S0[0]); Scalar_ cval(saturate_cast(_borderValue[0]), saturate_cast(_borderValue[1]), @@ -3183,9 +3183,9 @@ static void remapBicubic( const Mat& _src, Mat& _dst, const Mat& _xy, for( dy = 0; dy < dsize.height; dy++ ) { - T* D = (T*)(_dst.data + _dst.step*dy); - const short* XY = (const short*)(_xy.data + _xy.step*dy); - const ushort* FXY = (const ushort*)(_fxy.data + _fxy.step*dy); + T* D = _dst.ptr(dy); + const short* XY = _xy.ptr(dy); + const ushort* FXY = _fxy.ptr(dy); for( dx = 0; dx < dsize.width; dx++, D += cn ) { @@ -3268,7 +3268,7 @@ static void remapLanczos4( const Mat& _src, Mat& _dst, const Mat& _xy, Size ssize = _src.size(), dsize = _dst.size(); int cn = _src.channels(); const AT* wtab = (const AT*)_wtab; - const T* S0 = (const T*)_src.data; + const T* S0 = _src.ptr(); size_t sstep = _src.step/sizeof(S0[0]); Scalar_ cval(saturate_cast(_borderValue[0]), saturate_cast(_borderValue[1]), @@ -3288,9 +3288,9 @@ static void remapLanczos4( const Mat& _src, Mat& _dst, const Mat& _xy, for( dy = 0; dy < dsize.height; dy++ ) { - T* D = (T*)(_dst.data + _dst.step*dy); - const short* XY = (const short*)(_xy.data + _xy.step*dy); - const ushort* FXY = (const ushort*)(_fxy.data + _fxy.step*dy); + T* D = _dst.ptr(dy); + const short* XY = _xy.ptr(dy); + const ushort* FXY = _fxy.ptr(dy); for( dx = 0; dx < dsize.width; dx++, D += cn ) { @@ -3415,15 +3415,15 @@ public: if( nnfunc ) { - if( m1->type() == CV_16SC2 && !m2->data ) // the data is already in the right format + if( m1->type() == CV_16SC2 && m2->empty() ) // the data is already in the right format bufxy = (*m1)(Rect(x, y, bcols, brows)); else if( map_depth != CV_32F ) { for( y1 = 0; y1 < brows; y1++ ) { - short* XY = (short*)(bufxy.data + bufxy.step*y1); - const short* sXY = (const short*)(m1->data + m1->step*(y+y1)) + x*2; - const ushort* sA = (const ushort*)(m2->data + m2->step*(y+y1)) + x; + short* XY = bufxy.ptr(y1); + const short* sXY = m1->ptr(y+y1) + x*2; + const ushort* sA = m2->ptr(y+y1) + x; for( x1 = 0; x1 < bcols; x1++ ) { @@ -3439,9 +3439,9 @@ public: { for( y1 = 0; y1 < brows; y1++ ) { - short* XY = (short*)(bufxy.data + bufxy.step*y1); - const float* sX = (const float*)(m1->data + m1->step*(y+y1)) + x; - const float* sY = (const float*)(m2->data + m2->step*(y+y1)) + x; + short* XY = bufxy.ptr(y1); + const float* sX = m1->ptr(y+y1) + x; + const float* sY = m2->ptr(y+y1) + x; x1 = 0; #if CV_SSE2 @@ -3481,21 +3481,21 @@ public: Mat bufa(_bufa, Rect(0, 0, bcols, brows)); for( y1 = 0; y1 < brows; y1++ ) { - short* XY = (short*)(bufxy.data + bufxy.step*y1); - ushort* A = (ushort*)(bufa.data + bufa.step*y1); + short* XY = bufxy.ptr(y1); + ushort* A = bufa.ptr(y1); if( m1->type() == CV_16SC2 && (m2->type() == CV_16UC1 || m2->type() == CV_16SC1) ) { bufxy = (*m1)(Rect(x, y, bcols, brows)); - const ushort* sA = (const ushort*)(m2->data + m2->step*(y+y1)) + x; + const ushort* sA = m2->ptr(y+y1) + x; for( x1 = 0; x1 < bcols; x1++ ) A[x1] = (ushort)(sA[x1] & (INTER_TAB_SIZE2-1)); } else if( planar_input ) { - const float* sX = (const float*)(m1->data + m1->step*(y+y1)) + x; - const float* sY = (const float*)(m2->data + m2->step*(y+y1)) + x; + const float* sX = m1->ptr(y+y1) + x; + const float* sY = m2->ptr(y+y1) + x; x1 = 0; #if CV_SSE2 @@ -3548,7 +3548,7 @@ public: } else { - const float* sXY = (const float*)(m1->data + m1->step*(y+y1)) + x*2; + const float* sXY = m1->ptr(y+y1) + x*2; for( x1 = 0; x1 < bcols; x1++ ) { @@ -3650,7 +3650,7 @@ static bool ocl_remap(InputArray _src, OutputArray _dst, InputArray _map1, Input Mat scalar(1, 1, sctype, borderValue); ocl::KernelArg srcarg = ocl::KernelArg::ReadOnly(src), dstarg = ocl::KernelArg::WriteOnly(dst), map1arg = ocl::KernelArg::ReadOnlyNoSize(map1), - scalararg = ocl::KernelArg::Constant((void*)scalar.data, scalar.elemSize()); + scalararg = ocl::KernelArg::Constant((void*)scalar.ptr(), scalar.elemSize()); if (map2.empty()) k.args(srcarg, dstarg, map1arg, scalararg); @@ -3689,15 +3689,15 @@ public: int type = dst.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); if (borderType == BORDER_CONSTANT && - !IPPSet(borderValue, dstRoi.data, (int)dstRoi.step, dstRoiSize, cn, depth)) + !IPPSet(borderValue, dstRoi.ptr(), (int)dstRoi.step, dstRoiSize, cn, depth)) { *ok = false; return; } - if (ippFunc(src.data, ippiSize(src.size()), (int)src.step, srcRoiRect, - (const Ipp32f *)map1.data, (int)map1.step, (const Ipp32f *)map2.data, (int)map2.step, - dstRoi.data, (int)dstRoi.step, dstRoiSize, ippInterpolation) < 0) + if (ippFunc(src.ptr(), ippiSize(src.size()), (int)src.step, srcRoiRect, + map1.ptr(), (int)map1.step, map2.ptr(), (int)map2.step, + dstRoi.ptr(), (int)dstRoi.step, dstRoiSize, ippInterpolation) < 0) *ok = false; } @@ -3829,15 +3829,15 @@ void cv::remap( InputArray _src, OutputArray _dst, const Mat *m1 = &map1, *m2 = &map2; - if( (map1.type() == CV_16SC2 && (map2.type() == CV_16UC1 || map2.type() == CV_16SC1 || !map2.data)) || - (map2.type() == CV_16SC2 && (map1.type() == CV_16UC1 || map1.type() == CV_16SC1 || !map1.data)) ) + if( (map1.type() == CV_16SC2 && (map2.type() == CV_16UC1 || map2.type() == CV_16SC1 || map2.empty())) || + (map2.type() == CV_16SC2 && (map1.type() == CV_16UC1 || map1.type() == CV_16SC1 || map1.empty())) ) { if( map1.type() != CV_16SC2 ) std::swap(m1, m2); } else { - CV_Assert( ((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && !map2.data) || + CV_Assert( ((map1.type() == CV_32FC2 || map1.type() == CV_16SC2) && map2.empty()) || (map1.type() == CV_32FC1 && map2.type() == CV_32FC1) ); planar_input = map1.channels() == 1; } @@ -3861,7 +3861,7 @@ void cv::convertMaps( InputArray _map1, InputArray _map2, CV_Assert( (m1type == CV_16SC2 && (nninterpolate || m2type == CV_16UC1 || m2type == CV_16SC1)) || (m2type == CV_16SC2 && (nninterpolate || m1type == CV_16UC1 || m1type == CV_16SC1)) || (m1type == CV_32FC1 && m2type == CV_32FC1) || - (m1type == CV_32FC2 && !m2->data) ); + (m1type == CV_32FC2 && m2->empty()) ); if( m2type == CV_16SC2 ) { @@ -3888,7 +3888,7 @@ void cv::convertMaps( InputArray _map1, InputArray _map2, (m1type == CV_32FC2 && dstm1type == CV_16SC2))) ) { m1->convertTo( dstmap1, dstmap1.type() ); - if( dstmap2.data && dstmap2.type() == m2->type() ) + if( !dstmap2.empty() && dstmap2.type() == m2->type() ) m2->copyTo( dstmap2 ); return; } @@ -3907,8 +3907,8 @@ void cv::convertMaps( InputArray _map1, InputArray _map2, return; } - if( m1->isContinuous() && (!m2->data || m2->isContinuous()) && - dstmap1.isContinuous() && (!dstmap2.data || dstmap2.isContinuous()) ) + if( m1->isContinuous() && (m2->empty() || m2->isContinuous()) && + dstmap1.isContinuous() && (dstmap2.empty() || dstmap2.isContinuous()) ) { size.width *= size.height; size.height = 1; @@ -3918,13 +3918,13 @@ void cv::convertMaps( InputArray _map1, InputArray _map2, int x, y; for( y = 0; y < size.height; y++ ) { - const float* src1f = (const float*)(m1->data + m1->step*y); - const float* src2f = (const float*)(m2->data + m2->step*y); + const float* src1f = m1->ptr(y); + const float* src2f = m2->ptr(y); const short* src1 = (const short*)src1f; const ushort* src2 = (const ushort*)src2f; - float* dst1f = (float*)(dstmap1.data + dstmap1.step*y); - float* dst2f = (float*)(dstmap2.data + dstmap2.step*y); + float* dst1f = dstmap1.ptr(y); + float* dst2f = dstmap2.ptr(y); short* dst1 = (short*)dst1f; ushort* dst2 = (ushort*)dst2f; @@ -4135,7 +4135,7 @@ public: if( borderType == BORDER_CONSTANT ) { IppiSize setSize = { dst.cols, range.end - range.start }; - void *dataPointer = dst.data + dst.step[0] * range.start; + void *dataPointer = dst.ptr(range.start); if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) { *ok = false; @@ -4144,7 +4144,7 @@ public: } // Aug 2013: problem in IPP 7.1, 8.0 : sometimes function return ippStsCoeffErr - IppStatus status = func( src.data, srcsize, (int)src.step[0], srcroi, dst.data, + IppStatus status = func( src.ptr(), srcsize, (int)src.step[0], srcroi, dst.ptr(), (int)dst.step[0], dstroi, coeffs, mode ); if( status < 0) *ok = false; @@ -4502,7 +4502,7 @@ public: if( borderType == BORDER_CONSTANT ) { IppiSize setSize = {dst.cols, range.end - range.start}; - void *dataPointer = dst.data + dst.step[0] * range.start; + void *dataPointer = dst.ptr(range.start); if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) { *ok = false; @@ -4510,7 +4510,7 @@ public: } } - IppStatus status = func(src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode); + IppStatus status = func(src.ptr(), srcsize, (int)src.step[0], srcroi, dst.ptr(), (int)dst.step[0], dstroi, coeffs, mode); if (status != ippStsNoErr) *ok = false; } @@ -4629,7 +4629,7 @@ cv::Mat cv::getRotationMatrix2D( Point2f center, double angle, double scale ) double beta = sin(angle)*scale; Mat M(2, 3, CV_64F); - double* m = (double*)M.data; + double* m = M.ptr(); m[0] = alpha; m[1] = beta; @@ -4667,7 +4667,7 @@ cv::Mat cv::getRotationMatrix2D( Point2f center, double angle, double scale ) */ cv::Mat cv::getPerspectiveTransform( const Point2f src[], const Point2f dst[] ) { - Mat M(3, 3, CV_64F), X(8, 1, CV_64F, M.data); + Mat M(3, 3, CV_64F), X(8, 1, CV_64F, M.ptr()); double a[8][8], b[8]; Mat A(8, 8, CV_64F, a), B(8, 1, CV_64F, b); @@ -4687,7 +4687,7 @@ cv::Mat cv::getPerspectiveTransform( const Point2f src[], const Point2f dst[] ) } solve( A, B, X, DECOMP_SVD ); - ((double*)M.data)[8] = 1.; + M.ptr()[8] = 1.; return M; } @@ -4713,7 +4713,7 @@ cv::Mat cv::getPerspectiveTransform( const Point2f src[], const Point2f dst[] ) cv::Mat cv::getAffineTransform( const Point2f src[], const Point2f dst[] ) { - Mat M(2, 3, CV_64F), X(6, 1, CV_64F, M.data); + Mat M(2, 3, CV_64F), X(6, 1, CV_64F, M.ptr()); double a[6*6], b[6]; Mat A(6, 6, CV_64F, a), B(6, 1, CV_64F, b); @@ -4743,8 +4743,8 @@ void cv::invertAffineTransform(InputArray _matM, OutputArray __iM) if( matM.type() == CV_32F ) { - const float* M = (const float*)matM.data; - float* iM = (float*)_iM.data; + const float* M = matM.ptr(); + float* iM = _iM.ptr(); int step = (int)(matM.step/sizeof(M[0])), istep = (int)(_iM.step/sizeof(iM[0])); double D = M[0]*M[step+1] - M[1]*M[step]; @@ -4758,8 +4758,8 @@ void cv::invertAffineTransform(InputArray _matM, OutputArray __iM) } else if( matM.type() == CV_64F ) { - const double* M = (const double*)matM.data; - double* iM = (double*)_iM.data; + const double* M = matM.ptr(); + double* iM = _iM.ptr(); int step = (int)(matM.step/sizeof(M[0])), istep = (int)(_iM.step/sizeof(iM[0])); double D = M[0]*M[step+1] - M[1]*M[step]; @@ -4887,7 +4887,7 @@ cvConvertMaps( const CvArr* arr1, const CvArr* arr2, CvArr* dstarr1, CvArr* dsta { dstmap2 = cv::cvarrToMat(dstarr2); if( dstmap2.type() == CV_16SC1 ) - dstmap2 = cv::Mat(dstmap2.size(), CV_16UC1, dstmap2.data, dstmap2.step); + dstmap2 = cv::Mat(dstmap2.size(), CV_16UC1, dstmap2.ptr(), dstmap2.step); } cv::convertMaps( map1, map2, dstmap1, dstmap2, dstmap1.type(), false ); diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index d5f760591..65e874e00 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -476,7 +476,7 @@ void LineSegmentDetectorImpl::flsd(std::vector& lines, for(size_t i = 0, list_size = list.size(); i < list_size; ++i) { unsigned int adx = list[i].p.x + list[i].p.y * img_width; - if((used.data[adx] == NOTUSED) && (angles_data[adx] != NOTDEF)) + if((used.ptr()[adx] == NOTUSED) && (angles_data[adx] != NOTDEF)) { int reg_size; double reg_angle; @@ -640,7 +640,7 @@ void LineSegmentDetectorImpl::region_grow(const Point2i& s, std::vector(); + const Point2f* ptsf = contour.ptr(); CV_Assert( contour.depth() == CV_32S || contour.depth() == CV_32F ); @@ -338,7 +338,7 @@ static void momentsInTile( const Mat& img, double* moments ) for( y = 0; y < size.height; y++ ) { - const T* ptr = (const T*)(img.data + y*img.step); + const T* ptr = img.ptr(y); WT x0 = 0, x1 = 0, x2 = 0; MT x3 = 0; x = vop(ptr, size.width, x0, x1, x2, x3); @@ -690,7 +690,7 @@ 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); + HuMoments(m, hu.ptr()); } diff --git a/modules/imgproc/src/morph.cpp b/modules/imgproc/src/morph.cpp index fde70ef2c..9923f3b0d 100644 --- a/modules/imgproc/src/morph.cpp +++ b/modules/imgproc/src/morph.cpp @@ -1049,7 +1049,7 @@ cv::Mat cv::getStructuringElement(int shape, Size ksize, Point anchor) for( i = 0; i < ksize.height; i++ ) { - uchar* ptr = elem.data + i*elem.step; + uchar* ptr = elem.ptr(i); int j1 = 0, j2 = 0; if( shape == MORPH_RECT || (shape == MORPH_CROSS && i == anchor.y) ) @@ -1165,7 +1165,7 @@ static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kerne return false;\ IppiMorphState *pSpec = (IppiMorphState*)ippMalloc(specSize);\ Ipp8u *pBuffer = (Ipp8u*)ippMalloc(bufferSize);\ - if (0 > ippiMorphologyBorderInit_##flavor(roiSize.width, kernel.data, kernelSize, pSpec, pBuffer))\ + if (0 > ippiMorphologyBorderInit_##flavor(roiSize.width, kernel.ptr(), kernelSize, pSpec, pBuffer))\ {\ ippFree(pBuffer);\ ippFree(pSpec);\ @@ -1173,10 +1173,10 @@ static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kerne }\ bool ok = false;\ if (op == MORPH_ERODE)\ - ok = (0 <= ippiErodeBorder_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0],\ + ok = (0 <= ippiErodeBorder_##flavor(_src->ptr(), (int)_src->step[0], dst.ptr(), (int)dst.step[0],\ roiSize, ippBorderRepl, 0, pSpec, pBuffer));\ else\ - ok = (0 <= ippiDilateBorder_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0],\ + ok = (0 <= ippiDilateBorder_##flavor(_src->ptr(), (int)_src->step[0], dst.ptr(), (int)dst.step[0],\ roiSize, ippBorderRepl, 0, pSpec, pBuffer));\ ippFree(pBuffer);\ ippFree(pSpec);\ @@ -1192,19 +1192,19 @@ static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kerne {\ int specSize = 0;\ int bufferSize = 0;\ - if (0 > ippiMorphologyGetSize_##flavor( roiSize.width, kernel.data kernelSize, &specSize))\ + if (0 > ippiMorphologyGetSize_##flavor( roiSize.width, kernel.ptr() kernelSize, &specSize))\ return false;\ bool ok = false;\ IppiMorphState* pState = (IppiMorphState*)ippMalloc(specSize);\ - if (ippiMorphologyInit_##flavor(roiSize.width, kernel.data, kernelSize, point, pState) >= 0)\ + if (ippiMorphologyInit_##flavor(roiSize.width, kernel.ptr(), kernelSize, point, pState) >= 0)\ {\ if (op == MORPH_ERODE)\ - ok = ippiErodeBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0],\ - (Ipp##data_type *)dst.data, (int)dst.step[0],\ + ok = ippiErodeBorderReplicate_##flavor(_src->ptr(), (int)_src->step[0],\ + dst.ptr(), (int)dst.step[0],\ roiSize, ippBorderRepl, pState ) >= 0;\ else\ - ok = ippiDilateBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0],\ - (Ipp##data_type *)dst.data, (int)dst.step[0],\ + ok = ippiDilateBorderReplicate_##flavor(_src->ptr(), (int)_src->step[0],\ + dst.ptr(), (int)dst.step[0],\ roiSize, ippBorderRepl, pState ) >= 0;\ }\ ippFree(pState);\ @@ -1239,8 +1239,8 @@ static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kerne AutoBuffer buf(bufSize + 64);\ uchar* buffer = alignPtr((uchar*)buf, 32);\ if (op == MORPH_ERODE)\ - return (0 <= ippiFilterMinBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0], roiSize, kernelSize, point, buffer));\ - return (0 <= ippiFilterMaxBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0], roiSize, kernelSize, point, buffer));\ + return (0 <= ippiFilterMinBorderReplicate_##flavor(_src->ptr(), (int)_src->step[0], dst.ptr(), (int)dst.step[0], roiSize, kernelSize, point, buffer));\ + return (0 <= ippiFilterMaxBorderReplicate_##flavor(_src->ptr(), (int)_src->step[0], dst.ptr(), (int)dst.step[0], roiSize, kernelSize, point, buffer));\ }\ break; @@ -1298,7 +1298,7 @@ static bool IPPMorphOp(int op, InputArray _src, OutputArray _dst, } } - Size ksize = kernel.data ? kernel.size() : Size(3,3); + Size ksize = !kernel.empty() ? kernel.size() : Size(3,3); _dst.create( src.size(), src.type() ); Mat dst = _dst.getMat(); @@ -1310,7 +1310,7 @@ static bool IPPMorphOp(int op, InputArray _src, OutputArray _dst, } bool rectKernel = false; - if( !kernel.data ) + if( kernel.empty() ) { ksize = Size(1+iterations*2,1+iterations*2); anchor = Point(iterations, iterations); @@ -1502,7 +1502,7 @@ static bool ocl_morphOp(InputArray _src, OutputArray _dst, InputArray _kernel, int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type), esz = CV_ELEM_SIZE(type); Mat kernel = _kernel.getMat(); - Size ksize = kernel.data ? kernel.size() : Size(3, 3), ssize = _src.size(); + Size ksize = !kernel.empty() ? kernel.size() : Size(3, 3), ssize = _src.size(); bool doubleSupport = dev.doubleFPConfig() > 0; if ((depth == CV_64F && !doubleSupport) || borderType != BORDER_CONSTANT) @@ -1511,7 +1511,7 @@ static bool ocl_morphOp(InputArray _src, OutputArray _dst, InputArray _kernel, bool haveExtraMat = !_extraMat.empty(); CV_Assert(actual_op <= 3 || haveExtraMat); - if (!kernel.data) + if (kernel.empty()) { kernel = getStructuringElement(MORPH_RECT, Size(1+iterations*2,1+iterations*2)); anchor = Point(iterations, iterations); @@ -1665,7 +1665,7 @@ static void morphOp( int op, InputArray _src, OutputArray _dst, int borderType, const Scalar& borderValue ) { Mat kernel = _kernel.getMat(); - Size ksize = kernel.data ? kernel.size() : Size(3,3); + Size ksize = !kernel.empty() ? kernel.size() : Size(3,3); anchor = normalizeAnchor(anchor, ksize); CV_OCL_RUN(_dst.isUMat() && _src.dims() <= 2 && _src.channels() <= 4 && @@ -1680,7 +1680,7 @@ static void morphOp( int op, InputArray _src, OutputArray _dst, return; } - if (!kernel.data) + if (kernel.empty()) { kernel = getStructuringElement(MORPH_RECT, Size(1+iterations*2,1+iterations*2)); anchor = Point(iterations, iterations); @@ -1886,7 +1886,7 @@ cvCreateStructuringElementEx( int cols, int rows, { cv::Mat elem = cv::getStructuringElement(shape, ksize, anchor); for( i = 0; i < size; i++ ) - element->values[i] = elem.data[i]; + element->values[i] = elem.ptr()[i]; } return element; @@ -1915,7 +1915,7 @@ static void convertConvKernel( const IplConvKernel* src, cv::Mat& dst, cv::Point int i, size = src->nRows*src->nCols; for( i = 0; i < size; i++ ) - dst.data[i] = (uchar)(src->values[i] != 0); + dst.ptr()[i] = (uchar)(src->values[i] != 0); } diff --git a/modules/imgproc/src/phasecorr.cpp b/modules/imgproc/src/phasecorr.cpp index f513e84e2..e6416ead5 100644 --- a/modules/imgproc/src/phasecorr.cpp +++ b/modules/imgproc/src/phasecorr.cpp @@ -66,8 +66,8 @@ static void magSpectrums( InputArray _src, OutputArray _dst) if( depth == CV_32F ) { - const float* dataSrc = (const float*)src.data; - float* dataDst = (float*)dst.data; + const float* dataSrc = src.ptr(); + float* dataDst = dst.ptr(); size_t stepSrc = src.step/sizeof(dataSrc[0]); size_t stepDst = dst.step/sizeof(dataDst[0]); @@ -110,8 +110,8 @@ static void magSpectrums( InputArray _src, OutputArray _dst) } else { - const double* dataSrc = (const double*)src.data; - double* dataDst = (double*)dst.data; + const double* dataSrc = src.ptr(); + double* dataDst = dst.ptr(); size_t stepSrc = src.step/sizeof(dataSrc[0]); size_t stepDst = dst.step/sizeof(dataDst[0]); @@ -179,9 +179,9 @@ static void divSpectrums( InputArray _srcA, InputArray _srcB, OutputArray _dst, if( depth == CV_32F ) { - const float* dataA = (const float*)srcA.data; - const float* dataB = (const float*)srcB.data; - float* dataC = (float*)dst.data; + const float* dataA = srcA.ptr(); + const float* dataB = srcB.ptr(); + float* dataC = dst.ptr(); float eps = FLT_EPSILON; // prevent div0 problems size_t stepA = srcA.step/sizeof(dataA[0]); @@ -264,9 +264,9 @@ static void divSpectrums( InputArray _srcA, InputArray _srcB, OutputArray _dst, } else { - const double* dataA = (const double*)srcA.data; - const double* dataB = (const double*)srcB.data; - double* dataC = (double*)dst.data; + const double* dataA = srcA.ptr(); + const double* dataB = srcB.ptr(); + double* dataC = dst.ptr(); double eps = DBL_EPSILON; // prevent div0 problems size_t stepA = srcA.step/sizeof(dataA[0]); @@ -444,7 +444,7 @@ static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Siz if(type == CV_32FC1) { - const float* dataIn = (const float*)src.data; + const float* dataIn = src.ptr(); dataIn += minr*src.cols; for(int y = minr; y <= maxr; y++) { @@ -460,7 +460,7 @@ static Point2d weightedCentroid(InputArray _src, cv::Point peakLocation, cv::Siz } else { - const double* dataIn = (const double*)src.data; + const double* dataIn = src.ptr(); dataIn += minr*src.cols; for(int y = minr; y <= maxr; y++) { diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 0ab8d74c3..85c32ac04 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -230,7 +230,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType ) for( int y = 0; y < dsize.height; y++ ) { - T* dst = (T*)(_dst.data + _dst.step*y); + T* dst = _dst.ptr(y); WT *row0, *row1, *row2, *row3, *row4; // fill the ring buffer (horizontal convolution and decimation) @@ -238,7 +238,7 @@ pyrDown_( const Mat& _src, Mat& _dst, int borderType ) { WT* row = buf + ((sy - sy0) % PD_SZ)*bufstep; int _sy = borderInterpolate(sy, ssize.height, borderType); - const T* src = (const T*)(_src.data + _src.step*_sy); + const T* src = _src.ptr(_sy); int limit = cn; const int* tab = tabL; @@ -340,8 +340,8 @@ pyrUp_( const Mat& _src, Mat& _dst, int) for( int y = 0; y < ssize.height; y++ ) { - T* dst0 = (T*)(_dst.data + _dst.step*y*2); - T* dst1 = (T*)(_dst.data + _dst.step*(y*2+1)); + T* dst0 = _dst.ptr(y*2); + T* dst1 = _dst.ptr(y*2+1); WT *row0, *row1, *row2; if( y*2+1 >= dsize.height ) @@ -352,7 +352,7 @@ pyrUp_( const Mat& _src, Mat& _dst, int) { WT* row = buf + ((sy - sy0) % PU_SZ)*bufstep; int _sy = borderInterpolate(sy*2, dsize.height, BORDER_REFLECT_101)/2; - const T* src = (const T*)(_src.data + _src.step*_sy); + const T* src = _src.ptr(_sy); if( ssize.width == cn ) { diff --git a/modules/imgproc/src/rotcalipers.cpp b/modules/imgproc/src/rotcalipers.cpp index 0983d4d35..bfcc6ea26 100644 --- a/modules/imgproc/src/rotcalipers.cpp +++ b/modules/imgproc/src/rotcalipers.cpp @@ -356,7 +356,7 @@ cv::RotatedRect cv::minAreaRect( InputArray _points ) } int n = hull.checkVector(2); - const Point2f* hpoints = (const Point2f*)hull.data; + const Point2f* hpoints = hull.ptr(); if( n > 2 ) { @@ -402,5 +402,5 @@ void cv::boxPoints(cv::RotatedRect box, OutputArray _pts) { _pts.create(4, 2, CV_32F); Mat pts = _pts.getMat(); - box.points((Point2f*)pts.data); + box.points(pts.ptr()); } diff --git a/modules/imgproc/src/samplers.cpp b/modules/imgproc/src/samplers.cpp index d3edbbf12..744e95ec6 100644 --- a/modules/imgproc/src/samplers.cpp +++ b/modules/imgproc/src/samplers.cpp @@ -392,7 +392,7 @@ void cv::getRectSubPix( InputArray _image, Size patchSize, Point2f center, if( ippfunc) { - if (ippfunc(image.data, (int)image.step, src_size, patch.data, + if (ippfunc(image.ptr(), (int)image.step, src_size, patch.ptr(), (int)patch.step, win_size, icenter, &minpt, &maxpt) >= 0 ) return; setIppErrorStatus(); @@ -401,13 +401,13 @@ void cv::getRectSubPix( InputArray _image, Size patchSize, Point2f center, if( depth == CV_8U && ddepth == CV_8U ) getRectSubPix_Cn_ - (image.data, image.step, image.size(), patch.data, patch.step, patch.size(), center, cn); + (image.ptr(), image.step, image.size(), patch.ptr(), patch.step, patch.size(), center, cn); else if( depth == CV_8U && ddepth == CV_32F ) getRectSubPix_8u32f - (image.data, image.step, image.size(), (float*)patch.data, patch.step, patch.size(), center, cn); + (image.ptr(), image.step, image.size(), patch.ptr(), patch.step, patch.size(), center, cn); else if( depth == CV_32F && ddepth == CV_32F ) getRectSubPix_Cn_, nop > - ((const float*)image.data, image.step, image.size(), (float*)patch.data, patch.step, patch.size(), center, cn); + (image.ptr(), image.step, image.size(), patch.ptr(), patch.step, patch.size(), center, cn); else CV_Error( CV_StsUnsupportedFormat, "Unsupported combination of input and output formats"); } @@ -427,8 +427,8 @@ cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center ) CV_IMPL void cvGetQuadrangleSubPix( const void* srcarr, void* dstarr, const CvMat* mat ) { - cv::Mat src = cv::cvarrToMat(srcarr), m = cv::cvarrToMat(mat); - const cv::Mat dst = cv::cvarrToMat(dstarr); + const cv::Mat src = cv::cvarrToMat(srcarr), m = cv::cvarrToMat(mat); + cv::Mat dst = cv::cvarrToMat(dstarr); CV_Assert( src.channels() == dst.channels() ); @@ -442,8 +442,8 @@ cvGetQuadrangleSubPix( const void* srcarr, void* dstarr, const CvMat* mat ) matrix[5] -= matrix[3]*dx + matrix[4]*dy; if( src.depth() == CV_8U && dst.depth() == CV_32F ) - cv::getQuadrangleSubPix_8u32f_CnR( src.data, src.step, src.size(), - (float*)dst.data, dst.step, dst.size(), + cv::getQuadrangleSubPix_8u32f_CnR( src.ptr(), src.step, src.size(), + dst.ptr(), dst.step, dst.size(), matrix, src.channels()); else { diff --git a/modules/imgproc/src/segmentation.cpp b/modules/imgproc/src/segmentation.cpp index 320f2273a..af1d77736 100644 --- a/modules/imgproc/src/segmentation.cpp +++ b/modules/imgproc/src/segmentation.cpp @@ -147,7 +147,7 @@ void cv::watershed( InputArray _src, InputOutputArray _markers ) CV_Assert( src.type() == CV_8UC3 && dst.type() == CV_32SC1 ); CV_Assert( src.size() == dst.size() ); - const uchar* img = src.data; + const uchar* img = src.ptr(); int istep = int(src.step/sizeof(img[0])); int* mask = dst.ptr(); int mstep = int(dst.step / sizeof(mask[0])); @@ -210,7 +210,7 @@ void cv::watershed( InputArray _src, InputOutputArray _markers ) return; active_queue = i; - img = src.data; + img = src.ptr(); mask = dst.ptr(); // recursively fill the basins @@ -370,7 +370,7 @@ void cv::pyrMeanShiftFiltering( InputArray _src, OutputArray _dst, { cv::Mat src = src_pyramid[level]; cv::Size size = src.size(); - uchar* sptr = src.data; + const uchar* sptr = src.ptr(); int sstep = (int)src.step; uchar* mask = 0; int mstep = 0; @@ -382,11 +382,11 @@ void cv::pyrMeanShiftFiltering( InputArray _src, OutputArray _dst, if( level < max_level ) { cv::Size size1 = dst_pyramid[level+1].size(); - cv::Mat m( size.height, size.width, CV_8UC1, mask0.data ); + cv::Mat m( size.height, size.width, CV_8UC1, mask0.ptr() ); dstep = (int)dst_pyramid[level+1].step; - dptr = dst_pyramid[level+1].data + dstep + cn; + dptr = dst_pyramid[level+1].ptr() + dstep + cn; mstep = (int)m.step; - mask = m.data + mstep; + mask = m.ptr() + mstep; //cvResize( dst_pyramid[level+1], dst_pyramid[level], CV_INTER_CUBIC ); cv::pyrUp( dst_pyramid[level+1], dst_pyramid[level], dst_pyramid[level].size() ); m.setTo(cv::Scalar::all(0)); @@ -402,10 +402,10 @@ void cv::pyrMeanShiftFiltering( InputArray _src, OutputArray _dst, } cv::dilate( m, m, cv::Mat() ); - mask = m.data; + mask = m.ptr(); } - dptr = dst_pyramid[level].data; + dptr = dst_pyramid[level].ptr(); dstep = (int)dst_pyramid[level].step; for( i = 0; i < size.height; i++, sptr += sstep - size.width*3, @@ -425,7 +425,7 @@ void cv::pyrMeanShiftFiltering( InputArray _src, OutputArray _dst, // iterate meanshift procedure for( iter = 0; iter < termcrit.maxCount; iter++ ) { - uchar* ptr; + const uchar* ptr; int x, y, count = 0; int minx, miny, maxx, maxy; int s0 = 0, s1 = 0, s2 = 0, sx = 0, sy = 0; diff --git a/modules/imgproc/src/shapedescr.cpp b/modules/imgproc/src/shapedescr.cpp index 4258d473a..8adb30073 100644 --- a/modules/imgproc/src/shapedescr.cpp +++ b/modules/imgproc/src/shapedescr.cpp @@ -212,8 +212,8 @@ void cv::minEnclosingCircle( InputArray _points, Point2f& _center, float& _radiu return; bool is_float = depth == CV_32F; - const Point* ptsi = (const Point*)points.data; - const Point2f* ptsf = (const Point2f*)points.data; + const Point* ptsi = points.ptr(); + const Point2f* ptsf = points.ptr(); Point2f pt = is_float ? ptsf[0] : Point2f((float)ptsi[0].x,(float)ptsi[0].y); Point2f pts[4] = {pt, pt, pt, pt}; @@ -310,8 +310,8 @@ double cv::arcLength( InputArray _curve, bool is_closed ) bool is_float = depth == CV_32F; int last = is_closed ? count-1 : 0; - const Point* pti = (const Point*)curve.data; - const Point2f* ptf = (const Point2f*)curve.data; + const Point* pti = curve.ptr(); + const Point2f* ptf = curve.ptr(); Point2f prev = is_float ? ptf[last] : Point2f((float)pti[last].x,(float)pti[last].y); @@ -347,8 +347,8 @@ double cv::contourArea( InputArray _contour, bool oriented ) double a00 = 0; bool is_float = depth == CV_32F; - const Point* ptsi = (const Point*)contour.data; - const Point2f* ptsf = (const Point2f*)contour.data; + const Point* ptsi = contour.ptr(); + const Point2f* ptsf = contour.ptr(); Point2f prev = is_float ? ptsf[npoints-1] : Point2f((float)ptsi[npoints-1].x, (float)ptsi[npoints-1].y); for( int i = 0; i < npoints; i++ ) @@ -383,8 +383,8 @@ cv::RotatedRect cv::fitEllipse( InputArray _points ) double gfp[5], rp[5], t; const double min_eps = 1e-8; bool is_float = depth == CV_32F; - const Point* ptsi = (const Point*)points.data; - const Point2f* ptsf = (const Point2f*)points.data; + const Point* ptsi = points.ptr(); + const Point2f* ptsf = points.ptr(); AutoBuffer _Ad(n*5), _bd(n); double *Ad = _Ad, *bd = _bd; @@ -493,7 +493,7 @@ static Rect pointSetBoundingRect( const Mat& points ) if( npoints == 0 ) return Rect(); - const Point* pts = (const Point*)points.data; + const Point* pts = points.ptr(); Point pt = pts[0]; #if CV_SSE4_2 diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 6a28fabd7..9d00bd231 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -953,7 +953,7 @@ void cv::boxFilter( InputArray _src, OutputArray _dst, int ddepth, Ipp8u * buffer = ippsMalloc_8u(bufSize); \ ippType borderValue[4] = { 0, 0, 0, 0 }; \ ippBorderType = ippBorderType == BORDER_CONSTANT ? ippBorderConst : ippBorderRepl; \ - IppStatus status = ippiFilterBoxBorder_##flavor((const ippType *)src.data, (int)src.step, (ippType *)dst.data, \ + IppStatus status = ippiFilterBoxBorder_##flavor(src.ptr(), (int)src.step, dst.ptr(), \ (int)dst.step, roiSize, maskSize, \ (IppiBorderType)ippBorderType, borderValue, buffer); \ ippsFree(buffer); \ @@ -1141,8 +1141,8 @@ cv::Mat cv::getGaussianKernel( int n, double sigma, int ktype ) CV_Assert( ktype == CV_32F || ktype == CV_64F ); Mat kernel(n, 1, ktype); - float* cf = (float*)kernel.data; - double* cd = (double*)kernel.data; + float* cf = kernel.ptr(); + double* cd = kernel.ptr(); double sigmaX = sigma > 0 ? sigma : ((n-1)*0.5 - 1)*0.3 + 0.8; double scale2X = -0.5/(sigmaX*sigmaX); @@ -1272,10 +1272,10 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, typedef Ipp##ippfavor ippType; \ ippType borderValues[] = { 0, 0, 0 }; \ IppStatus status = ippcn == 1 ? \ - ippiFilterGaussianBorder_##ippfavor##_C1R((const ippType *)src.data, (int)src.step, \ - (ippType *)dst.data, (int)dst.step, roiSize, borderValues[0], pSpec, pBuffer) : \ - ippiFilterGaussianBorder_##ippfavor##_C3R((const ippType *)src.data, (int)src.step, \ - (ippType *)dst.data, (int)dst.step, roiSize, borderValues, pSpec, pBuffer); \ + ippiFilterGaussianBorder_##ippfavor##_C1R(src.ptr(), (int)src.step, \ + dst.ptr(), (int)dst.step, roiSize, borderValues[0], pSpec, pBuffer) : \ + ippiFilterGaussianBorder_##ippfavor##_C3R(src.ptr(), (int)src.step, \ + dst.ptr(), (int)dst.step, roiSize, borderValues, pSpec, pBuffer); \ ippFree(pBuffer); \ ippFree(pSpec); \ if (status >= 0) \ @@ -1418,8 +1418,8 @@ medianBlur_8u_O1( const Mat& _src, Mat& _dst, int ksize ) for( int x = 0; x < _dst.cols; x += STRIPE_SIZE ) { int i, j, k, c, n = std::min(_dst.cols - x, STRIPE_SIZE) + r*2; - const uchar* src = _src.data + x*cn; - uchar* dst = _dst.data + (x - r)*cn; + const uchar* src = _src.ptr() + x*cn; + uchar* dst = _dst.ptr() + (x - r)*cn; memset( h_coarse, 0, 16*n*cn*sizeof(h_coarse[0]) ); memset( h_fine, 0, 16*16*n*cn*sizeof(h_fine[0]) ); @@ -1601,8 +1601,8 @@ medianBlur_8u_Om( const Mat& _src, Mat& _dst, int m ) int x, y; int n2 = m*m/2; Size size = _dst.size(); - const uchar* src = _src.data; - uchar* dst = _dst.data; + const uchar* src = _src.ptr(); + uchar* dst = _dst.ptr(); int src_step = (int)_src.step, dst_step = (int)_dst.step; int cn = _src.channels(); const uchar* src_max = src + size.height*src_step; @@ -1878,8 +1878,8 @@ medianBlur_SortNet( const Mat& _src, Mat& _dst, int m ) typedef typename Op::arg_type WT; typedef typename VecOp::arg_type VT; - const T* src = (const T*)_src.data; - T* dst = (T*)_dst.data; + const T* src = _src.ptr(); + T* dst = _dst.ptr(); int sstep = (int)(_src.step/sizeof(T)); int dstep = (int)(_dst.step/sizeof(T)); Size size = _dst.size(); @@ -2162,8 +2162,8 @@ void cv::medianBlur( InputArray _src0, OutputArray _dst, int ksize ) ippDataType, CV_MAT_CN(type), &bufSize) >= 0) \ { \ Ipp8u * buffer = ippsMalloc_8u(bufSize); \ - IppStatus status = ippiFilterMedianBorder_##flavor((const ippType *)src0.data, (int)src0.step, \ - (ippType *)dst.data, (int)dst.step, dstRoiSize, maskSize, \ + IppStatus status = ippiFilterMedianBorder_##flavor(src0.ptr(), (int)src0.step, \ + dst.ptr(), (int)dst.step, dstRoiSize, maskSize, \ ippBorderRepl, (ippType)0, buffer); \ ippsFree(buffer); \ if (status >= 0) \ diff --git a/modules/imgproc/src/sumpixels.cpp b/modules/imgproc/src/sumpixels.cpp index 1c6f1513f..cf3104372 100755 --- a/modules/imgproc/src/sumpixels.cpp +++ b/modules/imgproc/src/sumpixels.cpp @@ -419,8 +419,8 @@ void cv::integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, Output else CV_Error( CV_StsUnsupportedFormat, "" ); - func( src.data, src.step, sum.data, sum.step, sqsum.data, sqsum.step, - tilted.data, tilted.step, src.size(), cn ); + func( src.ptr(), src.step, sum.ptr(), sum.step, sqsum.ptr(), sqsum.step, + tilted.ptr(), tilted.step, src.size(), cn ); } void cv::integral( InputArray src, OutputArray sum, int sdepth ) diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index 6919d7a3d..a658008cf 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -591,7 +591,7 @@ static bool ipp_crossCorr(const Mat& src, const Mat& tpl, Mat& dst) pBuffer = ippsMalloc_8u( bufSize ); - status = ippFunc(src.data, (int)src.step, srcRoiSize, tpl.data, (int)tpl.step, tplRoiSize, (Ipp32f*)dst.data, (int)dst.step, funCfg, pBuffer); + status = ippFunc(src.ptr(), (int)src.step, srcRoiSize, tpl.ptr(), (int)tpl.step, tplRoiSize, dst.ptr(), (int)dst.step, funCfg, pBuffer); ippsFree( pBuffer ); return status >= 0; @@ -624,7 +624,7 @@ static bool ipp_sqrDistance(const Mat& src, const Mat& tpl, Mat& dst) pBuffer = ippsMalloc_8u( bufSize ); - status = ippFunc(src.data, (int)src.step, srcRoiSize, tpl.data, (int)tpl.step, tplRoiSize, (Ipp32f*)dst.data, (int)dst.step, funCfg, pBuffer); + status = ippFunc(src.ptr(), (int)src.step, srcRoiSize, tpl.ptr(), (int)tpl.step, tplRoiSize, dst.ptr(), (int)dst.step, funCfg, pBuffer); ippsFree( pBuffer ); return status >= 0; @@ -934,7 +934,7 @@ void cv::matchTemplate( InputArray _img, InputArray _templ, OutputArray _result, for( i = 0; i < result.rows; i++ ) { - float* rrow = (float*)(result.data + i*result.step); + float* rrow = result.ptr(i); int idx = i * sumstep; int idx2 = i * sqstep; diff --git a/modules/imgproc/src/thresh.cpp b/modules/imgproc/src/thresh.cpp index 9376d62a5..e7246128e 100644 --- a/modules/imgproc/src/thresh.cpp +++ b/modules/imgproc/src/thresh.cpp @@ -75,28 +75,28 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type ) { case THRESH_TRUNC: #ifndef HAVE_IPP_ICV_ONLY - if (_src.data == _dst.data && ippiThreshold_GT_8u_C1IR(_src.data, (int)src_step, sz, thresh) >= 0) + if (_src.data == _dst.data && ippiThreshold_GT_8u_C1IR(_src.ptr(), (int)src_step, sz, thresh) >= 0) return; #endif - if (ippiThreshold_GT_8u_C1R(_src.data, (int)src_step, _dst.data, (int)dst_step, sz, thresh) >= 0) + if (ippiThreshold_GT_8u_C1R(_src.ptr(), (int)src_step, _dst.ptr(), (int)dst_step, sz, thresh) >= 0) return; setIppErrorStatus(); break; case THRESH_TOZERO: #ifndef HAVE_IPP_ICV_ONLY - if (_src.data == _dst.data && ippiThreshold_LTVal_8u_C1IR(_src.data, (int)src_step, sz, thresh+1, 0) >= 0) + if (_src.data == _dst.data && ippiThreshold_LTVal_8u_C1IR(_src.ptr(), (int)src_step, sz, thresh+1, 0) >= 0) return; #endif - if (ippiThreshold_LTVal_8u_C1R(_src.data, (int)src_step, _dst.data, (int)dst_step, sz, thresh+1, 0) >= 0) + if (ippiThreshold_LTVal_8u_C1R(_src.ptr(), (int)src_step, _dst.ptr(), (int)dst_step, sz, thresh+1, 0) >= 0) return; setIppErrorStatus(); break; case THRESH_TOZERO_INV: #ifndef HAVE_IPP_ICV_ONLY - if (_src.data == _dst.data && ippiThreshold_GTVal_8u_C1IR(_src.data, (int)src_step, sz, thresh, 0) >= 0) + if (_src.data == _dst.data && ippiThreshold_GTVal_8u_C1IR(_src.ptr(), (int)src_step, sz, thresh, 0) >= 0) return; #endif - if (ippiThreshold_GTVal_8u_C1R(_src.data, (int)src_step, _dst.data, (int)dst_step, sz, thresh, 0) >= 0) + if (ippiThreshold_GTVal_8u_C1R(_src.ptr(), (int)src_step, _dst.ptr(), (int)dst_step, sz, thresh, 0) >= 0) return; setIppErrorStatus(); break; @@ -151,8 +151,8 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type ) for( i = 0; i < roi.height; i++ ) { - const uchar* src = (const uchar*)(_src.data + src_step*i); - uchar* dst = (uchar*)(_dst.data + dst_step*i); + const uchar* src = _src.ptr() + src_step*i; + uchar* dst = _dst.ptr() + dst_step*i; switch( type ) { @@ -270,8 +270,8 @@ thresh_8u( const Mat& _src, Mat& _dst, uchar thresh, uchar maxval, int type ) { for( i = 0; i < roi.height; i++ ) { - const uchar* src = (const uchar*)(_src.data + src_step*i); - uchar* dst = (uchar*)(_dst.data + dst_step*i); + const uchar* src = _src.ptr() + src_step*i; + uchar* dst = _dst.ptr() + dst_step*i; j = j_scalar; #if CV_ENABLE_UNROLLED for( ; j <= roi.width - 4; j += 4 ) @@ -302,8 +302,8 @@ thresh_16s( const Mat& _src, Mat& _dst, short thresh, short maxval, int type ) int i, j; Size roi = _src.size(); roi.width *= _src.channels(); - const short* src = (const short*)_src.data; - short* dst = (short*)_dst.data; + const short* src = _src.ptr(); + short* dst = _dst.ptr(); size_t src_step = _src.step/sizeof(src[0]); size_t dst_step = _dst.step/sizeof(dst[0]); @@ -511,8 +511,8 @@ thresh_32f( const Mat& _src, Mat& _dst, float thresh, float maxval, int type ) int i, j; Size roi = _src.size(); roi.width *= _src.channels(); - const float* src = (const float*)_src.data; - float* dst = (float*)_dst.data; + const float* src = _src.ptr(); + float* dst = _dst.ptr(); size_t src_step = _src.step/sizeof(src[0]); size_t dst_step = _dst.step/sizeof(dst[0]); @@ -715,7 +715,7 @@ getThreshVal_Otsu_8u( const Mat& _src ) IppiSize srcSize = { size.width, size.height }; Ipp8u thresh; CV_SUPPRESS_DEPRECATED_START - IppStatus ok = ippiComputeThreshold_Otsu_8u_C1R(_src.data, step, srcSize, &thresh); + IppStatus ok = ippiComputeThreshold_Otsu_8u_C1R(_src.ptr(), step, srcSize, &thresh); CV_SUPPRESS_DEPRECATED_END if (ok >= 0) return thresh; @@ -726,7 +726,7 @@ getThreshVal_Otsu_8u( const Mat& _src ) int i, j, h[N] = {0}; for( i = 0; i < size.height; i++ ) { - const uchar* src = _src.data + step*i; + const uchar* src = _src.ptr() + step*i; j = 0; #if CV_ENABLE_UNROLLED for( ; j <= size.width - 4; j += 4 ) @@ -1003,9 +1003,9 @@ void cv::adaptiveThreshold( InputArray _src, OutputArray _dst, double maxValue, for( i = 0; i < size.height; i++ ) { - const uchar* sdata = src.data + src.step*i; - const uchar* mdata = mean.data + mean.step*i; - uchar* ddata = dst.data + dst.step*i; + const uchar* sdata = src.ptr(i); + const uchar* mdata = mean.ptr(i); + uchar* ddata = dst.ptr(i); for( j = 0; j < size.width; j++ ) ddata[j] = tab[sdata[j] - mdata[j] + 255]; diff --git a/modules/imgproc/src/undistort.cpp b/modules/imgproc/src/undistort.cpp index cacaa1d9f..e5da24b4d 100644 --- a/modules/imgproc/src/undistort.cpp +++ b/modules/imgproc/src/undistort.cpp @@ -53,8 +53,8 @@ cv::Mat cv::getDefaultNewCameraMatrix( InputArray _cameraMatrix, Size imgsize, cameraMatrix.convertTo(newCameraMatrix, CV_64F); if( centerPrincipalPoint ) { - ((double*)newCameraMatrix.data)[2] = (imgsize.width-1)*0.5; - ((double*)newCameraMatrix.data)[5] = (imgsize.height-1)*0.5; + newCameraMatrix.ptr()[2] = (imgsize.width-1)*0.5; + newCameraMatrix.ptr()[5] = (imgsize.height-1)*0.5; } return newCameraMatrix; } @@ -82,15 +82,15 @@ void cv::initUndistortRectifyMap( InputArray _cameraMatrix, InputArray _distCoef Mat_ R = Mat_::eye(3, 3); Mat_ A = Mat_(cameraMatrix), Ar; - if( newCameraMatrix.data ) + if( !newCameraMatrix.empty() ) Ar = Mat_(newCameraMatrix); else Ar = getDefaultNewCameraMatrix( A, size, true ); - if( matR.data ) + if( !matR.empty() ) R = Mat_(matR); - if( distCoeffs.data ) + if( !distCoeffs.empty() ) distCoeffs = Mat_(distCoeffs); else { @@ -114,23 +114,24 @@ void cv::initUndistortRectifyMap( InputArray _cameraMatrix, InputArray _distCoef if( distCoeffs.rows != 1 && !distCoeffs.isContinuous() ) distCoeffs = distCoeffs.t(); - double k1 = ((double*)distCoeffs.data)[0]; - double k2 = ((double*)distCoeffs.data)[1]; - double p1 = ((double*)distCoeffs.data)[2]; - double p2 = ((double*)distCoeffs.data)[3]; - double k3 = distCoeffs.cols + distCoeffs.rows - 1 >= 5 ? ((double*)distCoeffs.data)[4] : 0.; - double k4 = distCoeffs.cols + distCoeffs.rows - 1 >= 8 ? ((double*)distCoeffs.data)[5] : 0.; - double k5 = distCoeffs.cols + distCoeffs.rows - 1 >= 8 ? ((double*)distCoeffs.data)[6] : 0.; - double k6 = distCoeffs.cols + distCoeffs.rows - 1 >= 8 ? ((double*)distCoeffs.data)[7] : 0.; - double s1 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? ((double*)distCoeffs.data)[8] : 0.; - double s2 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? ((double*)distCoeffs.data)[9] : 0.; - double s3 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? ((double*)distCoeffs.data)[10] : 0.; - double s4 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? ((double*)distCoeffs.data)[11] : 0.; + const double* const distPtr = distCoeffs.ptr(); + double k1 = distPtr[0]; + double k2 = distPtr[1]; + double p1 = distPtr[2]; + double p2 = distPtr[3]; + double k3 = distCoeffs.cols + distCoeffs.rows - 1 >= 5 ? distPtr[4] : 0.; + double k4 = distCoeffs.cols + distCoeffs.rows - 1 >= 8 ? distPtr[5] : 0.; + double k5 = distCoeffs.cols + distCoeffs.rows - 1 >= 8 ? distPtr[6] : 0.; + double k6 = distCoeffs.cols + distCoeffs.rows - 1 >= 8 ? distPtr[7] : 0.; + double s1 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? distPtr[8] : 0.; + double s2 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? distPtr[9] : 0.; + double s3 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? distPtr[10] : 0.; + double s4 = distCoeffs.cols + distCoeffs.rows - 1 >= 12 ? distPtr[11] : 0.; for( int i = 0; i < size.height; i++ ) { - float* m1f = (float*)(map1.data + map1.step*i); - float* m2f = (float*)(map2.data + map2.step*i); + float* m1f = map1.ptr(i); + float* m2f = map2.ptr(i); short* m1 = (short*)m1f; ushort* m2 = (ushort*)m2f; double _x = i*ir[1] + ir[2], _y = i*ir[4] + ir[5], _w = i*ir[7] + ir[8]; @@ -183,7 +184,7 @@ void cv::undistort( InputArray _src, OutputArray _dst, InputArray _cameraMatrix, Mat_ A, Ar, I = Mat_::eye(3,3); cameraMatrix.convertTo(A, CV_64F); - if( distCoeffs.data ) + if( !distCoeffs.empty() ) distCoeffs = Mat_(distCoeffs); else { @@ -191,7 +192,7 @@ void cv::undistort( InputArray _src, OutputArray _dst, InputArray _cameraMatrix, distCoeffs = 0.; } - if( newCameraMatrix.data ) + if( !newCameraMatrix.empty() ) newCameraMatrix.convertTo(Ar, CV_64F); else A.copyTo(Ar); @@ -404,11 +405,11 @@ void cv::undistortPoints( InputArray _src, OutputArray _dst, CvMat _csrc = src, _cdst = dst, _ccameraMatrix = cameraMatrix; CvMat matR, matP, _cdistCoeffs, *pR=0, *pP=0, *pD=0; - if( R.data ) + if( !R.empty() ) pR = &(matR = R); - if( P.data ) + if( !P.empty() ) pP = &(matP = P); - if( distCoeffs.data ) + if( !distCoeffs.empty() ) pD = &(_cdistCoeffs = distCoeffs); cvUndistortPoints(&_csrc, &_cdst, &_ccameraMatrix, pD, pR, pP); } diff --git a/modules/imgproc/test/test_bilateral_filter.cpp b/modules/imgproc/test/test_bilateral_filter.cpp index ba4c9d57b..994f8544e 100644 --- a/modules/imgproc/test/test_bilateral_filter.cpp +++ b/modules/imgproc/test/test_bilateral_filter.cpp @@ -180,8 +180,8 @@ namespace cvtest for( i = 0; i < size.height; i++ ) { - const float* sptr = (const float*)(temp.data + (i+radius)*temp.step) + radius*cn; - float* dptr = (float*)(dst.data + i*dst.step); + const float* sptr = temp.ptr(i+radius) + radius*cn; + float* dptr = dst.ptr(i); if( cn == 1 ) { diff --git a/modules/imgproc/test/test_color.cpp b/modules/imgproc/test/test_color.cpp index cf420fd6a..5e00f65f0 100644 --- a/modules/imgproc/test/test_color.cpp +++ b/modules/imgproc/test/test_color.cpp @@ -1693,7 +1693,7 @@ TEST(Imgproc_ColorBayer, regression) Mat gold = imread(string(ts->get_data_path()) + "/cvtcolor/bayer_gold.png", IMREAD_UNCHANGED); Mat result; - CV_Assert(given.data != NULL && gold.data != NULL); + CV_Assert( !given.empty() && !gold.empty() ); cvtColor(given, result, CV_BayerBG2GRAY); @@ -1716,7 +1716,7 @@ TEST(Imgproc_ColorBayerVNG, regression) Mat gold = imread(goldfname, IMREAD_UNCHANGED); Mat result; - CV_Assert(given.data != NULL); + CV_Assert( !given.empty() ); cvtColor(given, result, CV_BayerBG2BGR_VNG, 3); @@ -1808,7 +1808,7 @@ TEST(Imgproc_ColorBayerVNG_Strict, regression) std::string full_path = parent_path + image_name; src = imread(full_path, IMREAD_UNCHANGED); - if (src.data == NULL) + if ( src.empty() ) { ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA); ts->printf(cvtest::TS::SUMMARY, "No input image\n"); @@ -1827,7 +1827,7 @@ TEST(Imgproc_ColorBayerVNG_Strict, regression) // reading a reference image full_path = parent_path + pattern[i] + image_name; reference = imread(full_path, IMREAD_UNCHANGED); - if (reference.data == NULL) + if ( reference.empty() ) { imwrite(full_path, dst); continue; @@ -2035,7 +2035,7 @@ static void test_Bayer2RGB_EdgeAware_8u(const Mat& src, Mat& dst, int code) } ++size.width; - uchar* firstRow = dst.data, *lastRow = dst.data + size.height * dst.step; + uchar* firstRow = dst.ptr(), *lastRow = dst.ptr(size.height); size.width *= dcn; for (int x = 0; x < size.width; ++x) { @@ -2058,8 +2058,8 @@ static void checkData(const Mat& actual, const Mat& reference, cvtest::TS* ts, c for (int y = 0; y < size.height && next; ++y) { - const T* A = reinterpret_cast(actual.data + actual.step * y); - const T* R = reinterpret_cast(reference.data + reference.step * y); + const T* A = actual.ptr(y); + const T* R = reference.ptr(y); for (int x = 0; x < size.width && next; ++x) if (std::abs(A[x] - R[x]) > 1) @@ -2095,7 +2095,7 @@ TEST(ImgProc_BayerEdgeAwareDemosaicing, accuracy) std::string full_path = parent_path + image_name; src = imread(full_path, IMREAD_UNCHANGED); - if (src.data == NULL) + if (src.empty()) { ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA); ts->printf(cvtest::TS::SUMMARY, "No input image\n"); diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp index 6b8cb8c47..a203e60f5 100644 --- a/modules/imgproc/test/test_filter.cpp +++ b/modules/imgproc/test/test_filter.cpp @@ -228,7 +228,7 @@ int CV_MorphologyBaseTest::prepare_test_case( int test_case_idx ) if( shape == CV_SHAPE_CUSTOM ) { eldata.resize(aperture_size.width*aperture_size.height); - const uchar* src = test_mat[INPUT][1].data; + const uchar* src = test_mat[INPUT][1].ptr(); int srcstep = (int)test_mat[INPUT][1].step; int i, j, nonzero = 0; diff --git a/modules/imgproc/test/test_floodfill.cpp b/modules/imgproc/test/test_floodfill.cpp index 07e0bcbc4..d919b1602 100644 --- a/modules/imgproc/test/test_floodfill.cpp +++ b/modules/imgproc/test/test_floodfill.cpp @@ -213,7 +213,7 @@ void CV_FloodFillTest::run_func() mask = test_array[INPUT_OUTPUT][1] ? cv::cvarrToMat(test_array[INPUT_OUTPUT][1]) : cv::Mat(); cv::Rect rect; int area; - if( !mask.data ) + if( mask.empty() ) area = cv::floodFill( img, seed_pt, new_val, &rect, l_diff, u_diff, flags ); else area = cv::floodFill( img, mask, seed_pt, new_val, &rect, l_diff, u_diff, flags ); diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index e08020dbe..3146ff72a 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -344,7 +344,7 @@ static void test_remap( const Mat& src, Mat& dst, const Mat& mapx, const Mat& ma int x, y, k; int drows = dst.rows, dcols = dst.cols; int srows = src.rows, scols = src.cols; - const uchar* sptr0 = src.data; + const uchar* sptr0 = src.ptr(); int depth = src.depth(), cn = src.channels(); int elem_size = (int)src.elemSize(); int step = (int)(src.step / CV_ELEM_SIZE(depth)); diff --git a/modules/imgproc/test/test_imgwarp_strict.cpp b/modules/imgproc/test/test_imgwarp_strict.cpp index 02016fb3d..669c60186 100644 --- a/modules/imgproc/test/test_imgwarp_strict.cpp +++ b/modules/imgproc/test/test_imgwarp_strict.cpp @@ -533,11 +533,11 @@ void CV_Resize_Test::resize_1d(const Mat& _src, Mat& _dst, int dy, const dim& _d Mat _extended_src_row(1, _src.cols + ksize * 2, _src.type()); const uchar* srow = _src.ptr(dy); - memcpy(_extended_src_row.data + elemsize * ksize, srow, _src.step); + memcpy(_extended_src_row.ptr() + elemsize * ksize, srow, _src.step); for (int k = 0; k < ksize; ++k) { - memcpy(_extended_src_row.data + k * elemsize, srow, elemsize); - memcpy(_extended_src_row.data + (ksize + k) * elemsize + _src.step, srow + _src.step - elemsize, elemsize); + memcpy(_extended_src_row.ptr() + k * elemsize, srow, elemsize); + memcpy(_extended_src_row.ptr() + (ksize + k) * elemsize + _src.step, srow + _src.step - elemsize, elemsize); } for (int dx = 0; dx < dsize.width; ++dx) @@ -757,7 +757,7 @@ void CV_Remap_Test::convert_maps() if (interpolation == INTER_NEAREST) mapy = Mat(); - CV_Assert(((interpolation == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16UC1 || + CV_Assert(((interpolation == INTER_NEAREST && mapy.empty()) || mapy.type() == CV_16UC1 || mapy.type() == CV_16SC1) && mapx.type() == CV_16SC2); } @@ -809,7 +809,7 @@ void CV_Remap_Test::run_reference_func() void CV_Remap_Test::remap_nearest(const Mat& _src, Mat& _dst) { CV_Assert(_src.depth() == CV_32F && _dst.type() == _src.type()); - CV_Assert(mapx.type() == CV_16SC2 && !mapy.data); + CV_Assert(mapx.type() == CV_16SC2 && mapy.empty()); Size ssize = _src.size(), dsize = _dst.size(); CV_Assert(ssize.area() > 0 && dsize.area() > 0); @@ -1079,7 +1079,7 @@ void CV_WarpAffine_Test::warpAffine(const Mat& _src, Mat& _dst) } } - CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16SC1)); + CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && mapy.empty()) || mapy.type() == CV_16SC1)); cv::remap(_src, _dst, mapx, mapy, inter, borderType, borderValue); } @@ -1206,7 +1206,7 @@ void CV_WarpPerspective_Test::warpPerspective(const Mat& _src, Mat& _dst) } } - CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && !mapy.data) || mapy.type() == CV_16SC1)); + CV_Assert(mapx.type() == CV_16SC2 && ((inter == INTER_NEAREST && mapy.empty()) || mapy.type() == CV_16SC1)); cv::remap(_src, _dst, mapx, mapy, inter, borderType, borderValue); } diff --git a/modules/imgproc/test/test_moments.cpp b/modules/imgproc/test/test_moments.cpp index b74ee5db8..5288e5b0c 100644 --- a/modules/imgproc/test/test_moments.cpp +++ b/modules/imgproc/test/test_moments.cpp @@ -392,15 +392,15 @@ int CV_HuMomentsTest::prepare_test_case( int test_case_idx ) void CV_HuMomentsTest::run_func() { - cvGetHuMoments( (CvMoments*)test_mat[INPUT][0].data, - (CvHuMoments*)test_mat[OUTPUT][0].data ); + cvGetHuMoments( test_mat[INPUT][0].ptr(), + test_mat[OUTPUT][0].ptr() ); } void CV_HuMomentsTest::prepare_to_validation( int /*test_case_idx*/ ) { - CvMoments* m = (CvMoments*)test_mat[INPUT][0].data; - CvHuMoments* hu = (CvHuMoments*)test_mat[REF_OUTPUT][0].data; + CvMoments* m = test_mat[INPUT][0].ptr(); + CvHuMoments* hu = test_mat[REF_OUTPUT][0].ptr(); double inv_m00 = m->inv_sqrt_m00*m->inv_sqrt_m00; double s2 = inv_m00*inv_m00; /* 1./(m00 ^ (2/2 + 1)) */ diff --git a/modules/imgproc/test/test_watershed.cpp b/modules/imgproc/test/test_watershed.cpp index 0edb18e02..28facf720 100644 --- a/modules/imgproc/test/test_watershed.cpp +++ b/modules/imgproc/test/test_watershed.cpp @@ -85,7 +85,7 @@ void CV_WatershedTest::run( int /* start_from */) //expected image was added with 1 in order to save to png //so now we substract 1 to get real color - if(exp.data) + if(!exp.empty()) colors.push_back(exp.ptr(p->y)[p->x] - 1); } fs.release(); @@ -107,7 +107,7 @@ void CV_WatershedTest::run( int /* start_from */) continue; // bad result, doing nothing and going to get error latter; // repaint in saved color to compare with expected; - if(exp.data) + if(!exp.empty()) pixel = colors[pixel]; } } diff --git a/modules/ml/src/ann_mlp.cpp b/modules/ml/src/ann_mlp.cpp index b0e1447dc..ad40c8a29 100644 --- a/modules/ml/src/ann_mlp.cpp +++ b/modules/ml/src/ann_mlp.cpp @@ -1150,19 +1150,19 @@ public: size_t esz = weights[0].elemSize(); fs << "input_scale" << "["; - fs.writeRaw("d", weights[0].data, weights[0].total()*esz); + fs.writeRaw("d", weights[0].ptr(), weights[0].total()*esz); fs << "]" << "output_scale" << "["; - fs.writeRaw("d", weights[l_count].data, weights[l_count].total()*esz); + fs.writeRaw("d", weights[l_count].ptr(), weights[l_count].total()*esz); fs << "]" << "inv_output_scale" << "["; - fs.writeRaw("d", weights[l_count+1].data, weights[l_count+1].total()*esz); + fs.writeRaw("d", weights[l_count+1].ptr(), weights[l_count+1].total()*esz); fs << "]" << "weights" << "["; for( i = 1; i < l_count; i++ ) { fs << "["; - fs.writeRaw("d", weights[i].data, weights[i].total()*esz); + fs.writeRaw("d", weights[i].ptr(), weights[i].total()*esz); fs << "]"; } fs << "]"; @@ -1250,18 +1250,18 @@ public: size_t esz = weights[0].elemSize(); FileNode w = fn["input_scale"]; - w.readRaw("d", weights[0].data, weights[0].total()*esz); + w.readRaw("d", weights[0].ptr(), weights[0].total()*esz); w = fn["output_scale"]; - w.readRaw("d", weights[l_count].data, weights[l_count].total()*esz); + w.readRaw("d", weights[l_count].ptr(), weights[l_count].total()*esz); w = fn["inv_output_scale"]; - w.readRaw("d", weights[l_count+1].data, weights[l_count+1].total()*esz); + w.readRaw("d", weights[l_count+1].ptr(), weights[l_count+1].total()*esz); FileNodeIterator w_it = fn["weights"].begin(); for( i = 1; i < l_count; i++, ++w_it ) - (*w_it).readRaw("d", weights[i].data, weights[i].total()*esz); + (*w_it).readRaw("d", weights[i].ptr(), weights[i].total()*esz); trained = true; } diff --git a/modules/ml/src/data.cpp b/modules/ml/src/data.cpp index c9a323a43..6b5ceb488 100644 --- a/modules/ml/src/data.cpp +++ b/modules/ml/src/data.cpp @@ -762,7 +762,7 @@ public: else { Mat mask(1, nsamples, CV_8U); - uchar* mptr = mask.data; + uchar* mptr = mask.ptr(); for( i = 0; i < nsamples; i++ ) mptr[i] = (uchar)(i < count); trainSampleIdx.create(1, count, CV_32S); diff --git a/modules/ml/src/inner_functions.cpp b/modules/ml/src/inner_functions.cpp index 3d5f33520..dbc21ff09 100644 --- a/modules/ml/src/inner_functions.cpp +++ b/modules/ml/src/inner_functions.cpp @@ -97,7 +97,7 @@ float StatModel::calcError( const Ptr& data, bool testerr, OutputArra err += fabs(val - val0) > FLT_EPSILON; else err += (val - val0)*(val - val0); - if( resp.data ) + if( !resp.empty() ) resp.at(i) = val; /*if( i < 100 ) { diff --git a/modules/ml/src/nbayes.cpp b/modules/ml/src/nbayes.cpp index 2dbbcdf69..425e33739 100644 --- a/modules/ml/src/nbayes.cpp +++ b/modules/ml/src/nbayes.cpp @@ -205,7 +205,7 @@ public: vidx = &_vidx; cls_labels = &_cls_labels; results = &_results; - results_prob = _results_prob.data ? &_results_prob : 0; + results_prob = !_results_prob.empty() ? &_results_prob : 0; rawOutput = _rawOutput; } diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index 70311d91f..b33f7c22f 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -503,7 +503,7 @@ bool FeatureEvaluator::setImage( InputArray _image, const std::vector& _s for (i = 0; i < nscales; i++) { const ScaleData& s = scaleData->at(i); - Mat dst(s.szi.height - 1, s.szi.width - 1, CV_8U, rbuf.data); + Mat dst(s.szi.height - 1, s.szi.width - 1, CV_8U, rbuf.ptr()); resize(image, dst, dst.size(), 1. / s.scale, 1. / s.scale, INTER_LINEAR); computeChannels((int)i, dst); } diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 7230954dc..c078c2deb 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -123,7 +123,7 @@ void HOGDescriptor::setSVMDetector(InputArray _svmDetector) for (int j = 0; j < blocks_per_img.width; ++j) { const float *src = &svmDetector[0] + (j * blocks_per_img.height + i) * block_hist_size; - float *dst = (float*)detector_reordered.data + (i * blocks_per_img.width + j) * block_hist_size; + float *dst = detector_reordered.ptr() + (i * blocks_per_img.width + j) * block_hist_size; for (size_t k = 0; k < block_hist_size; ++k) dst[k] = src[k]; } @@ -300,12 +300,12 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, float angleScale = (float)(nbins/CV_PI); for( y = 0; y < gradsize.height; y++ ) { - const uchar* imgPtr = 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]; + const uchar* imgPtr = img.ptr(ymap[y]); + const uchar* prevPtr = img.ptr(ymap[y-1]); + const uchar* nextPtr = img.ptr(ymap[y+1]); - float* gradPtr = (float*)grad.ptr(y); - uchar* qanglePtr = (uchar*)qangle.ptr(y); + float* gradPtr = grad.ptr(y); + uchar* qanglePtr = qangle.ptr(y); if( cn == 1 ) { @@ -781,8 +781,8 @@ const float* HOGCache::getBlock(Point pt, float* buf) } int k, C1 = count1, C2 = count2, C4 = count4; - const float* gradPtr = (const float*)(grad.data + grad.step*pt.y) + pt.x*2; - const uchar* qanglePtr = qangle.data + qangle.step*pt.y + pt.x*2; + const float* gradPtr = grad.ptr(pt.y) + pt.x*2; + const uchar* qanglePtr = qangle.ptr(pt.y) + pt.x*2; // CV_Assert( blockHist != 0 ); memset(blockHist, 0, sizeof(float) * blockHistogramSize); @@ -1581,7 +1581,7 @@ public: { double scale = levelScale[i]; Size sz(cvRound(img.cols/scale), cvRound(img.rows/scale)); - Mat smallerImg(sz, img.type(), smallerImgBuf.data); + Mat smallerImg(sz, img.type(), smallerImgBuf.ptr()); if( sz == img.size() ) smallerImg = Mat(sz, img.type(), img.data, img.step); else @@ -3282,7 +3282,7 @@ public: double scale = (*locations)[i].scale; Size sz(cvRound(img.cols / scale), cvRound(img.rows / scale)); - Mat smallerImg(sz, img.type(), smallerImgBuf.data); + Mat smallerImg(sz, img.type(), smallerImgBuf.ptr()); if( sz == img.size() ) smallerImg = Mat(sz, img.type(), img.data, img.step); diff --git a/modules/objdetect/test/test_cascadeandhog.cpp b/modules/objdetect/test/test_cascadeandhog.cpp index 4a311e49e..df33ffe93 100644 --- a/modules/objdetect/test/test_cascadeandhog.cpp +++ b/modules/objdetect/test/test_cascadeandhog.cpp @@ -852,8 +852,8 @@ const float* HOGCacheTester::getBlock(Point pt, float* buf) } int k, C1 = count1, C2 = count2, C4 = count4; - const float* gradPtr = (const float*)(grad.data + grad.step*pt.y) + pt.x*2; - const uchar* qanglePtr = qangle.data + qangle.step*pt.y + pt.x*2; + const float* gradPtr = grad.ptr(pt.y) + pt.x*2; + const uchar* qanglePtr = qangle.ptr(pt.y) + pt.x*2; CV_Assert( blockHist != 0 ); for( k = 0; k < blockHistogramSize; k++ ) @@ -1234,9 +1234,9 @@ void HOGDescriptorTester::computeGradient(const Mat& img, Mat& grad, Mat& qangle float angleScale = (float)(_nbins/CV_PI); for( y = 0; y < gradsize.height; y++ ) { - const uchar* imgPtr = 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]; + const uchar* imgPtr = img.ptr(ymap[y]); + const uchar* prevPtr = img.ptr(ymap[y-1]); + const uchar* nextPtr = img.ptr(ymap[y+1]); float* gradPtr = (float*)grad.ptr(y); uchar* qanglePtr = (uchar*)qangle.ptr(y); diff --git a/modules/optim/src/conjugate_gradient.cpp b/modules/optim/src/conjugate_gradient.cpp index 027e9f18a..8854d5898 100644 --- a/modules/optim/src/conjugate_gradient.cpp +++ b/modules/optim/src/conjugate_gradient.cpp @@ -119,13 +119,13 @@ namespace cv{namespace optim{ Mat_ proxy_x; if(x_mat.rows>1){ buf_x.create(1,ndim); - Mat_ proxy(ndim,1,(double*)buf_x.data); + Mat_ proxy(ndim,1,buf_x.ptr()); x_mat.copyTo(proxy); proxy_x=buf_x; }else{ proxy_x=x_mat; } - _Function->getGradient((double*)proxy_x.data,(double*)d.data); + _Function->getGradient(proxy_x.ptr(),d.ptr()); d*=-1.0; d.copyTo(r); @@ -138,7 +138,7 @@ namespace cv{namespace optim{ for(int count=0;count<_termcrit.maxCount;count++){ minimizeOnTheLine(_Function,proxy_x,d,minimizeOnTheLine_buf1,minimizeOnTheLine_buf2); r.copyTo(r_old); - _Function->getGradient((double*)proxy_x.data,(double*)r.data); + _Function->getGradient(proxy_x.ptr(),r.ptr()); r*=-1.0; double r_norm_sq=norm(r); if(_termcrit.type==(TermCriteria::MAX_ITER+TermCriteria::EPS) && r_norm_sq<_termcrit.epsilon){ @@ -152,9 +152,9 @@ namespace cv{namespace optim{ if(x_mat.rows>1){ - Mat(ndim, 1, CV_64F, (double*)proxy_x.data).copyTo(x); + Mat(ndim, 1, CV_64F, proxy_x.ptr()).copyTo(x); } - return _Function->calc((double*)proxy_x.data); + return _Function->calc(proxy_x.ptr()); } ConjGradSolverImpl::ConjGradSolverImpl(){ diff --git a/modules/optim/src/simplex.cpp b/modules/optim/src/simplex.cpp index 308a21974..253a2e989 100644 --- a/modules/optim/src/simplex.cpp +++ b/modules/optim/src/simplex.cpp @@ -182,7 +182,7 @@ namespace cv{namespace optim{ { ptry(j)=coord_sum(j)*fac1-p(ihi,j)*fac2; } - ytry=f->calc((double*)ptry.data); + ytry=f->calc(ptry.ptr()); if (ytry < y(ihi)) { y(ihi)=ytry; @@ -302,7 +302,7 @@ namespace cv{namespace optim{ { p(i,j) = coord_sum(j) = 0.5*(p(i,j)+p(ilo,j)); } - y(i)=f->calc((double*)coord_sum.data); + y(i)=f->calc(coord_sum.ptr()); } } nfunk += ndim; @@ -345,7 +345,7 @@ namespace cv{namespace optim{ if(x_mat.rows>1){ buf_x.create(1,_step.cols); - Mat_ proxy(_step.cols,1,(double*)buf_x.data); + Mat_ proxy(_step.cols,1,buf_x.ptr()); x_mat.copyTo(proxy); proxy_x=buf_x; }else{ @@ -365,7 +365,7 @@ namespace cv{namespace optim{ dprintf(("%d iterations done\n",count)); if(x_mat.rows>1){ - Mat(x_mat.rows, 1, CV_64F, (double*)proxy_x.data).copyTo(x); + Mat(x_mat.rows, 1, CV_64F, proxy_x.ptr()).copyTo(x); } return res; } diff --git a/modules/stitching/src/autocalib.cpp b/modules/stitching/src/autocalib.cpp index 98fe1472f..56a9df57b 100644 --- a/modules/stitching/src/autocalib.cpp +++ b/modules/stitching/src/autocalib.cpp @@ -67,7 +67,7 @@ void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, boo { CV_Assert(H.type() == CV_64F && H.size() == Size(3, 3)); - const double* h = reinterpret_cast(H.data); + const double* h = H.ptr(); double d1, d2; // Denominators double v1, v2; // Focal squares value candidates diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 2042f5cf0..7745c86c5 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -190,7 +190,7 @@ void add(const Mat& _a, double alpha, const Mat& _b, double beta, if(!b.empty()) buf[1].create(1, maxsize, CV_64FC(cn)); buf[2].create(1, maxsize, CV_64FC(cn)); - scalarToRawData(gamma, buf[2].data, CV_64FC(cn), (int)(maxsize*cn)); + scalarToRawData(gamma, buf[2].ptr(), CV_64FC(cn), (int)(maxsize*cn)); for( i = 0; i < nplanes; i++, ++it) { @@ -203,8 +203,8 @@ void add(const Mat& _a, double alpha, const Mat& _b, double beta, apart0.convertTo(apart, apart.type(), alpha); size_t k, n = (j2 - j)*cn; - double* aptr = (double*)apart.data; - const double* gptr = (const double*)buf[2].data; + double* aptr = apart.ptr(); + const double* gptr = buf[2].ptr(); if( b.empty() ) { @@ -216,7 +216,7 @@ void add(const Mat& _a, double alpha, const Mat& _b, double beta, Mat bpart0 = planes[1].colRange((int)j, (int)j2); Mat bpart = buf[1].colRange(0, (int)(j2 - j)); bpart0.convertTo(bpart, bpart.type(), beta); - const double* bptr = (const double*)bpart.data; + const double* bptr = bpart.ptr(); for( k = 0; k < n; k++ ) aptr[k] += bptr[k] + gptr[k]; @@ -303,8 +303,8 @@ void convert(const Mat& src, cv::OutputArray _dst, int dtype, double alpha, doub for( i = 0; i < nplanes; i++, ++it) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); switch( src.depth() ) { @@ -347,7 +347,7 @@ void copy(const Mat& src, Mat& dst, const Mat& mask, bool invertMask) size_t planeSize = planes[0].total()*src.elemSize(); for( i = 0; i < nplanes; i++, ++it ) - memcpy(planes[1].data, planes[0].data, planeSize); + memcpy(planes[1].ptr(), planes[0].ptr(), planeSize); return; } @@ -363,9 +363,9 @@ void copy(const Mat& src, Mat& dst, const Mat& mask, bool invertMask) for( i = 0; i < nplanes; i++, ++it) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; - const uchar* mptr = planes[2].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); + const uchar* mptr = planes[2].ptr(); for( j = 0; j < total; j++, sptr += elemSize, dptr += elemSize ) { @@ -398,7 +398,7 @@ void set(Mat& dst, const Scalar& gamma, const Mat& mask) for( i = 0; i < nplanes; i++, ++it ) { - uchar* dptr = plane.data; + uchar* dptr = plane.ptr(); if( uniform ) memset( dptr, gptr[0], planeSize ); else if( i == 0 ) @@ -408,7 +408,7 @@ void set(Mat& dst, const Scalar& gamma, const Mat& mask) dptr[k] = gptr[k]; } else - memcpy(dptr, dst.data, planeSize); + memcpy(dptr, dst.ptr(), planeSize); } return; } @@ -424,8 +424,8 @@ void set(Mat& dst, const Scalar& gamma, const Mat& mask) for( i = 0; i < nplanes; i++, ++it) { - uchar* dptr = planes[0].data; - const uchar* mptr = planes[1].data; + uchar* dptr = planes[0].ptr(); + const uchar* mptr = planes[1].ptr(); for( j = 0; j < total; j++, dptr += elemSize ) { @@ -450,8 +450,8 @@ void insert(const Mat& src, Mat& dst, int coi) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data + coi*size0; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr() + coi*size0; for( j = 0; j < total; j++, sptr += size0, dptr += size1 ) { @@ -475,8 +475,8 @@ void extract(const Mat& src, Mat& dst, int coi) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data + coi*size1; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr() + coi*size1; + uchar* dptr = planes[1].ptr(); for( j = 0; j < total; j++, sptr += size0, dptr += size1 ) { @@ -1055,8 +1055,8 @@ void minMaxLoc(const Mat& src, double* _minval, double* _maxval, for( i = 0; i < nplanes; i++, ++it, startidx += total ) { - const uchar* sptr = planes[0].data; - const uchar* mptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + const uchar* mptr = planes[1].ptr(); switch( depth ) { @@ -1262,7 +1262,7 @@ double norm(InputArray _src, int normType, InputArray _mask) int cellSize = normType == NORM_HAMMING ? 1 : 2; for( i = 0; i < nplanes; i++, ++it ) - result += normHamming(planes[0].data, total, cellSize); + result += normHamming(planes[0].ptr(), total, cellSize); return result; } int normType0 = normType; @@ -1282,8 +1282,8 @@ double norm(InputArray _src, int normType, InputArray _mask) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - const uchar* mptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + const uchar* mptr = planes[1].ptr(); switch( depth ) { @@ -1343,7 +1343,7 @@ double norm(InputArray _src1, InputArray _src2, int normType, InputArray _mask) int cellSize = normType == NORM_HAMMING ? 1 : 2; for( i = 0; i < nplanes; i++, ++it ) - result += normHamming(planes[0].data, total, cellSize); + result += normHamming(planes[0].ptr(), total, cellSize); return result; } int normType0 = normType; @@ -1363,9 +1363,9 @@ double norm(InputArray _src1, InputArray _src2, int normType, InputArray _mask) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; - const uchar* mptr = planes[2].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); + const uchar* mptr = planes[2].ptr(); switch( depth ) { @@ -1429,8 +1429,8 @@ double crossCorr(const Mat& src1, const Mat& src2) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); switch( depth ) { @@ -1526,9 +1526,9 @@ void logicOp( const Mat& src1, const Mat& src2, Mat& dst, char op ) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; - uchar* dptr = planes[2].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); + uchar* dptr = planes[2].ptr(); logicOp_(sptr1, sptr2, dptr, total, op); } @@ -1550,8 +1550,8 @@ void logicOp(const Mat& src, const Scalar& s, Mat& dst, char op) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); logicOpS_(sptr, (uchar*)&buf[0], dptr, total, op); } @@ -1644,9 +1644,9 @@ void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; - uchar* dptr = planes[2].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); + uchar* dptr = planes[2].ptr(); switch( depth ) { @@ -1692,8 +1692,8 @@ void compare(const Mat& src, double value, Mat& dst, int cmpop) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); switch( depth ) { @@ -1823,8 +1823,8 @@ bool cmpUlps(const Mat& src1, const Mat& src2, int imaxDiff, double* _realmaxdif for( i = 0; i < nplanes; i++, ++it, startidx += total ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); double realmaxdiff = 0; switch( depth ) @@ -1914,7 +1914,7 @@ int check( const Mat& a, double fmin, double fmax, vector* _idx ) for( i = 0; i < nplanes; i++, ++it, startidx += total ) { - const uchar* aptr = plane.data; + const uchar* aptr = plane.ptr(); switch( depth ) { @@ -1990,8 +1990,8 @@ int cmpEps( const Mat& arr, const Mat& refarr, double* _realmaxdiff, for( i = 0; i < nplanes; i++, ++it, startidx += total ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); switch( depth ) { @@ -2332,8 +2332,8 @@ void transform( const Mat& src, Mat& dst, const Mat& transmat, const Mat& _shift for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); switch( depth ) { @@ -2388,9 +2388,9 @@ static void minmax(const Mat& src1, const Mat& src2, Mat& dst, char op) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; - uchar* dptr = planes[2].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); + uchar* dptr = planes[2].ptr(); switch( depth ) { @@ -2457,8 +2457,8 @@ static void minmax(const Mat& src1, double val, Mat& dst, char op) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr1 = planes[0].data; - uchar* dptr = planes[1].data; + const uchar* sptr1 = planes[0].ptr(); + uchar* dptr = planes[1].ptr(); switch( depth ) { @@ -2528,9 +2528,9 @@ static void muldiv(const Mat& src1, const Mat& src2, Mat& dst, double scale, cha for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr1 = planes[0].data; - const uchar* sptr2 = planes[1].data; - uchar* dptr = planes[2].data; + const uchar* sptr1 = planes[0].ptr(); + const uchar* sptr2 = planes[1].ptr(); + uchar* dptr = planes[2].ptr(); switch( depth ) { @@ -2614,8 +2614,8 @@ Scalar mean(const Mat& src, const Mat& mask) for( i = 0; i < nplanes; i++, ++it ) { - const uchar* sptr = planes[0].data; - const uchar* mptr = planes[1].data; + const uchar* sptr = planes[0].ptr(); + const uchar* mptr = planes[1].ptr(); switch( depth ) { diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index 08c3d12d6..f7917f2e6 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -840,9 +840,9 @@ void BackgroundSubtractorMOG2Impl::apply(InputArray _image, OutputArray _fgmask, parallel_for_(Range(0, image.rows), MOG2Invoker(image, fgmask, - (GMM*)bgmodel.data, - (float*)(bgmodel.data + sizeof(GMM)*nmixtures*image.rows*image.cols), - bgmodelUsedModes.data, nmixtures, (float)learningRate, + bgmodel.ptr(), + (float*)(bgmodel.ptr() + sizeof(GMM)*nmixtures*image.rows*image.cols), + bgmodelUsedModes.ptr(), nmixtures, (float)learningRate, (float)varThreshold, backgroundRatio, varThresholdGen, fVarInit, fVarMin, fVarMax, float(-learningRate*fCT), fTau, @@ -864,7 +864,7 @@ void BackgroundSubtractorMOG2Impl::getBackgroundImage(OutputArray backgroundImag CV_Assert(nchannels == 1 || nchannels == 3); Mat meanBackground(frameSize, CV_MAKETYPE(CV_8U, nchannels), Scalar::all(0)); int firstGaussianIdx = 0; - const GMM* gmm = (GMM*)bgmodel.data; + const GMM* gmm = bgmodel.ptr(); const float* mean = reinterpret_cast(gmm + frameSize.width*frameSize.height*nmixtures); std::vector meanVal(nchannels, 0.f); for(int row=0; row() + (y + iprevPt.y)*dstep + iprevPt.x*cn2; - deriv_type* Iptr = (deriv_type*)(IWinBuf.data + y*IWinBuf.step); - deriv_type* dIptr = (deriv_type*)(derivIWinBuf.data + y*derivIWinBuf.step); + deriv_type* Iptr = IWinBuf.ptr(y); + deriv_type* dIptr = derivIWinBuf.ptr(y); x = 0; @@ -541,9 +541,9 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const for( y = 0; y < winSize.height; y++ ) { - const uchar* Jptr = (const uchar*)J.data + (y + inextPt.y)*stepJ + inextPt.x*cn; - const deriv_type* Iptr = (const deriv_type*)(IWinBuf.data + y*IWinBuf.step); - const deriv_type* dIptr = (const deriv_type*)(derivIWinBuf.data + y*derivIWinBuf.step); + const uchar* Jptr = J.ptr() + (y + inextPt.y)*stepJ + inextPt.x*cn; + const deriv_type* Iptr = IWinBuf.ptr(y); + const deriv_type* dIptr = derivIWinBuf.ptr(y); x = 0; @@ -725,8 +725,8 @@ void cv::detail::LKTrackerInvoker::operator()(const Range& range) const for( y = 0; y < winSize.height; y++ ) { - const uchar* Jptr = (const uchar*)J.data + (y + inextPoint.y)*stepJ + inextPoint.x*cn; - const deriv_type* Iptr = (const deriv_type*)(IWinBuf.data + y*IWinBuf.step); + const uchar* Jptr = J.ptr() + (y + inextPoint.y)*stepJ + inextPoint.x*cn; + const deriv_type* Iptr = IWinBuf.ptr(y); for( x = 0; x < winSize.width*cn; x++ ) { @@ -1120,13 +1120,13 @@ void cv::calcOpticalFlowPyrLK( InputArray _prevImg, InputArray _nextImg, Mat nextPtsMat = _nextPts.getMat(); CV_Assert( nextPtsMat.checkVector(2, CV_32F, true) == npoints ); - const Point2f* prevPts = (const Point2f*)prevPtsMat.data; - Point2f* nextPts = (Point2f*)nextPtsMat.data; + const Point2f* prevPts = prevPtsMat.ptr(); + Point2f* nextPts = nextPtsMat.ptr(); _status.create((int)npoints, 1, CV_8U, -1, true); Mat statusMat = _status.getMat(), errMat; CV_Assert( statusMat.isContinuous() ); - uchar* status = statusMat.data; + uchar* status = statusMat.ptr(); float* err = 0; for( i = 0; i < npoints; i++ ) @@ -1137,7 +1137,7 @@ void cv::calcOpticalFlowPyrLK( InputArray _prevImg, InputArray _nextImg, _err.create((int)npoints, 1, CV_32F, -1, true); errMat = _err.getMat(); CV_Assert( errMat.isContinuous() ); - err = (float*)errMat.data; + err = errMat.ptr(); } std::vector prevPyr, nextPyr; @@ -1230,7 +1230,7 @@ void cv::calcOpticalFlowPyrLK( InputArray _prevImg, InputArray _nextImg, { Size imgSize = prevPyr[level * lvlStep1].size(); Mat _derivI( imgSize.height + winSize.height*2, - imgSize.width + winSize.width*2, derivIBuf.type(), derivIBuf.data ); + imgSize.width + winSize.width*2, derivIBuf.type(), derivIBuf.ptr() ); derivI = _derivI(Rect(winSize.width, winSize.height, imgSize.width, imgSize.height)); calcSharrDeriv(prevPyr[level * lvlStep1], derivI); copyMakeBorder(derivI, _derivI, winSize.height, winSize.height, winSize.width, winSize.width, BORDER_CONSTANT|BORDER_ISOLATED); diff --git a/modules/video/src/optflowgf.cpp b/modules/video/src/optflowgf.cpp index 27abf739f..90499b5e5 100644 --- a/modules/video/src/optflowgf.cpp +++ b/modules/video/src/optflowgf.cpp @@ -134,8 +134,8 @@ FarnebackPolyExp( const Mat& src, Mat& dst, int n, double sigma ) for( y = 0; y < height; y++ ) { float g0 = g[0], g1, g2; - float *srow0 = (float*)(src.data + src.step*y), *srow1 = 0; - float *drow = (float*)(dst.data + dst.step*y); + const float *srow0 = src.ptr(y), *srow1 = 0; + float *drow = dst.ptr(y); // vertical part of convolution for( x = 0; x < width; x++ ) @@ -147,8 +147,8 @@ FarnebackPolyExp( const Mat& src, Mat& dst, int n, double sigma ) for( k = 1; k <= n; k++ ) { g0 = g[k]; g1 = xg[k]; g2 = xxg[k]; - srow0 = (float*)(src.data + src.step*std::max(y-k,0)); - srow1 = (float*)(src.data + src.step*std::min(y+k,height-1)); + srow0 = src.ptr(std::max(y-k,0)); + srow1 = src.ptr(std::min(y+k,height-1)); for( x = 0; x < width; x++ ) { @@ -220,16 +220,16 @@ FarnebackUpdateMatrices( const Mat& _R0, const Mat& _R1, const Mat& _flow, Mat& static const float border[BORDER] = {0.14f, 0.14f, 0.4472f, 0.4472f, 0.4472f}; int x, y, width = _flow.cols, height = _flow.rows; - const float* R1 = (float*)_R1.data; + const float* R1 = _R1.ptr(); size_t step1 = _R1.step/sizeof(R1[0]); matM.create(height, width, CV_32FC(5)); for( y = _y0; y < _y1; y++ ) { - const float* flow = (float*)(_flow.data + y*_flow.step); - const float* R0 = (float*)(_R0.data + y*_R0.step); - float* M = (float*)(matM.data + y*matM.step); + const float* flow = _flow.ptr(y); + const float* R0 = _R0.ptr(y); + float* M = matM.ptr(y); for( x = 0; x < width; x++ ) { @@ -325,13 +325,13 @@ FarnebackUpdateFlow_Blur( const Mat& _R0, const Mat& _R1, double* vsum = _vsum + (m+1)*5; // init vsum - const float* srow0 = (const float*)matM.data; + const float* srow0 = matM.ptr(); for( x = 0; x < width*5; x++ ) vsum[x] = srow0[x]*(m+2); for( y = 1; y < m; y++ ) { - srow0 = (float*)(matM.data + matM.step*std::min(y,height-1)); + srow0 = matM.ptr(std::min(y,height-1)); for( x = 0; x < width*5; x++ ) vsum[x] += srow0[x]; } @@ -340,10 +340,10 @@ FarnebackUpdateFlow_Blur( const Mat& _R0, const Mat& _R1, for( y = 0; y < height; y++ ) { double g11, g12, g22, h1, h2; - float* flow = (float*)(_flow.data + _flow.step*y); + float* flow = _flow.ptr(y); - srow0 = (const float*)(matM.data + matM.step*std::max(y-m-1,0)); - const float* srow1 = (const float*)(matM.data + matM.step*std::min(y+m,height-1)); + srow0 = matM.ptr(std::max(y-m-1,0)); + const float* srow1 = matM.ptr(std::min(y+m,height-1)); // vertical blur for( x = 0; x < width*5; x++ ) @@ -447,13 +447,13 @@ FarnebackUpdateFlow_GaussianBlur( const Mat& _R0, const Mat& _R1, for( y = 0; y < height; y++ ) { double g11, g12, g22, h1, h2; - float* flow = (float*)(_flow.data + _flow.step*y); + float* flow = _flow.ptr(y); // vertical blur for( i = 0; i <= m; i++ ) { - srow[m-i] = (const float*)(matM.data + matM.step*std::max(y-i,0)); - srow[m+i] = (const float*)(matM.data + matM.step*std::min(y+i,height-1)); + srow[m-i] = matM.ptr(std::max(y-i,0)); + srow[m+i] = matM.ptr(std::min(y+i,height-1)); } x = 0; @@ -1122,7 +1122,7 @@ void cv::calcOpticalFlowFarneback( InputArray _prev0, InputArray _next0, else flow = flow0; - if( !prevFlow.data ) + if( prevFlow.empty() ) { if( flags & OPTFLOW_USE_INITIAL_FLOW ) { diff --git a/samples/cpp/3calibration.cpp b/samples/cpp/3calibration.cpp index 53254050c..cf37e6500 100644 --- a/samples/cpp/3calibration.cpp +++ b/samples/cpp/3calibration.cpp @@ -268,7 +268,7 @@ int main( int argc, char** argv ) printf("%s\n", imageList[i*3+k].c_str()); view = imread(imageList[i*3+k], 1); - if(view.data) + if(!view.empty()) { vector ptvec; imageSize = view.size(); @@ -356,7 +356,7 @@ int main( int argc, char** argv ) int k2 = k == 0 ? 1 : k == 1 ? 0 : 2; view = imread(imageList[i*3+k], 1); - if(!view.data) + if(view.empty()) continue; Mat rview = canvas.colRange(k2*imageSize.width, (k2+1)*imageSize.width); diff --git a/samples/cpp/calibration.cpp b/samples/cpp/calibration.cpp index 9a71715b3..7c751f8f6 100644 --- a/samples/cpp/calibration.cpp +++ b/samples/cpp/calibration.cpp @@ -448,7 +448,7 @@ int main( int argc, char** argv ) else if( i < (int)imageList.size() ) view = imread(imageList[i], 1); - if(!view.data) + if(view.empty()) { if( imagePoints.size() > 0 ) runAndSave(outputFilename, imagePoints, imageSize, @@ -563,7 +563,7 @@ int main( int argc, char** argv ) for( i = 0; i < (int)imageList.size(); i++ ) { view = imread(imageList[i], 1); - if(!view.data) + if(view.empty()) continue; //undistort( view, rview, cameraMatrix, distCoeffs, cameraMatrix ); remap(view, rview, map1, map2, INTER_LINEAR); diff --git a/samples/cpp/cloning_gui.cpp b/samples/cpp/cloning_gui.cpp index db6cfcfde..07671ca8a 100644 --- a/samples/cpp/cloning_gui.cpp +++ b/samples/cpp/cloning_gui.cpp @@ -319,12 +319,12 @@ int main() img2 = imread(dest); - if(!img0.data) + if(img0.empty()) { cout << "Source Image does not exist" << endl; exit(0); } - if(!img2.data) + if(img2.empty()) { cout << "Destination Image does not exist" << endl; exit(0); @@ -367,7 +367,7 @@ int main() img0 = imread(src); - if(!img0.data) + if(img0.empty()) { cout << "Source Image does not exist" << endl; exit(0); @@ -397,7 +397,7 @@ int main() img0 = imread(src); - if(!img0.data) + if(img0.empty()) { cout << "Source Image does not exist" << endl; exit(0); @@ -430,7 +430,7 @@ int main() img0 = imread(src); - if(!img0.data) + if(img0.empty()) { cout << "Source Image does not exist" << endl; exit(0); diff --git a/samples/cpp/image.cpp b/samples/cpp/image.cpp index f63d3b77e..a9a18e312 100644 --- a/samples/cpp/image.cpp +++ b/samples/cpp/image.cpp @@ -48,7 +48,7 @@ int main( int argc, char** argv ) } #endif - if( !img.data ) // check if the image has been loaded properly + if( img.empty() ) // check if the image has been loaded properly return -1; Mat img_yuv; diff --git a/samples/cpp/morphology2.cpp b/samples/cpp/morphology2.cpp index 1bb4ec55e..d41265631 100644 --- a/samples/cpp/morphology2.cpp +++ b/samples/cpp/morphology2.cpp @@ -59,7 +59,7 @@ static void ErodeDilate(int, void*) int main( int argc, char** argv ) { char* filename = argc == 2 ? argv[1] : (char*)"baboon.jpg"; - if( (src = imread(filename,1)).data == 0 ) + if( (src = imread(filename,1)).empty() ) return -1; help(); diff --git a/samples/cpp/npr_demo.cpp b/samples/cpp/npr_demo.cpp index ff6a3fce6..e4fade0d8 100644 --- a/samples/cpp/npr_demo.cpp +++ b/samples/cpp/npr_demo.cpp @@ -38,7 +38,7 @@ int main(int argc, char* argv[]) Mat I = imread(argv[1]); - if(!I.data) + if(I.empty()) { cout << "Image not found" << endl; exit(0); diff --git a/samples/cpp/segment_objects.cpp b/samples/cpp/segment_objects.cpp index 814a3d79f..72afbdeed 100644 --- a/samples/cpp/segment_objects.cpp +++ b/samples/cpp/segment_objects.cpp @@ -79,7 +79,7 @@ int main(int argc, char** argv) Mat tmp_frame, bgmask, out_frame; cap >> tmp_frame; - if(!tmp_frame.data) + if(tmp_frame.empty()) { printf("can not read data from the video source\n"); return -1; @@ -94,7 +94,7 @@ int main(int argc, char** argv) for(;;) { cap >> tmp_frame; - if( !tmp_frame.data ) + if( tmp_frame.empty() ) break; bgsubtractor->apply(tmp_frame, bgmask, update_bg_model ? -1 : 0); refineSegments(tmp_frame, bgmask, out_frame); diff --git a/samples/cpp/select3dobj.cpp b/samples/cpp/select3dobj.cpp index 7df95d17c..ed598f2a1 100644 --- a/samples/cpp/select3dobj.cpp +++ b/samples/cpp/select3dobj.cpp @@ -147,7 +147,7 @@ static Rect extract3DBox(const Mat& frame, Mat& shownFrame, Mat& selectedObjFram projectPoints(Mat(objpt), rvec, tvec, cameraMatrix, Mat(), imgpt); - if( shownFrame.data ) + if( !shownFrame.empty() ) { if( nobjpt == 1 ) circle(shownFrame, imgpt[0], 3, Scalar(0,255,0), -1, LINE_AA); @@ -534,9 +534,9 @@ int main(int argc, char** argv) } else capture >> frame0; - if( !frame0.data ) + if( frame0.empty() ) break; - if( !frame.data ) + if( frame.empty() ) { if( frame0.size() != calibratedImageSize ) { diff --git a/samples/cpp/train_HOG.cpp b/samples/cpp/train_HOG.cpp index fbd217a96..dfecb0e03 100644 --- a/samples/cpp/train_HOG.cpp +++ b/samples/cpp/train_HOG.cpp @@ -37,7 +37,7 @@ void get_svm_detector(const Ptr& svm, vector< float > & hog_detector ) hog_detector.clear(); hog_detector.resize(sv.cols + 1); - memcpy(&hog_detector[0], sv.data, sv.cols*sizeof(hog_detector[0])); + memcpy(&hog_detector[0], sv.ptr(), sv.cols*sizeof(hog_detector[0])); hog_detector[sv.cols] = (float)-rho; } @@ -94,7 +94,7 @@ void load_images( const string & prefix, const string & filename, vector< Mat > break; } Mat img = imread( (prefix+line).c_str() ); // load the image - if( !img.data ) // invalid image, just skip it. + if( img.empty() ) // invalid image, just skip it. continue; #ifdef _DEBUG imshow( "image", img ); @@ -381,7 +381,7 @@ void test_it( const Size & size ) while( !end_of_process ) { video >> img; - if( !img.data ) + if( img.empty() ) break; draw = img.clone(); diff --git a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp index 475675b41..11843fb08 100644 --- a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp @@ -47,8 +47,8 @@ int main( void ) src1 = imread("../images/LinuxLogo.jpg"); src2 = imread("../images/WindowsLogo.jpg"); - if( !src1.data ) { printf("Error loading src1 \n"); return -1; } - if( !src2.data ) { printf("Error loading src2 \n"); return -1; } + if( src1.empty() ) { printf("Error loading src1 \n"); return -1; } + if( src2.empty() ) { printf("Error loading src2 \n"); return -1; } /// Initialize values alpha_slider = 0; diff --git a/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp index 3edfa8c3d..45db5854e 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp @@ -26,7 +26,7 @@ int main( int, char** argv ) /// Load image src = imread( argv[1], 1 ); - if( !src.data ) + if( src.empty() ) { cout<<"Usage: ./Histogram_Demo "<CreateTexture2D(&desc, &srInitData, &pInputTexture))) diff --git a/samples/directx/d3d11_interop.cpp b/samples/directx/d3d11_interop.cpp index 9db9c31fb..d4fca058e 100644 --- a/samples/directx/d3d11_interop.cpp +++ b/samples/directx/d3d11_interop.cpp @@ -104,7 +104,7 @@ bool initDirect3DTextures() desc.CPUAccessFlags = cv::ocl::useOpenCL() ? 0 : D3D11_CPU_ACCESS_READ; D3D11_SUBRESOURCE_DATA srInitData; - srInitData.pSysMem = inputMat.data; + srInitData.pSysMem = inputMat.ptr(); srInitData.SysMemPitch = (UINT)inputMat.step[0]; if (FAILED(dev->CreateTexture2D(&desc, &srInitData, &pInputTexture)))