• Hi,

    I am trying to find the equivalent of the copy(x,y,width,height) method in the QImage class for cv::Mat in OpenCV. Looking at the header qimage.h
    I see that the copy method is a wrapper over

        QImage copy(const QRect &rect = QRect()) const;
        inline QImage copy(int x, int y, int w, int h) const
            { return copy(QRect(x, y, w, h)); }

    which is wrapper over QRect. Using cv::Mat in OpenCV (http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html) would the equivalent be
    convertTo, copyTo or simply there is no equivalent and I have to write the equivalent?


  • Lifetime Qt Champion


    It's not a wrapper over QRect, it calls the copy method that takes a QRect as parameter. It's more or less the equivaled of the copyTo method that takes two parameters but in the case case of QImage, it copies all channels in the QImage object that is returned by that function.

  • Qt Champions 2016

    You can copy section using ctor

    int x = 10,
    y = 20,
    width = 200,
    height = 200;

    Mat img1, img2;
    img1 = imread("Lenna.png");
    img2 = img1(Rect(x, y, width, height));

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.