Merge two Mat images into one

前端 未结 3 1134
隐瞒了意图╮
隐瞒了意图╮ 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:46

    How about this:

    Mat newImage = image.clone();
    Mat image_temp1 = newImage(Rect(0, 0, image.cols, image.rows/2));
    Mat image_temp2 = newImage(Rect(0, image.rows/2, image.cols, image.rows/2));
    

    By not using clone() to create the temp images, you're implicitly modifying newImage when you modify the temp images without the need to merge them again. After changing image_temp1 and image_temp2, newImage will be exactly the same as if you had split, modified, and then merged the subimages.

提交回复
热议问题