Skip to content
Snippets Groups Projects
Commit 1a5f2e58 authored by l.dressen's avatar l.dressen
Browse files

Merge remote-tracking branch 'origin/master' into...

Merge remote-tracking branch 'origin/master' into 470-should-throw-error-on-reading-ill-formed-pet-file-e-g-wrong-decimal-separator

# Conflicts:
#	src/util/helper.cpp
parents 38565b1a f2c1b863
No related branches found
No related tags found
1 merge request!362Should throw error on reading ill-formed .pet-file (e.g. wrong decimal separator)
Pipeline #149242 passed
...@@ -76,7 +76,10 @@ bool BackgroundFilter::isForeground(int coloumn, int row) ...@@ -76,7 +76,10 @@ bool BackgroundFilter::isForeground(int coloumn, int row)
} }
} }
/// zuruecksetzen, wenn zB helligkeit veraendert wird oder schaerfe /**
* Reset the filter.
* This will set the changed()-value to true.
*/
void BackgroundFilter::reset() void BackgroundFilter::reset()
{ {
if(!mForeground.empty()) if(!mForeground.empty())
......
This diff is collapsed.
...@@ -310,6 +310,17 @@ public: ...@@ -310,6 +310,17 @@ public:
const QString &getLastTrackerExport() const; const QString &getLastTrackerExport() const;
void setLastTrackerExport(const QString &newLastTrackerExport); void setLastTrackerExport(const QString &newLastTrackerExport);
void getFilteredImage(
bool imageChanged,
bool brightContrastFilterChanged,
bool swapFilterChanged,
bool borderFilterChanged,
bool calibFilterChanged);
void resetExistingPoints();
void performTracking();
void performRecognition();
private slots: private slots:
void openAutosaveSettings(); void openAutosaveSettings();
......
...@@ -1349,14 +1349,13 @@ QList<TrackPoint> Recognizer::getMarkerPos( ...@@ -1349,14 +1349,13 @@ QList<TrackPoint> Recognizer::getMarkerPos(
bool ignoreWithoutMarker = controlWidget->isMarkerIgnoreWithoutChecked(); bool ignoreWithoutMarker = controlWidget->isMarkerIgnoreWithoutChecked();
bool autoWB = controlWidget->isRecoAutoWBChecked(); bool autoWB = controlWidget->isRecoAutoWBChecked();
cv::Mat tImg; auto rect = qRectToCvRect(
cv::Rect rect;
tImg = getRoi(
img,
roi, roi,
rect, img,
!((mRecoMethod == RecognitionMethod::Color) || (mRecoMethod == RecognitionMethod::MultiColor) || (mRecoMethod != RecognitionMethod::Color) && (mRecoMethod != RecognitionMethod::MultiColor) &&
(mRecoMethod == RecognitionMethod::Code))); (mRecoMethod != RecognitionMethod::Code));
auto tImg = img(rect);
if(tImg.empty()) if(tImg.empty())
{ {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "logger.h" #include "logger.h"
#include <algorithm>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
QString proFileName; ///< Path to the project (.pet) file; used for saving relative paths via getFileList and QString proFileName; ///< Path to the project (.pet) file; used for saving relative paths via getFileList and
...@@ -120,35 +121,23 @@ void copyToQImage(QImage &qImg, cv::Mat &img) // war static functin in animatiol ...@@ -120,35 +121,23 @@ void copyToQImage(QImage &qImg, cv::Mat &img) // war static functin in animatiol
/** /**
@brief get roi: copies roi to rect by setting values of roi to correct values inside rect * Create an opencv Rect from a given QRect
* This method creates an opencv Rect by respecting the given QRect dimensions and a given image matrix (for its maximum
no copy of data, only new header which allows to access rect * size) i. e. if an x or y value is less than zero, the whole rect will be moved such that the value is equal to zero.
rect wird veraendert, roi nicht * Correspondingly, if the width or height is greater than the given image, the rectangle will be trimmed to the maximum
* size.
@param[in] img Mat &img *
@param[in] const QRect &roi *
@param[in] Rect &rect * @param roi QRect of which a cv::Rect should be made
@return img(rect) * @param img the image for cutting width and height
*/ * @param evenPixelNumber if {@code true}, the rect will be cut to the next lesser even width and height.
cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNumber) * @return a cv::Rect matching the position of the QRect by respecting the given image and evenPixelNumber parameter.
*/
cv::Rect qRectToCvRect(const QRect &roi, const cv::Mat &img, bool evenPixelNumber)
{ {
rect.x = roi.x(); cv::Rect rect(roi.x(), roi.y(), roi.width(), roi.height());
rect.y = roi.y();
rect.width = roi.width(); // trim to image dimensions
rect.height = roi.height();
if(evenPixelNumber)
{
// roi.width and roi.height must be even
if(rect.width % 2 > 0)
{
--rect.width;
}
if(rect.height % 2 > 0)
{
--rect.height;
}
}
// roi.width and roi.height must be >=0
if(rect.x < 0) if(rect.x < 0)
{ {
rect.width += rect.x; rect.width += rect.x;
...@@ -161,7 +150,7 @@ cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNum ...@@ -161,7 +150,7 @@ cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNum
} }
if(rect.x + rect.width > img.cols) if(rect.x + rect.width > img.cols)
{ {
rect.width -= (rect.x + rect.width - img.cols); rect.width = img.cols - rect.x;
} }
if(rect.y < 0) if(rect.y < 0)
{ {
...@@ -175,11 +164,21 @@ cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNum ...@@ -175,11 +164,21 @@ cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNum
} }
if(rect.y + rect.height > img.rows) if(rect.y + rect.height > img.rows)
{ {
rect.height -= (rect.y + rect.height - img.rows); rect.height = img.rows - rect.y;
} }
return img(rect); rect.height = std::max(0, rect.height);
rect.width = std::max(0, rect.width);
if(evenPixelNumber)
{
rect.width -= rect.width % 2;
rect.height -= rect.height % 2;
}
return rect;
} }
#include <iostream> #include <iostream>
#include <vector> #include <vector>
/** /**
......
...@@ -20,7 +20,9 @@ ...@@ -20,7 +20,9 @@
#define HELPER_H #define HELPER_H
#include <QFileInfo> #include <QFileInfo>
#include <QRect>
#include <QString> #include <QString>
#include <opencv2/core/types.hpp>
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
extern const QString commandLineOptionsString; extern const QString commandLineOptionsString;
...@@ -61,7 +63,8 @@ inline constexpr double PI = 3.141592654; ...@@ -61,7 +63,8 @@ inline constexpr double PI = 3.141592654;
#include <QImage> #include <QImage>
void copyToQImage(QImage &qImg, cv::Mat &img); void copyToQImage(QImage &qImg, cv::Mat &img);
cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNumber = true); cv::Rect qRectToCvRect(const QRect &roi, const cv::Mat &img, bool evenPixelNumber = true);
cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNumber = true);
inline double getMedianOf3(double a, double b, double c) inline double getMedianOf3(double a, double b, double c)
{ {
......
...@@ -14,4 +14,5 @@ add_subdirectory(general) ...@@ -14,4 +14,5 @@ add_subdirectory(general)
add_subdirectory(IO) add_subdirectory(IO)
add_subdirectory(recognition) add_subdirectory(recognition)
add_subdirectory(tracking) add_subdirectory(tracking)
add_subdirectory(ui) add_subdirectory(ui)
\ No newline at end of file add_subdirectory(util)
\ No newline at end of file
target_sources(petrack_tests PRIVATE
tst_helper.cpp
)
\ No newline at end of file
/*
* PeTrack - Software for tracking pedestrians movement in videos
* Copyright (C) 2024 Forschungszentrum Jülich GmbH, IAS-7
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "helper.h"
#include "logger.h"
#include <catch2/catch.hpp>
TEST_CASE("Test qRectToCvRect", "[helper]")
{
// create image mock. The datatype has no effect, so take a small one
auto image = cv::Mat(1080, 1920, CV_8U);
// variables for reuse
cv::Rect rect;
QRect roi;
SECTION("ROI somewhere inside image")
{
GIVEN("uneven width ROI")
{
roi = QRect(10, 10, 201, 201);
rect = qRectToCvRect(roi, image);
THEN("Rect is shortened to even length")
{
REQUIRE(roi.x() == rect.x);
REQUIRE(roi.y() == rect.y);
REQUIRE(roi.width() - 1 == rect.width);
REQUIRE(roi.height() - 1 == rect.height);
}
}
GIVEN("uneven width ROI and explicit evenPixel=false")
{
rect = qRectToCvRect(roi, image, false);
THEN("Rect is equal to roi")
{
REQUIRE(roi.x() == rect.x);
REQUIRE(roi.y() == rect.y);
REQUIRE(roi.width() == rect.width);
REQUIRE(roi.height() == rect.height);
}
}
GIVEN("even width ROI")
{
roi = QRect(20, 20, 400, 400);
rect = qRectToCvRect(roi, image);
THEN("Rect is equal to roi")
{
REQUIRE(roi.x() == rect.x);
REQUIRE(roi.y() == rect.y);
REQUIRE(roi.width() == rect.width);
REQUIRE(roi.height() == rect.height);
}
rect = qRectToCvRect(roi, image, false);
THEN("Rect is equal to roi")
{
REQUIRE(roi.x() == rect.x);
REQUIRE(roi.y() == rect.y);
REQUIRE(roi.width() == rect.width);
REQUIRE(roi.height() == rect.height);
}
}
}
SECTION("ROI partly outside image")
{
GIVEN("roi top left outside")
{
roi = QRect(-10, -10, 200, 200);
rect = qRectToCvRect(roi, image);
THEN("rect is trimmed to be inside")
{
REQUIRE(0 == rect.x);
REQUIRE(0 == rect.y);
REQUIRE(190 == rect.width);
REQUIRE(190 == rect.height);
}
}
GIVEN("ROI bottom right outside")
{
roi = QRect(1900, 1050, 100, 100);
rect = qRectToCvRect(roi, image);
THEN("ROI is trimmed to image")
{
REQUIRE(roi.x() == rect.x);
REQUIRE(roi.y() == rect.y);
REQUIRE(20 == rect.width);
REQUIRE(30 == rect.height);
}
}
GIVEN("ROI is outside left and right")
{
roi = QRect(-10, 10, 2000, 100);
rect = qRectToCvRect(roi, image);
THEN("ROI is trimmed left and right")
{
REQUIRE(0 == rect.x);
REQUIRE(roi.y() == rect.y);
REQUIRE(1920 == rect.width);
REQUIRE(roi.height() == rect.height);
}
}
GIVEN("ROI is outside top and bottom")
{
roi = QRect(10, -10, 100, 2000);
rect = qRectToCvRect(roi, image);
THEN("ROI is trimmed top and bottom")
{
REQUIRE(roi.x() == rect.x);
REQUIRE(0 == rect.y);
REQUIRE(roi.width() == rect.width);
REQUIRE(1080 == rect.height);
}
}
GIVEN("ROI is completely bigger than image")
{
roi = QRect(-10, -10, 2000, 2000);
rect = qRectToCvRect(roi, image);
THEN("ROI is equal to image size")
{
REQUIRE(0 == rect.x);
REQUIRE(0 == rect.y);
REQUIRE(1920 == rect.width);
REQUIRE(1080 == rect.height);
}
}
SECTION("Trimming should not break evenPixel size")
{
GIVEN("ROI trimming would break evenness")
{
roi = QRect(-11, 10, 50, 10);
rect = qRectToCvRect(roi, image);
// with plain trimming the rect would be (0, 10, 39, 10)
// with even sides, width should be 38
THEN("Trimmed Rect has still even dimension")
{
REQUIRE(0 == rect.x);
REQUIRE(38 == rect.width);
}
}
}
}
SECTION("ROI completely outside image")
{
roi = QRect(-20, -20, 10, 10);
rect = qRectToCvRect(roi, image);
REQUIRE(0 == rect.x);
REQUIRE(0 == rect.y);
REQUIRE(0 == rect.width);
REQUIRE(0 == rect.height);
}
} // END TESTCASE qRectToCvRect
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment