예제 #1
0
def testDeLAffichageSurLImageGenereeParOpenCV():
    localisationIle = LocalisationIle()
    localisationRobot = LocalisationRobot()
    afficheurImage = AfficheurImage()

    nomPhotos = "../photos/table_iles_robot1.jpg"
    photo = cv2.imread(nomPhotos, cv2.IMREAD_UNCHANGED)

    listForme, listeCouleur, listePosition = localisationIle.trouverIles(photo)
    (xPosRobot, yPosRobot), orientation = localisationRobot.trouverRobot(photo)

    afficheurImage.afficherOrientationRobot(photo, (int(xPosRobot), int(yPosRobot)), int(orientation))
    afficheurImage.afficherPositionRobot(photo, (int(xPosRobot), int(yPosRobot)))

    for i in range(len(listForme)):
        afficheurImage.afficherInformationsIle(photo,
                                               (listePosition[i - 1][0], listePosition[i - 1][1]),
                                               forme = listForme[i - 1],
                                               couleur = listeCouleur[i - 1])

    while(True):
        cv2.imshow('frame',photo)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cv2.destroyAllWindows()
예제 #2
0
    def __init__(self):
        QThread.__init__(self)
        self.camera = CameraFixe()

        self.imageCount = 1
        self.nombreDImage = 3
        self.nombreDeForme = 4

        self.localisationIles = LocalisationIle()
        self.localisationRobot = LocalisationRobot()
        self.localisationRepere = LocalisationRepere()
        self.afficheurImage = AfficheurImage()

        self.couleurCarreTrouvee = ""
        self.xPositionCarreTrouvee = 0
        self.yPositionCarreTrouvee = 0

        self.couleurTriangleTrouvee = ""
        self.xPositionTriangleTrouvee = 0
        self.yPositionTriangleTrouvee = 0

        self.couleurCercleTrouvee = ""
        self.xPositionCercleTrouvee = 0
        self.yPositionCercleTrouvee = 0

        self.couleurPentagoneTrouvee = ""
        self.xPositionPentagoneTrouvee = 0
        self.yPositionPentagoneTrouvee = 0

        self.xPositionRobotTrouvee = 0
        self.yPositionRobotTrouvee = 0

        self.carreIndex = 0
        self.triangleIndex = 0
        self.cercleIndex = 0
        self.pentagoneIndex = 0

        self.detectionIlesTimeout = 10

        self.listeFormesThread = []
        self.listeCouleursThread = []
        self.listePositionsThread = []
        self.positionRobotThread = []

        self.time = None
        self.estVerouillee = False

        self.sauvegardePath = "C:\Users\phili_000\Desktop\Design 3\Design3\Code\Projet\photos\\table_iles_robot_MOD.jpg"

        self.photo = None

        self.reset = False
예제 #3
0
def testDeLAffichageSurLaVideoCaptureeParOpenCv():
    camera = cv2.VideoCapture(0)
    camera.set(3,1600)
    camera.set(4,1200)
    localisationIle = LocalisationIle()
    localisationRobot = LocalisationRobot()
    afficheurImage = AfficheurImage()
    carte = Carte()
    nbreFrame = 0
    #cheminement = Cheminement()

    while(True):
        ret, frame = camera.read()
        #frame = cv2.imread("../photos/table_iles_robot7.jpg",1)
        nbreFrame += 1
        print nbreFrame
        if nbreFrame % 60 == 0:
            listForme, listeCouleur, listePosition = localisationIle.trouverIles(frame)
            (xPosRobot, yPosRobot), orientation = localisationRobot.trouverRobot(frame)

            afficheurImage.afficherOrientationRobot(frame, (int(xPosRobot), int(yPosRobot)), int(orientation))
            afficheurImage.afficherPositionRobot(frame, (int(xPosRobot), int(yPosRobot)))


            for i in range(len(listForme)):
                afficheurImage.afficherInformationsIle(frame,
                                                       (listePosition[i - 1][0], listePosition[i - 1][1]),
                                                       forme = listForme[i - 1],
                                                       couleur = listeCouleur[i - 1])
        # Display the resulting frame
        #print repere
        #print xPosRobot,yPosRobot
        #cv2.circle(frame,(1140,168),5,(255,255,255),5)
            cv2.imshow('frame', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break


    # When everything done, release the capture
    camera.release()
    cv2.destroyAllWindows()
예제 #4
0
class DetectionEtAffichageThread(QThread):

    def __init__(self):
        QThread.__init__(self)
        self.camera = CameraFixe()

        self.imageCount = 1
        self.nombreDImage = 3
        self.nombreDeForme = 4

        self.localisationIles = LocalisationIle()
        self.localisationRobot = LocalisationRobot()
        self.localisationRepere = LocalisationRepere()
        self.afficheurImage = AfficheurImage()

        self.couleurCarreTrouvee = ""
        self.xPositionCarreTrouvee = 0
        self.yPositionCarreTrouvee = 0

        self.couleurTriangleTrouvee = ""
        self.xPositionTriangleTrouvee = 0
        self.yPositionTriangleTrouvee = 0

        self.couleurCercleTrouvee = ""
        self.xPositionCercleTrouvee = 0
        self.yPositionCercleTrouvee = 0

        self.couleurPentagoneTrouvee = ""
        self.xPositionPentagoneTrouvee = 0
        self.yPositionPentagoneTrouvee = 0

        self.xPositionRobotTrouvee = 0
        self.yPositionRobotTrouvee = 0

        self.carreIndex = 0
        self.triangleIndex = 0
        self.cercleIndex = 0
        self.pentagoneIndex = 0

        self.detectionIlesTimeout = 10

        self.listeFormesThread = []
        self.listeCouleursThread = []
        self.listePositionsThread = []
        self.positionRobotThread = []

        self.time = None
        self.estVerouillee = False

        self.sauvegardePath = "C:\Users\phili_000\Desktop\Design 3\Design3\Code\Projet\photos\\table_iles_robot_MOD.jpg"

        self.photo = None

        self.reset = False


    def __del__(self):
        self.wait()

    def run(self):
        global listeFormes
        global listeCouleurs
        global listePositions
        global repere
        global positionRobotTrouvee
        global orientationRobotTrouvee
        global ratioCMPixel
        while True:
            start = time.time()
            self.photo = None
            self.photo = self.camera.prendrePhoto()

            if(self.reset == True):
                self.reInitiliserVariables()
                self.reset = False
            if((not self.positionsIlesToutesTrouvee() or not self.couleurIlesToutesTrouvee()) and self.detectionIlesTimeout != 0):
                self.reInitiliserVariables()
                try:
                    listeFormes, listeCouleurs, listePositions = self.localisationIles.trouverIles(self.photo)
                    repere, ratioCMPixel = self.localisationRepere.trouverRepere(self.photo)
                    self.listePositionsThread = listePositions
                    self.listeCouleursThread = listeCouleurs
                    self.listeFormesThread = listeFormes
                    self.assignerIndexFormes()
                    self.loadIlesDataTrouvee()
                except Exception as e:
                    print e.message
                    self.detectionIlesTimeout -= 1
                    self.sauvegarderImage(self.photo)

                    if (self.detectionIlesTimeout == 0):
                        self.detectionIlesTimeout = 10
                        self.imageCount += 1
                    continue
            try:
                positionRobotTrouvee, orientationRobotTrouvee = self.localisationRobot.trouverRobot(self.photo,ratioCMPixel)
                self.positionRobotThread.append(positionRobotTrouvee)
            except Exception:
                continue
            xPosRobot = positionRobotTrouvee[0]
            yPosRobot = positionRobotTrouvee[1]
            self.afficheurImage.afficherOrientationRobot(self.photo, (int(xPosRobot), int(yPosRobot)), int(orientationRobotTrouvee))
            self.afficheurImage.afficherPositionRobot(self.photo, (int(xPosRobot), int(yPosRobot)), self.positionRobotThread)
            self.afficheurImage.afficherTrajectoire(self.photo, trajectoireCalculer)

            self.afficheurImage.afficherInformationsIle(self.photo,
                                                        (self.listePositionsThread[self.carreIndex][0], self.listePositionsThread[self.carreIndex][1]),
                                                        forme = self.listeFormesThread[self.carreIndex],
                                                        couleur = self.listeCouleursThread[self.carreIndex])
            self.afficheurImage.afficherInformationsIle(self.photo,
                                                        (self.listePositionsThread[self.triangleIndex][0], self.listePositionsThread[self.triangleIndex][1]),
                                                        forme = self.listeFormesThread[self.triangleIndex],
                                                        couleur = self.listeCouleursThread[self.triangleIndex])
            self.afficheurImage.afficherInformationsIle(self.photo,
                                                        (self.listePositionsThread[self.cercleIndex][0], self.listePositionsThread[self.cercleIndex][1]),
                                                        forme = self.listeFormesThread[self.cercleIndex],
                                                        couleur = self.listeCouleursThread[self.cercleIndex])
            self.afficheurImage.afficherInformationsIle(self.photo,
                                                        (self.listePositionsThread[self.pentagoneIndex][0], self.listePositionsThread[self.pentagoneIndex][1]),
                                                        forme = self.listeFormesThread[self.pentagoneIndex],
                                                        couleur = self.listeCouleursThread[self.pentagoneIndex])

            self.sauvegarderImage(self.photo)
            finish = time.time()

            deltaTime = finish - start
            time.sleep(2 - deltaTime)

    def positionsIlesToutesTrouvee(self):
        return self.xPositionCarreTrouvee != 0\
                and self.yPositionCarreTrouvee != 0\
                and self.xPositionTriangleTrouvee != 0\
                and self.yPositionTriangleTrouvee != 0\
                and self.xPositionCercleTrouvee != 0\
                and self.yPositionCercleTrouvee != 0\
                and self.xPositionPentagoneTrouvee != 0\
                and self.yPositionPentagoneTrouvee != 0

    def couleurIlesToutesTrouvee(self):
        return self.couleurCarreTrouvee != ""\
                and self.couleurCercleTrouvee != ""\
                and self.couleurTriangleTrouvee != ""\
                and self.couleurPentagoneTrouvee != ""

    def assignerIndexFormes(self):
        for i in range(self.nombreDeForme - 1):
                self.carreIndex = listeFormes.index("carre")
                self.triangleIndex = listeFormes.index("triangle")
                self.cercleIndex = listeFormes.index("cercle")
                self.pentagoneIndex = listeFormes.index("pentagon")

    def loadIlesDataTrouvee(self):
        self.couleurCarreTrouvee = self.listeCouleursThread[self.carreIndex]
        self.xPositionCarreTrouvee = self.listePositionsThread[self.carreIndex][0]
        self.yPositionCarreTrouvee = self.listePositionsThread[self.carreIndex][1]

        self.couleurTriangleTrouvee = self.listeCouleursThread[self.triangleIndex]
        self.xPositionTriangleTrouvee = self.listePositionsThread[self.triangleIndex][0]
        self.yPositionTriangleTrouvee = self.listePositionsThread[self.triangleIndex][1]

        self.couleurCercleTrouvee = self.listeCouleursThread[self.cercleIndex]
        self.xPositionCercleTrouvee = self.listePositionsThread[self.cercleIndex][0]
        self.yPositionCercleTrouvee = self.listePositionsThread[self.cercleIndex][1]

        self.couleurPentagoneTrouvee = self.listeCouleursThread[self.pentagoneIndex]
        self.xPositionPentagoneTrouvee = self.listePositionsThread[self.pentagoneIndex][0]
        self.yPositionPentagoneTrouvee = self.listePositionsThread[self.pentagoneIndex][1]

    def reInitiliserVariables(self):
        self.couleurCarreTrouvee = ""
        self.xPositionCarreTrouvee = 0
        self.yPositionCarreTrouvee = 0

        self.couleurTriangleTrouvee = ""
        self.xPositionTriangleTrouvee = 0
        self.yPositionTriangleTrouvee = 0

        self.couleurCercleTrouvee = ""
        self.xPositionCercleTrouvee = 0
        self.yPositionCercleTrouvee = 0

        self.couleurPentagoneTrouvee = ""
        self.xPositionPentagoneTrouvee = 0
        self.yPositionPentagoneTrouvee = 0

        self.xPositionRobotTrouvee = 0
        self.yPositionRobotTrouvee = 0
        self.positionRobotTrouvee = (0,0)
        self.orientationRobotTrouvee = 0

        self.carreIndex = 0
        self.triangleIndex = 0
        self.cercleIndex = 0
        self.pentagoneIndex = 0

        self.listeFormesThread = []
        self.listeCouleursThread = []
        self.listePositionsThread = []
        self.positionRobotThread = []

    def sauvegarderImage(self, photo):

        try:
            self.estVerouillee = True
            cv2.imwrite(self.sauvegardePath, photo)
            self.estVerouillee = False
        except Exception as e:
             print "Prob dans le sauvegarderImage: {0}".format(e.message)
        finally:
            self.estVerouillee = False