Exemplo n.º 1
0
    def __init__(self, environment, parent):
        super(CWPage4, self).__init__(parent)

        # The final object is stored here:
        self.newRobotMrkr = None

        # Create global GUI objects
        self.hintLbl = QtWidgets.QLabel(
            "")  # This will tell the user how many points are on the object
        self.movieLbl = QtWidgets.QLabel(
            ""
        )  # Changes the gif depending on what the user is having trouble with
        self.selMovie = QtGui.QMovie(
            Paths.help_sel_marker)  # Help with selecting the marker
        self.detMovie = QtGui.QMovie(
            Paths.help_add_detail)  # Help with adding detail to marker

        # Get the Environment objects that will be used
        self.vision = environment.getVision()
        self.robot = environment.getRobot()
        self.objManager = environment.getObjectManager()

        # Create the camera widget and set it up
        self.cameraWidget = CameraSelector(environment.getVStream(),
                                           parent=self)
        self.cameraWidget.play()
        self.cameraWidget.objSelected.connect(self.objectSelected)

        self.initUI()
Exemplo n.º 2
0
    def __init__(self, environment, parent):
        super(CWPage4, self).__init__(parent)

        # The final object is stored here:
        self.newRobotMrkr    = None

        # Create global GUI objects
        self.hintLbl  = QtWidgets.QLabel("")  # This will tell the user how many points are on the object
        self.movieLbl = QtWidgets.QLabel("")  # Changes the gif depending on what the user is having trouble with
        self.selMovie = QtGui.QMovie(Paths.help_sel_marker)  # Help with selecting the marker
        self.detMovie = QtGui.QMovie(Paths.help_add_detail)  # Help with adding detail to marker


        # Get the Environment objects that will be used
        self.vision       = environment.getVision()
        self.robot        = environment.getRobot()
        self.objManager   = environment.getObjectManager()

        # Create the camera widget and set it up
        self.cameraWidget = CameraSelector(environment.getVStream(), parent=self)
        self.cameraWidget.play()
        self.cameraWidget.objSelected.connect(self.objectSelected)

        self.initUI()
