Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

processing.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "processing.h"
  2. Processing::Processing(/* args */)
  3. {
  4. }
  5. Processing::~Processing()
  6. {
  7. }
  8. static double angle( Point pt1, Point pt2, Point pt0 )
  9. {
  10. double dx1 = pt1.x - pt0.x;
  11. double dy1 = pt1.y - pt0.y;
  12. double dx2 = pt2.x - pt0.x;
  13. double dy2 = pt2.y - pt0.y;
  14. return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
  15. }
  16. void Processing::processImage(Mat& inputPicture, int thresholdValue, int gaussKernelSize)
  17. {
  18. //Idea here is: Processing module consists of two methods:
  19. // One (this) to do all kinds of stuff to the picture (grayscale conversion, threshold, gauss etc etc)
  20. // And one (the other one) to segment the lines.
  21. // No return value here as the input is passed by reference -> directly modified.
  22. cvtColor(inputPicture, inputPicture, COLOR_BGR2GRAY);
  23. threshold(inputPicture, inputPicture, thresholdValue, 255, THRESH_BINARY);
  24. GaussianBlur(inputPicture, inputPicture, Size(gaussKernelSize, gaussKernelSize), 0);
  25. Canny(inputPicture, inputPicture, 50, 100, 3);
  26. }
  27. std::vector<Vec4i> Processing::calculateLineSegments(const Mat& inputPicture)
  28. {
  29. //See following link
  30. //https://stackoverflow.com/questions/45322630/how-to-detect-lines-in-opencv
  31. vector<Vec4i> lines;
  32. VectorOfLines linesInVectors;
  33. HoughLinesP(inputPicture, lines, 1, CV_PI/360, 150, 0, 250);
  34. //lines = linesInVectors.findMiddleLine(lines);
  35. return lines;
  36. }