如何使用Jupyter Notebook和OpenCV库展示图像?

2026-05-27 03:441阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计332个文字,预计阅读时间需要2分钟。

如何使用Jupyter Notebook和OpenCV库展示图像?

在用Jupyter Notebook时,我们经常需要可视化一些东西,尤其是图像。以下是一个简单的示例代码,展示了如何使用opencv-python、matplotlib和numpy进行图像可视化:

pythonimport osimport numpy as npfrom matplotlib import pyplot as plt

示例代码

感想

我们在用jupyter notebook的时候,经常需要可视化一些东西,尤其是一些图像,我这里给个sample code

环境

opencv-python
matplotlib
numpy

sample

import os import numpy as np from matplotlib import pyplot as plt %matplotlib inline img_dir='/Users/eric/Documents/data/wheel_train_val/train/non_defect/' filename='00005.BMP_block_8.jpg' img = cv2.imread(img_dir +os.sep+ filename) plt.imshow(img) plt.show()

补充知识:jupyter notebook 调用摄像投运行程序

import cv2 ----前提是需要安装opencv 可以百度下如何安装即可

cap = cv2.VideoCapture(0) while(1): # get a frame ret,frame = cap.read() # show a frame cv2.imshow("capture", frame) if cv2.waitKey(1) & 0xFF == ord('q'): cv2.imwrite("./test.jpeg", frame) break cap.release() cv2.destroyAllWindows()

上述在jupyter notebook 中运行如下

以上这篇jupyter notebook oepncv 显示一张图像的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

如何使用Jupyter Notebook和OpenCV库展示图像?

本文共计332个文字,预计阅读时间需要2分钟。

如何使用Jupyter Notebook和OpenCV库展示图像?

在用Jupyter Notebook时,我们经常需要可视化一些东西,尤其是图像。以下是一个简单的示例代码,展示了如何使用opencv-python、matplotlib和numpy进行图像可视化:

pythonimport osimport numpy as npfrom matplotlib import pyplot as plt

示例代码

感想

我们在用jupyter notebook的时候,经常需要可视化一些东西,尤其是一些图像,我这里给个sample code

环境

opencv-python
matplotlib
numpy

sample

import os import numpy as np from matplotlib import pyplot as plt %matplotlib inline img_dir='/Users/eric/Documents/data/wheel_train_val/train/non_defect/' filename='00005.BMP_block_8.jpg' img = cv2.imread(img_dir +os.sep+ filename) plt.imshow(img) plt.show()

补充知识:jupyter notebook 调用摄像投运行程序

import cv2 ----前提是需要安装opencv 可以百度下如何安装即可

cap = cv2.VideoCapture(0) while(1): # get a frame ret,frame = cap.read() # show a frame cv2.imshow("capture", frame) if cv2.waitKey(1) & 0xFF == ord('q'): cv2.imwrite("./test.jpeg", frame) break cap.release() cv2.destroyAllWindows()

上述在jupyter notebook 中运行如下

以上这篇jupyter notebook oepncv 显示一张图像的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

如何使用Jupyter Notebook和OpenCV库展示图像?