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

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

Index: upcbarcode.cc
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/server/drivers/blobfinder/upcbarcode/upcbarcode.cc,v
retrieving revision 1.17
retrieving revision 1.17.2.1
diff -C2 -d -r1.17 -r1.17.2.1
*** upcbarcode.cc       23 Feb 2006 18:54:54 -0000      1.17
--- upcbarcode.cc       7 Jun 2006 16:12:39 -0000       1.17.2.1
***************
*** 107,131 ****
  /** @} */
  
! #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;
- 
  // Info on potential blobs.
  struct blob_t
--- 107,115 ----
  /** @} */
  
! #include "../../base/imagebase.h"
  
  #include <opencv/cv.h>
  #include <opencv/highgui.h>
  
  // Info on potential blobs.
  struct blob_t
***************
*** 140,169 ****
  
  // Driver for detecting laser retro-reflectors.
! class UPCBarcode : public Driver
  {
    // Constructor
    public: UPCBarcode( 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();
! 
!   // Handle geometry requests.
!   //private: void HandleGetGeom(void *client, void *req, int reqlen);
!   
!   // Process any new camera data.
!   //private: int ReadCamera();
  
    // Look for barcodes in the image.  
!   private: void ProcessImage();
  
    // Extract a bit string from the image.  
--- 124,138 ----
  
  // Driver for detecting laser retro-reflectors.
! class UPCBarcode : public ImageBase
  {
    // Constructor
    public: UPCBarcode( ConfigFile* cf, int section);
  
!     // Setup/shutdown routines.
!     virtual int Setup();
!     virtual int Shutdown();
  
    // Look for barcodes in the image.  
!   private: int ProcessFrame();
  
    // Extract a bit string from the image.  
***************
*** 177,185 ****
  
    // Write the device data (the data going back to the client).
!   private: void WriteCameraData();
  
-   // Output devices
-   private: player_device_id_t blobfinder_id;
-   private: player_device_id_t out_camera_id;
  
    // Image processing
--- 146,151 ----
  
    // Write the device data (the data going back to the client).
!   //private: void WriteCameraData();
  
  
    // Image processing
***************
*** 192,205 ****
    private: double errFirst, errSecond;
  
!   // Input camera stuff
!   private:
!   Driver *camera;
!   player_device_id_t camera_id;
!   struct timeval cameraTime;  
!   player_camera_data_t cameraData;
!   bool NewCamData;
!       
!   ClientDataInternal * BaseClient;
!   
    // Images
    private: IplImage *inpImage;
--- 158,162 ----
    private: double errFirst, errSecond;
  
!  
    // Images
    private: IplImage *inpImage;
***************
*** 233,278 ****
  // Constructor
  UPCBarcode::UPCBarcode( ConfigFile* cf, int section)
!     : Driver(cf, section)
  {
-   
-   // 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;
-   }
- 
-   // Other camera settings
-   this->camera = NULL;
-   this->BaseClient = NULL;
-   this->NewCamData = false;
- 
    // Image workspace
    this->inpImage = NULL;
--- 190,195 ----
  // Constructor
  UPCBarcode::UPCBarcode( ConfigFile* cf, int section)
!       : ImageBase(cf, section, true, PLAYER_MSGQUEUE_DEFAULT_MAXLEN, 
PLAYER_BLOBFINDER_CODE)
  {
    // Image workspace
    this->inpImage = NULL;
***************
*** 300,345 ****
  }
  
- 
  
////////////////////////////////////////////////////////////////////////////////
! // Set up the device (called by server thread).
  int UPCBarcode::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);
!   }
! 
!   // Start the driver thread.
!   this->StartThread();
!   
!   return 0;
  }
  
- 
  
////////////////////////////////////////////////////////////////////////////////
  // Shutdown the device (called by server thread).
  int UPCBarcode::Shutdown()
  {
!   // Stop the driver thread.
!   StopThread();
!   
!   // Unsubscribe from devices.
!   BaseClient->Unsubscribe(this->camera_id);
! 
!   clientmanager->RemoveClient(BaseClient);
!   delete BaseClient;
!   BaseClient = NULL;
  
    if (this->inpImage)
--- 217,232 ----
  }
  
  
