コード例 #1
0
ファイル: coordcalibrator.py プロジェクト: derric/libavg
    def __init__(self, calibrationTerminatedCb):
        self.__calibrationTerminatedCb = calibrationTerminatedCb
        self.__CurPointIndex = 0
        self.__CPPCal = player.getTracker().startCalibration()
        self.__LastCenter = None
        self.__NumMessages = 0
        self._mycursor = None
        mainNode = player.getElementByID("cal_coordcalibrator")
        mainNode.active = True
        mainNode.opacity = 1
        mainNode.setEventHandler(avg.Event.CURSOR_DOWN, avg.Event.TOUCH,
                                 self.__onTouchDown)
        mainNode.setEventHandler(avg.Event.CURSOR_MOTION, avg.Event.TOUCH,
                                 self.__onTouchMove)
        mainNode.setEventHandler(avg.Event.CURSOR_UP, avg.Event.TOUCH,
                                 self.__onTouchUp)
        self.__crosshair = player.getElementByID("cal_crosshair")
        self.__feedback = player.getElementByID("cal_feedback")
        self.__feedback.opacity = 0
        self.__addMessage("Starting calibration.")
        self.__moveMarker()

        g_KbManager.push()
        g_KbManager.bindKey('space', self.__nextPoint, 'sample next point')
        g_KbManager.bindKey('a', self.__abortCalibration, 'abort calibration')
コード例 #2
0
ファイル: coordcalibrator.py プロジェクト: gunawanw9/libavg
    def __nextPoint(self):
        if self.__LastCenter:
            self.__CPPCal.setCamPoint(self.__LastCenter)
            self.__addMessage("  Using: %(x).2f, %(y).2f" % {"x": self.__LastCenter[0], "y": self.__LastCenter[1]})
            self._mycursor = None
            self.__LastCenter = None

        hasNextPoint = self.__CPPCal.nextPoint()

        if not hasNextPoint:
            # Note: may raise RuntimeError. A rollback doesn't appear to be possible,
            # which means crashing here is safer than handling the exception
            player.getTracker().endCalibration()
            self.__endCalibration(True)
        else:
            self.__CurPointIndex += 1
            self.__moveMarker()
コード例 #3
0
    def __nextPoint(self):
        if self.__lastCenter:
            self.__cppCal.setCamPoint(self.__lastCenter)
            self.__addMessage("Using: %(x).2f, %(y).2f" %
                    {"x": self.__lastCenter[0], "y": self.__lastCenter[1]})
            self._myCursor = None
            self.__lastCenter = None

        hasNextPoint = self.__cppCal.nextPoint()

        if not hasNextPoint:
            # Note: may raise RuntimeError. A rollback doesn't appear to be possible,
            # which means crashing here is safer than handling the exception
            player.getTracker().endCalibration()
            self.__endCalibration(True)
        else:
            self.__curPointIndex += 1
            self.__moveMarker()
コード例 #4
0
ファイル: coordcalibrator.py プロジェクト: gunawanw9/libavg
    def __init__(self, calibrationTerminatedCb):
        self.__calibrationTerminatedCb = calibrationTerminatedCb
        self.__CurPointIndex = 0
        self.__CPPCal = player.getTracker().startCalibration()
        self.__LastCenter = None
        self.__NumMessages = 0
        self._mycursor = None
        mainNode = player.getElementByID("cal_coordcalibrator")
        mainNode.active = True
        mainNode.opacity = 1
        mainNode.setEventHandler(avg.Event.CURSOR_DOWN, avg.Event.TOUCH, self.__onTouchDown)
        mainNode.setEventHandler(avg.Event.CURSOR_MOTION, avg.Event.TOUCH, self.__onTouchMove)
        mainNode.setEventHandler(avg.Event.CURSOR_UP, avg.Event.TOUCH, self.__onTouchUp)
        self.__crosshair = player.getElementByID("cal_crosshair")
        self.__feedback = player.getElementByID("cal_feedback")
        self.__feedback.opacity = 0
        self.__addMessage("Starting calibration.")
        self.__moveMarker()

        g_KbManager.push()
        g_KbManager.bindKey("space", self.__nextPoint, "sample next point")
        g_KbManager.bindKey("a", self.__abortCalibration, "abort calibration")
コード例 #5
0
ファイル: coordcalibrator.py プロジェクト: gunawanw9/libavg
 def __abortCalibration(self):
     player.getTracker().abortCalibration()
     self.__endCalibration(False)
