Update of /cvsroot/playerstage/code/player/server/drivers/blobfinder/simpleshape
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4552/server/drivers/blobfinder/simpleshape

Modified Files:
      Tag: release-2-0-patches
        simpleshape.cc 
Log Message:
backported lots of stuff from HEAD

Index: simpleshape.cc
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/server/drivers/blobfinder/simpleshape/simpleshape.cc,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -C2 -d -r1.4 -r1.4.2.1
*** simpleshape.cc      27 Feb 2006 18:19:03 -0000      1.4
--- simpleshape.cc      7 Jun 2006 16:12:39 -0000       1.4.2.1
***************
*** 101,125 ****
  /** @} */
  
! #include "player.h"
! 
! #include <errno.h>
! #include <string.h>
! #include <math.h>
! #include <stdlib.h>       // for atoi(3)
! #include <netinet/in.h>   // for htons(3)
! #include <unistd.h>
  
  #include <opencv/cv.h>
  #include <opencv/highgui.h>
  
- #include "error.h"
- #include "driver.h"
- #include "devicetable.h"
- #include "drivertable.h"
- #include "clientdata.h"
- #include "clientmanager.h"
- 
- extern ClientManager* clientmanager;
- 
  // Invariant feature set for a contour
  class FeatureSet
--- 101,109 ----
  /** @} */
  
! #include "../../base/imagebase.h"
  
  #include <opencv/cv.h>
  #include <opencv/highgui.h>
  
  // Invariant feature set for a contour
  class FeatureSet
***************
*** 152,175 ****
  
  // Driver for detecting laser retro-reflectors.
