# Luxonis OAK

이 [Luxonis OAK (OpenCV AI Kit)](https://shop.luxonis.com/) 는 임베디드 컴퓨터 비전 시스템 배포에 널리 사용되는 edge device입니다.

OAK device는 다운스트림 애플리케이션의 작동을 구동하는 host machine과 함께 사용됩니다. 흥미로운 영감을 얻고 싶다면 [Luxonis의 use cases](https://docs.luxonis.com/en/latest/#example-use-cases) 및 [Roboflow의 case studies](https://blog.roboflow.com/tag/case-studies/).

**참고로:** 아직 OAK device가 없다면, [Roboflow Store를 통해 구매하여](https://store.roboflow.com/) 10% 할인을 받을 수 있습니다.

### Task 지원

다음 task type은 hosted API에서 지원됩니다:

| Task Type                                                                                                                                        | Luxonis OAK Deployment에서 지원됨 |
| ------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- |
| <p>Object Detection:</p><ul><li>Roboflow에서 학습된 YOLOv8 모델(모든 크기: Nano, Small, Medium, Large, X Large)</li><li>Roboflow에서 학습된 YOLOv11 모델</li></ul> | ✅                            |
| Classification                                                                                                                                   |                              |
| Instance Segmentation                                                                                                                            |                              |
| Semantic Segmentation                                                                                                                            |                              |

### Luxonis OAK에 Model 배포하기

#### 지원되는 Luxonis Device 및 Host 요구 사항

Roboflow Inference Server는 다음 device를 지원합니다:

* OAK-D
* OAK-D-Lite
* OAK-D-POE
* OAK-1 (depth 없음)

#### 설치

다음을 설치하세요 `roboflowoak`, `depthai`, 및 `opencv-python` 패키지:

```python
pip install roboflowoak
pip install depthai
pip install opencv-python
```

이제 `roboflowoak` 패키지를 사용하여 custom trained Roboflow model을 실행할 수 있습니다.

#### Inference 실행: Deployment

Depth 기능이 없는 OAK device에 배포하는 경우, `depth=False` 를 `rf` object를 인스턴스화(생성)할 때 설정하세요. Depth가 있는 OAK에는 모델 이름에 "D"가 붙습니다. 예: OAK-D 및 OAK-D-Lite.

또한, `max_depth = np.amax(depth)` 및 `cv2.imshow("depth", depth/max_depth)`

```python
from roboflowoak import RoboflowOak
import cv2
import time
import numpy as np

if __name__ == '__main__':
    # RoboflowOak 모듈로 object(rf) 인스턴스화
    rf = RoboflowOak(model="YOUR-MODEL-ID", confidence=0.05, overlap=0.5,
    version="YOUR-MODEL-VERSION-#", api_key="YOUR-PRIVATE_API_KEY", rgb=True,
    depth=True, device=None, blocking=True)
    # 모델을 실행하고 detection이 포함된 video output 표시
    while True:
        t0 = time.time()
        # rf.detect() 함수는 model inference를 실행합니다
        result, frame, raw_frame, depth = rf.detect()
        predictions = result["predictions"]
        #{
        #    predictions:
        #    [ {
        #        x: (중앙),
        #        y:(중앙),
        #        width:
        #        height:
        #        depth: ###->
        #        confidence:
        #        class:
        #        mask: {
        #    ]
        #}
        #frame - prediction이 포함된 전처리 후 frame
        #raw_frame - OAK의 원본 frame
        #depth - raw_frame용 depth map, center camera의 중심에 맞게 rectified됨
        
        # timing: benchmarking 목적
        t = time.time()-t0
        print("FPS ", 1/t)
        print("PREDICTIONS ", [p.json() for p in predictions])

        # depth 계산을 위한 parameter 설정
        # Depth가 없는 OAK를 사용하는 경우 아래 2줄을 주석 처리하세요
        max_depth = np.amax(depth)
        cv2.imshow("depth", depth/max_depth)
        # 연속된 frame으로 video feed 표시
        cv2.imshow("frame", frame)
    
        # OAK inference window를 닫는 방법 / inference 중지: CTRL+q 또는 CTRL+c
        if cv2.waitKey(1) == ord('q'):
            break
```

아래 코드를 입력하세요(placeholder 텍스트를 Python script 경로로 바꾼 후)

```python
# 창을 닫으려면(inference를 중단하거나 종료하려면) 키보드에서 CTRL+c를 입력하세요
python3 /path/to/[YOUR-PYTHON-FILE].py
```

host device로 Apple Macbook Air (M1)를 사용했을 때 inference 속도(밀리초 기준)는 평균 약 15ms, 즉 66 FPS였습니다. ***참고**: OAK와 함께 사용하는 host device는 FPS에 큰 영향을 미칩니다. 시스템을 만들 때 이 점을 고려하세요.*

#### 문제 해결

OAK device 설정 중 문제가 발생하면 Luxonis의 installation instructions를 방문하고, [Luxonis installation](https://docs.luxonis.com/en/latest/#demo-script)에서 RGB example을 성공적으로 실행할 수 있는지 확인하세요. 또한 [Roboflow Forum](https://discuss.roboflow.com/).

### 참고 자료

* [단계별 Luxonis OAK setup guide](https://blog.roboflow.com/opencv-ai-kit-deployment/)
* [M1 Chip 사용 시 installation issue · Issue #299 · luxonis/depthai · GitHub](https://github.com/luxonis/depthai/issues/299) (depthai SDK)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roboflow.com/roboflow/roboflow-ko/deploy/sdks/luxonis-oak.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
