基于python的opencv学习笔记(一)
环境介绍
- pycharm开发工具
- 配置opencv库
- python是3.8版本
图像相关操作
1.导入图片并显示
import cv2
import matplotlib.pyplot as plt
import numpy as np
img = cv2.imread('2.jpg', cv2.IMREAD_GRAYSCALE)
cv2.imshow("Output", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("myboy.png",img)
**注意:想要成功显示代码,需要将想展示的图片,存储到这个项目文件夹目录下,非常重要!!!如下: ** 2.视频读取显示
vc = cv2.VideoCapture('fu.mp4')
if vc.isOpened():
open, frame = vc.read()
else:
open = False
while open:
ret, frame = vc.read()
if frame is None:
break
if ret == True:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('result',gray)
if cv2.waitKey(1) & 0xFF == 27:
break
vc.release()
cv2.destroyAllWindows()
当然,视频也要放在此项目下~
|