下载配置anaconda
配置环境变量
将下列路径添加到path中
D:\anaconda\Library\bin
D:\anaconda\Scripts
D:\anaconda
安装opencv包
在anaconda的anaconda prompt中输入anaconda路径 再在Scripts中输入pip install opencv-python和opencv-contrib-python 因为在3.2版本之后包内的某些算法申请了专利,以此3.1及之前的版本都比较丰富 我们使用opencv包的时候需要数据分析的相关包在prompt中输入 pip install numpy pip install matplotlib pip install pandas
opencv之图像基本操作
import numpy as np
import cv2
import matplotlib.pyplot as plt
image=cv2.imread('zan.png')
print(image.shape)
def cv_show(name,img):
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destoryAllWindows()
img=cv2.imread('cat.jpg',cv2.IMREAD_GRAYSCALE)
cv_show(image,img)
print(img)
print(img.shape)
print(img.size)
print(img.dtype)
cv2.imwrite('mycat.jpg',img)
##opencv之视频读取与处理
vc=cv2.VideoCapture('video1.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(10)&0xFF==27:
break
vc.release()
cv2.destoryAllWindows()
|