iVS3D v2.0.0
Loading...
Searching...
No Matches
roi.h
1#pragma once
2
3#include <QtGlobal>
4#include <QString>
5#include <QRectF>
6#include <QPoint>
7#include <opencv2/core.hpp>
8#include <opencv2/imgproc.hpp>
9
10#include "resolution.h"
11
21class ROI{
22private:
23 QRectF m_roi;
24
25public:
29 ROI() : m_roi(0.0,0.0,1.0,1.0) {}
30
35 ROI(const QRectF &roi) : m_roi(roi) {}
36
41 ROI(const cv::Rect2f &roi) : m_roi(roi.x,roi.y,roi.width,roi.height) {}
42
48 ROI(const QRect &roi, const Resolution &resolution);
54 ROI(const cv::Rect &roi, const Resolution &resolution);
55
60 bool isDefault() const { return m_roi == QRectF(0.0,0.0,1.0,1.0); }
61
62 cv::Rect2f toCvRect() const { return cv::Rect2f(m_roi.left(), m_roi.top(), m_roi.width(), m_roi.height()); }
63 QRectF toQRectF() const { return QRectF(m_roi.left(), m_roi.top(), m_roi.width(), m_roi.height()); }
64
70 QRect cropAsQRect(const Resolution& resolution) const { return QRect(m_roi.left() * resolution.getWidth(), m_roi.top() * resolution.getHeight(), m_roi.width() * resolution.getWidth(), m_roi.height() * resolution.getHeight()); }
71
77 cv::Rect cropAsCvRect(const Resolution& resolution) const { return cv::Rect(m_roi.left() * resolution.getWidth(), m_roi.top() * resolution.getHeight(), m_roi.width() * resolution.getWidth(), m_roi.height() * resolution.getHeight()); }
78
84 void crop(const cv::Mat &src, cv::Mat &dest) const { dest = src(cropAsCvRect(Resolution(src))); }
85
90 void crop(cv::Mat &img) const { crop(img,img); }
91};
The ROI class manages a region of interest represented as a rectangle in the [0,1]x[0,...
Definition roi.h:21
ROI()
Default constructor initializing ROI to the full image (normalized [0,1] scale).
Definition roi.h:29
void crop(cv::Mat &img) const
Crops an image in-place.
Definition roi.h:90
ROI(const QRectF &roi)
Constructs an ROI object from a QRectF.
Definition roi.h:35
bool isDefault() const
Checks if the ROI matches the default ROI which is the entire image.
Definition roi.h:60
cv::Rect cropAsCvRect(const Resolution &resolution) const
Converts to an OpenCV rect, scaled to the given resolution.
Definition roi.h:77
ROI(const cv::Rect2f &roi)
Constructs an ROI object from an OpenCV Rect2f.
Definition roi.h:41
QRect cropAsQRect(const Resolution &resolution) const
Converts to a QRect, scaled to the given resolution.
Definition roi.h:70
void crop(const cv::Mat &src, cv::Mat &dest) const
Crops an image using the ROI and stores the result in dest.
Definition roi.h:84
The Resolution class encapsulates an image resolution (width and height). It provides functionality f...
Definition resolution.h:17