[英]python and combining a multidimensional list (opencv)
我对 python/opencv 有点陌生,我有点困惑。 我想我的问题与 opencv 无关,只是 python。 所以我会在没有 opencv 的东西的情况下解释它:我有一个 3-dim 列表:
for contour in contours:
contour = cv2.approxPolyDP(contour,10,True)
print "--------------------------"
print contour
print "--------------------------"
我明白了:
--------------------------
[[[168 377]]
[[250 404]]]
--------------------------
--------------------------
[[[332 153]]
[[419 216]]]
--------------------------
但是,我真正想要的是:
--------------------------
[[[168 377]]
[[250 404]]
[[332 153]]
[[419 216]]]
--------------------------
当我通过 oy own 构建列表时,它也可以正常工作,它应该是:
>>> np.array([[[168,377],[250,404],[332,153],[419,216]]])
array([[[168, 377],
[250, 404],
[332, 153],
[419, 216]]])
我知道...尺寸不一样。 我不知道为什么 opencv 可以处理这个!? (这些是cv2.findContours
轮廓有人知道如何重新排列这个列表吗?或者一个有用的文档。谢谢和问候 :)
res = []
for contour in contours:
contour = cv2.approxPolyDP(contour,10,True)
print "--------------------------"
print contour
print "--------------------------"
res.append(contour)
print np.vstack(res)
for i in range(2):
tempcnts = cv2.findContours(gray, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
tempcnts = imutils.grab_contours(tempcnts)
# tempcnts = cv2.approxPolyDP(tempcnts, 10, True)
print("--------------------------")
print(tempcnts)
print("--------------------------")
if i==0:
cnts=tempcnts
else:
cnts[0]=np.append(cnts[0], tempcnts[0],0)
print("--------------------------")
print("--------------------------")
print("--------------------------")
print(cnts)
print("--------------------------")
print("--------------------------")
print("--------------------------")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.