-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolortracking.cpp
56 lines (41 loc) · 1.33 KB
/
colortracking.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
#include "colortracking.h"
std::vector< Object >& ColorTracking::getObjects() {
Object red( "red" ), black( "black" ), green( "green" );
addColorRange( red.getHSVmin(), red.getHSVmax() );
addColorRange( black.getHSVmin(), red.getHSVmax() );
addColorRange( green.getHSVmin(), red.getHSVmax() );
for( auto r: color_ranges ) {
auto circles = process( r );
for( auto c : circles ) {
Object o;
o.setXPos( c[ 0 ] );
o.setYPos( c[ 1 ] );
o.setRadius( c[ 2 ] );
objects.push_back( o );
}
}
return objects;
}
void ColorTracking::drawObjects() {
for( auto o : objects ) {
circle( image, Point( o.getXPos(), o.getYPos() ), o.getRadius(), Scalar( 200, 200, 0 ) );
}
}
std::vector< cv::Vec3f > ColorTracking::process( ColorRange range ) {
std::vector< cv::Vec3f > circles;
if( image.empty() )
return circles;
// reduce noise by blurring
medianBlur( image, image, 3 );
convertBGRtoHSV();
cv::GaussianBlur( hsv, hsv, cv::Size( 9, 9 ), 2, 2 );
// tresh image, keep on image in color range
Mat in_range;
inRange( hsv, range.first, range.second, in_range );
temp_imgs.push_back( in_range );
createDebugWindow( in_range );
// blur again to void false positives
// Use the Hough transform to detect circles in the image
//cv::HoughCircles( in_range, circles, CV_HOUGH_GRADIENT, 1, 1, 150, 50, 0, 0 );
return circles;
}