Ejemplo n.º 1
0
cs_status mc_init()
{
    if(mc_dev_init()) {
        MC_LOG(IROS_LOG_LEVEL_CRI, "mc_init() fail!\n");
        return CS_E_ERROR;
    }

    mc_timer_init(mc_static_timer_handler);

    return CS_E_OK;
}
Ejemplo n.º 2
0
void VideoWatcher::CheckFiles()
{
  if (QFile("no_calibration").exists() && Undistort)
  {
    Undistort = false;
    MC_LOG("Disable the calibration");
  } else
  if (!QFile("no_calibration").exists() && !Undistort)
  {
    Undistort = true;
    MC_LOG("Enable the calibration");
  }

  if (QFile("debug_corners").exists() && !DebugCorners)
  {
    DebugCorners = true;
    MC_LOG("Enable corner detection debugging");
  } else
  if (!QFile("debug_corners").exists() && DebugCorners)
  {
    DebugCorners = false;
    MC_LOG("Disable corner detection debugging");
  }

  if (QFile("debug_motions").exists() && !DebugMotions)
  {
    DebugMotions = true;
    MC_LOG("Enable motion detection debugging");
  } else
  if (!QFile("debug_motions").exists() && DebugMotions)
  {
    DebugMotions = false;
    MC_LOG("Disable motion detection debugging");
  }
}
Ejemplo n.º 3
0
void VideoWatcher::CaptureFinished()
{
  QFuture<void> CaptureTask;
  static bool AudioStarted = false;

  // In debug mode, keep the audio and video playback in sync
  if (WaitDuration > 0)
    MCSleep(WaitDuration);

  FrameCount++;
  OverallFrameCount++;
  *OriginalImage = *CapturedImage;
  if (AudioStarted == false)
  {
    QTimer::singleShot(100, this, SIGNAL(StartAudio()));
    AudioStarted = true;
  }
  // Start a new capture
  CaptureTask = QtConcurrent::run(boost::bind(&VideoWatcher::CaptureImage, this));
  CaptureWatcher.setFuture(CaptureTask);
  if (FrameCount % 3 == 1)
    return;

  OriginalImage->ConvertBGRToRGB();
  *FinalImage = *OriginalImage;
  CheckFiles();
  // Check if the capture process stopped by some reason
  if (!CaptureDevice->IsCapturing())
  {
    MC_LOG("Capture stopped");
    QCoreApplication::quit();
  }
  // Be sure that the image has the expected size
  if (FinalImage->GetWidth() != FrameWidth && FinalImage->GetHeight() != FrameHeight)
  {
    FinalImage->Resize(FrameWidth, FrameHeight);
  }
  if (Undistort && FinalImage->GetWidth() == FrameWidth && FinalImage->GetHeight() == FrameHeight)
  {
    Calibration->Undistort(*FinalImage);
    // TODO: The rotational correction is too CPU expensive
    if (!MCIsFloatInfinity(RotationAngle))
    {
      FinalImage->Rotate(RotationCenter.X, RotationCenter.Y, RotationAngle);
    }
  }
  // Check if the lights are off
  if (FinalImage->AverageBrightnessLevel() < 10)
  {
    Markers->Reset();
    MotionDetection->Reset();
    Q_EMIT(VideoEvent(IOP::IdleEvent));
    Q_EMIT(VideoEvent(IOP::CaptureEvent));
    return;
  }
  // Calculate fps
  if (FrameCount % 300 == 0)
  {
    MC_LOG("Capture speed: %1.2f fps", (float)1000 / FpsTimer.elapsed()*FrameCount);
    FpsTimer.start();
    FrameCount = 0;
    MC_LOG("Average brightness level: %1.2f", FinalImage->AverageBrightnessLevel());
  }
  // Corner detection
  Markers->AddImage(*FinalImage);
  // TODO: The rotational correction is too CPU expensive
  if (Markers->IsReady() && !Markers->IsAnyMissingCorner() && MCIsFloatInfinity(RotationAngle))
  {
    // Get the rotational angle and reset the marker detection
    Markers->GetRotationalCorrection(*FinalImage, RotationAngle, RotationCenter);
    MC_LOG("Detected rotation: %1.2f degrees", RotationAngle);
    Markers->Reset();
  }
  // Motion detection
  MEImage MotionFrame = *FinalImage;

  MotionFrame.Resize(FrameWidth / 4, FrameHeight / 4);
  MotionDetection->DetectMotions(MotionFrame);
  /*
   * Draw the debug signs and texts on the original image
   */
  DebugMessageImage->Clear();
  // Composite debug signs
  if (DebugMotions)
  {
    MEImage MaskImage;

    MotionDetection->GetMotionsMask(MaskImage);
    // Convert the grayscale image back to RGB
    MaskImage.ConvertToRGB();
    MaskImage.Resize(FrameWidth, FrameHeight);
    FinalImage->Addition(MaskImage, ME::MaskAddition);
  }
  if (DebugCorners)
    Markers->DrawDebugSigns(*FinalImage);
  if (Markers->IsReady() && Markers->IsAnyMissingCorner())
  {
    Markers->DrawMissingCorners(*FinalImage);
    DebugMessageImage->DrawText(160, 320, "Table not detected", 1, MEColor(255, 255, 255));
    Q_EMIT(VideoEvent(IOP::MissingCornersEvent));
  }
  Q_EMIT(VideoEvent(IOP::NormalEvent));
  Q_EMIT(VideoEvent(IOP::CaptureEvent));
}
Ejemplo n.º 4
0
void mc_static_timer_handler()
{
    MC_LOG(IROS_LOG_LEVEL_DBG0, "mc tmr heartbeat\n");
    
    mc_node_fdb_age(g_mc_dev);
}