My input video was sourced from a smart CCTV camera that automatically goes into night-vision mode when it gets dark enough.
I would like to determine if a frame/image in the video I am processing using open-cv (cv2) was a frame/image that was in night-vision mode.
Unfortunately, the shape of each frame/image is (1920,1080,3) even it still switched to night-vision mode which means it's still in RGB channel (3 channels).
Are there ways I can achieve what I intend to achieve?
I would like to thank you in advance for taking time to think and answer to my question.
I cannot find other approaches aside from looking at the number of channels per frame/image.
Here is a sample image showing the difference of a video frame/image in normal and night-vision mode:
If your night-mode images are 3-channel the same as your day-mode images, but look grey, then the likelihood is that your camera has an infra-red (or other) single channel (greyscale) sensor and, when active at night, the single channel is just duplicated into the other two empty channels before being sent to your app by the camera.
You can test this by looking at the first, or any other pixel and seeing if the R, G and B channels are all equal, For example, looking at the first pixel:
# {Print all three RGB channels of pixel at [0,0]
print(im[0,0,:])
If they are all the same, it will appear grey. If your camera is recording in colour, they are unlikely to be equal.
So, to test an entire frame, you could use numpy.allclose()
to see if the Reds are close to the Greens and the Greens are close to the Blues:
Reds = im[:, :, 0]
Greens = im[:, :, 1]
Blues = im[:, :, 2]
nightmode = np.allclose(Reds, Greens, atol=2.0) and np.allclose(Greens, Blues, atol=2.0)
I put in a tolerance of 2 on the brightnesses being equal, to allow for some deviation from being 100% identical - though I am not sure how this could possibly come about.