Select a subset of a Mat and copy them to create a new mat in C++/Opencv

前端 未结 1 1716
借酒劲吻你
借酒劲吻你 2021-01-22 20:48

In C++/opencv, how can I select a subset of a big Mat and copy them to create a new Mat? I know how to use copyto, colrange, rowrange, etc., but don\'t know to combine them toge

相关标签:
1条回答
  • 2021-01-22 21:31

    You can use copyTo() for this purpose:

    //copy a sub matrix of X to Y with starting coodinate (startX,startY)
    // and dimension (cols,rows)
    cv::Mat tmp = X(cv::Rect(startX,startY,cols,rows));
    cv::Mat Y;
    tmp.copyTo(Y);
    

    or directly:

    cv::Mat Y;
    X(cv::Rect(startX,startY,cols,rows)).copyTo(Y);
    
    0 讨论(0)
提交回复
热议问题