////////////////////////////////////////////////////////////////////////////////
! // Setup the device (called by server thread).
  int UPCBarcode::Setup()
  {
!   return ImageBase::Setup();
  }
  
  
////////////////////////////////////////////////////////////////////////////////
  // Shutdown the device (called by server thread).
  int UPCBarcode::Shutdown()
  {
!   ImageBase::Shutdown();
  
    if (this->inpImage)
***************
*** 347,350 ****
--- 234,238 ----
    if (this->outImage)
      cvReleaseImage(&(this->outImage));
+   inpImage = outImage = NULL;
  
    return 0;
***************
*** 352,451 ****
  
  
- 
////////////////////////////////////////////////////////////////////////////////
- // Main function for device thread
- void UPCBarcode::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();
-       this->ProcessImage();
-       this->WriteBlobfinderData();
-       this->WriteCameraData();      
-     }
-     else
-       Unlock();
- 
-     // Process any pending requests.
-     this->ProcessMessages();
-   }
-   return;
- }
- 
- 
- 
////////////////////////////////////////////////////////////////////////////////
- // Process an incoming message
- int UPCBarcode::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;
- 
-   /* TODO
-   if (MatchMessage(hdr, PLAYER_MSGTYPE_REQ, PLAYER_BLOBFINDER_GET_GEOM, 
device_id))
-   {
-   }
-   */
-  
-   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();
-       return 0;
-   }
-  
-   return -1;
- }
- 
- 
- 
////////////////////////////////////////////////////////////////////////////////
- // Process any new camera data.
- /*int UPCBarcode::ReadCamera()
- {
-   size_t size;
- 
-   // Get the camera data.
-   size = this->camera->GetData(this->camera_id, &this->cameraData,
-                                sizeof(this->cameraData), &this->cameraTime);
-   
-   // 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.image_size = ntohl(this->cameraData.image_size);
-   this->cameraData.format = this->cameraData.format;
-   this->cameraData.compression = this->cameraData.compression;
-   
-   return 1;
- }
- */
  
  
////////////////////////////////////////////////////////////////////////////////
  // Look for barcodes in the image.  This looks for verical barcodes,
  // and assumes barcodes are not placed above each other.
! void UPCBarcode::ProcessImage()
  {
    int x, step_x;
--- 240,248 ----
  
  
  
  
////////////////////////////////////////////////////////////////////////////////
  // Look for barcodes in the image.  This looks for verical barcodes,
  // and assumes barcodes are not placed above each other.
! int UPCBarcode::ProcessFrame()
  {
    int x, step_x;
***************
*** 457,462 ****
    int width, height;
  
!   width = this->cameraData.width;
!   height = this->cameraData.height;
  
    // Create input image if it doesnt exist
--- 254,259 ----
    int width, height;
  
!   width = this->stored_data.width;
!   height = this->stored_data.height;
  
    // Create input image if it doesnt exist
***************
*** 465,481 ****
  
    // Copy pixels into input image
!   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;
      }
    }
--- 262,278 ----
  
    // Copy pixels into input image
!   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;
      }
    }
***************
*** 490,498 ****
  
    // Copy original image to output
!   if (this->out_camera_id.port)
    {
      cvSetZero(this->outImage);
      cvCopy(this->inpImage, this->outSubImages + 0);
!   }
  
    step_x = 16;
--- 287,295 ----
  
    // Copy original image to output
! /*  if (this->out_camera_id.port)
    {
      cvSetZero(this->outImage);
      cvCopy(this->inpImage, this->outSubImages + 0);
!   }*/
  
    step_x = 16;
***************
*** 529,543 ****
        blob->bx = x + 1;
        blob->ay = min;
!       blob->by = this->cameraData.height - 2;
  
        if (this->out_camera_id.port)
        {
-         /*
          cvRectangle(this->outSubImages + 0, cvPoint(blob->ax, blob->ay),
                      cvPoint(blob->bx, blob->by), CV_RGB(0, 0, 0), 1);
          cvRectangle(this->outSubImages + 1, cvPoint(blob->ax, blob->ay),
                      cvPoint(blob->bx, blob->by), CV_RGB(255, 255, 255), 1);
-         */
        }
      }
  
