相关案例:@Fu Xianjun. All Rights Reserved.
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