예제 #1
0
// Basic test for camera device.
int test_camera(playerc_client_t *client, int index)
{
  int t;
  void *rdevice;
  playerc_camera_t *device;
  char filename[128];
  int csize, usize;

  printf("device [camera] index [%d]\n", index);

  device = playerc_camera_create(client, index);

  TEST("subscribing (read)");
  if (playerc_camera_subscribe(device, PLAYER_OPEN_MODE) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();

  for (t = 0; t < 10; t++)
  {
    TEST1("reading data (attempt %d)", t);

    do
      rdevice = playerc_client_read(client);
    while (rdevice == client);

    if (rdevice == device)
    {
      PASS();

      // Decompress the image
      csize = device->image_count;
      playerc_camera_decompress(device);
      usize = device->image_count;

      printf("camera: [w %d h %d d %d] [%d/%d bytes]\n",
             device->width, device->height, device->bpp, csize, usize);

      snprintf(filename, sizeof(filename), "camera_%03d.ppm", t);
      printf("camera: saving [%s]\n", filename);
      playerc_camera_save(device, filename);
    }
    else
      FAIL();
  }

  TEST("unsubscribing");
  if (playerc_camera_unsubscribe(device) != 0)
  {
    FAIL();
    return -1;
  }
  PASS();

  playerc_camera_destroy(device);

  return 0;
}
예제 #2
0
PlayerCam::PlayerCam(char *hostname, int port) {
  index = 0;
  client = playerc_client_create(NULL, hostname, port);
  playerc_client_connect(client);
  camDevice = playerc_camera_create(client, index);
  if (playerc_camera_subscribe(camDevice, PLAYER_OPEN_MODE) != 0) {
    printf("PlayerCam: subscribe failed\n");
  } else {
    printf("PlayerCam: subscribe succeeded\n");
  }
  // get image details
  depth = 3;
  // set width, height 0 to trigger automatically:
  width = 0;
  height = 0;
  updateMMap(0); // this will set height and width automatically
  initialize(width, height, depth, 0, 1, 2); // create some space
}
예제 #3
0
int
player_init(int argc, char *argv[])
{
  int csize, usize, i;

  if(get_options(argc, argv) < 0)
  {
    print_usage();
    exit(-1);
  }

  // Create a g_client object and connect to the server; the server must
  // be running on "localhost" at port 6665
  g_client = playerc_client_create(NULL, g_hostname, g_port);
  playerc_client_set_transport(g_client, g_transport);
  if (0 != playerc_client_connect(g_client))
  {
    fprintf(stderr, "error: %s\n", playerc_error_str());
    exit(-1);
  }

/*  if (0 != playerc_client_datafreq(g_client, 20))
  {
    fprintf(stderr, "error: %s\n", playerc_error_str());
    return -1;
  }
*/

  // Create a camera proxy (device id "camera:index") and susbscribe
  g_camera = playerc_camera_create(g_client, g_camera_index);
  if (0 != playerc_camera_subscribe(g_camera, PLAYER_OPEN_MODE))
  {
    fprintf(stderr, "camera error: %s\n", playerc_error_str());
    fprintf(stderr, "playercam will attempt to continue without a camera\n");
    playerc_camera_destroy(g_camera);
    g_camera = NULL;
  }

  // Create a blobfinder proxy (device id "blobfinder:index") and susbscribe
  g_blobfinder = playerc_blobfinder_create(g_client, g_blobfinder_index);
  if (0 != playerc_blobfinder_subscribe(g_blobfinder, PLAYER_OPEN_MODE))
  {
    fprintf(stderr, "blobfinder error: %s\n", playerc_error_str());
    fprintf(stderr, "playercam will attempt to continue without a blobfinder\n");
    playerc_blobfinder_destroy(g_blobfinder);
    g_blobfinder = NULL;
  }

  if ((NULL == g_camera) && (NULL == g_blobfinder))
  {
    fprintf(stderr, "we need either a camera or blobfinder! aborting\n");
    exit(-1);
  }

  // Get up to 10 images until we have a valid frame (g_wdith > 0)
  for (i=0, g_width=0; i < 10 && g_width==0 && NULL != playerc_client_read(g_client); ++i)
  {
    if (NULL != g_camera)
    {
      // Decompress the image
      csize = g_camera->image_count;
      playerc_camera_decompress(g_camera);
      usize = g_camera->image_count;

      g_print("camera: [w %d h %d d %d] [%d/%d bytes]\n",
              g_camera->width, g_camera->height, g_camera->bpp, csize, usize);

      g_width  = g_camera->width;
      g_height = g_camera->height;
      if (allocated_size != usize)
      {
    	  g_img = realloc(g_img, usize);
        allocated_size = usize;
      }
    }
    else // try the blobfinder
    {
      g_print("blobfinder: [w %d h %d]\n",
              g_blobfinder->width, g_blobfinder->height);

      g_width  = g_blobfinder->width;
      g_height = g_blobfinder->height;
      usize = g_width * g_height * 3;
      if (allocated_size != usize)
      {
        g_img = realloc(g_img, usize);
        allocated_size = usize;
      }
      // set the image data to 0 since we don't have a camera
      memset(g_img, 128, usize);
    }
  }

  g_window_width  = g_width;
  g_window_height = g_height;

  assert(g_width>0);
  assert(g_height>0);

  playerc_client_datamode(g_client,PLAYER_DATAMODE_PULL);
  playerc_client_set_replace_rule(g_client,-1,-1,PLAYER_MSGTYPE_DATA,-1,1);

  return 0;
}