--- 326,340 ----
        blob->bx = x + 1;
        blob->ay = min;
!       blob->by = this->stored_data.height - 2;
  
+         /*
        if (this->out_camera_id.port)
        {
          cvRectangle(this->outSubImages + 0, cvPoint(blob->ax, blob->ay),
                      cvPoint(blob->bx, blob->by), CV_RGB(0, 0, 0), 1);
          cvRectangle(this->outSubImages + 1, cvPoint(blob->ax, blob->ay),
                      cvPoint(blob->bx, blob->by), CV_RGB(255, 255, 255), 1);
        }
+         */
      }
  
***************
*** 549,553 ****
    }
  
!   return;
  }
  
--- 346,352 ----
    }
  
!   WriteBlobfinderData();
! 
!   return 0;
  }
  
***************
*** 761,771 ****
    int i;
    blob_t *blob;
!   size_t size;
    player_blobfinder_data_t data;
  
!   data.width = htons(this->cameraData.width);
!   data.height = htons(this->cameraData.height);
  
!   data.blob_count = htons(this->blobCount);
      
    for (i = 0; i < this->blobCount; i++)
--- 560,570 ----
    int i;
    blob_t *blob;
! //  size_t size;
    player_blobfinder_data_t data;
  
!   data.width = (this->stored_data.width);
!   data.height = (this->stored_data.height);
  
!   data.blobs_count = (this->blobCount);
      
    for (i = 0; i < this->blobCount; i++)
***************
*** 773,792 ****
      blob = this->blobs + i;
  
!     data.blobs[i].id = 0;  // TODO
      data.blobs[i].color = 0;  // TODO
!     data.blobs[i].area = htonl((int) ((blob->bx - blob->ax) * (blob->by - 
blob->ay)));
!     data.blobs[i].x = htons((int) ((blob->bx + blob->ax) / 2));
!     data.blobs[i].y = htons((int) ((blob->by + blob->ay) / 2));
!     data.blobs[i].left = htons((int) (blob->ax));
!     data.blobs[i].right = htons((int) (blob->ay));
!     data.blobs[i].top = htons((int) (blob->bx));
!     data.blobs[i].bottom = htons((int) (blob->by));
!     data.blobs[i].range = htons(0);
    }
      
    // Copy data to server
!   size = sizeof(data) - sizeof(data.blobs) + this->blobCount * 
sizeof(data.blobs[0]);
    PutMsg(blobfinder_id, NULL, PLAYER_MSGTYPE_DATA, 0, (unsigned char*) &data, 
size, &this->cameraTime);               
!   
    return;
  }
--- 572,593 ----
      blob = this->blobs + i;
  
!     data.blobs[i].id = blob->id;  // TODO
      data.blobs[i].color = 0;  // TODO
!     data.blobs[i].area = ((int) ((blob->bx - blob->ax) * (blob->by - 
blob->ay)));
!     data.blobs[i].x = ((int) ((blob->bx + blob->ax) / 2));
!     data.blobs[i].y = ((int) ((blob->by + blob->ay) / 2));
!     data.blobs[i].left = ((int) (blob->ax));
!     data.blobs[i].right = ((int) (blob->ay));
!     data.blobs[i].top = ((int) (blob->bx));
!     data.blobs[i].bottom = ((int) (blob->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->blobCount * 
sizeof(data.blobs[0]);
    PutMsg(blobfinder_id, NULL, PLAYER_MSGTYPE_DATA, 0, (unsigned char*) &data, 
size, &this->cameraTime);               
!   */
    return;
  }
***************
*** 796,800 ****
  // Write camera data; this is a little bit naughty: we re-use the
  // input camera data, but modify the pixels
! void UPCBarcode::WriteCameraData()
  {
    size_t size;
--- 597,601 ----
  // Write camera data; this is a little bit naughty: we re-use the
  // input camera data, but modify the pixels
! /*void UPCBarcode::WriteCameraData()
  {
    size_t size;
***************
*** 825,827 ****
    
    return;
! }
--- 626,628 ----
    
    return;
! }*/



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

Reply via email to