// Load Regions related to a provided SfM_Data View container
  virtual bool load(
    const SfM_Data & sfm_data,
    const std::string & feat_directory,
    std::unique_ptr<features::Image_describer>& image_describer)
  {
    C_Progress_display my_progress_bar( sfm_data.GetViews().size(),
      std::cout, "\n- Regions Loading -\n");
    // Read for each view the corresponding regions and store them
    for (Views::const_iterator iter = sfm_data.GetViews().begin();
      iter != sfm_data.GetViews().end(); ++iter, ++my_progress_bar)
    {
      const std::string sImageName = stlplus::create_filespec(sfm_data.s_root_path, iter->second.get()->s_Img_path);
      const std::string basename = stlplus::basename_part(sImageName);
      const std::string featFile = stlplus::create_filespec(feat_directory, basename, ".feat");
      const std::string descFile = stlplus::create_filespec(feat_directory, basename, ".desc");

      image_describer->Allocate(regions_per_view[iter->second.get()->id_view]);
      if (!image_describer->Load(
        regions_per_view[iter->second.get()->id_view].get(),
        featFile,
        descFile))
      {
        std::cerr << "Invalid regions files for the view: " << sImageName << std::endl;
        return false;
      }
    }
    return true;
  }
示例#2
0
/**
 * Construct an analog input.
 *
 * @param channel The channel number on the roboRIO to represent. 0-3 are
 * on-board 4-7 are on the MXP port.
 */
AnalogInput::AnalogInput(uint32_t channel) {
    std::stringstream buf;
    buf << "Analog Input " << channel;
    Resource::CreateResourceObject(inputs, kAnalogInputs);

    if (!checkAnalogInputChannel(channel)) {
        wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
        return;
    }

    if (inputs->Allocate(channel, buf.str()) ==
            std::numeric_limits<uint32_t>::max()) {
        CloneError(*inputs);
        return;
    }

    m_channel = channel;

    void *port = getPort(channel);
    int32_t status = 0;
    m_port = initializeAnalogInputPort(port, &status);
    wpi_setErrorWithContext(status, getHALErrorMessage(status));

    LiveWindow::GetInstance()->AddSensor("AnalogInput", channel, this);
    HALReport(HALUsageReporting::kResourceType_AnalogChannel, channel);
}
示例#3
0
/**
 * Relay constructor given a channel.
 *
 * This code initializes the relay and reserves all resources that need to be
 * locked. Initially the relay is set to both lines at 0v.
 * @param channel The channel number (0-3).
 * @param direction The direction that the Relay object will control.
 */
Relay::Relay(uint32_t channel, Relay::Direction direction)
    : m_channel(channel), m_direction(direction) {
  std::stringstream buf;
  Resource::CreateResourceObject(relayChannels,
                                 dio_kNumSystems * kRelayChannels * 2);
  if (!SensorBase::CheckRelayChannel(m_channel)) {
    buf << "Relay Channel " << m_channel;
    wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
    return;
  }

  if (m_direction == kBothDirections || m_direction == kForwardOnly) {
    buf << "Forward Relay " << m_channel;
    if (relayChannels->Allocate(m_channel * 2, buf.str()) == ~0ul) {
      CloneError(*relayChannels);
      return;
    }

    HALReport(HALUsageReporting::kResourceType_Relay, m_channel);
  }
  if (m_direction == kBothDirections || m_direction == kReverseOnly) {
    buf << "Reverse Relay " << m_channel;
    if (relayChannels->Allocate(m_channel * 2 + 1, buf.str()) == ~0ul) {
      CloneError(*relayChannels);
      return;
    }

    HALReport(HALUsageReporting::kResourceType_Relay, m_channel + 128);
  }

  int32_t status = 0;
  setRelayForward(m_relay_ports[m_channel], false, &status);
  setRelayReverse(m_relay_ports[m_channel], false, &status);
  wpi_setErrorWithContext(status, getHALErrorMessage(status));

  LiveWindow::GetInstance().AddActuator("Relay", 1, m_channel, this);
}
bool SaveAndLoad
(
  std::unique_ptr<Image_describer> & image_describer
)
{
  const std::string sImage_describer = stlplus::create_filespec("./", "image_describer", "json");
  {
    std::ofstream stream(sImage_describer.c_str());
    if (!stream.is_open())
      return false;

    try
    {
      cereal::JSONOutputArchive archive(stream);
      archive(cereal::make_nvp("image_describer", image_describer));
      auto regionsType = image_describer->Allocate();
      archive(cereal::make_nvp("regions_type", regionsType));
    }
    catch (const cereal::Exception & e)
    {
      std::cerr << e.what() << std::endl
        << "Cannot dynamically allocate the Image_describer interface." << std::endl;
      return false;
    }
  }

  image_describer.reset();

  {
    // Dynamically load the image_describer from the file (will restore old used settings)
    std::ifstream stream(sImage_describer.c_str());
    if (!stream.is_open())
      return false;
    try
    {
      cereal::JSONInputArchive archive(stream);
      archive(cereal::make_nvp("image_describer", image_describer));
    }
    catch (const cereal::Exception & e)
    {
      std::cerr << e.what() << std::endl
        << "Cannot dynamically allocate the Image_describer interface." << std::endl;
      return false;
    }
  }
  return true;
}