python如何对两个矩阵进行拼接_如何在Python OpenCV中连接两个矩阵?

1586010002-jmsa.png

How do I concatenate two matrices into one matrix? The resulting matrix should have the same height as the two input matrices, and its width will equal the sum of the width of the two input matrices.

I am looking for a pre-existing method that will perform the equivalent of this code:

def concatenate(mat0, mat1):

# Assume that mat0 and mat1 have the same height

res = cv.CreateMat(mat0.height, mat0.width + mat1.width, mat0.type)

for x in xrange(res.height):

for y in xrange(mat0.width):

cv.Set2D(res, x, y, mat0[x, y])

for y in xrange(mat1.width):

cv.Set2D(res, x, y + mat0.width, mat1[x, y])

return res

解决方案

If you are using cv2, (you will get Numpy support then), you can use Numpy function np.hstack((img1,img2)) to do this.

eg :

import cv2

import numpy as np

# Load two images of same size

img1 = cv2.imread('img1.jpg')

img2 = cv2.imread('img2.jpg')

both = np.hstack((img1,img2))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值