Is it possible to recognise from a camera video stream is it night or day?

Is it possible to recognise from a camera video stream is it night or day? If yes, how?

What are you trying to solve? Knowing if it is night or day is one of the easiest things to do and you are trying to solve that in a very complicated unusual way…

Try to describe your problem, not the way you are trying to solve the probkem.

It would be remarkably complex and you would probably need a Raspberry Pi running an AI program…
Why not simply use the sun integration in Home Assistant?

I don’t think it would be too difficult technically to measure the amount of light in an image, but as @EdwardTFN said there are far easier ways.

Well, and the discussion about what is considered night can be quite long… You can have a dark image indoor in a sunny day at noon… That is technically day time, but the camera might require a night mode…
Where I live you can have quite bright nights during summer, so the camera might thing it’s day…

Again it’s more important to understand what is the final goal, not how to solve a problem…

I was assuming that the camera was pointing somewhere easy. Its an expensive light sensor though.

I don’t know if that is the case or not, this is why I’m asking for more details on the problem… maybe you are right, but with the info we have we can only speculate. :wink:


Not directly to what I believe is your question, I however I had an issue with a video camera that faced the street, when a car’s headlight would hit the camera, it would switch from night mode to day mode and the camera had no api to say which mode it was in. So the solution I came up with was to check the noise level of a still image taken from the video stream every minute, if the noise level of the image went above a certain level, I send a http api command to the camera to change it to night mode. You could combine something like this with similar to check the color or b/w levels of the still, since a night camera (other than some of the newer low light color capable ones) is ir black and white.
I don’t have the linux app that I use in front of me, I will post when I can get back to a place I can find it on github. Good hunting!

Why don’t you send that command when the sun is below let’s say -6° (when it ends the civil twilight and it’s dark enough to a night mode)?


@python Apologies, the routine listed below checks the most recent .jpg still in a directory and does an action based on the noise level returned by the scikit image noise routine. It is not directly looking at the video stream. However, it would not be too much more work to capture a still out of a video stream and pass the still to this routine. Hope you find a good solution, good hunting!

python3 skimage program to look at noise level of most recent .jpg file in directory and do action based on noise level