尝试在OpenCV中进行单应矩阵的向前变形。你不必知道这是什么意思来理解这个问题。使用像素数组设置opencv图像/ numpy数组值
假设有2个图像(图像是像素值的2D numpy的阵列)中,A和B,并且看起来像
[[ 6.96122642e+01 -1.06556338e+03 1.02251944e+00]
[ 6.92265938e+01 -1.06334423e+03 1.02246589e+00]
[ 6.88409234e+01 -1.06112508e+03 1.02241234e+00]
... ]
第一列是X,第二Y-阵列match
,和第三是标量。这些XY值图像的像素指标和对应imageB指标
[[0,0],
[0,1],
[0,2]
... ]
我想用这个信息来快速从imageA设置imageB值。我有这个工作,但它是没有那么快,因为我想
yAs = np.int32(np.round(match[:, 0]/match[:, 2])
xAs = np.int32(np.round(match[:, 1]/match[:, 2])
it = np.nditer(pixelsImageB[0], flags=['f_index'])
while not it.finished:
i = it.index
xA = xAs[i]
yA = yAs[i]
if in_bounds(xA, yA, imageA):
yB = pixB[0][i]
xB = pixB[1][i]
imageB[xB,yB] = imageA[xA,yA]
it.iternext()
但我不知道如何与NumPy使这个快速,天真地做这个循环是很慢的。在高级索引,广播等方面,我是一个彻底的磨合。有任何想法吗?
'x'和'y'看起来像第一个候选人移出循环。例如'x = np.int32(np.round(match [:,0]/match [:,2]))' –
什么是'in_bounds'? – Divakar
x或y> 0且<宽度,高度。你会如何使用这些x,y阵列丹? –