Exemplo n.º 1
0
    def __init__(self):
        # construct the argument parse and parse the arguments
        ap = argparse.ArgumentParser()
        ap.add_argument("-v",
                        "--video",
                        help="path to the (optional) video file")
        args = vars(ap.parse_args())
        self.recordedVideo = args.get("video", False)
        if self.recordedVideo:
            self.videoFilenanme = args["video"]

        # Get config
        config = Config()
        self.debugPrint = config.get("minesweeper.analysis.debugPrint", False)
        self.analysis_width = config.get("minesweeper.analysis.imagewidth",
                                         480)
        self.blur_radius = config.get("minesweeper.analysis.burrradius", 11)
        #self.minSize = config.get("minesweeper.analysis.minsize", 10)
        self.minWidth = config.get("minesweeper.analysis.minWidth", 15)
        self.minHeight = config.get("minesweeper.analysis.minHeight", 10)
        # Scale factors for real-world measures
        self.angleAdjustment = config.get("minesweeper.analysis.anglescale",
                                          2.6)  #1.3#0.55

        # define the lower and upper boundaries of the target
        # colour in the HSV color space, then initialize the
        useCalibrationColours = config.get(
            "minesweeper.analysis.useCalibrationColours", True)
        if not useCalibrationColours:
            useLEDColours = config.get("minesweeper.analysis.useLEDColours",
                                       False)
            if useLEDColours:
                # For LED:
                self.colourTargetLower = tuple(
                    config.get("minesweeper.analysis.colourTargetLowerLED",
                               [155, 24, 200
                                ]))  #(165,90,100)#(158,60,90) #(160,128,24)
                self.colourTargetUpper = tuple(
                    config.get("minesweeper.analysis.colourTargetUpperLED",
                               [175, 255, 255]))  #(175,255,255) #(180,255,255)
            else:
                # For test biscuit tin lid
                self.colourTargetLower = tuple(
                    config.get("minesweeper.analysis.colourTargetLowerTest",
                               [165, 94, 69]))
                self.colourTargetUpper = tuple(
                    config.get("minesweeper.analysis.colourTargetUpperTest",
                               [180, 255, 255]))

        self.showImage = config.get("minesweeper.display.image", True)
        self.trailSize = config.get("minesweeper.display.trail", 25)
        self.frameDelayMs = config.get("minesweeper.analysis.frameDelayMs",
                                       20)  # delay after each frame analysis
        config.save()

        # Load calibration values
        configCal = Config("calibrationMinesweeper.json")
        if useCalibrationColours:
            self.colourTargetLower = tuple(
                configCal.get("minesweeper.analysis.colourTargetLower", None))
            self.colourTargetUpper = tuple(
                configCal.get("minesweeper.analysis.colourTargetUpper", None))
        self.cameraNearestVisibleDistance = configCal.get(
            "distance.analysis.nearest", 130)
        self.cameraNearestVisiblePixels = int(
            self.cameraNearestVisibleDistance *
            3.5)  # Rough approximation equivallent!!
        self.cameraFurthestVisiblePixel = configCal.get(
            "distance.analysis.horizon", 500)
        self.cameraHeightDistance = configCal.get(
            "distance.analysis.cameraHeight", 170)
        calibrationResolution = configCal.get(
            "distance.analysis.calibrationResolution", [480, 640])
        self.cameraHeightAdjustment = np.sqrt(
            self.cameraHeightDistance * self.cameraHeightDistance +
            self.cameraNearestVisibleDistance * self.
            cameraNearestVisibleDistance) / self.cameraNearestVisibleDistance
        # Adjust for the analysis picture resolution being different to the calibrator
        self.cameraFurthestVisiblePixel = self.cameraFurthestVisiblePixel * self.analysis_width // calibrationResolution[
            1]

        # Results IPC
        self.resultsIpc = ImageAnalysisSharedIPC()
        self.resultsIpc.create()

        # Yaw reading accessor
        self.sensors = SensorAccessFactory.getSingleton()
        self.yawAccessor = self.sensors.yaw()
	def __init__(self):
		# Initialise the IPC classes
		self.lineIPC = LineAnalysisSharedIPC()
		self.lineIPC.read()
		self.imageIPC = ImageAnalysisSharedIPC()
		self.imageIPC.read()