p_blobfinder.cc
Go to the documentation of this file.
1 /*
2  * Player - One Hell of a Robot Server
3  * Copyright (C) 2004, 2005 Richard Vaughan
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 /*
23  * Desc: A plugin driver for Player that gives access to Stage devices.
24  * Author: Richard Vaughan
25  * Date: 10 December 2004
26  * CVS: $Id$
27  */
28 
29 // DOCUMENTATION
30 
36 // CODE
37 
38 #include "p_driver.h"
39 using namespace Stg;
40 
42  StgDriver* driver,
43  ConfigFile* cf,
44  int section )
45  : InterfaceModel( addr, driver, cf, section, "blobfinder" )
46 {
47  // nothing to do for now
48 }
49 
50 
52 {
53  player_blobfinder_data_t bfd;
54  bzero( &bfd, sizeof(bfd) );
55 
56  ModelBlobfinder* blobmod = (ModelBlobfinder*)this->mod;
57 
58  uint32_t bcount = 0;
59  const ModelBlobfinder::Blob* blobs = blobmod->GetBlobs( &bcount );
60 
61  if ( bcount > 0 )
62  {
63  // and set the image width * height
64  bfd.width = blobmod->scan_width;
65  bfd.height = blobmod->scan_height;
66  bfd.blobs_count = bcount;
67 
68  bfd.blobs = new player_blobfinder_blob_t[ bcount ];
69 
70  // now run through the blobs, packing them into the player buffer
71  // counting the number of blobs in each channel and making entries
72  // in the acts header
73  unsigned int b;
74  for( b=0; b<bcount; b++ )
75  {
76  // useful debug - leave in
77  /*
78  cout << "blob "
79  << " left: " << blobs[b].left
80  << " right: " << blobs[b].right
81  << " top: " << blobs[b].top
82  << " bottom: " << blobs[b].bottom
83  << " color: " << hex << blobs[b].color << dec
84  << endl;
85  */
86 
87  int dx = blobs[b].right - blobs[b].left;
88  int dy = blobs[b].top - blobs[b].bottom;
89 
90  bfd.blobs[b].x = blobs[b].left + dx/2;
91  bfd.blobs[b].y = blobs[b].bottom + dy/2;
92 
93  bfd.blobs[b].left = blobs[b].left;
94  bfd.blobs[b].right = blobs[b].right;
95  bfd.blobs[b].top = blobs[b].top;
96  bfd.blobs[b].bottom = blobs[b].bottom;
97 
98  bfd.blobs[b].color =
99  ((uint8_t)(blobs[b].color.r*255.0) << 16) +
100  ((uint8_t)(blobs[b].color.g*255.0) << 8) +
101  ((uint8_t)(blobs[b].color.b*255.0));
102 
103  bfd.blobs[b].area = dx * dy;
104 
105  bfd.blobs[b].range = blobs[b].range;
106  }
107  }
108 
109  // should change player interface to support variable-lenght blob data
110  // size_t size = sizeof(bfd) - sizeof(bfd.blobs) + bcount * sizeof(bfd.blobs[0]);
111 
112  this->driver->Publish( this->addr,
113  PLAYER_MSGTYPE_DATA,
114  PLAYER_BLOBFINDER_DATA_BLOBS,
115  &bfd, sizeof(bfd), NULL);
116  if ( bfd.blobs )
117  delete [] bfd.blobs;
118 }
119 
120 int InterfaceBlobfinder::ProcessMessage( QueuePointer& resp_queue,
121  player_msghdr_t* hdr,
122  void* data )
123 {
124  // todo: handle configuration requests
125 
126  //else
127  {
128  // Don't know how to handle this message.
129  PRINT_WARN2( "blobfinder doesn't support msg with type/subtype %d/%d",
130  hdr->type, hdr->subtype);
131  return(-1);
132  }
133 }
134 
InterfaceBlobfinder(player_devaddr_t addr, StgDriver *driver, ConfigFile *cf, int section)
Definition: p_blobfinder.cc:41
unsigned int scan_height
Definition: stage.hh:2516
The Stage library uses its own namespace.
Definition: canvas.hh:8
virtual void Publish(void)
Definition: p_blobfinder.cc:51
#define PRINT_WARN2(m, a, b)
Definition: stage.hh:635
StgDriver * driver
Definition: p_driver.h:72
player_devaddr_t addr
Definition: p_driver.h:66
double b
Definition: stage.hh:200
double g
Definition: stage.hh:200
Stg::Model * mod
Definition: p_driver.h:115
ModelBlobfinder class
Definition: stage.hh:2483
virtual int ProcessMessage(QueuePointer &resp_queue, player_msghdr *hdr, void *data)
Blob * GetBlobs(unsigned int *count)
Definition: stage.hh:2531
unsigned int scan_width
Definition: stage.hh:2517


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:09