I am writing a module which gets cv::cuda::GpuMat data on gpu and draw it on QOpenGLWidget. To accelarate the speed, I want to avoid downloading data from device to host.
The error tells “OpenCV(4.6.0) Error: Gpu API call (OS call failed or operation not supported on this OS) in `anonymous-namespace’::CudaResource::registerBuffer, file D:\lib\opencv_my\source\opencv-4.6.0\modules\core\src\opengl.cpp, line 176”
But if I use the cv::ogl::texture2D::copyFrom(cv::Mat) instead of cv::ogl::texture2D::copyFrom(cv::cuda::GpuMat), it can work well.
I read some source code of opencv and find the error is appear at here:
Thanks! And I tried the code you given. But it shows the same error
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.6.0) Error: Gpu API call (OS call failed or operation not supported on this OS) in `anonymous-namespace'::CudaResource::registerBuffer, file D:\lib\opencv_my\source\opencv-4.6.0\modules\core\src\opengl.cpp, line 176
I guess it is because of the cuda environment, but I can’t find more information about the error.
!!! I use the same code in my vs+cuda+opencv project. And it can work without error and show an image.
Can you run bin\opencv_test_cudaarithm.exe --gtest_filter=OpenGL/Texture2D.Constructor1/0 without errors? e.g.
[ RUN ] OpenGL/Texture2D.Constructor1/0, where GetParam() = (128x128, 8UC1)
[ OK ] OpenGL/Texture2D.Constructor1/0 (2926 ms)
[----------] 1 test from OpenGL/Texture2D (2927 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (3090 ms total)
[ PASSED ] 1 test.
Do any of the tests from opencv_test_cudaarithm.exe report that they have PASSED
OpenCV version: 4.6.0
OpenCV VCS version: unknown
Build type: Debug Release
WARNING: build value differs from runtime: Release
Compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe (ver 19.32.31329.0)
Parallel framework: ms-concurrency (nthreads=16)
CPU features: SSE? SSE2? SSE3?
Intel(R) IPP version: disabled
OpenCL is disabled
TEST: Skip tests with tags: 'mem_6gb', 'verylong'
Note: Google Test filter = OpenGL/Texture2D.Constructor1/0
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from OpenGL/Texture2D
[ RUN ] OpenGL/Texture2D.Constructor1/0, where GetParam() = (128x128, 8UC1)
[ OK ] OpenGL/Texture2D.Constructor1/0 (3 ms)
[----------] 1 test from OpenGL/Texture2D (3 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (172 ms total)
[ PASSED ] 1 test.
I guess the problem is on my qt project environment. Because my visual studio project with opencv+cuda doesn’t have the error.
wow. I create a clickbutton on mainWidget and connect the signal and the test code as slot funtion. I think this doesn’t matter.
Could you please show me you .pro file?
And this is my .prg file.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
# ===========opengl==============
QT += opengl
QT += core gui openglwidgets
QT += widgets
# ===============================
# ============opencv=============
INCLUDEPATH += D:\lib\opencv_my\build\install\include
#LIBS += D:\lib\opencv_my\build\install\x64\vc17\lib
LIBS += D:\lib\opencv_my\build\install\x64\vc17\lib\opencv_world460.lib
# ===============================
# ============eigen============
INCLUDEPATH += D:\lib\eigen-3.4.0
# =============================
# ============cuda=============
CUDA_DIR = $$(CUDA_PATH)
#message($${CUDA_DIR})
INCLUDEPATH += $${CUDA_DIR}/include
# =============================
# ============vtk==============
#LIBS += D:\lib\VTK-8.2.0\build\install_prefix\lib
# =============================
DISTFILES += \
draw_image.frag \
draw_image.vert