我试图删除一些图像的背景,调整一些值,并使用一些方法,如morphologyEx给我一个aceptable结果但仍然剩下一些孔,在最后一种情况下,孔不会填充甚至迭代每个轮廓并绘制它与-1.我可以看到阈值图像真的很好,整个形状都用线条,但我不知道如何继续......
更新 我已经改变了我的代码,所以我得到了更好的结果,但我仍然有一些漏洞......如果我能填补这些漏洞,那么剧本就会完美无缺.
def get_contrasted(image, type="dark", level=3):
maxIntensity = 255.0 # depends on dtype of image data
phi = 1
theta = 1
if type == "light":
newImage0 = (maxIntensity/phi)*(image/(maxIntensity/theta))**0.5
newImage0 = array(newImage0,dtype=uint8)
return newImage0
elif type == "dark":
newImage1 = (maxIntensity/phi)*(image/(maxIntensity/theta))**level
newImage1 = array(newImage1,dtype=uint8)
return newImage1
def sharp(image, level=3):
f = cv2.GaussianBlur(image, (level,level), level)
f = cv2.addWeighted(image, 1.5, f, -0.5, 0)
return f
original_image = imread('imagen.jpg')
# 1 Convert to gray & Normalize
gray_img = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 warpPerspective 变换在围板上实现皮卡丘图像。输出没有平滑的边缘,而是有点。
import cv2
import numpy as np
image = cv2.imread("base_img.jpg")
h_base, w_base = image.shape[0], image.shape[1]
white_subject = np.ones((480,640,3),dtype="uint8")*255
h_white, w_white = white_subject.shape[:2]
subject = cv2.imread('subject.jpg')
h_sub, w_sub = subject.shape[:2]
pts2 = np.float32([[109,186],[455,67],[480,248],[90,349]])
pts3 = np.float32([[0, 0], [w_white, 0], [w_white, h_white], [0, h_white]])
transformation_matrix_white = cv2.getPerspectiveTransform(pts3, pts2)
mask = cv2.warpPerspective(white_subject, transformation_matrix_white, (w_base, h_base))
image[mask==255] = 0
pts3 = np.float32([[0, 0], [w_sub, 0], [w_sub, h_sub], [0, h_sub]])
transformation_matrix = cv2.getPerspectiveTransform(pts3, pts2)
warped_image = cv2.warpPerspective(subject, transformation_matrix, (w_base, h_base))
Run Code Online (Sandbox Code Playgroud)
围板图片
皮卡丘图片
输出图像 …