Bootstrap

Python_Opencv8_ROI与泛洪处理

import cv2 as cv
import numpy as np

def fill_color_demo(image):#彩色图像填充。泛洪算法 1.基于扫描的2.基于递归的 一般而言基于扫描的速度快
    copying=image.copy()                                      #复制一张图片
    h,w=image.shape[:2]                                       #取shape的前两个值,分别付给h,w.shape[0]=h,shape[1]=w
    mask=np.zeros([h+2,w+2],np.uint8)      #必须这样!保证周边元素都被处理
    #从(30,30)开始,填充成(0,255,255),(100,100,100)需要填充的最低像素值为(30,30)-(100,100),高值(30,30)+(50,50)
    cv.floodFill(copying,mask,(30,30),(0,255,255),(100,100,100),(50,50,50),cv.FLOODFILL_FIXED_RANGE)
    cv.imshow("fill_color_demo",copying)


def fill_binary():
    image=np.zeros([400,400,3],np.uint8)
    image[100:300,100:300,:]=255
    cv.imshow("fill_bi

;