2016-08-01 8 views
0

저는 파노라마를 Python OpenCV로 작업하고 있습니다. 누군가 최종 이미지에서 검은 선을 제거하는 방법을 보여줄 수 있습니까? 나는 어쩌면 내가 먼저 색을 확인해야한다고 생각하고있다. 0, 0, 0, atlas 이미지로 복사하기 전에,하지만 난 그걸하는 방법을 잘 모르겠습니다.python opencv panorama blacklines

def warpTwoImages(img1, img2, H): 
    '''warp img2 to img1 with homograph H''' 
    h1,w1 = img1.shape[:2] 
    h2,w2 = img2.shape[:2] 
    pts1 = np.float32([[0,0],[0,h1],[w1,h1],[w1,0]]).reshape(-1,1,2) 
    pts2 = np.float32([[0,0],[0,h2],[w2,h2],[w2,0]]).reshape(-1,1,2) 
    pts2_ = cv2.perspectiveTransform(pts2, H) 
    pts = np.concatenate((pts1, pts2_), axis=0) 
    [xmin, ymin] = np.int32(pts.min(axis=0).ravel() - 0.5) 
    [xmax, ymax] = np.int32(pts.max(axis=0).ravel() + 0.5) 
    t = [-xmin,-ymin] 
    Ht = np.array([[1,0,t[0]],[0,1,t[1]],[0,0,1]]) # translate 

    result = cv2.warpPerspective(img2, Ht.dot(H), (xmax-xmin, ymax-ymin)) 
    result[t[1]:h1+t[1],t[0]:w1+t[0]] = img1 
    return result 

Click here to see my reult

답변

0

이 답변 RGBA와 함께 작동하도록 warpPrespicteve 기능에 따라 달라집니다. 각 이미지의 알파 채널을 사용할 수 있습니다. 각 이미지를 RGBA로 변환하기 전에 (아래 코드 참조) 검정색 선은 알파 채널이 0이고 다른 모든 픽셀은 255가됩니다.

import cv2 
import numpy as np 

# Read img 
img = cv2.imread('i.jpg') 

# Create mask from all the black lines 
mask = np.zeros((img.shape[0],img.shape[1]),np.uint8) 
cv2.inRange(img,(0,0,0),(1,1,1),mask) 
mask[mask==0]=1 
mask[mask==255]=0 
mask = mask*255 

b_channel, g_channel, r_channel = cv2.split(img) 

# Create a new image with 4 channels the forth channel Aplha will give the opacity for each pixel 
newImage = cv2.merge((b_channel, g_channel, r_channel, mask))