hybridgroup / gocv

Go package for computer vision using OpenCV 4 and beyond. Includes support for DNN, CUDA, OpenCV Contrib, and OpenVINO.
https://gocv.io
Other
6.75k stars 869 forks source link

Opening an RTSP stream fails when using gocv/opencv docker image for arm64 #1076

Open treygilliland opened 1 year ago

treygilliland commented 1 year ago

I have been using the Dockerfile on gocv/opencv for amd64 for a while to read from an RTSP stream and it has worked totally fine. I am now trying to use the arm64 image and it fails to open the RTSP stream successfully.

Description

Steps to Reproduce

  1. Run the gocv/opencv docker image on an arm device with docker run -it --rm gocv/opencv:4.7.0 bash
  2. Add these files to a directory such as /code

main.go:

package main

import (
        "fmt"
        "gocv.io/x/gocv"
)

func main() {
        fmt.Printf("connecting...\n")

        webcam, err := gocv.OpenVideoCapture("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4")
        if err != nil {
                fmt.Printf("connect fail: %s\n", err)
        }

        fmt.Printf("connected successfully!\n")
}

go.mod:

module main

go 1.20

require gocv.io/x/gocv v0.32.1
  1. Run go mod tidy to download dependencies
  2. Run the code with the following command to get OpenCV debug logs OPENCV_LOG_LEVEL=DEBUG go run main.go

Your Environment

Other

arm output:

[DEBUG:0@0.003] global videoio_registry.cpp:206 VideoBackendRegistry VIDEOIO: Builtin backends(8): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); UEYE(940); OBSENSOR(930)
[DEBUG:0@0.003] global videoio_registry.cpp:230 VideoBackendRegistry VIDEOIO: Available backends(8): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); UEYE(940); OBSENSOR(930)
[ INFO:0@0.003] global videoio_registry.cpp:232 VideoBackendRegistry VIDEOIO: Enabled backends(8, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); UEYE(940); OBSENSOR(930)
[ INFO:0@0.003] global backend_plugin.cpp:369 getPluginCandidates VideoIO plugin (FFMPEG): glob is 'libopencv_videoio_ffmpeg*.so', 1 location(s)
[ INFO:0@0.005] global backend_plugin.cpp:379 getPluginCandidates     - /usr/local/lib: 0
[ INFO:0@0.005] global backend_plugin.cpp:383 getPluginCandidates Found 0 plugin(s) for FFMPEG
[ INFO:0@0.005] global backend_plugin.cpp:369 getPluginCandidates VideoIO plugin (GSTREAMER): glob is 'libopencv_videoio_gstreamer*.so', 1 location(s)
[ INFO:0@0.005] global backend_plugin.cpp:379 getPluginCandidates     - /usr/local/lib: 0
[ INFO:0@0.005] global backend_plugin.cpp:383 getPluginCandidates Found 0 plugin(s) for GSTREAMER
[ INFO:0@0.005] global backend_plugin.cpp:369 getPluginCandidates VideoIO plugin (INTEL_MFX): glob is 'libopencv_videoio_intel_mfx*.so', 1 location(s)
[ INFO:0@0.006] global backend_plugin.cpp:379 getPluginCandidates     - /usr/local/lib: 0
[ INFO:0@0.006] global backend_plugin.cpp:383 getPluginCandidates Found 0 plugin(s) for INTEL_MFX
[DEBUG:0@0.006] global cap_v4l.cpp:990 open VIDEOIO(V4L2:rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4): opening...
[DEBUG:0@0.006] global cap_v4l.cpp:1006 open VIDEOIO(V4L2:rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4): deviceHandle=-1
[ INFO:0@0.006] global cap_images.cpp:282 icvExtractPattern Pattern: rtsp://wowzaec2demo.streamlock.net/vod/mp%01d:BigBuckBunny_115k.mp4 @ 4
connect fail: Error opening file: rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4

amd output:

[DEBUG:0@0.003] global videoio_registry.cpp:206 VideoBackendRegistry VIDEOIO: Builtin backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); FIREWIRE(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@0.003] global videoio_registry.cpp:230 VideoBackendRegistry VIDEOIO: Available backends(9): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); FIREWIRE(940); UEYE(930); OBSENSOR(920)
[ INFO:0@0.003] global videoio_registry.cpp:232 VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); FIREWIRE(940); UEYE(930); OBSENSOR(920)
[DEBUG:0@1.683] global cap_ffmpeg_impl.hpp:1168 open FFMPEG: stream[1] is video stream with codecID=27 width=240 height=160
[DEBUG:0@1.683] global cap_ffmpeg_hw.hpp:934 HWAccelIterator FFMPEG: allowed acceleration types (none): ''
connected successfully!
treygilliland commented 1 year ago

Patch fix for now is rebuilding opencv at the start of the docker image:

FROM gocv/opencv:4.6.0-arm64 as base

ARG OPENCV_VERSION=4.5.4
ENV OPENCV_VERSION=4.5.4

RUN curl -Lo opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
    unzip -q opencv.zip && \
    curl -Lo opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
    unzip -q opencv_contrib.zip && \
    rm opencv.zip opencv_contrib.zip && \
    cd opencv-${OPENCV_VERSION} && \
    mkdir build && cd build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D WITH_IPP=OFF \
          -D WITH_OPENGL=OFF \
          -D WITH_QT=OFF \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
          -D OPENCV_ENABLE_NONFREE=ON \
          -D WITH_JASPER=OFF \
          -D WITH_JPEG=ON \
          -D WITH_TBB=ON \
          -D BUILD_DOCS=OFF \
          -D BUILD_EXAMPLES=OFF \
          -D BUILD_TESTS=OFF \
          -D BUILD_PERF_TESTS=OFF \
          -D BUILD_opencv_java=NO \
          -D BUILD_opencv_python=NO \
          -D BUILD_opencv_python2=NO \
          -D BUILD_opencv_python3=NO \
          -D OPENCV_GENERATE_PKGCONFIG=ON \
          .. && \
    make -j $(nproc --all) && \
    make preinstall && make install && \
    ldconfig && \
    cd / && rm -rf opencv*
treygilliland commented 1 year ago

@deadprogram any idea as to why this is the case? I spent some more time with this problem today. 4.7.0 works fine when opening a VideoCapture on an RTSP stream on amd64, but not arm64. It seems to have something to do with the V4L2 backend but not sure.

When I specify to use the ffmpeg backed and run apt-get install ffmpeg, again amd64 works fine and arm64 fails.

It would be really great to use the same image tag across both architectures if possible so I don't have to maintain separate Dockerfiles.

Thanks!

gbaranski commented 1 year ago

Same issue here.