Ejemplo n.º 1
0
void CaptureDSCapture::stop()
{
    if (isCapturing()) {
      HRESULT hr = m_pDSCapture->Stop();
      mIsCapturing = false;
    }
}
void CaptureBlackMagic::stop()
{
    if (isCapturing()) {
    fprintf(stderr,"stop capture\n");
        camera->StopCapture();
        cvReleaseImage(&mReturnFrame);
    }
}
Ejemplo n.º 3
0
UINT MMCapture::run() {
  for(;;) {
    CaptureMessage message = m_messageQueue.get();
    switch(message) {
    case MESSAGE_STARTCAPTURE:
      m_receiver.log(_T("handle MESSAGE_STARTCAPTURE\n"));
      if(!isCapturing()) {
        m_stopPending = false;
        capCaptureSequenceNoFile(m_captureWindow);
      }
      break;

    case MESSAGE_STOPCAPTURE :
      m_receiver.log(_T("handle MESSAGE_STOPCAPTURE\n"));
      m_stopPending = true;
      break;

    case MESSAGE_CAPTURESTOPPED:
      m_receiver.log(_T("handle MESSAGE_CAPTURESTOPPED\n"));
      m_capturing = false;
      break;

    case MESSAGE_TERMINATE   :
      m_receiver.log(_T("handle MESSAGE_TERMINATE\n"));
      if(isCapturing()) {
        m_receiver.log(_T("isCapturing = true. stopPending...\n"));
        m_stopPending = true;
        for(;;) {
          if(m_messageQueue.get() == MESSAGE_CAPTURESTOPPED) {
            m_receiver.log(_T("got MESSAGE_CAPTURESTOPPED. Now stop loop\n"));
            m_capturing = false;
            break;
          }
        }
      }
      return 0;

    default:
      showError(_T("%s:Unknown message in messageQueue:%d"), __TFUNCTION__,message);
      exit(-1);
    }
  }
}
IplImage *CaptureBlackMagic::captureImage()
{
    if (!isCapturing()) {
        return NULL;
    }
    camera->readIplImage(mReturnFrame);

   /* if (mCamera->RetrieveBuffer(mImage) == FlyCapture2::PGRERROR_OK) {
        unsigned long length = mReturnFrame->widthStep * mYResolution;
        memcpy(mReturnFrame->imageData, mImage->GetData(), length);
    }*/
    return mReturnFrame;
}
Ejemplo n.º 5
0
void VideoInput::releaseBufferCb(uint8_t* ptr)
{
    std::lock_guard<std::mutex> lck(mutex_);

    for(auto &buffer : buffers_) {
        if (buffer.data == ptr) {
            buffer.status = BUFFER_AVAILABLE;
            if (!isCapturing())
                freeOneBuffer(buffer);
            break;
        }
    }
}
Ejemplo n.º 6
0
void KeyboardCallback(unsigned char key, int /*x*/, int /*y*/)
{
	if (isCapturing())
	{
		captureStop(0);
	}
	else
	{
		handleKey(key);
	}
    
	//glutPostRedisplay();
}
Ejemplo n.º 7
0
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;    
    } 
  }
}
Ejemplo n.º 8
0
IplImage *CaptureDSCapture::captureImage()
{
    if (!isCapturing()) {
        return NULL;
    }

    IplImage *ret = NULL;
    if (WaitForSingleObject(next_event, 1000) == WAIT_OBJECT_0) {
      EnterCriticalSection(&crit);
      ret = mReturnFrame;
      ret->origin = 1;
      memcpy(imgBuffer,imgBufferForCallback,buffer_size);
      LeaveCriticalSection(&crit);
    }
  return ret;
}
Ejemplo n.º 9
0
void CallbackPipeline::do_capture(JNIEnv *env) {
	ENTER();

	uvc_frame_t *frame;
	uvc_frame_t *temp = get_frame(default_frame_size);
	uvc_frame_t *callback_frame;
	uint32_t width = 0, height = 0;
	size_t sz = default_frame_size;

	if (LIKELY(temp)) {
		for (; isRunning() && isCapturing();) {
			frame = waitCaptureFrame();
			if ((LIKELY(frame))) {
				if (UNLIKELY((width != frame->width) || (height != frame->height))) {
					width = frame->width;
					height = frame->height;
					callbackPixelFormatChanged(width, height);
					uvc_ensure_frame_size(temp, callbackPixelBytes);
					sz = callbackPixelBytes;
				}
				if (mFrameCallbackObj) {
					callback_frame = frame;
					sz = frame->actual_bytes;
					if (mFrameCallbackFunc) {
						callback_frame = temp;
						sz = callbackPixelBytes;
						int b = mFrameCallbackFunc(frame, temp);
						if (UNLIKELY(b)) {
							LOGW("failed to convert to callback frame");
							goto SKIP;
						}
					}
					jobject buf = env->NewDirectByteBuffer(callback_frame->data, callbackPixelBytes);
					env->CallVoidMethod(mFrameCallbackObj, iframecallback_fields.onFrame, buf);
					env->ExceptionClear();
					env->DeleteLocalRef(buf);
				}
SKIP:
				recycle_frame(frame);
			}
		}
		recycle_frame(temp);
	}

	EXIT();
}
Ejemplo n.º 10
0
int UVCPreview::setFrameCallback(JNIEnv *env, jobject frame_callback_obj, int pixel_format) {
	
	ENTER();
	pthread_mutex_lock(&capture_mutex);
	{
		if (isRunning() && isCapturing()) {
			mIsCapturing = false;
			if (mFrameCallbackObj) {
				pthread_cond_signal(&capture_sync);
				pthread_cond_wait(&capture_sync, &capture_mutex);	// wait finishing capturing
			}
		}
		if (!env->IsSameObject(mFrameCallbackObj, frame_callback_obj))	{
			iframecallback_fields.onFrame = NULL;
			if (mFrameCallbackObj) {
				env->DeleteGlobalRef(mFrameCallbackObj);
			}
			mFrameCallbackObj = frame_callback_obj;
			if (frame_callback_obj) {
				// get method IDs of Java object for callback
				jclass clazz = env->GetObjectClass(frame_callback_obj);
				if (LIKELY(clazz)) {
					iframecallback_fields.onFrame = env->GetMethodID(clazz,
						"onFrame",	"(Ljava/nio/ByteBuffer;)V");
				} else {
					LOGW("failed to get object class");
				}
				env->ExceptionClear();
				if (!iframecallback_fields.onFrame) {
					LOGE("Can't find IFrameCallback#onFrame");
					env->DeleteGlobalRef(frame_callback_obj);
					mFrameCallbackObj = frame_callback_obj = NULL;
				}
			}
		}
		if (frame_callback_obj) {
			mPixelFormat = pixel_format;
			callbackPixelFormatChanged();
		}
	}
	pthread_mutex_unlock(&capture_mutex);
	RETURN(0, int);
}
Ejemplo n.º 11
0
void
VideoInput::releaseFrame(void *ptr)
{
    std::lock_guard<std::mutex> lck(mutex_);
    for(auto& buffer : buffers_) {
        if (buffer.data  == ptr) {
            if (buffer.status != BUFFER_CAPTURING)
                RING_ERR("Released a buffer with status %d, expected %d",
                         buffer.status, BUFFER_CAPTURING);
            if (isCapturing()) {
                buffer.status = BUFFER_FULL;
                buffer.index = capture_index_++;
                frame_cv_.notify_one();
            } else {
                freeOneBuffer(buffer);
            }
            break;
        }
    }
}
Ejemplo n.º 12
0
void QgsMapToolAddPart::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
{
  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = currentVectorLayer();
  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  bool isGeometryEmpty = false;
  QgsFeatureList selectedFeatures = vlayer->selectedFeatures();
  if ( !selectedFeatures.isEmpty() && selectedFeatures.at( 0 ).geometry().isNull() )
    isGeometryEmpty = true;

  if ( !checkSelection() )
  {
    stopCapturing();
    return;
  }

  int errorCode = 0;
  switch ( mode() )
  {
    case CapturePoint:
    {
      QgsPoint layerPoint;
      QgsPointXY mapPoint = e->mapPoint();

      if ( nextPoint( QgsPoint( mapPoint ), layerPoint ) != 0 )
      {
        QgsDebugMsg( "nextPoint failed" );
        return;
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      errorCode = vlayer->addPart( QgsPointSequence() << layerPoint );
    }
    break;

    case CaptureLine:
    case CapturePolygon:
    {
      //add point to list and to rubber band
      if ( e->button() == Qt::LeftButton )
      {
        int error = addVertex( e->mapPoint(), e->mapPointMatch() );
        if ( error == 1 )
        {
          QgsDebugMsg( "current layer is not a vector layer" );
          return;
        }
        else if ( error == 2 )
        {
          //problem with coordinate transformation
          emit messageEmitted( tr( "Coordinate transform error. Cannot transform the point to the layers coordinate system" ), Qgis::Warning );
          return;
        }

        startCapturing();
        return;
      }
      else if ( e->button() != Qt::RightButton )
      {
        deleteTempRubberBand();

        return;
      }

      if ( !isCapturing() )
        return;

      if ( mode() == CapturePolygon )
      {
        closePolygon();
      }

      //does compoundcurve contain circular strings?
      //does provider support circular strings?
      bool hasCurvedSegments = captureCurve()->hasCurvedSegments();
      bool providerSupportsCurvedSegments = vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::CircularGeometries;

      QgsCurve *curveToAdd = nullptr;
      if ( hasCurvedSegments && providerSupportsCurvedSegments )
      {
        curveToAdd = captureCurve()->clone();
      }
      else
      {
        curveToAdd = captureCurve()->curveToLine();
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      if ( mode() == CapturePolygon )
      {
        //avoid intersections
        QgsCurvePolygon *cp = new QgsCurvePolygon();
        cp->setExteriorRing( curveToAdd );
        QgsGeometry *geom = new QgsGeometry( cp );
        geom->avoidIntersections( QgsProject::instance()->avoidIntersectionsLayers() );

        const QgsCurvePolygon *cpGeom = qgsgeometry_cast<const QgsCurvePolygon *>( geom->constGet() );
        if ( !cpGeom )
        {
          stopCapturing();
          delete geom;
          vlayer->destroyEditCommand();
          return;
        }

        errorCode = vlayer->addPart( cpGeom->exteriorRing()->clone() );
        delete geom;
      }
      else
      {
        errorCode = vlayer->addPart( curveToAdd );
      }
      stopCapturing();
    }
    break;
    default:
      Q_ASSERT( !"invalid capture mode" );
      errorCode = 6;
      break;
  }

  QString errorMessage;
  switch ( errorCode )
  {
    case 0:
    {
      // remove previous message
      emit messageDiscarded();

      //add points to other features to keep topology up-to-date
      bool topologicalEditing = QgsProject::instance()->topologicalEditing();
      if ( topologicalEditing )
      {
        addTopologicalPoints( points() );
      }

      vlayer->endEditCommand();

      vlayer->triggerRepaint();

      if ( ( !isGeometryEmpty ) && QgsWkbTypes::isSingleType( vlayer->wkbType() ) )
      {
        emit messageEmitted( tr( "Add part: Feature geom is single part and you've added more than one" ), Qgis::Warning );
      }

      return;
    }

    case 1:
      errorMessage = tr( "Selected feature is not multi part." );
      break;

    case 2:
      errorMessage = tr( "New part's geometry is not valid." );
      break;

    case 3:
      errorMessage = tr( "New polygon ring not disjoint with existing polygons." );
      break;

    case 4:
      errorMessage = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
      break;

    case 5:
      errorMessage = tr( "Several features are selected. Please select only one feature to which an island should be added." );
      break;

    case 6:
      errorMessage = tr( "Selected geometry could not be found" );
      break;
  }

  emit messageEmitted( errorMessage, Qgis::Warning );
  vlayer->destroyEditCommand();
}
Ejemplo n.º 13
0
void MMCapture::saveAudioFrame(const WAVEHDR *audioHeader) {
  if(isCapturing()) {
    m_audioQueue.put(AudioQueueElement(audioHeader));
    m_audioSampleCount += audioHeader->dwBytesRecorded / m_audioFormat.wBitsPerSample * 8;
  }
}
Ejemplo n.º 14
0
void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
{
  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  //inform user at the begin of the digitising action that the island tool only works if exactly one feature is selected
  int nSelectedFeatures = vlayer->selectedFeatureCount();
  QString selectionErrorMsg;
  if ( nSelectedFeatures < 1 )
  {
    selectionErrorMsg = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
  }
  else if ( nSelectedFeatures > 1 )
  {
    selectionErrorMsg = tr( "Several features are selected. Please select only one feature to which an part should be added." );
  }

  if ( !selectionErrorMsg.isEmpty() )
  {
    emit messageEmitted( tr( "Could not add part. %1" ).arg( selectionErrorMsg ), QgsMessageBar::WARNING );
    stopCapturing();
    return;
  }

  int errorCode;
  switch ( mode() )
  {
    case CapturePoint:
    {
      QgsPoint layerPoint;
      QgsPoint mapPoint;

      if ( nextPoint( e->pos(), layerPoint, mapPoint ) != 0 )
      {
        QgsDebugMsg( "nextPoint failed" );
        return;
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      errorCode = vlayer->addPart( QList<QgsPoint>() << layerPoint );
    }
    break;

    case CaptureLine:
    case CapturePolygon:
    {
      //add point to list and to rubber band
      if ( e->button() == Qt::LeftButton )
      {
        int error = addVertex( e->pos() );
        if ( error == 1 )
        {
          QgsDebugMsg( "current layer is not a vector layer" );
          return;
        }
        else if ( error == 2 )
        {
          //problem with coordinate transformation
          emit messageEmitted( tr( "Coordinate transform error. Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
          return;
        }

        startCapturing();
        return;
      }
      else if ( e->button() != Qt::RightButton )
      {
        deleteTempRubberBand();

        return;
      }

      if ( !isCapturing() )
        return;

      // we are now going to finish the capturing

      if ( mode() == CapturePolygon )
      {
        //close polygon
        closePolygon();
        //avoid intersections
        QgsGeometry* geom = QgsGeometry::fromPolygon( QgsPolygon() << points().toVector() );
        if ( geom )
        {
          geom->avoidIntersections();
          QgsPolygon poly = geom->asPolygon();
          if ( poly.size() < 1 )
          {
            stopCapturing();
            delete geom;
            vlayer->destroyEditCommand();
            return;
          }
          setPoints( geom->asPolygon()[0].toList() );
          delete geom;
        }
      }

      vlayer->beginEditCommand( tr( "Part added" ) );
      errorCode = vlayer->addPart( points() );

      stopCapturing();
    }
    break;
    default:
      Q_ASSERT( !"invalid capture mode" );
      errorCode = 6;
      break;
  }

  QString errorMessage;
  switch ( errorCode )
  {
    case 0:
    {
      // remove previous message
      emit messageDiscarded();

      //add points to other features to keep topology up-to-date
      int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
      if ( topologicalEditing )
      {
        addTopologicalPoints( points() );
      }

      vlayer->endEditCommand();

      mCanvas->refresh();
      return;
    }

    case 1:
      errorMessage = tr( "Selected feature is not multi part." );
      break;

    case 2:
      errorMessage = tr( "New part's geometry is not valid." );
      break;

    case 3:
      errorMessage = tr( "New polygon ring not disjoint with existing polygons." );
      break;

    case 4:
      errorMessage = tr( "No feature selected. Please select a feature with the selection tool or in the attribute table" );
      break;

    case 5:
      errorMessage = tr( "Several features are selected. Please select only one feature to which an island should be added." );
      break;

    case 6:
      errorMessage = tr( "Selected geometry could not be found" );
      break;
  }

  emit messageEmitted( errorMessage, QgsMessageBar::WARNING );
  vlayer->destroyEditCommand();
}
Ejemplo n.º 15
0
void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
{
  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );

  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  //add point to list and to rubber band
  if ( e->button() == Qt::LeftButton )
  {
    int error = addVertex( e->mapPoint() );
    if ( error == 1 )
    {
      //current layer is not a vector layer
      return;
    }
    else if ( error == 2 )
    {
      //problem with coordinate transformation
      emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
      return;
    }

    startCapturing();
  }
  else if ( e->button() == Qt::RightButton )
  {
    if ( !isCapturing() )
      return;

    deleteTempRubberBand();

    closePolygon();

    vlayer->beginEditCommand( tr( "Ring added and filled" ) );
    QList< QgsPoint > pointList = points();

    QgsFeatureId modifiedFid;
    int addRingReturnCode = vlayer->addRing( pointList, &modifiedFid );
    if ( addRingReturnCode != 0 )
    {
      QString errorMessage;
      //todo: open message box to communicate errors
      if ( addRingReturnCode == 1 )
      {
        errorMessage = tr( "a problem with geometry type occured" );
      }
      else if ( addRingReturnCode == 2 )
      {
        errorMessage = tr( "the inserted Ring is not closed" );
      }
      else if ( addRingReturnCode == 3 )
      {
        errorMessage = tr( "the inserted Ring is not a valid geometry" );
      }
      else if ( addRingReturnCode == 4 )
      {
        errorMessage = tr( "the inserted Ring crosses existing rings" );
      }
      else if ( addRingReturnCode == 5 )
      {
        errorMessage = tr( "the inserted Ring is not contained in a feature" );
      }
      else
      {
        errorMessage = tr( "an unknown error occured" );
      }
      emit messageEmitted( tr( "could not add ring since %1." ).arg( errorMessage ), QgsMessageBar::CRITICAL );
      vlayer->destroyEditCommand();
    }
    else
    {
      // find parent feature and get it attributes
      double xMin, xMax, yMin, yMax;
      QgsRectangle bBox;

      xMin = std::numeric_limits<double>::max();
      xMax = -std::numeric_limits<double>::max();
      yMin = std::numeric_limits<double>::max();
      yMax = -std::numeric_limits<double>::max();

      Q_FOREACH ( const QgsPoint& point, pointList )
      {
        xMin = qMin( xMin, point.x() );
        xMax = qMax( xMax, point.x() );
        yMin = qMin( yMin, point.y() );
        yMax = qMax( yMax, point.y() );
      }

      bBox.setXMinimum( xMin );
      bBox.setYMinimum( yMin );
      bBox.setXMaximum( xMax );
      bBox.setYMaximum( yMax );

      QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterFid( modifiedFid ) );

      QgsFeature f;
      bool res = false;
      if ( fit.nextFeature( f ) )
      {
        //create QgsFeature with wkb representation
        QgsFeature* ft = new QgsFeature( vlayer->fields(), 0 );

        ft->setGeometry( QgsGeometry::fromPolygon( QgsPolygon() << pointList.toVector() ) );
        ft->setAttributes( f.attributes() );

        if ( QApplication::keyboardModifiers() == Qt::ControlModifier )
        {
          res = vlayer->addFeature( *ft );
        }
        else
        {
          QgsAttributeDialog *dialog = new QgsAttributeDialog( vlayer, ft, false, NULL, true );
          dialog->setIsAddDialog( true );
          res = dialog->exec(); // will also add the feature
        }

        if ( res )
        {
          vlayer->endEditCommand();
        }
        else
        {
          delete ft;
          vlayer->destroyEditCommand();
        }
        res = false;
      }
    }
    stopCapturing();
  }
Ejemplo n.º 16
0
void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )
{

  emit messageDiscarded();

  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );

  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  //add point to list and to rubber band
  if ( e->button() == Qt::LeftButton )
  {
    int error = addVertex( e->pos() );
    if ( error == 1 )
    {
      //current layer is not a vector layer
      return;
    }
    else if ( error == 2 )
    {
      //problem with coordinate transformation
      emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
      return;
    }

    startCapturing();
  }
  else if ( e->button() == Qt::RightButton )
  {
    if ( !isCapturing() )
      return;

    deleteTempRubberBand();

    closePolygon();

    vlayer->beginEditCommand( tr( "Ring added" ) );
    int addRingReturnCode = vlayer->addRing( points() );
    if ( addRingReturnCode != 0 )
    {
      QString errorMessage;
      //todo: open message box to communicate errors
      if ( addRingReturnCode == 1 )
      {
        errorMessage = tr( "a problem with geometry type occured" );
      }
      else if ( addRingReturnCode == 2 )
      {
        errorMessage = tr( "the inserted ring is not closed" );
      }
      else if ( addRingReturnCode == 3 )
      {
        errorMessage = tr( "the inserted ring is not a valid geometry" );
      }
      else if ( addRingReturnCode == 4 )
      {
        errorMessage = tr( "the inserted ring crosses existing rings" );
      }
      else if ( addRingReturnCode == 5 )
      {
        errorMessage = tr( "the inserted ring is not contained in a feature" );
      }
      else
      {
        errorMessage = tr( "an unknown error occured" );
      }
      emit messageEmitted( tr( "could not add ring since %1." ).arg( errorMessage ), QgsMessageBar::CRITICAL );
      vlayer->destroyEditCommand();
    }
    else
    {
      vlayer->endEditCommand();
    }

    stopCapturing();
  }
}
bool CaptureBlackMagic::start()
{
    HRESULT						result;
    if (isCapturing()) {
        return isCapturing();
    }
    { /// CONNECTING TO ONE CAMERA AND START THE STREAM
        /* Connect to the first DeckLink instance */
        result = deckLinkIterator->Next(&deckLink);
        if (result != S_OK)
        {
            fprintf(stderr, "No DeckLink PCI cards found.\n");
        }

        camera->initializeCamera(deckLink);
    }

   /* stringstream id(captureDevice().id());
    id.setf(ios_base::hex, ios_base::basefield);
    id >> mGUID.value[0]; id.get();
    id >> mGUID.value[1]; id.get();
    id >> mGUID.value[2]; id.get();
    id >> mGUID.value[3];

    if (mCamera->Connect(&mGUID) != FlyCapture2::PGRERROR_OK) {
        return false;
    }

    FlyCapture2::VideoMode videoMode;
    FlyCapture2::FrameRate frameRate;
    if (mCamera->GetVideoModeAndFrameRate (&videoMode, &frameRate) != FlyCapture2::PGRERROR_OK) {
        return false;
    }
    
    if (videoMode == FlyCapture2::VIDEOMODE_640x480RGB) {
      mChannels = 3;
      mXResolution = 640;
      mYResolution = 480;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_640x480Y8) {
      mChannels = 1;
      mXResolution = 640;
      mYResolution = 480;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_800x600RGB) {
      mChannels = 3;
      mXResolution = 800;
      mYResolution = 600;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_800x600Y8) {
      mChannels = 1;
      mXResolution = 800;
      mYResolution = 600;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_1024x768RGB) {
      mChannels = 3;
      mXResolution = 1024;
      mYResolution = 768;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_1024x768Y8) {
      mChannels = 1;
      mXResolution = 1024;
      mYResolution = 768;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_1280x960RGB) {
      mChannels = 3;
      mXResolution = 1280;
      mYResolution = 960;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_1280x960Y8) {
      mChannels = 1;
      mXResolution = 1280;
      mYResolution = 960;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_1600x1200RGB) {
      mChannels = 3;
      mXResolution = 1600;
      mYResolution = 1200;
    
    } else if (videoMode == FlyCapture2::VIDEOMODE_1600x1200Y8) {
      mChannels = 1;
      mXResolution = 1600;
      mYResolution = 1200;
    
    } else {
        return false;
    }
    if (mCamera->StartCapture() != FlyCapture2::PGRERROR_OK) {
        return false;
    }
    */
      mChannels = 3;
      mXResolution = 1920;
      mYResolution = 1080;
    fprintf(stderr,"cvCreateImage(cvSize(mXResolution, mYResolution), IPL_DEPTH_8U, mChannels); %d %d \n",mXResolution, mYResolution);
    mReturnFrame = cvCreateImage(cvSize(mXResolution, mYResolution), IPL_DEPTH_8U, mChannels);
    mIsCapturing = true;
    return isCapturing();
}
Ejemplo n.º 18
0
void QgsMapToolAddRing::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
{

  emit messageDiscarded();

  //check if we operate on a vector layer
  QgsVectorLayer *vlayer = currentVectorLayer();

  if ( !vlayer )
  {
    notifyNotVectorLayer();
    return;
  }

  if ( !vlayer->isEditable() )
  {
    notifyNotEditableLayer();
    return;
  }

  //add point to list and to rubber band
  if ( e->button() == Qt::LeftButton )
  {
    int error = addVertex( e->mapPoint() );
    if ( error == 1 )
    {
      //current layer is not a vector layer
      return;
    }
    else if ( error == 2 )
    {
      //problem with coordinate transformation
      emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
      return;
    }

    startCapturing();
  }
  else if ( e->button() == Qt::RightButton )
  {
    if ( !isCapturing() )
      return;

    deleteTempRubberBand();

    closePolygon();

    vlayer->beginEditCommand( tr( "Ring added" ) );

    //does compoundcurve contain circular strings?
    //does provider support circular strings?
    bool hasCurvedSegments = captureCurve()->hasCurvedSegments();
    bool providerSupportsCurvedSegments = vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::CircularGeometries;

    QgsCurveV2* curveToAdd = 0;
    if ( hasCurvedSegments && providerSupportsCurvedSegments )
    {
      curveToAdd = dynamic_cast<QgsCurveV2*>( captureCurve()->clone() );
    }
    else
    {
      curveToAdd = captureCurve()->curveToLine();
    }

    int addRingReturnCode = vlayer->addRing( curveToAdd );
    if ( addRingReturnCode != 0 )
    {
      QString errorMessage;
      //todo: open message box to communicate errors
      if ( addRingReturnCode == 1 )
      {
        errorMessage = tr( "a problem with geometry type occured" );
      }
      else if ( addRingReturnCode == 2 )
      {
        errorMessage = tr( "the inserted ring is not closed" );
      }
      else if ( addRingReturnCode == 3 )
      {
        errorMessage = tr( "the inserted ring is not a valid geometry" );
      }
      else if ( addRingReturnCode == 4 )
      {
        errorMessage = tr( "the inserted ring crosses existing rings" );
      }
      else if ( addRingReturnCode == 5 )
      {
        errorMessage = tr( "the inserted ring is not contained in a feature" );
      }
      else
      {
        errorMessage = tr( "an unknown error occured" );
      }
      emit messageEmitted( tr( "could not add ring since %1." ).arg( errorMessage ), QgsMessageBar::CRITICAL );
      vlayer->destroyEditCommand();
    }
    else
    {
      vlayer->endEditCommand();
    }

    stopCapturing();
  }
}
Ejemplo n.º 19
0
bool Private_Impl::grab() {
    if ( !isCapturing() ) return false;
    callback_data.waitForFrame();
    return true;
}