Sj0*_*3rd 1 python opencv image
我使用下面的代码绘制了预测错误的图片。当显示图片时,我看到图片的格式似乎是 BGR。
我找到了对单张图片执行此操作但不适用于图片列表的方法 有没有办法在这段代码中将颜色更改为 RGB?
这是我用来绘制图像的代码:
plt.figure(figsize=(15,10))
for i in range(10):
err_index = errors[errors['error']==1].index[i]
plt.subplot(2,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(X_test[err_index].reshape(224,224,3))
plt.xlabel("ture is {}, predicted as {}".format(np.argmax(y_test[err_index]), y_pred[err_index]))
Run Code Online (Sandbox Code Playgroud)
编辑 - 抱歉粘贴了错误的代码。我尝试添加一行 cv2.COLOR_BGR2RGB 但这不起作用。这一切真的很新鲜。
我很确定这个问题已经被问过并回答过好几次了,但实际上我把它放在这里比搜索要快:因为你使用的是 numpy,所以:
img_rgb = img_bgr[:, :, ::-1]
Run Code Online (Sandbox Code Playgroud)
另外,考虑到您获得的是 BGR 格式,您可能正在使用 OpenCV,所以也是这样:
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
Run Code Online (Sandbox Code Playgroud)
看这里。
| 归档时间: |
|
| 查看次数: |
3977 次 |
| 最近记录: |