2016-08-15 2 views
1

내가 바라는 것은 쿼드 프레임 피드에 4 개의 비디오 피드, RGB, B, G, R 채널을 함께 쌓을 수 있도록 만드는 것입니다. 여기에 내 코드가 있습니다. "모든 입력 배열의 치수가 같아야합니다.이 작업을 수행 할 수있는 방법이 있는지 알고 싶습니까? GRAY를 삽입하면 RGB가 전체 결과를 볼 수 있습니다. 회색 프레임이 어디 RGB 프레임 이외 걸려 라하는 것은해야한다스택 cv2 RGB 채널과 단일 채널의 프레임 함께

import numpy as np 
import cv2 

cap = cv2.VideoCapture(0) 
ret, frame = cap.read() 

while(True): 
    ret, frame = cap.read() 
    # Resizing down the image to fit in the screen. 
    b,g,r = cv2.split(frame) 
    RGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA) 
    GRAY = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 

    # creating another frame. 
    channels = cv2.split(frame) 
    frame_merge = cv2.merge(channels) 

    # horizintally concatenating the two frames. 
    final_frame = cv2.hconcat((frame, frame_merge)) 
    final_frame2 = cv2.hconcat((frame, frame_merge)) 
    final = cv2.vconcat((final_frame, final_frame2)) 

    frame1 = np.hstack((RGB,b)) 
    frame2 = np.hstack((g,r)) 
    final = np.vstack((frame1,frame2)) 
    cv2.imshow('frame', final) 

    k = cv2.waitKey(30) & 0xff 
    if k == 27: 
     break 

cap.release() 
cv2.destroyAllWindows() 

답변

0

여기 내 솔루션입니다 :. 당신이 내 위의 코드를 가지고 GRAY = CV2를 추가 한 후 GRAY와 RGB를 교체 할 경우

import numpy as np 
import cv2 

cap = cv2.VideoCapture(0) 
ret, frame = cap.read() 

red = np.zeros(frame.shape, 'uint8') 
green = np.zeros(frame.shape, 'uint8') 
blue = np.zeros(frame.shape, 'uint8') 

while(True): 
    ret, frame = cap.read() 
    b, g, r = cv2.split(frame) 

    red[..., 0], red[..., 1], red[..., 2] = r, r, r 
    green[..., 0], green[..., 1], green[..., 2] = g, g, g 
    blue[..., 0], blue[..., 1], blue[..., 2] = b, b, b 

    final = cv2.vconcat((
     cv2.hconcat((frame, blue)), 
     cv2.hconcat((green, red)) 
    )) 

    cv2.imshow('frame', final) 

    k = cv2.waitKey(30) & 0xff 
    if k == 27: 
     break 

cap.release() 
cv2.destroyAllWindows() 
+0

. cvtColor (frame, cv2.COLOR_BGR2GRAY)를 사용하면 내가 수행 할 결과를 볼 수 있습니다. 카메라 앞에 빨간색 물체를 올려 놓으면 빨간색 채널이 빨간색을 강조하고 다른 색상은 계속 강조 표시됩니다. 첫 번째 회색 프레임 대신에 나는 그것이 규칙적인 컬러 프레임이되기를 원합니다. –

+0

@MichaelHenderson 내가 올바르게 이해했는지 모르겠다. 그건 내 솔루션이 편집하기 전에 달성 하려던 것이 아니란 말인가요? – BPL

+0

@MichaelHenderson 새로운 솔루션을 추가했습니다. 원하는 솔루션인지 알려주십시오. 그렇지 않은 경우 조금 더 설명하십시오. – BPL

관련 문제