コード例 #6
0
ファイル: camcalibrator.py プロジェクト: lynxis/libavg
    def __init__(self, parentNode, CameraType = "FireFly", appStarter = None):
        super(Calibrator, self).__init__(parentNode)
        self.paramList = camera_setup(CameraType)
        self.parentNode=parentNode
        self.appStarter = appStarter
        self.mainNode = player.createNode(
        """
        <div active="False" opacity="0">
            <image width="1280" height="800" href="black.png"/>
            <image id="cal_distorted" x="0" y="0" width="1280" height="800"
                    sensitive="false" opacity="1"/>
            <words id="cal_fps" x="30" y="30" color="00FF00" text=""/>
            <words id="cal_notification" x="390" y="390" width="500" fontsize="18"
                    color="ff3333" alignment="center" />
            <div id="cal_gui" x="30" y="540">
                <image id="cal_shadow" x="0" y="13" width="500" height="150" 
                        href="black.png" opacity="0.6"/>
                
                <words x="2" y="13" text="camera" fontsize="16" color="00FF00"/>
                <image x="2" y="32" href="CamImgBorder.png"/>
                <image id="cal_camera" x="4" y="34" width="160" height="120"/>

                <words x="168" y="13" text="nohistory" fontsize="16" color="00FF00"/>
                <image x="168" y="32" href="CamImgBorder.png"/>
                <image id="cal_nohistory" x="170" y="34" width="160" height="120"/>
                
                <words x="334" y="13" text="histogram" fontsize="16" color="00FF00"/>
                <image x="334" y="32" href="CamImgBorder.png"/>
                <image id="cal_histogram" x="336" y="34" width="160" height="120"/>

                <div id="cal_params" y="170" opacity="0.9">
                <image id="cal_shadow2" width="750" height="65" href="black.png" opacity="0.6"/>
                    <div id="cal_paramdiv0" x="2">
                        <words text="camera" y="0" fontsize="10" color="00ff00" /> 
                        <words id="cal_param0" y="12" fontsize="10"/> 
                        <words id="cal_param1" y="24" fontsize="10"/> 
                        <words id="cal_param2" y="36" fontsize="10"/> 
                        <words id="cal_param3" y="48" fontsize="10"/> 
                    </div>
                    <div id="cal_paramdiv1" x="80">
                        <words text="touch" y="0" fontsize="10" color="00ff00" /> 
                        <words id="cal_param4" y="12" fontsize="10"/> 
                        <words id="cal_param5" y="24" fontsize="10"/> 
                        <words id="cal_param6" y="36" fontsize="10"/> 
                        <words id="cal_param7" y="48" fontsize="10"/> 
                    </div>
                    <div id="cal_paramdiv2" x="200">
                        <words id="cal_param8" y="0" fontsize="10"/> 
                        <words id="cal_param9" y="12" fontsize="10"/> 
                        <words id="cal_param10" y="24" fontsize="10"/> 
                        <words id="cal_param11" y="36" fontsize="10"/> 
                        <words id="cal_param12" y="48" fontsize="10"/> 
                    </div>
                    <div id="cal_paramdiv3" x="350">
                        <words text="track" y="0" fontsize="10" color="00ff00" /> 
                        <words id="cal_param13" y="12" fontsize="10"/> 
                        <words id="cal_param14" y="24" fontsize="10"/> 
                        <words id="cal_param15" y="36" fontsize="10"/> 
                        <words id="cal_param16" y="48" fontsize="10"/> 
                    </div>
                    <div id="cal_paramdiv4" x="500">
                        <words id="cal_param17" y="0" fontsize="10"/> 
                        <words text="distort" y="12" fontsize="10" color="00ff00"/> 
                        <words id="cal_param18" y="24" fontsize="10"/> 
                        <words id="cal_param19" y="36" fontsize="10"/> 
                        <words id="cal_param20" y="48" fontsize="10"/> 
                    </div>
                    <div id="cal_paramdiv5" x="650">
                        <words id="cal_param21" y="0" fontsize="10"/> 
                        <words id="cal_param22" y="12" fontsize="10"/> 
                        <words id="cal_param23" y="24" fontsize="10"/> 
                        <words id="cal_param24" y="36" fontsize="10"/> 
                        <words id="cal_param25" y="48" fontsize="10"/> 
                    </div>
                </div>
            </div>
            <div id="cal_coordcalibrator" opacity="0" active="false">
              <image x="0" y="0" width="1280" height="800" href="border.png"/>
              <div id="cal_messages" x="100" y="100"/>
              <image id="cal_crosshair" href="crosshair.png"/>
              <image id="cal_feedback" href="Feedback.png"/>
            </div>
        </div>
        """)
        self.mainNode.mediadir=mediadir
        parentNode.insertChild(self.mainNode, 0)

        self.coordCal = None
        self.tracker = player.getTracker()
        self.curParam = 0
        self.saveIndex = 0
        self.hideMainNodeTimeout = None
        self.video = []
        self.__guiOpacity = 1
        self.__showBigCamImage = False
        self.__notificationTimer = None
        self.__onCalibrationSuccess = None
