opencv视频捕获

相关案例:@Fu Xianjun. All Rights Reserved.

 

读取摄像头

opencv视频捕获_第1张图片

A.数据读取-图像

cv2.IMREAD_COLOR:彩色图像
cv2.IMREAD_GRAYSCALE:灰度图像

import cv2 
import matplotlib.pyplot as plt
import numpy as np 
%matplotlib inline 

img=cv2.imread('cat.jpg')(#注意opencv读取的格式是BGR)
import cv2
import numpy as np
sxt = cv2.VideoCapture(0)#视频捕获
while(sxt.isOpened()):#
    ret, frame = sxt.read()#
    
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    #设定绿色的阈值
    lower_green = np.array([26,43,46])
    upper_green = np.array([26,43,46])
    #根据阈值构建掩膜
    mask = cv2.inRange(hsv,lower_green,upper_green)
    #对原图图像和掩膜进行运算
    Green = cv2.bitwise_and(frame, frame, mask=mask)
    
    cv2.imshow("frame",frame)#窗口化
    if cv2.waitKey(1)==ord("q"):
        break
sxt.release()#释放
cv2.destroyAllWindows()

视频处理示例

import cv2
import numpy as np
sxt = cv2.VideoCapture(0)#视频捕获
while(sxt.isOpened()):#
    ret, frame = sxt.read()#
    
    h,w,c = frame.shape
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    ret, binary = cv2.threshold(frame, 50,255,0)
    canny = cv2.Canny(binary,50,100)
    
    cv2.imshow("binary",binary)#窗口化
    if cv2.w

你可能感兴趣的:(opencv,python,图像识别)