Sorry, my previous post had a mistake with the variable names of the GpuMats
I have reduced the code down to less than 50 lines of code, I hope this constitutes a minimum reproducible example
my issue with this code is the same error again
File "C:\Users\fdasfasdfasd\Documents\test.py, line 45, in <module>
openglcudamat.copyTo(outputcudamat) # copy the OpenGL texture from temporary CUDA GpuMat
cv2.error: OpenCV(4.10.0) D:\repos\opencv\opencv-python\opencv\modules\core\src\cuda\gpu_mat.cu:270: error: (-217:Gpu API call) invalid argument in function 'cv::cuda::GpuMat::copyTo'
import numpy as np
from OpenGL.GL import *
import cv2
import pygame
height = 480
width = 640
#pygame
#-----------------------
pygame.init()
pygame.display.set_caption('Texture Receiver Example')
pygame.display.set_mode((width, height),
pygame.OPENGL | pygame.DOUBLEBUF)
TextureID = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, TextureID)
#--------------------------------
pbo = glGenBuffers(1) # create a pixel buffer object
openglframe =np.random.randint(low=0,high=255,size=(height,width,4)) # array with the resolution of the image I want to use, in 4 channels for RGBA, used for the byte size of glBufferData
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo)
glBufferData(GL_PIXEL_PACK_BUFFER,openglframe , GL_DYNAMIC_READ) # configures the pixel buffer
openglcudamatcudamat = cv2.cuda.GpuMat(height,width,cv2.CV_8UC3) # temporary texture used for mapping the address from OpenGL as a CUDA GpuMat
outputcudamat = cv2.cuda.GpuMat(height,width,cv2.CV_8UC3) # the OpenGL texture should end up as this CUDA GpuMat
glActiveTexture(GL_TEXTURE0) # activate the OpenGL texture slot
glBindTexture(GL_TEXTURE_2D, TextureID) # selects the texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, openglframe) # Load the image into OpenGL
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo) #selects the pixel buffer
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE,0)
# After this is the Python part
mapdata = glMapBuffer(GL_PIXEL_PACK_BUFFER,GL_READ_ONLY) # returns a ctype pointer of the pixel buffer
openglcudamat=cv2.cuda.createGpuMatFromCudaMemory(rows=height,cols=width,type=cv2.CV_8UC4,cudaMemoryAddress=mapdata)
openglcudamat.copyTo(outputcudamat) # copy the OpenGL texture from temporary CUDA GpuMat
# And finally, unmap the pixel buffer in OpenGl
glUnmapBuffer(GL_PIXEL_PACK_BUFFER)
outputimage = outputcudamat.download()
cv2.imshow("test",outputimage)
print (outputimage)