2025년 9월 5일 금요일

9.05 센서 정보를 가져오기 위한 스레드 / 차선 추출을 위한 대표적인 색 공간에는 HSV, HLS, YUV

using System;
using System.Collections.Generic;
using UnityEngine;

namespace DMOA.Data
{
    /// <summary>
    /// 센서 데이터
    /// </summary>
    public class SensorData
    {
        public float Humidity;
        public float Temperature;
        public float Light;
    }
}

using System;

using System.Collections.Generic;

using UnityEngine;


namespace DMOA.Data

{

    /// <summary>

    /// 센서 데이터

    /// </summary>

    public class SensorData

    {

        public float Humidity;

        public float Temperature;

        public float Light;

    }

}

[InstallShield Silent]
Version=v7.00
[ResponseResult]
ResultCode=0
[Application]
Name=Realtek Audio Driver
Version=4.78
Company=Realtek Semiconductor Corp.
Lang=0412

[InstallShield Silent]

Version=v7.00

File=Log File

[ResponseResult]

ResultCode=0

[Application]

Name=Realtek Audio Driver

Version=4.78

Company=Realtek Semiconductor Corp.

Lang=0412



 using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using DmoaThingWorxDll.Interface;

using Newtonsoft.Json.Linq;

using System.Threading;

using DMOA.Data;



namespace DMOA.Manager

{

    public class ThingworxManager : MonoBehaviour

    {

        /// <summary>

        ///  센서 데이터

        /// </summary>

        public SensorData SensorData { get; private set; } = new();


        private static ThingworxManager _instance;

        public static ThingworxManager Instance => _instance;


        /// <summary>

        /// URL

        /// </summary>

        private string _thingUrl = "http://122.199.130.214:80/Thingworx";

        /// <summary>

        /// APPKEY 

        /// </summary>

        private readonly string AppKey = "48106a4f-adf1-439f-ab15-ebbcf200bb9e";

        /// <summary>

        /// 센서 Thing Name

        /// </summary>

        private readonly string ThingName_Sensor = "UnityDTDemo_Sensor";


        /// <summary>

        /// 센서 습도 정보

        /// </summary>

        private readonly string U_CON_BoschSensor_Unsolicited_Environmental_Humidity = "U_CON_BoschSensor_Unsolicited_Environmental_Humidity";

        /// <summary>

        /// 센서 온도 정보

        /// </summary>

        private readonly string U_CON_BoschSensor_Unsolicited_Environmental_Temperature = "U_CON_BoschSensor_Unsolicited_Environmental_Temperature";

        /// <summary>

        /// 센서 조도 정보

        /// </summary>

        private readonly string U_CON_BoschSensor_Unsolicited_Light = "U_CON_BoschSensor_Unsolicited_Light";


        // 센서 스레드 관련

        private Thread _thread;

        private bool _runThread;


        void Awake()

        {

            // 클래스의 인스턴스가 존재하면 새로 생성된 gameObject를 삭제

            if (_instance)

            {

                Destroy(this.gameObject);

                return;

            }


            // 기존 인스턴스가 없다면 이 객체를 instance로 설정 (클래스의 유일한 인스턴스로 만듬)

            _instance = this;


            // 씬이 변경되더라도 이 gameObject가 삭제되지 않도록 처리

            DontDestroyOnLoad(this.gameObject);

        }


        private void Start()

        {

            // 센서정보를 가져오기 위한 스레드 시작

            _runThread = true;

            _thread = new(RunSensorThread);

            _thread.Start();

        }


        private void OnApplicationQuit()

        {

            // 센서 정보를 가져오기 위한 스레드 종료

            _runThread = false;

            _thread?.Join();

        }


        public void SetConfig(string url)

        {

            _thingUrl = url;

        }


        /// <summary>

        /// 센서 데이터 가져오기

        /// </summary>

        /// <returns></returns>

        private void RunSensorThread()

        {

            // Thingworx 연결 객체 생성

            Thingworx thingworx = new(_thingUrl, AppKey);


            while (_runThread)

            {

                // 1초 마다 가져오도록 딜레이

                Thread.Sleep(1000);


                SensorData.Humidity = GetHumiditySensorData(thingworx);


                SensorData.Temperature = GetTemperatureSensorData(thingworx);


                SensorData.Light = GetLightSensorData(thingworx);

            }

        }


