Python OpenCV学习笔记之:使用Grabcut算法进行图像背景和前景分割
生活随笔
收集整理的這篇文章主要介紹了
Python OpenCV学习笔记之:使用Grabcut算法进行图像背景和前景分割
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
# -*- coding: utf-8 -*- """ 圖像分割 """import numpy as np import cv2 from matplotlib import pyplot as pltimg = cv2.imread('../../../datas/images/building.jpg') mask = np.zeros(img.shape[:2],np.uint8) # 背景模型 bgdModel = np.zeros((1,65),np.float64) # 前景模型 fgdModel = np.zeros((1,65),np.float64)rect = (50,50,450,290) # 使用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]plt.imshow(img),plt.colorbar(),plt.show()轉(zhuǎn)載于:https://my.oschina.net/wujux/blog/801387
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的Python OpenCV学习笔记之:使用Grabcut算法进行图像背景和前景分割的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pyCharm 当中使用VirtualE
- 下一篇: LeetCode 题解汇总