Help Center/ ModelArts/ Troubleshooting/ DevEnviron/ Code Running Failures/ Notebook Instance Breaks Down When opencv.imshow Is Used
Updated on 2025-06-06 GMT+08:00

Notebook Instance Breaks Down When opencv.imshow Is Used

Symptom

When opencv.imshow is used in a notebook instance, the notebook instance breaks down.

Possible Causes

OpenCV's cv2.imshow malfunctions in such a client/server environment as Jupyter. However, Matplotlib does not have this problem.

Solution

Display images by referring to the following example. Note that OpenCV displays BGR images while Matplotlib displays RGB images.

Python:

1
2
3
4
5
6
from matplotlib import pyplot as plt
import cv2
img = cv2.imread('Image path')
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('my picture')
plt.show()