        #region SENSOR DATA


        /// <summary>

        /// 습도

        /// </summary>

        private float GetHumiditySensorData(Thingworx thingworx)

        {

            float humidity;

            string result;


            thingworx.Rest_GetThingPropertie(ThingName_Sensor, U_CON_BoschSensor_Unsolicited_Environmental_Humidity, out result);


            if (string.IsNullOrEmpty(result))

            {

                //Debug.Log("GetHumiditySenserData() Error");

                humidity = 0f;

            }

            else

            {

                humidity = float.Parse(result);

            }


            return humidity;

        }


        /// <summary>

        /// 기온

        /// </summary>

        private float GetTemperatureSensorData(Thingworx thingworx)

        {

            string result;

            float temperature;


            thingworx.Rest_GetThingPropertie(ThingName_Sensor, U_CON_BoschSensor_Unsolicited_Environmental_Temperature, out result);


            if (string.IsNullOrEmpty(result))

            {

                //Debug.Log("GetTemperatureSenserData() Error");

                temperature = 0f;

            }

            else

            {

                temperature = float.Parse(result);

            }


            return temperature;

        }


        /// <summary>

        /// 조도

        /// </summary>

        private float GetLightSensorData(Thingworx thingworx)

        {

            string result;

            float light;


            thingworx.Rest_GetThingPropertie(ThingName_Sensor, U_CON_BoschSensor_Unsolicited_Light, out result);


            if (string.IsNullOrEmpty(result))

            {

                //Debug.Log("GetLightSenserData() Error");

                light = 0f;

            }

            else

                light = float.Parse(result);


            return light;

        }


        #endregion SENSOR DATA

    }



}

차선 추출을 위한 대표적인 색 공간에는 HSV, HLS, YUV가 있습니다. 이 색 공간들은 RGB(빨강, 녹색, 파랑) 색 공간과 달리 색상의 특징을 나타내는 방식으로 밝기, 채도, 색상 등을 분리하여 표현하므로, 차선 색상(주로 흰색이나 노란색)을 효과적으로 분리하고 추출하는 데 사용될 수 있습니다. 특히 HSV와 HLS는 색상, 채도, 명도(또는 밝기)로 색을 표현하여, 색상 범위를 설정하여 특정 차선 색상을 추출하기에 용이합니다. 
대표적인 색 공간과 차선 추출에서의 역할
  • 색상(Hue), 채도(Saturation), 명도(Value)의 3가지 요소로 색을 표현합니다. 차선 인식 시, 노란색이나 흰색과 같이 특정 색상의 범위를 설정하여 다른 색과 구분하고 추출할 때 효과적입니다. 
  • HSV와 유사하게 색상(Hue), 밝기(Lightness), 채도(Saturation)를 사용하여 색을 표현합니다. HSV처럼 색상 범위를 설정하여 차선을 추출할 수 있습니다. 
  • 밝기(Y)와 색차(U, V)로 색을 구성합니다. 밝기 정보(Y)를 활용하여 차선의 밝기 변화를 분석하거나, 특정 색상에 집중하여 추출하는 데 활용될 수 있습니다. 
이유 및 장점 
  • 색상 분리:
    RGB 색 공간은 빛의 삼원색으로 색을 표현하므로, 조명이나 그림자에 따라 색상 값이 크게 변할 수 있습니다. 반면, HSV나 HLS는 색상, 채도, 명도(또는 밝기)를 분리하여 색의 특정 특성을 강조하거나 제거하기 용이합니다.
  • 효율성:
    YUV와 같이 밝기 정보와 색상 정보를 분리하는 것은 영상 처리에서 특정 목적에 따라 특정 정보를 강조하거나 무시하는 데 효율적입니다. 차선은 주로 특정 색상과 밝기를 가지므로, 이러한 색 공간을 사용하면 차선 정보만을 효과적으로 추출할 수 있습니다

댓글 없음:

앤시스 실습_(2) / 구조해석절차

 다운로드 방법(영문) - https://www.ansys.com/ko-kr/academic/students Ansys Student Versions | Free Student Software Downloads https://www.ansys.com/...