将两个Mat图像合并为一个 [英] Merge two Mat images into one
问题描述
我有问题。我有一张图片。然后,我必须将图像分成两个相等的部分。我这样做是这样的(代码已编译,一切都很好):
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 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();
然后我必须独立更改每个部分,最后合并为一个。我不知道如何正确地做到这一点。如何将图像的这两个部分合并为一个图像?
示例: http ://i.stack.imgur.com/CLDK7.jpg
Then I have to change each part independently and finally to merge into one. I have no idea how to make this correctly. How I should merge this 2 parts of image into one image?
Example: http://i.stack.imgur.com/CLDK7.jpg
推荐答案
有几种方法可以做到这一点,但我发现的最好方法是使用 cv :: hconcat(mat1,mat2,dst)
进行水平合并或 cv :: vconcat(mat1 ,mat2,dst)
(垂直)。
There is several way to do this, but the best way I found is to use cv::hconcat(mat1, mat2, dst)
for horizontal merge orcv::vconcat(mat1, mat2, dst)
for vertical.
别忘了照顾空矩阵合并的情况!
Don't forget to take care of empty matrix merge case !
这篇关于将两个Mat图像合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!