我试图从Docker中运行的烧瓶应用程序打开相机时会遇到此错误: 172.17.0.1-- [17/MAR/2025 11:24:10]“ GET/HTTP/1.1” 200- [2025-03-17 11:24:19,498]应用中的错误:exce ...

问题描述 投票:0回答:1
我的代码:

def detect_faces_api(): timestamp = int(time.time()) video_capture = cv2.VideoCapture(0,cv2.CAP_DSHOW) image = request.files['image'] image_path = '/face_app/'+str(timestamp)+ '.jpg' image.save(image_path) result = detect_faces(image_path, video_capture) video_capture.release() cv2.destroyAllWindows()
我需要在Linux服务器中运行此应用程序
有人可以帮我吗?

在我的计算机上运行时,该应用程序正常运行,但我在Docker中会遇到此错误 我确实有video_capture = cv2.VIDEOCAPTURE(0),但我得到了错误

72.17.0.1 - - [14/Mar/2025 15:45:53] "GET / HTTP/1.1" 200 -
[ WARN:[email protected]] global cap_v4l.cpp:913 open VIDEOIO(V4L2:/dev/video0): can''t open camera by index
[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:158 getStreamChannelGroup Camera index out of range
[2025-03-14 15:46:02,507] ERROR in app: Exception on /detect_faces [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/face_app/face_recognition_.py", line 113, in detect_faces_api
    result = detect_faces(image_path, video_capture)
  File "/face_app/face_recognition_.py", line 48, in detect_faces
    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
cv2.error: OpenCV(4.11.0) /io/opencv/modules/imgproc/src/resize.cpp:4208: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

I还尝试了CV2.VIDECAPTURE(1),CV2.VIDEOCAPTURE(2),CV2.VIDECAPTURE(-1),CV2.VIDECAPTURE(1,CV2.CAP_V4L2)和所有内容

我的dockerfile

FROM python:3.9-slim RUN apt-get update && apt-get install -y \ build-essential \ cmake \ gfortran \ wget \ libboost-all-dev \ libatlas-base-dev \ libopenblas-dev \ liblapack-dev \ libx11-dev \ tesseract-ocr \ libgl1-mesa-glx \ libglib2.0-0 \ libsm6 \ libxrender1 \ libxext6 \ && rm -rf /var/lib/apt/lists/* COPY requirements.txt /face_app/ RUN pip install --no-cache-dir -r /face_app/requirements.txt WORKDIR /face_app COPY . /face_app EXPOSE 5000 ENV NAME=World CMD ["python", "face_recognition_.py"]
docker build -t docker-face-app.

我如何运行该应用程序:

docker Run -P 5000:5000 Docker-Face-App

我的错误是两次打电话给视频贴

ERROR in app: Exception on /detect_faces [POST]

制定整个程序停止

将图像路径和删除视频捕获在函数之外固定了错误,并且在这种情况下CV2.VIDECAPTURE(0,CV2.CAP_DSHOW)是正确的:)

python linux docker opencv flask
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.