Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x np的不同结果类型,其中x,y在两种条件下互换。我错过了什么?_Python 3.x_Opencv_Opencv Python - Fatal编程技术网

Python 3.x np的不同结果类型,其中x,y在两种条件下互换。我错过了什么?

Python 3.x np的不同结果类型,其中x,y在两种条件下互换。我错过了什么?,python-3.x,opencv,opencv-python,Python 3.x,Opencv,Opencv Python,我正在尝试初始化两个数组image和a 在图像中,我用颜色值255填充轮廓 在轮廓cnt中,其顺序为x,y 在一个数组中,我为[2][0]赋值1,其中2是x轴点,0是y轴点 但在结果中,我得到了图像在y数组,x数组中的顺序,但在a中,它是x数组,y数组 我在哪里犯错误 import cv2 import numpy as np image = np.zeros((700,700),dtype=np.int32) cnt = np.array([[340, 157], [695, 157], [6

我正在尝试初始化两个数组image和a

在图像中,我用颜色值255填充轮廓 在轮廓cnt中,其顺序为x,y

在一个数组中,我为[2][0]赋值1,其中2是x轴点,0是y轴点

但在结果中,我得到了图像在y数组,x数组中的顺序,但在a中,它是x数组,y数组

我在哪里犯错误

import cv2
import numpy as np
image = np.zeros((700,700),dtype=np.int32)
cnt = np.array([[340, 157], [695, 157], [695, 309], [340, 309], [340, 157]])

image = cv2.fillPoly(image,[cnt],color=255)

a = np.zeros((10,10),dtype=np.int32)
a [2][0] = 1

print(np.where(a>0)) #output_1
print(np.where(image>0)) #output_2
输出\u 1: (数组([2]),数组([0]))

输出_2
(数组([157,157,…,309,309,309,309]),数组([340,341,342,…,693,694,695])。

代码没有错误。我已经使用numpy切片重写了它,以填充数组的部分

import cv2
import numpy as np
image = np.zeros((700,700),dtype=np.int32)
print(image.shape)
# cnt = np.array([[340, 157], [695, 157], [695, 309], [340, 309], [340, 157]])
image[157:309, 340:695] = 255

# image = cv2.fillPoly(image,[cnt],color=255)
print(image.shape)

a = np.zeros((10,10),dtype=np.int32)
a [2, 0:5] = 1

print(np.where(a>0)) #output_1
print(np.where(image==255)) #output_2
如果你看这个,
image[157:309,340:695]=255
沿x轴的切片由列描述,y轴的切片由行描述。
代码的cnt部分描述了157-309之间的行范围和340-695之间的列范围,这就是输出的原因。

我得到了它,谢谢。x是列,y是行。所以在输出中它是(行,列)i,e(y数组,x数组)。通过cnt是多边形([x,y]点),我不认为它可以通过切片填充。
(array([2], dtype=int64), array([0], dtype=int64))
(array([157, 157, 157, ..., 308, 308, 308], dtype=int64), array([340, 341, 342, ..., 692, 693, 694], dtype=int64))