コード例 #7
0
ファイル: coordcalibrator.py プロジェクト: derric/libavg
 def __abortCalibration(self):
     player.getTracker().abortCalibration()
     self.__endCalibration(False)
コード例 #8
0
    def __init__(self, parentNode, cameraType = "FireFly", appStarter=None):
        super(Calibrator, self).__init__(parentNode)
        self.paramList = camera_setup(cameraType)
        self.parentNode = parentNode
        self.appStarter = appStarter
        self.mainNode = player.createNode(
            """
        <div active = "False" opacity = "0">
            <image width = "1280" height = "800" href = "black.png"/>
            <image id = "cal_distorted" x = "0" y = "0" width = "1280" height = "800"
                    sensitive = "false" opacity = "1"/>
            <words id = "cal_fps" x = "30" y = "30" color = "00FF00" text = ""/>
            <words id = "cal_notification" x = "390" y = "390" width = "500" fontsize = "18"
                    color = "ff3333" alignment = "center" />
            <div id = "cal_gui" x = "30" y = "540">
                <image id = "cal_shadow" x = "0" y = "13" width = "500" height = "150" 
                        href = "black.png" opacity = "0.6"/>
                
                <words x = "2" y = "13" text = "camera" fontsize = "16" color = "00FF00"/>
                <image x = "2" y = "32" href = "CamImgBorder.png"/>
                <image id = "cal_camera" x = "4" y = "34" width = "160" height = "120"/>

                <words x = "168" y = "13" text = "nohistory" fontsize = "16" color = "00FF00"/>
                <image x = "168" y = "32" href = "CamImgBorder.png"/>
                <image id = "cal_nohistory" x = "170" y = "34" width = "160" height = "120"/>
                
                <words x = "334" y = "13" text = "histogram" fontsize = "16" color = "00FF00"/>
                <image x = "334" y = "32" href = "CamImgBorder.png"/>
                <image id = "cal_histogram" x = "336" y = "34" width = "160" height = "120"/>

                <div id = "cal_params" y = "170" opacity = "0.9">
                <image id = "cal_shadow2" width = "750" height = "65" href = "black.png" opacity = "0.6"/>
                    <div id = "cal_paramdiv0" x = "2">
                        <words text = "camera" y = "0" fontsize = "10" color = "00ff00" /> 
                        <words id = "cal_param0" y = "12" fontsize = "10"/> 
                        <words id = "cal_param1" y = "24" fontsize = "10"/> 
                        <words id = "cal_param2" y = "36" fontsize = "10"/> 
                        <words id = "cal_param3" y = "48" fontsize = "10"/> 
                    </div>
                    <div id = "cal_paramdiv1" x = "80">
                        <words text = "touch" y = "0" fontsize = "10" color = "00ff00" /> 
                        <words id = "cal_param4" y = "12" fontsize = "10"/> 
                        <words id = "cal_param5" y = "24" fontsize = "10"/> 
                        <words id = "cal_param6" y = "36" fontsize = "10"/> 
                        <words id = "cal_param7" y = "48" fontsize = "10"/> 
                    </div>
                    <div id = "cal_paramdiv2" x = "200">
                        <words id = "cal_param8" y = "0" fontsize = "10"/> 
                        <words id = "cal_param9" y = "12" fontsize = "10"/> 
                        <words id = "cal_param10" y = "24" fontsize = "10"/> 
                        <words id = "cal_param11" y = "36" fontsize = "10"/> 
                        <words id = "cal_param12" y = "48" fontsize = "10"/> 
                    </div>
                    <div id = "cal_paramdiv3" x = "350">
                        <words text = "track" y = "0" fontsize = "10" color = "00ff00" /> 
                        <words id = "cal_param13" y = "12" fontsize = "10"/> 
                        <words id = "cal_param14" y = "24" fontsize = "10"/> 
                        <words id = "cal_param15" y = "36" fontsize = "10"/> 
                        <words id = "cal_param16" y = "48" fontsize = "10"/> 
                    </div>
                    <div id = "cal_paramdiv4" x = "500">
                        <words id = "cal_param17" y = "0" fontsize = "10"/> 
                        <words text = "distort" y = "12" fontsize = "10" color = "00ff00"/> 
                        <words id = "cal_param18" y = "24" fontsize = "10"/> 
                        <words id = "cal_param19" y = "36" fontsize = "10"/> 
                        <words id = "cal_param20" y = "48" fontsize = "10"/> 
                    </div>
                    <div id = "cal_paramdiv5" x = "650">
                        <words id = "cal_param21" y = "0" fontsize = "10"/> 
                        <words id = "cal_param22" y = "12" fontsize = "10"/> 
                        <words id = "cal_param23" y = "24" fontsize = "10"/> 
                        <words id = "cal_param24" y = "36" fontsize = "10"/> 
                        <words id = "cal_param25" y = "48" fontsize = "10"/> 
                    </div>
                </div>
            </div>
            <div id = "cal_coordcalibrator" opacity = "0" active = "false">
              <image x = "0" y = "0" width = "1280" height = "800" href = "border.png"/>
              <div id = "cal_messages" x = "100" y = "100"/>
              <image id = "cal_crosshair" href = "crosshair.png"/>
              <image id = "cal_feedback" href = "Feedback.png"/>
            </div>
        </div>
        """)
        self.mainNode.mediadir = mediadir
        parentNode.insertChild(self.mainNode, 0)

        self.coordCal = None
        self.tracker = player.getTracker()
        self.curParam = 0
        self.saveIndex = 0
        self.hideMainNodeTimeout = None
        self.video = []
        self.__guiOpacity = 1
        self.__showBigCamImage = False
        self.__notificationTimer = None
        self.__onCalibrationSuccess = None
