int VideoSaverFlyCapture::startCapture() {

  if (!isFlyCapture()) {
    return VideoSaver::startCapture();
    
  } else {

  
    if ((isFinished()) && (isInit()) && (!isCapturing())) {
      // start thread to begin capture and populate Mat frame
      FlyCapture2::Error error = m_Camera.StartCapture();
      if ( error == FlyCapture2::PGRERROR_ISOCH_BANDWIDTH_EXCEEDED )
      {
	std::cout << "Bandwidth exceeded" << std::endl;     
	return -1;
      }
      else if ( error != FlyCapture2::PGRERROR_OK )
      {
	std::cout << "Failed to start image capture" << std::endl;     
	return -1;
      } 
    
    
      //start the grabbing thread
      m_KeepWritingAlive = false;  // not to be started
      m_WritingFinished = true;
      m_newFrameAvailable = false;
      std::cout <<  "Start video grabbing .." << std::endl;

      m_captureThread = new std::thread(&VideoSaverFlyCapture::captureThread,this);

      m_capturing = true;

      sleep(500);
      waitForNewFrame();

      return 0;

    } else {
      if (isInit()) {
	std::cout << "Warning: capture not yet finished !" << std::endl;    
      } else {
	std::cout << "Warning: camera not available!" << std::endl;    
      }
      return -1;    
    } 
  }
}
void MSRDailyColorInstance::nextFrame(QHashDataFrames &output)
{
    Q_ASSERT(output.size() > 0);
    shared_ptr<ColorFrame> colorFrame = static_pointer_cast<ColorFrame>(output.value(DataFrame::Color));

    // Wait for new frame
    waitForNewFrame();

    // Read this frame
    QMutexLocker locker(&m_lockFrame);

    if (m_readFrame->isValid()) {
        m_readFrame->map(QAbstractVideoBuffer::ReadOnly);
        if (m_readFrame->isMapped()) {
            memcpy( (void*) colorFrame->getDataPtr(), m_readFrame->bits(), m_readFrame->mappedBytes());
            m_readFrame->unmap();
        }
    }
}
bool SyncMultiFrameListener::waitForNewFrame(FrameMap &frame, int milliseconds)
{
#ifdef LIBFREENECT2_THREADING_STDLIB
  libfreenect2::unique_lock l(impl_->mutex_);

  auto predicate = std::bind(&SyncMultiFrameListenerImpl::hasNewFrame, impl_);

  if(impl_->condition_.wait_for(l, std::chrono::milliseconds(milliseconds), predicate))
  {
    frame = impl_->next_frame_;
    impl_->next_frame_.clear();
    impl_->ready_frame_types_ = 0;

    return true;
  }
  else
  {
    return false;
  }
#else
  waitForNewFrame(frame);
  return true;
#endif // LIBFREENECT2_THREADING_STDLIB
}
Exemple #4
0
int main (void)
{
  SP=0xffff;


  uint16_t shipX =150;

  tile_a_x=1;
  tile_b_x=5;

  setMap();


  uint8_t lastTime = 5;
  uint8_t mode = 0x74;

    tileMap[100]=0x0001;


    for (;;)  {
      waitForNewFrame();
      //read the mouse location
      uint16_t mouse_x=PORT_MOUSEX;
      uint16_t mouse_y=PORT_MOUSEY;

      uint16_t tile_x = mouse_x / 8;
      uint16_t tile_y = mouse_y / 8;

      uint16_t mtile = tile_y*32+tile_x;

      uint8_t ch = PORT_CONSOLE;
      switch (ch) {
        case 'a':
            translateTilePalette(-1,0);
          break;
        case 'd':
            translateTilePalette(1,0);
          break;
        case 'w':
            translateTilePalette(0,-1);
          break;
        case 's':
           translateTilePalette(0,1);
          break;
        case 'z':
          tileMap[mtile]= (tileMap[mtile] & 0xf0ff) | ((tileMap[mtile] - 0x0100)  & 0x0f00);
          break;
        case 'x':
          tileMap[mtile]= (tileMap[mtile] & 0xf0ff) | ((tileMap[mtile] + 0x0100)  & 0x0f00) ;
      }
      if (ch=='z') {
      }
      if (ch=='x') {

      }


      uint8_t now = PORT_TIME;
      uint8_t nextStep = now>lastTime;
      lastTime=now;

      if (nextStep) {
        mode+=1;
        if (mode > 0x74) mode=0x71;
      }

      renderMode1(tileset,tileMap,tileset_palettes,32*2,0,0);

      blitTilePalette();
      //write a grid of rectangles showing the serial pixel output palette
      for (uint16_t ty=0;ty <4; ty++) {
        for (uint16_t tx=0;tx <4; tx++) {
          serial_fillRect(200+tx*6,20+ty*6,5,5,(ty<<2)+tx);
        }
      }

      uint16_t buttons = PORT_BUTTONS;
      for (uint16_t b=0;b <16; b++) {
          serial_fillRect(100+b*6,30,5,5,(buttons & (1<<b))?2:1);
      }
      
      if (buttons & 0x2000) {
		  int16_t tile = screen_to_palette_tile(mouse_x,mouse_y);
		  if (tile != -1) {
			  tile_a_x=tile >>8;
			  tile_a_y=tile &0xff;
		  } 
	  }