! class SimpleShape : public Driver
  {
!   // Constructor
!   public: SimpleShape( ConfigFile* cf, int section);
! 
!   // Setup/shutdown routines.
!   public: virtual int Setup();
!   public: virtual int Shutdown();
! 
!   // Process incoming messages from clients 
!   int ProcessMessage(ClientData * client, player_msghdr * hdr, uint8_t * 
data, uint8_t * resp_data, int * resp_len);
! 
!   // Main function for device thread.
!   private: virtual void Main();
  
!   // Process requests.  Returns 1 if the configuration has changed.
!   //private: int HandleRequests();
!   
!   // Grab new camera data.
!   //private: bool UpdateCamera();
  
    // Load a shape model
--- 136,148 ----
  
  // Driver for detecting laser retro-reflectors.
! class SimpleShape : public ImageBase
  {
!   public: 
!     // Constructor
!     SimpleShape( ConfigFile* cf, int section);
  
!     // Setup/shutdown routines.
!     virtual int Setup();
!     virtual int Shutdown();
  
    // Load a shape model
***************
*** 177,181 ****
  
    // Process the image
!   private: void ProcessImage();
  
    // Having pre-processed the image, find some shapes
--- 150,154 ----
  
    // Process the image
!   private: int ProcessFrame();
  
    // Having pre-processed the image, find some shapes
***************
*** 191,214 ****
    private: void WriteBlobfinderData();
  
-   // Write the outgoing camera data
-   private: void WriteCameraData();
- 
-   // Output devices
-   private: player_device_id_t blobfinder_id;
-   private: player_device_id_t out_camera_id;
- 
-   // Input camera stuff
-   private:
-   Driver *camera;
-   player_device_id_t camera_id;
-   struct timeval cameraTime;  
-   player_camera_data_t cameraData;
-   bool NewCamData;
-       
-   ClientDataInternal * BaseClient;
- 
-   // Output camera stuff
-   private: player_camera_data_t outCameraData;
- 
    // Model data (this is the shape to search for)
    private: const char *modelFilename;
--- 164,167 ----
***************
*** 250,301 ****
  // Constructor
  SimpleShape::SimpleShape( ConfigFile* cf, int section)
!     : Driver(cf, section)
  {
-   memset(&this->camera_id.code, 0, sizeof(player_device_id_t));
-   memset(&this->blobfinder_id.code, 0, sizeof(player_device_id_t));
-   memset(&this->out_camera_id.code, 0, sizeof(player_device_id_t));
- 
-   // Must have a blobfinder interface
-   if (cf->ReadDeviceId(&this->blobfinder_id, section, "provides",
-                        PLAYER_BLOBFINDER_CODE, -1, NULL) != 0)
-   {
-     this->SetError(-1);    
-     return;
-   }
-   if(this->AddInterface(this->blobfinder_id, PLAYER_READ_MODE) != 0)
-   {
-     this->SetError(-1);    
-     return;
-   }
- 
-   // Optionally have a camera interface
-   if (cf->ReadDeviceId(&this->out_camera_id, section, "provides",
-                        PLAYER_CAMERA_CODE, -1, NULL) == 0)
-   {
-     if(this->AddInterface(this->out_camera_id, PLAYER_READ_MODE) != 0)
-     {
-       this->SetError(-1);    
-       return;
-     }
-   }
-   else
-     memset(&this->out_camera_id.code, 0, sizeof(player_device_id_t));
- 
- 
-   // Must have an input camera
-   if (cf->ReadDeviceId(&this->camera_id, section, "requires",
-                        PLAYER_CAMERA_CODE, -1, NULL) != 0)
-   {
-     this->SetError(-1);    
-     return;
-   }
-   this->cameraTime.tv_sec = 0;
-   this->cameraTime.tv_usec = 0;
- 
-   // Other camera settings
-   this->camera = NULL;
-   this->BaseClient = NULL;
-   this->NewCamData = false;
- 
    this->inpImage = NULL;
    this->outImage = NULL;
--- 203,208 ----
  // Constructor
  SimpleShape::SimpleShape( ConfigFile* cf, int section)
!       : ImageBase(cf, section, true, PLAYER_MSGQUEUE_DEFAULT_MAXLEN, 
PLAYER_BLOBFINDER_CODE)
  {
    this->inpImage = NULL;
    this->outImage = NULL;
***************
*** 322,347 ****
  int SimpleShape::Setup()
  {
-   BaseClient = new ClientDataInternal(this);
-   clientmanager->AddClient(BaseClient);
- 
-   // Subscribe to the camera.
-   this->camera = deviceTable->GetDriver(this->camera_id);
-   if (!this->camera)
-   {
-     PLAYER_ERROR("unable to locate suitable camera device");
-     return(-1);
-   }
-   if (BaseClient->Subscribe(this->camera_id) != 0)
-   {
-     PLAYER_ERROR("unable to subscribe to camera device");
-     return(-1);
-   }
- 
    // Load the shape model
    if (this->LoadModel() != 0)
      return -1;
  
!   // Start the driver thread.
!   this->StartThread();
  
    return 0;
--- 229,237 ----
  int SimpleShape::Setup()
  {
    // Load the shape model
    if (this->LoadModel() != 0)
      return -1;
  
!   return ImageBase::Setup();
  
    return 0;
***************
*** 353,365 ****
  int SimpleShape::Shutdown()
  {
!   // Stop the driver thread.
!   StopThread();
!   
!   // Unsubscribe from devices.
!   BaseClient->Unsubscribe(this->camera_id);
! 
!   clientmanager->RemoveClient(BaseClient);
!   delete BaseClient;
!   BaseClient = NULL;
    
    // Free images
--- 243,247 ----
  int SimpleShape::Shutdown()
  {
!   ImageBase::Shutdown();
    
    // Free images
***************
*** 374,487 ****
  
  
////////////////////////////////////////////////////////////////////////////////
- // Main function for device thread
- void SimpleShape::Main() 
- {
- 
-   while (true)
-   {
-     // Let the camera drive update rate
-     this->camera->Wait();
- 
-     // Test if we are supposed to cancel this thread.
-     pthread_testcancel();
- 
-     // Process any new camera data.
-     Lock();
-     if (NewCamData)
-     {
-       NewCamData = false;
-       Unlock();
-       // Find all the shapes in the image
-       this->ProcessImage();
- 
-       // Write the results to the client
-       this->WriteBlobfinderData();
-       this->WriteCameraData();
-     }
-     else
-       Unlock();
- 
-     // Process any pending requests.
-     ProcessMessages();
-     //this->HandleRequests();
-   }
-   return;
- }
- 
- 
- 
////////////////////////////////////////////////////////////////////////////////
- // Process an incoming message
- int SimpleShape::ProcessMessage(ClientData * client, player_msghdr * hdr, 
uint8_t * data, uint8_t * resp_data, int * resp_len)
- {
-   assert(hdr);
-   assert(data);
-   assert(resp_data);
-   assert(resp_len);
-   assert(*resp_len==PLAYER_MAX_MESSAGE_SIZE);
-   
-   *resp_len = 0;
- 
-   if (MatchMessage(hdr, PLAYER_MSGTYPE_DATA, 0, camera_id))
-   {
-       assert(hdr->size == sizeof(this->cameraData));
-       player_camera_data_t * cam_data = reinterpret_cast<player_camera_data_t 
* > (data);
-       Lock();
-     this->cameraData.width = ntohs(cam_data->width);
-     this->cameraData.height = ntohs(cam_data->height); 
-     this->cameraData.bpp = cam_data->bpp;
-     this->cameraData.image_size = ntohl(cam_data->image_size);
-     this->cameraData.format = cam_data->format;
-     this->cameraData.compression = cam_data->compression; 
-     this->NewCamData=true;
-       Unlock();
-     if (this->cameraData.compression != PLAYER_CAMERA_COMPRESS_RAW)
-     {
-       PLAYER_WARN("camera data is compressed");
-       return false;
-     }
-     return 0;
-   }
-   
-   return -1;
- }
- 
- 
////////////////////////////////////////////////////////////////////////////////
- // Grag new camera data; returns true if there is new data to process.
- /*bool SimpleShape::UpdateCamera()
- {
-   size_t size;
-   struct timeval time;
-   
-   // Get the camera data.
-   size = this->camera->GetData(this->camera_id, &this->cameraData,
-                                sizeof(this->cameraData), &time);
-   if (size == 0)
-     return false;
- 
-   if (time.tv_sec == this->cameraTime.tv_sec &&
-       time.tv_usec == this->cameraTime.tv_usec)
-     return false;
- 
-   this->cameraTime = time;
-   
-   // Do some byte swapping
-   this->cameraData.width = ntohs(this->cameraData.width);
-   this->cameraData.height = ntohs(this->cameraData.height);
-   this->cameraData.bpp = this->cameraData.bpp;
-   this->cameraData.format = this->cameraData.format;
-   this->cameraData.compression = this->cameraData.compression;
-   this->cameraData.image_size = ntohl(this->cameraData.image_size);
- 
-   if (this->cameraData.compression != PLAYER_CAMERA_COMPRESS_RAW)
-   {
-     PLAYER_WARN("camera data is compressed");
-     return false;
-   }
- 
-   return true;
- }*/
- 
- 
- 
////////////////////////////////////////////////////////////////////////////////
  // Load a shape model
  int SimpleShape::LoadModel()
--- 256,259 ----
***************
*** 546,556 ****
  
////////////////////////////////////////////////////////////////////////////////
  // Look for stuff in the image.
! void SimpleShape::ProcessImage()
  {
    CvSize size;
    int width, height;
    
!   width = this->cameraData.width;
!   height = this->cameraData.height;
    assert(width > 0 && height > 0);
      
--- 318,328 ----
  
////////////////////////////////////////////////////////////////////////////////
  // Look for stuff in the image.
! int SimpleShape::ProcessFrame()
  {
    CvSize size;
    int width, height;
    
!   width = this->stored_data.width;
!   height = this->stored_data.height;
    assert(width > 0 && height > 0);
      
***************
*** 570,595 ****
  
    // Create a main image and copy in the pixels
!   switch (this->cameraData.format)
    {
      case PLAYER_CAMERA_FORMAT_MONO8:
      {
        // Copy pixels to input image (grayscale)
!       assert(this->inpImage->imageSize >= (int) this->cameraData.image_size);
!       memcpy(this->inpImage->imageData, this->cameraData.image, 
this->inpImage->imageSize);
        break;
      }
      default:
      {
!       PLAYER_WARN1("image format [%d] is not supported", 
this->cameraData.format);
!       return;
      }
    }
  
    // Copy original image to output
!   if (this->out_camera_id.port)
    {
      cvSetZero(this->outImage);
      cvCopy(this->inpImage, this->outSubImages + 0);
!   }
  
    // Clone the input image to our workspace
--- 342,367 ----
  
    // Create a main image and copy in the pixels
!   switch (this->stored_data.format)
    {
      case PLAYER_CAMERA_FORMAT_MONO8:
      {
        // Copy pixels to input image (grayscale)
!       assert(this->inpImage->imageSize >= (int) 
this->stored_data.image_count);
!       memcpy(this->inpImage->imageData, this->stored_data.image, 
this->inpImage->imageSize);
        break;
      }
      default:
      {
!       PLAYER_WARN1("image format [%d] is not supported", 
this->stored_data.format);
!       return -1;
      }
    }
  
    // Copy original image to output
! /*  if (this->out_camera_id.port)
    {
      cvSetZero(this->outImage);
      cvCopy(this->inpImage, this->outSubImages + 0);
!   }*/
  
    // Clone the input image to our workspace
***************
*** 602,607 ****
    cvReleaseImage(&this->workImage);
    this->workImage = NULL;
      
!   return;
  }
  
--- 374,381 ----
    cvReleaseImage(&this->workImage);
    this->workImage = NULL;
+ 
+   WriteBlobfinderData();
      
!   return 0;
  }
  
***************
*** 626,631 ****
  
    // Copy edges to output image
!   if (this->out_camera_id.port)
!     cvCopy(this->workImage, this->outSubImages + 1);
  
    // Find contours on a binary image
--- 400,405 ----
  
    // Copy edges to output image
! /*  if (this->out_camera_id.port)
!     cvCopy(this->workImage, this->outSubImages + 1);*/
  
    // Find contours on a binary image
***************
*** 653,659 ****
      
      // Draw eligable contour on the output image; useful for debugging
!     if (this->out_camera_id.port)
        cvDrawContours(this->outSubImages + 2, contour, CV_RGB(255, 255, 255),
!                      CV_RGB(255, 255, 255), 0, 1, 8);
  
      // Compute the contour features
--- 427,433 ----
      
      // Draw eligable contour on the output image; useful for debugging
! /*    if (this->out_camera_id.port)
        cvDrawContours(this->outSubImages + 2, contour, CV_RGB(255, 255, 255),
!                      CV_RGB(255, 255, 255), 0, 1, 8);*/
  
      // Compute the contour features
***************
*** 666,670 ****
  
      // Draw contour on the main image; useful for debugging
!     if (this->out_camera_id.port)
      {
        cvDrawContours(this->outSubImages + 3, contour, CV_RGB(128, 128, 128),
--- 440,444 ----
  
      // Draw contour on the main image; useful for debugging
! /*    if (this->out_camera_id.port)
      {
        cvDrawContours(this->outSubImages + 3, contour, CV_RGB(128, 128, 128),
***************
*** 672,676 ****
        cvRectangle(this->outSubImages + 3, cvPoint(rect.x, rect.y),
                    cvPoint(rect.x + rect.width, rect.y + rect.height), 
CV_RGB(255, 255, 255), 1);
!     }
  
      // Check for overrun
--- 446,450 ----
        cvRectangle(this->outSubImages + 3, cvPoint(rect.x, rect.y),
                    cvPoint(rect.x + rect.width, rect.y + rect.height), 
CV_RGB(255, 255, 255), 1);
!     }*/
  
      // Check for overrun
***************
*** 822,834 ****
  {
    unsigned int i;
!   size_t size;
    Shape *shape;
    player_blobfinder_data_t data;
  
    // Se the image dimensions
!   data.width = htons(this->cameraData.width);
!   data.height = htons(this->cameraData.height);
  
!   data.blob_count = htons(this->shapeCount);
      
    for (i = 0; i < this->shapeCount; i++)
--- 596,608 ----
  {
    unsigned int i;
!   //size_t size;
    Shape *shape;
    player_blobfinder_data_t data;
  
    // Se the image dimensions
!   data.width = (this->stored_data.width);
!   data.height = (this->stored_data.height);
  
!   data.blobs_count = (this->shapeCount);
      
    for (i = 0; i < this->shapeCount; i++)
***************
*** 837,855 ****
  
      // Set the data to pass back
!     data.blobs[i].id = 0;  // TODO
      data.blobs[i].color = 0;  // TODO
!     data.blobs[i].area = htonl((int) ((shape->bx - shape->ax) * (shape->by - 
shape->ay)));
!     data.blobs[i].x = htons((int) ((shape->bx + shape->ax) / 2));
!     data.blobs[i].y = htons((int) ((shape->by + shape->ay) / 2));
!     data.blobs[i].left = htons((int) (shape->ax));
!     data.blobs[i].top = htons((int) (shape->ay));
!     data.blobs[i].right = htons((int) (shape->bx));
!     data.blobs[i].bottom = htons((int) (shape->by));
!     data.blobs[i].range = htons(0);
    }
  
    // Copy data to server
!   size = sizeof(data) - sizeof(data.blobs) + this->shapeCount * 
sizeof(data.blobs[0]);
!   this->PutMsg(this->blobfinder_id, NULL, PLAYER_MSGTYPE_DATA, 0, &data, 
size, &this->cameraTime);
    
    return;
--- 611,631 ----
  
      // Set the data to pass back
!     data.blobs[i].id = shape->id;  // TODO
      data.blobs[i].color = 0;  // TODO
!     data.blobs[i].area = ((int) ((shape->bx - shape->ax) * (shape->by - 
shape->ay)));
!     data.blobs[i].x = ((int) ((shape->bx + shape->ax) / 2));
!     data.blobs[i].y = ((int) ((shape->by + shape->ay) / 2));
!     data.blobs[i].left = ((int) (shape->ax));
!     data.blobs[i].top = ((int) (shape->ay));
!     data.blobs[i].right = ((int) (shape->bx));
!     data.blobs[i].bottom = ((int) (shape->by));
!     data.blobs[i].range = (0);
    }
  
+   // Copy data to server.
+   
Publish(device_addr,NULL,PLAYER_MSGTYPE_DATA,PLAYER_BLOBFINDER_DATA_BLOBS,&data,sizeof(data));
    // Copy data to server
! /*  size = sizeof(data) - sizeof(data.blobs) + this->shapeCount * 
sizeof(data.blobs[0]);
!   this->PutMsg(this->blobfinder_id, NULL, PLAYER_MSGTYPE_DATA, 0, &data, 
size, &this->cameraTime);*/
    
    return;
***************
*** 860,864 ****
  // Write camera data; this is a little bit naughty: we re-use the
  // input camera data, but modify the pixels
! void SimpleShape::WriteCameraData()
  {
    size_t size;
--- 636,640 ----
  // Write camera data; this is a little bit naughty: we re-use the
  // input camera data, but modify the pixels
! /*void SimpleShape::WriteCameraData()
  {
    size_t size;
***************
*** 888,892 ****
    
    return;
! }
  
  
--- 664,668 ----
    
    return;
! }*/
  
  



_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to