Пример #1
0
def run_test(filename,only_im,roomin):
	#comment out to silence logger
	try:
		if os.environ['DEBUG'] == '2':
			debug = True #this line is changed
		else:
			debug = False
	except KeyError:
		debug = False
	
	#from phones import args.camera.split('-')[0] as phone
	phone = __import__('phones.' + 'lumia_1020', fromlist=[1,])
	camera = phone.cameras[0]

	imag_proc = __import__('processors.' + 'opencv_fft', fromlist=[1,]).imag_proc

	if only_im:
		try:
			centers, radii, estimated_frequencies, shape =\
					imag_proc(filename, 0, camera, debug)
			return estimated_frequencies
		except Exception as e:
			logger.warn('Exception: {}'.format(e))
			raise
	else:
		from aoa_full import aoa_full
		room = __import__('rooms.' + roomin, fromlist=[1,])
		try:
			rx_location, rx_rotation, location_error = aoa_full(
					filename, camera, room, imag_proc, debug)
			return location_error
		except Exception as e:
			return "false"
			logger.warn('Exception: {}'.format(e))
			raise
Пример #2
0
Файл: test.py Проект: glfpes/VLP
def run_test(filename, only_im, roomin):
    # comment out to silence logger
    try:
        if os.environ["DEBUG"] == "2":
            debug = True  # this line is changed
        else:
            debug = False
    except KeyError:
        debug = False

        # from phones import args.camera.split('-')[0] as phone
    phone = __import__("phones." + "lumia_1020", fromlist=[1])
    camera = phone.cameras[0]

    imag_proc = __import__("processors." + "opencv_fft", fromlist=[1]).imag_proc

    if only_im:
        try:
            centers, radii, estimated_frequencies, shape = imag_proc(filename, 0, camera, debug)
            return estimated_frequencies
        except Exception as e:
            logger.warn("Exception: {}".format(e))
            raise
    else:
        from aoa_full import aoa_full

        room = __import__("rooms." + roomin, fromlist=[1])
        try:
            rx_location, rx_rotation, location_error = aoa_full(filename, camera, room, imag_proc, debug)
            return location_error
        except Exception as e:
            return "false"
            logger.warn("Exception: {}".format(e))
            raise
Пример #3
0
def on_image_received(input_image_path):
	directory, fname = os.path.split(input_image_path)
	img_name, ext = os.path.splitext(fname)
	root, img = os.path.split(directory)
	result_path = os.path.join(root, 'result', img_name + '.result.txt')
	output_path = os.path.join(root, 'result', img_name + '.log.txt')

	size = PIL.Image.open(input_image_path).size
	if (7712 in size) and (4352 in size):
		camera = phones.lumia_1020.back
	elif (7136 in size) and (5360 in size):
		camera = phones.lumia_1020.back
	elif (960 in size) and (1280 in size):
		camera = phones.lumia_1020.front
	else:
		raise NotImplementedError('Unknown phone type for image dimensions: ' + str(size))

	# Copy work to an output file
	logger.copy_to_file(output_path)

	try:
		rx_location, rx_rotation, location_error = aoa_full(
				input_image_path,
				camera,
				rooms.test_rig,
				processors.opencv_fft.imag_proc,
				False,
				)
		logger.info('rx_location = {}'.format(rx_location))
		logger.info('rx_rotation =\n{}'.format(rx_rotation))
		logger.info('location_error = {}'.format(location_error))

		ofile = open(result_path, 'w')
		ofile.write('rx_location = {}\n'.format(rx_location))
		ofile.write('rx_rotation =\n{}\n'.format(rx_rotation))
		ofile.write('location_error = {}\n'.format(location_error))
		ofile.close()
		logger.info('Result saved to {}'.format(result_path))

		data = {
				'rx_location' : list(rx_location),
				'rx_rotation' : rx_rotation.tolist(),
				'location_error' : location_error,
				'image_name' : img_name,
		}

		req = urllib2.Request('http://inductor.eecs.umich.edu:8081/WEgwAGyc9N')
		req.add_header('Content-Type', 'application/json')

		response = urllib2.urlopen(req, json.dumps(data))
		logger.info('Result posted to gatd')

	finally:
		logger.close_copy_file()
