OpenCV floodfill with mask

前端 未结 3 1191
感情败类
感情败类 2020-12-02 17:14

The documentation for OpenCV\'s floodfill function states:

The function uses and updates the mask, so you take responsibility of initializing the ma

3条回答
  •  没有蜡笔的小新
    2020-12-02 18:11

    And a python version

    im = cv2.imread("seagull.jpg")
    h,w,chn = im.shape
    seed = (w/2,h/2)
    
    mask = np.zeros((h+2,w+2),np.uint8)
    
    floodflags = 4
    floodflags |= cv2.FLOODFILL_MASK_ONLY
    floodflags |= (255 << 8)
    
    num,im,mask,rect = cv2.floodFill(im, mask, seed, (255,0,0), (10,)*3, (10,)*3, floodflags)
    
    cv2.imwrite("seagull_flood.png", mask)
    

    (Seagull image from Wikimedia: https://commons.wikimedia.org/wiki/Commons:Quality_images#/media/File:Gull_portrait_ca_usa.jpg)

    Result: result

提交回复
热议问题