コード例 #9
0
ファイル: appstarter.py プロジェクト: dboesel/libavg
class AVGMTAppStarter(AVGAppStarter):
    def __init__(self, *args, **kwargs):
        self.__touchVisOverlay = None
        super(AVGMTAppStarter, self).__init__(*args, **kwargs)

    def setTouchVisualization(self, visClass):
        if not (self.__touchVisOverlay is None):
            self.__touchVisOverlay.unlink(True)
            del self.__touchVisOverlay
            self.__touchVisOverlay = None
        if not (visClass is None):
            rootNode = player.getRootNode()
            self.__touchVisOverlay = apphelpers.TouchVisualizationOverlay(
                isDebug=False,
                visClass=visClass,
                size=self._appNode.size,
                parent=rootNode)

    def toggleTrackerImage(self):
        if self.__showTrackerImage:
            self.hideTrackerImage()
        else:
            self.showTrackerImage()

    def showTrackerImage(self):
        if self.__showTrackerImage:
            return
        self.__showTrackerImage = True
        self.__updateTrackerImageInterval = \
                player.subscribe(player.ON_FRAME, self.__updateTrackerImage)
        self.__trackerImageNode.opacity = 1
        self.tracker.setDebugImages(False, True)

    def hideTrackerImage(self):
        if not self.__showTrackerImage:
            return
        self.__showTrackerImage = False
        if self.__updateTrackerImageInterval:
            player.clearInterval(self.__updateTrackerImageInterval)
            self.__updateTrackerImageInterval = None
        self.__trackerImageNode.opacity = 0
        self.tracker.setDebugImages(False, False)

    def __updateTrackerImage(self):
        def transformPos((x, y)):
            if self.trackerFlipX:
                x = 1 - x
            if self.trackerFlipY:
                y = 1 - y
            return (x, y)

        fingerBitmap = self.tracker.getImage(avg.IMG_FINGERS)
        node = self.__trackerImageNode
        node.setBitmap(fingerBitmap)
        node.pos = self.tracker.getDisplayROIPos()
        node.size = self.tracker.getDisplayROISize()

        grid = node.getOrigVertexCoords()
        grid = [[transformPos(pos) for pos in line] for line in grid]
        node.setWarpedVertexCoords(grid)

    def _onStart(self):
        from camcalibrator import Calibrator

        # we must add the tracker first, calibrator depends on it
        try:
            player.enableMultitouch()
        except RuntimeError, err:
            avg.logger.warning(str(err))

        self.tracker = player.getTracker()

        if self.tracker:
            if Calibrator:
                self.__calibratorNode = player.createNode(
                    'div', {
                        'opacity': 0,
                        'active': False,
                    })
                rootNode = player.getRootNode()
                rootNode.appendChild(self.__calibratorNode)
                self.__calibratorNode.size = rootNode.size
                self.__calibrator = Calibrator(self.__calibratorNode,
                                               appStarter=self)
                self.__calibrator.setOnCalibrationSuccess(
                    self.__onCalibrationSuccess)
                self.__calibrator.init()
            else:
                self.__calibrator = None

            self.__showTrackerImage = False
            self.__updateTrackerImageInterval = None
            self.__trackerImageNode = player.createNode(
                'image', {'sensitive': False})
            player.getRootNode().appendChild(self.__trackerImageNode)

            self.__updateTrackerImageFixup()

            g_KbManager.bindKey('h', self.tracker.resetHistory,
                                'RESET tracker history')
            g_KbManager.bindKey('d', self.toggleTrackerImage,
                                'toggle tracker image')

            if self.__calibrator:
                g_KbManager.bindKey('c', self.__enterCalibrator,
                                    'enter calibrator')
        AVGAppStarter._onStart(self)