简体   繁体   English

如何打印/返回多维数组中的值?

[英]How can I print/return values in multi-dimensional arrays?

Hi I have been working on opencv-python with opencv 3.0.0 and python 2.7.x 嗨,我一直在使用opencv 3.0.0和python 2.7.x开发opencv-python

import numpy as np
import cv2

img = cv2.imread('C:\\Users\\J\\Desktop\\image.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

corners = cv2.goodFeaturesToTrack(gray,25,0.01,10)

print corners

this is returning me 这回来了我

[[[ 335.  263.]]

 [[ 306.  254.]]

 [[ 337.  253.]]

 [[ 349.  262.]]

 [[ 507.  361.]]

 [[ 300.  264.]]

 [[ 420.  250.]]

 [[ 362.  252.]]

 [[ 375.  261.]]

 [[ 322.  254.]]

 [[ 409.  260.]]

 [[ 545.  294.]]

 [[ 505.  398.]]

 [[ 388.  252.]]

 [[ 493.  315.]]

 [[ 578.  376.]]

 [[ 480.  376.]]

 [[ 510.  375.]]

 [[ 396.  261.]]

 [[ 493.  376.]]

 [[ 532.  376.]]

 [[ 575.  357.]]

 [[ 540.  360.]]

 [[ 514.  307.]]

 [[ 401.  251.]]]

I know this is a multi-dimensional array and how can I print the values in this array in the form of (x,y) ? 我知道这是一个多维数组,我如何以(x,y)的形式打印此数组中的值? I think there is a simple answer for this but it has been quite a long time I have used python. 我认为对此有一个简单的答案,但是使用python已经很长时间了。 Thanks in advance ! 提前致谢 !

import numpy as np
import cv2
img = cv2.imread('C:\\Users\\J\\Desktop\\image.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
corners = cv2.goodFeaturesToTrack(gray,25,0.01,10)

corners = np.int0(corners)
for corner in corners:
    x,y = corner.ravel()
    print(x,y)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM