def __init__(self, pictureNumber): resultFileName = 'Results/Picture ' + str(pictureNumber) + '.txt' frameFileName = 'Frames/Picture ' + str(pictureNumber) + '.jpg' image = cv2.imread(frameFileName) self.geometricalImage = WorldImage() self.geometricalImage.buildMap(image) self.geometricalImage.updateRobotPosition(image) resultFile = open(resultFileName, 'r') centerOfMassLine = resultFile.readline() centerOfMassLine = centerOfMassLine[13:] self.centersOfMass = [] xPosition = "" yPosition = "" isFirstNumber = True for character in centerOfMassLine: if character != '(' and character != ',' and character != ')': if isFirstNumber: xPosition += character else: yPosition += character if character == '(': isFirstNumber = True if character == ',': isFirstNumber = False if character == ')': self.centersOfMass.append((int(xPosition), int(yPosition))) xPosition = "" yPosition = ""
class ResultChecker: def __init__(self, pictureNumber): resultFileName = 'Results/Picture ' + str(pictureNumber) + '.txt' frameFileName = 'Frames/Picture ' + str(pictureNumber) + '.jpg' image = cv2.imread(frameFileName) self.geometricalImage = WorldImage() self.geometricalImage.buildMap(image) self.geometricalImage.updateRobotPosition(image) resultFile = open(resultFileName, 'r') centerOfMassLine = resultFile.readline() centerOfMassLine = centerOfMassLine[13:] self.centersOfMass = [] xPosition = "" yPosition = "" isFirstNumber = True for character in centerOfMassLine: if character != '(' and character != ',' and character != ')': if isFirstNumber: xPosition += character else: yPosition += character if character == '(': isFirstNumber = True if character == ',': isFirstNumber = False if character == ')': self.centersOfMass.append((int(xPosition), int(yPosition))) xPosition = "" yPosition = "" def checkNumberOfShapesFound(self): shapeFound = 0 for shape in self.geometricalImage.getMap().getShapesList(): shapeCenterOfMassX, shapeCenterOfMassY = shape.findCenterOfMass() for centerOfMass in self.centersOfMass: if abs(shapeCenterOfMassX - centerOfMass[0]) < 10 and abs( shapeCenterOfMassY - centerOfMass[1]) < 10: shapeFound += 1 if shapeFound != len(self.centersOfMass) or len( self.geometricalImage.getMap().getShapesList()) != len( self.centersOfMass): print("Number of shapes found : " + str(len(self.geometricalImage.getMap().getShapesList()))) print("Number of real shapes found : " + str(shapeFound)) print("Number of shapes present : " + str(len(self.centersOfMass))) return shapeFound, len(self.centersOfMass) def checkIfLimitFound(self): if self.geometricalImage.getMap().getMapLimit().getArea() < 1: print("Limit not found") def checkIfRobotFound(self): if self.geometricalImage.getMap().robot.square.getArea() < 1: print("Robot not found")
def __init__(self, pictureNumber): resultFileName = 'Results/Picture ' + str(pictureNumber) + '.txt' frameFileName = 'Frames/Picture ' + str(pictureNumber) + '.jpg' image = cv2.imread(frameFileName) self.geometricalImage = WorldImage() self.geometricalImage.buildMap(image) self.geometricalImage.updateRobotPosition(image) resultFile = open(resultFileName, 'r') centerOfMassLine = resultFile.readline() centerOfMassLine = centerOfMassLine[13:] self.centersOfMass = [] xPosition = "" yPosition = "" isFirstNumber = True for character in centerOfMassLine: if character != '(' and character != ',' and character != ')': if isFirstNumber: xPosition += character else: yPosition += character if character == '(': isFirstNumber = True if character == ',': isFirstNumber = False if character == ')': self.centersOfMass.append((int(xPosition), int(yPosition))) xPosition = "" yPosition = ""
class ResultChecker: def __init__(self, pictureNumber): resultFileName = 'Results/Picture ' + str(pictureNumber) + '.txt' frameFileName = 'Frames/Picture ' + str(pictureNumber) + '.jpg' image = cv2.imread(frameFileName) self.geometricalImage = WorldImage() self.geometricalImage.buildMap(image) self.geometricalImage.updateRobotPosition(image) resultFile = open(resultFileName, 'r') centerOfMassLine = resultFile.readline() centerOfMassLine = centerOfMassLine[13:] self.centersOfMass = [] xPosition = "" yPosition = "" isFirstNumber = True for character in centerOfMassLine: if character != '(' and character != ',' and character != ')': if isFirstNumber: xPosition += character else: yPosition += character if character == '(': isFirstNumber = True if character == ',': isFirstNumber = False if character == ')': self.centersOfMass.append((int(xPosition), int(yPosition))) xPosition = "" yPosition = "" def checkNumberOfShapesFound(self): shapeFound = 0 for shape in self.geometricalImage.getMap().getShapesList(): shapeCenterOfMassX, shapeCenterOfMassY = shape.findCenterOfMass() for centerOfMass in self.centersOfMass: if abs(shapeCenterOfMassX - centerOfMass[0]) < 10 and abs(shapeCenterOfMassY - centerOfMass[1]) < 10: shapeFound += 1 if shapeFound != len(self.centersOfMass) or len(self.geometricalImage.getMap().getShapesList()) != len(self.centersOfMass): print("Number of shapes found : " + str(len(self.geometricalImage.getMap().getShapesList()))) print("Number of real shapes found : " + str(shapeFound)) print("Number of shapes present : " + str(len(self.centersOfMass))) return shapeFound, len(self.centersOfMass) def checkIfLimitFound(self): if self.geometricalImage.getMap().getMapLimit().getArea() < 1: print("Limit not found") def checkIfRobotFound(self): if self.geometricalImage.getMap().robot.square.getArea() < 1: print("Robot not found")
def myMain(): #frame = cv2.imread('Photo-Test/Frames/Picture 500.jpg') geometricalImage = WorldImage() camera = cv2.VideoCapture(1) while(True): ret, frame = camera.read() #frame = cv2.imread('Photo-Test/Frames/Picture 500.jpg') frame = cv2.resize(frame, (960, 720)) copyF = copy.copy(frame) geometricalImage.buildMap(frame) geometricalImage.updateRobotPosition(frame) geometricalImage.addLabels(frame) worldImage = geometricalImage.drawMapOnFrame(frame) cv2.imshow("resized", worldImage) if cv2.waitKey(1) & 0xFF == ord('q'): break
# return m * (X - x1) + y1 # # line = np.vectorize(line_eq) # # x = np.arange(0, 1200) # y = line(x).astype(np.uint) # # cv2.line(frame, (x[0], y[0]), (x[-1], y[-1]), (0,0,0)) # cv2.imshow("foo",frame) # cv2.waitKey() while (True): ret, frame = camera.read() #frame = cv2.imread('Photos/3105/table 5/Jour/rideau ferme/Picture 1.jpg') cv2.resize(frame, (960, 720)) geometricalImage = WorldImage() geometricalImage.buildMap(frame) geometricalImage.updateRobotPosition(frame) geometricalImage.addLabels(frame) # worldV = worldVision() # map = worldV.getCurrentImage() worldImage = geometricalImage.drawMapOnFrame(frame) #print(geometricalImage.getMap().robot.findCenterOfMass()) cv2.imshow('Picture ' + str(x), worldImage) # geometricalImage = WorldImage(frame) # geometricalImage.setMap() # geometricalImage.addLabels() # worldImage = geometricalImage.drawMapOnImage()
def myMain2(): camera = cv2.VideoCapture(0) camera.set(3, 3264) camera.set(4, 2448) #frame = cv2.imread('Photo-Test/Frames/Picture 500.jpg') geometricalImage = WorldImage() #ret, frame = camera.read() frame = cv2.imread('Photo-Test/Frames/Picture 501.jpg') frame = cv2.resize(frame, (960, 720)) # copyF = copy.copy(frame) geometricalImage.buildMap(frame) geometricalImage.updateRobotPosition(frame) geometricalImage.defineTreasures([88, 30]) #geometricalImage.findBestTresor() geometricalImage.addLabels(frame) myTarget = ShapeTarget("pentagone") geometricalImage.getIslandPositioning(myTarget) geometricalImage.drawMapOnFrame(frame) cv2.imshow("resized", frame) cv2.waitKey(0)
# line = np.vectorize(line_eq) # # x = np.arange(0, 1200) # y = line(x).astype(np.uint) # # cv2.line(frame, (x[0], y[0]), (x[-1], y[-1]), (0,0,0)) # cv2.imshow("foo",frame) # cv2.waitKey() while(True): ret, frame = camera.read() #frame = cv2.imread('Photos/3105/table 5/Jour/rideau ferme/Picture 1.jpg') cv2.resize(frame, (960,720)) geometricalImage = WorldImage() geometricalImage.buildMap(frame) geometricalImage.updateRobotPosition(frame) geometricalImage.addLabels(frame) # worldV = worldVision() # map = worldV.getCurrentImage() worldImage = geometricalImage.drawMapOnFrame(frame) #print(geometricalImage.getMap().robot.findCenterOfMass()) cv2.imshow('Picture ' + str(x), worldImage) # geometricalImage = WorldImage(frame) # geometricalImage.setMap() # geometricalImage.addLabels() # worldImage = geometricalImage.drawMapOnImage()