1

I'm trying to build a portable green screen photo booth. There's no way to know the lighting conditions ahead of time so I can't hard code the the color values for chroma key.

I thought the easiest way to get around this issue would be to build a calibration script that will take a picture of the blank background, get the "highest" and "lowest" colors from it, and use those to produce the background mask.

I'm running into trouble because while I can get the highest or lowest value in each of the channels, there's no guarantee that when the three are combined they match the actual color range of the image.

UPDATE: I have changed to use only the hue channel. This helped a lot but still isn't perfect. I think better lighting will make a difference but if you can see any way to help I would be grateful.

Here's what I have (edited with updates)

import cv2
import numpy as np



screen = cv2.imread("screen.jpg")
test = cv2.imread("test.jpg")

hsv_screen = cv2.cvtColor(screen, cv2.COLOR_BGR2HSV)
hsv_test = cv2.cvtColor(test, cv2.COLOR_BGR2HSV)

hueMax = hsv_screen[:,:,0].max()
hueMin = hsv_screen[:,:,0].min()

lowerBound = np.array([hueMin-10,100,100], np.uint8)
upperBound = np.array([hueMax+10,255,255], np.uint8)


mask = cv2.inRange(hsv_test,lowerBound,upperBound)
cv2.imwrite("mask.jpg",mask)

output_img = cv2.bitwise_and(test,test,mask=inv_mask)
cv2.imwrite("output.jpg",output_img)

screen and test images

screen.jpg screen

test.jpg test.jpg

2
  • 1
    wouldn't be enough to inspect only the Hue channel? Commented Sep 27, 2016 at 12:37
  • I dont guess your highest and lowest value approach would work out. Kindly share some input images, a simple diff with a tolerance value of background and current frame can also do the job pretty nicely as well Commented Sep 27, 2016 at 15:00

1 Answer 1

3

HUE colors have specified intervals, get the green interval and then do an inRange using it, ignoring the saturation and value, that would give you all degrees of green, to minimize noise much, make the value range to be from 20% to 80%, that would avoid the too much light, or too much dark regions, and ensure you only get what's green anywhere in the screen. Detecting using only HUE channel is dependable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.