Show calculated boxes like tested in spielwiese

This commit is contained in:
Tim Zeuner 2022-12-07 20:06:54 +01:00
parent 633b75176c
commit 44a266629f
3 changed files with 30 additions and 21 deletions

View File

@ -15,8 +15,8 @@ int main(void)
const int apertureSizeCanny = 3;
LFR lfr(videoHeight, videoWidth, thresholdBinary, gaussKernelSize, thresholdCanny1, thresholdCanny2, apertureSizeCanny);
lfr.saveOutputFlag = true;
lfr.outputFileName = "/home/pi/Line-Following-Robot/AutonomousMode/tmp/test.jpg";
lfr.saveOutputFlag = false;
lfr.videoFlag = true;
lfr.startLoop();
//To end the video stream, write any char in the console.
char a;

View File

@ -2,7 +2,7 @@
LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSize, int thresholdCanny1, int thresholdCanny2, int apertureSizeCanny)
: iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler(), roi()
: iAmLooping(false), input(videoHeight, videoWidth), processing(), controlModule(), interpreter(), intersectionHandler()
{
this->iAmLooping = false;
this->thresholdBinary = thresholdBinary;
@ -14,10 +14,6 @@ LFR::LFR(int videoHeight, int videoWidth, int thresholdBinary, int gaussKernelSi
this->videoFlag = false;
this->saveOutputFlag = false;
this->outputFileName = "";
cv::Point roiOrigin(0, videoHeight*(7.5/12.0));
roi = Rect(roiOrigin.x, roiOrigin.y, videoWidth, videoHeight/12);
}
LFR::~LFR()
@ -34,10 +30,14 @@ void LFR::loop()
while(iAmLooping)
{
Mat originalImage = input.readWebcam();
Mat processedImage = originalImage;
Point roiOrigin(0, int(originalImage.rows*(7.5/12.0)));
Rect roi(roiOrigin.x, roiOrigin.y, originalImage.cols, originalImage.rows/12);
Mat processedImage = originalImage(roi);
processing.processImage(processedImage, this->thresholdBinary, this->gaussKernelSize, this->thresholdCanny1, thresholdCanny2, this->apertureSizeCanny);
FrameData data = processing.calculateLineSegments(processedImage, this->roi);
this->provideOutput(processedImage);
FrameData data = processing.calculateLineSegments(processedImage, roi);
this->provideOutput(originalImage, data, roi);
}
if(this->videoFlag) {destroyWindow("Display window");}
input.freeWebcam();
@ -56,12 +56,22 @@ void LFR::endLoop()
return;
}
void LFR::provideOutput(const Mat& image)
void LFR::provideOutput(Mat image, const FrameData& frameData, const Rect& roi)
{
for(int i = 0; i < frameData.contours.size(); i++)
{
drawContours(image, frameData.contours, i, Scalar(0,255,255), 1, 8, noArray(), 0, Point(roi.x, roi.y));
rectangle(image, frameData.boundingBoxes[i], Scalar(0,255,0));
Rect center(Point(frameData.middlePoints[i].x-2, frameData.middlePoints[i].y-2), Point(frameData.middlePoints[i].x+2, frameData.middlePoints[i].y+2));
rectangle(image, center, Scalar(0,0,255));
Rect leftRect(Point(frameData.leftEdges[i].x-2, frameData.leftEdges[i].y-2), Point(frameData.leftEdges[i].x+2, frameData.leftEdges[i].y+2));
rectangle(image, leftRect, Scalar(0,0,255));
}
if(this->videoFlag)
{
imshow("Display window", image);
char c = (char)waitKey(1);
char c = (char)waitKey(25);
}
if (this->saveOutputFlag && !(this->outputFileName.empty()))
{

View File

@ -30,9 +30,8 @@ class LFR
int thresholdCanny1;
int thresholdCanny2;
int apertureSizeCanny;
cv::Rect roi;
void provideOutput(const Mat& image);
void provideOutput(Mat image,const FrameData& frameData, const Rect& roi);
public: