Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the example with gpu+imshow [+opengl] #25579

Closed
wants to merge 3 commits into from
Closed

Conversation

bjornborg
Copy link

Patches the example of passing gpumat to GUI.

It does not fix the underlying issue with imshow, opengl, and cuda gpumat when trying to render the GPU data to the window, but by specifying the texture size (through window resize) the rendering will be correct.

Furthermore, cv::imshow("GPU", cv::ogl::Texture2D(d_frame)); should be avoided since it causes memory leak.

Relates to
#22336
#4644
#22328

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@cudawarped
Copy link
Contributor

cudawarped commented May 14, 2024

It does not fix the underlying issue with imshow, opengl, and cuda gpumat when trying to render the GPU data to the window, but by specifying the texture size (through window resize) the rendering will be correct.

The existing code has a memory leak but the sample doesn't throw an exception. By passing a GpuMat directly to cv::imshow the sample will now crash because of #22328.

Wouldn't it be better to remove all the references to OpenGL as the workaround for #22328 causes a memory leak so it is not recommended to pass cv::imshow device memory?

@bjornborg
Copy link
Author

If you compile with QT6+opengl+cuda, passing in the gpumat for rendering does work. It took me a while to debug to figure out why sometimes the rendering won't work, and sometimes it would.

@cudawarped
Copy link
Contributor

If you compile with QT6+opengl+cuda,

Can the check also test for the presence of QT6?

@bjornborg
Copy link
Author

I don't know which test you are referring to, but here is the build info:

