detect-camera-lighting
v2.0.6
Published
This library is designed to detect the lighting conditions of a camera in real-time, providing insights into whether the camera is in a well-lit or poorly lit environment.
Downloads
129
Maintainers
Readme
Detect Camera Lighting
This library is designed to detect the lighting conditions from video stream or an image.
Installation
npm install detect-camera-lightingUsage - Detect lighting from image
import DetectLighting from 'detect-camera-lighting';
const detectLighting = new DetectLighting();
const lightImageUrl = './images/light.jpg';
const eventEmitter = detectLighting.image(lightImageUrl);
eventEmitter.addEventListener('processed', (data) => {
console.log('Processed image:', data.detail); // this will give value 'light' or 'dark'
});
Usage - Detect lighting from video stream
Note: Ensure video is loaded before passing to the library
import DetectLighting from 'detect-camera-lighting';
navigator.mediaDevices.getUserMedia({ video: true })
.then((stream) => {
const video = document.getElementById('video');
video.srcObject = stream;
video.addEventListener('loadedmetadata', () => {
video.play();
});
video.addEventListener('play', () => {
detectLighting.video(video).addEventListener('processed', (data) => {
console.log('Processed video frame:', data.detail); // this will give value 'light' or 'dark'
});
});
})
.catch((error) => {
console.error('Error accessing webcam:', error);
});Options
You can pass options to the image/video methods of DetectLighting to customize the detection process.
Threshold: The default threshold is set to 0.5, which means if the average brightness of the image is greater than 0.5, it will be considered as 'light', otherwise 'dark'.
const eventEmitter = detectLighting.image(lightImageUrl, {
threshold: 0.5, // Threshold for light detection (default is 0.5)
});
const eventEmitter = detectLighting.video(video, {
threshold: 0.5, // Threshold for light detection (default is 0.5)
});If you like my work, please consider giving it a star on GitHub or Sponsor my work by following sponsoring me link.
