def __init__(self,camera, now):
		global fdr
		global idr
		global currentTime
		self.camera =  camera
		self.now = now
		fdr = DataRecorder()
		idr = DataRecorder()
		if not os.path.exists(RGB_path):
    			os.makedirs(RGB_path)
		if not os.path.exists(GS_path):
    			os.makedirs(GS_path)
		if not os.path.exists(Otsu_path):
    			os.makedirs(Otsu_path)
示例#2
0
 def __init__(self, config):
     self._config = config
     logging.basicConfig(level=self._config.logging_level)
     self.logger = logging.getLogger('SpeedTrap.LogSpeed')
     self.logger.debug("Creating LogSpeed() instance")
     self._current_max = 0
     self._video_recorder = VideoRecorder2(config)
     self._data_recorder = DataRecorder(config)
     self._video_recorder.start_recorder()
     self._current_filename = None
     self._current_record = False
    def writeCameraStatus(self):
        global camera
        global now
        fdr = DataRecorder()
        fdr.openFDR()
        if camera is None:
            now = datetime.datetime.now()
            currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(
                now.second)
            camStatus = [
                currentTime +
                "\t\tCamera\t\t\t\tNot Connected.\t\t\tInactive\n"
            ]
            sys.exit(0)
        else:
            now = datetime.datetime.now()
            currentTime = str(self.now.hour) + ":" + str(
                self.now.minute) + ":" + str(self.now.second)
            camStatus = [currentTime + "\t\tCamera\t\t\t\tOK.\t\t\tActive\n"]

        fdr.writeToFDR(camStatus)
        fdr.closeFDR()
	def generatePixelData(self):
		global counter
		global idr
		global image_Data
    		global imgh
		global previous_Height
		global previous_Width
		idr = DataRecorder()
	    	imgh = 0
    	    	colnum = 0
    	    	cell_Height = 0
    	    	current_Cell_Height = 0
	    	cell_Width = 0
    	    	current_Cell_Width = 0
	    	address = Otsu_path+str(counter)+".jpg"
            	image = Image.open(address)
            	imwidth, imheight = image.size
            	pix = image.load()
            	impix = (126, 0, 0)
            	image_Data = [0 for i in xrange(16)]
            	cell_Height = imheight * 0.25
	    	cell_Width = imwidth * 0.25
            	current_Cell_Height = current_Cell_Height + cell_Height #150
	    	current_Cell_Width = current_Cell_Width + cell_Width #200
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
	    	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #400
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #600
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #800
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
	    	previous_Height = imgh #150
	    	previous_Width = 0
	    	current_Cell_Width = 0
	    	current_Cell_Height = current_Cell_Height + cell_Height #300
	    	current_Cell_Width = current_Cell_Width + cell_Width #200
	    	colnum = colnum + 1
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #400
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #600
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #800
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
	    	previous_Height = imgh
	    	previous_Width = 0
	    	current_Cell_Width = 0
	    	current_Cell_Height = current_Cell_Height + cell_Height #450
	    	current_Cell_Width = current_Cell_Width + cell_Width #200
	    	colnum = colnum + 1
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #400
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #600
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #800
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
	    	previous_Height = imgh
	    	previous_Width = 0
	    	current_Cell_Width = 0
	    	current_Cell_Height = current_Cell_Height + cell_Height #600
	    	current_Cell_Width = current_Cell_Width + cell_Width #200
	    	colnum = colnum + 1
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #400
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #600
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
            	colnum = colnum + 1
	    	current_Cell_Width = current_Cell_Width + cell_Width #800
            	self.countRedPixels(current_Cell_Width, current_Cell_Height, colnum, impix, pix)
	    	previous_Height = imgh
	    	previous_Width = 0
	    	colnum = 0
	    	idr.openIDR()
		data = ""
            	while colnum<16:
                	data = data + str(image_Data[colnum])+","
			colnum = colnum + 1
	    	data = data + "?\n"
            	idr.writeToIDR(str(data))
	    	terminators = "%\n%\n%"
	    	idr.writeToIDR(terminators)
	    	image_Data = None
	    	colnum = 0
            	idr.closeIDR()
