Merge two Mat images into one

前端 未结 3 1151
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 23:15

I have a problem. I have an image. Then I have to split the image into two equal parts. I made this like that (the code is compiled, everything is good):

Mat         


        
3条回答
  •  滥情空心
    2020-12-31 23:29

    Seems that cv::Mat::push_back is exactly what are you looking for:

    C++: void Mat::push_back(const Mat& m) : Adds elements to the bottom of the matrix.

    Parameters:    
        m – Added line(s).
    

    The methods add one or more elements to the bottom of the matrix. When elem is Mat , its type and the number of columns must be the same as in the container matrix.

    Optionally, you could create new cv::Mat of proper size and place image parts directly into it:

    Mat image_temp1 = image(Rect(0, 0, image.cols, image.rows/2)).clone();
    Mat image_temp2 = image(Rect(0, image.rows/2, image.cols, image.rows/2)).clone();
    ...
    cv::Mat result(image.rows, image.cols);
    image_temp1.copyTo(result(Rect(0, 0, image.cols, image.rows/2)));
    image_temp2.copyTo(result(Rect(0, image.rows/2, image.cols, image.rows/2));
    

提交回复
热议问题