Thank you for your reply.
I used the OpenCV procedures that you proposed in order to detect the light spot on an image, using the function “treshold” on a grayscale image, findContours to find the spot contour and minEnclosingCirlce to draw a circle the size of the light source. This seems to work quite well.
I have an extra question about treshold however. In the current iteration in my code, I have set the thresh and maxval values manually, but this depends on the “brightness” or whitest pixels in the grayscale image: If the original input image is yellow indstead of pure white light, the grayscale image white brightness of the light source will be less than pure white as well.
My question: Is there a way in OpenCV to detect the average brightest white on a grayscale image ? this way I can dynamically set the thresh value in the treshold procedure which depends on the average whitest pixels in the grayscale image instad of manually hardcoding these values as I do now.
Example of what I use now, for a specific input:
thresh = cv2.threshold(grayImage, 240, 255, cv2.THRESH_BINARY)
The problem with this is that the thresh value (240 here) is not dynamic.
To remedy this, I also tried using Otsu’s method together with gaussian blur (in order to reduce noise) as Otsu’s method calculates the thresh value in treshold on its own, and this seems to work well also. The issue with this method is however that I cannot define a “lower bound” as if a minimum “brightness” value for the thresh parameter in treshold. With the Otsu method, it doesn’t matter what you enter as the algorithm will try to find the optimal thresh value itself.
threshvalue = 150 # arbitrary with otsu method
maxvalue = 255 # pure white
gaussianBlur = cv2.GaussianBlur(grayImage, (5, 5), 0)
ret, thresh = cv2.threshold(gaussianBlur, threshvalue, maxvalue, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
The reason why I want this lower bound, is because the Otsu method still detects the shape of the light source (the lamp) when it is turned off.
For clarification: I have a video file of a light source as input, which turns on and off. When it is turned on, I want to detect the light. When it is off, no light should be detected. With the Otsu method, the turned-off lamp is still detected when the light is turned off. The reason for this being that the Otsu method finds a low enough thresh value in order to be able to detect the turned off light, which is still the brightest object in the frame (even when turned off).
Is it possible to the light only when it is turned on ? If so, how can I do this ?
Is the Otsu method a correct path forwared, or should I use something else ?
Thank you very much for your help !
With Kind Regards,