blob: adc129931b8fa774eff5d07237ef2b7ea8e6dc9f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/* Copyright (c) 2021 Michael Welter <michael@welter-4d.de>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*/
#pragma once
#include "model_adapters.h"
#include "cv/video-widget.hpp"
#include <optional>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
namespace neuralnet_tracker_ns
{
/** Makes a maximum size cropping rect with the given aspect.
* @param aspect_w: nominator of the aspect ratio
* @param aspect_h: denom of the aspect ratio
*/
cv::Rect make_crop_rect_for_aspect(const cv::Size &size, int aspect_w, int aspect_h);
/** This class is responsible for drawing the debug/info gizmos
*
* In addition there function to transform the inputs to the size of
* the preview image which can be different from the camera frame.
*/
class Preview
{
public:
void init(const cv_video_widget& widget);
void copy_video_frame(const cv::Mat& frame);
void draw_gizmos(
const std::optional<PoseEstimator::Face> &face,
const std::optional<cv::Rect2f>& last_roi,
const std::optional<cv::Rect2f>& last_localizer_roi,
const cv::Point2f& neckjoint_position);
void overlay_netinput(const cv::Mat& netinput);
void draw_fps(double fps, double last_inference_time);
void copy_to_widget(cv_video_widget& widget);
private:
// Transform from camera image to preview
cv::Rect2f transform(const cv::Rect2f& r) const;
cv::Point2f transform(const cv::Point2f& p) const;
float transform(float s) const;
cv::Mat preview_image_;
cv::Size preview_size_ = { 0, 0 };
float scale_ = 1.f;
cv::Point2f offset_ = { 0.f, 0.f};
};
} // neuralnet_tracker_ns
|