博客
关于我
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/

你可能感兴趣的文章
netty底层——nio知识点 ByteBuffer+Channel+Selector
查看>>
netty底层源码探究:启动流程;EventLoop中的selector、线程、任务队列;监听处理accept、read事件流程;
查看>>
Netty心跳检测
查看>>
Netty心跳检测机制
查看>>
netty既做服务端又做客户端_网易新闻客户端广告怎么做
查看>>
Netty核心模块组件
查看>>
Netty框架内的宝藏:ByteBuf
查看>>
Netty框架的服务端开发中创建EventLoopGroup对象时线程数量源码解析
查看>>
Netty源码—1.服务端启动流程一
查看>>
Netty源码—1.服务端启动流程二
查看>>
Netty源码—2.Reactor线程模型一
查看>>
Netty源码—2.Reactor线程模型二
查看>>
Netty源码—3.Reactor线程模型三
查看>>
Netty源码—3.Reactor线程模型四
查看>>
Netty源码—4.客户端接入流程一
查看>>
Netty源码—4.客户端接入流程二
查看>>
Netty源码—5.Pipeline和Handler一
查看>>
Netty源码—5.Pipeline和Handler二
查看>>
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>