Esempio n. 1
0
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"
Esempio n. 2
0
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"
Esempio n. 3
0
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"
Esempio n. 4
0
 def test_cam1(self):
         uut = WebcamMap("uut",512)
         uut.compute()
Esempio n. 5
0
 def test_cam1(self):
     uut = WebcamMap(512)
     uut.compute()