Opencv 的基础认识

 

 第一个应用

import cv2
img=cv2.imread('./Desktop/university/Python/img.jpg') #读取某路径下的图片
cv2.imshow('spring',img)   #输出文件名魏spring的图片
k=cv2.waitKey(0)           #等待按键
if k==27:                  #如果为  esc
    cv2.destroyAllWindows()   #关闭所有窗口
elif k==ord('s'):
    cv2.imwrite('c:/Users/86138/Desktop/university/Python/result.png',img) #保存为png
    cv2.destroyAllWindows()

 其中ret 为bool 值, 读取正确返回 true 否则为 false

frame 是一帧图像,是一个三维数组,三维分别是长,宽,通道数

代码尝试

import cv2
cap=cv2.VideoCapture(0)
while(True):
    ret,frame=cap.read()
    cv2.imshow(u"Capture",frame)
    key=cv2.waitKey(1)
    if key&0xff==ord('q') or key==27:
        print(frame.shape,ret)
        break
cap.release()
cv2.destroyAllWindows()
原文地址:https://www.cnblogs.com/fengzhiyuan/p/14725556.html