Skip to content

Commit

Permalink
Implemented demo of scenario analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
elisabethhoppe committed Jun 7, 2016
1 parent 8745572 commit 7a3ea9d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/ScenarioAnalysation/analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// <http://www.gnu.org/licenses/>.
//

//std
#include <iostream>

#include "analyser.h"

Expand Down Expand Up @@ -55,6 +57,7 @@ Scenario* Analyser::Analyse(FrameDetectionData detected_objects){
bool detected = current_scenario->Detect(detected_objects);

if(detected){
std::cout << "Analyser: A scenario was detected! " <<std::endl;
return current_scenario;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/ScenarioAnalysation/humans_in_front_of_bus_scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// <http://www.gnu.org/licenses/>.
//

//std
#include <iostream>

#include "humans_in_front_of_bus_scenario.h"

bool HumansInFrontOfBusScenario::Detect(FrameDetectionData detected_objects){
Expand All @@ -31,6 +34,7 @@ bool HumansInFrontOfBusScenario::Detect(FrameDetectionData detected_objects){
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){
Expand All @@ -47,7 +51,7 @@ bool HumansInFrontOfBusScenario::Detect(FrameDetectionData detected_objects){
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;
Expand Down
50 changes: 49 additions & 1 deletion src/ScenarioAnalysation/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@

//std
#include <iostream>
#include <sstream>
#include <vector>
#include <list>

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


using namespace std;

Expand All @@ -45,8 +49,52 @@ int main(int argc, const char* argv[]) {
std::vector<Scenario*> possible_scenarios;
possible_scenarios.push_back(new HumansInFrontOfBusScenario());

Analyser analyser(possible_scenarios);

// create fake detected elements for test issues
std::vector<int> human_position;
std::vector<int> human_size;

human_position.push_back(10);
human_position.push_back(10);

human_size.push_back(10);
human_size.push_back(50);

Element human(human_position, human_size);


std::vector<int> vehicle_position;
std::vector<int> vehicle_size;

vehicle_position.push_back(5);
vehicle_position.push_back(5);

vehicle_size.push_back(20);
vehicle_size.push_back(15);

Element vehicle(vehicle_position, vehicle_size);


FrameDetectionData frame_detection;

std::list<Element> all_humans;
all_humans.push_back(human);

std::list<Element> all_vehicles;
all_vehicles.push_back(vehicle);

frame_detection.AddElementsOfType(OBJECT_HUMAN, all_humans);
frame_detection.AddElementsOfType(OBJECT_VEHICLE, all_vehicles);


// analyse the fake frame detection data
Scenario* result_scenario = analyser.Analyse(frame_detection);

if( HumansInFrontOfBusScenario* result = dynamic_cast<HumansInFrontOfBusScenario*>(result_scenario) ){

std::cout << "Main: Humans in front of bus scenario detected! " << std::endl;
}

return 0;
}
11 changes: 10 additions & 1 deletion src/ScenarioAnalysation/scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// <http://www.gnu.org/licenses/>.
//

//std
#include <iostream>
#include <math.h>

#include "scenario.h"
Expand Down Expand Up @@ -59,12 +61,19 @@ bool Scenario::Overlap(Element first, Element second){
int second_max_x = second_min_x + second.GetBoxSize().at(0);
int second_max_y = second_min_y + second.GetBoxSize().at(1);

// std::cout << "SCENARIO::OVERLAP: first min, max x;y : " << first_min_x << " " << first_max_x << " " << first_min_y << " " << first_max_y <<std::endl;
// std::cout << "SCENARIO::OVERLAP: second min, max x;y : " << second_min_x << " " << second_max_x << " " << second_min_y << " " << second_max_y <<std::endl;

if( (first_min_x <= second_min_x) || (first_max_x >= second_max_x) ){

if( (first_min_x <= second_min_x) || (first_max_x >= second_max_x) || ( (first_min_x >= second_min_x) && (first_max_x <= second_max_x) ) ){

// std::cout << " SCENARIO::OVERLAP erstes if " <<std::endl;

if( ( (second_min_y >= first_min_y) && (second_min_y <= first_max_y) )
|| ( (second_max_y <= first_max_y) && (second_max_y >= first_min_y) ) ){


std::cout << "Scenario: There are overlapping elements in the frame! " << std::endl;
return true;
}

Expand Down

0 comments on commit 7a3ea9d

Please sign in to comment.