怎么能ı;在openCV python中显示数组

怎么能ı;在openCV python中显示数组,python,opencv,Python,Opencv,您可以使用PILL中的Image,如下所示 cv2.error: OpenCV(4.4.0) C:/Users/appveyor/AppData/Local/Temp/1/pip-req-build-zsozjuva/opencv/modules/highgui/src/precomp.hpp:137: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'co

您可以使用
PILL
中的
Image
,如下所示

cv2.error: OpenCV(4.4.0) C:/Users/appveyor/AppData/Local/Temp/1/pip-req-build-zsozjuva/opencv/modules/highgui/src/precomp.hpp:137: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'
导入cv2
将numpy作为np导入
从PIL导入图像
大列表=[]
很棒的列表=[]
n=28
对于范围(n)中的i:
大列表。追加([255255])
对于范围(28)内的i:
大列表。追加(大列表)
数组=np.数组(大列表)
h、 w,c=array.shape
array1=np.数组(大列表)
h、 w,c=array.shape
array2=np.array(大列表)
h、 w,c=array.shape
b=0
对于范围(h)内的i:
对于范围(w)内的j:
对于范围(c)中的k:
数组[i,j,k]=255-5*b
b+=1
对于范围(c)中的k:
对于范围(h)内的i:
对于范围(w)内的j:
如果阵列1[i,j,k]200:
阵列2[i,j,k]=255
img=Image.fromarray(数组'RGB')
img.show()
img=Image.fromarray(array1,'RGB')
img.show()
img=Image.fromarray(array2,'RGB')
img.show()

在显示图像之前,在PIL中使用fromarray创建图像。 例如:


感谢您

因为OpenCV中的循环是一件非常低效的事情。尽可能避免它

绘制
np.array
最简单的方法是使用
matplotlib

我不明白你们想用for循环做什么,但这里有一个方法来描绘

image = Image.fromarray(array, 'RGB')
image .show()
要更改您拥有的第一个阵列的颜色,可以使用此逻辑,这将更加有效:

img1 = np.zeros((row, col, dim), dtype=np.uint8)
img2 = 255*np.ones((row, col, dim), dtype=np.uint8)
img3 = 255*np.eye((row, col, dim), dtype=np.uint8)

import matplotlib.pyplot as plt

plt.subplot(311)
plt.imshow(img1)
plt.subplot(312)
plt.imshow(img2)
plt.subplot(313)
plt.imshow(img3)
plt.show()

我想剩下的你可以做。

回答你的问题了吗?我也能帮忙。查看它们我已经看到了这一点,但不明白在哪里编写代码,用于循环中更改元素array@izmirlikezzap有什么能帮你解决问题吗
image = Image.fromarray(array, 'RGB')
image .show()
img1 = np.zeros((row, col, dim), dtype=np.uint8)
img2 = 255*np.ones((row, col, dim), dtype=np.uint8)
img3 = 255*np.eye((row, col, dim), dtype=np.uint8)

import matplotlib.pyplot as plt

plt.subplot(311)
plt.imshow(img1)
plt.subplot(312)
plt.imshow(img2)
plt.subplot(313)
plt.imshow(img3)
plt.show()
array = np.zeros((row, col, dim), dtype=np.uint8)
for i in range(h):
    array[i,:,:]=255-5*i