博客
关于我
opencv grabcut
阅读量:76 次
发布时间:2019-02-26

本文共 850 字,大约阅读时间需要 2 分钟。

 

#!/usr/bin/env python# -*- coding: utf-8 -*-import numpy as npimport cv2frame=cv2.imread(r0.jpg")# setup initial location of windowwhile 1:    frame = cv2.imread(r"0.jpg")    roi = cv2.selectROI(windowName="roi", img=frame, showCrosshair=True, fromCenter=False)    x, y, w, h = roi    print(w,h)    img = frame[y:y + h, x:x + w]    cv2.imshow('a', img)    height, width = img.shape[:2]    mask = np.zeros(img.shape[:2],np.uint8)    # 背景模型    bgdModel = np.zeros((1,65),np.float64)    # 前景模型    fgdModel = np.zeros((1,65),np.float64)    rect = (w//20, h//20, width -w//10, height -  h//10)    # 使用grabCut算法    cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)    mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')    img = img*mask2[:,:,np.newaxis]    cv2.imshow('image', img)    k = cv2.waitKey(0)    cv2.destroyAllWindows()

 

转载地址:http://hmik.baihongyu.com/

你可能感兴趣的文章
MYSQL数据库简单的状态检查(show status)
查看>>
MYSQL数据库自动本地/异地双备份/MYSQL增量备份
查看>>
mysql数据库表增添字段,删除字段、修改字段的排列等操作,还不快来
查看>>
MYSQL数据库进阶操作
查看>>
MySQL数据库面试题(2021最新版)
查看>>
MySQL数据库高并发优化配置
查看>>
mysql数据恢复
查看>>
MySQL数据的主从复制、半同步复制和主主复制详解
查看>>
mysql数据碎片整理
查看>>
MySQL数据类型
查看>>
MySQL数据类型字节长度
查看>>
mysql数据被误删的恢复方案
查看>>
MySQL数据读写分离(MaxScale)上干货!!!
查看>>
mysql整库导入、导出
查看>>
mysql文本函数和数字函数
查看>>
Mysql新建用户和数据库并授权
查看>>
mysql日志文件
查看>>
mysql日志管理学习笔记
查看>>
MySQL日期时间函数大全
查看>>
mysql时间相减的问题
查看>>