参考文档# https://blog.csdn.net/weixin_38383877/article/details/82659779# https://www.cnblogs.com/arkenstone/p/8560846.html# https://www.cnblogs.com/little-monkey/p/7637130.html
实际程序,就是图形转为灰度图
This is a sample Python script.
Press Shift+F10 to execute it or replace it with your code.
Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
https://blog.csdn.net/weixin_38383877/article/details/82659779
https://www.cnblogs.com/arkenstone/p/8560846.html
https://www.cnblogs.com/little-monkey/p/7637130.html
import cv2
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f’Hi, {name}’) # Press Ctrl+F8 to toggle the breakpoint.
Press the green button in the gutter to run the script.
if name == ‘main’:
print(‘opencv’)
‘’’
img = cv2.imread(‘image9.jpg’,2)
print(img.shape)
cv2.imshow(‘imshow’,img)
cv2.waitKey(0)
cv2.destroyAllWindows()
‘’’
top,bottom,left,right=(200,200,50,50)
vc = cv2.VideoCapture(‘video.mp4’)
fgbg = cv2.createBackgroundSubtractorMOG2()
if vc.isOpened():
open , frame = vc.read()
print(frame.shape)
else:
open=False
while open:
open,frame=vc.read()
if frame is None:
break
if open is True:
#img = frame[0:200,0:200]
#b,g,r = cv2.split(frame)
img=frame[400:450,
00:600]
#img = cv2.resize(img,(100,800))
img = cv2.copyMakeBorder(img,top,bottom,left,right,borderType=cv2.BORDER_CONSTANT)
cur_img=img.copy()
cur_img[:,:,2]=0
gray = cv2.cvtColor(cur_img,cv2.COLOR_BGR2GRAY)
ret, dest = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY)
cv2.imshow('result',dest)
fgmask = fgbg.apply(dest)
cnts, aa = cv2.findContours(fgmask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
if len(cnts)>0 :
print('有气泡'+str(len(cnts)))
cv2.waitKey(20)
vc.release()
#img.shape