Пример #1
0
class ModelWMCam(Model, Renderable):
    def initMaps(self, size):
        model = 'spike'
        self.size = size
        dt = 0.6
        wrap = True
        model_ = 'spike'
        #Input
        self.webcam = WebcamMap("Webcam", size=size, dt=dt, numDevice=0)
        self.color_select = ImageColorSelection("Color Select",
                                                size,
                                                dt=dt,
                                                thresh=5)

        mapSize = 0.3
        #Excitatory Memory
        self.fieldE = MapDNF("ExcitatoryField",
                             size,
                             dt=dt,
                             mapSize=mapSize,
                             model='spike',
                             iExc=2.2,
                             iInh=1.5,
                             wExc=0.1 / 2.,
                             wInh=0.2 / 2.)
        #Inhibition memory
        self.fieldI = MapDNF("InhibitoryField",
                             size,
                             dt=dt,
                             mapSize=mapSize,
                             model='spike',
                             iExc=2.2,
                             iInh=1.5,
                             wExc=0.1 / 2.,
                             wInh=0.2 / 2.,
                             h=-0.6)
        #artificial gaussian to bost inhbitory
        center = (size - 1) / 2
        self.gauss = ShortStim("ArtificialOnClickGaussian",
                               size=size,
                               dt=dt,
                               wrap=wrap,
                               timeout=0,
                               intensity=0.,
                               width=0.1,
                               centerX=center,
                               centerY=center)
        #TODO add unlimited amount of input to field
        self.add_gauss_and_input = FuncWithoutKeywords(
            utils.sumArrays, "InputAndArtificialGaussian", size=size, dt=dt)
        self.add_gauss_and_input.addChildren(gauss=self.gauss,
                                             input=self.color_select)

        #Exc - Inh
        self.substract = FuncMap2D(utils.subArrays, "Exc - Inh", size, dt=0.1)

        #Neural field selection
        self.field = MapDNF("DNF", size, model='spike')

        #Link maps

        self.color_select.addChildren(image=self.webcam)
        self.aff = self.color_select

        #Excitatory
        self.fieldE.addChildren(aff=self.aff)

        #Inhibitory
        self.fieldI.addChildren(aff=self.add_gauss_and_input)

        #Exc - Inh
        self.substract.addChildren(a=self.fieldE.getActivation(),
                                   b=self.fieldI.getActivation())
        #Neural field

        self.field.addChildren(aff=self.substract)

        #return the root
        return self.field

    def getArrays(self):
        ret = [
            self.webcam,
            self.aff,
            self.substract,
            self.add_gauss_and_input,
            self.fieldI.getActivation(),
            self.fieldE.getActivation(),
            self.field.getActivation(),
        ]
        return ret

    def onClick(self, mapName, x, y):
        if mapName == "Webcam":
            bgr = self.webcam.getData()

            sizeROI = self.size / 10.
            s2 = int(round(sizeROI / 2.))
            roi = bgr[y - s2:y + s2, x - s2:x + s2, :]
            hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
            colorVal = np.median(hsv[:, :, 0])
            satHigh = np.max(hsv[:, :, 1])
            satLow = np.min(hsv[:, :, 1])
            valHigh = np.max(hsv[:, :, 2])
            valLow = np.min(hsv[:, :, 2])
            self.color_select.setArg(colorVal=colorVal,
                                     satLow=satLow,
                                     satHigh=satHigh)
            return "Color Select"
        elif mapName == "InputAndArtificialGaussian":
            time = self.gauss.getArg('time')
            self.gauss.setParams(centerX=x,
                                 centerY=y,
                                 intensity=1.,
                                 timeout=time + 1)
Пример #2
0
class ModelFingerDetection(Model, Renderable):
    def initMaps(self):
        """We initiate the map and link them"""
        #Create maps
        size = self.globalParams['size']

        self.webcam = WebcamMap(size)
        self.color_select = ImageColorSelection(size)
        self.onOff1 = OnOffFilter(size=60,
                                  onIntXY=(1, 1),
                                  onStdXY=(0.1, 0.5),
                                  offIntXY=(0.7, 0.7),
                                  offStdXY=(0.1, 0.5),
                                  shift=0.2)
        self.onOff2 = OnOffFilter(size=20,
                                  onIntXY=(1, 1),
                                  onStdXY=(0.1, 0.5),
                                  offIntXY=(0.7, 0.7),
                                  offStdXY=(0.1, 0.5),
                                  shift=0.2)

        self.convo1 = Convolution(size)
        self.convo2 = Convolution(size)
        self.aff = FuncWithoutKeywords(utils.sumArrays, size)

        #Link maps
        self.webcam.registerOnGlobalParamsChange(dt='dt')

        self.color_select.registerOnGlobalParamsChange(
            dt='dt',
            color='color',
            reverseColors='reverseColors',
            color_threshold='color_threshold')
        self.color_select.addChildren(image=self.webcam)

        self.onOff1.registerOnGlobalParamsChange(dt='kernel_dt')
        self.onOff2.registerOnGlobalParamsChange(dt='kernel_dt')

        self.convo1.registerOnGlobalParamsChange(dt='dt', wrap='wrap')
        self.convo2.registerOnGlobalParamsChange(dt='dt', wrap='wrap')
        self.convo1.addChildren(source=self.color_select, kernel=self.onOff1)
        self.convo2.addChildren(source=self.color_select, kernel=self.onOff2)

        self.aff.registerOnGlobalParamsChange_ignoreCompute(dt='dt')
        self.aff.addChildren(
            color=self.color_select,
            convo1=self.convo1,
            convo2=self.convo2,
        )

        #Update args
        self.aff.updateParams(self.globalParams)

        #Compute onOff once and for all
        self.onOff1.artificialRecursiveComputation()
        self.onOff2.artificialRecursiveComputation()

        #return the root
        return self.aff

    def getArraysDict(self):
        return dict(webcam=self.webcam.getData(),
                    aff=self.aff.getData(),
                    onOff1=self.onOff1.getData(),
                    onOff2=self.onOff2.getData(),
                    convo1=self.convo1.getData(),
                    convo2=self.convo2.getData(),
                    color=self.color_select.getData())