Browse Source

Resolve mixing of std::string and cv::String, more work on new img processing approach.

pull/1/head
Tim Zeuner 2 years ago
parent
commit
f208cda1ed
2 changed files with 38 additions and 11 deletions
  1. 2
    2
      AutonomousMode/Input/input.cpp
  2. 36
    9
      AutonomousMode/Spielwiese/spielwiese.cpp

+ 2
- 2
AutonomousMode/Input/input.cpp View File

{ {
std::srand(std::time(0)); std::srand(std::time(0));
// Read all .jpg files from the specified folder // Read all .jpg files from the specified folder
std::string folder = filePath;
std::vector<std::string> filenames;
cv::String folder = filePath;
std::vector<cv::String> filenames;
cv::glob(folder, filenames); cv::glob(folder, filenames);


// Random shuffle // Random shuffle

+ 36
- 9
AutonomousMode/Spielwiese/spielwiese.cpp View File

#include <opencv2/core/utils/logger.hpp>
//#include <opencv2/core/utils/logger.hpp>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>


#include <iostream> #include <iostream>
{ {
Input input(videoHeight, videoWidth); Input input(videoHeight, videoWidth);


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";
cv::String outputFolder = "C:\\Users\\tim-z\\Desktop\\temp";
cv::String inputFolder = "C:\\Users\\tim-z\\Desktop\\Studium\\02_Master MSY\\2. Semester Winter 2022 2023\\Projekt\\Repo\\Line-Following-Robot\\AutonomousMode\\Test_data";


std::vector<std::string> filenames;
std::vector<cv::String> filenames;
cv::glob(inputFolder, filenames); cv::glob(inputFolder, filenames);


//filenames.begin(), filenames.end() //filenames.begin(), filenames.end()
int i = 0; int i = 0;
for(std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); it++)
for(std::vector<cv::String>::iterator it = filenames.begin(); it != filenames.end(); it++)
{ {
std::string current_output = outputFolder + "\\" + to_string(i); std::string current_output = outputFolder + "\\" + to_string(i);
std::cout << current_output << std::endl; std::cout << current_output << std::endl;
Mat original_image = input.readFile(inputFile); Mat original_image = input.readFile(inputFile);
imwrite(current_output + "\\00_input.jpg", original_image); 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);
Point roiOrigin(0, original_image.rows*(7.5/12.0));
Rect roi = Rect(roiOrigin.x, roiOrigin.y, original_image.cols, original_image.rows/12);


Mat image = original_image(roi); Mat image = original_image(roi);




vector<vector<Point> > contours; vector<vector<Point> > contours;
vector<Vec4i> hierarchy; vector<Vec4i> hierarchy;
vector<Rect> vectorOfRects;
vector<Point> vectorOfLeftEdges;


findContours(image,contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE); findContours(image,contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
int amountOfValidRects = 0;
for( int i = 0; i< contours.size(); i++ ) // iterate through each contour. for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
{ {
double a = contourArea( contours[i],false); // Find the area of contour double a = contourArea( contours[i],false); // Find the area of contour
if(a > 3500) 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)));
drawContours(original_image, contours, i, Scalar(0,255,255), 1, 8, hierarchy, 0, roiOrigin);
Rect currentBoundingRect = boundingRect(contours[i]);
//Handle roi offset:
currentBoundingRect.x += roiOrigin.x;
currentBoundingRect.y += roiOrigin.y;
vectorOfRects.push_back(currentBoundingRect);

rectangle(original_image, currentBoundingRect, Scalar(0,255,0));
// get mid-point of rect
Point midRect = Point(currentBoundingRect.x+currentBoundingRect.width/2, currentBoundingRect.y+currentBoundingRect.height/2);

// Draw middle as small rect instead of circle because for whatever reasons drawing a circle doesnt work.
Rect testRect(Point(midRect.x-2, midRect.y-2), Point(midRect.x+2, midRect.y+2));
rectangle(original_image, testRect, Scalar(0,0,255));
// get the left edge of rect
// used as offset as raspicam is not
// mounted on mid of regbot
Point leftEdge(currentBoundingRect.x, currentBoundingRect.y+currentBoundingRect.height/2);
vectorOfLeftEdges.push_back(leftEdge);

testRect = Rect(Point(leftEdge.x-2, leftEdge.y-2), Point(leftEdge.x+2, leftEdge.y+2));
rectangle(original_image, testRect, Scalar(0,0,255));
amountOfValidRects++;
} }
} }
imwrite(current_output + "\\06_contours.jpg", original_image); imwrite(current_output + "\\06_contours.jpg", original_image);
int main(void) int main(void)
{ {
//Disable opencv logging messages //Disable opencv logging messages
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);
//cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_WARNING);


const int thresholdBinary = 140; const int thresholdBinary = 140;
const int videoHeight = 720; const int videoHeight = 720;

Loading…
Cancel
Save