Skip to content

Commit

Permalink
Refactor naming + Fix small errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vietanhdev committed Mar 7, 2021
1 parent e755339 commit 9bf2282
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 52 deletions.
7 changes: 1 addition & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,9 @@ int main(int argc, char *argv[]) {
}

// Set simulation
main_window->setInputSource(InputFromSimulation);
main_window->setInputSource(kInputFromSimulation);
main_window->setSimulation((Simulation*)simulation);

} else if (input_source == "camera") {

// cout << "Input from camera has not been supported yet." << endl;
// exit(1);

}

main_window->startVideoGrabber();
Expand Down
6 changes: 3 additions & 3 deletions src/perception/camera_model/birdview_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cv::Mat BirdViewModel::transformImage(const cv::Mat &img) {
four_image_points.to_vector(img_width, img_height);

cv::warpPerspective(img, dst, birdview_transform_matrix,
cv::Size(birdview_img_width, birdview_img_height));
cv::Size(kBirdviewImgWidth, kBirdviewImgHeight));
return dst;
}

Expand Down Expand Up @@ -72,11 +72,11 @@ cv::Mat BirdViewModel::getDangerZone(const cv::Size img_size, float danger_dista

std::lock_guard<std::mutex> guard(mtx);
int tl_y = car_y_in_pixel - danger_distance / height_pixel_to_meter_ratio;
int tl_x = birdview_img_width / 2 - car_width_in_pixel / 2;
int tl_x = kBirdviewImgWidth / 2 - car_width_in_pixel / 2;
int br_x = tl_x + car_width_in_pixel;
int br_y = car_y_in_pixel - 1;

cv::Mat danger_mask(cv::Size(birdview_img_width, birdview_img_height), CV_8UC1, cv::Scalar(0));
cv::Mat danger_mask(cv::Size(kBirdviewImgWidth, kBirdviewImgHeight), CV_8UC1, cv::Scalar(0));
cv::rectangle(danger_mask, cv::Rect(tl_x, tl_y, br_x-tl_x, br_y-tl_y),
cv::Scalar(255), -1);

Expand Down
4 changes: 2 additions & 2 deletions src/perception/camera_model/birdview_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class BirdViewModel {

int birdview_img_width = 1000;
int birdview_img_height = 10000;
static constexpr int kBirdviewImgWidth = 1000;
static constexpr int kBirdviewImgHeight = 10000;
FourPoints four_points =
FourPoints(cv::Point2f(250, 8000), cv::Point2f(750, 8000),
cv::Point2f(750, 8500), cv::Point2f(250, 8500));
Expand Down
2 changes: 1 addition & 1 deletion src/perception/camera_model/camera_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ class CameraModel {
bool isCalibrated();
};

#endif
#endif // CAMERA_MODEL_H
2 changes: 1 addition & 1 deletion src/perception/camera_model/four_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class FourPoints {
}
};

#endif // UTILS_H
#endif // FOUR_POINTS_H
2 changes: 1 addition & 1 deletion src/perception/lane_detection/lane_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <vector>

#include "lane_line.h"
#include "perception/lane_detection/lane_line.h"
#include "perception/common/uff_models/unet/unet.h"
#include "utils/timer.h"

Expand Down
23 changes: 12 additions & 11 deletions src/perception/object_detection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ list(APPEND CUDA_NVCC_FLAGS "-D_FORCE_INLINES -Xcompiler -fPIC")
# Build sign classifier
add_subdirectory(./traffic_sign_classification)

include_directories(${CUDA_INCLUDE_DIRS}
${TENSORRT_INCLUDE_DIR}
${OpenCV_INCLUDE_DIRS}
../common/utils/include
../common/onnx_models/include
../common/onnx_models/onnx-tensorrt
../common/uff_models/common/include
../common/uff_models/classification_net
../configs/
./traffic_sign_classification
)
include_directories(
".."
${CUDA_INCLUDE_DIRS}
${TENSORRT_INCLUDE_DIR}
${OpenCV_INCLUDE_DIRS}
"../common/utils/include"
"../common/onnx_models/include"
"../common/onnx_models/onnx-tensorrt"
"../common/uff_models/common/include"
"../common/uff_models/classification_net"
"../configs/"
)

file(GLOB CPP_SRC ../common/onnx_models/*.cpp *.cpp)
file(GLOB CU_SRC ../common/onnx_models/*.cu)
Expand Down
2 changes: 1 addition & 1 deletion src/perception/object_detection/object_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <memory>
#include <string>

#include "../common/onnx_models/include/ctdetNet.h"
#include "perception/common/onnx_models/include/ctdetNet.h"
#include "traffic_object.h"
#include "traffic_sign_classification/sign_classifier.h"

Expand Down
2 changes: 1 addition & 1 deletion src/perception/object_detection/traffic_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ class TrafficObject {
bbox(detection.bbox), classId(detection.classId), prob(detection.prob), traffic_sign_type(traffic_sign_type) {}
};

#endif
#endif // TRAFFIC_OBJECT_H
3 changes: 1 addition & 2 deletions src/sensors/can_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class CANReader {
struct timeval tv, timeout_config = {0, 0};
struct stat dirstat;
fd_set rdfs;
char
ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))];
char ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))];
int running = 1;
int nbytes, maxdlen;
int ret;
Expand Down
22 changes: 11 additions & 11 deletions src/sensors/car_gps_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ CarGPSReader::CarGPSReader() {

int CarGPSReader::printError() {
switch (signal_status) {
case SIGNAL_NORMAL:
case kSignalNormal:
cout << "Socket: No error" << endl;
break;
case SIGNAL_NOT_CONNECTED:
case kSignalNotConnected:
cout << "Socket: Not connected" << endl;
break;
case SIGNAL_SOCKET_CREATION_ERROR:
case kSignalsocketCreationError:
cout << "Socket: Socket creation error" << endl;
break;
case SIGNAL_INVALID_ADDRESS:
case kSignalInvalidAddress:
cout << "Socket: Invalid address/ Address not supported" << endl;
break;
case SIGNAL_CONNECTION_FAILED:
case kSignalConnectionFailed:
cout << "Socket: Connection failed" << endl;
break;
}
Expand All @@ -35,7 +35,7 @@ int CarGPSReader::printError() {
// Return 0: success
// Return 1: fail
int CarGPSReader::updateProps() {
if (getSignalStatus() == SIGNAL_NOT_CONNECTED) {
if (getSignalStatus() == kSignalNotConnected) {
init_socket_conn();
}

Expand All @@ -58,7 +58,7 @@ int CarGPSReader::updateProps() {
nmea_parser->readBuffer((uint8_t *)buffer, sizeof(buffer));

std::lock_guard<std::mutex> lk(car_prop_mutex);
signal_status = SIGNAL_NORMAL;
signal_status = kSignalNormal;
longitude = gps->fix.longitude;
latitude = gps->fix.latitude;
car_speed = gps->fix.speed;
Expand Down Expand Up @@ -98,9 +98,9 @@ int CarGPSReader::init_socket_conn() {
}

if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
setSignalStatus(SIGNAL_SOCKET_CREATION_ERROR);
setSignalStatus(kSignalsocketCreationError);
// cerr << "\n Socket creation error \n" << endl;
return SIGNAL_SOCKET_CREATION_ERROR;
return kSignalsocketCreationError;
}

struct timeval tv;
Expand All @@ -113,13 +113,13 @@ int CarGPSReader::init_socket_conn() {

// Convert IPv4 and IPv6 addresses from text to binary form
if (inet_pton(AF_INET, socket_server.c_str(), &serv_addr.sin_addr) <= 0) {
setSignalStatus(SIGNAL_INVALID_ADDRESS);
setSignalStatus(kSignalInvalidAddress);
// cerr << "\nInvalid address/ Address not supported \n" << endl;
return -1;
}

if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
setSignalStatus(SIGNAL_CONNECTION_FAILED);
setSignalStatus(kSignalConnectionFailed);
// cerr << "\nConnection Failed \n" << endl;
return -1;
}
Expand Down
12 changes: 6 additions & 6 deletions src/sensors/car_gps_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ using namespace std;


enum SignalStatus {
SIGNAL_NORMAL = 0,
SIGNAL_NOT_CONNECTED = 1,
SIGNAL_SOCKET_CREATION_ERROR = -1,
SIGNAL_INVALID_ADDRESS = -2,
SIGNAL_CONNECTION_FAILED = -3
kSignalNormal = 0,
kSignalNotConnected = 1,
kSignalsocketCreationError = -1,
kSignalInvalidAddress = -2,
kSignalConnectionFailed = -3
};

class CarGPSReader {
Expand All @@ -47,7 +47,7 @@ class CarGPSReader {
// -1: Socket creation error
// -2: Invalid address/ Address not supported
// -3: Connection failed
int signal_status = SIGNAL_NOT_CONNECTED;
int signal_status = kSignalNotConnected;


std::mutex car_prop_mutex;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/input_source.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef MAIN_H
#define MAIN_H

enum InputSource {InputFromSimulation, InputFromWebcam};
enum InputSource {kInputFromSimulation, kInputFromWebcam};

#endif
6 changes: 3 additions & 3 deletions src/ui/traffic_sign_images.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <opencv2/opencv.hpp>

struct TrafficSignImage {
const int IMG_WIDTH = 48;
const int IMG_HEIGHT = 48;
static constexpr int kImgWidth = 48;
static constexpr int kImgHeight = 48;
int speed;
cv::Mat image;
TrafficSignImage(int speed, std::string img_path, std::string default_img_path): speed(speed) {
Expand All @@ -16,7 +16,7 @@ struct TrafficSignImage {
if (image.empty()) {
image = cv::imread(default_img_path);
}
cv::resize(image, image, cv::Size(IMG_WIDTH, IMG_HEIGHT));
cv::resize(image, image, cv::Size(kImgWidth, kImgHeight));
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/utils/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ error_t _dupenv_s(char **pValue, size_t *len, const char *pPath) {
}
#endif // _WIN32

void setLabel(cv::Mat &im, const std::string label, const cv::Point &origin) {
void setLabel(cv::Mat &im, const std::string& label, const cv::Point &origin) {
int fontface = cv::FONT_HERSHEY_SIMPLEX;
double scale = 0.5;
int thickness = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ml_cam {

void setLabel(cv::Mat& im, const std::string label, const cv::Point & origin);
void setLabel(cv::Mat& im, const std::string& label, const cv::Point & origin);
std::string getHomePath();

QImage Mat2QImage(cv::Mat const& src);
Expand Down

0 comments on commit 9bf2282

Please sign in to comment.