Exemplo n.º 3
0
class CWPage4(QtWidgets.QWizardPage):

    def __init__(self, environment, parent):
        super(CWPage4, self).__init__(parent)

        # The final object is stored here:
        self.newRobotMrkr    = None

        # Create global GUI objects
        self.hintLbl  = QtWidgets.QLabel("")  # This will tell the user how many points are on the object
        self.movieLbl = QtWidgets.QLabel("")  # Changes the gif depending on what the user is having trouble with
        self.selMovie = QtGui.QMovie(Paths.help_sel_marker)  # Help with selecting the marker
        self.detMovie = QtGui.QMovie(Paths.help_add_detail)  # Help with adding detail to marker


        # Get the Environment objects that will be used
        self.vision       = environment.getVision()
        self.robot        = environment.getRobot()
        self.objManager   = environment.getObjectManager()

        # Create the camera widget and set it up
        self.cameraWidget = CameraSelector(environment.getVStream(), parent=self)
        self.cameraWidget.play()
        self.cameraWidget.objSelected.connect(self.objectSelected)

        self.initUI()

    def initUI(self):
        prompt = self.tr("""Make sure the robot's head is in the center of the camera view. Then, click the mouse on
                 the top \nright corner of the marker, and drag it to the bottom right corner of the marker.\n\n
                 The camera will begin tracking the marker. Try to have more than 500 points on the marker. Move\n
                 the robot around and make sure that the object can be recognized for the majority of the cameras\n
                 view.\n""")

        stepLbl    = QtWidgets.QLabel(self.tr("Step 4: Selecting the Marker"))
        promptLbl  = QtWidgets.QLabel(prompt)


        # Set the animated gif on the movieLbl

        self.movieLbl.setMovie(self.selMovie)
        self.selMovie.start()
        self.detMovie.start()


        # Set titles bold
        bold = QtGui.QFont()
        bold.setBold(True)
        stepLbl.setFont(bold)
        self.hintLbl.setFont(bold)

        # Create a special row for the camera that will force it to remain in the center, regardless of size changes
        camRow = QtWidgets.QHBoxLayout()
        camRow.addWidget(self.cameraWidget)
        camRow.addStretch(1)
        camRow.addWidget(self.movieLbl)

        # Place the GUI objects vertically
        col1 = QtWidgets.QVBoxLayout()
        col1.addWidget(stepLbl)
        col1.addWidget(promptLbl)
        col1.addWidget(self.hintLbl)
        col1.addLayout(camRow)

        mainHLayout = QtWidgets.QHBoxLayout()
        mainHLayout.addLayout(col1)

        self.setLayout(mainHLayout)

    def objectSelected(self):
        """
            Runs when the user has selected an object on the CameraSelector widget.
            It will verify if the object is trackable (has enough points), if so, it will set the vision to tracking
            mode, generate a "trackable" object, and set the camera to play.

            Then, it will display information about the object next to the camera, so that the user can decide if
            they want to keep this selected object or try again.

            If there are not enough keypoints, the program will warn the user that this is a bad idea. If there are
            zero keypoints, it won't allow the user to track it, and will automatically revert the camera to
            selection mode.
        """

        # Reset any previous markers
        self.newRobotMrkr = None
        self.completeChanged.emit()
        self.hintLbl.setText("")
        self.vision.endAllTrackers()
        self.movieLbl.setMovie(self.selMovie)
        self.movieLbl.show()

        rect     = self.cameraWidget.getSelectedRect()
        frame    = self.cameraWidget.getSelectedFrame()
        h, w, _  = frame.shape

        # Get the "target" object from the image and rectangle
        trackable = TrackableObject("Robot Marker")
        trackable.addNewView(image      = frame,
                             rect       = rect,
                             pickupRect = [0, 0, h, w],
                             height     = 0)

        target = self.vision.planeTracker.createTarget(trackable.getViews()[0])

        # Analyze it, and make sure it's a valid target. If not, return the camera to selection mode.
        if len(target.descrs) == 0 or len(target.keypoints) == 0:
            self.cameraWidget.takeAnother()
            self.hintLbl.setText(self.tr("You must select an object with more detail."))
            return

        if len(target.descrs) < 450:
            self.movieLbl.setMovie(self.detMovie)
            self.hintLbl.setText(self.tr("Your selected marker does not have enough detail. Only ") +
                                 str(len(target.descrs)) + self.tr(" points were found.\nAdd detail to your marker and "
                                 "try again."))
            self.cameraWidget.takeAnother()
            return

        self.objManager.deleteObject("Robot Marker")  # Delete any previous end effector file
        self.newRobotMrkr = trackable
        self.objManager.saveObject(self.newRobotMrkr)
        self.completeChanged.emit()


        # If the object was not very good, warn the user. Otherwise, state the # of points on the object
        if len(target.descrs) < 600:
            self.movieLbl.setMovie(self.detMovie)
            self.hintLbl.setText(self.tr("Your selected marker is not very detailed, or is too small, only ") +
                                 str(len(target.descrs)) + self.tr(" points were found.\n") +
                                 self.tr("Tracking may not be very accurate."))
        else:
            self.hintLbl.setText(self.tr("Found ") + str(len(target.descrs)) + self.tr(" Points"))

        # Turn on the camera, and start tracking
        self.cameraWidget.play()
        self.vision.addTarget(self.newRobotMrkr)

    def isComplete(self):
        return self.newRobotMrkr is not None

    def close(self):
        self.cameraWidget.close()
        self.vision.endAllTrackers()
