Image processing in front Live Camera to detect t when the light of a room is open or closed

Ahmed Wassim BEN SALEM (ENISo) 241 Reputation points
2021-04-01T13:31:56.3+00:00

So i am student in my final year , and i need in my project graduation to detect via a live camera if the light in a room is open/closed in Xamarin Forms
Do u have any suggestions guys how can i implement that ? and what to use to do that

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,298 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,318 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,901 Reputation points Microsoft Vendor
    2021-04-02T06:44:17.963+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    You do not need to use camera to detect the light, lots of android devices have a light sensor.

    For Android, you should SensorManager to get the light value.

       SensorManager _senMan = (SensorManager)GetSystemService(Context.SensorService);  
                   Sensor sen = _senMan.GetDefaultSensor(SensorType.Light);  
                   _senMan.RegisterListener(new MySensorListner(_senMan,this), sen, Android.Hardware.SensorDelay.Game);  
         
        internal class MySensorListner : Java.Lang.Object, ISensorEventListener  
           {  
               SensorManager _senMan;  
               MainActivity mainActivity;  
               public MySensorListner(SensorManager _senMan, MainActivity mainActivity)  
               {  
                   this._senMan = _senMan;  
                   this.mainActivity = mainActivity;  
               }  
               public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)  
               {  
                   
               }  
         
               public void OnSensorChanged(SensorEvent s)  
               {  
                   // get lightSensor value.  
         
                   s.Sensor = _senMan.GetDefaultSensor(SensorType.Light);  
                   float lightSensorValue = s.Values[0];  
                    Toast.MakeText(mainActivity, lightSensorValue.ToString("0.00"), ToastLength.Long).Show();  
               }  
           }  
       }  
    

    Based on the lightSensorValue, you should detect if light is ON or OFF.

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. jhon233 1 Reputation point
    2023-04-16T07:44:17.2666667+00:00

    Hi there! Congratulations on your final year of study! For detecting if a room light is open or closed via a live camera in Xamarin Forms, you can use the camera functionality provided by Xamarin.Forms.MediaElement. You can capture a live video feed from the camera and process the frames to determine the state of the room light. You can use C# to implement the logic for processing the video frames and detecting the open/closed state of the room light. Some possible approaches could be to analyze the pixel values in the video frames to determine the brightness level or to use computer vision techniques such as edge detection or color thresholding to identify the state of the room light. It may require some experimentation and testing to find the most accurate approach for your specific project. Good luck with your graduation project!

    0 comments No comments