def initMaps(self, size): self.size = size dt = 0.6 # CREATE MAPS # 1st and 2nd webcam + possible perturbations self.webcam1 = WebcamMap("Webcam1", size, dt=dt, numDevice=0) self.playcam1 = PlayCamMap("PlayCam1", size) self.webcam2 = WebcamMap("Webcam2", size, dt=dt, numDevice=1) self.playcam2 = PlayCamMap("PlayCam2", size) # 1st webcam basic filtering: HSV color (outputing V) self.color_select = ImageColorSelection("ColorSelect", size, dt=dt) # one neural field per webcam self.field1 = MapDNF("DNF1", size, model='spike', dt=dt) self.field2 = MapDNF("DNF2", size, model='spike', dt=dt) # computing optical flows from both maps, then translating into colors self.flow1 = OpticalFlowMap("OpticalFlow1", size, dt=dt) self.flow2 = OpticalFlowMap("OpticalFlow2", size, dt=dt) self.ofBGR1 = OpticalFlowToBGR("OFtoBGR1", size=size, dt=dt) self.ofBGR2 = OpticalFlowToBGR("OFtoBGR2", size=size, dt=dt) # extracting average optical flow (1st webcam) under spikes as BGR coding, then filtering optical flow of webcam 2 accordingly self.ofColor = FlowDirectionSelect("SelectDir", size=1, dt=dt, globalSize=size, sampleSize=0.07) self.color_select2 = ImageColorSelection("OptFlowColorSelect", size, dt=dt, color='fullManu') # finally summing for webcam 2 the filtered color and the extracted optical flow (coded as color) self.aff2 = FuncWithoutKeywords(utils.sumArrays, "MixedModeInput", size, dt=dt) # LINK MAPS # from webcam 1 to DNF 1 self.playcam1.addChildren(image=self.webcam1) self.color_select.addChildren(image=self.playcam1) self.field1.addChildren(aff=self.color_select) # from webcam 1 to the extraction under spikes of the selected motion direction self.flow1.addChildren(img=self.playcam1) self.ofBGR1.addChildren(opticalFlow=self.flow1) self.ofColor.addChildren(flowBGR=self.ofBGR1, colorDNFAct=self.field1.getActivation()) # from webcam 2 to DNF 2, using the selected motion direction, and mixing with the color filtering self.playcam2.addChildren(image=self.webcam2) self.flow2.addChildren(img=self.playcam2) self.ofBGR2.addChildren(opticalFlow=self.flow2) self.color_select2.addChildren(image=self.ofBGR2, hsv=self.ofColor) self.aff2.addChildren(of=self.color_select2, col=self.color_select) self.field2.addChildren(aff=self.aff2) # compute the playCam to avoid some problems TODO fix self.playcam1.compute() self.playcam2.compute() #return the roots root = self.field2 return root
class ModelDNFCamFlow(Model,Renderable): def initMaps(self,size): self.size = size dt = 0.5 #Create maps self.webcam = WebcamMap("Webcam",size,dt=dt,numDevice=0) self.flow = OpticalFlowMap("OpticalFlow",size,dt=dt) self.channel = ChannelSelect("OFNorm",size,dt=dt,channel=0) self.abs = FuncMap2D(utils.abs,"OFIntensity",size,dt=dt) self.field = MapDNF("DNF",size,model='spike',dt=dt) self.test = OpticalFlowToBGR("test",size=size,dt=dt) #Link maps self.flow.addChildren(img=self.webcam) self.channel.addChildren(map=self.flow) self.abs.addChildren(x=self.channel) self.field.addChildren(aff=self.abs) self.test.addChildren(opticalFlow=self.flow) #return the root return [self.field,self.test] def getArrays(self): ret = [ self.webcam, self.abs, self.field, self.test, ] ret.extend(self.field.getArrays()) return ret def onClick(self,mapName,x,y): pass
def initMaps(self, size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs", size) self.field = MapDNF("DNF", size, model='spike') self.field.addChildren(aff=self.aff) #return the root return self.field
def initMaps(self, size): self.size = size dt = 0.6 #Create maps self.webcam1 = WebcamMap("Webcam1", size, dt=dt, numDevice=0) self.webcam1.compute() self.playcam1 = PlayCamMap("PlayCam1", size) self.webcam2 = WebcamMap("Webcam2", size, dt=dt, numDevice=0) self.webcam2.compute() self.playcam2 = PlayCamMap("PlayCam2", size) self.color_select = ImageColorSelection("ColorSelect", size, dt=dt) self.field1 = MapDNF("DNF1", size, model='spike', dt=dt) self.field2 = MapDNF("DNF2", size, model='spike', dt=dt) self.chan1 = ChannelSelect("chan1", size, dt=dt, channel=0) self.chan2 = ChannelSelect("chan2", size, dt=dt, channel=0) self.flow1 = OpticalFlowMap("OpticalFlow1", size, dt=dt) self.flow2 = OpticalFlowMap("OpticalFlow2", size, dt=dt) self.ofBGR1 = OpticalFlowToBGR("OFtoBGR1", size=size, dt=dt) self.ofBGR2 = OpticalFlowToBGR("OFtoBGR2", size=size, dt=dt) self.ofColor = FlowDirectionSelect("SelectDir", size=1, dt=dt, globalSize=size, sampleSize=0.07) self.color_select2 = ImageColorSelection("OptFlowColorSelect", size, dt=dt, color='fullManu') #Link maps self.playcam1.addChildren(image=self.webcam1) self.color_select.addChildren(image=self.playcam1) self.field1.addChildren(aff=self.color_select) self.flow1.addChildren(img=self.playcam1) self.ofBGR1.addChildren(opticalFlow=self.flow1) self.ofColor.addChildren(flowBGR=self.ofBGR1, colorDNFAct=self.field1.getActivation()) self.playcam2.addChildren(image=self.webcam2) self.flow2.addChildren(img=self.playcam2) self.ofBGR2.addChildren(opticalFlow=self.flow2) self.color_select2.addChildren(image=self.ofBGR2, hsv=self.ofColor) self.field2.addChildren(aff=self.color_select2) #compute the playCam to avoid some problems TODO fix self.playcam1.compute() self.playcam2.compute() #return the roots root = self.field2 return root
def initMaps(self,size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs",size) self.fieldCNFT = MapDNF("CNFT",size,model='cnft') self.fieldSpike = MapDNF("SpikingDNF",size,model='spike') self.fieldCNFT.addChildren(aff=self.aff) self.fieldSpike.addChildren(aff=self.aff) self.field = [self.fieldCNFT,self.fieldSpike] #return the root return self.field
def initMaps(self, size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs", size) self.fieldCNFT = MapDNF("CNFT", size, model='cnft') self.fieldSpike = MapDNF("SpikingDNF", size, model='spike') self.fieldCNFT.addChildren(aff=self.aff) self.fieldSpike.addChildren(aff=self.aff) self.field = [self.fieldCNFT, self.fieldSpike] #return the root return self.field
def initMaps(self,size): self.size = size dt = 0.6 #Create maps self.webcam1 = WebcamMap("Webcam1",size,dt=dt,numDevice=0) self.playcam1 = PlayCamMap("PlayCam1",size) self.webcam2 = WebcamMap("Webcam2",size,dt=dt,numDevice=0) self.playcam2 = PlayCamMap("PlayCam2",size) self.color_select = ImageColorSelection("ColorSelect",size,dt=dt) self.field1 = MapDNF("DNF1",size,model='spike',dt=dt) self.field2 = MapDNF("DNF2",size,model='spike',dt=dt) self.chan1 = ChannelSelect("chan1",size,dt=dt,channel=0) self.chan2 = ChannelSelect("chan2",size,dt=dt,channel=0) self.flow1 = OpticalFlowMap("OpticalFlow1",size,dt=dt) self.flow2 = OpticalFlowMap("OpticalFlow2",size,dt=dt) self.ofBGR1 = OpticalFlowToBGR("OFtoBGR1",size=size,dt=dt) self.ofBGR2 = OpticalFlowToBGR("OFtoBGR2",size=size,dt=dt) self.ofColor = FlowDirectionSelect("SelectDir",size=1,dt=dt,globalSize=size, sampleSize=0.07) self.color_select2 = ImageColorSelection("OptFlowColorSelect",size,dt=dt,color='fullManu') #Link maps self.playcam1.addChildren(image=self.webcam1) self.color_select.addChildren(image=self.playcam1) self.field1.addChildren(aff=self.color_select) self.flow1.addChildren(img=self.playcam1) self.ofBGR1.addChildren(opticalFlow=self.flow1) self.ofColor.addChildren(flowBGR=self.ofBGR1,colorDNFAct=self.field1.getActivation()) self.playcam2.addChildren(image=self.webcam2) self.flow2.addChildren(img=self.playcam2) self.ofBGR2.addChildren(opticalFlow=self.flow2) self.color_select2.addChildren(image=self.ofBGR2,hsv=self.ofColor) self.field2.addChildren(aff=self.color_select2) #compute the playCam to avoid some problems TODO fix self.playcam1.compute() self.playcam2.compute() #return the roots root = self.field2 return root
def initMaps(self, size): self.size = size dt = 0.6 #Create maps self.webcam = WebcamMap("Webcam", size, dt=dt, numDevice=0) self.webcam.compute() self.playcam = PlayCamMap("PlayCam", size) self.playcam.addChildren(image=self.webcam) self.color_select = ImageColorSelection("ColorSelect", size, dt=dt) self.field = MapDNF("DNF", size, model='spike', dt=dt) #Link maps self.color_select.addChildren(image=self.playcam) self.aff = self.color_select self.field.addChildren(aff=self.aff) #return the root return self.field
def initMaps(self,size=49,model="spike",nbStep=0, iExc=1.25,iInh=0.7,wExc=0.1,wInh=10.,alpha=10., ): """We initiate the map and link them""" # print("iExc : %s, iInh: %s, wExc %s, wInh %s"%(iExc,iInh,wExc,wInh)) dt = 0.1 self.aff = InputMap("Inputs",size) #iStim1 = 0, iStim2 = 0,noiseI=1.,noise_dt=1e10) self.field = MapDNF("DNF",size,model=model,nbStep=nbStep, \ iExc=iExc,iInh=iInh,wExc=wExc,wInh=wInh) self.field.addChildren(aff=self.aff) dt2 = 0.01 self.lat = Lateral("Lateral",size,dt=dt2,delta=0.02) self.exc = HppMap("exc",size,dt=dt2) self.inh = HppMap("inh",size,dt=dt2) self.lat.addChildren(exc=self.exc,inh=self.inh) self.field.lat = self.lat self.field.addChildren(lat=self.field.lat) self.exc.addChildren(source=self.field.act) self.inh.addChildren(source=self.field.act) #stats #self.stats = StatsList(size,self.aff,self.field.getActivation(), # self.field,shapeType='gauss') #return the roots roots = [self.field] #roots.extend(self.stats.getRoots()) return roots
def initMaps(self,size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs",size) self.field = MapDNF("DNF",size) self.field.addChildren(aff=self.aff) #return the root return self.field
class ModelDNF(Model,Renderable): def initMaps(self,size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs",size) self.field = MapDNF("DNF",size) self.field.addChildren(aff=self.aff) #return the root return self.field #override Renderable def getArrays(self): ret = [self.aff,self.field] ret.extend(self.field.getArrays()) return ret def onClick(self,mapName,x,y): print("clicked on %s, at coord %s,%s"%(unicode(mapName),x,y))
class ModelDNFCam(Model,Renderable): def initMaps(self,size): self.size = size dt = 0.6 #Create maps self.webcam = WebcamMap("Webcam",size,dt=dt,numDevice=0) self.webcam.compute() self.playcam = PlayCamMap("PlayCam",size) self.playcam.addChildren(image=self.webcam) self.color_select = ImageColorSelection("ColorSelect",size,dt=dt) self.field = MapDNF("DNF",size,model='spike',dt=dt) #Link maps self.color_select.addChildren(image=self.playcam) self.aff = self.color_select self.field.addChildren(aff=self.aff) #return the root return self.field def getArrays(self): ret = [ self.playcam, self.aff, self.field ] ret.extend(self.field.getArrays()) return ret def onClick(self,mapName,x,y): print("clicked on %s, at coord %s,%s"%(unicode(mapName),x,y)) if mapName == "PlayCam": bgr = self.playcam.getData() sizeROI = 1 #self.size/10. s2 = int(round(sizeROI/2.)) roi = bgr[y-s2:y+s2,x-s2:x+s2,:] # In BGR order 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) print("ColorVal = ",colorVal, "SatHigh", satHigh, "SatLow", satLow, "ValHigh", valHigh, "ValLow", valLow) return "ColorSelect"
class ModelDNFCam(Model,Renderable): def initMaps(self,size): self.size = size dt = 0.6 #Create maps self.webcam = WebcamMap("Webcam",size,dt=dt,numDevice=0) self.webcam.compute() self.playcam = PlayCamMap("PlayCam",size) self.playcam.addChildren(self.webcam) self.color_select = ImageColorSelection("ColorSelect",size,dt=dt) self.field = MapDNF("DNF",size,model='spike',dt=dt) #Link maps self.color_select.addChildren(image=self.playcam) self.aff = self.color_select self.field.addChildren(aff=self.aff) #return the root return self.field def getArrays(self): ret = [ self.playcam, self.aff, self.field ] ret.extend(self.field.getArrays()) return ret def onClick(self,mapName,x,y): print("clicked on %s, at coord %s,%s"%(unicode(mapName),x,y)) if mapName == "PlayCam": bgr = self.playcam.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 "ColorSelect"
class ModelDNF(Model, Renderable): def initMaps(self, size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs", size) self.field = MapDNF("DNF", size, model='spike') self.field.addChildren(aff=self.aff) #return the root return self.field #override Renderable def getArrays(self): ret = [self.aff, self.field] ret.extend(self.field.getArrays()) return ret def onClick(self, mapName, x, y): print("clicked on %s, at coord %s,%s" % (unicode(mapName), x, y))
class ModelHPP(Model,Renderable): def initMaps(self,size=49,model="spike",nbStep=0, iExc=1.25,iInh=0.7,wExc=0.1,wInh=10.,alpha=10., ): """We initiate the map and link them""" # print("iExc : %s, iInh: %s, wExc %s, wInh %s"%(iExc,iInh,wExc,wInh)) dt = 0.1 self.aff = InputMap("Inputs",size) #iStim1 = 0, iStim2 = 0,noiseI=1.,noise_dt=1e10) self.field = MapDNF("DNF",size,model=model,nbStep=nbStep, \ iExc=iExc,iInh=iInh,wExc=wExc,wInh=wInh) self.field.addChildren(aff=self.aff) dt2 = 0.01 self.lat = Lateral("Lateral",size,dt=dt2,delta=0.02) self.exc = HppMap("exc",size,dt=dt2) self.inh = HppMap("inh",size,dt=dt2) self.lat.addChildren(exc=self.exc,inh=self.inh) self.field.lat = self.lat self.field.addChildren(lat=self.field.lat) self.exc.addChildren(source=self.field.act) self.inh.addChildren(source=self.field.act) #stats #self.stats = StatsList(size,self.aff,self.field.getActivation(), # self.field,shapeType='gauss') #return the roots roots = [self.field] #roots.extend(self.stats.getRoots()) return roots #override Renderable def getArrays(self): ret = [self.aff,self.field,self.exc,self.inh] ret.extend(self.field.getArrays()) #ret.extend(self.stats.getArrays()) return ret def onClick(self,mapName,x,y): print("clicked on %s, at coord %s,%s"%(unicode(mapName),x,y))
def initMaps(self,size): self.size = size dt = 0.5 #Create maps self.webcam = WebcamMap("Webcam",size,dt=dt,numDevice=0) self.flow = OpticalFlowMap("OpticalFlow",size,dt=dt) self.channel = ChannelSelect("OFNorm",size,dt=dt,channel=0) self.abs = FuncMap2D(utils.abs,"OFIntensity",size,dt=dt) self.field = MapDNF("DNF",size,model='spike',dt=dt) self.test = OpticalFlowToBGR("test",size=size,dt=dt) #Link maps self.flow.addChildren(img=self.webcam) self.channel.addChildren(map=self.flow) self.abs.addChildren(x=self.channel) self.field.addChildren(aff=self.abs) self.test.addChildren(opticalFlow=self.flow) #return the root return [self.field,self.test]
def initMaps(self,size): self.size = size dt = 0.6 #Create maps self.webcam = WebcamMap("Webcam",size,dt=dt,numDevice=0) self.webcam.compute() self.playcam = PlayCamMap("PlayCam",size) self.playcam.addChildren(self.webcam) self.color_select = ImageColorSelection("ColorSelect",size,dt=dt) self.field = MapDNF("DNF",size,model='spike',dt=dt) #Link maps self.color_select.addChildren(image=self.playcam) self.aff = self.color_select self.field.addChildren(aff=self.aff) #return the root return self.field
class ModelDNFdual(Model,Renderable): def initMaps(self,size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs",size) self.fieldCNFT = MapDNF("CNFT",size,model='cnft') self.fieldSpike = MapDNF("SpikingDNF",size,model='spike') self.fieldCNFT.addChildren(aff=self.aff) self.fieldSpike.addChildren(aff=self.aff) self.field = [self.fieldCNFT,self.fieldSpike] #return the root return self.field #override Renderable def getArrays(self): ret = [self.aff,self.fieldCNFT,self.fieldSpike] ret.extend(self.fieldCNFT.getArrays()) ret.extend(self.fieldSpike.getArrays()) return ret
class ModelDNFdual(Model, Renderable): def initMaps(self, size): """We initiate the map and link them""" #Create maps self.aff = InputMap("Inputs", size) self.fieldCNFT = MapDNF("CNFT", size, model='cnft') self.fieldSpike = MapDNF("SpikingDNF", size, model='spike') self.fieldCNFT.addChildren(aff=self.aff) self.fieldSpike.addChildren(aff=self.aff) self.field = [self.fieldCNFT, self.fieldSpike] #return the root return self.field #override Renderable def getArrays(self): ret = [self.aff, self.fieldCNFT, self.fieldSpike] ret.extend(self.fieldCNFT.getArrays()) ret.extend(self.fieldSpike.getArrays()) return ret
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
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)
class ModelDNFDualCam2(Model,Renderable): def initMaps(self,size): self.size = size dt = 0.6 #Create maps self.webcam1 = WebcamMap("Webcam1",size,dt=dt,numDevice=0) self.playcam1 = PlayCamMap("PlayCam1",size) self.webcam2 = WebcamMap("Webcam2",size,dt=dt,numDevice=0) self.playcam2 = PlayCamMap("PlayCam2",size) self.color_select = ImageColorSelection("ColorSelect",size,dt=dt) self.field1 = MapDNF("DNF1",size,model='spike',dt=dt) self.field2 = MapDNF("DNF2",size,model='spike',dt=dt) self.ofBGR2 = OpticalFlowToBGR("OFtoBGR2",size=size,dt=dt) self.flow1 = OpticalFlowMap("OpticalFlow1",size,dt=dt) self.flow2 = OpticalFlowMap("OpticalFlow2",size,dt=dt) self.ofColor = FlowDirectionSelectHSV("SelectDir",size=1,dt=dt,globalSize=size, sampleSize=0.07) self.color_select2 = ImageColorSelection("OptFlowColorSelect",size,dt=dt,color='fullManu') #Link maps self.playcam1.addChildren(image=self.webcam1) self.color_select.addChildren(image=self.playcam1) self.field1.addChildren(aff=self.color_select) self.flow1.addChildren(img=self.playcam1) self.ofColor.addChildren(flow=self.flow1,colorDNFAct=self.field1.getActivation()) self.playcam2.addChildren(image=self.webcam2) self.flow2.addChildren(img=self.playcam2) self.ofBGR2.addChildren(opticalFlow=self.flow2) self.color_select2.addChildren(image=self.ofBGR2,hsv=self.ofColor) self.field2.addChildren(aff=self.color_select2) #compute the playCam to avoid some problems TODO fix self.playcam1.compute() self.playcam2.compute() #return the roots root = self.field2 return root def getArrays(self): ret = [ self.playcam1, self.color_select, self.field1.getActivation(), self.ofColor, self.playcam2, self.ofBGR2, self.color_select2, self.field2 ] return ret def onClick(self,mapName,x,y): print mapName.__class__ if mapName == "PlayCam1": bgr = self.playcam1.getData() sizeROI = self.size/10. s2 = 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 "ColorSelect"
class ModelDNFDualCam(Model, Renderable): def initMaps(self, size): self.size = size dt = 0.6 #Create maps self.webcam1 = WebcamMap("Webcam1", size, dt=dt, numDevice=0) self.webcam1.compute() self.playcam1 = PlayCamMap("PlayCam1", size) self.webcam2 = WebcamMap("Webcam2", size, dt=dt, numDevice=0) self.webcam2.compute() self.playcam2 = PlayCamMap("PlayCam2", size) self.color_select = ImageColorSelection("ColorSelect", size, dt=dt) self.field1 = MapDNF("DNF1", size, model='spike', dt=dt) self.field2 = MapDNF("DNF2", size, model='spike', dt=dt) self.chan1 = ChannelSelect("chan1", size, dt=dt, channel=0) self.chan2 = ChannelSelect("chan2", size, dt=dt, channel=0) self.flow1 = OpticalFlowMap("OpticalFlow1", size, dt=dt) self.flow2 = OpticalFlowMap("OpticalFlow2", size, dt=dt) self.ofBGR1 = OpticalFlowToBGR("OFtoBGR1", size=size, dt=dt) self.ofBGR2 = OpticalFlowToBGR("OFtoBGR2", size=size, dt=dt) self.ofColor = FlowDirectionSelect("SelectDir", size=1, dt=dt, globalSize=size, sampleSize=0.07) self.color_select2 = ImageColorSelection("OptFlowColorSelect", size, dt=dt, color='fullManu') #Link maps self.playcam1.addChildren(image=self.webcam1) self.color_select.addChildren(image=self.playcam1) self.field1.addChildren(aff=self.color_select) self.flow1.addChildren(img=self.playcam1) self.ofBGR1.addChildren(opticalFlow=self.flow1) self.ofColor.addChildren(flowBGR=self.ofBGR1, colorDNFAct=self.field1.getActivation()) self.playcam2.addChildren(image=self.webcam2) self.flow2.addChildren(img=self.playcam2) self.ofBGR2.addChildren(opticalFlow=self.flow2) self.color_select2.addChildren(image=self.ofBGR2, hsv=self.ofColor) self.field2.addChildren(aff=self.color_select2) #compute the playCam to avoid some problems TODO fix self.playcam1.compute() self.playcam2.compute() #return the roots root = self.field2 return root def getArrays(self): ret = [ self.playcam1, self.color_select, self.field1.getActivation(), self.ofBGR1, self.ofColor, self.playcam2, self.ofBGR2, self.color_select2, self.field2 ] return ret def onClick(self, mapName, x, y): print mapName.__class__ if mapName == "PlayCam1": bgr = self.playcam1.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 "ColorSelect"
class ModelDNFDualCam_BG(Model, Renderable): def initMaps(self, size): self.size = size dt = 0.6 # CREATE MAPS # 1st and 2nd webcam + possible perturbations self.webcam1 = WebcamMap("Webcam1", size, dt=dt, numDevice=0) self.playcam1 = PlayCamMap("PlayCam1", size) self.webcam2 = WebcamMap("Webcam2", size, dt=dt, numDevice=1) self.playcam2 = PlayCamMap("PlayCam2", size) # 1st webcam basic filtering: HSV color (outputing V) self.color_select = ImageColorSelection("ColorSelect", size, dt=dt) # one neural field per webcam self.field1 = MapDNF("DNF1", size, model='spike', dt=dt) self.field2 = MapDNF("DNF2", size, model='spike', dt=dt) # computing optical flows from both maps, then translating into colors self.flow1 = OpticalFlowMap("OpticalFlow1", size, dt=dt) self.flow2 = OpticalFlowMap("OpticalFlow2", size, dt=dt) self.ofBGR1 = OpticalFlowToBGR("OFtoBGR1", size=size, dt=dt) self.ofBGR2 = OpticalFlowToBGR("OFtoBGR2", size=size, dt=dt) # extracting average optical flow (1st webcam) under spikes as BGR coding, then filtering optical flow of webcam 2 accordingly self.ofColor = FlowDirectionSelect("SelectDir", size=1, dt=dt, globalSize=size, sampleSize=0.07) self.color_select2 = ImageColorSelection("OptFlowColorSelect", size, dt=dt, color='fullManu') # finally summing for webcam 2 the filtered color and the extracted optical flow (coded as color) self.aff2 = FuncWithoutKeywords(utils.sumArrays, "MixedModeInput", size, dt=dt) # LINK MAPS # from webcam 1 to DNF 1 self.playcam1.addChildren(image=self.webcam1) self.color_select.addChildren(image=self.playcam1) self.field1.addChildren(aff=self.color_select) # from webcam 1 to the extraction under spikes of the selected motion direction self.flow1.addChildren(img=self.playcam1) self.ofBGR1.addChildren(opticalFlow=self.flow1) self.ofColor.addChildren(flowBGR=self.ofBGR1, colorDNFAct=self.field1.getActivation()) # from webcam 2 to DNF 2, using the selected motion direction, and mixing with the color filtering self.playcam2.addChildren(image=self.webcam2) self.flow2.addChildren(img=self.playcam2) self.ofBGR2.addChildren(opticalFlow=self.flow2) self.color_select2.addChildren(image=self.ofBGR2, hsv=self.ofColor) self.aff2.addChildren(of=self.color_select2, col=self.color_select) self.field2.addChildren(aff=self.aff2) # compute the playCam to avoid some problems TODO fix self.playcam1.compute() self.playcam2.compute() #return the roots root = self.field2 return root def getArrays(self): ret = [ self.playcam1, self.color_select, self.field1.getActivation(), self.ofBGR1, # self.ofColor, self.playcam2, self.ofBGR2, self.color_select2, self.aff2, self.field2.getActivation() ] return ret def onClick(self, mapName, x, y): print mapName.__class__ if mapName == "PlayCam1": bgr = self.playcam1.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 "ColorSelect"