Skip to content

Commit

Permalink
Merge pull request #50 from JoHeinrich/analysationClasses
Browse files Browse the repository at this point in the history
Analysation subdirectory added
  • Loading branch information
elisabethhoppe committed Jun 7, 2016
2 parents 089617b + 7a3ea9d commit 778afaf
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ add_subdirectory(src/ObjectDetection)

add_subdirectory(src/StreamDecoder)

add_subdirectory(src/ScenarioAnalysation)

file(GLOB_RECURSE sources "./src/*.cpp")
file(GLOB_RECURSE headers "./src/*.h")

Expand Down
3 changes: 1 addition & 2 deletions src/ObjectDetection/element.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//
// element.cpp

// Projectname: amos-ss16-proj5
//
// Created on 02.06.2016.
Expand Down
6 changes: 2 additions & 4 deletions src/ObjectDetection/element.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

//
// element.h
// Projectname: amos-ss16-proj5
//
// Created on 02.06.2016.
Expand Down Expand Up @@ -36,8 +34,8 @@ class Element {
/**
* Constructor
*
* @param position The vector with position of the element
* @param box_size The vector with the size of the bounding box of the element
* @param position The vector with position of the element (x, y)
* @param box_size The vector with the size of the bounding box of the element (width, height)
*/
Element(std::vector<int> position, std::vector<int> box_size);

Expand Down
11 changes: 5 additions & 6 deletions src/ObjectDetection/frame_detection_data.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//
// frame_detection_data.cpp

// Projectname: amos-ss16-proj5
//
// Created on 03.06.2016.
Expand All @@ -25,23 +24,23 @@

#include "frame_detection_data.h"

std::list<Element> FrameDetectionData::GetElementsOfType(std::string type){
std::list<Element> FrameDetectionData::GetElementsOfType(ObjectType type){

std::list<Element> result = all_elements_.at(type);

return result;

}

void FrameDetectionData::AddElementsOfType(std::string type, std::list<Element> elements){
void FrameDetectionData::AddElementsOfType(ObjectType type, std::list<Element> elements){

std::map<std::string, std::list<Element> >::iterator map_iterator;
std::map<ObjectType, std::list<Element> >::iterator map_iterator;

map_iterator = all_elements_.find(type);

if(map_iterator == all_elements_.end()){

all_elements_.insert(std::pair<std::string, std::list<Element> > (type, elements));
all_elements_.insert(std::pair<ObjectType, std::list<Element> > (type, elements));

}

Expand Down
17 changes: 8 additions & 9 deletions src/ObjectDetection/frame_detection_data.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

//
// FrameDetectionData.h
// Projectname: amos-ss16-proj5
//
// Created on 02.06.2016.
Expand Down Expand Up @@ -37,6 +35,10 @@
//element
#include "element.h"

// enum for the types of detected objects
enum ObjectType { OBJECT_HUMAN = 0, OBJECT_VEHICLE = 1 };


class FrameDetectionData {

public:
Expand All @@ -48,23 +50,20 @@ class FrameDetectionData {
*
* @return The list with all elements of the given type
*/
std::list<Element> GetElementsOfType(std::string type);
std::list<Element> GetElementsOfType(ObjectType type);

/**
* Adds a list of elements with a new type
* Adds a list of elements with a given type
*
* @param type The type of the elements
* @param elements The list with elements
*
*/
void AddElementsOfType(std::string type, std::list<Element> elements);
void AddElementsOfType(ObjectType type, std::list<Element> elements);


private:

//TODO: encapsulate type in own class?
std::vector<std::string> types_; ///< The vector with all existing types so far
std::map<std::string, std::list<Element> > all_elements_; ///< The map containing all elements of all types
std::map<ObjectType, std::list<Element> > all_elements_; ///< The map containing all elements of all types
};


Expand Down
26 changes: 26 additions & 0 deletions src/ScenarioAnalysation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 2.8)
project( analyser )
set (OUTPUT_NAME analyser)



set(sources
analyser.cpp
scenario.cpp
humans_in_front_of_bus_scenario.cpp
main.cpp
../ObjectDetection/element.cpp
../ObjectDetection/frame_detection_data.cpp

)

set(headers
analyser.h
scenario.h
humans_in_front_of_bus_scenario.h
../ObjectDetection/element.h
../ObjectDetection/frame_detection_data.h


)
add_executable( ${OUTPUT_NAME} ${sources} ${header} )
67 changes: 67 additions & 0 deletions src/ScenarioAnalysation/analyser.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// hdf_reader.cpp
// Projectname: amos-ss16-proj5
//
// Created on 10.05.2016.
// Copyright (c) 2016 de.fau.cs.osr.amos2016.gruppe5
//
// This file is part of the AMOS Project 2016 @ FAU
// (Friedrich-Alexander University Erlangen-Nürnberg)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//

//std
#include <iostream>

#include "analyser.h"

//object detection
#include "../ObjectDetection/element.h"


//std
#include <list>

Analyser::Analyser(std::vector<Scenario *> scenarios){

all_scenarios_ = scenarios;

}

void Analyser::AddScenario(Scenario* scenario){

all_scenarios_.push_back(scenario);

}

Scenario* Analyser::Analyse(FrameDetectionData detected_objects){

// iterate over all scenarios and return the first detected scenario
for(int i = 0; i < all_scenarios_.size(); i++){

Scenario* current_scenario = all_scenarios_.at(i);

bool detected = current_scenario->Detect(detected_objects);

if(detected){
std::cout << "Analyser: A scenario was detected! " <<std::endl;
return current_scenario;
}
}

return NULL;

}
70 changes: 70 additions & 0 deletions src/ScenarioAnalysation/analyser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

//
// analyser.h
// Projectname: amos-ss16-proj5
//
// Created on 03.06.2016.
// Copyright (c) 2016 de.fau.cs.osr.amos2016.gruppe5
//
// This file is part of the AMOS Project 2016 @ FAU
// (Friedrich-Alexander University Erlangen-Nürnberg)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//

#ifndef ANALYSER_H
#define ANALYSER_H

//std
#include <vector>

#include "../ObjectDetection/frame_detection_data.h"
#include "scenario.h"
#include "humans_in_front_of_bus_scenario.h"

class Analyser {

public:

/**
* Constructor.
*
* @param scenarios The vector with the possible scenarios
*/
Analyser(std::vector<Scenario*> scenarios);

/**
* Adds a scenario to the vector with analysed scenarios.
*
* @param scenario The scenario to add.
*/
void AddScenario(Scenario* scenario);

/**
* Analyses the frame detection data and detetermines which scenario is there
*
* @param detected_objects The frame data with detected objects
* @return The detected scenario
*/
Scenario* Analyse(FrameDetectionData detected_objects);

private:

std::vector<Scenario*> all_scenarios_; ///< Vector with all possible scenarios

};


#endif // ANALYSER_H
71 changes: 71 additions & 0 deletions src/ScenarioAnalysation/humans_in_front_of_bus_scenario.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

// Projectname: amos-ss16-proj5
//
// Created on 10.05.2016.
// Copyright (c) 2016 de.fau.cs.osr.amos2016.gruppe5
//
// This file is part of the AMOS Project 2016 @ FAU
// (Friedrich-Alexander University Erlangen-Nürnberg)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//

//std
#include <iostream>

#include "humans_in_front_of_bus_scenario.h"

bool HumansInFrontOfBusScenario::Detect(FrameDetectionData detected_objects){

// first: check whether there are humans detected

std::list<Element> humans = detected_objects.GetElementsOfType(OBJECT_HUMAN);
std::list<Element> vehicles = detected_objects.GetElementsOfType(OBJECT_VEHICLE);

std:: cout << "Humans in Front of Bus Scenario: Number of humans = " << humans.size() << " Number of vehicles = " << vehicles.size() << std::endl;
if(humans.size() != 0){

if(vehicles.size() != 0){

// check whether there are human objects which overlap with vehicle objects
std::list <Element>::const_iterator humans_iterator;

for(humans_iterator = humans.begin(); humans_iterator != humans.end(); ++humans_iterator){

Element current_human = *humans_iterator;

std::list <Element>::const_iterator vehicles_iterator;

for(vehicles_iterator = vehicles.begin(); vehicles_iterator != vehicles.end(); ++vehicles_iterator){

bool overlapping = Overlap(current_human, *vehicles_iterator);
// std::cout << "Humans in front of bus OVERLAPPING: " << overlapping << std::endl;
if(overlapping){

return true;

}

}
}

}

return false;
}

return false;
}

Loading

0 comments on commit 778afaf

Please sign in to comment.