jupyter notebook oepncv 显示一张图像的实现显示一张图像的实现
感想感想
我们在用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 中运行如下
评论0
最新资源