Skip to content

Commit

Permalink
Update README. Organize code
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatake2222 committed Sep 11, 2021
1 parent 627f8ca commit ac18583
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 72 deletions.
Binary file modified 00_doc/class_diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed 00_doc/data_flow.jpg
Binary file not shown.
Binary file added 00_doc/data_flow_diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
287 changes: 256 additions & 31 deletions 00_doc/design_document.drawio

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ https://user-images.githubusercontent.com/11009876/132947317-3c839522-b347-4a8d-
tensorflow/lite/tools/make/download_dependencies.sh
```
- Download prebuilt library (You don't need this step if you use TensorRT)
- Download prebuilt libraries (third_party.zip) from https://github.com/iwatake2222/InferenceHelper/releases/ (<- Not in this repository)
- Download prebuilt libraries (third_party.zip) from https://github.com/iwatake2222/InferenceHelper/releases/
- Extract it to `inference_helper/third_party/`
- Download models
- Download models (resource.zip) from https://github.com/iwatake2222/self-driving-ish_computer_vision_system/releases/
- Download models (resource.zip) from https://github.com/iwatake2222/self-driving-ish_computer_vision_system/releases/
- Extract it to `resource/`
## Windows (Visual Studio)
Expand Down Expand Up @@ -96,14 +96,14 @@ cmake .. -DENABLE_TENSORRT=on # Use TensorRT
```
## Note
It will take around 10 - 20 minutes when you execute the app for the first time, because the model conversion runs
It will take around 10 - 20 minutes when you execute the app for the first time, due to model conversion
# Software Design
## Class Diagram
![class_diagram](00_doc/class_diagram.jpg)
## Data Flow
![data_flow](00_doc/data_flow.jpg)
## Data Flow Diagram
![data_flow_diagram](00_doc/data_flow_diagram.jpg)
# Model Information
Expand Down
6 changes: 3 additions & 3 deletions image_processor/lane_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int32_t LaneDetection::Process(const cv::Mat& mat, const cv::Mat& mat_transform,
error = CurveFitting::ErrorMaxQuadraticRegression(line, a, b, c);
}
if (error > 0.1 && line.size() > 2) {
/* Use linear regression, if I didn't use quadratic regression or the result of quadratic regression is not good (the maximum error > 0.3m) */
/* Use linear regression, if I didn't use quadratic regression or the result of quadratic regression is not good (the maximum error > 0.1m) */
(void)CurveFitting::SolveLinearRegression(line, b, c);
error = CurveFitting::ErrorMaxLinearRegression(line, b, c);
if (error > 0.1) {
Expand Down Expand Up @@ -144,9 +144,9 @@ int32_t LaneDetection::Process(const cv::Mat& mat, const cv::Mat& mat_transform,
if (current_line_valid_list_[line_index]) {
float kMixRatio = 0.05f;
if (!line_valid_list_[line_index]) {
kMixRatio = 1.0f; /* detect the line at the first time */
kMixRatio = 1.0f; /* detect the line for the first time */
} else if (line_det_cnt_list_[line_index] < 10) {
kMixRatio = 0.2f; /* the first few frames after the line is detected at the first time */
kMixRatio = 0.2f; /* the first few frames after the line is detected for the first time */
}
auto& line_coeff = line_coeff_list_[line_index];
line_coeff.a = current_line_coeff_list[line_index].a * kMixRatio + line_coeff.a * (1.0 - kMixRatio);
Expand Down
64 changes: 31 additions & 33 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ limitations under the License.
#include "common_helper_cv.h"

/*** Macro ***/
#define WORK_DIR RESOURCE_DIR
#define DEFAULT_INPUT_IMAGE RESOURCE_DIR"/dashcam_00.jpg"
#define LOOP_NUM_FOR_TIME_MEASUREMENT 10
//#define SEPARATE_WINDOW

#define WORK_DIR RESOURCE_DIR
static constexpr char kDefaultInputImage[] = RESOURCE_DIR"/dashcam_00.jpg";
static constexpr int32_t kLoopNumForTimeMeasurement = 10;
static constexpr int32_t kNumThread = 4;
static constexpr int32_t kInputImageSize = 960;
static constexpr char kOutputVideoFilename[] = ""; /* out.mp4 */
static constexpr bool kIsSeparateWindow = false;
static constexpr char kWindowNormal[] = "WindowNormal";
static constexpr char kWindowTopView[] = "WindowTopView";
static constexpr char kWindowSegmentation[] = "WindowSegmentation";
Expand All @@ -47,7 +46,6 @@ static constexpr char kWindowParam[] = "WindowParam";


/*** Global variable ***/
/* variables for processing time measurement */
static bool is_pause = false;
static bool is_process_one_frame = false;

Expand Down Expand Up @@ -238,7 +236,7 @@ int main(int argc, char* argv[])
double total_time_image_process = 0;

/* Find source image */
std::string input_name = (argc > 1) ? argv[1] : DEFAULT_INPUT_IMAGE;
std::string input_name = (argc > 1) ? argv[1] : kDefaultInputImage;
cv::VideoCapture cap; /* if cap is not opened, src is still image */
if (!CommonHelper::FindSourceImage(input_name, cap)) {
return -1;
Expand All @@ -250,29 +248,29 @@ int main(int argc, char* argv[])
/* Initialize image processor library */
cv::setNumThreads(kNumThread);
std::unique_ptr<ImageProcessorIf> image_processor = ImageProcessorIf::Create();
ImageProcessorIf::InputParam input_param = { WORK_DIR, kNumThread };
ImageProcessorIf::InputParam input_param = { RESOURCE_DIR, kNumThread };
if (image_processor->Initialize(input_param) != 0) {
printf("Initialization Error\n");
return -1;
}

/* Initialize cvui */
cvui::init(kWindowNormal);
#ifdef SEPARATE_WINDOW
cvui::init(kWindowTopView);
cvui::init(kWindowSegmentation);
cvui::init(kWindowDepth);
cv::setMouseCallback(kWindowTopView, CallbackMouseMain, image_processor.get());
#else
cv::setMouseCallback(kWindowNormal, CallbackMouseMain, image_processor.get());
#endif
if (kIsSeparateWindow) {
cvui::init(kWindowTopView);
cvui::init(kWindowSegmentation);
cvui::init(kWindowDepth);
cv::setMouseCallback(kWindowTopView, CallbackMouseMain, image_processor.get());
} else {
cv::setMouseCallback(kWindowNormal, CallbackMouseMain, image_processor.get());
}
cvui::init(kWindowParam);


/*** Process for each frame ***/
cv::Mat mat_original;
int32_t frame_cnt = 0;
for (frame_cnt = 0; cap.isOpened() || frame_cnt < LOOP_NUM_FOR_TIME_MEASUREMENT || is_pause; frame_cnt++) {
for (frame_cnt = 0; cap.isOpened() || frame_cnt < kLoopNumForTimeMeasurement || is_pause; frame_cnt++) {
const auto& time_all0 = std::chrono::steady_clock::now();
/* Read image */
const auto& time_cap0 = std::chrono::steady_clock::now();
Expand All @@ -294,23 +292,23 @@ int main(int argc, char* argv[])
const auto& time_image_process1 = std::chrono::steady_clock::now();

/* Display result */
#ifdef SEPARATE_WINDOW
cvui::imshow(kWindowNormal, result.mat_output);
if (!result.mat_output_topview.empty()) cvui::imshow(kWindowTopView, result.mat_output_topview);
if (!result.mat_output_segmentation.empty()) cvui::imshow(kWindowSegmentation, result.mat_output_segmentation);
if (!result.mat_output_depth.empty()) cvui::imshow(kWindowDepth, result.mat_output_depth);
#else
cv::Mat mat(cv::Size(result.mat_output.cols + result.mat_output_topview.cols, result.mat_output.rows + result.mat_output_segmentation.rows), CV_8UC3);
result.mat_output.copyTo(mat(cv::Rect(0, 0, result.mat_output.cols, result.mat_output.rows)));
if (!result.mat_output_topview.empty()) result.mat_output_topview.copyTo(mat(cv::Rect(result.mat_output.cols, 0, result.mat_output_topview.cols, result.mat_output_topview.rows)));
if (!result.mat_output_depth.empty()) result.mat_output_depth.copyTo(mat(cv::Rect(result.mat_output.cols, result.mat_output_topview.rows, result.mat_output_depth.cols, result.mat_output_depth.rows)));
if (!result.mat_output_segmentation.empty()) result.mat_output_segmentation.copyTo(mat(cv::Rect(0, result.mat_output.rows, result.mat_output_segmentation.cols, result.mat_output_segmentation.rows)));
cvui::imshow(kWindowNormal, mat);
if (frame_cnt == 0 && kOutputVideoFilename[0] != '\0') {
writer = cv::VideoWriter(kOutputVideoFilename, cv::VideoWriter::fourcc('M', 'P', '4', 'V'), (std::max)(10.0, cap.get(cv::CAP_PROP_FPS)), cv::Size(mat.cols, mat.rows));
if (kIsSeparateWindow) {
cvui::imshow(kWindowNormal, result.mat_output);
if (!result.mat_output_topview.empty()) cvui::imshow(kWindowTopView, result.mat_output_topview);
if (!result.mat_output_segmentation.empty()) cvui::imshow(kWindowSegmentation, result.mat_output_segmentation);
if (!result.mat_output_depth.empty()) cvui::imshow(kWindowDepth, result.mat_output_depth);
} else {
cv::Mat mat(cv::Size(result.mat_output.cols + result.mat_output_topview.cols, result.mat_output.rows + result.mat_output_segmentation.rows), CV_8UC3);
result.mat_output.copyTo(mat(cv::Rect(0, 0, result.mat_output.cols, result.mat_output.rows)));
if (!result.mat_output_topview.empty()) result.mat_output_topview.copyTo(mat(cv::Rect(result.mat_output.cols, 0, result.mat_output_topview.cols, result.mat_output_topview.rows)));
if (!result.mat_output_depth.empty()) result.mat_output_depth.copyTo(mat(cv::Rect(result.mat_output.cols, result.mat_output_topview.rows, result.mat_output_depth.cols, result.mat_output_depth.rows)));
if (!result.mat_output_segmentation.empty()) result.mat_output_segmentation.copyTo(mat(cv::Rect(0, result.mat_output.rows, result.mat_output_segmentation.cols, result.mat_output_segmentation.rows)));
cvui::imshow(kWindowNormal, mat);
if (frame_cnt == 0 && kOutputVideoFilename[0] != '\0') {
writer = cv::VideoWriter(kOutputVideoFilename, cv::VideoWriter::fourcc('M', 'P', '4', 'V'), (std::max)(10.0, cap.get(cv::CAP_PROP_FPS)), cv::Size(mat.cols, mat.rows));
}
if (writer.isOpened()) writer.write(mat);
}
if (writer.isOpened()) writer.write(mat);
#endif

/* Parameter control window */
loop_param(image_processor);
Expand Down

0 comments on commit ac18583

Please sign in to comment.