Exemplo n.º 4
0
class CWPage4(QtWidgets.QWizardPage):

    def __init__(self, environment, parent):
        super(CWPage4, self).__init__(parent)

        # The final object is stored here:
        self.newRobotMrkr    = None

        # Create global GUI objects
        self.hintLbl  = QtWidgets.QLabel("")  # This will tell the user how many points are on the object
        self.movieLbl = QtWidgets.QLabel("")  # Changes the gif depending on what the user is having trouble with
        self.selMovie = QtGui.QMovie(Paths.help_sel_marker)  # Help with selecting the marker
        self.detMovie = QtGui.QMovie(Paths.help_add_detail)  # Help with adding detail to marker


        # Get the Environment objects that will be used
        self.vision       = environment.getVision()
        self.robot        = environment.getRobot()
        self.objManager   = environment.getObjectManager()

        # Create the camera widget and set it up
        self.cameraWidget = CameraSelector(environment.getVStream(), parent=self)
        self.cameraWidget.play()
        self.cameraWidget.objSelected.connect(self.objectSelected)

        self.initUI()

    def initUI(self):
        prompt = "Make sure the robot's head is in the center of the camera view. Then, click the mouse on the top "  +\
                 "\nright corner of the marker, and drag it to the bottom right corner of the marker.\n\n"            +\
                 "The camera will begin tracking the marker. Try to have more than 500 points on the marker. Move\n"  +\
                 "the robot around and make sure that the object can be recognized for the majority of the cameras\n" +\
                 "view.\n"

        stepLbl    = QtWidgets.QLabel("Step 4: Selecting the Marker")
        promptLbl  = QtWidgets.QLabel(prompt)


        # Set the animated gif on the movieLbl

        self.movieLbl.setMovie(self.selMovie)
        self.selMovie.start()
        self.detMovie.start()


        # Set titles bold
        bold = QtGui.QFont()
        bold.setBold(True)
        stepLbl.setFont(bold)
        self.hintLbl.setFont(bold)

        # Create a special row for the camera that will force it to remain in the center, regardless of size changes
        camRow = QtWidgets.QHBoxLayout()
        camRow.addWidget(self.cameraWidget)
        camRow.addStretch(1)
        camRow.addWidget(self.movieLbl)

        # Place the GUI objects vertically
        col1 = QtWidgets.QVBoxLayout()
        col1.addWidget(stepLbl)
        col1.addWidget(promptLbl)
        col1.addWidget(self.hintLbl)
        col1.addLayout(camRow)

        mainHLayout = QtWidgets.QHBoxLayout()
        mainHLayout.addLayout(col1)

        self.setLayout(mainHLayout)

    def objectSelected(self):
        """
            Runs when the user has selected an object on the CameraSelector widget.
            It will verify if the object is trackable (has enough points), if so, it will set the vision to tracking
            mode, generate a "trackable" object, and set the camera to play.

            Then, it will display information about the object next to the camera, so that the user can decide if
            they want to keep this selected object or try again.

            If there are not enough keypoints, the program will warn the user that this is a bad idea. If there are
            zero keypoints, it won't allow the user to track it, and will automatically revert the camera to
            selection mode.
        """

        # Reset any previous markers
        self.newRobotMrkr = None
        self.completeChanged.emit()
        self.hintLbl.setText("")
        self.vision.endAllTrackers()
        self.movieLbl.setMovie(self.selMovie)
        self.movieLbl.show()

        rect     = self.cameraWidget.getSelectedRect()
        frame    = self.cameraWidget.getSelectedFrame()
        h, w, _  = frame.shape

        # Get the "target" object from the image and rectangle
        trackable = TrackableObject("Robot Marker")
        trackable.addNewView(image      = frame,
                             rect       = rect,
                             pickupRect = [0, 0, h, w],
                             height     = 0)

        target = self.vision.planeTracker.createTarget(trackable.getViews()[0])

        # Analyze it, and make sure it's a valid target. If not, return the camera to selection mode.
        if len(target.descrs) == 0 or len(target.keypoints) == 0:
            self.cameraWidget.takeAnother()
            self.hintLbl.setText("You must select an object with more detail.")
            return

        if len(target.descrs) < 450:
            self.movieLbl.setMovie(self.detMovie)
            self.hintLbl.setText("Your selected marker does not have enough detail. Only " + str(len(target.descrs)) +
                                 " points were found.\nAdd detail to your marker and try again.")
            self.cameraWidget.takeAnother()
            return

        self.objManager.deleteObject("Robot Marker")  # Delete any previous end effector file
        self.newRobotMrkr = trackable
        self.objManager.saveObject(self.newRobotMrkr)
        self.completeChanged.emit()


        # If the object was not very good, warn the user. Otherwise, state the # of points on the object
        if len(target.descrs) < 600:
            self.movieLbl.setMovie(self.detMovie)
            self.hintLbl.setText("Your selected marker is not very detailed, or is too small, only " +
                                 str(len(target.descrs)) + " points were found.\n"
                                 "Tracking may not be very accurate.")
        else:
            self.hintLbl.setText("Found " + str(len(target.descrs)) + " Points")

        # Turn on the camera, and start tracking
        self.cameraWidget.play()
        self.vision.addTarget(self.newRobotMrkr)

    def isComplete(self):
        return self.newRobotMrkr is not None

    def close(self):
        self.cameraWidget.close()
        self.vision.endAllTrackers()