Ask Your Question

Revision history [back]

error bitwise operation

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()

image description

and the real color of the picture image description

error bitwise operation

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 #Initialize camera
capture = cv2.VideoCapture(0)
imagen1= image1= 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)
capture.set(3,600)
capture.set(4,400)



while(1):

  #Capturamos una imagen y la convertimos de #Capture image from camera and I make  RGB -> HSV
  _, imagen = captura.read()
  _,camara = captura.read()
image = capture.read()
  _,camera = capture.read()
  hsv = cv2.cvtColor(imagen, cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
  #Establecemos el rango de colores que vamos a detectar
  #En este caso de verde oscuro a verde-azulado claro
  verde_bajos #I APPLY THE COLOR RANGE TO BE DETECTED. IN THIS CASE LIGTH GREEN AND DARK GREEN
  DARK_GREEN = np.array([49,50,50], dtype=np.uint8)
  verde_altos LIGTH_GREEN = 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
#I CREATE A MASK WITH THE COLOR RANGE I WANT
  mask = cv2.inRange(hsv, verde_bajos, verde_altos)
  #creacion # kernel 4x4
CREATION 4x4 TO ELIMINATE NOISE
  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 #I apply erosion
  mask = cv2.erode(mask,kernel,iterations = 2)
  #Aplicamos una dilatacion
#I apply dilation
  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.bitwise_not(image1,image,mask=mask)
  #show binary mask
  cv2.imshow('mask', mask)
  #show default camera
  cv2.imshow('Camara', camara)
  #show result
  cv2.imshow('res', res)

  tecla = cv2.waitKey(5) & 0xFF
  if tecla == 27:
     break
 cv2.destroyAllWindows()

image description

and the real color of the picture image description

error bitwise operation

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
#green objects detected and an image replacement
#also eliminates noise



import cv2
import numpy as np
from PIL import Image
#Initialize camera
capture = cv2.VideoCapture(0)
image1= cv2.imread('playa2.jpg')
capture.set(3,600)
capture.set(4,400)



while(1):

  #Capture image from camera and I make  RGB -> HSV
  _, image = capture.read()
  _,camera = capture.read()
  hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
  #I APPLY THE COLOR RANGE TO BE DETECTED. IN THIS CASE LIGTH GREEN AND DARK GREEN
  DARK_GREEN = np.array([49,50,50], dtype=np.uint8)
  LIGTH_GREEN = np.array([80, 255, 211], dtype=np.uint8)
  #I CREATE A MASK WITH THE COLOR RANGE I WANT
  mask = cv2.inRange(hsv, verde_bajos, verde_altos)
  # kernel CREATION 4x4 TO ELIMINATE NOISE
  kernel = np.ones((3,3),np.uint8)
  #kernel1 = np.ones((3,3), np.uint8)
  #I apply erosion
  mask = cv2.erode(mask,kernel,iterations = 2)
  #I apply dilation
  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(image1,image,mask=mask)
  #show binary mask
  cv2.imshow('mask', mask)
  #show default camera
  cv2.imshow('Camara', camara)
  #show result
  cv2.imshow('res', res)

  tecla = cv2.waitKey(5) & 0xFF
  if tecla == 27:
     break
 cv2.destroyAllWindows()

image description

and the real color of the picture image description

click to hide/show revision 4
retagged

updated 2014-08-20 02:28:45 -0600

berak gravatar image

error bitwise operation

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

#green objects detected and an image replacement
#also eliminates noise



import cv2
import numpy as np
from PIL import Image
#Initialize camera
capture = cv2.VideoCapture(0)
image1= cv2.imread('playa2.jpg')
capture.set(3,600)
capture.set(4,400)



while(1):

  #Capture image from camera and I make  RGB -> HSV
  _, image = capture.read()
  _,camera = capture.read()
  hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
  #I APPLY THE COLOR RANGE TO BE DETECTED. IN THIS CASE LIGTH GREEN AND DARK GREEN
  DARK_GREEN = np.array([49,50,50], dtype=np.uint8)
  LIGTH_GREEN = np.array([80, 255, 211], dtype=np.uint8)
  #I CREATE A MASK WITH THE COLOR RANGE I WANT
  mask = cv2.inRange(hsv, verde_bajos, verde_altos)
  # kernel CREATION 4x4 TO ELIMINATE NOISE
  kernel = np.ones((3,3),np.uint8)
  #kernel1 = np.ones((3,3), np.uint8)
  #I apply erosion
  mask = cv2.erode(mask,kernel,iterations = 2)
  #I apply dilation
  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(image1,image,mask=mask)
  #show binary mask
  cv2.imshow('mask', mask)
  #show default camera
  cv2.imshow('Camara', camara)
  #show result
  cv2.imshow('res', res)

  tecla = cv2.waitKey(5) & 0xFF
  if tecla == 27:
     break
 cv2.destroyAllWindows()

image description

and the real color of the picture image description