class QrDetectionTests(unittest.TestCase):
    def setUp(self):
        rospack = rospkg.RosPack()
        self.pkgDir = rospack.get_path('rapp_testing_tools')

        self.ch = RappPlatformAPI()

    def test_detect_qr(self):
        imagepath = path.join(self.pkgDir, 'test_data', 'qr_code_rapp.jpg')

        valid_results = {
            'qr_centers': [{
                'y': 165,
                'x': 165
            }],
            'qr_messages': ['rapp project qr sample'],
            'error': ''
        }

        response = self.ch.qrDetection(imagepath)
        self.assertEqual(response, valid_results)

    def test_detect_qr_erroneous(self):
        response = self.ch.qrDetection('')
        self.assertNotEqual(response['error'], u'')
        response = self.ch.qrDetection(3)
        self.assertNotEqual(response['error'], u'')
        response = self.ch.qrDetection([])
        self.assertNotEqual(response['error'], u'')
class QrDetectionTests(unittest.TestCase):

    def setUp(self):
        rospack = rospkg.RosPack()
        self.pkgDir = rospack.get_path('rapp_testing_tools')

        self.ch = RappPlatformAPI()

    def test_detect_qr(self):
        imagepath = path.join(self.pkgDir, 'test_data','qr_code_rapp.jpg')

        valid_results = {
            'qr_centers': [{'y': 165, 'x': 165}],
            'qr_messages': ['rapp project qr sample'],
            'error': ''
        }

        response = self.ch.qrDetection(imagepath)
        self.assertEqual(response, valid_results)

    def test_detect_qr_erroneous(self):
        response = self.ch.qrDetection('')
        self.assertNotEqual(response['error'], u'')
        response = self.ch.qrDetection(3)
        self.assertNotEqual(response['error'], u'')
        response = self.ch.qrDetection([])
        self.assertNotEqual(response['error'], u'')
Beispiel #3
0
    def RappQrDetection(self, imageString, image):

        path = imageORimageString(imageString, image)  #path of saved image.
        ch = RappPlatformAPI()  ###############address = addr
        response = ch.qrDetection(path)  # Use the server's path of the image.
        if not response.get('error') == "":
            abort(500, response.get('error'))
        return response
Beispiel #4
0
class NaoInterface:
	def __init__(self):
		self.rh = RappRobot()
		self.ch = RappPlatformAPI()
		rospy.Timer(rospy.Duration(0.1), self.sonarsCallback)
		rospy.Timer(rospy.Duration(5), self.qrDetectionCallback)
		#self.pub = rospy.Publisher('/inner/sonar_measurements', LaserScan, queue_size=1)
		self.pub1 = rospy.Publisher('/inner/qr_detection', RfidSensorMeasurementMsg, queue_size=1)
		self.s = rospy.Service('set_object', SetObject, self.setNewObjectCallback)
		self.s1 = rospy.Service('get_objects', GetObjects, self.getObjectsCallback)
		
		self.objects = {}
		self.static_objects = []
		
	def sonarsCallback(self, event):
		sonars = self.rh.sensors.getSonarsMeasurements()['sonars']
		laser_msg = LaserScan()
		laser_msg.ranges.append(sonars['front_right'])
		laser_msg.ranges.append(sonars['front_left'])
		laser_msg.range_max = 1.00
		laser_msg.angle_increment = 0.785398185253
		laser_msg.angle_min = -0.392699092627
		self.pub.publish(laser_msg)
		
	def qrDetectionCallback(self, event):
		print "QrDetection"
		rospack = rospkg.RosPack()
		img_path = rospack.get_path('nao_localization') + "/cfg/nao_capture.jpg"
		self.rh.vision.capturePhoto("/home/nao/test.jpg", "front", "640x480")
		print img_path
		self.rh.utilities.moveFileToPC("/home/nao/test.jpg", img_path)
		#svc = QrDetection(imageFilepath="/home/chrisa/test.jpg")
		response = self.ch.qrDetection(img_path)
		print response
		print response['qr_messages']
		if "Localization" in response['qr_messages']:
			qr_msg = RfidSensorMeasurementMsg()
			qr_msg.rfid_tags_ids.append(response['qr_messages'])
			self.pub1.publish(qr_msg)
		head_yaw = self.rh.humanoid_motion.getJointAngles(["HeadYaw"])['angles'][0]
		print head_yaw
		
	def setNewObjectCallback(self, req):
		print "setNewObjectCallback"
		print req
		self.objects[req.object.message] = req.object
		res = SetObjectResponse()
		res.success = True
		return res
		
	def getObjectsCallback(self, req):
		res = GetObjectsResponse()
		if req.localization_type == "dynamic":
			for i in range(0, len(self.objects)):
				obj = ObjectMsg()
				obj.x = self.objects.values()[i].x
				obj.y = self.objects.values()[i].y
				obj.message = self.objects.values()[i].message
				obj.type = self.objects.values()[i].type
				if req.object_type == self.objects.values()[i].type or req.object_type == "all" or req.object_type == "":
					if obj.message in res.objects:
						continue
					res.objects.append(obj)
		elif req.localization_type == "static":
			for i in range(0, len(self.static_objects)):
				obj = ObjectMsg()
				obj.x = static_objects[i].x
				obj.y = static_objects[i].y
				obj.message = static_objects[i].message
				obj.type = static_objects[i].type
				res.objects.append(obj)
		elif req.localization_type == "all":
			for i in range(0, len(self.objects)):
				obj = ObjectMsg()
				obj.x = self.objects.values()[i].x
				obj.y = self.objects.values()[i].y
				obj.message = self.objects.values()[i].message
				obj.type = self.objects.values()[i].type
				if req.object_type == self.objects.values()[i].type or req.object_type == "all" or req.object_type == "":
					if obj.message in res.objects:
						continue
					res.objects.append(obj)
			for i in range(0, len(self.static_objects)):
				obj = ObjectMsg()
				obj.x = static_objects[i].x
				obj.y = static_objects[i].y
				obj.message = static_objects[i].message
				obj.type = static_objects[i].type
				res.objects.append(obj)
		else:
			print "No such type"
		res.success = True	
		print res.objects
		return res		
Beispiel #5
0
        rh.motion.disableMotors()

        # Delay to stabilize the head
        time.sleep(1)

        image_name = "img_" + str(i * 3 + j) + ".jpg"
        # Capture an image from the NAO cameras
        rh.vision.capturePhoto("/home/nao/" + image_name, "front", "640x480")
        # Get the photo to the PC
        rh.utilities.moveFileToPC("/home/nao/" + image_name, \
            home + image_name)
        
        imageFilepath = home + image_name
        
        # Get the responses
        qr_resp = ch.qrDetection(imageFilepath)
        face_resp = ch.faceDetection(imageFilepath, False)
        obj_resp = ch.objectRecognitionCaffe(imageFilepath)

        # Prints for debugging purposes
        print str(global_counter) + ": " + str(qr_resp)
        print str(global_counter) + ": " + str(face_resp)
        print str(global_counter) + ": " + str(obj_resp)
        print "\n"

        # Store the objects and the respective head angles
        # Store the unique QR codes
        if len(qr_resp['qr_centers']) != 0:
            # Transform Image-frame angles to NAO-frame
            obj_frame_ang = pointToRads(
                    qr_resp['qr_centers'][0]['x'],