|
@@ -22,11 +22,15 @@ namespace Assets.StreetLight.Scripts
|
|
|
|
|
|
void Start()
|
|
void Start()
|
|
{
|
|
{
|
|
- if (File.Exists(Configuration.Instance.HomographyFilePath))
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
var homographyArray = GetHomographyArrayFromFile();
|
|
var homographyArray = GetHomographyArrayFromFile();
|
|
PositionCalculator = new PositionCalculator(homographyArray);
|
|
PositionCalculator = new PositionCalculator(homographyArray);
|
|
}
|
|
}
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ Debug.LogError($"Could not load homography: {ex.Message}");
|
|
|
|
+ }
|
|
|
|
|
|
Persons = new ObservableCollection<Person>();
|
|
Persons = new ObservableCollection<Person>();
|
|
personDetector = new ZedPersonDetector(FindObjectOfType<ZEDManager>());
|
|
personDetector = new ZedPersonDetector(FindObjectOfType<ZEDManager>());
|
|
@@ -59,23 +63,25 @@ namespace Assets.StreetLight.Scripts
|
|
personDetector.PersonsDetected -= InvokeDetectionReady;
|
|
personDetector.PersonsDetected -= InvokeDetectionReady;
|
|
}
|
|
}
|
|
|
|
|
|
- public Vector3 CalculateUnityPosition(Person person)
|
|
|
|
|
|
+ private void PersonDetector_PersonsDetected(object sender, IEnumerable<Person> e)
|
|
{
|
|
{
|
|
- if (PositionCalculator == null)
|
|
|
|
|
|
+ var detectedIds = new HashSet<int>();
|
|
|
|
+ foreach (var detectedPerson in e)
|
|
{
|
|
{
|
|
- throw new InvalidOperationException("Cannot calculate Unity position because the PositionCalculator is not initialized. This might occur when the homography file is not found or not in the right format.");
|
|
|
|
|
|
+ var person = Persons.SingleOrDefault(p => p.Id == detectedPerson.Id);
|
|
|
|
+ if (person == null)
|
|
|
|
+ {
|
|
|
|
+ person = new Person(detectedPerson.Id, PositionCalculator);
|
|
|
|
+ Persons.Add(person);
|
|
|
|
+ }
|
|
|
|
+ person.WorldPosition = detectedPerson.WorldPosition;
|
|
|
|
+ detectedIds.Add(detectedPerson.Id);
|
|
}
|
|
}
|
|
|
|
|
|
- return PositionCalculator.WorldPositionToUnityPosition(person.WorldPosition);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void PersonDetector_PersonsDetected(object sender, IEnumerable<Person> e)
|
|
|
|
- {
|
|
|
|
- // TODO: update carefully instead of clear and add all
|
|
|
|
- Persons.Clear();
|
|
|
|
- foreach (var person in e)
|
|
|
|
|
|
+ var personsToBeRemoved = Persons.Where(p => !detectedIds.Contains(p.Id)).ToArray();
|
|
|
|
+ foreach (var person in personsToBeRemoved)
|
|
{
|
|
{
|
|
- Persons.Add(person);
|
|
|
|
|
|
+ Persons.Remove(person);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|