diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index d9c1df3923..ac4c8367a3 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -60,6 +60,7 @@ \************************************************************************************/ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include "circlesgrid.hpp" #include diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index bcf20cb800..176503f81f 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include #include diff --git a/modules/calib3d/src/checkchessboard.cpp b/modules/calib3d/src/checkchessboard.cpp index 9191fc8c84..4019d564e6 100644 --- a/modules/calib3d/src/checkchessboard.cpp +++ b/modules/calib3d/src/checkchessboard.cpp @@ -40,6 +40,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include #include diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index 9d893ffe97..3514aeb4be 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -1364,7 +1364,7 @@ void CirclesGridFinder::drawHoles(const Mat &srcImage, Mat &drawImage) const const Scalar holeColor = Scalar(0, 255, 0); if (srcImage.channels() == 1) - cvtColor(srcImage, drawImage, CV_GRAY2RGB); + cvtColor(srcImage, drawImage, COLOR_GRAY2RGB); else srcImage.copyTo(drawImage); diff --git a/modules/calib3d/src/precomp.hpp b/modules/calib3d/src/precomp.hpp index 7cd4a4ec48..12885f37a7 100644 --- a/modules/calib3d/src/precomp.hpp +++ b/modules/calib3d/src/precomp.hpp @@ -44,7 +44,6 @@ #include "opencv2/calib3d.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/features2d.hpp" #include "opencv2/core/utility.hpp" diff --git a/modules/calib3d/src/quadsubpix.cpp b/modules/calib3d/src/quadsubpix.cpp index 26f26b5807..b2a9ab836b 100644 --- a/modules/calib3d/src/quadsubpix.cpp +++ b/modules/calib3d/src/quadsubpix.cpp @@ -47,40 +47,8 @@ #include -//#define _SUBPIX_VERBOSE - -#undef max - namespace cv { - -// static void drawCircles(Mat& img, const std::vector& corners, const std::vector& radius) -// { -// for(size_t i = 0; i < corners.size(); i++) -// { -// circle(img, corners[i], cvRound(radius[i]), CV_RGB(255, 0, 0)); -// } -// } - -// static int histQuantile(const Mat& hist, float quantile) -// { -// if(hist.dims > 1) return -1; // works for 1D histograms only - -// float cur_sum = 0; -// float total_sum = (float)sum(hist).val[0]; -// float quantile_sum = total_sum*quantile; -// for(int j = 0; j < hist.size[0]; j++) -// { -// cur_sum += (float)hist.at(j); -// if(cur_sum > quantile_sum) -// { -// return j; -// } -// } - -// return hist.size[0] - 1; -// } - inline bool is_smaller(const std::pair& p1, const std::pair& p2) { return p1.second < p2.second; @@ -124,29 +92,6 @@ static void findLinesCrossPoint(Point2f origin1, Point2f dir1, Point2f origin2, cross_point = origin1 + dir1*alpha; } -// static void findCorner(const std::vector& contour, Point2f point, Point2f& corner) -// { -// // find the nearest point -// double min_dist = std::numeric_limits::max(); -// int min_idx = -1; - -// // find corner idx -// for(size_t i = 0; i < contour.size(); i++) -// { -// double dist = norm(Point2f((float)contour[i].x, (float)contour[i].y) - point); -// if(dist < min_dist) -// { -// min_dist = dist; -// min_idx = (int)i; -// } -// } -// assert(min_idx >= 0); - -// // temporary solution, have to make something more precise -// corner = contour[min_idx]; -// return; -// } - static void findCorner(const std::vector& contour, Point2f point, Point2f& corner) { // find the nearest point @@ -173,13 +118,7 @@ static void findCorner(const std::vector& contour, Point2f point, Point static int segment_hist_max(const Mat& hist, int& low_thresh, int& high_thresh) { Mat bw; - //const double max_bell_width = 20; // we expect two bells with width bounded above - //const double min_bell_width = 5; // and below - double total_sum = sum(hist).val[0]; - //double thresh = total_sum/(2*max_bell_width)*0.25f; // quarter of a bar inside a bell - -// threshold(hist, bw, thresh, 255.0, CV_THRESH_BINARY); double quantile_sum = 0.0; //double min_quantile = 0.2; @@ -233,12 +172,6 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size const float* _ranges = ranges; Mat hist; -#if defined(_SUBPIX_VERBOSE) - std::vector radius; - radius.assign(corners.size(), 0.0f); -#endif //_SUBPIX_VERBOSE - - Mat black_comp, white_comp; for(int i = 0; i < ncorners; i++) { @@ -248,39 +181,20 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size Mat img_roi = img(roi); calcHist(&img_roi, 1, &channels, Mat(), hist, 1, &nbins, &_ranges); -#if 0 - int black_thresh = histQuantile(hist, 0.45f); - int white_thresh = histQuantile(hist, 0.55f); -#else int black_thresh = 0, white_thresh = 0; segment_hist_max(hist, black_thresh, white_thresh); -#endif - threshold(img, black_comp, black_thresh, 255.0, CV_THRESH_BINARY_INV); - threshold(img, white_comp, white_thresh, 255.0, CV_THRESH_BINARY); + threshold(img, black_comp, black_thresh, 255.0, THRESH_BINARY_INV); + threshold(img, white_comp, white_thresh, 255.0, THRESH_BINARY); const int erode_count = 1; erode(black_comp, black_comp, Mat(), Point(-1, -1), erode_count); erode(white_comp, white_comp, Mat(), Point(-1, -1), erode_count); -#if defined(_SUBPIX_VERBOSE) - namedWindow("roi", 1); - imshow("roi", img_roi); - imwrite("test.jpg", img); - namedWindow("black", 1); - imshow("black", black_comp); - namedWindow("white", 1); - imshow("white", white_comp); - cvWaitKey(0); - imwrite("black.jpg", black_comp); - imwrite("white.jpg", white_comp); -#endif - - std::vector > white_contours, black_contours; std::vector white_hierarchy, black_hierarchy; - findContours(black_comp, black_contours, black_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); - findContours(white_comp, white_contours, white_hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); + findContours(black_comp, black_contours, black_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE); + findContours(white_comp, white_contours, white_hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE); if(black_contours.size() < 5 || white_contours.size() < 5) continue; @@ -302,15 +216,11 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size Point2f quad_corners[4]; for(int k = 0; k < 4; k++) { -#if 1 std::vector temp; for(size_t j = 0; j < quads[k]->size(); j++) temp.push_back((*quads[k])[j]); approxPolyDP(Mat(temp), quads_approx[k], 0.5, true); findCorner(quads_approx[k], corners[i], quad_corners[k]); -#else - findCorner(*quads[k], corners[i], quad_corners[k]); -#endif quad_corners[k] += Point2f(0.5f, 0.5f); } @@ -323,44 +233,7 @@ bool cv::find4QuadCornerSubpix(InputArray _img, InputOutputArray _corners, Size if(cvIsNaN(angle) || cvIsInf(angle) || angle < 0.5 || angle > CV_PI - 0.5) continue; findLinesCrossPoint(origin1, dir1, origin2, dir2, corners[i]); - -#if defined(_SUBPIX_VERBOSE) - radius[i] = norm(corners[i] - ground_truth_corners[ground_truth_idx])*6; - -#if 1 - Mat test(img.size(), CV_32FC3); - cvtColor(img, test, CV_GRAY2RGB); -// line(test, quad_corners[0] - corners[i] + Point2f(30, 30), quad_corners[1] - corners[i] + Point2f(30, 30), cvScalar(0, 255, 0)); -// line(test, quad_corners[2] - corners[i] + Point2f(30, 30), quad_corners[3] - corners[i] + Point2f(30, 30), cvScalar(0, 255, 0)); - std::vector > contrs; - contrs.resize(1); - for(int k = 0; k < 4; k++) - { - //contrs[0] = quads_approx[k]; - contrs[0].clear(); - for(size_t j = 0; j < quads_approx[k].size(); j++) contrs[0].push_back(quads_approx[k][j]); - drawContours(test, contrs, 0, CV_RGB(0, 0, 255), 1, 1, std::vector(), 2); - circle(test, quad_corners[k], 0.5, CV_RGB(255, 0, 0)); - } - Mat test1 = test(Rect(corners[i].x - 30, corners[i].y - 30, 60, 60)); - namedWindow("1", 1); - imshow("1", test1); - imwrite("test.jpg", test); - waitKey(0); -#endif -#endif //_SUBPIX_VERBOSE - } -#if defined(_SUBPIX_VERBOSE) - Mat test(img.size(), CV_32FC3); - cvtColor(img, test, CV_GRAY2RGB); - drawCircles(test, corners, radius); - - namedWindow("corners", 1); - imshow("corners", test); - waitKey(); -#endif //_SUBPIX_VERBOSE - return true; } diff --git a/modules/calib3d/test/test_cameracalibration_artificial.cpp b/modules/calib3d/test/test_cameracalibration_artificial.cpp index 733f0069c7..811e7002e6 100644 --- a/modules/calib3d/test/test_cameracalibration_artificial.cpp +++ b/modules/calib3d/test/test_cameracalibration_artificial.cpp @@ -304,7 +304,7 @@ protected: for(size_t i = 0; i < brdsNum; ++i) { Mat gray; - cvtColor(boards[i], gray, CV_BGR2GRAY); + cvtColor(boards[i], gray, COLOR_BGR2GRAY); vector tmp = imagePoints_findCb[i]; cornerSubPix(gray, tmp, Size(5, 5), Size(-1,-1), tc); imagePoints.push_back(tmp); @@ -314,7 +314,7 @@ protected: for(size_t i = 0; i < brdsNum; ++i) { Mat gray; - cvtColor(boards[i], gray, CV_BGR2GRAY); + cvtColor(boards[i], gray, COLOR_BGR2GRAY); vector tmp = imagePoints_findCb[i]; find4QuadCornerSubpix(gray, tmp, Size(5, 5)); imagePoints.push_back(tmp); diff --git a/modules/calib3d/test/test_chesscorners_timing.cpp b/modules/calib3d/test/test_chesscorners_timing.cpp index 171a74857b..7dffd597e3 100644 --- a/modules/calib3d/test/test_chesscorners_timing.cpp +++ b/modules/calib3d/test/test_chesscorners_timing.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" class CV_ChessboardDetectorTimingTest : public cvtest::BaseTest { diff --git a/modules/calib3d/test/test_cornerssubpix.cpp b/modules/calib3d/test/test_cornerssubpix.cpp index 88f7deee06..4426d5ea5e 100644 --- a/modules/calib3d/test/test_cornerssubpix.cpp +++ b/modules/calib3d/test/test_cornerssubpix.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include #include "test_chessboardgenerator.hpp" diff --git a/modules/calib3d/test/test_precomp.hpp b/modules/calib3d/test/test_precomp.hpp index de30e80290..3fe4480d5b 100644 --- a/modules/calib3d/test/test_precomp.hpp +++ b/modules/calib3d/test/test_precomp.hpp @@ -12,7 +12,6 @@ #include #include "opencv2/ts.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/calib3d.hpp" #include "opencv2/highgui.hpp" diff --git a/modules/calib3d/test/test_stereomatching.cpp b/modules/calib3d/test/test_stereomatching.cpp index e5f146d21d..4e58fcadf7 100644 --- a/modules/calib3d/test/test_stereomatching.cpp +++ b/modules/calib3d/test/test_stereomatching.cpp @@ -80,7 +80,7 @@ void computeTextureBasedMasks( const Mat& _img, Mat* texturelessMask, Mat* textu Mat img = _img; if( _img.channels() > 1) { - Mat tmp; cvtColor( _img, tmp, CV_BGR2GRAY ); img = tmp; + Mat tmp; cvtColor( _img, tmp, COLOR_BGR2GRAY ); img = tmp; } Mat dxI; Sobel( img, dxI, CV_32FC1, 1, 0, 3 ); Mat dxI2; pow( dxI / 8.f/*normalize*/, 2, dxI2 ); @@ -714,8 +714,8 @@ protected: RunParams params = caseRunParams[caseIdx]; assert( params.ndisp%16 == 0 ); assert( _leftImg.type() == CV_8UC3 && _rightImg.type() == CV_8UC3 ); - Mat leftImg; cvtColor( _leftImg, leftImg, CV_BGR2GRAY ); - Mat rightImg; cvtColor( _rightImg, rightImg, CV_BGR2GRAY ); + Mat leftImg; cvtColor( _leftImg, leftImg, COLOR_BGR2GRAY ); + Mat rightImg; cvtColor( _rightImg, rightImg, COLOR_BGR2GRAY ); Ptr bm = createStereoBM( params.ndisp, params.winSize ); Mat tempDisp; diff --git a/modules/calib3d/test/test_undistort.cpp b/modules/calib3d/test/test_undistort.cpp index 8484aa4731..959d8bec71 100644 --- a/modules/calib3d/test/test_undistort.cpp +++ b/modules/calib3d/test/test_undistort.cpp @@ -41,6 +41,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" using namespace cv; using namespace std; diff --git a/modules/calib3d/test/test_undistort_badarg.cpp b/modules/calib3d/test/test_undistort_badarg.cpp index 37c080f6e0..60460a55a0 100644 --- a/modules/calib3d/test/test_undistort_badarg.cpp +++ b/modules/calib3d/test/test_undistort_badarg.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" class CV_UndistortPointsBadArgTest : public cvtest::BadArgTest { diff --git a/modules/contrib/src/adaptiveskindetector.cpp b/modules/contrib/src/adaptiveskindetector.cpp index a44c42077f..35d945837e 100644 --- a/modules/contrib/src/adaptiveskindetector.cpp +++ b/modules/contrib/src/adaptiveskindetector.cpp @@ -35,6 +35,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #define ASD_INTENSITY_SET_PIXEL(pointer, qq) {(*pointer) = (unsigned char)qq;} diff --git a/modules/contrib/src/colormap.cpp b/modules/contrib/src/colormap.cpp index ca98b3a918..028533828e 100644 --- a/modules/contrib/src/colormap.cpp +++ b/modules/contrib/src/colormap.cpp @@ -483,8 +483,8 @@ namespace colormap } // Turn into a BGR matrix into its grayscale representation. if(src.type() == CV_8UC3) - cvtColor(src.clone(), src, CV_BGR2GRAY); - cvtColor(src.clone(), src, CV_GRAY2BGR); + cvtColor(src.clone(), src, COLOR_BGR2GRAY); + cvtColor(src.clone(), src, COLOR_GRAY2BGR); // Apply the ColorMap. LUT(src, _lut, _dst); } diff --git a/modules/contrib/src/facerec.cpp b/modules/contrib/src/facerec.cpp index de4fb5bc45..bb1d21e96a 100644 --- a/modules/contrib/src/facerec.cpp +++ b/modules/contrib/src/facerec.cpp @@ -832,7 +832,7 @@ void LBPH::predict(InputArray _src, int &minClass, double &minDist) const { minDist = DBL_MAX; minClass = -1; for(size_t sampleIdx = 0; sampleIdx < _histograms.size(); sampleIdx++) { - double dist = compareHist(_histograms[sampleIdx], query, CV_COMP_CHISQR); + double dist = compareHist(_histograms[sampleIdx], query, HISTCMP_CHISQR); if((dist < minDist) && (dist < _threshold)) { minDist = dist; minClass = _labels.at((int) sampleIdx); diff --git a/modules/contrib/src/gencolors.cpp b/modules/contrib/src/gencolors.cpp index 504015308c..688c98d9ff 100644 --- a/modules/contrib/src/gencolors.cpp +++ b/modules/contrib/src/gencolors.cpp @@ -118,7 +118,7 @@ void cv::generateColors( std::vector& colors, size_t count, size_t facto // Convert the colors set to Lab space. // Distances between colors in this space correspond a human perception. Mat lab; - cvtColor( bgr, lab, CV_BGR2Lab); + cvtColor( bgr, lab, COLOR_BGR2Lab); // Subsample colors from the generated set so that // to maximize the minimum distances between each other. @@ -128,7 +128,7 @@ void cv::generateColors( std::vector& colors, size_t count, size_t facto // Convert subsampled colors back to RGB Mat bgr_subset; - cvtColor( lab_subset, bgr_subset, CV_Lab2BGR ); + cvtColor( lab_subset, bgr_subset, COLOR_Lab2BGR ); CV_Assert( bgr_subset.total() == count ); for( size_t i = 0; i < count; i++ ) diff --git a/modules/contrib/src/precomp.hpp b/modules/contrib/src/precomp.hpp index 03ef4acc3b..09ffd086ce 100644 --- a/modules/contrib/src/precomp.hpp +++ b/modules/contrib/src/precomp.hpp @@ -47,7 +47,6 @@ #include "opencv2/features2d.hpp" #include "opencv2/objdetect.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core/utility.hpp" #include "opencv2/core/private.hpp" diff --git a/modules/contrib/src/spinimages.cpp b/modules/contrib/src/spinimages.cpp index 291c66f8a0..54eaf825c8 100644 --- a/modules/contrib/src/spinimages.cpp +++ b/modules/contrib/src/spinimages.cpp @@ -770,7 +770,7 @@ Mat cv::SpinImageModel::packRandomScaledSpins(bool separateScale, size_t xCount, int endx = (x + 1) * sz + x; Mat color; - cvtColor(spins[pos++], color, CV_GRAY2BGR); + cvtColor(spins[pos++], color, COLOR_GRAY2BGR); Mat roi = result(Range(starty, endy), Range(startx, endx)); color.copyTo(roi); } diff --git a/modules/contrib/src/stereovar.cpp b/modules/contrib/src/stereovar.cpp index a825ad8d82..30cd12d4c1 100644 --- a/modules/contrib/src/stereovar.cpp +++ b/modules/contrib/src/stereovar.cpp @@ -367,8 +367,8 @@ void StereoVar::operator ()( const Mat& left, const Mat& right, Mat& disp ) // Preprocessing Mat leftgray, rightgray; if (left.type() != CV_8UC1) { - cvtColor(left, leftgray, CV_BGR2GRAY); - cvtColor(right, rightgray, CV_BGR2GRAY); + cvtColor(left, leftgray, COLOR_BGR2GRAY); + cvtColor(right, rightgray, COLOR_BGR2GRAY); } else { left.copyTo(leftgray); right.copyTo(rightgray); diff --git a/modules/core/doc/operations_on_arrays.rst b/modules/core/doc/operations_on_arrays.rst index 55fb83248f..d42f2890b5 100644 --- a/modules/core/doc/operations_on_arrays.rst +++ b/modules/core/doc/operations_on_arrays.rst @@ -3460,3 +3460,101 @@ The function :ocv:func:`transpose` transposes the matrix ``src`` : \texttt{dst} (i,j) = \texttt{src} (j,i) .. note:: No complex conjugation is done in case of a complex matrix. It it should be done separately if needed. + + +borderInterpolate +----------------- +Computes the source location of an extrapolated pixel. + +.. ocv:function:: int borderInterpolate( int p, int len, int borderType ) + +.. ocv:pyfunction:: cv2.borderInterpolate(p, len, borderType) -> retval + + :param p: 0-based coordinate of the extrapolated pixel along one of the axes, + likely <0 or >= ``len`` . + + :param len: Length of the array along the corresponding axis. + + :param borderType: Border type, one of the ``BORDER_*`` , except for ``BORDER_TRANSPARENT`` + and ``BORDER_ISOLATED`` . When ``borderType==BORDER_CONSTANT`` , the + function always returns -1, regardless of ``p`` and ``len`` . + +The function computes and returns the coordinate of a donor pixel corresponding to the specified +extrapolated pixel when using the specified extrapolation border mode. For example, if you use +``BORDER_WRAP`` mode in the horizontal direction, ``BORDER_REFLECT_101`` in the vertical direction +and want to compute value of the "virtual" pixel ``Point(-5, 100)`` in a floating-point image +``img`` , it looks like: :: + + float val = img.at(borderInterpolate(100, img.rows, BORDER_REFLECT_101), + borderInterpolate(-5, img.cols, BORDER_WRAP)); + + +Normally, the function is not called directly. It is used inside :ocv:class:`FilterEngine` +and :ocv:func:`copyMakeBorder` to compute tables for quick extrapolation. + +.. seealso:: + + :ocv:class:`FilterEngine`, + :ocv:func:`copyMakeBorder` + + +copyMakeBorder +-------------- +Forms a border around an image. + +.. ocv:function:: void copyMakeBorder( InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar& value=Scalar() ) + +.. ocv:pyfunction:: cv2.copyMakeBorder(src, top, bottom, left, right, borderType[, dst[, value]]) -> dst + + :param src: Source image. + + :param dst: Destination image of the same type as ``src`` and the + size ``Size(src.cols+left+right, src.rows+top+bottom)`` . + + :param top: + + :param bottom: + + :param left: + + :param right: Parameter specifying how many pixels in each direction from the source image + rectangle to extrapolate. For example, ``top=1, bottom=1, left=1, right=1`` + mean that 1 pixel-wide border needs to be built. + + :param borderType: Border type. See :ocv:func:`borderInterpolate` for details. + + :param value: Border value if ``borderType==BORDER_CONSTANT`` . + +The function copies the source image into the middle of the destination image. The areas to the +left, to the right, above and below the copied source image will be filled with extrapolated pixels. +This is not what :ocv:class:`FilterEngine` or filtering functions based on it do (they extrapolate +pixels on-fly), but what other more complex functions, including your own, may do to simplify image +boundary handling. + +The function supports the mode when ``src`` is already in the middle of ``dst`` . In this case, the +function does not copy ``src`` itself but simply constructs the border, for example: :: + + // let border be the same in all directions + int border=2; + // constructs a larger image to fit both the image and the border + Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth()); + // select the middle part of it w/o copying data + Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows)); + // convert image from RGB to grayscale + cvtColor(rgb, gray, CV_RGB2GRAY); + // form a border in-place + copyMakeBorder(gray, gray_buf, border, border, + border, border, BORDER_REPLICATE); + // now do some custom filtering ... + ... + + +.. note:: + + When the source image is a part (ROI) of a bigger image, the function will try to use the pixels + outside of the ROI to form a border. To disable this feature and always do extrapolation, as if + ``src`` was not a ROI, use ``borderType | BORDER_ISOLATED``. + +.. seealso:: + + :ocv:func:`borderInterpolate` diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 2e3a98c4ed..8fc875ac8c 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -112,6 +112,14 @@ CV_EXPORTS void error( const Exception& exc ); //! swaps two matrices CV_EXPORTS void swap(Mat& a, Mat& b); +//! 1D interpolation function: returns coordinate of the "donor" pixel for the specified location p. +CV_EXPORTS_W int borderInterpolate(int p, int len, int borderType); + +//! copies 2D array to a larger destination array with extrapolation of the outer part of src using the specified border mode +CV_EXPORTS_W void copyMakeBorder(InputArray src, OutputArray dst, + int top, int bottom, int left, int right, + int borderType, const Scalar& value = Scalar() ); + //! adds one matrix to another (dst = src1 + src2) CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1); @@ -169,6 +177,9 @@ CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mas CV_EXPORTS_W double norm(InputArray src1, InputArray src2, int normType = NORM_L2, InputArray mask = noArray()); +//! computes PSNR image/video quality metric +CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2); + //! computes norm of a sparse matrix CV_EXPORTS double norm( const SparseMat& src, int normType ); diff --git a/modules/core/include/opencv2/core/base.hpp b/modules/core/include/opencv2/core/base.hpp index df49601a60..5cce1db148 100644 --- a/modules/core/include/opencv2/core/base.hpp +++ b/modules/core/include/opencv2/core/base.hpp @@ -157,6 +157,20 @@ enum { DFT_INVERSE = 1, DCT_ROWS = DFT_ROWS }; +//! Various border types, image boundaries are denoted with '|' +enum { + BORDER_CONSTANT = 0, // iiiiii|abcdefgh|iiiiiii with some specified 'i' + BORDER_REPLICATE = 1, // aaaaaa|abcdefgh|hhhhhhh + BORDER_REFLECT = 2, // fedcba|abcdefgh|hgfedcb + BORDER_WRAP = 3, // cdefgh|abcdefgh|abcdefg + BORDER_REFLECT_101 = 4, // gfedcb|abcdefgh|gfedcba + BORDER_TRANSPARENT = 5, // uvwxyz|absdefgh|ijklmno + + BORDER_REFLECT101 = BORDER_REFLECT_101, + BORDER_DEFAULT = BORDER_REFLECT_101, + BORDER_ISOLATED = 16 // do not look outside of ROI + }; + //////////////// static assert ///////////////// diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index e5708d2795..05cf5052fa 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -667,6 +667,51 @@ public: +///////////////////////// raster image moments ////////////////////////// + +class CV_EXPORTS_W_MAP Moments +{ +public: + //! the default constructor + Moments(); + //! the full constructor + Moments(double m00, double m10, double m01, double m20, double m11, + double m02, double m30, double m21, double m12, double m03 ); + ////! the conversion from CvMoments + //Moments( const CvMoments& moments ); + ////! the conversion to CvMoments + //operator CvMoments() const; + + //! spatial moments + CV_PROP_RW double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; + //! central moments + CV_PROP_RW double mu20, mu11, mu02, mu30, mu21, mu12, mu03; + //! central normalized moments + CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03; +}; + +/*! + traits +*/ +template<> class DataType +{ +public: + typedef Moments value_type; + typedef double work_type; + typedef double channel_type; + + enum { generic_type = 0, + depth = DataType::depth, + channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24 + fmt = DataType::fmt + ((channels - 1) << 8), + type = CV_MAKETYPE(depth, channels) + }; + + typedef Vec vec_type; +}; + + + ///////////////////////////////////////////////////////////////////////// ///////////////////////////// Implementation //////////////////////////// ///////////////////////////////////////////////////////////////////////// diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 8276ffddb6..3d58df7871 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -512,6 +512,231 @@ Mat repeat(const Mat& src, int ny, int nx) return dst; } + +} // cv + + +/* + Various border types, image boundaries are denoted with '|' + + * BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh + * BORDER_REFLECT: fedcba|abcdefgh|hgfedcb + * BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba + * BORDER_WRAP: cdefgh|abcdefgh|abcdefg + * BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii with some specified 'i' + */ +int cv::borderInterpolate( int p, int len, int borderType ) +{ + if( (unsigned)p < (unsigned)len ) + ; + else if( borderType == BORDER_REPLICATE ) + p = p < 0 ? 0 : len - 1; + else if( borderType == BORDER_REFLECT || borderType == BORDER_REFLECT_101 ) + { + int delta = borderType == BORDER_REFLECT_101; + if( len == 1 ) + return 0; + do + { + if( p < 0 ) + p = -p - 1 + delta; + else + p = len - 1 - (p - len) - delta; + } + while( (unsigned)p >= (unsigned)len ); + } + else if( borderType == BORDER_WRAP ) + { + if( p < 0 ) + p -= ((p-len+1)/len)*len; + if( p >= len ) + p %= len; + } + else if( borderType == BORDER_CONSTANT ) + p = -1; + else + CV_Error( CV_StsBadArg, "Unknown/unsupported border type" ); + return p; +} + +namespace +{ + +void copyMakeBorder_8u( const uchar* src, size_t srcstep, cv::Size srcroi, + uchar* dst, size_t dststep, cv::Size dstroi, + int top, int left, int cn, int borderType ) +{ + const int isz = (int)sizeof(int); + int i, j, k, elemSize = 1; + bool intMode = false; + + if( (cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0 ) + { + cn /= isz; + elemSize = isz; + intMode = true; + } + + cv::AutoBuffer _tab((dstroi.width - srcroi.width)*cn); + int* tab = _tab; + int right = dstroi.width - srcroi.width - left; + int bottom = dstroi.height - srcroi.height - top; + + for( i = 0; i < left; i++ ) + { + j = cv::borderInterpolate(i - left, srcroi.width, borderType)*cn; + for( k = 0; k < cn; k++ ) + tab[i*cn + k] = j + k; + } + + for( i = 0; i < right; i++ ) + { + j = cv::borderInterpolate(srcroi.width + i, srcroi.width, borderType)*cn; + for( k = 0; k < cn; k++ ) + tab[(i+left)*cn + k] = j + k; + } + + srcroi.width *= cn; + dstroi.width *= cn; + left *= cn; + right *= cn; + + uchar* dstInner = dst + dststep*top + left*elemSize; + + for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep ) + { + if( dstInner != src ) + memcpy(dstInner, src, srcroi.width*elemSize); + + if( intMode ) + { + const int* isrc = (int*)src; + int* idstInner = (int*)dstInner; + for( j = 0; j < left; j++ ) + idstInner[j - left] = isrc[tab[j]]; + for( j = 0; j < right; j++ ) + idstInner[j + srcroi.width] = isrc[tab[j + left]]; + } + else + { + for( j = 0; j < left; j++ ) + dstInner[j - left] = src[tab[j]]; + for( j = 0; j < right; j++ ) + dstInner[j + srcroi.width] = src[tab[j + left]]; + } + } + + dstroi.width *= elemSize; + dst += dststep*top; + + for( i = 0; i < top; i++ ) + { + j = cv::borderInterpolate(i - top, srcroi.height, borderType); + memcpy(dst + (i - top)*dststep, dst + j*dststep, dstroi.width); + } + + for( i = 0; i < bottom; i++ ) + { + j = cv::borderInterpolate(i + srcroi.height, srcroi.height, borderType); + memcpy(dst + (i + srcroi.height)*dststep, dst + j*dststep, dstroi.width); + } +} + + +void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, cv::Size srcroi, + uchar* dst, size_t dststep, cv::Size dstroi, + int top, int left, int cn, const uchar* value ) +{ + int i, j; + cv::AutoBuffer _constBuf(dstroi.width*cn); + uchar* constBuf = _constBuf; + int right = dstroi.width - srcroi.width - left; + int bottom = dstroi.height - srcroi.height - top; + + for( i = 0; i < dstroi.width; i++ ) + { + for( j = 0; j < cn; j++ ) + constBuf[i*cn + j] = value[j]; + } + + srcroi.width *= cn; + dstroi.width *= cn; + left *= cn; + right *= cn; + + uchar* dstInner = dst + dststep*top + left; + + for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep ) + { + if( dstInner != src ) + memcpy( dstInner, src, srcroi.width ); + memcpy( dstInner - left, constBuf, left ); + memcpy( dstInner + srcroi.width, constBuf, right ); + } + + dst += dststep*top; + + for( i = 0; i < top; i++ ) + memcpy(dst + (i - top)*dststep, constBuf, dstroi.width); + + for( i = 0; i < bottom; i++ ) + memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width); +} + +} + +void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom, + int left, int right, int borderType, const Scalar& value ) +{ + Mat src = _src.getMat(); + CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 ); + + if( src.isSubmatrix() && (borderType & BORDER_ISOLATED) == 0 ) + { + Size wholeSize; + Point ofs; + src.locateROI(wholeSize, ofs); + int dtop = std::min(ofs.y, top); + int dbottom = std::min(wholeSize.height - src.rows - ofs.y, bottom); + int dleft = std::min(ofs.x, left); + int dright = std::min(wholeSize.width - src.cols - ofs.x, right); + src.adjustROI(dtop, dbottom, dleft, dright); + top -= dtop; + left -= dleft; + bottom -= dbottom; + right -= dright; + } + + _dst.create( src.rows + top + bottom, src.cols + left + right, src.type() ); + Mat dst = _dst.getMat(); + + if(top == 0 && left == 0 && bottom == 0 && right == 0) + { + if(src.data != dst.data || src.step != dst.step) + src.copyTo(dst); + return; + } + + borderType &= ~BORDER_ISOLATED; + + if( borderType != BORDER_CONSTANT ) + copyMakeBorder_8u( src.data, src.step, src.size(), + dst.data, dst.step, dst.size(), + top, left, (int)src.elemSize(), borderType ); + else + { + int cn = src.channels(), cn1 = cn; + AutoBuffer buf(cn); + if( cn > 4 ) + { + CV_Assert( value[0] == value[1] && value[0] == value[2] && value[0] == value[3] ); + 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(), + top, left, (int)src.elemSize(), (uchar*)(double*)buf ); + } } /* dst = src */ diff --git a/modules/core/src/gpumat.cpp b/modules/core/src/gpumat.cpp index 0db8536879..c5d4d7a4a6 100644 --- a/modules/core/src/gpumat.cpp +++ b/modules/core/src/gpumat.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include using namespace cv; using namespace cv::gpu; diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index 9821de8879..9e64697c31 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include #if defined _M_IX86 && defined _MSC_VER && _MSC_VER < 1700 #pragma float_control(precise, on) diff --git a/modules/core/src/rand.cpp b/modules/core/src/rand.cpp index 74eba60066..079e1fb7be 100644 --- a/modules/core/src/rand.cpp +++ b/modules/core/src/rand.cpp @@ -54,6 +54,8 @@ #undef min #undef max #undef abs +#else + #include #endif #if defined __SSE2__ || (defined _M_IX86_FP && 2 == _M_IX86_FP) diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index dad78356dd..3b8916bbf1 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -1922,6 +1922,14 @@ void cv::findNonZero( InputArray _src, OutputArray _idx ) } } +double cv::PSNR(InputArray _src1, InputArray _src2) +{ + Mat src1 = _src1.getMat(), src2 = _src2.getMat(); + CV_Assert( src1.depth() == CV_8U ); + double diff = std::sqrt(norm(src1, src2, NORM_L2SQR)/(src1.total()*src1.channels())); + return 20*log10(255./(diff+DBL_EPSILON)); +} + CV_IMPL CvScalar cvSum( const CvArr* srcarr ) { diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp index 785651fe38..59f3c8e282 100644 --- a/modules/features2d/src/blobdetector.cpp +++ b/modules/features2d/src/blobdetector.cpp @@ -169,7 +169,7 @@ void SimpleBlobDetector::findBlobs(const cv::Mat &image, const cv::Mat &binaryIm std::vector < std::vector > contours; Mat tmpBinaryImage = binaryImage.clone(); - findContours(tmpBinaryImage, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE); + findContours(tmpBinaryImage, contours, RETR_LIST, CHAIN_APPROX_NONE); #ifdef DEBUG_BLOB_DETECTOR // Mat keypointsImage; @@ -239,7 +239,7 @@ void SimpleBlobDetector::findBlobs(const cv::Mat &image, const cv::Mat &binaryIm if (ratio < params.minConvexity || ratio >= params.maxConvexity) continue; } - + center.location = Point2d(moms.m10 / moms.m00, moms.m01 / moms.m00); if (params.filterByColor) @@ -281,7 +281,7 @@ void SimpleBlobDetector::detectImpl(const cv::Mat& image, std::vector &radiusList, std::vector &numberLi // get the total number of points const int rings = (int)radiusList.size(); - assert(radiusList.size()!=0&&radiusList.size()==numberList.size()); + CV_Assert(radiusList.size() != 0 && radiusList.size() == numberList.size()); points_ = 0; // remember the total number of points for (int ring = 0; ring < rings; ring++) { @@ -336,7 +336,7 @@ BRISK::generateKernel(std::vector &radiusList, std::vector &numberLi else if (norm_sq < dMax_sq) { // save to short pairs - assert(noShortPairs_& k inline int BriskScaleSpace::getScoreAbove(const int layer, const int x_layer, const int y_layer) const { - assert(layer0); + CV_Assert(layer > 0); const BriskLayer& layerBelow = pyramid_[layer - 1]; // check the first row @@ -2109,7 +2109,7 @@ BriskLayer::getAgastScore(float xf, float yf, int threshold_in, float scale_in) inline int BriskLayer::value(const cv::Mat& mat, float xf, float yf, float scale_in) const { - assert(!mat.empty()); + CV_Assert(!mat.empty()); // get the position const int x = cvFloor(xf); const int y = cvFloor(yf); @@ -2216,8 +2216,8 @@ inline void BriskLayer::halfsample(const cv::Mat& srcimg, cv::Mat& dstimg) { // make sure the destination image is of the right size: - assert(srcimg.cols/2==dstimg.cols); - assert(srcimg.rows/2==dstimg.rows); + CV_Assert(srcimg.cols / 2 == dstimg.cols); + CV_Assert(srcimg.rows / 2 == dstimg.rows); // handle non-SSE case resize(srcimg, dstimg, dstimg.size(), 0, 0, INTER_AREA); @@ -2227,8 +2227,8 @@ inline void BriskLayer::twothirdsample(const cv::Mat& srcimg, cv::Mat& dstimg) { // make sure the destination image is of the right size: - assert((srcimg.cols/3)*2==dstimg.cols); - assert((srcimg.rows/3)*2==dstimg.rows); + CV_Assert((srcimg.cols / 3) * 2 == dstimg.cols); + CV_Assert((srcimg.rows / 3) * 2 == dstimg.rows); resize(srcimg, dstimg, dstimg.size(), 0, 0, INTER_AREA); } diff --git a/modules/features2d/src/descriptors.cpp b/modules/features2d/src/descriptors.cpp index b093d23f0a..ab87686459 100644 --- a/modules/features2d/src/descriptors.cpp +++ b/modules/features2d/src/descriptors.cpp @@ -118,7 +118,7 @@ OpponentColorDescriptorExtractor::OpponentColorDescriptorExtractor( const Ptr& opponentChannels ) { if( bgrImage.type() != CV_8UC3 ) - CV_Error( CV_StsBadArg, "input image must be an BGR image of type CV_8UC3" ); + CV_Error( Error::StsBadArg, "input image must be an BGR image of type CV_8UC3" ); // Prepare opponent color space storage matrices. opponentChannels.resize( 3 ); diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index 5fcf7c6874..8752dd2851 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -128,7 +128,7 @@ GFTTDetector::GFTTDetector( int _nfeatures, double _qualityLevel, void GFTTDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask) const { Mat grayImage = image; - if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY ); + if( image.type() != CV_8U ) cvtColor( image, grayImage, COLOR_BGR2GRAY ); std::vector corners; goodFeaturesToTrack( grayImage, corners, nfeatures, qualityLevel, minDistance, mask, @@ -346,7 +346,7 @@ void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, Ma } else if( image.type() == CV_8UC1 ) { - cvtColor( image, outImage, CV_GRAY2BGR ); + cvtColor( image, outImage, COLOR_GRAY2BGR ); } else { - CV_Error( CV_StsBadArg, "Incorrect type of input image.\n" ); + CV_Error( Error::StsBadArg, "Incorrect type of input image.\n" ); } } @@ -129,7 +129,7 @@ static void _prepareImgAndDrawKeypoints( const Mat& img1, const std::vector outImg.cols || size.height > outImg.rows ) - CV_Error( CV_StsBadSize, "outImg has size less than need to draw img1 and img2 together" ); + CV_Error( Error::StsBadSize, "outImg has size less than need to draw img1 and img2 together" ); outImg1 = outImg( Rect(0, 0, img1.cols, img1.rows) ); outImg2 = outImg( Rect(img1.cols, 0, img2.cols, img2.rows) ); } @@ -141,12 +141,12 @@ static void _prepareImgAndDrawKeypoints( const Mat& img1, const std::vector& keypoints1, @@ -189,7 +189,7 @@ void drawMatches( const Mat& img1, const std::vector& keypoints1, const std::vector& matchesMask, int flags ) { if( !matchesMask.empty() && matchesMask.size() != matches1to2.size() ) - CV_Error( CV_StsBadSize, "matchesMask must have the same size as matches1to2" ); + CV_Error( Error::StsBadSize, "matchesMask must have the same size as matches1to2" ); Mat outImg1, outImg2; _prepareImgAndDrawKeypoints( img1, keypoints1, img2, keypoints2, @@ -218,7 +218,7 @@ void drawMatches( const Mat& img1, const std::vector& keypoints1, const std::vector >& matchesMask, int flags ) { if( !matchesMask.empty() && matchesMask.size() != matches1to2.size() ) - CV_Error( CV_StsBadSize, "matchesMask must have the same size as matches1to2" ); + CV_Error( Error::StsBadSize, "matchesMask must have the same size as matches1to2" ); Mat outImg1, outImg2; _prepareImgAndDrawKeypoints( img1, keypoints1, img2, keypoints2, diff --git a/modules/features2d/src/evaluation.cpp b/modules/features2d/src/evaluation.cpp index 591e1c20bc..cdc5834d44 100644 --- a/modules/features2d/src/evaluation.cpp +++ b/modules/features2d/src/evaluation.cpp @@ -185,7 +185,7 @@ void EllipticKeyPoint::convert( const std::vector& src, std::vector& src, { if( !src.empty() ) { - assert( !H.empty() && H.cols == 3 && H.rows == 3); + CV_Assert( !H.empty() && H.cols == 3 && H.rows == 3); dst.resize(src.size()); std::vector::const_iterator srcIt = src.begin(); std::vector::iterator dstIt = dst.begin(); @@ -462,7 +462,7 @@ void cv::evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H keypoints2 = _keypoints2 != 0 ? _keypoints2 : &buf2; if( (keypoints1->empty() || keypoints2->empty()) && fdetector.empty() ) - CV_Error( CV_StsBadArg, "fdetector must not be empty when keypoints1 or keypoints2 is empty" ); + CV_Error( Error::StsBadArg, "fdetector must not be empty when keypoints1 or keypoints2 is empty" ); if( keypoints1->empty() ) fdetector->detect( img1, *keypoints1 ); @@ -573,15 +573,15 @@ void cv::evaluateGenericDescriptorMatcher( const Mat& img1, const Mat& img2, con correctMatches1to2Mask = _correctMatches1to2Mask != 0 ? _correctMatches1to2Mask : &buf2; if( keypoints1.empty() ) - CV_Error( CV_StsBadArg, "keypoints1 must not be empty" ); + CV_Error( Error::StsBadArg, "keypoints1 must not be empty" ); if( matches1to2->empty() && dmatcher.empty() ) - CV_Error( CV_StsBadArg, "dmatch must not be empty when matches1to2 is empty" ); + CV_Error( Error::StsBadArg, "dmatch must not be empty when matches1to2 is empty" ); bool computeKeypoints2ByPrj = keypoints2.empty(); if( computeKeypoints2ByPrj ) { - assert(0); + CV_Error(Error::StsNotImplemented, ""); // TODO: add computing keypoints2 from keypoints1 using H1to2 } diff --git a/modules/features2d/src/fast.cpp b/modules/features2d/src/fast.cpp index e026412fdc..9e2181c140 100644 --- a/modules/features2d/src/fast.cpp +++ b/modules/features2d/src/fast.cpp @@ -286,7 +286,7 @@ FastFeatureDetector::FastFeatureDetector( int _threshold, bool _nonmaxSuppressio void FastFeatureDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const { Mat grayImage = image; - if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY ); + if( image.type() != CV_8U ) cvtColor( image, grayImage, COLOR_BGR2GRAY ); FAST( grayImage, keypoints, threshold, nonmaxSuppression, type ); KeyPointsFilter::runByPixelsMask( keypoints, mask ); } diff --git a/modules/features2d/src/freak.cpp b/modules/features2d/src/freak.cpp index 6c9093f7ce..086a2e2e71 100644 --- a/modules/features2d/src/freak.cpp +++ b/modules/features2d/src/freak.cpp @@ -206,7 +206,7 @@ void FREAK::buildPattern() descriptionPairs[i] = allPairs[selectedPairs0.at(i)]; } else { - CV_Error(CV_StsVecLengthErr, "Input vector does not match the required size"); + CV_Error(Error::StsVecLengthErr, "Input vector does not match the required size"); } } else { // default selected pairs @@ -548,7 +548,7 @@ std::vector FREAK::selectPairs(const std::vector& images int idxB = pairStat[m].idx; double corr(0); // compute correlation between 2 pairs - corr = fabs(compareHist(descriptorsFloat.col(idxA), descriptorsFloat.col(idxB), CV_COMP_CORREL)); + corr = fabs(compareHist(descriptorsFloat.col(idxA), descriptorsFloat.col(idxB), HISTCMP_CORREL)); if( corr > corrMax ) { corrMax = corr; @@ -575,7 +575,7 @@ std::vector FREAK::selectPairs(const std::vector& images else { if( verbose ) std::cout << "correlation threshold too small (restrictive)" << std::endl; - CV_Error(CV_StsError, "correlation threshold too small (restrictive)"); + CV_Error(Error::StsError, "correlation threshold too small (restrictive)"); } extAll = false; return idxBestPairs; diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index c9ab9be488..5f75ad4c84 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -112,7 +112,7 @@ void DescriptorMatcher::DescriptorCollection::set( const std::vector& descr dim = descriptors[0].cols; type = descriptors[0].type(); } - assert( dim > 0 ); + CV_Assert( dim > 0 ); int count = startIdxs[imageCount-1] + descriptors[imageCount-1].rows; @@ -484,7 +484,7 @@ Ptr DescriptorMatcher::create( const String& descriptorMatche dm = new BFMatcher(NORM_HAMMING2); } else - CV_Error( CV_StsBadArg, "Unknown matcher name" ); + CV_Error( Error::StsBadArg, "Unknown matcher name" ); return dm; } @@ -727,7 +727,7 @@ Ptr FlannBasedMatcher::clone( bool emptyTrainData ) const FlannBasedMatcher* matcher = new FlannBasedMatcher(indexParams, searchParams); if( !emptyTrainData ) { - CV_Error( CV_StsNotImplemented, "deep clone functionality is not implemented, because " + CV_Error( Error::StsNotImplemented, "deep clone functionality is not implemented, because " "Flann::Index has not copy constructor or clone method "); //matcher->flannIndex; matcher->addedDescCount = addedDescCount; diff --git a/modules/features2d/src/mser.cpp b/modules/features2d/src/mser.cpp index ebd1f571c4..21f01ba0d2 100644 --- a/modules/features2d/src/mser.cpp +++ b/modules/features2d/src/mser.cpp @@ -40,6 +40,7 @@ */ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" namespace cv { diff --git a/modules/features2d/src/orb.cpp b/modules/features2d/src/orb.cpp index 33c23d1610..7ed3ff03c3 100644 --- a/modules/features2d/src/orb.cpp +++ b/modules/features2d/src/orb.cpp @@ -240,7 +240,7 @@ static void computeOrbDescriptor(const KeyPoint& kpt, } } else - CV_Error( CV_StsBadSize, "Wrong WTA_K. It can be only 2, 3 or 4." ); + CV_Error( Error::StsBadSize, "Wrong WTA_K. It can be only 2, 3 or 4." ); #undef GET_VALUE } @@ -738,7 +738,7 @@ void ORB::operator()( InputArray _image, InputArray _mask, std::vector Mat image = _image.getMat(), mask = _mask.getMat(); if( image.type() != CV_8UC1 ) - cvtColor(_image, image, CV_BGR2GRAY); + cvtColor(_image, image, COLOR_BGR2GRAY); int levelsNum = this->nlevels; diff --git a/modules/features2d/src/precomp.hpp b/modules/features2d/src/precomp.hpp index fc6df5c260..3c9073ec52 100644 --- a/modules/features2d/src/precomp.hpp +++ b/modules/features2d/src/precomp.hpp @@ -45,7 +45,6 @@ #include "opencv2/features2d.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core/utility.hpp" #include "opencv2/core/private.hpp" diff --git a/modules/features2d/src/stardetector.cpp b/modules/features2d/src/stardetector.cpp index 3dbea0ac13..02b999b620 100644 --- a/modules/features2d/src/stardetector.cpp +++ b/modules/features2d/src/stardetector.cpp @@ -114,7 +114,7 @@ StarDetectorComputeResponses( const Mat& img, Mat& responses, Mat& sizes, int ma #if CV_SSE2 __m128 invSizes4[MAX_PATTERN][2]; __m128 sizes1_4[MAX_PATTERN]; - Cv32suf absmask; + union { int i; float f; } absmask; absmask.i = 0x7fffffff; volatile bool useSIMD = cv::checkHardwareSupport(CV_CPU_SSE2); #endif @@ -429,7 +429,7 @@ StarDetector::StarDetector(int _maxSize, int _responseThreshold, void StarDetector::detectImpl( const Mat& image, std::vector& keypoints, const Mat& mask ) const { Mat grayImage = image; - if( image.type() != CV_8U ) cvtColor( image, grayImage, CV_BGR2GRAY ); + if( image.type() != CV_8U ) cvtColor( image, grayImage, COLOR_BGR2GRAY ); (*this)(grayImage, keypoints); KeyPointsFilter::runByPixelsMask( keypoints, mask ); diff --git a/modules/features2d/test/test_brisk.cpp b/modules/features2d/test/test_brisk.cpp index c76afff570..adac8e2e70 100644 --- a/modules/features2d/test/test_brisk.cpp +++ b/modules/features2d/test/test_brisk.cpp @@ -69,8 +69,8 @@ void CV_BRISKTest::run( int ) } Mat gray1, gray2; - cvtColor(image1, gray1, CV_BGR2GRAY); - cvtColor(image2, gray2, CV_BGR2GRAY); + cvtColor(image1, gray1, COLOR_BGR2GRAY); + cvtColor(image2, gray2, COLOR_BGR2GRAY); Ptr detector = Algorithm::create("Feature2D.BRISK"); diff --git a/modules/features2d/test/test_descriptors_regression.cpp b/modules/features2d/test/test_descriptors_regression.cpp index 193545162b..548e818840 100644 --- a/modules/features2d/test/test_descriptors_regression.cpp +++ b/modules/features2d/test/test_descriptors_regression.cpp @@ -80,12 +80,16 @@ static Mat readMatFromBin( const string& filename ) size_t elements_read4 = fread( (void*)&dataSize, sizeof(int), 1, f ); CV_Assert(elements_read1 == 1 && elements_read2 == 1 && elements_read3 == 1 && elements_read4 == 1); - uchar* data = (uchar*)cvAlloc(dataSize); - size_t elements_read = fread( (void*)data, 1, dataSize, f ); + size_t step = dataSize / rows / CV_ELEM_SIZE(type); + CV_Assert(step >= (size_t)cols); + + Mat m = Mat( rows, step, type).colRange(0, cols); + + size_t elements_read = fread( m.ptr(), 1, dataSize, f ); CV_Assert(elements_read == (size_t)(dataSize)); fclose(f); - return Mat( rows, cols, type, data ); + return m; } return Mat(); } @@ -205,7 +209,7 @@ protected: double t = (double)getTickCount(); dextractor->compute( img, keypoints, calcDescriptors ); t = getTickCount() - t; - ts->printf(cvtest::TS::LOG, "\nAverage time of computing one descriptor = %g ms.\n", t/((double)cvGetTickFrequency()*1000.)/calcDescriptors.rows); + ts->printf(cvtest::TS::LOG, "\nAverage time of computing one descriptor = %g ms.\n", t/((double)getTickFrequency()*1000.)/calcDescriptors.rows); if( calcDescriptors.rows != (int)keypoints.size() ) { diff --git a/modules/features2d/test/test_fast.cpp b/modules/features2d/test/test_fast.cpp index cee9152bff..76d7918640 100644 --- a/modules/features2d/test/test_fast.cpp +++ b/modules/features2d/test/test_fast.cpp @@ -71,8 +71,8 @@ void CV_FastTest::run( int ) } Mat gray1, gray2; - cvtColor(image1, gray1, CV_BGR2GRAY); - cvtColor(image2, gray2, CV_BGR2GRAY); + cvtColor(image1, gray1, COLOR_BGR2GRAY); + cvtColor(image2, gray2, COLOR_BGR2GRAY); vector keypoints1; vector keypoints2; @@ -82,13 +82,13 @@ void CV_FastTest::run( int ) for(size_t i = 0; i < keypoints1.size(); ++i) { const KeyPoint& kp = keypoints1[i]; - cv::circle(image1, kp.pt, cvRound(kp.size/2), CV_RGB(255, 0, 0)); + cv::circle(image1, kp.pt, cvRound(kp.size/2), Scalar(255, 0, 0)); } for(size_t i = 0; i < keypoints2.size(); ++i) { const KeyPoint& kp = keypoints2[i]; - cv::circle(image2, kp.pt, cvRound(kp.size/2), CV_RGB(255, 0, 0)); + cv::circle(image2, kp.pt, cvRound(kp.size/2), Scalar(255, 0, 0)); } Mat kps1(1, (int)(keypoints1.size() * sizeof(KeyPoint)), CV_8U, &keypoints1[0]); diff --git a/modules/features2d/test/test_mser.cpp b/modules/features2d/test/test_mser.cpp index b30400a502..1627886ba5 100644 --- a/modules/features2d/test/test_mser.cpp +++ b/modules/features2d/test/test_mser.cpp @@ -41,6 +41,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include #include diff --git a/modules/features2d/test/test_precomp.hpp b/modules/features2d/test/test_precomp.hpp index 979e7c78cb..49bc1dfd18 100644 --- a/modules/features2d/test/test_precomp.hpp +++ b/modules/features2d/test/test_precomp.hpp @@ -11,7 +11,6 @@ #include "opencv2/ts.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/features2d.hpp" #include "opencv2/highgui.hpp" #include diff --git a/modules/features2d/test/test_rotation_and_scale_invariance.cpp b/modules/features2d/test/test_rotation_and_scale_invariance.cpp index 1f67da17be..dd0e48e7d3 100644 --- a/modules/features2d/test/test_rotation_and_scale_invariance.cpp +++ b/modules/features2d/test/test_rotation_and_scale_invariance.cpp @@ -217,7 +217,7 @@ protected: vector keypoints0; featureDetector->detect(image0, keypoints0); if(keypoints0.size() < 15) - CV_Error(CV_StsAssert, "Detector gives too few points in a test image\n"); + CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n"); const int maxAngle = 360, angleStep = 15; for(int angle = 0; angle < maxAngle; angle += angleStep) @@ -246,7 +246,7 @@ protected: float angle0 = keypoints0[matches[m].queryIdx].angle; float angle1 = keypoints1[matches[m].trainIdx].angle; if(angle0 == -1 || angle1 == -1) - CV_Error(CV_StsBadArg, "Given FeatureDetector is not rotation invariant, it can not be tested here.\n"); + CV_Error(Error::StsBadArg, "Given FeatureDetector is not rotation invariant, it can not be tested here.\n"); CV_Assert(angle0 >= 0.f && angle0 < 360.f); CV_Assert(angle1 >= 0.f && angle1 < 360.f); @@ -330,7 +330,7 @@ protected: Mat descriptors0; featureDetector->detect(image0, keypoints0); if(keypoints0.size() < 15) - CV_Error(CV_StsAssert, "Detector gives too few points in a test image\n"); + CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n"); descriptorExtractor->compute(image0, keypoints0, descriptors0); BFMatcher bfmatcher(normType); @@ -413,7 +413,7 @@ protected: vector keypoints0; featureDetector->detect(image0, keypoints0); if(keypoints0.size() < 15) - CV_Error(CV_StsAssert, "Detector gives too few points in a test image\n"); + CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n"); for(int scaleIdx = 1; scaleIdx <= 3; scaleIdx++) { @@ -424,7 +424,7 @@ protected: vector keypoints1, osiKeypoints1; // osi - original size image featureDetector->detect(image1, keypoints1); if(keypoints1.size() < 15) - CV_Error(CV_StsAssert, "Detector gives too few points in a test image\n"); + CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n"); if(keypoints1.size() > keypoints0.size()) { @@ -532,7 +532,7 @@ protected: vector keypoints0; featureDetector->detect(image0, keypoints0); if(keypoints0.size() < 15) - CV_Error(CV_StsAssert, "Detector gives too few points in a test image\n"); + CV_Error(Error::StsAssert, "Detector gives too few points in a test image\n"); Mat descriptors0; descriptorExtractor->compute(image0, keypoints0, descriptors0); diff --git a/modules/gpu/src/precomp.hpp b/modules/gpu/src/precomp.hpp index d8fdca7ddc..cc25ab2f97 100644 --- a/modules/gpu/src/precomp.hpp +++ b/modules/gpu/src/precomp.hpp @@ -65,7 +65,6 @@ #include "opencv2/core/utility.hpp" #include "opencv2/gpu.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/calib3d.hpp" #include "opencv2/video.hpp" diff --git a/modules/highgui/src/precomp.hpp b/modules/highgui/src/precomp.hpp index 9c13ef1281..81ccb32030 100644 --- a/modules/highgui/src/precomp.hpp +++ b/modules/highgui/src/precomp.hpp @@ -43,12 +43,13 @@ #define __HIGHGUI_H_ #include "opencv2/highgui.hpp" -#include "opencv2/highgui/highgui_c.h" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core/utility.hpp" #include "opencv2/core/private.hpp" +#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/highgui/highgui_c.h" + #include #include #include diff --git a/modules/imgproc/doc/filtering.rst b/modules/imgproc/doc/filtering.rst index 81a64bd333..3e0bbb3a9a 100755 --- a/modules/imgproc/doc/filtering.rst +++ b/modules/imgproc/doc/filtering.rst @@ -444,37 +444,6 @@ The call ``blur(src, dst, ksize, anchor, borderType)`` is equivalent to ``boxFil :ocv:func:`medianBlur` -borderInterpolate ------------------ -Computes the source location of an extrapolated pixel. - -.. ocv:function:: int borderInterpolate( int p, int len, int borderType ) - -.. ocv:pyfunction:: cv2.borderInterpolate(p, len, borderType) -> retval - - :param p: 0-based coordinate of the extrapolated pixel along one of the axes, likely <0 or >= ``len`` . - - :param len: Length of the array along the corresponding axis. - - :param borderType: Border type, one of the ``BORDER_*`` , except for ``BORDER_TRANSPARENT`` and ``BORDER_ISOLATED`` . When ``borderType==BORDER_CONSTANT`` , the function always returns -1, regardless of ``p`` and ``len`` . - -The function computes and returns the coordinate of a donor pixel corresponding to the specified extrapolated pixel when using the specified extrapolation border mode. For example, if you use ``BORDER_WRAP`` mode in the horizontal direction, ``BORDER_REFLECT_101`` in the vertical direction and want to compute value of the "virtual" pixel ``Point(-5, 100)`` in a floating-point image ``img`` , it looks like: :: - - float val = img.at(borderInterpolate(100, img.rows, BORDER_REFLECT_101), - borderInterpolate(-5, img.cols, BORDER_WRAP)); - - -Normally, the function is not called directly. It is used inside -:ocv:class:`FilterEngine` and -:ocv:func:`copyMakeBorder` to compute tables for quick extrapolation. - -.. seealso:: - - :ocv:class:`FilterEngine`, - :ocv:func:`copyMakeBorder` - - - boxFilter --------- Blurs an image using the box filter. @@ -537,63 +506,6 @@ The function constructs a vector of images and builds the Gaussian pyramid by re :ocv:func:`pyrDown` to the previously built pyramid layers, starting from ``dst[0]==src`` . - -copyMakeBorder --------------- -Forms a border around an image. - -.. ocv:function:: void copyMakeBorder( InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar& value=Scalar() ) - -.. ocv:pyfunction:: cv2.copyMakeBorder(src, top, bottom, left, right, borderType[, dst[, value]]) -> dst - -.. ocv:cfunction:: void cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset, int bordertype, CvScalar value=cvScalarAll(0) ) -.. ocv:pyoldfunction:: cv.CopyMakeBorder(src, dst, offset, bordertype, value=(0, 0, 0, 0))-> None - - :param src: Source image. - - :param dst: Destination image of the same type as ``src`` and the size ``Size(src.cols+left+right, src.rows+top+bottom)`` . - - :param top: - - :param bottom: - - :param left: - - :param right: Parameter specifying how many pixels in each direction from the source image rectangle to extrapolate. For example, ``top=1, bottom=1, left=1, right=1`` mean that 1 pixel-wide border needs to be built. - - :param borderType: Border type. See :ocv:func:`borderInterpolate` for details. - - :param value: Border value if ``borderType==BORDER_CONSTANT`` . - -The function copies the source image into the middle of the destination image. The areas to the left, to the right, above and below the copied source image will be filled with extrapolated pixels. This is not what -:ocv:class:`FilterEngine` or filtering functions based on it do (they extrapolate pixels on-fly), but what other more complex functions, including your own, may do to simplify image boundary handling. - -The function supports the mode when ``src`` is already in the middle of ``dst`` . In this case, the function does not copy ``src`` itself but simply constructs the border, for example: :: - - // let border be the same in all directions - int border=2; - // constructs a larger image to fit both the image and the border - Mat gray_buf(rgb.rows + border*2, rgb.cols + border*2, rgb.depth()); - // select the middle part of it w/o copying data - Mat gray(gray_canvas, Rect(border, border, rgb.cols, rgb.rows)); - // convert image from RGB to grayscale - cvtColor(rgb, gray, CV_RGB2GRAY); - // form a border in-place - copyMakeBorder(gray, gray_buf, border, border, - border, border, BORDER_REPLICATE); - // now do some custom filtering ... - ... - - -.. note:: - - When the source image is a part (ROI) of a bigger image, the function will try to use the pixels outside of the ROI to form a border. To disable this feature and always do extrapolation, as if ``src`` was not a ROI, use ``borderType | BORDER_ISOLATED``. - -.. seealso:: - - :ocv:func:`borderInterpolate` - - createBoxFilter ------------------- Returns a box filter engine. diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 16827201f8..fcaf6a58ee 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -51,20 +51,6 @@ namespace cv { -//! Various border types, image boundaries are denoted with '|' -enum { - BORDER_CONSTANT = 0, // iiiiii|abcdefgh|iiiiiii with some specified 'i' - BORDER_REPLICATE = 1, // aaaaaa|abcdefgh|hhhhhhh - BORDER_REFLECT = 2, // fedcba|abcdefgh|hgfedcb - BORDER_WRAP = 3, // cdefgh|abcdefgh|abcdefg - BORDER_REFLECT_101 = 4, // gfedcb|abcdefgh|gfedcba - BORDER_TRANSPARENT = 5, // uvwxyz|absdefgh|ijklmno - - BORDER_REFLECT101 = BORDER_REFLECT_101, - BORDER_DEFAULT = BORDER_REFLECT_101, - BORDER_ISOLATED = 16 // do not look outside of ROI - }; - //! type of the kernel enum { KERNEL_GENERAL = 0, // the kernel is generic. No any type of symmetry or other properties. KERNEL_SYMMETRICAL = 1, // kernel[i] == kernel[ksize-i-1] , and the anchor is at the center @@ -753,29 +739,6 @@ public: }; -//! raster image moments -class CV_EXPORTS_W_MAP Moments -{ -public: - //! the default constructor - Moments(); - //! the full constructor - Moments(double m00, double m10, double m01, double m20, double m11, - double m02, double m30, double m21, double m12, double m03 ); - ////! the conversion from CvMoments - //Moments( const CvMoments& moments ); - ////! the conversion to CvMoments - //operator CvMoments() const; - - //! spatial moments - CV_PROP_RW double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03; - //! central moments - CV_PROP_RW double mu20, mu11, mu02, mu30, mu21, mu12, mu03; - //! central normalized moments - CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03; -}; - - class CV_EXPORTS_W Subdiv2D { public: @@ -959,14 +922,6 @@ CV_EXPORTS Ptr createMorphologyFilter(int op, int type, InputArray //! returns structuring element of the specified shape and size CV_EXPORTS_W Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1,-1)); -//! 1D interpolation function: returns coordinate of the "donor" pixel for the specified location p. -CV_EXPORTS_W int borderInterpolate( int p, int len, int borderType ); - -//! copies 2D array to a larger destination array with extrapolation of the outer part of src using the specified border mode -CV_EXPORTS_W void copyMakeBorder( InputArray src, OutputArray dst, - int top, int bottom, int left, int right, - int borderType, const Scalar& value = Scalar() ); - //! smooths the image using median filter. CV_EXPORTS_W void medianBlur( InputArray src, OutputArray dst, int ksize ); @@ -1165,9 +1120,6 @@ CV_EXPORTS_W void accumulateProduct( InputArray src1, InputArray src2, CV_EXPORTS_W void accumulateWeighted( InputArray src, InputOutputArray dst, double alpha, InputArray mask = noArray() ); -//! computes PSNR image/video quality metric -CV_EXPORTS_W double PSNR(InputArray src1, InputArray src2); - CV_EXPORTS_W Point2d phaseCorrelate(InputArray src1, InputArray src2, InputArray window = noArray(), CV_OUT double* response = 0); diff --git a/modules/imgproc/include/opencv2/imgproc/types_c.h b/modules/imgproc/include/opencv2/imgproc/types_c.h index 5b89e2d7c1..2b1d0722e2 100644 --- a/modules/imgproc/include/opencv2/imgproc/types_c.h +++ b/modules/imgproc/include/opencv2/imgproc/types_c.h @@ -45,10 +45,6 @@ #include "opencv2/core/core_c.h" -#ifdef __cplusplus -# include "opencv2/imgproc.hpp" -#endif - #ifdef __cplusplus extern "C" { #endif diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 19c90df8f1..86322e4ba5 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -46,50 +46,6 @@ Base Image Filter \****************************************************************************************/ -/* - Various border types, image boundaries are denoted with '|' - - * BORDER_REPLICATE: aaaaaa|abcdefgh|hhhhhhh - * BORDER_REFLECT: fedcba|abcdefgh|hgfedcb - * BORDER_REFLECT_101: gfedcb|abcdefgh|gfedcba - * BORDER_WRAP: cdefgh|abcdefgh|abcdefg - * BORDER_CONSTANT: iiiiii|abcdefgh|iiiiiii with some specified 'i' - */ -int cv::borderInterpolate( int p, int len, int borderType ) -{ - if( (unsigned)p < (unsigned)len ) - ; - else if( borderType == BORDER_REPLICATE ) - p = p < 0 ? 0 : len - 1; - else if( borderType == BORDER_REFLECT || borderType == BORDER_REFLECT_101 ) - { - int delta = borderType == BORDER_REFLECT_101; - if( len == 1 ) - return 0; - do - { - if( p < 0 ) - p = -p - 1 + delta; - else - p = len - 1 - (p - len) - delta; - } - while( (unsigned)p >= (unsigned)len ); - } - else if( borderType == BORDER_WRAP ) - { - if( p < 0 ) - p -= ((p-len+1)/len)*len; - if( p >= len ) - p %= len; - } - else if( borderType == BORDER_CONSTANT ) - p = -1; - else - CV_Error( CV_StsBadArg, "Unknown/unsupported border type" ); - return p; -} - - namespace cv { diff --git a/modules/imgproc/src/generalized_hough.cpp b/modules/imgproc/src/generalized_hough.cpp index 41a4e72b2e..8eadff200b 100644 --- a/modules/imgproc/src/generalized_hough.cpp +++ b/modules/imgproc/src/generalized_hough.cpp @@ -41,6 +41,7 @@ #include "precomp.hpp" #include +#include using namespace cv; diff --git a/modules/imgproc/src/precomp.hpp b/modules/imgproc/src/precomp.hpp index f2c4ee0f6a..a3bbd65dbb 100644 --- a/modules/imgproc/src/precomp.hpp +++ b/modules/imgproc/src/precomp.hpp @@ -43,11 +43,10 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ - #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" - #include "opencv2/core/utility.hpp" + +#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core/private.hpp" #include diff --git a/modules/imgproc/src/utils.cpp b/modules/imgproc/src/utils.cpp index 72f4978e93..4f45cde5e0 100644 --- a/modules/imgproc/src/utils.cpp +++ b/modules/imgproc/src/utils.cpp @@ -75,196 +75,6 @@ CV_IMPL CvSeq* cvPointSeqFromMat( int seq_kind, const CvArr* arr, return (CvSeq*)contour_header; } -namespace cv -{ - -static void copyMakeBorder_8u( const uchar* src, size_t srcstep, Size srcroi, - uchar* dst, size_t dststep, Size dstroi, - int top, int left, int cn, int borderType ) -{ - const int isz = (int)sizeof(int); - int i, j, k, elemSize = 1; - bool intMode = false; - - if( (cn | srcstep | dststep | (size_t)src | (size_t)dst) % isz == 0 ) - { - cn /= isz; - elemSize = isz; - intMode = true; - } - - AutoBuffer _tab((dstroi.width - srcroi.width)*cn); - int* tab = _tab; - int right = dstroi.width - srcroi.width - left; - int bottom = dstroi.height - srcroi.height - top; - - for( i = 0; i < left; i++ ) - { - j = borderInterpolate(i - left, srcroi.width, borderType)*cn; - for( k = 0; k < cn; k++ ) - tab[i*cn + k] = j + k; - } - - for( i = 0; i < right; i++ ) - { - j = borderInterpolate(srcroi.width + i, srcroi.width, borderType)*cn; - for( k = 0; k < cn; k++ ) - tab[(i+left)*cn + k] = j + k; - } - - srcroi.width *= cn; - dstroi.width *= cn; - left *= cn; - right *= cn; - - uchar* dstInner = dst + dststep*top + left*elemSize; - - for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep ) - { - if( dstInner != src ) - memcpy(dstInner, src, srcroi.width*elemSize); - - if( intMode ) - { - const int* isrc = (int*)src; - int* idstInner = (int*)dstInner; - for( j = 0; j < left; j++ ) - idstInner[j - left] = isrc[tab[j]]; - for( j = 0; j < right; j++ ) - idstInner[j + srcroi.width] = isrc[tab[j + left]]; - } - else - { - for( j = 0; j < left; j++ ) - dstInner[j - left] = src[tab[j]]; - for( j = 0; j < right; j++ ) - dstInner[j + srcroi.width] = src[tab[j + left]]; - } - } - - dstroi.width *= elemSize; - dst += dststep*top; - - for( i = 0; i < top; i++ ) - { - j = borderInterpolate(i - top, srcroi.height, borderType); - memcpy(dst + (i - top)*dststep, dst + j*dststep, dstroi.width); - } - - for( i = 0; i < bottom; i++ ) - { - j = borderInterpolate(i + srcroi.height, srcroi.height, borderType); - memcpy(dst + (i + srcroi.height)*dststep, dst + j*dststep, dstroi.width); - } -} - - -static void copyMakeConstBorder_8u( const uchar* src, size_t srcstep, Size srcroi, - uchar* dst, size_t dststep, Size dstroi, - int top, int left, int cn, const uchar* value ) -{ - int i, j; - AutoBuffer _constBuf(dstroi.width*cn); - uchar* constBuf = _constBuf; - int right = dstroi.width - srcroi.width - left; - int bottom = dstroi.height - srcroi.height - top; - - for( i = 0; i < dstroi.width; i++ ) - { - for( j = 0; j < cn; j++ ) - constBuf[i*cn + j] = value[j]; - } - - srcroi.width *= cn; - dstroi.width *= cn; - left *= cn; - right *= cn; - - uchar* dstInner = dst + dststep*top + left; - - for( i = 0; i < srcroi.height; i++, dstInner += dststep, src += srcstep ) - { - if( dstInner != src ) - memcpy( dstInner, src, srcroi.width ); - memcpy( dstInner - left, constBuf, left ); - memcpy( dstInner + srcroi.width, constBuf, right ); - } - - dst += dststep*top; - - for( i = 0; i < top; i++ ) - memcpy(dst + (i - top)*dststep, constBuf, dstroi.width); - - for( i = 0; i < bottom; i++ ) - memcpy(dst + (i + srcroi.height)*dststep, constBuf, dstroi.width); -} - -} - -void cv::copyMakeBorder( InputArray _src, OutputArray _dst, int top, int bottom, - int left, int right, int borderType, const Scalar& value ) -{ - Mat src = _src.getMat(); - CV_Assert( top >= 0 && bottom >= 0 && left >= 0 && right >= 0 ); - - if( src.isSubmatrix() && (borderType & BORDER_ISOLATED) == 0 ) - { - Size wholeSize; - Point ofs; - src.locateROI(wholeSize, ofs); - int dtop = std::min(ofs.y, top); - int dbottom = std::min(wholeSize.height - src.rows - ofs.y, bottom); - int dleft = std::min(ofs.x, left); - int dright = std::min(wholeSize.width - src.cols - ofs.x, right); - src.adjustROI(dtop, dbottom, dleft, dright); - top -= dtop; - left -= dleft; - bottom -= dbottom; - right -= dright; - } - - _dst.create( src.rows + top + bottom, src.cols + left + right, src.type() ); - Mat dst = _dst.getMat(); - - if(top == 0 && left == 0 && bottom == 0 && right == 0) - { - if(src.data != dst.data || src.step != dst.step) - src.copyTo(dst); - return; - } - - borderType &= ~BORDER_ISOLATED; - - if( borderType != BORDER_CONSTANT ) - copyMakeBorder_8u( src.data, src.step, src.size(), - dst.data, dst.step, dst.size(), - top, left, (int)src.elemSize(), borderType ); - else - { - int cn = src.channels(), cn1 = cn; - AutoBuffer buf(cn); - if( cn > 4 ) - { - CV_Assert( value[0] == value[1] && value[0] == value[2] && value[0] == value[3] ); - 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(), - top, left, (int)src.elemSize(), (uchar*)(double*)buf ); - } -} - - -double cv::PSNR(InputArray _src1, InputArray _src2) -{ - Mat src1 = _src1.getMat(), src2 = _src2.getMat(); - CV_Assert( src1.depth() == CV_8U ); - double diff = std::sqrt(norm(src1, src2, NORM_L2SQR)/(src1.total()*src1.channels())); - return 20*log10(255./(diff+DBL_EPSILON)); -} - - CV_IMPL void cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset, int borderType, CvScalar value ) diff --git a/modules/java/android_test/src/org/opencv/test/core/CoreTest.java b/modules/java/android_test/src/org/opencv/test/core/CoreTest.java index 0916cae0e3..9b49ba4d20 100644 --- a/modules/java/android_test/src/org/opencv/test/core/CoreTest.java +++ b/modules/java/android_test/src/org/opencv/test/core/CoreTest.java @@ -2256,4 +2256,35 @@ public class CoreTest extends OpenCVTestCase { } + public void testCopyMakeBorderMatMatIntIntIntIntInt() { + Mat src = new Mat(2, 2, CvType.CV_32F, new Scalar(1)); + int border = 2; + + Core.copyMakeBorder(src, dst, border, border, border, border, Core.BORDER_REPLICATE); + + truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1)); + assertMatEqual(truth, dst, EPS); + } + + public void testCopyMakeBorderMatMatIntIntIntIntIntScalar() { + Mat src = new Mat(2, 2, CvType.CV_32F, new Scalar(1)); + + Scalar value = new Scalar(0); + int border = 2; + + Core.copyMakeBorder(src, dst, border, border, border, border, Core.BORDER_REPLICATE, value); + // TODO_: write better test (use Core.BORDER_CONSTANT) + + truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1)); + assertMatEqual(truth, dst, EPS); + } + + public void testBorderInterpolate() { + float val1 = Core.borderInterpolate(100, 150, Core.BORDER_REFLECT_101); + assertEquals(100f, val1); + + float val2 = Core.borderInterpolate(-5, 10, Core.BORDER_WRAP); + assertEquals(5f, val2); + } + } diff --git a/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java b/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java index 9d4d1346aa..b4221b1336 100644 --- a/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java +++ b/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java @@ -176,7 +176,7 @@ public class ImgprocTest extends OpenCVTestCase { } public void testBilateralFilterMatMatIntDoubleDoubleInt() { - Imgproc.bilateralFilter(gray255, dst, 5, 10, 5, Imgproc.BORDER_REFLECT); + Imgproc.bilateralFilter(gray255, dst, 5, 10, 5, Core.BORDER_REFLECT); assertMatEqual(gray255, dst); // TODO_: write better test @@ -198,19 +198,11 @@ public class ImgprocTest extends OpenCVTestCase { } public void testBlurMatMatSizePointInt() { - Imgproc.blur(gray0, dst, size, anchorPoint, Imgproc.BORDER_REFLECT); + Imgproc.blur(gray0, dst, size, anchorPoint, Core.BORDER_REFLECT); assertMatEqual(gray0, dst); // TODO_: write better test } - public void testBorderInterpolate() { - float val1 = Imgproc.borderInterpolate(100, 150, Imgproc.BORDER_REFLECT_101); - assertEquals(100f, val1); - - float val2 = Imgproc.borderInterpolate(-5, 10, Imgproc.BORDER_WRAP); - assertEquals(5f, val2); - } - public void testBoundingRect() { MatOfPoint points = new MatOfPoint(new Point(0, 0), new Point(0, 4), new Point(4, 0), new Point(4, 4)); Point p1 = new Point(1, 1); @@ -236,7 +228,7 @@ public class ImgprocTest extends OpenCVTestCase { } public void testBoxFilterMatMatIntSizePointBooleanInt() { - Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false, Imgproc.BORDER_REFLECT); + Imgproc.boxFilter(gray255, dst, 8, size, anchorPoint, false, Core.BORDER_REFLECT); assertMatEqual(gray255, dst); // TODO_: write better test } @@ -479,29 +471,6 @@ public class ImgprocTest extends OpenCVTestCase { assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects); } - public void testCopyMakeBorderMatMatIntIntIntIntInt() { - Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1)); - int border = 2; - - Imgproc.copyMakeBorder(src, dst, border, border, border, border, Imgproc.BORDER_REPLICATE); - - truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1)); - assertMatEqual(truth, dst, EPS); - } - - public void testCopyMakeBorderMatMatIntIntIntIntIntScalar() { - Mat src = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(1)); - - Scalar value = new Scalar(0); - int border = 2; - - Imgproc.copyMakeBorder(src, dst, border, border, border, border, Imgproc.BORDER_REPLICATE, value); - // TODO_: write better test (use Imgproc.BORDER_CONSTANT) - - truth = new Mat(6, 6, CvType.CV_32F, new Scalar(1)); - assertMatEqual(truth, dst, EPS); - } - public void testCornerEigenValsAndVecsMatMatIntInt() { fail("Not yet implemented"); // TODO: write better test @@ -528,7 +497,7 @@ public class ImgprocTest extends OpenCVTestCase { truth = new Mat(4, 4, CvType.CV_32FC(6), new Scalar(0)); - Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize, Imgproc.BORDER_REFLECT); + Imgproc.cornerEigenValsAndVecs(src, dst, blockSize, ksize, Core.BORDER_REFLECT); assertMatEqual(truth, dst, EPS); } @@ -552,7 +521,7 @@ public class ImgprocTest extends OpenCVTestCase { int blockSize = 5; int ksize = 7; double k = 0.1; - Imgproc.cornerHarris(gray255, dst, blockSize, ksize, k, Imgproc.BORDER_REFLECT); + Imgproc.cornerHarris(gray255, dst, blockSize, ksize, k, Core.BORDER_REFLECT); assertMatEqual(truth, dst, EPS); } @@ -598,7 +567,7 @@ public class ImgprocTest extends OpenCVTestCase { int blockSize = 3; int ksize = 5; - Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize, Imgproc.BORDER_REFLECT); + Imgproc.cornerMinEigenVal(src, dst, blockSize, ksize, Core.BORDER_REFLECT); truth = new Mat(3, 3, CvType.CV_32FC1) { { @@ -742,7 +711,7 @@ public class ImgprocTest extends OpenCVTestCase { Mat kernel = new Mat(); Scalar sc = new Scalar(3, 3); - Imgproc.erode(src, dst, kernel, anchorPoint, 10, Imgproc.BORDER_REFLECT, sc); + Imgproc.erode(src, dst, kernel, anchorPoint, 10, Core.BORDER_REFLECT, sc); truth = new Mat(3, 3, CvType.CV_8U, new Scalar(8)); assertMatEqual(truth, dst); @@ -773,7 +742,7 @@ public class ImgprocTest extends OpenCVTestCase { Mat kernel = new Mat(imgprocSz, imgprocSz, CvType.CV_32F, new Scalar(0)); Point point = new Point(0, 0); - Imgproc.filter2D(gray128, dst, -1, kernel, point, 2, Imgproc.BORDER_CONSTANT); + Imgproc.filter2D(gray128, dst, -1, kernel, point, 2, Core.BORDER_CONSTANT); assertMatEqual(gray2, dst); } @@ -901,7 +870,7 @@ public class ImgprocTest extends OpenCVTestCase { } public void testGaussianBlurMatMatSizeDoubleDoubleInt() { - Imgproc.GaussianBlur(gray2, dst, size, 1, 3, Imgproc.BORDER_REFLECT); + Imgproc.GaussianBlur(gray2, dst, size, 1, 3, Core.BORDER_REFLECT); assertMatEqual(gray2, dst); // TODO_: write better test @@ -1384,7 +1353,7 @@ public class ImgprocTest extends OpenCVTestCase { public void testLaplacianMatMatIntIntDoubleDoubleInt() { Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(2)); - Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS, Imgproc.BORDER_REFLECT); + Imgproc.Laplacian(src, dst, CvType.CV_32F, 1, 2, EPS, Core.BORDER_REFLECT); truth = new Mat(3, 3, CvType.CV_32F, new Scalar(0.00099945068)); assertMatEqual(truth, dst, EPS); @@ -1486,7 +1455,7 @@ public class ImgprocTest extends OpenCVTestCase { Point point = new Point(1, 1); Scalar sc = new Scalar(3, 3); - Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel, point, 10, Imgproc.BORDER_REFLECT, sc); + Imgproc.morphologyEx(src, dst, Imgproc.MORPH_TOPHAT, kernel, point, 10, Core.BORDER_REFLECT, sc); truth = new Mat(imgprocSz, imgprocSz, CvType.CV_8U) { { put(0, 0, 1, 0); @@ -1520,7 +1489,7 @@ public class ImgprocTest extends OpenCVTestCase { Mat src = new Mat(4, 4, CvType.CV_32F, new Scalar(1)); int ksize = 3; - Imgproc.preCornerDetect(src, dst, ksize, Imgproc.BORDER_REFLECT); + Imgproc.preCornerDetect(src, dst, ksize, Core.BORDER_REFLECT); truth = new Mat(4, 4, CvType.CV_32F, new Scalar(0)); assertMatEqual(truth, dst, EPS); @@ -1640,7 +1609,7 @@ public class ImgprocTest extends OpenCVTestCase { truth = new Mat(1, 3, CvType.CV_32F, new Scalar(2)); - Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR, Imgproc.BORDER_REFLECT, sc); + Imgproc.remap(src, dst, map1, map2, Imgproc.INTER_LINEAR, Core.BORDER_REFLECT, sc); assertMatEqual(truth, dst, EPS); } @@ -1683,7 +1652,7 @@ public class ImgprocTest extends OpenCVTestCase { public void testScharrMatMatIntIntIntDoubleDoubleInt() { Mat src = Mat.eye(3, 3, CvType.CV_32F); - Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0, Imgproc.BORDER_REFLECT); + Imgproc.Scharr(src, dst, CvType.CV_32F, 1, 0, 1.5, 0, Core.BORDER_REFLECT); truth = new Mat(3, 3, CvType.CV_32F) { { @@ -1728,7 +1697,7 @@ public class ImgprocTest extends OpenCVTestCase { Mat kernelY = new Mat(1, 3, CvType.CV_32FC1); kernelY.put(0, 0, 1, 1, 1); - Imgproc.sepFilter2D(gray0, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS, Imgproc.BORDER_REFLECT); + Imgproc.sepFilter2D(gray0, dst, CvType.CV_32F, kernelX, kernelY, anchorPoint, weakEPS, Core.BORDER_REFLECT); truth = new Mat(10, 10, CvType.CV_32F, new Scalar(weakEPS)); assertMatEqual(truth, dst, EPS); @@ -1756,7 +1725,7 @@ public class ImgprocTest extends OpenCVTestCase { } }; - Imgproc.Sobel(src, dst, CvType.CV_32F, 1, 0, 3, 2, 0, Imgproc.BORDER_REPLICATE); + Imgproc.Sobel(src, dst, CvType.CV_32F, 1, 0, 3, 2, 0, Core.BORDER_REPLICATE); truth = new Mat(3, 3, CvType.CV_32F) { { diff --git a/modules/objdetect/src/cascadedetect.cpp b/modules/objdetect/src/cascadedetect.cpp index 3b7eb58c16..f288b2c0a8 100644 --- a/modules/objdetect/src/cascadedetect.cpp +++ b/modules/objdetect/src/cascadedetect.cpp @@ -1126,7 +1126,7 @@ void CascadeClassifier::detectMultiScale( const Mat& image, std::vector& o if( grayImage.channels() > 1 ) { Mat temp; - cvtColor(grayImage, temp, CV_BGR2GRAY); + cvtColor(grayImage, temp, COLOR_BGR2GRAY); grayImage = temp; } @@ -1149,7 +1149,7 @@ void CascadeClassifier::detectMultiScale( const Mat& image, std::vector& o continue; Mat scaledImage( scaledImageSize, CV_8U, imageBuffer.data ); - resize( grayImage, scaledImage, scaledImageSize, 0, 0, CV_INTER_LINEAR ); + resize( grayImage, scaledImage, scaledImageSize, 0, 0, INTER_LINEAR ); int yStep; if( getFeatureType() == cv::FeatureEvaluator::HOG ) diff --git a/modules/objdetect/src/datamatrix.cpp b/modules/objdetect/src/datamatrix.cpp index 94aed159b7..2d7561b2ba 100644 --- a/modules/objdetect/src/datamatrix.cpp +++ b/modules/objdetect/src/datamatrix.cpp @@ -1,4 +1,5 @@ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include #include diff --git a/modules/objdetect/src/featurepyramid.cpp b/modules/objdetect/src/featurepyramid.cpp index c6bc6c0e8a..a193eef431 100644 --- a/modules/objdetect/src/featurepyramid.cpp +++ b/modules/objdetect/src/featurepyramid.cpp @@ -1,4 +1,5 @@ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include "_latentsvm.h" #include "_lsvm_resizeimg.h" diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index 0f7ac288a8..625f5841f8 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -42,7 +42,8 @@ /* Haar features calculation */ #include "precomp.hpp" -#include "stdio.h" +#include "opencv2/imgproc/imgproc_c.h" +#include #if CV_SSE2 # if 1 /*!CV_SSE4_1 && !CV_SSE4_2*/ diff --git a/modules/objdetect/src/latentsvmdetector.cpp b/modules/objdetect/src/latentsvmdetector.cpp index 5944333e4a..78225c64e4 100644 --- a/modules/objdetect/src/latentsvmdetector.cpp +++ b/modules/objdetect/src/latentsvmdetector.cpp @@ -1,4 +1,5 @@ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include "_lsvmparser.h" #include "_lsvm_matching.h" diff --git a/modules/objdetect/src/linemod.cpp b/modules/objdetect/src/linemod.cpp index f3b7af6f63..d0a6a19947 100644 --- a/modules/objdetect/src/linemod.cpp +++ b/modules/objdetect/src/linemod.cpp @@ -483,7 +483,7 @@ void ColorGradientPyramid::pyrDown() if (!mask.empty()) { Mat next_mask; - resize(mask, next_mask, size, 0.0, 0.0, CV_INTER_NN); + resize(mask, next_mask, size, 0.0, 0.0, INTER_NEAREST); mask = next_mask; } @@ -635,17 +635,11 @@ static void quantizedNormals(const Mat& src, Mat& dst, int distance_threshold, { dst = Mat::zeros(src.size(), CV_8U); - IplImage src_ipl = src; - IplImage* ap_depth_data = &src_ipl; - IplImage dst_ipl = dst; - IplImage* dst_ipl_ptr = &dst_ipl; - IplImage** m_dep = &dst_ipl_ptr; + const unsigned short * lp_depth = src.ptr(); + unsigned char * lp_normals = dst.ptr(); - unsigned short * lp_depth = (unsigned short *)ap_depth_data->imageData; - unsigned char * lp_normals = (unsigned char *)m_dep[0]->imageData; - - const int l_W = ap_depth_data->width; - const int l_H = ap_depth_data->height; + const int l_W = src.cols; + const int l_H = src.rows; const int l_r = 5; // used to be 7 const int l_offset0 = -l_r - l_r * l_W; @@ -662,7 +656,7 @@ static void quantizedNormals(const Mat& src, Mat& dst, int distance_threshold, for (int l_y = l_r; l_y < l_H - l_r - 1; ++l_y) { - unsigned short * lp_line = lp_depth + (l_y * l_W + l_r); + const unsigned short * lp_line = lp_depth + (l_y * l_W + l_r); unsigned char * lp_norm = lp_normals + (l_y * l_W + l_r); for (int l_x = l_r; l_x < l_W - l_r - 1; ++l_x) @@ -725,7 +719,7 @@ static void quantizedNormals(const Mat& src, Mat& dst, int distance_threshold, ++lp_norm; } } - cvSmooth(m_dep[0], m_dep[0], CV_MEDIAN, 5, 5); + medianBlur(dst, dst, 5); } class DepthNormalPyramid : public QuantizedPyramid @@ -772,12 +766,12 @@ void DepthNormalPyramid::pyrDown() // In this case, NN-downsample the quantized image Mat next_normal; Size size(normal.cols / 2, normal.rows / 2); - resize(normal, next_normal, size, 0.0, 0.0, CV_INTER_NN); + resize(normal, next_normal, size, 0.0, 0.0, INTER_NEAREST); normal = next_normal; if (!mask.empty()) { Mat next_mask; - resize(mask, next_mask, size, 0.0, 0.0, CV_INTER_NN); + resize(mask, next_mask, size, 0.0, 0.0, INTER_NEAREST); mask = next_mask; } } @@ -805,7 +799,7 @@ bool DepthNormalPyramid::extractTemplate(Template& templ) const temp.setTo(1 << i, local_mask); bitwise_and(temp, normal, temp); // temp is now non-zero at pixels in the mask with quantized orientation i - distanceTransform(temp, distances[i], CV_DIST_C, 3); + distanceTransform(temp, distances[i], DIST_C, 3); } // Count how many features taken for each label diff --git a/modules/objdetect/src/precomp.hpp b/modules/objdetect/src/precomp.hpp index fd5f560257..de636de029 100644 --- a/modules/objdetect/src/precomp.hpp +++ b/modules/objdetect/src/precomp.hpp @@ -45,8 +45,6 @@ #include "opencv2/objdetect.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/core/core_c.h" #include "opencv2/core/utility.hpp" diff --git a/modules/objdetect/src/resizeimg.cpp b/modules/objdetect/src/resizeimg.cpp index 59f0b8cb8d..d999d12846 100644 --- a/modules/objdetect/src/resizeimg.cpp +++ b/modules/objdetect/src/resizeimg.cpp @@ -1,4 +1,5 @@ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include "_lsvm_resizeimg.h" #include #include diff --git a/modules/ocl/src/color.cpp b/modules/ocl/src/color.cpp index a98549c400..e6c958f672 100644 --- a/modules/ocl/src/color.cpp +++ b/modules/ocl/src/color.cpp @@ -182,90 +182,90 @@ void cvtColor_caller(const oclMat &src, oclMat &dst, int code, int dcn) switch (code) { /* - case CV_BGR2BGRA: case CV_RGB2BGRA: case CV_BGRA2BGR: - case CV_RGBA2BGR: case CV_RGB2BGR: case CV_BGRA2RGBA: - case CV_BGR2BGR565: case CV_BGR2BGR555: case CV_RGB2BGR565: case CV_RGB2BGR555: - case CV_BGRA2BGR565: case CV_BGRA2BGR555: case CV_RGBA2BGR565: case CV_RGBA2BGR555: - case CV_BGR5652BGR: case CV_BGR5552BGR: case CV_BGR5652RGB: case CV_BGR5552RGB: - case CV_BGR5652BGRA: case CV_BGR5552BGRA: case CV_BGR5652RGBA: case CV_BGR5552RGBA: + case COLOR_BGR2BGRA: case COLOR_RGB2BGRA: case COLOR_BGRA2BGR: + case COLOR_RGBA2BGR: case COLOR_RGB2BGR: case COLOR_BGRA2RGBA: + case COLOR_BGR2BGR565: case COLOR_BGR2BGR555: case COLOR_RGB2BGR565: case COLOR_RGB2BGR555: + case COLOR_BGRA2BGR565: case COLOR_BGRA2BGR555: case COLOR_RGBA2BGR565: case COLOR_RGBA2BGR555: + case COLOR_BGR5652BGR: case COLOR_BGR5552BGR: case COLOR_BGR5652RGB: case COLOR_BGR5552RGB: + case COLOR_BGR5652BGRA: case COLOR_BGR5552BGRA: case COLOR_BGR5652RGBA: case COLOR_BGR5552RGBA: */ - case CV_BGR2GRAY: - case CV_BGRA2GRAY: - case CV_RGB2GRAY: - case CV_RGBA2GRAY: + case COLOR_BGR2GRAY: + case COLOR_BGRA2GRAY: + case COLOR_RGB2GRAY: + case COLOR_RGBA2GRAY: { CV_Assert(scn == 3 || scn == 4); - bidx = code == CV_BGR2GRAY || code == CV_BGRA2GRAY ? 0 : 2; + bidx = code == COLOR_BGR2GRAY || code == COLOR_BGRA2GRAY ? 0 : 2; dst.create(sz, CV_MAKETYPE(depth, 1)); RGB2Gray_caller(src, dst, bidx); break; } - case CV_GRAY2BGR: - case CV_GRAY2BGRA: + case COLOR_GRAY2BGR: + case COLOR_GRAY2BGRA: { CV_Assert(scn == 1); - dcn = code == CV_GRAY2BGRA ? 4 : 3; + dcn = code == COLOR_GRAY2BGRA ? 4 : 3; dst.create(sz, CV_MAKETYPE(depth, dcn)); Gray2RGB_caller(src, dst); break; } - case CV_BGR2YUV: - case CV_RGB2YUV: + case COLOR_BGR2YUV: + case COLOR_RGB2YUV: { CV_Assert(scn == 3 || scn == 4); - bidx = code == CV_BGR2YUV ? 0 : 2; + bidx = code == COLOR_BGR2YUV ? 0 : 2; dst.create(sz, CV_MAKETYPE(depth, 3)); RGB2YUV_caller(src, dst, bidx); break; } - case CV_YUV2BGR: - case CV_YUV2RGB: + case COLOR_YUV2BGR: + case COLOR_YUV2RGB: { CV_Assert(scn == 3 || scn == 4); - bidx = code == CV_YUV2BGR ? 0 : 2; + bidx = code == COLOR_YUV2BGR ? 0 : 2; dst.create(sz, CV_MAKETYPE(depth, 3)); YUV2RGB_caller(src, dst, bidx); break; } - case CV_YUV2RGB_NV12: - case CV_YUV2BGR_NV12: - case CV_YUV2RGBA_NV12: - case CV_YUV2BGRA_NV12: + case COLOR_YUV2RGB_NV12: + case COLOR_YUV2BGR_NV12: + case COLOR_YUV2RGBA_NV12: + case COLOR_YUV2BGRA_NV12: { CV_Assert(scn == 1); CV_Assert( sz.width % 2 == 0 && sz.height % 3 == 0 && depth == CV_8U ); - dcn = code == CV_YUV2BGRA_NV12 || code == CV_YUV2RGBA_NV12 ? 4 : 3; - bidx = code == CV_YUV2BGRA_NV12 || code == CV_YUV2BGR_NV12 ? 0 : 2; + dcn = code == COLOR_YUV2BGRA_NV12 || code == COLOR_YUV2RGBA_NV12 ? 4 : 3; + bidx = code == COLOR_YUV2BGRA_NV12 || code == COLOR_YUV2BGR_NV12 ? 0 : 2; Size dstSz(sz.width, sz.height * 2 / 3); dst.create(dstSz, CV_MAKETYPE(depth, dcn)); YUV2RGB_NV12_caller(src, dst, bidx); break; } - case CV_BGR2YCrCb: - case CV_RGB2YCrCb: + case COLOR_BGR2YCrCb: + case COLOR_RGB2YCrCb: { CV_Assert(scn == 3 || scn == 4); - bidx = code == CV_BGR2YCrCb ? 0 : 2; + bidx = code == COLOR_BGR2YCrCb ? 0 : 2; dst.create(sz, CV_MAKETYPE(depth, 3)); RGB2YCrCb_caller(src, dst, bidx); break; } - case CV_YCrCb2BGR: - case CV_YCrCb2RGB: + case COLOR_YCrCb2BGR: + case COLOR_YCrCb2RGB: { break; } /* - case CV_BGR5652GRAY: case CV_BGR5552GRAY: - case CV_GRAY2BGR565: case CV_GRAY2BGR555: - case CV_BGR2YCrCb: case CV_RGB2YCrCb: - case CV_BGR2XYZ: case CV_RGB2XYZ: - case CV_XYZ2BGR: case CV_XYZ2RGB: - case CV_BGR2HSV: case CV_RGB2HSV: case CV_BGR2HSV_FULL: case CV_RGB2HSV_FULL: - case CV_BGR2HLS: case CV_RGB2HLS: case CV_BGR2HLS_FULL: case CV_RGB2HLS_FULL: - case CV_HSV2BGR: case CV_HSV2RGB: case CV_HSV2BGR_FULL: case CV_HSV2RGB_FULL: - case CV_HLS2BGR: case CV_HLS2RGB: case CV_HLS2BGR_FULL: case CV_HLS2RGB_FULL: + case COLOR_BGR5652GRAY: case COLOR_BGR5552GRAY: + case COLOR_GRAY2BGR565: case COLOR_GRAY2BGR555: + case COLOR_BGR2YCrCb: case COLOR_RGB2YCrCb: + case COLOR_BGR2XYZ: case COLOR_RGB2XYZ: + case COLOR_XYZ2BGR: case COLOR_XYZ2RGB: + case COLOR_BGR2HSV: case COLOR_RGB2HSV: case COLOR_BGR2HSV_FULL: case COLOR_RGB2HSV_FULL: + case COLOR_BGR2HLS: case COLOR_RGB2HLS: case COLOR_BGR2HLS_FULL: case COLOR_RGB2HLS_FULL: + case COLOR_HSV2BGR: case COLOR_HSV2RGB: case COLOR_HSV2BGR_FULL: case COLOR_HSV2RGB_FULL: + case COLOR_HLS2BGR: case COLOR_HLS2RGB: case COLOR_HLS2BGR_FULL: case COLOR_HLS2RGB_FULL: */ default: CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" ); diff --git a/modules/ocl/src/filtering.cpp b/modules/ocl/src/filtering.cpp index 064357e030..3430245022 100644 --- a/modules/ocl/src/filtering.cpp +++ b/modules/ocl/src/filtering.cpp @@ -544,21 +544,21 @@ void cv::ocl::morphologyEx(const oclMat &src, oclMat &dst, int op, const Mat &ke erode(src, temp, kernel, anchor, iterations, borderType, borderValue); dilate(temp, dst, kernel, anchor, iterations, borderType, borderValue); break; - case CV_MOP_CLOSE: + case MORPH_CLOSE: dilate(src, temp, kernel, anchor, iterations, borderType, borderValue); erode(temp, dst, kernel, anchor, iterations, borderType, borderValue); break; - case CV_MOP_GRADIENT: + case MORPH_GRADIENT: erode(src, temp, kernel, anchor, iterations, borderType, borderValue); dilate(src, dst, kernel, anchor, iterations, borderType, borderValue); subtract(dst, temp, dst); break; - case CV_MOP_TOPHAT: + case MORPH_TOPHAT: erode(src, dst, kernel, anchor, iterations, borderType, borderValue); dilate(dst, temp, kernel, anchor, iterations, borderType, borderValue); subtract(src, temp, dst); break; - case CV_MOP_BLACKHAT: + case MORPH_BLACKHAT: dilate(src, dst, kernel, anchor, iterations, borderType, borderValue); erode(dst, temp, kernel, anchor, iterations, borderType, borderValue); subtract(temp, src, dst); diff --git a/modules/ocl/src/haar.cpp b/modules/ocl/src/haar.cpp index 18ac8b0949..9e71315b68 100644 --- a/modules/ocl/src/haar.cpp +++ b/modules/ocl/src/haar.cpp @@ -906,7 +906,7 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS if( CV_MAT_CN(gimg.type()) > 1 ) { - cvtColor( gimg, gtemp, CV_BGR2GRAY ); + cvtColor( gimg, gtemp, COLOR_BGR2GRAY ); gimg = gtemp; } diff --git a/modules/ocl/src/hough.cpp b/modules/ocl/src/hough.cpp index 840f53d7de..c57603eef6 100644 --- a/modules/ocl/src/hough.cpp +++ b/modules/ocl/src/hough.cpp @@ -242,7 +242,7 @@ void cv::ocl::HoughCircles(const oclMat& src, oclMat& circles, HoughCirclesBuf& CV_Assert(src.type() == CV_8UC1); CV_Assert(src.cols < std::numeric_limits::max()); CV_Assert(src.rows < std::numeric_limits::max()); - CV_Assert(method == CV_HOUGH_GRADIENT); + CV_Assert(method == HOUGH_GRADIENT); CV_Assert(dp > 0); CV_Assert(minRadius > 0 && maxRadius > minRadius); CV_Assert(cannyThreshold > 0); diff --git a/modules/ocl/src/match_template.cpp b/modules/ocl/src/match_template.cpp index 77f7b1d637..362231fda9 100644 --- a/modules/ocl/src/match_template.cpp +++ b/modules/ocl/src/match_template.cpp @@ -125,7 +125,7 @@ namespace cv const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf & buf) { result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F); - if (useNaive(CV_TM_SQDIFF, image.depth(), templ.size())) + if (useNaive(TM_SQDIFF, image.depth(), templ.size())) { matchTemplateNaive_SQDIFF(image, templ, result, image.oclchannels()); return; @@ -255,7 +255,7 @@ namespace cv const oclMat &image, const oclMat &templ, oclMat &result, MatchTemplateBuf &buf) { result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F); - if (useNaive(CV_TM_CCORR, image.depth(), templ.size())) + if (useNaive(TM_CCORR, image.depth(), templ.size())) { matchTemplateNaive_CCORR(image, templ, result, image.oclchannels()); return; diff --git a/modules/ocl/src/moments.cpp b/modules/ocl/src/moments.cpp index 51cde6fd88..d209c2c224 100644 --- a/modules/ocl/src/moments.cpp +++ b/modules/ocl/src/moments.cpp @@ -44,7 +44,10 @@ // //M*/ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" #include + + namespace cv { namespace ocl diff --git a/modules/ocl/src/precomp.hpp b/modules/ocl/src/precomp.hpp index 98787df47d..76d15513af 100644 --- a/modules/ocl/src/precomp.hpp +++ b/modules/ocl/src/precomp.hpp @@ -62,8 +62,6 @@ #include #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/core/core_c.h" #include "opencv2/objdetect.hpp" #include "opencv2/ocl.hpp" diff --git a/modules/softcascade/src/integral_channel_builder.cpp b/modules/softcascade/src/integral_channel_builder.cpp index f804abe2bb..08f155e4c6 100644 --- a/modules/softcascade/src/integral_channel_builder.cpp +++ b/modules/softcascade/src/integral_channel_builder.cpp @@ -76,7 +76,7 @@ public: channels.create(h * N_CHANNELS, w, CV_8UC1); channels.setTo(0); - cvtColor(frame, gray, CV_BGR2GRAY); + cvtColor(frame, gray, cv::COLOR_BGR2GRAY); cv::Mat df_dx, df_dy, mag, angle; cv::Sobel(gray, df_dx, CV_32F, 1, 0); @@ -102,13 +102,13 @@ public: } cv::Mat luv, shrunk; - cv::cvtColor(frame, luv, CV_BGR2Luv); + cv::cvtColor(frame, luv, cv::COLOR_BGR2Luv); std::vector splited; for (int i = 0; i < 3; ++i) splited.push_back(channels(cv::Rect(0, h * (7 + i), w, h))); split(luv, splited); - cv::resize(channels, shrunk, cv::Size(integrals.cols - 1, integrals.rows - 1), -1 , -1, CV_INTER_AREA); + cv::resize(channels, shrunk, cv::Size(integrals.cols - 1, integrals.rows - 1), -1 , -1, cv::INTER_AREA); cv::integral(shrunk, integrals, cv::noArray(), CV_32S); } }; diff --git a/modules/softcascade/src/precomp.hpp b/modules/softcascade/src/precomp.hpp index 166440b46a..b4854f7927 100644 --- a/modules/softcascade/src/precomp.hpp +++ b/modules/softcascade/src/precomp.hpp @@ -45,8 +45,6 @@ #include "opencv2/softcascade.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/core/core_c.h" #include "opencv2/ml.hpp" #include "opencv2/core/private.hpp" diff --git a/modules/video/include/opencv2/video/tracking.hpp b/modules/video/include/opencv2/video/tracking.hpp index af3c423f50..f943bb7e52 100644 --- a/modules/video/include/opencv2/video/tracking.hpp +++ b/modules/video/include/opencv2/video/tracking.hpp @@ -48,7 +48,7 @@ # include "opencv2/imgproc.hpp" #endif -#include "opencv2/imgproc/imgproc_c.h" +#include "opencv2/imgproc/types_c.h" #ifdef __cplusplus extern "C" { diff --git a/modules/video/src/affineflow.cpp b/modules/video/src/affineflow.cpp index ad03744a66..bc3fdba2fc 100644 --- a/modules/video/src/affineflow.cpp +++ b/modules/video/src/affineflow.cpp @@ -41,6 +41,7 @@ //M*/ #include "precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" // to be moved to legacy diff --git a/modules/video/src/bgfg_gmg.cpp b/modules/video/src/bgfg_gmg.cpp index 04f90a8f21..20ddeba447 100644 --- a/modules/video/src/bgfg_gmg.cpp +++ b/modules/video/src/bgfg_gmg.cpp @@ -49,6 +49,7 @@ */ #include "precomp.hpp" +#include namespace cv { @@ -72,7 +73,7 @@ public: minVal_ = maxVal_ = 0; name_ = "BackgroundSubtractor.GMG"; } - + ~BackgroundSubtractorGMGImpl() { } diff --git a/modules/video/src/precomp.hpp b/modules/video/src/precomp.hpp index 389e2823da..fdbbb0ae1d 100644 --- a/modules/video/src/precomp.hpp +++ b/modules/video/src/precomp.hpp @@ -44,9 +44,8 @@ #define __OPENCV_PRECOMP_H__ #include "opencv2/video.hpp" -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/core/utility.hpp" +#include "opencv2/core/utility.hpp" #include "opencv2/core/private.hpp" #include diff --git a/modules/video/src/tvl1flow.cpp b/modules/video/src/tvl1flow.cpp index 07477bbe89..cdf42f91ef 100644 --- a/modules/video/src/tvl1flow.cpp +++ b/modules/video/src/tvl1flow.cpp @@ -73,6 +73,7 @@ */ #include "precomp.hpp" +#include using namespace cv; diff --git a/modules/video/test/test_accum.cpp b/modules/video/test/test_accum.cpp index b7c6b719ec..ef6c05f980 100644 --- a/modules/video/test/test_accum.cpp +++ b/modules/video/test/test_accum.cpp @@ -40,6 +40,7 @@ //M*/ #include "test_precomp.hpp" +#include "opencv2/imgproc/imgproc_c.h" using namespace cv; using namespace std; diff --git a/modules/video/test/test_precomp.hpp b/modules/video/test/test_precomp.hpp index 524ba80fcb..0aae1031f8 100644 --- a/modules/video/test/test_precomp.hpp +++ b/modules/video/test/test_precomp.hpp @@ -12,7 +12,6 @@ #include #include "opencv2/ts.hpp" #include "opencv2/imgproc.hpp" -#include "opencv2/imgproc/imgproc_c.h" #include "opencv2/video.hpp" #include "opencv2/highgui.hpp" diff --git a/samples/cpp/Qt_sample/main.cpp b/samples/cpp/Qt_sample/main.cpp index c884a330ac..c4a8c5fbf2 100644 --- a/samples/cpp/Qt_sample/main.cpp +++ b/samples/cpp/Qt_sample/main.cpp @@ -8,9 +8,10 @@ #include #include #include -#include +#include #include +#include #if defined WIN32 || defined _WIN32 || defined WINCE #include @@ -126,7 +127,7 @@ static void foundCorners(vector *srcImagePoints,IplImage* source, //MgrayImage = MgrayImage.clone();//deep copy vector > contours; vector hierarchy; - findContours(MgrayImage, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); + findContours(MgrayImage, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_NONE); Point p; vector srcImagePoints_temp(4,cvPoint2D32f(0,0));