jjunyuongv commited on
Commit
9602c19
·
1 Parent(s): b2df149

Fix: Add libGL library to Dockerfile for OpenCV

Browse files
Files changed (3) hide show
  1. Dockerfile +9 -1
  2. app.py +5 -1
  3. requirements.txt +1 -1
Dockerfile CHANGED
@@ -2,10 +2,18 @@ FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
 
 
 
 
 
 
 
 
5
  COPY requirements.txt .
6
 
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  COPY . .
10
 
11
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # [중요] OpenCV/MediaPipe 실행을 위한 시스템 라이브러리 설치
6
+ # libgl1-mesa-glx: libGL.so.1 에러 해결
7
+ # libglib2.0-0: 추가적인 의존성 에러 방지
8
+ RUN apt-get update && apt-get install -y \
9
+ libgl1-mesa-glx \
10
+ libglib2.0-0 \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
  COPY requirements.txt .
14
 
15
  RUN pip install --no-cache-dir -r requirements.txt
16
 
17
  COPY . .
18
 
19
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -21,6 +21,10 @@ async def analyze_pose(image: UploadFile = File(...)):
21
  data = await image.read()
22
  pil_image = Image.open(io.BytesIO(data)).convert("RGB")
23
  np_img = np.array(pil_image)
 
 
 
 
24
  bgr = np_img[:, :, ::-1]
25
 
26
  result = pose.process(bgr)
@@ -40,4 +44,4 @@ async def analyze_pose(image: UploadFile = File(...)):
40
  return {"landmarks": landmarks}
41
 
42
  except Exception as e:
43
- return {"error": str(e)}
 
21
  data = await image.read()
22
  pil_image = Image.open(io.BytesIO(data)).convert("RGB")
23
  np_img = np.array(pil_image)
24
+
25
+ # MediaPipe는 RGB를 사용하지만, OpenCV 기반 변환이 필요할 수 있어 BGR로 변환
26
+ # (일반적인 MediaPipe 사용 예제에서는 RGB를 넣지만, cv2 함수를 섞어 쓸 때 주의 필요)
27
+ # 작성하신 코드대로라면 BGR로 변환해서 넣고 있습니다.
28
  bgr = np_img[:, :, ::-1]
29
 
30
  result = pose.process(bgr)
 
44
  return {"landmarks": landmarks}
45
 
46
  except Exception as e:
47
+ return {"error": str(e)}
requirements.txt CHANGED
@@ -2,4 +2,4 @@ fastapi
2
  uvicorn
3
  mediapipe==0.10.9
4
  numpy
5
- Pillow
 
2
  uvicorn
3
  mediapipe==0.10.9
4
  numpy
5
+ Pillow