Hello, I am a engineer student in Universidad Católica de Temuco (Chile) and currently I'm working on my thesis. I'm making a prototype in real time chroma key on linux (ubuntu 11|.04). So this prototype is being developed in python with opencv. As can see I could apply a mask with a range of green colors (light and dark green) - this showing in the window called res resulting from the mask denied (leaving in black green hues ). the problem is the background image shown in negative any suggestions? Regards
#Detecta objetos verdes, elimina el ruido
import cv2
import numpy as np
from PIL import Image
#Iniciamos la camara
captura = cv2.VideoCapture(0)
imagen1= cv2.imread('playa2.jpg')
#captura.set(3,1024)
#captura.set(4,780)
captura.set(3,600)
captura.set(4,400)
hola= captura.get(3)
chao=captura.get(4)
while(1):
#Capturamos una imagen y la convertimos de RGB -> HSV
_, imagen = captura.read()
_,camara = captura.read()
hsv = cv2.cvtColor(imagen, cv2.COLOR_BGR2HSV)
#Establecemos el rango de colores que vamos a detectar
#En este caso de verde oscuro a verde-azulado claro
verde_bajos = np.array([49,50,50], dtype=np.uint8)
verde_altos = np.array([80, 255, 211], dtype=np.uint8)
rojo= np.array([0,255,0], dtype=np.uint8)
#Crear una mascara con solo los pixeles dentro del rango de verdes
mask = cv2.inRange(hsv, verde_bajos, verde_altos)
#creacion kernel 4x4
kernel = np.ones((3,3),np.uint8)
#kernel1 = np.ones((3,3), np.uint8)
#mask2 = cv2.threshold(mask, 10, 255, cv2.THRESH_BINARY)
#Aplicamos una erosion
mask = cv2.erode(mask,kernel,iterations = 2)
#Aplicamos una dilatacion
mask = cv2.dilate(mask,kernel,iterations = 2)
mask_inv = cv2.bitwise_not(mask)
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel, iterations = 1)
mask= cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel, iterations = 1)
res = cv2.bitwise_not(imagen1,imagen,mask=mask)
cv2.imshow('mask', mask)
cv2.imshow('Camara', camara)
cv2.imshow('res', res)
tecla = cv2.waitKey(5) & 0xFF
if tecla == 27:
break
cv2.destroyAllWindows()
and the real color of the picture