示例#5
0
    def __init__(self, opt):
        self.session_id = opt.session_id
        # Initialize camera and window
        self.cap = cv.VideoCapture(opt.input_device,
                                   eval(f'cv.{opt.input_api}'))
        assert self.cap.isOpened(), 'Failed to initialize video capture!'

        self.width, self.height = opt.video_width, opt.video_height
        self.cap.set(cv.CAP_PROP_FRAME_WIDTH, self.width)
        self.cap.set(cv.CAP_PROP_FRAME_HEIGHT, self.height)
        self.window_name = 'tutorial'
        if opt.fullscreen:
            cv.namedWindow(self.window_name, cv.WINDOW_NORMAL)
            cv.setWindowProperty(self.window_name, cv.WND_PROP_FULLSCREEN,
                                 cv.WINDOW_FULLSCREEN)
        else:
            cv.namedWindow(self.window_name)
        self.width_qr = self.width // 4
        self.width_half = self.width // 2
        self.width_3qr = self.width // 4 * 3
        self.border_margin = round(max(self.width, self.height) * 0.025)

        # Initialize openpose library
        import os
        import sys
        sys.path.append(os.fspath(opt.op_path / 'python/openpose/Release'))
        os.environ['PATH'] += f';{os.fspath(opt.op_path/"x64/Release")}'
        os.environ['PATH'] += f';{os.fspath(opt.op_path/"bin")}'

        try:
            import pyopenpose as op
        except ImportError as e:
            print('Error: OpenPose library could not be found.')
            raise e

        self._op_wrapper = op.WrapperPython()
        self._op_wrapper.configure({
            'model_folder':
            os.fspath(opt.op_path / '../models/'),
            'model_pose':
            'BODY_25',
            'number_people_max':
            1
        })
        self._op_wrapper.start()
        self._datum = op.Datum()

        # Raw data recorder
        if not opt.no_save:
            self.recorder = DataRecorder(
                (self.width, self.height), 24,
                f'records/{opt.session_id}/{int(time())}')
        else:
            self.recorder = DummyDataRecorder()

        # Handler of each state
        self.handlers = {
            State.Ready: self.handle_ready,
            State.PoseReady: self.handle_pose_ready,
            State.PoseMeasuring: self.handle_pose_measuring,
            State.Finish: self.handle_finish,
        }

        # Load assets
        self.assets = Assets('assets/')
        self.poses: List[Posture] = [
            Pose_01, Pose_02, Pose_03, Pose_04, Pose_05, Pose_06, Pose_08,
            Pose_09, Pose_10
        ]
        self.poses_ui: List[InformationLayer] = generate_info_layers(
            self.poses)

        self.running: bool = True
        self.state: State = State.Ready
        self.pose_index_iter: Iterator[int] = iter(range(len(self.poses)))
        self.current_pose_i: int = 0
        self.t_start: float = perf_counter()
        self.fail_counter = deque([False] * opt.fail_tolerance,
                                  maxlen=opt.fail_tolerance)
        self.angle: float = np.pi
        self.confidence: float = 0
        self.score: int = 0

        self.keypoints: np.ndarray = np.array([], np.float32)
        self.frame: np.ndarray = np.array([], np.uint8)
示例#6
0
class iMaze(object):

    now = datetime.datetime.now()
    currentDate = str(now.day) + "." + str(now.month) + "." + str(now.year)
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    fdr = DataRecorder()
    fdr.openFDR()
    startOfData = "################################# DATE: " + currentDate + " #################################\n"
    deviceTableHeaders = "Timestamp\tDevice\t\t\t\tStatus\t\t\tValue\n"
    fdr.writeToFDR(startOfData)
    fdr.writeToFDR(deviceTableHeaders)

    finch = pyfinch.Finch()
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    finchStatus = [currentTime + "\t\tFinch\t\t\t\tOK.\t\t\tActive\n"]
    fdr.writeToFDR(finchStatus)
    time.sleep(1.0)
    finch.led(255, 0, 0)
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    ledOneStatus = [currentTime + "\t\tLED_1\t\t\t\tOK.\t\t\t255,0,0 RGB\n"]
    fdr.writeToFDR(ledOneStatus)
    time.sleep(1.0)
    finch.led(0, 255, 0)
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    ledTwoStatus = [currentTime + "\t\tLED_2\t\t\t\tOK.\t\t\t0,255,0 RGB\n"]
    fdr.writeToFDR(ledTwoStatus)
    time.sleep(1.0)
    finch.led(0, 0, 255)
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    ledThreeStatus = [currentTime + "\t\tLED_3\t\t\t\tOK.\t\t\t0,0,255 RGB\n"]
    fdr.writeToFDR(ledThreeStatus)
    time.sleep(1.0)
    finch.buzzer(0.1, 700)
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    buzzerStatus = [currentTime + "\t\tBuzzer\t\t\t\tOK.\t\t\t0.1s,700Hz\n"]
    fdr.writeToFDR(buzzerStatus)
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    thermometerStatus = [
        currentTime + "\t\tThermometer\t\t\tOK.\t\t\t" +
        str(finch.temperature()) + " C\n"
    ]
    fdr.writeToFDR(thermometerStatus)
    time.sleep(1.0)
    finch.wheels(1.0, 0)
    time.sleep(0.1)
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    leftWheelStatus = [currentTime + "\t\tLeft Wheel\t\t\tOK.\t\t\t255m/s\n"]
    fdr.writeToFDR(leftWheelStatus)
    finch.wheels(0, 1.0)
    time.sleep(0.1)
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    rightWheelStatus = [currentTime + "\t\tRight Wheel\t\t\tOK.\t\t\t255m/s\n"]
    fdr.writeToFDR(rightWheelStatus)
    finch.wheels(1.0, 1.0)
    time.sleep(0.5)
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    accelerometerStatus = [
        currentTime + "\t\tAccelerometer\t\t\tOK.\t\t\t" +
        str(finch.acceleration()) + " m/s\n"
    ]
    fdr.writeToFDR(accelerometerStatus)
    finch.idle()
    now = datetime.datetime.now()
    currentTime = str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
    finchStatus = [currentTime + "\t\tFinch\t\t\t\tOK.\t\t\tIdle\n"]
    fdr.writeToFDR(finchStatus)
    fdr.closeFDR()

    cam = Camera(now)
    cam.setCamera()
    cam.startCamera()
    cam.writeCameraStatus()
    imp = ImageProcessing(cam.getCamera(), now)
    while True:
        imp.captureRGBImage()
        imp.convertRGBtoGS()
        imp.convertGStoOtsu()
        imp.generatePixelData()
        classify = DirectionClassifier()
        direction = classify.predict("IDR.arff")
        print direction
        break