示例#1
0
    def draw(self, p0, p1):
        Brush.draw(self, p0, p1)
        #self.probFg(x1-20, x1+20, y1-20, y1+20)
        #return
        """color = self.colorTri[self.type]

        #self.argsScore[5] = np.int32(self.nComponentsFg)

        #seed = []
        hasSeeds = False
        redoBg = False

        minX = sys.maxint
        maxX = -sys.maxint
        minY = sys.maxint
        maxY = -sys.maxint

        for point in self.points[0:nPoints]:
            #if self.hTriFlat[point] != color:
                self.hTriFlat[point] = color
                #seed += point
                hasSeeds = True

                minX = min(minX, point%self.width)

                maxX = max(maxX, point%self.width)
                minY = min(minY, point/self.width)
                maxY = max(maxY, point/self.width)

                #if (point[1]*self.width + point[0]) in self.randIdx:

                #	redoBg = True
        #if redoBg:
        #	self.probBg(0)

        #if len(seed) == 0:
        if not hasSeeds:
            return

        minX = max(0, minX-DILATE)
        maxX = min(self.width-1, maxX + DILATE)
        minY = max(0, minY-DILATE)
        maxY = min(self.height-1, maxY + DILATE)
        """

        args = [
            np.int32(self.n_points),
            self.d_points,
            cl.Sampler(self.context, False, cl.addressing_mode.NONE,
                cl.filter_mode.NEAREST),
            self.d_img,
            self.dSampleFg
        ]

        gWorksize = roundUp((self.n_points, ), (256, ))

        self.kern_get_samples(self.queue, gWorksize, (256,), *args).wait()

        cl.enqueue_copy(self.queue, self.hSampleFg, self.dSampleFg)
#        print self.hSampleFg.view(np.uint8).reshape(10240, 4)[0:self.n_points, :]

#        print self.n_points
        self.gmmFg.fit(self.dSampleFg, self.n_points)
#        print w
#        print m
#        print c

        self.gmmFg.score(self.d_img, self.dScoreFg)

        #        self.argsSampleBg = [
        #            self.d_labels,
        #            np.int32(self.label),
        #            cl.Sampler(self.context, False, cl.addressing_mode.NONE,
        #                cl.filter_mode.NEAREST),
        #            self.d_img,
        #            self.dSampleFg
        #        ]
        #
        #        gWorksize = roundUp(self.dim, (16, 16))
        #
        #        self.kernSampleBg(self.queue, gWorksize, (16, 16),
        #            *(self.argsSampleBg)).wait()
        #        cl.enqueue_copy(self.queue, self.hSampleBg, self.dSampleBg).wait()

        pass
示例#2
0
import time

import pyopencl as cl
from clutil import Buffer2D
import numpy as np

platforms = cl.get_platforms()

devices = platforms[0].get_devices()
devices = [devices[1]]
context = cl.Context(devices)

cm = cl.mem_flags

dim = (800, 608)

dStrokes = Buffer2D(context, cm.READ_WRITE, dim, dtype=np.uint8)

from Brush import Brush

brush = Brush(context, devices, dStrokes)

iterations = 10

t0 = time.clock()
for i in range(iterations):
    brush.draw((0, 0), (100, 100))
dt = (time.clock() - t0) / iterations * 1000

print "%.2f milliseconds per iteration (mean)" % dt