python - 将来自不同函数 python3 opencv 的几个读数附加到 txt 文件
问题描述
我的代码出现错误。基本上,我有一些函数叫做 Triangulate
triangulate = cv2.triangulatePoints(projection_matrix_1,projection_matrix_2,projection_points1,projection_points_2)
该函数给了我一些这样的输出
[[ X1 X2 X3 ... Xn]
[ Y1 Y2 Y3 ... Yn]
[ Z1 Z2 Z3 ... Zn]
[ W1 W2 W3 ... Wn]]
我还有另一个功能可以从某些相机帧中检测描述符。
kps, desc = self.detector.detectAndCompute(self.image, None)
desc的输出是这样的
here [[ 97 93 2 ..., 255 63 1]
[ 64 141 1 ..., 123 255 62]
[ 97 29 14 ..., 253 127 3]
...,
[218 233 131 ..., 253 255 15]
[ 1 237 143 ..., 127 255 15]
[ 97 253 13 ..., 176 255 3]]
here [[ 64 141 0 ..., 123 255 31]
[ 97 29 78 ..., 253 127 1]
[ 0 13 0 ..., 123 255 30]
...,
[ 97 253 15 ..., 255 255 3]
[ 64 141 1 ..., 2 16 48]
[ 1 237 143 ..., 255 102 15]]
每当有新读数出现时,这两个函数的输出都会发生变化。读数来自机器人运动。它记录在rosbag中。
现在我想写一个txt文件。
X1 Y1 Z1 W1 desc1 X2 Y2 Z2 W2 desc2 ... Xn Yn Zn Wn descn
其中 xyzw 是 triangulate 的第一次读取的输出,而 desc1 是 desc 函数的第一次读取的输出 .. 等直到它完成。
我能够读取 triangulate 的读数并添加它,而这段代码没有任何问题
f = open("11.txt", "w") # Erases the file content.
f.close()
这里存在两个功能
f = open("11.txt", "a")
f.write(','.join(str(v) for v in self.tringulate.T.flat) + '\n')
f.close()
我能够保存 X1 Y1 Z1 W1 X2 Y2 Z2 W2 但没有 desc1 ... desc2 ...等
请问有什么建议吗?
解决方案
推荐阅读
- javascript - window.open with _blank 在 Firefox 中打开两个标签页
- javascript - 如果参数是另一个函数的返回值,该函数将不起作用
- linux - 使用 grep 精确匹配单词
- r - 将数据框列名更改为小写时使用 set_names 与 mutate(colnames)
- android - DataSnapShot 对象的值返回 0 而不是实际值
- azure - Azure 容器注册表 - 删除除 2 之外的所有映像
- python-3.x - 使用元组对实例的“装饰”列表进行排序 - Zelle Ex。11.9
- ubuntu - Unable to Run Amethyst Starter Template: 'VkError(ERROR_INCOMPATIBLE_DRIVER)'
- macos - SceneKit 在 macOS Catalyst 应用程序中是否可以继续工作?
- android - android design library 28.0.0 causes app to crash