Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Commit

Permalink
Stoplights adjusted ROI & Windows cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszg12 committed Jul 14, 2018
1 parent 8254e76 commit edc857b
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 78 deletions.
42 changes: 21 additions & 21 deletions CIRCUIT/opencv-app/opencv-app/include/ids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,27 +426,27 @@ static void update_auto_trackbars(int,void*){
}
//Creating in debug mode trackbars
void IDS::create_manual_trackbars(void){
cvNamedWindow("ids", 1);
cv::createTrackbar("Pixel", "ids", &pixelclock_slider, 40, update_suwaki);
cv::createTrackbar("Exposure", "ids", &exposure_slider, 30*30, update_suwaki);
cv::createTrackbar("FPS", "ids", &fps_slider, 100, update_suwaki);
cv::createTrackbar("Master", "ids", &Master_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Master", "ids", 100);
cv::createTrackbar("Green", "ids", &Green_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Green", "ids",100);
cv::createTrackbar("Red", "ids", &Red_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Red", "ids", 100);
cv::createTrackbar("Blue", "ids", &Blue_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Blue", "ids", 100);
cv::createTrackbar("Sharpness", "ids", &sharpness_slider, 9, update_suwaki);
cv::setTrackbarMin("Sharpness", "ids", 0);
cv::createTrackbar("Gamma", "ids", &Gamma, 300, update_suwaki);
cvNamedWindow(ids_windowname, 1);
cv::createTrackbar("Pixel", ids_windowname, &pixelclock_slider, 40, update_suwaki);
cv::createTrackbar("Exposure", ids_windowname, &exposure_slider, 30*30, update_suwaki);
cv::createTrackbar("FPS", ids_windowname, &fps_slider, 100, update_suwaki);
cv::createTrackbar("Master", ids_windowname, &Master_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Master", ids_windowname, 100);
cv::createTrackbar("Green", ids_windowname, &Green_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Green", ids_windowname,100);
cv::createTrackbar("Red", ids_windowname, &Red_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Red", ids_windowname, 100);
cv::createTrackbar("Blue", ids_windowname, &Blue_GAIN_Factor, 300, update_suwaki);
cv::setTrackbarMin("Blue", ids_windowname, 100);
cv::createTrackbar("Sharpness", ids_windowname, &sharpness_slider, 9, update_suwaki);
cv::setTrackbarMin("Sharpness", ids_windowname, 0);
cv::createTrackbar("Gamma", ids_windowname, &Gamma, 300, update_suwaki);
}
void IDS::create_auto_trackbars(void){
cvNamedWindow("IDS Settings", 1);
cv::createTrackbar("Min Exposure", "IDS Settings", &min_exposure_slider, 5*100, update_auto_trackbars);
cv::createTrackbar("Max Exposure", "IDS Settings", &max_exposure_slider, 30*100, update_auto_trackbars);
cv::createTrackbar("Reference", "IDS Settings", &reference_slider, 2000, update_auto_trackbars);
cv::createTrackbar("Hysteresis", "IDS Settings", &hysteresis_slider, 500, update_auto_trackbars);
cv::createTrackbar("Gamma", "IDS Settings", &Gamma, 400, update_auto_trackbars);
cvNamedWindow(ids_windowname, 1);
cv::createTrackbar("Min Exposure", ids_windowname, &min_exposure_slider, 5*100, update_auto_trackbars);
cv::createTrackbar("Max Exposure", ids_windowname, &max_exposure_slider, 30*100, update_auto_trackbars);
cv::createTrackbar("Reference", ids_windowname, &reference_slider, 2000, update_auto_trackbars);
cv::createTrackbar("Hysteresis", ids_windowname, &hysteresis_slider, 500, update_auto_trackbars);
cv::createTrackbar("Gamma", ids_windowname, &Gamma, 400, update_auto_trackbars);
}
8 changes: 4 additions & 4 deletions CIRCUIT/opencv-app/opencv-app/include/ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class IDS {
double max_exposure = 5.0;

int min_exposure_slider = 1;
int max_exposure_slider = 100;
int hysteresis_slider = 1;
int reference_slider = 2;
int max_exposure_slider = 200;
int hysteresis_slider = 10;
int reference_slider = 40;
UINT nSizeOfParam;
AES_CONFIGURATION *pAesConfiguration;
AES_PEAK_CONFIGURATION *pPeakConfiguration;
Expand All @@ -57,7 +57,7 @@ class IDS {
pthread_mutex_t signal_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t frame_signal = PTHREAD_COND_INITIALIZER;
public:

char ids_windowname[11] = {'I','D','S',' ','O','U','T','P','U','T'};
cv::Mat ids_frame = cv::Mat(IDS_HEIGHT, IDS_WIDTH, CV_8UC3);
pthread_mutex_t frame_mutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down
26 changes: 13 additions & 13 deletions CIRCUIT/opencv-app/opencv-app/include/lanedetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ void LaneDetector::CreateTrackbars()
{
cv::namedWindow("1.1 Yellow Line", 1);
cv::namedWindow("1.2 White Line", 1);
cv::namedWindow("3.1 Yellow Bird Eye", 1);
cv::namedWindow("3.2 White Bird Eye", 1);
cv::namedWindow("3.3 Line Accuracy",1);
cv::namedWindow("5 Cone Detect", 1);

cv::createTrackbar("Acc", "3.3 Line Accuracy", &Acc_value, 255, NULL);
cv::createTrackbar("Acc_filt", "3.3 Line Accuracy", &Acc_filt, 50, NULL);
cv::createTrackbar("Rdown", "5 Cone Detect", &R_down, 255, NULL);
cv::createTrackbar("Rup", "5 Cone Detect", &R_up, 255, NULL);
cv::createTrackbar("Gdown", "5 Cone Detect", &G_down, 255, NULL);
cv::createTrackbar("Gup", "5 Cone Detect", &G_up, 255, NULL);
cv::createTrackbar("Bdown", "5 Cone Detect", &B_down, 255, NULL);
cv::createTrackbar("Bup", "5 Cone Detect", &B_up, 255, NULL);
// cv::namedWindow("3.1 Yellow Bird Eye", 1);
// cv::namedWindow("3.2 White Bird Eye", 1);
// cv::namedWindow("3.3 Line Accuracy",1);
// cv::namedWindow("5 Cone Detect", 1);
cv::namedWindow("4.1 Yellow Vector", 1);
cv::createTrackbar("Acc", "4.1 Yellow Vector", &Acc_value, 255, NULL);
cv::createTrackbar("Acc_filt", "4.1 Yellow Vector", &Acc_filt, 50, NULL);
// cv::createTrackbar("Rdown", "5 Cone Detect", &R_down, 255, NULL);
// cv::createTrackbar("Rup", "5 Cone Detect", &R_up, 255, NULL);
// cv::createTrackbar("Gdown", "5 Cone Detect", &G_down, 255, NULL);
// cv::createTrackbar("Gup", "5 Cone Detect", &G_up, 255, NULL);
// cv::createTrackbar("Bdown", "5 Cone Detect", &B_down, 255, NULL);
// cv::createTrackbar("Bup", "5 Cone Detect", &B_up, 255, NULL);
cv::createTrackbar("Hdown", "1.1 Yellow Line", &H_down, 255, NULL);
cv::createTrackbar("Hup", "1.1 Yellow Line", &H_up, 255, NULL);
cv::createTrackbar("Sdown", "1.1 Yellow Line", &S_down, 255, NULL);
Expand Down
45 changes: 23 additions & 22 deletions CIRCUIT/opencv-app/opencv-app/include/stoplights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,23 @@ Fle include methods definition that can be used with StopLightDetector class

#include "stoplights.h"



#define FRAME_WIDTH 752 //1280
#define FRAME_HEIGHT 400 //720
#define IDS_HEIGHT_ROI 360
#define THRESH_LEVEL 35
#define BLUR_SIZE 15


//methode is making roi from input and returning it to output, number tells method with roi, you can test it with test_roi
void StopLightDetector::make_roi(cv::Mat &input, cv::Mat &output, int number) {
int upper_roi = 0;//IDS_HEIGHT_ROI/2;
int middle_roi = FRAME_WIDTH / 2;
int width_roi = FRAME_WIDTH / 3;
int height_roi = IDS_HEIGHT_ROI/2;
int upper_roi = 0;//IDS_HEIGHT/2;
int middle_roi = IDS_WIDTH / 2;
int width_roi = IDS_WIDTH / 3;
int height_roi = IDS_HEIGHT/2;
cv::Rect roi_rectangle1 = cv::Rect(middle_roi - width_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle2 = cv::Rect(middle_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle3 = cv::Rect(0, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle4 = cv::Rect(FRAME_WIDTH - width_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle4 = cv::Rect(IDS_WIDTH - width_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle5 = cv::Rect(0, upper_roi, middle_roi, height_roi);
cv::Rect roi_rectangle6 = cv::Rect(middle_roi, upper_roi, middle_roi, height_roi);

cv::Rect roi_rectangle7 = cv::Rect(adj_roi[0],adj_roi[1],adj_roi[2],adj_roi[3]);
switch (number) {
case 1:
output = input(roi_rectangle1);
Expand All @@ -49,42 +45,47 @@ void StopLightDetector::make_roi(cv::Mat &input, cv::Mat &output, int number) {
case 6:
output = input(roi_rectangle6);
break;
case 7:
output = input(roi_rectangle7);
}
}

//methode that tells us which roi is which
void StopLightDetector::test_roi(cv::Mat &input, cv::Mat &output) {
start_finding = true;
int upper_roi = 0;//IDS_HEIGHT_ROI/2;
int middle_roi = FRAME_WIDTH / 2;
int width_roi = FRAME_WIDTH / 3;
int height_roi = IDS_HEIGHT_ROI/2;
int upper_roi = 0;//IDS_HEIGHT/2;
int middle_roi = IDS_WIDTH / 2;
int width_roi = IDS_WIDTH / 3;
int height_roi = IDS_HEIGHT/2;
cv::Rect roi_rectangle1 = cv::Rect(middle_roi - width_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle2 = cv::Rect(middle_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle3 = cv::Rect(0, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle4 = cv::Rect(FRAME_WIDTH - width_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle4 = cv::Rect(IDS_WIDTH - width_roi, upper_roi, width_roi, height_roi);
cv::Rect roi_rectangle5 = cv::Rect(0, upper_roi, middle_roi, height_roi);
cv::Rect roi_rectangle6 = cv::Rect(middle_roi, upper_roi, middle_roi, height_roi);
cv::Rect roi_rectangle7 = cv::Rect(adj_roi[0],adj_roi[1],adj_roi[2],adj_roi[3]);

input.copyTo(output);
rectangle(output, roi_rectangle1, cv::Scalar(100, 0, 0), 5, 8, 0);
/*
rectangle(output, roi_rectangle1, cv::Scalar(100, 0, 0), 5, 8, 0);
putText(output, "1", cv::Point(middle_roi - width_roi, 100), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(100, 0, 0), 9, 8, false);
rectangle(output, roi_rectangle2, cv::Scalar(0, 100, 0), 5, 18, 0);
putText(output, "2", cv::Point(middle_roi, 100), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(0, 100, 0), 9, 8, false);
rectangle(output, roi_rectangle3, cv::Scalar(0, 0, 100), 5, 18, 0);
putText(output, "3", cv::Point(0, 100), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(0, 0, 100), 9, 8, false);
rectangle(output, roi_rectangle4, cv::Scalar(100, 100, 0), 5, 18, 0);
putText(output, "4", cv::Point(FRAME_WIDTH - width_roi, 100), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(100, 100, 0), 9, 8, false);
putText(output, "4", cv::Point(IDS_WIDTH - width_roi, 100), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(100, 100, 0), 9, 8, false);
rectangle(output, roi_rectangle5, cv::Scalar(100, 0, 100), 5, 18, 0);
putText(output, "5", cv::Point(0, 200), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(100, 0, 100), 9, 8, false);
rectangle(output, roi_rectangle6, cv::Scalar(0, 100, 100), 5, 18, 0);
putText(output, "6", cv::Point(middle_roi, 200), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(0, 100, 100), 9, 8, false);

*/
rectangle(output, roi_rectangle7, cv::Scalar(0, 100, 100), 5, 10, 0);
}

//methode returns Mat with value (hsv) from input image
void StopLightDetector::split_bright(cv::Mat &input, cv::Mat &output) {
cv::Mat hsv(FRAME_WIDTH, FRAME_HEIGHT, CV_8UC4);
cv::Mat hsv(IDS_WIDTH, IDS_HEIGHT, CV_8UC4);
std::vector<cv::Mat> hsv_split;
cv::cvtColor(input, hsv, CV_RGB2HSV);
cv::split(hsv, hsv_split);
Expand Down Expand Up @@ -147,9 +148,9 @@ void StopLightDetector::prepare_first_image(cv::Mat &input, cv::Mat &output, int

//methot giving and setting varaibles that there is chane in lights
void StopLightDetector::count_pixels(cv::Mat &input) {
int count = cv::countNonZero(input);
int count = cv::countNonZero(input);
//if (count > 0){
// std::cout << count << std::endl;
// std::cout << count << std::endl;
//}
if (count < max_dif_pixels and count > min_dif_pixels and start_finding == true) {
start_light = true;
Expand Down
10 changes: 8 additions & 2 deletions CIRCUIT/opencv-app/opencv-app/include/stoplights.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ Declaration of StopLightDetector class
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"

#include "ids.h"

#include <iostream>
#include <stdio.h>
#include <stdlib.h>



class StopLightDetector {
private:
int max_dif_pixels = 4000;
int min_dif_pixels = 400;//1000;
int min_dif_pixels = 150;//1000;
//makes roi on input image
void make_roi(cv::Mat &input, cv::Mat &output, int number);
//find bright
Expand All @@ -38,7 +42,9 @@ class StopLightDetector {
//flag not to analize first frame
bool start_finding = false;
//storing roi number
int roi_number = 6;
int roi_number = 7;
//adjusted roi params
int adj_roi[4]={IDS_WIDTH /2,0,IDS_WIDTH /4,IDS_HEIGHT/5};
//prepare first image
void prepare_first_image(cv::Mat &input, cv::Mat &output, int number);
//showing roi rectangles
Expand Down
37 changes: 23 additions & 14 deletions CIRCUIT/opencv-app/opencv-app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ cv :: Mat rect;
int main()
{
// sounds_init();
cvNamedWindow("PREVIEW", 1);
cv::createTrackbar("Enabled?", "PREVIEW", &preview_enabled, 1, NULL);

laneDetector.CreateTrackbars();
INIT_TIMER
INIT_TIMER2
Expand Down Expand Up @@ -131,7 +130,7 @@ int main()


ids.init();

cv::createTrackbar("Enabled?", ids.ids_windowname, &preview_enabled, 1, NULL);
//Read XML file
laneDetector.UndistXML(cameraMatrix, distCoeffs);
#ifdef DEBUG_MODE
Expand All @@ -157,16 +156,22 @@ int main()


// Main loop
// STOPLIGHTS
cv::namedWindow("0.2 Light detection",1);
cv::namedWindow("0.1 ROI",1);
cv::namedWindow("3.1 Yellow Bird Eye", 1);
cv::namedWindow("3.2 White Bird Eye", 1);
cv::createTrackbar("ROI_x", "0.1 ROI", lightDetector.adj_roi, IDS_WIDTH, NULL);
cv::createTrackbar("ROI_y", "0.1 ROI", lightDetector.adj_roi+1, IDS_HEIGHT, NULL);
cv::createTrackbar("ROI_width", "0.1 ROI", lightDetector.adj_roi+2, IDS_WIDTH, NULL);
cv::createTrackbar("ROI_height", "0.1 ROI", lightDetector.adj_roi+3, IDS_HEIGHT, NULL);
//
// cv::namedWindow("3.1 Yellow Bird Eye", 1);
// cv::namedWindow("3.2 White Bird Eye", 1);

cv::createTrackbar("f", "3.1 Yellow Bird Eye", &laneDetector.f_i, 1000, update_trackbar);
cv::createTrackbar("dst", "3.1 Yellow Bird Eye", &laneDetector.dist_i, 1000, update_trackbar);
cv::createTrackbar("dst inv", "3.1 Yellow Bird Eye", &laneDetector.dist_inv_i, 1000, update_trackbar);
cv::createTrackbar("cut y", "3.1 Yellow Bird Eye", &laneDetector.cut_y, 100, update_trackbar);
cv::createTrackbar("alpha", "3.1 Yellow Bird Eye", &laneDetector.alpha_i, 100, update_trackbar);
// cv::createTrackbar("f", "3.1 Yellow Bird Eye", &laneDetector.f_i, 1000, update_trackbar);
// cv::createTrackbar("dst", "3.1 Yellow Bird Eye", &laneDetector.dist_i, 1000, update_trackbar);
// cv::createTrackbar("dst inv", "3.1 Yellow Bird Eye", &laneDetector.dist_inv_i, 1000, update_trackbar);
// cv::createTrackbar("cut y", "3.1 Yellow Bird Eye", &laneDetector.cut_y, 100, update_trackbar);
// cv::createTrackbar("alpha", "3.1 Yellow Bird Eye", &laneDetector.alpha_i, 100, update_trackbar);


// Bird Eye first calculation
Expand Down Expand Up @@ -280,7 +285,7 @@ int main()
shm_lane_points.push_lane_data(yellow_vector, white_vector, laneDetector.cones_vector);

// Push data
//std::cout<<"red"<<red_light_visible<<" green"<<green_light_visible<<"Light"<<lightDetector.start_light<<std::endl;
// std::cout<<light_3_pos<<"red"<<red_light_visible<<" green"<<green_light_visible<<"Light"<<lightDetector.start_light<<std::endl;
shm_usb_to_send.push_scene_data(red_light_visible, green_light_visible);

// Data ready
Expand All @@ -304,7 +309,7 @@ int main()
cv::imshow("0.1 ROI", display);
}
#endif
cv::imshow("0 Frame", ids_image);
cv::imshow(ids.ids_windowname, ids_image);
//cv::imshow("Hist frame", hist_frame);
// cv::imshow("Hsv frame", hsv_frame);
cv::imshow("1.1 Yellow Line", frame_out_yellow);
Expand Down Expand Up @@ -377,13 +382,17 @@ int main()
if(++denom >= IMSHOW_RATE){
denom = 0;
laneDetector.drawPoints_both(white_vector, white_vector_frame,yellow_vector, yellow_vector_frame);
cv::imshow("0 Frame", ids_image);
cv::imshow(ids.ids_windowname, ids_image);

cv::imshow("1.1 Yellow Line", frame_out_yellow);
cv::imshow("4.1 Yellow Vector", yellow_vector_frame);
cv::imshow("1.2 White Line", frame_out_white);
cv::imshow("4.2 White Vector", white_vector_frame);

if (lightDetector.start_light == false){
lightDetector.test_roi(ids_image,display);
cv::imshow("0.2 Light detection", difference);
cv::imshow("0.1 ROI", display);
}
// cv::waitKey(1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions CIRCUIT/trajectory-planning/trajectory-planning/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include <opencv2/opencv.hpp>
#include <vector>

//#define RACE_MODE //without display
#define DEBUG_MODE //data display
#define RACE_MODE //without display
//#define DEBUG_MODE //data display
//#define TEST_MODE //load data from file

extern const int Height;
Expand Down

0 comments on commit edc857b

Please sign in to comment.