def vglClBinConway(self, img_input, img_output): vl.vglCheckContext(img_input, vl.VGL_CL_CONTEXT()) vl.vglCheckContext(img_output, vl.VGL_CL_CONTEXT()) _program = self.cl_ctx.get_compiled_kernel( "../CL_BIN/vglClBinConway.cl", "vglClBinConway") kernel_run = _program.vglClBinConway mobj_img_shape = img_input.getVglShape().get_asVglClShape_buffer() kernel_run.set_arg(0, img_input.get_oclPtr()) kernel_run.set_arg(1, img_output.get_oclPtr()) kernel_run.set_arg(2, mobj_img_shape) _worksize_0 = img_input.getWidthIn() if (img_input.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_input.getWidthStep() if (img_output.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_output.getWidthStep() worksize = (int(_worksize_0), img_input.getHeigthIn(), img_input.getNFrames()) cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, worksize, None) #cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, img_output.get_oclPtr().shape, None) vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())
def vglClNdBinThreshold(self, img_input, img_output, thresh): if (not img_input.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinThreshold: Error: this function supports only OpenCL data as buffer and img_input isn't." ) exit() if (not img_output.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinThreshold: Error: this function supports only OpenCL data as buffer and img_output isn't." ) exit() if (not isinstance(thresh, np.uint8)): print( "vglClNdBinThreshold: Warning: thresh not np.uint8! Trying to convert..." ) try: thresh = np.uint8(thresh) except Exception as e: print( "vglClNdBinThreshold: Error!! Impossible to convert thresh as a np.uint8 object." ) print(str(e)) exit() vl.vglCheckContext(img_input, vl.VGL_CL_CONTEXT()) vl.vglCheckContext(img_output, vl.VGL_CL_CONTEXT()) _program = self.cl_ctx.get_compiled_kernel( "../CL_BIN/vglClNdBinThreshold.cl", "vglClNdBinThreshold") kernel_run = _program.vglClNdBinThreshold mobj_img_shape_input = img_input.getVglShape().get_asVglClShape_buffer( ) mobj_img_shape_output = img_output.getVglShape( ).get_asVglClShape_buffer() kernel_run.set_arg(0, img_input.get_oclPtr()) kernel_run.set_arg(1, img_output.get_oclPtr()) kernel_run.set_arg(2, thresh) kernel_run.set_arg(3, mobj_img_shape_input) kernel_run.set_arg(4, mobj_img_shape_output) _worksize_0 = img_input.getWidthIn() if (img_input.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_input.getWidthStep() if (img_output.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_output.getWidthStep() worksize = (int(_worksize_0), img_input.getHeigthIn(), img_input.getNFrames()) # ENQUEUEING KERNEL EXECUTION #cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, worksize, None) cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, img_output.ipl.shape, None) vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())
def vglClNdBinMin(self, img_input, img_input2, img_output): if (not img_input.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinMin: Error: this function supports only OpenCL data as buffer and img_input isn't." ) exit() if (not img_input2.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinMin: Error: this function supports only OpenCL data as buffer and img_input isn't." ) exit() if (not img_output.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinMin: Error: this function supports only OpenCL data as buffer and img_output isn't." ) exit() vl.vglCheckContext(img_input, vl.VGL_CL_CONTEXT()) vl.vglCheckContext(img_input2, vl.VGL_CL_CONTEXT()) vl.vglCheckContext(img_output, vl.VGL_CL_CONTEXT()) if (not isinstance(window, vl.VglStrEl)): print( "vglClNdBinMin: Error: window is not a VglStrEl object. aborting execution." ) exit() _program = self.cl_ctx.get_compiled_kernel( "../CL_BIN/vglClNdBinMin.cl", "vglClNdBinMin") kernel_run = _program.vglClNdBinMin kernel_run.set_arg(0, img_input.get_oclPtr()) kernel_run.set_arg(1, img_input2.get_oclPtr()) kernel_run.set_arg(2, img_output.get_oclPtr()) _worksize_0 = img_input.getWidthIn() if (img_input.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_input.getWidthStep() if (img_input2.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_input2.getWidthStep() if (img_output.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_output.getWidthStep() worksize = (int(_worksize_0), img_input.getHeigthIn(), img_input.getNFrames()) # ENQUEUEING KERNEL EXECUTION #cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, worksize, None) cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, img_output.get_ipl().shape, None) vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())
def vglClNdBinDilatePack(self, img_input, img_output, window): if (not img_input.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinDilatePack: Error: this function supports only OpenCL data as buffer and img_input isn't." ) exit() if (not img_output.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinDilatePack: Error: this function supports only OpenCL data as buffer and img_output isn't." ) exit() vl.vglCheckContext(img_input, vl.VGL_CL_CONTEXT()) vl.vglCheckContext(img_output, vl.VGL_CL_CONTEXT()) if (not isinstance(window, vl.VglStrEl)): print( "vglClNdBinDilatePack: Error: window is not a VglStrEl object. aborting execution." ) exit() _program = self.cl_ctx.get_compiled_kernel( "../CL_BIN/vglClNdBinDilatePack.cl", "vglClNdBinDilatePack") kernel_run = _program.vglClNdBinDilatePack # CREATING OPENCL BUFFER TO VglStrEl and VglShape mobj_window = window.get_asVglClStrEl_buffer() mobj_img_shape = img_input.getVglShape().get_asVglClShape_buffer() # SETTING ARGUMENTS kernel_run.set_arg(0, img_input.get_oclPtr()) kernel_run.set_arg(1, img_output.get_oclPtr()) kernel_run.set_arg(2, mobj_img_shape) kernel_run.set_arg(3, mobj_window) _worksize_0 = img_input.getWidthIn() if (img_input.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_input.getWidthStep() if (img_output.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_output.getWidthStep() worksize = (int(_worksize_0), img_input.getHeigthIn(), img_input.getNFrames()) # ENQUEUEING KERNEL EXECUTION #cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, worksize, None) cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, img_output.get_ipl().shape, None) vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())
def vglClNdBinToGray(self, img_input, img_output): if (not img_input.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinToGray: Error: this function supports only OpenCL data as buffer and img_input isn't." ) exit() if (not img_output.clForceAsBuf == vl.IMAGE_ND_ARRAY()): print( "vglClNdBinToGray: Error: this function supports only OpenCL data as buffer and img_output isn't." ) exit() vl.vglCheckContext(img_input, vl.VGL_CL_CONTEXT()) vl.vglCheckContext(img_output, vl.VGL_CL_CONTEXT()) _program = self.cl_ctx.get_compiled_kernel( "../CL_BIN/vglClNdBinToGray.cl", "vglClNdBinToGray") kernel_run = _program.vglClNdBinToGray mobj_img_shape_input = img_input.getVglShape().get_asVglClShape_buffer( ) mobj_img_shape_output = img_output.getVglShape( ).get_asVglClShape_buffer() kernel_run.set_arg(0, img_input.get_oclPtr()) kernel_run.set_arg(1, img_output.get_oclPtr()) kernel_run.set_arg(2, mobj_img_shape_input) kernel_run.set_arg(3, mobj_img_shape_output) _worksize_0 = img_input.getWidthIn() if (img_input.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_input.getWidthStep() if (img_output.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_output.getWidthStep() #worksize = (np.int32(_worksize_0), img_input.getHeigthIn(), img_input.getNFrames() ) # ENQUEUEING KERNEL EXECUTION #cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, worksize, None) cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, img_output.ipl.shape, None) vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())
def iplFindWidthStep(depth, width, channels=1): if( depth == vl.IPL_DEPTH_1U() ): return (width - 1) / (8 + 1) bpp = vl.iplFindBitsPerSample(depth) if(bpp < 8): print("iplFindWidthStep: Error: bits per pixel=", bpp, "and != 1. Image depth may be wrong.") exit(1) return (depth / 8) * channels * width
def vglClBinThreshold(self, img_input, img_output, thresh): vl.vglCheckContext(img_input, vl.VGL_CL_CONTEXT()) vl.vglCheckContext(img_output, vl.VGL_CL_CONTEXT()) if (not isinstance(thresh, np.float32)): print( "vglClBinThreshold: Warning: thresh not np.float32! Trying to convert..." ) try: thresh = np.float32(thresh) except Exception as e: print( "vglClBinThreshold: Error!! Impossible to convert thresh as a np.float32 object." ) print(str(e)) exit() _program = self.cl_ctx.get_compiled_kernel( "../CL_BIN/vglClBinThreshold.cl", "vglClBinThreshold") kernel_run = _program.vglClBinThreshold kernel_run.set_arg(0, img_input.get_oclPtr()) kernel_run.set_arg(1, img_output.get_oclPtr()) kernel_run.set_arg(2, thresh) _worksize_0 = img_input.getWidthIn() if (img_input.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_input.getWidthStep() if (img_output.depth == vl.IPL_DEPTH_1U()): _worksize_0 = img_output.getWidthStep() worksize = (int(_worksize_0), img_input.getHeigthIn(), img_input.getNFrames()) cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, worksize, None) #cl.enqueue_nd_range_kernel(self.ocl.commandQueue, kernel_run, img_output.get_oclPtr().shape, None) vl.vglSetContext(img_output, vl.VGL_CL_CONTEXT())
def __init__(self, imgPath="", depth=None, ndim=None, clForceAsBuf=None ): # IF THE IMAGE TYPE IS NOT SPECIFIED, A 2D IMAGE WILL BE ASSUMED # INICIALIZING DATA self.ipl = None self.ndim = ndim self.shape = np.zeros((2*vl.VGL_MAX_DIM()), np.uint8) self.vglShape = None self.depth = depth self.nChannels = 0 self.has_mipmap = 0 self.oclPtr = None self.clForceAsBuf = clForceAsBuf self.inContext = 0 self.filename = imgPath # NOT IMPLEMENTED IN PYTHON-SIDE self.fbo = -1 self.tex = -1 self.cudaPtr = None self.cudaPbo = -1 if( self.depth == None ): self.depth = vl.IPL_DEPTH_1U() if( self.clForceAsBuf is None ): self.clForceAsBuf = vl.IMAGE_CL_OBJECT() elif( not((self.clForceAsBuf is vl.IMAGE_CL_OBJECT() ) or (self.clForceAsBuf is vl.IMAGE_ND_ARRAY() ) ) ): print("VglImage: Error! Unexistent image treatment. Use vl.IMAGE_CL_OBJECT() or vl.IMAGE_ND_ARRAY()!") exit() if(self.ndim is None): self.ndim = vl.VGL_IMAGE_2D_IMAGE() print(":Assuming 2D Image!") elif(self.ndim is vl.VGL_IMAGE_2D_IMAGE()): print(":Creating 2D Image!") elif(self.ndim is vl.VGL_IMAGE_3D_IMAGE()): print(":Creating 3D Image!") else: print("vglImage: Warning! Image is not 2D or 3D. Execution will continue.") print(":::-->path", imgPath) print(":::-->dept", depth) print(":::-->ndim", ndim) print(":::-->forc", clForceAsBuf)