Modifying diddyRedFollowBall to follow flashlight

Hello! I am making some, ahem, "extensive" ( ;-) ) modifications to my brand new Diddyborg Red!

I have installed a night vision (no IR filter) Pi camera. I'm trying to modify the diddyRedFollowBall.py program to follow a flashlight instead of a red ball (since red balls don't exactly look red, especially at night with the night vision activated).

I can't quite tune the colors on this line properly:

image = cv2.medianBlur(image, 5)
image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) # Swaps the red and blue channels!
#red = cv2.inRange(image, numpy.array((115, 127, 64)), numpy.array((125, 255, 255)))
bright = cv2.inRange(image, numpy.array((115, 127, 64)), numpy.array((125, 255, 255)))

Any thoughts? Attached is a sample image taken from the web GUI when shining the flashlight at the Pi night vision camera. Also attached is what an infrared remote control LED looks like to the Pi night vision camera (which would be cool to get working instead of a visible light flashlight).

Images: 
piborg's picture

In order to change the test it helps to understand what the numbers actualy are:

  1. Hue - The colour of the rainbow to match (cv2 uses values between 0 and 180)
  2. Saturtion - How far from grey the colour is, 0 is fully grey, 255 is full colour
  3. Lightness - How bright the colour is, 0 is black, 255 is full colour

In order to match the lights you have shown:

  1. Hue - Since pure white has no specific hue the full range shoud be allowed.
    Both lights: 0 to 180
  2. Saturation - This will be closer to the grey end, the IR light has a tinge of blue though:
    Visible light: 0 to 32
    IR light: 0 to 160, maybe larger
  3. Lightness - This should be the brightest part of the image and therfore a large number:
    Both lights: 220 to 255
image = cv2.medianBlur(image, 5)
image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) # Swaps the red and blue channels!
#red = cv2.inRange(image, numpy.array((115, 127, 64)), numpy.array((125, 255, 255)))
visible = cv2.inRange(image, numpy.array((0, 0, 220)), numpy.array((180, 32, 255)))
ir = cv2.inRange(image, numpy.array((0, 0, 220)), numpy.array((180, 160, 255)))

Hopefully these will get you going.
Since the IR test includes everything from the visible test it would probably work for both lights :)

Nice! Everything now (almost) works! :-D

Thanks for clarifying what the function arguments represented!

Subscribe to Comments for "Modifying diddyRedFollowBall to follow flashlight"