Ala*_*rit 22 opencv matplotlib show imshow google-colaboratory
我正在开发一个需要 OpenCV 函数来绘制图像的项目。我正在尝试在 Google Colab 中使用以下代码显示图像。但输出中没有显示任何内容。有人可以帮我解决这个问题吗?
%pylab notebook
import cv2
testim = imread('butterfly.jpg')
figure()
imshow(testim)
plt.show()
Run Code Online (Sandbox Code Playgroud)
截屏:
小智 43
如果您尝试使用cv2.imshow()而不是导入from google.colab.patches import cv2_imshow和显示来显示图像,Google colab 会崩溃cv2_imshow(<image>)
The cv2.imshow() and cv.imshow() functions from the opencv-python package are incompatible with Jupyter notebook; see https://github.com/jupyter/notebook/issues/3935.
As a replacement, you can use the following function:
from google.colab.patches import cv2_imshow
Run Code Online (Sandbox Code Playgroud)
For example, here we download and display a PNG image of the Colab logo:
!curl -o logo.png https://colab.research.google.com/img/colab_favicon_256px.png
import cv2
img = cv2.imread('logo.png', cv2.IMREAD_UNCHANGED)
cv2_imshow(img)
Run Code Online (Sandbox Code Playgroud)
Credits: Code Snippets in Google Colab
| 归档时间: |
|
| 查看次数: |
71415 次 |
| 最近记录: |