-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselector.cpp
More file actions
30 lines (26 loc) · 757 Bytes
/
selector.cpp
File metadata and controls
30 lines (26 loc) · 757 Bytes
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
#include "selector.h"
#include <cmath>
using namespace cv;
void Selector::mouse_callback(int event, int x, int y, int flags, void* data) {
Selector& self = *((Selector*)data);
switch( event ) {
case CV_EVENT_LBUTTONDOWN:
self.m_selection_valid = false;
self.m_selecting = true;
self.m_selection = Rect(0,0,0,0);
self.m_origin.x = x;
self.m_origin.y = y;
break;
case CV_EVENT_LBUTTONUP:
self.m_selection_valid = true;
self.m_selecting = false;
break;
default:
if( self.m_selecting ) {
self.m_selection.x = MIN(x, self.m_origin.x);
self.m_selection.y = MIN(y, self.m_origin.y);
self.m_selection.width = std::abs(x - self.m_origin.x);
self.m_selection.height = std::abs(y - self.m_origin.y);
}
}
}