[main] Configuring project: opencv 
[proc] Executing command: /usr/bin/cmake --no-warn-unused-cli -DBUILD_EXAMPLES=ON -DBUILD_opencv_apps=OFF -DBUILD_opencv_rgbd=OFF -DBUILD_opencv_cvv=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=OFF -DENABLE_FAST_MATH=ON -DWITH_QT=ON -DWITH_GTK=OFF -DWITH_WAYLAND=OFF -DOpenGL_GL_PREFERENCE=GLVND -DWITH_OPENGL=ON -DOPENCV_ENABLE_NONFREE=ON -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -DOPENCV_GENERATE_PKGCONFIG=ON -DENABLE_CUDA_FIRST_CLASS_LANGUAGE=ON -DCUDA_GENERATION=Auto -DWITH_CUBLAS=ON -DCUDA_FAST_MATH=ON -DWITH_CUDA=ON -DWITH_NVCUVID=ON -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ -S/home/bjornborg/git/opencv -B/home/bjornborg/git/opencv/build -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Detected processor: x86_64
[cmake] -- Looking for ccache - found (/usr/bin/ccache)
[cmake] -- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
[cmake] -- OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.9.0-dev-openjp2-2.5.0
[cmake] -- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
[cmake] -- found Intel IPP (ICV version): 2021.11.0 [2021.11.0]
[cmake] -- at: /home/bjornborg/git/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
[cmake] -- found Intel IPP Integration Wrappers sources: 2021.11.0
[cmake] -- at: /home/bjornborg/git/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
[cmake] -- Could NOT find CUDNN (missing: CUDNN_LIBRARY CUDNN_INCLUDE_DIR) (Required is at least version "7.5")
[cmake] -- Found NVCUVID: /usr/lib/x86_64-linux-gnu/libnvcuvid.so
[cmake] -- Found NVCUVENC:  /usr/lib/x86_64-linux-gnu/libnvidia-encode.so
[cmake] -- CUDA: NVCC target flags -D_FORCE_INLINES
[cmake] -- LAPACK(LAPACK/clapack): LAPACK_LIBRARIES: /usr/lib/x86_64-linux-gnu/libopenblas.so;-lm;-ldl
[cmake] CMake Warning at cmake/OpenCVFindLAPACK.cmake:29 (message):
[cmake]   LAPACK(LAPACK/clapack): CBLAS/LAPACK headers are not found in
[cmake]   '/home/bjornborg/git/opencv/3rdparty/clapack/include'
[cmake] Call Stack (most recent call first):
[cmake]   cmake/OpenCVFindLAPACK.cmake:222 (ocv_lapack_check)
[cmake]   CMakeLists.txt:824 (include)
[cmake] 
[cmake] 
[cmake] -- Could NOT find Java (missing: Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVADOC_EXECUTABLE) (found version "21.0.3")
[cmake] -- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 AWT) 
[cmake] -- Could NOT find Flake8 (missing: FLAKE8_EXECUTABLE) 
[cmake] -- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
[cmake] -- Checking for module 'libavresample'
[cmake] --   Package 'libavresample', required by 'virtual:world', not found
[cmake] -- freetype2:   YES (ver 26.1.20)
[cmake] -- harfbuzz:    YES (ver 8.3.0)
[cmake] -- Julia not found. Not compiling Julia Bindings. 
[cmake] -- Module opencv_ovis disabled because OGRE3D was not found
[cmake] -- CERES support is disabled. Ceres Solver for reconstruction API is required.
[cmake] -- Checking for module 'tesseract'
[cmake] --   Package 'tesseract', required by 'virtual:world', not found
[cmake] -- Tesseract:   NO
[cmake] -- Allocator metrics storage type: 'long long'
[cmake] -- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
[cmake] -- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
[cmake] -- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/bjornborg/git/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
[cmake] -- opencv_dnn: filter out cuda4dnn source code
[cmake] -- Excluding from source files list: modules/dnn/src/layers/cpu_kernels/conv_winograd_f63.neon.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.rvv.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon_fp16.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.rvv.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.lasx.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_winograd_f63.neon_fp16.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.neon.cpp
[cmake] -- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.lasx.cpp
[cmake] -- highgui: using builtin backend: QT6
[cmake] -- GAPI VPL samples with VAAPI
[cmake] -- CERES support is disabled. Ceres Solver for reconstruction API is required.
[cmake] -- Building with NVIDIA Optical Flow API 2.0
[cmake] -- Found 'misc' Python modules from /home/bjornborg/git/opencv/modules/python/package/extra_modules
[cmake] -- Found 'mat_wrapper;utils' Python modules from /home/bjornborg/git/opencv/modules/core/misc/python/package
[cmake] -- Found 'gapi' Python modules from /home/bjornborg/git/opencv/modules/gapi/misc/python/package
[cmake] -- Found 'misc' Python modules from /home/bjornborg/git/opencv/modules/python/package/extra_modules
[cmake] -- Found 'mat_wrapper;utils' Python modules from /home/bjornborg/git/opencv/modules/core/misc/python/package
[cmake] -- Found 'gapi' Python modules from /home/bjornborg/git/opencv/modules/gapi/misc/python/package
[cmake] -- SYCL/OpenCL samples are skipped: SYCL SDK is required
[cmake] --    - check configuration of SYCL_DIR/SYCL_ROOT/CMAKE_MODULE_PATH
[cmake] --    - ensure that right compiler is selected from SYCL SDK (e.g, clang++): CMAKE_CXX_COMPILER=/usr/bin/g++
[cmake] -- Registered 'check_pylint' target: using /usr/bin/pylint (ver: 3.0.3), checks: 194
[cmake] -- 
[cmake] -- General configuration for OpenCV 4.9.0-dev =====================================
[cmake] --   Version control:               4.9.0-461-gca17aa9ccd
[cmake] -- 
[cmake] --   Extra modules:
[cmake] --     Location (extra):            /home/bjornborg/git/opencv/opencv_contrib/modules
[cmake] --     Version control (extra):     4.9.0-68-g3c2bcbfe
[cmake] -- 
[cmake] --   Platform:
[cmake] --     Timestamp:                   2024-05-13T11:10:52Z
[cmake] --     Host:                        Linux 6.8.0-31-generic x86_64
[cmake] --     CMake:                       3.28.3
[cmake] --     CMake generator:             Ninja
[cmake] --     CMake build tool:            /usr/bin/ninja
[cmake] --     Configuration:               Release
[cmake] -- 
[cmake] --   CPU/HW features:
[cmake] --     Baseline:                    SSE SSE2 SSE3
[cmake] --       requested:                 SSE3
[cmake] --     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
[cmake] --       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
[cmake] --       SSE4_1 (16 files):         + SSSE3 SSE4_1
[cmake] --       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
[cmake] --       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
[cmake] --       AVX (8 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
[cmake] --       AVX2 (36 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
[cmake] --       AVX512_SKX (5 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
[cmake] -- 
[cmake] --   C/C++:
[cmake] --     Built as dynamic libs?:      YES
[cmake] --     C++ standard:                11
[cmake] --     C++ Compiler:                /usr/bin/g++  (ver 13.2.0)
[cmake] --     C++ flags (Release):         -fsigned-char -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
[cmake] --     C++ flags (Debug):           -fsigned-char -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
[cmake] --     C Compiler:                  /usr/bin/gcc
[cmake] --     C flags (Release):           -fsigned-char -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
[cmake] --     C flags (Debug):             -fsigned-char -ffast-math -fno-finite-math-only -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
[cmake] --     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
[cmake] --     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
[cmake] --     ccache:                      YES
[cmake] --     Precompiled headers:         NO
[cmake] --     Extra dependencies:          /usr/lib/x86_64-linux-gnu/libcudart_static.a /usr/lib/x86_64-linux-gnu/libnppial.so /usr/lib/x86_64-linux-gnu/libnppc.so /usr/lib/x86_64-linux-gnu/libnppitc.so /usr/lib/x86_64-linux-gnu/libnppig.so /usr/lib/x86_64-linux-gnu/libnppist.so /usr/lib/x86_64-linux-gnu/libnppidei.so /usr/lib/x86_64-linux-gnu/libcublas.so /usr/lib/x86_64-linux-gnu/libcublasLt.so /usr/lib/x86_64-linux-gnu/libcufft.so /usr/lib/x86_64-linux-gnu/libnppicc.so /usr/lib/x86_64-linux-gnu/libnppif.so /usr/lib/x86_64-linux-gnu/libnppim.so dl m pthread rt
[cmake] --     3rdparty dependencies:
[cmake] -- 
[cmake] --   OpenCV modules:
[cmake] --     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg saliency sfm shape signal stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
[cmake] --     Disabled:                    cvv rgbd world
[cmake] --     Disabled by dependency:      -
[cmake] --     Unavailable:                 cannops java julia matlab ovis python2 ts viz
[cmake] --     Applications:                examples
[cmake] --     Documentation:               NO
[cmake] --     Non-free algorithms:         YES
[cmake] -- 
[cmake] --   GUI:                           QT6
[cmake] --     QT:                          YES (ver 6.4.2 )
[cmake] --       QT OpenGL support:         YES (Qt6::OpenGL )
[cmake] --     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libOpenGL.so /usr/lib/x86_64-linux-gnu/libGLX.so /usr/lib/x86_64-linux-gnu/libGLU.so)
[cmake] --     VTK support:                 NO
[cmake] -- 
[cmake] --   Media I/O: 
[cmake] --     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.3)
[cmake] --     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
[cmake] --     WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x020f)
[cmake] --     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.43)
[cmake] --     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.5.1)
[cmake] --     JPEG 2000:                   build (ver 2.5.0)
[cmake] --     OpenEXR:                     OpenEXR::OpenEXR (ver 3.1.5)
[cmake] --     HDR:                         YES
[cmake] --     SUNRASTER:                   YES
[cmake] --     PXM:                         YES
[cmake] --     PFM:                         YES
[cmake] -- 
[cmake] --   Video I/O:
[cmake] --     DC1394:                      YES (2.2.6)
[cmake] --     FFMPEG:                      YES
[cmake] --       avcodec:                   YES (60.31.102)
[cmake] --       avformat:                  YES (60.16.100)
[cmake] --       avutil:                    YES (58.29.100)
[cmake] --       swscale:                   YES (7.5.100)
[cmake] --       avresample:                NO
[cmake] --     GStreamer:                   YES (1.24.2)
[cmake] --     v4l/v4l2:                    YES (linux/videodev2.h)
[cmake] -- 
[cmake] --   Parallel framework:            pthreads
[cmake] -- 
[cmake] --   Trace:                         YES (with Intel ITT)
[cmake] -- 
[cmake] --   Other third-party libraries:
[cmake] --     Intel IPP:                   2021.11.0 [2021.11.0]
[cmake] --            at:                   /home/bjornborg/git/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
[cmake] --     Intel IPP IW:                sources (2021.11.0)
[cmake] --               at:                /home/bjornborg/git/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
[cmake] --     VA:                          YES
[cmake] --     Lapack:                      NO
[cmake] --     Eigen:                       YES (ver 3.4.0)
[cmake] --     Custom HAL:                  NO
[cmake] --     Protobuf:                    build (3.19.1)
[cmake] --     Flatbuffers:                 builtin/3rdparty (23.5.9)
[cmake] -- 
[cmake] --   NVIDIA CUDA:                   YES (ver 12.0.140, CUFFT CUBLAS NVCUVID NVCUVENC FAST_MATH)
[cmake] --     NVIDIA GPU arch:             86
[cmake] --     NVIDIA PTX archs:
[cmake] -- 
[cmake] --   cuDNN:                         NO
[cmake] -- 
[cmake] --   OpenCL:                        YES (INTELVA)
[cmake] --     Include path:                /home/bjornborg/git/opencv/3rdparty/include/opencl/1.2
[cmake] --     Link libraries:              Dynamic load
[cmake] -- 
[cmake] --   Python 3:
[cmake] --     Interpreter:                 /usr/bin/python3 (ver 3.12.3)
[cmake] --     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.12.so (ver 3.12.3)
[cmake] --     Limited API:                 NO
[cmake] --     numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.26.4)
[cmake] --     install path:                lib/python3.12/dist-packages/cv2/python-3.12
[cmake] -- 
[cmake] --   Python (for build):            /usr/bin/python3
[cmake] -- 
[cmake] --   Java:                          
[cmake] --     ant:                         NO
[cmake] --     Java:                        NO
[cmake] --     JNI:                         NO
[cmake] --     Java wrappers:               NO
[cmake] --     Java tests:                  NO
[cmake] -- 
[cmake] --   Install to:                    /usr/local
[cmake] -- -----------------------------------------------------------------
[cmake] -- 
[cmake] -- Configuring done (6.4s)
[cmake] -- Generating done (1.4s)
[cmake] -- Build files have been written to: /home/bjornborg/git/opencv/build

