-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial code showing intersections on a osm map
- Loading branch information
Showing
207 changed files
with
256,007 additions
and
942 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <chrono> | ||
#include <iostream> | ||
#include <thread> | ||
#include <opencv2/core.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
#include <opencv2/highgui.hpp> | ||
#include "BasicGraphics.h" | ||
|
||
BasicGraphics::BasicGraphics(float minLat, float minLon, float maxLat, float maxLon) | ||
{ | ||
this->minLat = minLat; | ||
this->minLon = minLon; | ||
this->maxLat = maxLat; | ||
this->maxLon = maxLon; | ||
} | ||
|
||
void BasicGraphics::simulate() | ||
{ | ||
this->loadBackgroundImg(); | ||
while (true) | ||
{ | ||
// sleep at every iteration to reduce CPU usage | ||
// TODO: Shorten below delay once ready for active updating | ||
std::this_thread::sleep_for(std::chrono::milliseconds(10000)); | ||
|
||
// update graphics | ||
this->drawIntersections(); | ||
} | ||
} | ||
|
||
void BasicGraphics::loadBackgroundImg() | ||
{ | ||
// create window | ||
_windowName = "Rideshare Simulation"; | ||
cv::namedWindow(_windowName, cv::WINDOW_NORMAL); | ||
|
||
// load image and create copy to be used for semi-transparent overlay | ||
cv::Mat background = cv::imread(_bgFilename); | ||
_images.push_back(background); // first element is the original background | ||
_images.push_back(background.clone()); // second element will be the transparent overlay | ||
_images.push_back(background.clone()); // third element will be the result image for display | ||
} | ||
|
||
void BasicGraphics::drawIntersections() | ||
{ | ||
// reset images | ||
_images.at(1) = _images.at(0).clone(); | ||
_images.at(2) = _images.at(0).clone(); | ||
|
||
// Get image rows and columns to help with coordinate adjustments for image | ||
float imgRows = _images.at(0).rows; | ||
float imgCols = _images.at(0).cols; | ||
|
||
// create overlay from intersections | ||
for (auto intersect : _intersections) | ||
{ | ||
std::vector<float> position = intersect.getPosition(); | ||
|
||
// Adjust the position based on lat & lon in image | ||
position[0] = (position[0] - minLon) / (maxLon - minLon); | ||
position[1] = (maxLat - position[1]) / (maxLat - minLat); | ||
|
||
// set color according to traffic light and draw the intersection as a circle | ||
//std::cout << "Position at: " << (int)(position[0] * imgCols) << "," << (int)(position[1] * imgRows) << std::endl; | ||
cv::circle(_images.at(1), cv::Point2d((int)(position[0] * imgCols), (int)(position[1] * imgRows)), 25, cv::Scalar(0, 255, 0), -1); | ||
} | ||
|
||
float opacity = 0.85; | ||
cv::addWeighted(_images.at(1), opacity, _images.at(0), 1.0 - opacity, 0, _images.at(2)); | ||
std::cout << "Image size is: " << _images.at(0).rows << " rows, and " << _images.at(0).cols << " columns." << std::endl; | ||
|
||
// display background and overlay image | ||
cv::imshow(_windowName, _images.at(2)); | ||
cv::waitKey(33); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef BASICGRAPHICS_H | ||
#define BASICGRAPHICS_H | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <opencv2/core.hpp> | ||
#include "BasicIntersection.h" | ||
|
||
class BasicGraphics | ||
{ | ||
public: | ||
// constructor / destructor | ||
BasicGraphics(float minLat, float minLon, float maxLat, float maxLon); | ||
|
||
// getters / setters | ||
void setBgFilename(std::string filename) { _bgFilename = filename; } | ||
void setIntersections(std::vector<BasicIntersection> &intersections) { _intersections = intersections; }; | ||
|
||
// typical behaviour methods | ||
void simulate(); | ||
|
||
private: | ||
// typical behaviour methods | ||
void loadBackgroundImg(); | ||
void drawIntersections(); | ||
|
||
// member variables | ||
float minLat, minLon, maxLat, maxLon; | ||
std::vector<BasicIntersection> _intersections; | ||
std::string _bgFilename; | ||
std::string _windowName; | ||
std::vector<cv::Mat> _images; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef BASICINTERSECTION_H | ||
#define BASICINTERSECTION_H | ||
|
||
#include <vector> | ||
|
||
class BasicIntersection | ||
{ | ||
public: | ||
// constructor / destructor | ||
|
||
// getters / setters | ||
void setPosition(float x, float y) { _x = x; _y = y;} | ||
std::vector<float> getPosition() { return {_x, _y}; } | ||
|
||
private: | ||
// member variables | ||
float _x, _y; | ||
}; | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.