Пример #4
0
            raise
    else:
        from aoa_full import aoa_full

        try:
            room = __import__('rooms.' + args.room, fromlist=[
                1,
            ])
        except ImportError:
            logger.error('Unknown room')
            raise
        try:
            rx_location, rx_rotation, location_error = aoa_full(
                args.filename,
                camera,
                room,
                imag_proc,
                actual_location=args.actual_location,
                k_val_method=args.k_val_method,
            )
            logger.info('rx_location = {}'.format(rx_location))
            if args.actual_location is not None:
                logger.info(' rx_loc_err = {}'.format(
                    map(abs, rx_location - args.actual_location)))
                logger.info('x, y, z err = {} {}'.format(
                    dist(rx_location, args.actual_location), room.units))
                rx_location[2] = 0
                args.actual_location[2] = 0
                logger.info('   x, y err = {} {}'.format(
                    dist(rx_location, args.actual_location), room.units))
            logger.info('rx_rotation =\n{}'.format(rx_rotation))
        except Exception as e:
Пример #5
0
		try:
			centers, radii, estimated_frequencies, shape =\
					imag_proc(args.filename, 0, camera, debug)
			for c,r,f in zip(centers, radii, estimated_frequencies):
				logger.info('{}: {} pixel radius. Freq {}'.format(c, r, f))
			#logger.info('shape = {}'.format(shape))
		except Exception as e:
			logger.warn('Exception: {}'.format(e))
			raise
	else:
		from aoa_full import aoa_full
		try:
			room = __import__('rooms.' + args.room, fromlist=[1,])
		except ImportError:
			logger.error('Unknown room')
			raise
		try:
			rx_location, rx_rotation, location_error = aoa_full(
					args.filename, camera, room, imag_proc, debug)
			logger.info('rx_location = {}'.format(rx_location))
			logger.info('rx_rotation =\n{}'.format(rx_rotation))
			logger.info('location_error = {}'.format(location_error))
			logfile=open('log.txt','w')
			logfile.write('rx_location = {}\n'.format(rx_location))
			logfile.write('rx_rotation =\n{}\n'.format(rx_rotation))
			logfile.write('location_error = {}\n'.format(location_error))
			logfile.close()
		except Exception as e:
			logger.warn('Exception: {}'.format(e))
			raise
