jupyter notebook oepncv 显示一张图像的实现

来自:互联网
时间:2020-05-26
阅读:

感想

我们在用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 oepncv 显示一张图像的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

返回顶部
顶部