气泡识别三,在一基础上输出包括是否有气泡

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值