Пример #6
0
def on_image_received(input_image_path):
    directory, fname = os.path.split(input_image_path)
    img_name, ext = os.path.splitext(fname)
    root, img = os.path.split(directory)
    result_path = os.path.join(root, 'result', img_name + '.result.txt')
    output_path = os.path.join(root, 'result', img_name + '.log.txt')

    hfile = open(os.path.splitext(input_image_path)[0] + '.headers')
    headers = dict()
    for h in hfile:
        k, v = h.split(':', 1)
        headers[k.strip().lower()] = v.strip()

    try:
        phone = getattr(phones, headers['x-luxapose-phone-type'].lower())
        camera = getattr(phone, headers['x-luxapose-camera'].lower())
    except (KeyError, AttributeError):
        logger.warn(
            "Bad or missing headers, attempting to guess phone and camera")
        # Fall back to guessing
        size = PIL.Image.open(input_image_path).size
        if (7712 in size) and (4352 in size):
            camera = phones.lumia_1020.back
        elif (7136 in size) and (5360 in size):
            camera = phones.lumia_1020.back
        elif (960 in size) and (1280 in size):
            camera = phones.lumia_1020.front
        else:
            raise NotImplementedError(
                'Unknown phone type for image dimensions: ' + str(size))

    # Override room to ipsn for demo
    room = rooms.ipsn15

    #try:
    #	hint = headers['x-luxapose-ble-loc-hints'].split()[0].strip()
    #	room = getattr(rooms, hint)
    #except KeyError:
    #	logger.warn("No location hint. Assuming demo_floor")
    #	room = rooms.demo_floor
    #except AttributeError:
    #	logger.error("Location hint for unknown room: {}".format(hint))
    #	logger.error("Skipping image in unknown room")
    #	return

    source_ip = headers['x-luxapose-source-ip']
    user = headers['x-luxapose-user']

    # Copy work to an output file
    logger.copy_to_file(output_path)

    try:
        rx_location, rx_rotation, location_error = aoa_full(
            input_image_path,
            camera,
            room,
            processors.opencv_fft.imag_proc,
        )
        logger.primary('rx_location = {}'.format(rx_location))
        logger.info('rx_rotation =\n{}'.format(rx_rotation))
        logger.info('location_error = {}'.format(location_error))

        ofile = open(result_path, 'w')
        ofile.write('rx_location = {}\n'.format(rx_location))
        ofile.write('rx_rotation =\n{}\n'.format(rx_rotation))
        ofile.write('location_error = {}\n'.format(location_error))
        ofile.close()
        logger.debug('Result saved to {}'.format(result_path))

        m_avg.append(rx_location)
        if len(m_avg) > 3:
            m_avg.pop(0)
        m = map(lambda x: sum(x) / len(x), zip(*m_avg))
        logger.primary('m_avg_loc = {}'.format(m))

        #data = {
        #		'rx_location' : list(rx_location),
        #		'rx_rotation' : rx_rotation.tolist(),
        #		'location_error' : location_error,
        #		'image_name' : img_name,
        #		'phone_ip' : source_ip,
        #		'user': user,
        #}

        #req = urllib2.Request('http://gatd.eecs.umich.edu:8081/WEgwAGyc9N')
        #req.add_header('Content-Type', 'application/json')

        #response = urllib2.urlopen(req, json.dumps(data))
        #logger.info('Result posted to gatd')

    finally:
        logger.close_copy_file()

    print('')
    print('')
Пример #7
0
		except Exception as e:
			logger.warn('Exception: {}'.format(e))
			raise
	else:
		from aoa_full import aoa_full

		try:
			room = __import__('rooms.' + args.room, fromlist=[1,])
		except ImportError:
			logger.error('Unknown room')
			raise
		try:
			rx_location, rx_rotation, location_error = aoa_full(
					args.filename,
					camera, room,
					imag_proc,
					actual_location=args.actual_location,
					k_val_method=args.k_val_method,
					)
			logger.info('rx_location = {}'.format(rx_location))
			if args.actual_location is not None:
				logger.info(' rx_loc_err = {}'.format(
					map(abs, rx_location - args.actual_location)))
				logger.info('x, y, z err = {} {}'.format(
					dist(rx_location, args.actual_location),
					room.units))
				rx_location[2] = 0
				args.actual_location[2] = 0
				logger.info('   x, y err = {} {}'.format(
					dist(rx_location, args.actual_location),
					room.units))
Пример #8
0
Файл: run.py Проект: glfpes/IPS
	except IndexError:
		# A camera was not specified, use the default (elem 0) for this phone
		camera = phone.cameras[0]
	except AttributeError:
		# Found the phone, but not the specified camera
		logger.error("Unknown phone / camera combination")
		raise


	try:
		room = __import__('rooms.' + args.room, fromlist=[1,])
	except ImportError:
		logger.error('Unknown room')
		raise
	try:
		rx_location, rx_rotation, location_error = aoa_full(
				camera, room, debug)
		logger.info('rx_location = {}'.format(rx_location))
		logger.info('rx_rotation =\n{}'.format(rx_rotation))
		logger.info('location_error = {}'.format(location_error))
		logfile=open('log.txt','w')
		logfile.write('rx_location = {}\n'.format(rx_location))
		logfile.write('rx_rotation =\n{}\n'.format(rx_rotation))
		logfile.write('location_error = {}\n'.format(location_error))
		logfile.close()
		logfile=open('log_location.txt','w')
		logfile.write(format(rx_location))
		logfile.close()
	except Exception as e:
		logger.warn('Exception: {}'.format(e))
		raise
