()
copy image and process using CUDA
copy image and process using CUDA
copy image and process using CUDA
def process_image():
    """ copy image and process using CUDA """
    global pycuda_source_pbo,source_pbo,current_size, dest_pbo
    image_width, image_height = current_size
    assert source_pbo is not None

    # tell cuda we are going to get into these buffers
    pycuda_source_pbo.unregister()

    # activate destination buffer
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, int(source_pbo))

    # read data into pbo. note: use BGRA format for optimal performance
    glReadPixels(
             0,                  #start x
             0,                  #start y
             image_width,        #end   x
             image_height,       #end   y
             GL_BGRA,            #format
             GL_UNSIGNED_BYTE,   #output type
             ctypes.c_void_p(0))

    pycuda_source_pbo = cuda_gl.BufferObject(int(source_pbo))

    # run the Cuda kernel
    process(image_width, image_height)
    # blit convolved texture onto the screen
    # download texture from PBO
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, int(dest_pbo))
    glBindTexture(GL_TEXTURE_2D, output_texture)

    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
                    image_width, image_height,
                    GL_BGRA, GL_UNSIGNED_BYTE, ctypes.c_void_p(0))
def process_image ( ) : global pycuda_source_pbo , source_pbo , current_size , dest_pbo image_width , image_height = current_size assert source_pbo is not None # tell cuda we are going to get into these buffers pycuda_source_pbo . unregister ( ) # activate destination buffer glBindBufferARB ( GL_PIXEL_PACK_BUFFER_ARB , int ( source_pbo ) ) # read data into pbo. note: use BGRA format for optimal performance glReadPixels ( 0 , #start x 0 , #start y image_width , #end   x image_height , #end   y GL_BGRA , #format GL_UNSIGNED_BYTE , #output type ctypes . c_void_p ( 0 ) ) pycuda_source_pbo = cuda_gl . BufferObject ( int ( source_pbo ) ) # run the Cuda kernel process ( image_width , image_height ) # blit convolved texture onto the screen # download texture from PBO glBindBuffer ( GL_PIXEL_UNPACK_BUFFER_ARB , int ( dest_pbo ) ) glBindTexture ( GL_TEXTURE_2D , output_texture ) glTexSubImage2D ( GL_TEXTURE_2D , 0 , 0 , 0 , image_width , image_height , GL_BGRA , GL_UNSIGNED_BYTE , ctypes . c_void_p ( 0 ) )