summaryrefslogtreecommitdiffhomepage
path: root/cv
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-01-16 08:59:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-01-16 08:59:21 +0100
commit6cf93c06abad63721bf66f695587a98377b6178d (patch)
treeaf029c638c9a62d6c34bc95a4dc3060c5d2f8921 /cv
parent88849a1ca4b7c253f7427d361443a496c1b5fe28 (diff)
cv/video-frame, tracker/pt: add hidpi preview support
Diffstat (limited to 'cv')
-rw-r--r--cv/video-widget.cpp26
-rw-r--r--cv/video-widget.hpp6
2 files changed, 29 insertions, 3 deletions
diff --git a/cv/video-widget.cpp b/cv/video-widget.cpp
index 4c9a73e6..f125bf76 100644
--- a/cv/video-widget.cpp
+++ b/cv/video-widget.cpp
@@ -85,8 +85,27 @@ void cv_video_widget::update_image(const QImage& img)
void cv_video_widget::paintEvent(QPaintEvent*)
{
QMutexLocker foo(&mtx);
+
QPainter painter(this);
+
+ double dpr = devicePixelRatioF();
+
+ int W = int(QWidget::width() * dpr);
+ int H = int(QWidget::height() * dpr);
+
painter.drawImage(rect(), texture);
+
+ if (texture.width() != W || texture.height() != H)
+ {
+ texture = QImage(W, H, QImage::Format_ARGB32);
+ texture.setDevicePixelRatio(dpr);
+
+ width = W, height = H;
+
+ _frame = cv::Mat();
+ _frame2 = cv::Mat();
+ _frame3 = cv::Mat();
+ }
}
void cv_video_widget::update_and_repaint()
@@ -102,3 +121,10 @@ void cv_video_widget::update_and_repaint()
repaint();
}
}
+
+void cv_video_widget::get_preview_size(int& w, int& h)
+{
+ QMutexLocker l(&mtx);
+
+ w = width, h = height;
+}
diff --git a/cv/video-widget.hpp b/cv/video-widget.hpp
index 7faddb49..15430e2f 100644
--- a/cv/video-widget.hpp
+++ b/cv/video-widget.hpp
@@ -31,9 +31,8 @@ public:
cv_video_widget(QWidget *parent);
void update_image(const cv::Mat& frame);
void update_image(const QImage& image);
-
- static constexpr inline int width = 320, height = 240;
-protected slots:
+ void get_preview_size(int& w, int& h);
+private slots:
void paintEvent(QPaintEvent*) override;
void update_and_repaint();
private:
@@ -42,5 +41,6 @@ private:
std::vector<unsigned char> vec;
QTimer timer;
cv::Mat _frame, _frame2, _frame3;
+ int width = 320, height = 240;
bool freshp = false;
};