Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
pipeline_thread.cpp
1
2
/***************************************************************************
3
* pipeline_thread.cpp - SwissRanger Save Pipeline Thread
4
*
5
* Created: Fri Jan 22 10:50:13 2010
6
* Copyright 2005-2010 Tim Niemueller [www.niemueller.de]
7
*
8
****************************************************************************/
9
10
/* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Library General Public License for more details.
19
*
20
* Read the full text in the LICENSE.GPL file in the doc directory.
21
*/
22
23
#include "pipeline_thread.h"
24
25
#include <fvcams/camera.h>
26
27
#include <sys/time.h>
28
#include <stdlib.h>
29
#include <cstdio>
30
31
using namespace
fawkes;
32
33
/** @class FvSrSavePipelineThread "pipeline_thread.h"
34
* SrSave vision image processing pipeline.
35
* This thread implements an image processing pipeline that uses a colormodel and
36
* classifier to determine regions of interest (ROI) which contain a significant
37
* amount with "pixels of ball color". The best ROI is then filtered for edge detection.
38
* On the edges a circle shape detection is carried out to confirm the result and to
39
* get the required data to calculate the relative and global position of the ball.
40
*
41
* @author Tim Niemueller
42
*/
43
44
45
/** Constructor. */
46
FvSrSavePipelineThread::FvSrSavePipelineThread
()
47
:
Thread
(
"FvSrSavePipelineThread"
,
Thread
::OPMODE_WAITFORWAKEUP),
48
VisionAspect
(
VisionAspect
::CYCLIC)
49
{
50
}
51
52
53
/** Destructor. */
54
FvSrSavePipelineThread::~FvSrSavePipelineThread
()
55
{
56
}
57
58
59
/** Initialize the pipeline thread.
60
* Camera is requested, config parameters are obtained from the config db, and
61
* other miscellaneous init stuff is done here.
62
*/
63
void
64
FvSrSavePipelineThread::init
()
65
{
66
try
{
67
__cam =
vision_master
->
register_for_raw_camera
(
"swissranger:any:mode=CARTESIAN_FLOAT"
,
this
);
68
}
catch
(
Exception
& e) {
69
e.
append
(
"FvSrSavePipelineThread::init() failed since no camera is specified"
);
70
throw
;
71
}
72
}
73
74
75
/** Thread finalization. */
76
void
77
FvSrSavePipelineThread::finalize
()
78
{
79
vision_master
->
unregister_thread
(
this
);
80
}
81
82
/** A new image is retrieved from the camera and the classifier looks for a ball
83
* in the image */
84
void
85
FvSrSavePipelineThread::loop
()
86
{
87
__cam->
capture
();
88
89
const
unsigned
int
width = __cam->
pixel_width
();
90
const
unsigned
int
height = __cam->
pixel_height
();
91
92
float
*fbuf = (
float
*)__cam->
buffer
();
93
float
*x = fbuf;
94
float
*y = x + width * height;
95
float
*z = y + width * height;
96
97
char
*filename;
98
if
(asprintf(&filename,
"swissranger-%05u.pts"
, __frame_i++) != -1) {
99
FILE *f = fopen(filename,
"w"
);
100
101
for
(
unsigned
int
h = 0; h < height; ++h) {
102
for
(
unsigned
int
w = 0; w < width; ++w) {
103
fprintf(f,
"%f %f %f 128 128 128\n"
,
104
*x++ * 2000., *y++ * 2000., *z++ * 2000.);
105
}
106
}
107
108
fclose(f);
109
free(filename);
110
}
else
{
111
logger
->
log_warn
(
name
(),
"Failed to allocate filename"
);
112
}
113
114
115
__cam->
dispose_buffer
();
116
}
117
src
plugins
perception
srsave
pipeline_thread.cpp
Generated by
1.8.3.1