小编zug*_*dia的帖子

翻译Python函数以将掩码应用到Java中

我正在尝试将以下Python函数转换为Java,该函数将掩码应用于图像:

# Applies an image mask.
def region_of_interest(img, vertices):
    #defining a blank mask to start with
    mask = np.zeros_like(img)   

    #defining a 3 channel or 1 channel color to fill the mask with depending on the input image
    if len(img.shape) > 2:
        channel_count = img.shape[2]  # i.e. 3 or 4 depending on your image
        ignore_mask_color = (255,) * channel_count
    else:
        ignore_mask_color = 255

    #filling pixels inside the polygon defined by "vertices" with the fill color    
    cv2.fillPoly(mask, vertices, ignore_mask_color)

    #returning the image …
Run Code Online (Sandbox Code Playgroud)

java opencv mask

11
推荐指数
1
解决办法
814
查看次数

标签 统计

java ×1

mask ×1

opencv ×1