@@ -20,24 +21,26 @@ int main(int argc, const char* argv[])
return -1;

const std::string fname(argv[1]);
cv::VideoCapture reader(fname);
cv::Size imageSize{(int)reader.get(cv::CAP_PROP_FRAME_WIDTH),
(int)reader.get(cv::CAP_PROP_FRAME_HEIGHT)};

cv::namedWindow("CPU", cv::WINDOW_NORMAL);
#if defined(HAVE_OPENGL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this (#if defined(HAVE_OPENGL)) also check for the presence of QT6 if this crashes the sample without it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reader nor the imageSize is dependent on the QT6. Is it crashing on this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reader is moved in earlier from below from the previous sample code, to extract the image size of the frames.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if defined(HAVE_OPENGL)
        cv::imshow("GPU", d_frame);
#else
        d_frame.download(frame);
        cv::imshow("GPU", frame);
#endif

According to your previous comment, if OpenCV is built against OpenGL but not against QT6 `cv::imshow("GPU", d_frame) will cause the sample to crash. To prevent this you need to be able to check for QT6 at compile or runtime. e.g.

#if defined(HAVE_OPENGL) && defined(HAVE_QT6)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked for other GUI backends and I was assuming to work similarly. But I can add the check to enforce QT6 guard.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is HAVE_QT6 defined? It is not in #include "cvconfig.h".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is HAVE_QT6 defined? It is not in #include "cvconfig.h".

I don't think it is, it was an example of the test that needs to be performed.

The point of my comments is that you have taken a sample which doen't crash when run and converted it into a sample that will crash when using the default GUI backend which most users will have compiled OpenCV against. Do you think this will be useful to people who run the sample who don't realize they need QT6, or do you think they will see the crash and assume the cudacodec::VideoReader class has a bug?

Copy link
Author

@bjornborg bjornborg May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should split the sample into two then, one purely for demonstrating cudacodec::VideoReader parsing, and other using opengl+gpumat for imshow. Would this be clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the new sample still crashes then I don't think its clearer.

There are several options, not limited to:

  1. Find a way to check for working GUI backends at compile/runtime. If the GUI's are plugins then I would have thought you could do this at runtime.
  2. Check for exceptions and print an informative message combined with a flag to enable or disable calling cv::imshow with a GpuMat.
  3. ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now introduced a new flag HAVE_QT_OPENGL for checking both qt and opengl in the new commit. Please have a look.

@cudawarped
Copy link
Contributor

cudawarped commented May 15, 2024

@bjornborg Looking at the code I'm not sure if the inteded behaviour is for this to work when OpenGL is used in combination with QT, it looks like it works under these circumstances becauase it falls through the initial checks when there is a different back end (not Win32) but I may be wrong. @opencv-alalek is this correct?

If so I would remove all code which uses WINDOW_OPENGL in conjunction with GpuMat's because it is likely to break in the future.

@bjornborg
Copy link
Author

Well, it beats me if it wasn't intended to work. It has been working for some time when OpenGL + QT + cuda combination is enabled on Linux, and it is quite efficient at rendering as well.

@bjornborg bjornborg closed this May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants