【发布时间】:2022-01-06 08:44:57
【问题描述】:
我有这部分代码在 C++ 中工作
Mat mapFrame5(Size(321,262), CV_16UC2);
for (int y = 0; y < mapFrame5.rows; y++) {
for (int x = 0; x < mapFrame5.cols; x++) {
mapFrame5.at<Vec2w>(y, x) = Vec2w(y, x);
cout<<mapFrame5.at<Vec2w>(y,x);
}
}
我很难找到 Python 中是否存在与此表达式等效的内容:
mapFrame5.at<Vec2w>(y, x) = Vec2w(y, x);
我按照建议尝试了以下操作:
testArr2 = np.zeros([262,321], np.uint16)
y,yy = 0,0
byteCount = 0
while yy < 262:
x,xx = 0,0
while xx < 321:
testArr2[yy,xx] = [yy,xx]
xx+=1
x+=1
byteCount+=1
yy+=1
y+=1
但它只给了我这个错误:
builtins.TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
为了清楚起见,我正在尝试将 y,x 值保存到小端二进制文件中。
例子:
y = 0
0 0 0 1 0 2 0 3 ... 0 320
y = 261
261 0 261 1 261 2 ... 261 320
C++ 文件正好给了我 336408 字节
【问题讨论】:
-
如果你能用简单的语言解释你想用你的表达方式为非 C++ 读者实现什么,这可能会有所帮助......
-
opencv
Mat在 python 中只是 numpy 数组。你的代码在 python 中可以是mapFrame5[y,x] = [y,x]。 -
@QuangHoang 已编辑帖子,我无法让您的解决方案发挥作用
-
您需要将阵列设为 2 通道 -
np.zeros([262,321,2], np.uint16)。
标签: python c++ numpy opencv opencv-python