QT&Opencv学习——OpenCV中图片复制clone和 copyTo的区别

OpenCV

OpenCV中图片复制clone和 copyTo的区别

clone()和copyTo()最大的区别在于clone()会给目标矩阵分配新地址,而copyTo()不会。

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include

using namespace cv;
using namespace std;
int main()
{
    float a[5]={1,1,1,1,1};
    float b[5]={0,0,0,0,0};
    Mat img1(1, 5, CV_32F,a);
    Mat img2 = img1;
    Mat img3(1, 5, CV_32F,b);
    //img3.copyTo(img1);
    img1 = img3.clone();
    cout << img1 << endl;
    cout << img2 << endl;
}

你可能感兴趣的:(OpenCV)