QR 코드 인식 소스코드 설명 부분 담당

Unity와 Zxing 라이브러리를 활용하여, 카메라 화면 내 QR코드 자동 인식 기능을 구현

현재까지 구현(완성)——

Update() 함수 - 실시간 인식

Color32[] pixels = webcamTexture.GetPixels32();
var result = reader.Decode(pixels, webcamTexture.width, webcamTexture.height);

진행 중

1.파싱 후 변수에 저장

<aside> 💡

예시

{ "id": "QR01", "position": { "x": 3.2, "y": 1.5 }, "floor": "6F" }

</aside>

/*먼저 JSON 구조에 맞는 클래스 정의*/
[System.Serializable]
public class QRInfo
{
    public string id;
    public Position position;
    public string floor;
}

[System.Serializable]
public class Position
{
    public float x;
    public float y;
}

void Update()
{
    if (webcamTexture != null && webcamTexture.isPlaying)
    {
        try
        {
            Color32[] pixels = webcamTexture.GetPixels32();
            var result = reader.Decode(pixels, webcamTexture.width, webcamTexture.height);
            if (result != null)
            {
                Debug.Log("QR Code Detected: " + result.Text);
                /* 예시 JSON: {"id":"QR01","position":{"x":3.2,"y":1.5},"floor":"6F"} */

                // JSON 문자열 → QRInfo 객체로 변환
                QRInfo qrInfo = JsonUtility.FromJson<QRInfo>(result.Text);

                // 위치 정보 추출
                Vector2 startPosition = new Vector2(
                    qrInfo.position.x,
                    qrInfo.position.y
                );

                // A* 탐색 시작점 + 층 정보 전달
                NavigationManager.Instance.SetStartPoint(startPosition, qrInfo.floor);
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogWarning("QR Parsing Failed: " + ex.Message);
        }
    }
}

2. QR → A* 탐색 시작점으로 전달

NavigationManager.cs에서 A* 알고리즘을 실행한다고 가정할 때:

public class NavigationManager : MonoBehaviour
{
    public static NavigationManager Instance;

    private Vector2 start;
    private string currentFloor;

    private void Awake()
    {
        Instance = this;
    }

    public void SetStartPoint(Vector2 startPos, string floor)
    {
        start = startPos;
        currentFloor = floor;
        Debug.Log($"A* 시작 위치: {start}, 층: {currentFloor}");
        
        // A* 탐색 실행
        RunPathfinding();
    }

    void RunPathfinding()
    {
        // 여기에 A* 알고리즘 적용
        List<Vector2> path = AStar.FindPath(start, goal);

        // AR 경로 시각화로 전달
        ARPathRenderer.Instance.RenderPath(path);
    }
}

3. A* 결과를 AR로 시각화

ARPathRenderer.cs