小编Ara*_*ram的帖子

使用opencv删除任何图像的背景

我一直在寻找一种技术来删除任何给定图像的背景.想法是检测面部并移除检测到的面部的背景.我完成了脸部.现在删除背景部分仍然存在.

我用过这段代码.

import cv2
import numpy as np

#== Parameters           
BLUR = 21
CANNY_THRESH_1 = 10
CANNY_THRESH_2 = 200
MASK_DILATE_ITER = 10
MASK_ERODE_ITER = 10
MASK_COLOR = (0.0,0.0,1.0) # In BGR format


#-- Read image
img = cv2.imread('SYxmp.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

#-- Edge detection 
edges = cv2.Canny(gray, CANNY_THRESH_1, CANNY_THRESH_2)
edges = cv2.dilate(edges, None)
edges = cv2.erode(edges, None)

#-- Find contours in edges, sort by area 
contour_info = []
_, contours, _ = cv2.findContours(edges, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
for c in contours:
    contour_info.append(( …
Run Code Online (Sandbox Code Playgroud)

python opencv numpy image-processing python-3.x

2
推荐指数
1
解决办法
4437
查看次数

标签 统计

image-processing ×1

numpy ×1

opencv ×1

python ×1

python-3.x ×1