博客
关于我
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工作笔记0057---Netty群聊系统服务端
查看>>
Netty工作笔记0058---Netty群聊系统客户端
查看>>
Netty工作笔记0059---Netty私聊实现思路
查看>>
Netty工作笔记0060---Netty心跳机制实例
查看>>
Netty工作笔记0060---Tcp长连接和短连接_Http长连接和短连接_UDP长连接和短连接
查看>>
Netty工作笔记0061---Netty心跳处理器编写
查看>>
Netty工作笔记0062---WebSocket长连接开发
查看>>
Netty工作笔记0063---WebSocket长连接开发2
查看>>
vue样式穿透 ::v-deep的具体使用
查看>>
Netty工作笔记0065---WebSocket长连接开发4
查看>>
Netty工作笔记0066---Netty核心模块内容梳理
查看>>
Vue基本使用---vue工作笔记0002
查看>>
Netty工作笔记0068---Protobuf机制简述
查看>>
Netty工作笔记0069---Protobuf使用案例
查看>>
Netty工作笔记0070---Protobuf使用案例Codec使用
查看>>
Netty工作笔记0071---Protobuf传输多种类型
查看>>
Netty工作笔记0072---Protobuf内容小结
查看>>
Netty工作笔记0073---Neety的出站和入站机制
查看>>
Netty工作笔记0074---handler链调用机制实例1
查看>>
Netty工作笔记0075---handler链调用机制实例1
查看>>