예제 #1
0
int
main(int argc, char **argv)
{

  const char *filename = "qatest.colormap";
  if ( argc > 1 ) {
    filename = argv[1];
  }

  printf("Creating simple one-plane colormap\n");
  YuvColormap *cm = new YuvColormap();

  for (unsigned int u = 100; u < 150; ++u) {
    for (unsigned int v = 100; v < 150; ++v) {
      cm->set(128, u, v, C_ORANGE);
    }
  }

  unsigned char *imgb = malloc_buffer(YUV422_PLANAR, cm->width() * 2, cm->height() * 2);
  cm->to_image(imgb);

  ImageDisplay *imgd = new ImageDisplay(cm->width() * 2, cm->height() * 2);
  imgd->show(imgb);

  imgd->loop_until_quit();

  delete cm;

  printf("Trying to create colormap with illegal depth, should throw an exception..");
  try {
    cm = new YuvColormap(3);
    printf(" Test failed, colormap was created\n");
    delete cm;
  } catch (Exception &e) {
    printf(" Test succeeded, caught exception\n");
  }

  printf("Trying colormap with depth of %u\n", BIGDEPTH);
  cm = new YuvColormap(BIGDEPTH);

  for (unsigned int d = 0; d < cm->depth(); ++d) {
    unsigned int y = 256 / cm->depth() * d;
    printf("d=%u   y=%u   u=[%u,%u]  v=[%u,%u]\n", d, y,
	   cm->depth() * d, cm->depth() * (d+1), cm->depth() * d, cm->depth() * (d+1));

    for (unsigned int u = cm->deepness() / cm->depth() * d; u < cm->deepness() / cm->depth() * (d+1); ++u) {
      for (unsigned int v = cm->deepness() / cm->depth() * d; v < cm->deepness() / cm->depth() * (d+1); ++v) {
	cm->set(y, u, v, C_ORANGE);
      }
    }

    cm->to_image(imgb, d);
    imgd->show(imgb);
    imgd->loop_until_quit();
  }

  printf("Saving colormap to a file\n");
  ColormapFile cmf;
  cmf.add_colormap(cm);
  cmf.write(filename);

  ColormapFile::ColormapBlockVector *blocks = cmf.colormap_blocks();
  printf("Written, created %zu blocks\n", blocks->size());
  delete blocks;
  delete cm;

  cmf.clear();

  printf("Reading colormap from file\n");
  cmf.read(filename);

  Colormap *tcm = cmf.get_colormap();
  if ( (cm = dynamic_cast<YuvColormap *>(tcm)) == 0 ) {
    printf("Error, did not get valid yuv colormap\n");
  } else {
    printf("Showing all %u colormap levels\n", cm->depth());
    for (unsigned int d = 0; d < cm->depth(); ++d) {
      cm->to_image(imgb, d);
      imgd->show(imgb);
      imgd->loop_until_quit();
    }
  }

  delete cm;

  unsigned int depth = 4, width = 128, height = 128;
  printf("Trying colormap with low resolution, choosing %dx%dx%d\n", depth, width, height);
  cm = new YuvColormap(depth, width, height);
  printf("YuvColormap dimensions: %dx%dx%d\n", cm->depth(), cm->width(), cm->height());
  ColormapFile cmfr(depth, width, height);
  delete cm;
  cmfr.write(filename);
  cmfr.clear();
  cmfr.read(filename);
  cm = dynamic_cast<YuvColormap *>(cmfr.get_colormap());
  printf("Read back colormap dimensions %dx%dx%d\n",
	 cm->depth(), cm->width(), cm->height());
  delete cm;

  //delete imgd;
  //free(imgb);
  return 0;
}
예제 #2
0
/** Copy constructor.
 * Creates a colormap in shared memory for the given LUT ID and copies the data of the
 * given existing colormap.
 * @param cm color mape to copy from
 */
YuvColormap::YuvColormap(const YuvColormap &cm)
{
	constructor(cm.depth(), cm.width(), cm.height());
	memcpy(lut_, cm.lut_, lut_size_);
}
예제 #3
0
void
FvRetrieverThread::init()
{
  colorspace_t cspace = YUV422_PLANAR;
  std::string cspace_str = colorspace_to_string(cspace);
  try {
    cspace_str = config->get_string((cfg_prefix_ + "colorspace").c_str());
    cspace = colorspace_by_name(cspace_str.c_str());
  } catch (Exception &e) {} // ignored, use default
  if (cspace == CS_UNKNOWN) {
    throw Exception("Unknown colorspace '%s' configured", cspace_str.c_str());
  }

  try {
    logger->log_debug(name(), "Registering for camera '%s' (colorspace %s)",
                      camera_string_.c_str(), colorspace_to_string(cspace));
    cam = vision_master->register_for_camera(camera_string_.c_str(), this, cspace);
  } catch (Exception &e) {
    e.append("FvRetrieverThread::init() failed");
    throw;
  }
  try {
    char *imgbufname;
    if ( asprintf(&imgbufname, "retriever_%s", cfg_name_.c_str()) == -1 ) {
      throw Exception("Cannot allocate buffer name");
    }
    shm = new SharedMemoryImageBuffer(imgbufname, cam->colorspace(),
				      cam->pixel_width(), cam->pixel_height());

    free(imgbufname);
    if ( ! shm->is_valid() ) {
      throw Exception("Shared memory segment not valid");
    }
  } catch (Exception &e) {
    delete cam;
    cam = NULL;
    throw;
  }

  try {
    std::string frame_id = config->get_string((cfg_prefix_ + "frame").c_str());
    shm->set_frame_id(frame_id.c_str());
  } catch (Exception &e) {/* ignored, not critical */}

  seq_writer = NULL;
  try {
    if ( config->get_bool("/firevision/retriever/save_images") ) {
      logger->log_info(name(), "Writing images to disk");
      Writer* writer = new JpegWriter();
      seq_writer = new SeqWriter(writer);
      std::string save_path;
       try {
 	save_path = config->get_string("/firevision/retriever/save_path");
       } catch (Exception &e) {
	 save_path = ("recorded_images");
	 logger->log_info(name(), "No save path specified. Using './%s'", save_path.c_str());
       }
      seq_writer->set_path( save_path.c_str() );
      seq_writer->set_dimensions( cam->pixel_width(), cam->pixel_height() );
      seq_writer->set_colorspace( cam->colorspace() );
    }
  } catch (Exception &e) {
    // ignored, not critical
  }

  __tt = NULL;
  try {
    if ( config->get_bool("/firevision/retriever/use_time_tracker") ) {
      __tt = new TimeTracker();
      __ttc_capture = __tt->add_class("Capture");
      __ttc_memcpy  = __tt->add_class("Memcpy");
      __ttc_dispose = __tt->add_class("Dispose");
      __loop_count  = 0;
    }
  } catch (Exception &e) {
    // ignored, not critical
  }

  __cm = new ColorModelLookupTable(1, "retriever-colormap", true);
  YuvColormap *ycm = __cm->get_colormap();
  for (unsigned int u = 100; u < 150; ++u) {
    for (unsigned int v = 100; v < 150; ++v) {
      ycm->set(128, u, v, C_ORANGE);
    }
  }

  __cam_has_timestamp_support = true;
  try {
    fawkes::Time *t = cam->capture_time();
    if (t->is_zero()) {
      throw NotImplementedException("");
    }
    cap_time_ = NULL;
  }
  catch (NotImplementedException &e)
  {
    __cam_has_timestamp_support = false;
    cap_time_ = new Time(clock);
  }
}