|
|
|
|
|
|
|
|
#include <opencv2/opencv.hpp> |
|
|
#include <opencv2/opencv.hpp> |
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
#include <iostream> |
|
|
|
|
|
#include <direct.h> |
|
|
|
|
|
|
|
|
#include <input.h> |
|
|
#include <input.h> |
|
|
#include <processing.h> |
|
|
#include <processing.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void in_depth_processing_chain(int thresholdBinary, int videoHeight, int videoWidth, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny) |
|
|
void in_depth_processing_chain(int thresholdBinary, int videoHeight, int videoWidth, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny) |
|
|
{ |
|
|
{ |
|
|
std::string outputFolder = "C:\\Users\\User\\Desktop\\temp"; |
|
|
|
|
|
Input input(videoHeight, videoWidth); |
|
|
Input input(videoHeight, videoWidth); |
|
|
|
|
|
|
|
|
Mat image = input.readFile("C:\\Users\\User\\Desktop\\Studium\\02_Master_MSY\\2. Semester Winter 22 23\\Projekt\\Line-Following-Robot\\Test_data"); |
|
|
|
|
|
imwrite(outputFolder + "\\01_input.jpg", image); |
|
|
|
|
|
cvtColor(image, image, COLOR_BGR2GRAY); |
|
|
|
|
|
imwrite(outputFolder + "\\02_color_convert.jpg", image); |
|
|
|
|
|
GaussianBlur(image, image, Size(gaussKernelSize, gaussKernelSize), 0); |
|
|
|
|
|
imwrite(outputFolder + "\\03_gauss.jpg", image); |
|
|
|
|
|
threshold(image, image, thresholdBinary, 255, THRESH_BINARY); |
|
|
|
|
|
imwrite(outputFolder + "\\04_threshold.jpg", image); |
|
|
|
|
|
Canny(image, image, thresholdCanny1, thresholdCanny2, apertureSizeCanny); |
|
|
|
|
|
imwrite(outputFolder + "\\05_canny.jpg", image); |
|
|
|
|
|
|
|
|
std::string outputFolder = "C:\\Users\\User\\Desktop\\temp"; |
|
|
|
|
|
std::string inputFolder = "C:\\Users\\User\\Desktop\\Studium\\02_Master_MSY\\2. Semester Winter 22 23\\Projekt\\Line-Following-Robot\\AutonomousMode\\Test_data"; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> filenames; |
|
|
|
|
|
cv::glob(inputFolder, filenames); |
|
|
|
|
|
|
|
|
|
|
|
//filenames.begin(), filenames.end() |
|
|
|
|
|
int i = 0; |
|
|
|
|
|
for(std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); it++) |
|
|
|
|
|
{ |
|
|
|
|
|
std::string current_output = outputFolder + "\\" + to_string(i); |
|
|
|
|
|
std::cout << current_output << std::endl; |
|
|
|
|
|
const char* current_output_char = current_output.c_str(); |
|
|
|
|
|
_mkdir(current_output_char); |
|
|
|
|
|
|
|
|
|
|
|
std::string inputFile = inputFolder + "\\image" + to_string(i+1) + ".jpeg"; |
|
|
|
|
|
Mat original_image = input.readFile(inputFile); |
|
|
|
|
|
imwrite(current_output + "\\00_input.jpg", original_image); |
|
|
|
|
|
|
|
|
|
|
|
Rect roi = Rect(0, original_image.rows*(7.5/12.0), original_image.cols, original_image.rows/12); |
|
|
|
|
|
|
|
|
|
|
|
Mat image = original_image(roi); |
|
|
|
|
|
|
|
|
|
|
|
imwrite(current_output + "\\01_roi.jpg", image); |
|
|
|
|
|
cvtColor(image, image, COLOR_BGR2GRAY); |
|
|
|
|
|
imwrite(current_output + "\\02_color_convert.jpg", image); |
|
|
|
|
|
GaussianBlur(image, image, Size(gaussKernelSize, gaussKernelSize), 0); |
|
|
|
|
|
imwrite(current_output + "\\03_gauss.jpg", image); |
|
|
|
|
|
threshold(image, image, thresholdBinary, 255, THRESH_BINARY); |
|
|
|
|
|
imwrite(current_output + "\\04_threshold.jpg", image); |
|
|
|
|
|
|
|
|
|
|
|
// Opening (reduces noise) |
|
|
|
|
|
Mat kernel(5,5, CV_8UC1,1); |
|
|
|
|
|
morphologyEx(image, image, 2, kernel); |
|
|
|
|
|
imwrite(current_output + "\\05_opening.jpg", image); |
|
|
|
|
|
|
|
|
|
|
|
//Canny(image, image, thresholdCanny1, thresholdCanny2, apertureSizeCanny); |
|
|
|
|
|
//imwrite(outputFolder + "\\06_canny.jpg", image); |
|
|
|
|
|
|
|
|
|
|
|
vector<vector<Point> > contours; |
|
|
|
|
|
vector<Vec4i> hierarchy; |
|
|
|
|
|
|
|
|
|
|
|
findContours(image,contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE); |
|
|
|
|
|
|
|
|
|
|
|
for( int i = 0; i< contours.size(); i++ ) // iterate through each contour. |
|
|
|
|
|
{ |
|
|
|
|
|
double a = contourArea( contours[i],false); // Find the area of contour |
|
|
|
|
|
if(a > 3500) |
|
|
|
|
|
{ |
|
|
|
|
|
drawContours(original_image, contours, i, Scalar(0,255,255), 1, 8, hierarchy, 0, Point(0,original_image.rows*(7.5/12.0))); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
imwrite(current_output + "\\06_contours.jpg", original_image); |
|
|
|
|
|
i++; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|