25 #ifndef __CAMERASENSORS_H
26 #define __CAMERASENSORS_H
29 #include <selforg/controller_misc.h>
58 assert(img && img->getPixelFormat()==GL_LUMINANCE && img->getDataType()==GL_UNSIGNED_BYTE);
59 num = img->s() * img->t();
67 const unsigned char* pixel = img->data();
68 if(img->s() * img->t() <
num)
return false;
70 for(
int k=0; k<
num; k++){
81 virtual int get(
sensor* sensors,
int length)
const {
137 std::vector<std::string> names;
156 if(
conf.
dims &
X) names.push_back(
"PosH");
157 if(
conf.
dims &
Y) names.push_back(
"PosV");
176 assert(img && img->getPixelFormat()==GL_LUMINANCE &&
177 img->getDataType()==GL_UNSIGNED_BYTE);
197 virtual int get(
sensor* sensors,
int length)
const {
231 for(
int i=kstart; i<k; i++){
242 static bool calcImgCOG(
const osg::Image* img,
double& x,
double& y,
double& size,
246 double centerX = w/2.0;
247 double centerY = h/2.0;
248 if(threshold<1) threshold = 1;
251 for(
int r=0; r< h; r++){
252 const unsigned char* row = img->data(0, r);
253 double pY = ((double)r-centerY);
254 for(
int c=0;
c < w;
c++){
256 x += row[
c] * ((double)
c-centerX);
267 size = double(sum) / (w*h) / 128;
313 std::vector<std::string> names;
314 if(
mconf.
dims &
X) names.push_back(
"MotionH");
315 if(
mconf.
dims &
Y) names.push_back(
"MotionV");
345 if(
last && success && fabs(x -
lastX) < 0.4 && fabs(y -
lastY) < 0.4){
357 for(
int i=0; i<k; i++){
374 if(x>-0.5 && x<0.5)
return 1.0;
375 if(x<= -0.5)
return 2+ 2*x;
virtual ~PositionCameraSensor()
Definition: camerasensors.h:164
This CameraSensor calculates the position of the visible object(s) that is essentially the center of ...
Definition: camerasensors.h:119
void setBaseInfo(const SensorMotorInfo &baseinfo)
Definition: sensormotorinfoable.h:50
double lastX
Definition: camerasensors.h:383
int maxValue
Definition: camerasensors.h:91
Definition: camerasensors.h:281
ValueTypes
additional sensor values.
Definition: camerasensors.h:123
virtual bool processAndFillData(double &x, double &y, double &size, int &k)
process sensor information and fills
Definition: camerasensors.h:206
static PositionCameraSensorConf getDefaultConf()
Definition: camerasensors.h:141
virtual bool sense(const GlobalData &globaldata)
Performs the calculations.
Definition: camerasensors.h:182
Sensor::Dimensions dims
dims dimensions to return the position (X means horizonal, Y vertical)
Definition: camerasensors.h:101
Definition: sensormotorinfo.h:36
double windowfunc(double x)
window function for the interval -1 to 1, with ramps from 0.5 off center
Definition: camerasensors.h:373
Values values
values additional sensor values,
Definition: camerasensors.h:99
static MotionCameraSensorConf getDefaultConf()
Definition: camerasensors.h:319
void setNames(const std::vector< std::string > &names)
set names explicitly (basename is anyway suffixed)
Definition: sensormotorinfoable.h:67
PositionCameraSensorConf conf
Definition: camerasensors.h:274
bool last
whether last image had a valid position
Definition: camerasensors.h:382
double sensor
Definition: types.h:29
int num
Definition: camerasensors.h:275
MotionCameraSensor(const MotionCameraSensorConf &mconf=getDefaultConf())
The camera image should be black and white (e.g.
Definition: camerasensors.h:306
Definition: camerasensors.h:123
Definition: camerasensors.h:123
This CameraSensor implements a direct conversion from pixels to sensors.
Definition: camerasensors.h:37
virtual int getSensorNumber() const
overload this function and return the number of sensor values
Definition: camerasensors.h:76
Definition: position.h:30
sensor * data
Definition: camerasensors.h:276
virtual bool sense(const GlobalData &globaldata)
Performs the calculations.
Definition: camerasensors.h:65
double factorMotion
factor for measured velocity (velocity is in framesize/frame)
Definition: camerasensors.h:285
virtual ~DirectCameraSensor()
Definition: camerasensors.h:51
double factorSizeChange
factor for measured size change (velocity is in framesize/frame)
Definition: camerasensors.h:106
virtual void setNamesIntern(std::vector< std::string > &names)
sets the names of the sensors and starts with the given names (for subclasses)
Definition: camerasensors.h:153
Interface for objects, that can be stored and restored to/from a file stream (binary).
Definition: sensormotorinfo.h:33
virtual int getSensorNumber() const
overload this function and return the number of sensor values
Definition: camerasensors.h:192
virtual ~MotionCameraSensor()
Definition: camerasensors.h:333
int minValue
Definition: camerasensors.h:90
Data structure holding all essential global information.
Definition: globaldata.h:57
Camera * camera
Definition: camerasensor.h:91
double clip(double r, double x)
clipping function for mapP
Definition: controller_misc.cpp:39
bool isInitialized()
Definition: camera.h:145
int avg
averaging time window (1: no averaging)
Definition: camerasensors.h:283
virtual bool sense(const GlobalData &globaldata)
Performs the calculations.
Definition: camerasensors.h:337
double lambda
Definition: camerasensors.h:381
double lastY
Definition: camerasensors.h:384
double border
if >0 then the size and sizechange are zero if position is that far (border) away from the image bord...
Definition: camerasensors.h:110
Definition: camerasensors.h:123
sensor * data
Definition: camerasensors.h:92
Class to connect a Camera as a sensor to a robot.
Definition: camerasensor.h:43
short Values
combination of PositionCameraSensor::ValueTypes
Definition: camerasensors.h:96
double clipsize
clipsize value at which the values are clipped, e.g. [-1.5,1.5]
Definition: camerasensors.h:108
double sizeExponent
exponent for the measured size.
Definition: camerasensors.h:104
MotionCameraSensorConf mconf
Definition: camerasensors.h:380
static bool calcImgCOG(const osg::Image *img, double &x, double &y, double &size, int threshold=1)
calculates the Center of Gravity (normalized to -1 to 1) of an image.
Definition: camerasensors.h:242
DirectCameraSensor(int minValue=-256, int maxValue=256)
the camera image should be black and white (e.g.
Definition: camerasensors.h:46
PositionCameraSensor(PositionCameraSensorConf conf=getDefaultConf())
The camera image should be black and white (e.g.
Definition: camerasensors.h:133
virtual const osg::Image * getImage() const
last image of processing stack
Definition: camera.h:139
Definition: camerasensors.h:123
This CameraSensor calculates the global optical flow of the camera image using the center of gravity ...
Definition: camerasensors.h:297
virtual void intern_init()
overload this function to initialized you data structures.
Definition: camerasensors.h:168
Dimensions
defines which dimensions should be sensed. The meaning is sensor specific.
Definition: sensor.h:46
virtual void intern_init()
overload this function to initialized you data structures.
Definition: camerasensors.h:55
int num
Definition: camerasensors.h:89
bool window
window whether to apply a windowing function to motion data to avoid edge effects ...
Definition: camerasensors.h:287
double oldsize
Definition: camerasensors.h:277
Definition: camerasensors.h:95
int c
Definition: hexapod.cpp:56