Пример #1
0
    def load_headers(self, filepath):
        #print("Loading Headers")
        self.kernel_file = open(filepath, "r")
        buildDir = self.getDir(filepath)

        self.build_options = "-I " + buildDir
        self.build_options = self.build_options + " -D VGL_SHAPE_NCHANNELS={0}".format(
            vl.VGL_SHAPE_NCHANNELS())
        self.build_options = self.build_options + " -D VGL_SHAPE_WIDTH={0}".format(
            vl.VGL_SHAPE_WIDTH())
        self.build_options = self.build_options + " -D VGL_SHAPE_HEIGTH={0}".format(
            vl.VGL_SHAPE_HEIGTH())
        self.build_options = self.build_options + " -D VGL_SHAPE_LENGTH={0}".format(
            vl.VGL_SHAPE_LENGTH())
        self.build_options = self.build_options + " -D VGL_MAX_DIM={0}".format(
            vl.VGL_MAX_DIM())
        self.build_options = self.build_options + " -D VGL_ARR_SHAPE_SIZE={0}".format(
            vl.VGL_ARR_SHAPE_SIZE())
        self.build_options = self.build_options + " -D VGL_ARR_CLSTREL_SIZE={0}".format(
            vl.VGL_ARR_CLSTREL_SIZE())
        self.build_options = self.build_options + " -D VGL_STREL_CUBE={0}".format(
            vl.VGL_STREL_CUBE())
        self.build_options = self.build_options + " -D VGL_STREL_CROSS={0}".format(
            vl.VGL_STREL_CROSS())
        self.build_options = self.build_options + " -D VGL_STREL_GAUSS={0}".format(
            vl.VGL_STREL_GAUSS())
        self.build_options = self.build_options + " -D VGL_STREL_MEAN={0}".format(
            vl.VGL_STREL_MEAN())

        # READING THE HEADER FILES BEFORE COMPILING THE KERNEL
        while (buildDir):
            for file in glob.glob(buildDir + "/*.h"):
                #print(file)
                self.pgr = cl.Program(self.ctx, open(file, "r"))

            buildDir = self.getDir(buildDir)
Пример #2
0
	msg = ""

	# INPUT IMAGE
	img_input = vl.VglImage(sys.argv[1], None, vl.VGL_IMAGE_2D_IMAGE(), vl.IMAGE_ND_ARRAY())
	vl.vglLoadImage(img_input)
	vl.vglClUpload(img_input)

	# OUTPUT IMAGE
	img_output = vl.create_blank_image_as(img_input)
	img_output.set_oclPtr( vl.get_similar_oclPtr_object(img_input) )
	vl.vglAddContext(img_output, vl.VGL_CL_CONTEXT())

	# STRUCTURANT ELEMENT
	window = vl.VglStrEl()
	window.constructorFromTypeNdim(vl.VGL_STREL_CROSS(), 2)

	inicio = t.time()
	vglClNdCopy(img_input, img_output)
	fim = t.time()
	vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT())
	vl.vglSaveImage("img-vglNdCopy.jpg", img_output)
	msg = msg + "Tempo de execução do método vglClNdCopy:\t" +str( round( (fim-inicio), 9 ) ) +"s\n"

	inicio = t.time()
	vglClNdConvolution(img_input, img_output, window)
	fim = t.time()
	vl.vglCheckContext(img_output, vl.VGL_RAM_CONTEXT())
	vl.vglSaveImage("img-vglNdConvolution.jpg", img_output)
	msg = msg + "Tempo de execução do método vglClNdConvolution:\t" +str( round( (fim-inicio), 9 ) ) +"s\n"
Пример #3
0
    def constructorFromTypeNdim(self, Type, ndim):
        shape = np.zeros(vl.VGL_MAX_DIM(), np.int32)
        shape[0] = 1
        shape[2] = 1

        for i in range(1, ndim + 1):  # ndim+1 cuz in c++ is for i <= ndim
            shape[i] = 3

        vglShape = vl.VglShape()
        vglShape.constructorFromShapeNdimBps(shape, ndim)

        size = vglShape.getSize()
        data = np.zeros((size), np.float32)
        index = 0

        if (Type == vl.VGL_STREL_CROSS()):
            coord = np.zeros((vl.VGL_ARR_SHAPE_SIZE()), np.int32)

            for i in range(0, size):
                data[i] = np.float32(0.0)

            for d in range(1, ndim + 1):
                coord[d] = np.int32(1)

            index = vglShape.getIndexFromCoord(coord)
            data[index] = np.float32(1.0)

            for d in range(1, ndim + 1):
                coord[d] = np.int32(0)
                index = vglShape.getIndexFromCoord(coord)
                data[index] = np.float32(1.0)

                coord[d] = np.int32(2)
                index = vglShape.getIndexFromCoord(coord)
                data[index] = np.float32(1.0)

                coord[d] = 1

        elif (Type == vl.VGL_STREL_GAUSS()):
            coord = np.zeros((vl.VGL_ARR_SHAPE_SIZE()), np.int32)
            coord[0] = np.int32(0)
            size = vglShape.getSize()

            for i in range(0, size):
                val = np.float32(1.0)
                vglShape.getCoordFromIndex(i, coord)

                for d in range(1, ndim + 1):
                    if (coord[d] == 1):
                        val = val * np.float32(0.5)
                    else:
                        val = val * np.float32(0.25)

                data[i] = val

        elif (Type == vl.VGL_STREL_MEAN()):
            for i in range(0, size):
                data[i] = 1.0 / size

        elif (Type == vl.VGL_STREL_CUBE()):
            for i in range(0, size):
                data[i] = 1.0
        else:
            for i in range(0, size):
                data[i] = 1.0

        self.constructorFromDataVglShape(data, vglShape)