Ask Your Question

Victor Sandoval's profile - activity

2014-08-25 14:27:13 -0600 received badge  Scholar (source)
2014-08-25 14:27:12 -0600 received badge  Supporter (source)
2014-08-19 12:00:07 -0600 commented question error bitwise operation

ok my apologies, I edit the post and I hope you can understand. the problem is in the line res = cv2.bitwise_not(image1,image,mask=mask)

I think it hits the negative image1 (beach)

2014-08-19 11:48:13 -0600 received badge  Editor (source)
2014-08-18 15:41:56 -0600 asked a question 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

2014-08-04 15:47:16 -0600 asked a question Modify ROI in the mask

Hi! Hello, I am a engineer student in Universidad Católica de Temuco 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 and simplecv library and I wonder if there is any chance to help me with the mask in simplecv and opencv. Any kind of help,examples or doumentation would be useful for my research. source code

from SimpleCV import *
import cv2
import numpy as np
from PIL import Image
from SimpleCV import *
from ImageChops import subtract
import math
greenscreen = Image("ploc.png")
#Iniciamos la camara
captura = cv2.VideoCapture(0)
imagen1= cv2.imread('JUE14.PNG')
#captura.set(3,1024)
#captura.set(4,780)
captura.set(3,400)
captura.set(4,266)

while(1):

    #Capturamos una imagen y la convertimos de RGB -> HSV
    _, imagen = 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)

    #prueba de mascara resultante  quitando bit a bit los pixeles
    res = cv2.bitwise_and(imagen,imagen,mask=~mask)



    cv2.imshow('mask', mask)
    cv2.imshow('Camara', imagen)
    cv2.imshow('res', res)

    #cv2.imshow('res2', mask2)
    #cv2.imshow('ploc', ploc)
    tecla = cv2.waitKey(5) & 0xFF
    if tecla == 27:
        break

cv2.destroyAllWindows()

I need replace ROI (in res window) for any background (picture or video)

Regards.