forked from edman007/chiton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv_target_rect.cpp
99 lines (86 loc) · 2.63 KB
/
cv_target_rect.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**************************************************************************
*
* This file is part of Chiton.
*
* Chiton 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.
*
* Chiton 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 Chiton. If not, see <https://www.gnu.org/licenses/>.
*
* Copyright 2022 Ed Martin <[email protected]>
*
**************************************************************************
*/
#include "cv_target_rect.hpp"
#ifdef HAVE_OPENCV
#include "util.hpp"
TargetRect::TargetRect(const cv::RotatedRect &rect) : rect(rect) {
count = 0;
valid = true;
frame = NULL;//we never actually allocate for the first frame
}
TargetRect::TargetRect(const TargetRect &old_target, const cv::RotatedRect &new_rect, const AVFrame *cur_frame){
frame = av_frame_alloc();
if (old_target.frame && old_target.rect.size.area() > new_rect.size.area()){
av_frame_ref(frame, old_target.frame);
best_rect = old_target.rect;
} else {
av_frame_ref(frame, cur_frame);
best_rect = new_rect;
}
rect = new_rect;
valid = true;
count = old_target.count + 1;
}
TargetRect::TargetRect(const TargetRect &rhs){
rect = rhs.rect;
best_rect = rhs.best_rect;
count = rhs.count;
valid = rhs.valid;
if (rhs.frame){
//alloc and copy the frame
frame = av_frame_alloc();
av_frame_ref(frame, rhs.frame);
} else {
frame = NULL;
}
LDEBUG("Slow copy of TargetRect");
}
TargetRect::TargetRect(TargetRect &&rhs) noexcept
: rect(std::move(rhs.rect)), best_rect(std::move(rhs.best_rect)) {
count = rhs.count;
valid = rhs.valid;
frame = rhs.frame;
rhs.frame = NULL;
}
TargetRect::~TargetRect(){
av_frame_free(&frame);
}
const cv::RotatedRect& TargetRect::get_rect(void) const{
return rect;
}
bool TargetRect::is_valid(void) const{
return valid;
}
void TargetRect::mark_invalid(void){
valid = false;
}
int TargetRect::get_count(void) const{
return count;
}
const AVFrame *TargetRect::get_best_frame(void) const{
return frame;
}
const cv::RotatedRect& TargetRect::get_best_rect(void) const{
return best_rect;
}
//HAVE_OPENCV
#endif