Пример #9
0
def on_image_received(input_image_path):
	directory, fname = os.path.split(input_image_path)
	img_name, ext = os.path.splitext(fname)
	root, img = os.path.split(directory)
	result_path = os.path.join(root, 'result', img_name + '.result.txt')
	output_path = os.path.join(root, 'result', img_name + '.log.txt')

	hfile = open(os.path.splitext(input_image_path)[0]+'.headers')
	headers = dict()
	for h in hfile:
		k,v = h.split(':', 1)
		headers[k.strip().lower()] = v.strip()

	try:
		phone = getattr(phones, headers['x-luxapose-phone-type'].lower())
		camera = getattr(phone, headers['x-luxapose-camera'].lower())
	except (KeyError, AttributeError):
		logger.warn("Bad or missing headers, attempting to guess phone and camera")
		# Fall back to guessing
		size = PIL.Image.open(input_image_path).size
		if (7712 in size) and (4352 in size):
			camera = phones.lumia_1020.back
		elif (7136 in size) and (5360 in size):
			camera = phones.lumia_1020.back
		elif (960 in size) and (1280 in size):
			camera = phones.lumia_1020.front
		else:
			raise NotImplementedError('Unknown phone type for image dimensions: ' + str(size))

	# Override room to ipsn for demo
	room = rooms.ipsn15

	#try:
	#	hint = headers['x-luxapose-ble-loc-hints'].split()[0].strip()
	#	room = getattr(rooms, hint)
	#except KeyError:
	#	logger.warn("No location hint. Assuming demo_floor")
	#	room = rooms.demo_floor
	#except AttributeError:
	#	logger.error("Location hint for unknown room: {}".format(hint))
	#	logger.error("Skipping image in unknown room")
	#	return

	source_ip = headers['x-luxapose-source-ip']
	user = headers['x-luxapose-user']

	# Copy work to an output file
	logger.copy_to_file(output_path)

	try:
		rx_location, rx_rotation, location_error = aoa_full(
				input_image_path,
				camera,
				room,
				processors.opencv_fft.imag_proc,
				)
		logger.primary('rx_location = {}'.format(rx_location))
		logger.info('rx_rotation =\n{}'.format(rx_rotation))
		logger.info('location_error = {}'.format(location_error))

		ofile = open(result_path, 'w')
		ofile.write('rx_location = {}\n'.format(rx_location))
		ofile.write('rx_rotation =\n{}\n'.format(rx_rotation))
		ofile.write('location_error = {}\n'.format(location_error))
		ofile.close()
		logger.debug('Result saved to {}'.format(result_path))

		m_avg.append(rx_location)
		if len(m_avg) > 3:
			m_avg.pop(0)
		m = map(lambda x: sum(x)/len(x), zip(*m_avg))
		logger.primary('m_avg_loc = {}'.format(m))

		#data = {
		#		'rx_location' : list(rx_location),
		#		'rx_rotation' : rx_rotation.tolist(),
		#		'location_error' : location_error,
		#		'image_name' : img_name,
		#		'phone_ip' : source_ip,
		#		'user': user,
		#}

		#req = urllib2.Request('http://gatd.eecs.umich.edu:8081/WEgwAGyc9N')
		#req.add_header('Content-Type', 'application/json')

		#response = urllib2.urlopen(req, json.dumps(data))
		#logger.info('Result posted to gatd')

	finally:
		logger.close_copy_file()

	print('')
	print('')