void RawMultiTestApp::setup()
{

	setFrameRate(60);
	setWindowSize(1280, 480);

	PGRGuid	guid;

	//////////////////
	// setup camera 1
	mErr = mBusManager.GetCameraFromIndex(0, &guid);
    if (mErr != PGRERROR_OK) {
		showError();
		quit();
	}

	mCamera1 = new FlyCapture2::Camera();
	mErr = mCamera1->Connect(&guid);
    if (mErr != PGRERROR_OK) {
		showError();
		mCamera1 = 0;
		quit();
	}

	mCam1Data.targetSurface = Surface8u(640, 480, false);
	mErr = mCamera1->StartCapture(onImageGrabbed, &mCam1Data);
    if (mErr != PGRERROR_OK) {
		showError();
		quit();
	}

	//////////////////
	// setup camera 2
	mErr = mBusManager.GetCameraFromIndex(1, &guid);
    if (mErr != PGRERROR_OK) {
		showError();
		quit();
	}

	mCamera2 = new FlyCapture2::Camera();
	mErr = mCamera2->Connect(&guid);
    if (mErr != PGRERROR_OK) {
		showError();
		mCamera2 = 0;
		quit();
	}

	mCam2Data.targetSurface = Surface8u(640, 480, false);
	mErr = mCamera2->StartCapture(onImageGrabbed, &mCam2Data);
    if (mErr != PGRERROR_OK) {
		showError();
		quit();
	}

}
void CCflycap_set_num_framebuffers( CCflycap *ccntxt,
				    int num_framebuffers ) {
  CHECK_CC(ccntxt);
  FlyCapture2::Camera *cam = (FlyCapture2::Camera *)ccntxt->inherited.cam;
  FlyCapture2::FC2Config cfg;
  CIPGRCHK(cam->StopCapture());
  CIPGRCHK(cam->GetConfiguration(&cfg));
  cfg.numBuffers = num_framebuffers;
  CIPGRCHK(cam->SetConfiguration(&cfg));
  CIPGRCHK(cam->StartCapture());
}
int init_cam_capture ( FlyCapture2::Camera &camera, PGRGuid guid)  
{
  CameraInfo camInfo;

  // Connect the camera
    err = camera.Connect( &guid );
    if ( err != PGRERROR_OK )
    {
        std::cout << "Failed to connect to camera" << std::endl;     
        return false;
    }
    
    // Get the camera info and print it out
    err = camera.GetCameraInfo( &camInfo );
    if ( err != PGRERROR_OK )
    {
        std::cout << "Failed to get camera info from camera" << std::endl;     
        return false;
    }
    std::cout << camInfo.vendorName << " "
          << camInfo.modelName << " " 
          << camInfo.serialNumber << std::endl;
  
    err = camera.StartCapture();
    if ( err == PGRERROR_ISOCH_BANDWIDTH_EXCEEDED )
    {
        std::cout << "Bandwidth exceeded" << std::endl;     
        return false;
    }
    else if ( err != PGRERROR_OK )
    {
        std::cout << "Failed to start image capture" << std::endl;     
        return false;
    } 

}
void CCflycap_start_camera( CCflycap *ccntxt ) {
  CHECK_CC(ccntxt);
  FlyCapture2::Camera *cam = (FlyCapture2::Camera *)ccntxt->inherited.cam;
  CIPGRCHK(cam->StartCapture());
}
void CCflycap_CCflycap( CCflycap * ccntxt, int device_number, int NumImageBuffers,
                        int mode_number) {

  // call parent
  CamContext_CamContext((CamContext*)ccntxt,device_number,NumImageBuffers,mode_number); // XXX cast error?
  ccntxt->inherited.vmt = (CamContext_functable*)&CCflycap_vmt;

  CAM_IFACE_CHECK_DEVICE_NUMBER(device_number);
  std::vector<CamMode> result;
  int myerr = get_mode_list(device_number, result);

  ccntxt->inherited.device_number = device_number;
  ccntxt->inherited.backend_extras = new cam_iface_backend_extras;
  memset(ccntxt->inherited.backend_extras,0,sizeof(cam_iface_backend_extras));

  FlyCapture2::Camera *cam = new FlyCapture2::Camera;
  FlyCapture2::PGRGuid guid;
  CIPGRCHK( BACKEND_GLOBAL(busMgr_ptr)->GetCameraFromIndex(device_number, &guid));
  CIPGRCHK(cam->Connect(&guid));

  FlyCapture2::FC2Config cfg;
  CIPGRCHK(cam->GetConfiguration(&cfg));
  cfg.numBuffers = NumImageBuffers;
  CIPGRCHK(cam->SetConfiguration(&cfg));

  // Set the settings to the camera
  CamMode target_mode = result[mode_number];

  if (target_mode.videomode == FlyCapture2::VIDEOMODE_FORMAT7) {
    CIPGRCHK(cam->SetFormat7Configuration(&target_mode.fmt7ImageSettings,
					  target_mode.fmt7PacketInfo.recommendedBytesPerPacket ));
  } else {
    CIPGRCHK(cam->SetVideoModeAndFrameRate(target_mode.videomode, target_mode.framerate));
  }

  ccntxt->inherited.cam = (void*)cam;

  // XXX move this to start camera and query camera for settings

  CIPGRCHK(cam->StartCapture());


  // Retrieve an image to get width, height. XXX change to query later.
  FlyCapture2::Image rawImage;
  CIPGRCHK( cam->RetrieveBuffer( &rawImage ));

  cam_iface_backend_extras *extras = (cam_iface_backend_extras *)ccntxt->inherited.backend_extras;

  ccntxt->inherited.depth = rawImage.GetBitsPerPixel();
  extras->buf_size = rawImage.GetDataSize();
  extras->current_height = rawImage.GetRows();
  extras->current_width = rawImage.GetCols();
  extras->max_height = rawImage.GetRows();
  extras->max_width = rawImage.GetCols();
  CIPGRCHK( cam->GetTriggerModeInfo( &extras->trigger_mode_info ));

  switch (rawImage.GetPixelFormat()) {
  case FlyCapture2::PIXEL_FORMAT_MONO8:
    ccntxt->inherited.coding = CAM_IFACE_MONO8;
    if (rawImage.GetBayerTileFormat()!=FlyCapture2::NONE) {
      NOT_IMPLEMENTED;
    }
    break;
  case FlyCapture2::PIXEL_FORMAT_RAW8:
    switch (rawImage.GetBayerTileFormat()) {
    case FlyCapture2::NONE:
      ccntxt->inherited.coding = CAM_IFACE_RAW8;
      break;
    case FlyCapture2::RGGB:
      ccntxt->inherited.coding = CAM_IFACE_MONO8_BAYER_RGGB;
      break;
    case FlyCapture2::GRBG:
      ccntxt->inherited.coding = CAM_IFACE_MONO8_BAYER_GRBG;
      break;
    case FlyCapture2::GBRG:
      ccntxt->inherited.coding = CAM_IFACE_MONO8_BAYER_GBRG;
      break;
    case FlyCapture2::BGGR:
      ccntxt->inherited.coding = CAM_IFACE_MONO8_BAYER_BGGR;
      break;
    default:
      NOT_IMPLEMENTED;
    }
  }
  CIPGRCHK(cam->StopCapture());

}
Exemple #6
0
int main()
{
    FlyCapture2::Error error;
    FlyCapture2::PGRGuid guid;
    FlyCapture2::BusManager busMgr;
    FlyCapture2::Camera cam;
    FlyCapture2::VideoMode vm;
    FlyCapture2::FrameRate fr;
    FlyCapture2::Image rawImage;

    //Initializing camera
        error = busMgr.GetCameraFromIndex(0, &guid);
    if (error != FlyCapture2::PGRERROR_OK)
    {
        error.PrintErrorTrace();
        return CAM_FAILURE;
    }

          vm = FlyCapture2::VIDEOMODE_640x480Y8;
    fr = FlyCapture2::FRAMERATE_60;

    error = cam.Connect(&guid);
    if (error != FlyCapture2::PGRERROR_OK)
    {
        error.PrintErrorTrace();
        return CAM_FAILURE;
    }

    cam.SetVideoModeAndFrameRate(vm, fr);
    //Starting the capture
    error = cam.StartCapture();
    if (error != FlyCapture2::PGRERROR_OK)
    {
        error.PrintErrorTrace();
               return CAM_FAILURE;
    }

    while(1)
    {
        Mat frame (Size(640,480),CV_8UC1);
        // Mat img_scene (Size(640,480),CV_8UC3);
        Mat img_object = imread( "bitslogo.png", CV_LOAD_IMAGE_GRAYSCALE );
        cam.RetrieveBuffer(&rawImage);
        memcpy(frame.data, rawImage.GetData(), rawImage.GetDataSize());
        cvtColor(frame,frame,CV_BayerBG2RGB);
        imwrite("temp.bmp",frame);
        // cvtColor(img_scene,img_scene,CV_RGB2GRAY);
        Mat img_scene = imread( "temp.bmp", CV_LOAD_IMAGE_GRAYSCALE );

        if( !img_object.data || !img_scene.data )
        { std::cout<< " --(!) Error reading images " << std::endl; return -1; }

        //-- Step 1: Detect the keypoints using SURF Detector
        int minHessian = 400;

        SurfFeatureDetector detector( minHessian );

        std::vector<KeyPoint> keypoints_object, keypoints_scene;

        detector.detect( img_object, keypoints_object );
        detector.detect( img_scene, keypoints_scene );

        //-- Step 2: Calculate descriptors (feature vectors)
        SurfDescriptorExtractor extractor;

        Mat descriptors_object, descriptors_scene;

        extractor.compute( img_object, keypoints_object, descriptors_object );
        extractor.compute( img_scene, keypoints_scene, descriptors_scene );

        //-- Step 3: Matching descriptor vectors using FLANN matcher
        FlannBasedMatcher matcher;
        std::vector< DMatch > matches;
        matcher.match( descriptors_object, descriptors_scene, matches );

        double max_dist = 0; double min_dist = 100;

        //-- Quick calculation of max and min distances between keypoints
        for( int i = 0; i < descriptors_object.rows; i++ )
        { double dist = matches[i].distance;
          if( dist < min_dist ) min_dist = dist;
          if( dist > max_dist ) max_dist = dist;
        }

        printf("-- Max dist : %f \n", max_dist );
        printf("-- Min dist : %f \n", min_dist );

        //-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
        std::vector< DMatch > good_matches;

        for( int i = 0; i < descriptors_object.rows; i++ )
        { if( matches[i].distance < 3*min_dist )
           { good_matches.push_back( matches[i]); }
        }

        Mat img_matches;
        drawMatches( img_object, keypoints_object, img_scene, keypoints_scene,
                     good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
                     vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

        //-- Localize the object
        std::vector<Point2f> obj;
        std::vector<Point2f> scene;

        for( int i = 0; i < good_matches.size(); i++ )
        {
          //-- Get the keypoints from the good matches
          obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );
          scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );
        }

        Mat H = findHomography( obj, scene, CV_RANSAC );

        //-- Get the corners from the image_1 ( the object to be "detected" )
        std::vector<Point2f> obj_corners(4);
        obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( img_object.cols, 0 );
        obj_corners[2] = cvPoint( img_object.cols, img_object.rows ); obj_corners[3] = cvPoint( 0, img_object.rows );
        std::vector<Point2f> scene_corners(4);

        perspectiveTransform( obj_corners, scene_corners, H);

        //-- Draw lines between the corners (the mapped object in the scene - image_2 )
        line( img_matches, scene_corners[0] + Point2f( img_object.cols, 0), scene_corners[1] + Point2f( img_object.cols, 0), Scalar(0, 255, 0), 4 );
        line( img_matches, scene_corners[1] + Point2f( img_object.cols, 0), scene_corners[2] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
        line( img_matches, scene_corners[2] + Point2f( img_object.cols, 0), scene_corners[3] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );
        line( img_matches, scene_corners[3] + Point2f( img_object.cols, 0), scene_corners[0] + Point2f( img_object.cols, 0), Scalar( 0, 255, 0), 4 );

        //-- Show detected matches
        imshow( "Good Matches & Object detection", img_matches );
        int c = cvWaitKey(100);
        if(c == 27)
            break;
    }

    return 0;
}
Exemple #7
0
int main()
{
    FlyCapture2::Error error;
    FlyCapture2::PGRGuid guid;
    FlyCapture2::BusManager busMgr;
    FlyCapture2::Camera cam;
    FlyCapture2::VideoMode vm;
    FlyCapture2::FrameRate fr;
    FlyCapture2::Image rawImage;

    //Initializing camera
        error = busMgr.GetCameraFromIndex(0, &guid);
    if (error != FlyCapture2::PGRERROR_OK)
    {
        error.PrintErrorTrace();
        return CAM_FAILURE;
    }

          vm = FlyCapture2::VIDEOMODE_640x480Y8;
    fr = FlyCapture2::FRAMERATE_60;

    error = cam.Connect(&guid);
    if (error != FlyCapture2::PGRERROR_OK)
    {
        error.PrintErrorTrace();
        return CAM_FAILURE;
    }

    cam.SetVideoModeAndFrameRate(vm, fr);
    //Starting the capture
    error = cam.StartCapture();
    if (error != FlyCapture2::PGRERROR_OK)
    {
        error.PrintErrorTrace();
               return CAM_FAILURE;
    }

        //Image Variables
        Mat frame (Size(640,480),CV_8UC1);
        Mat img_bgr (Size(640,480),CV_8UC3);
        Mat img_hsv (Size(640,480),CV_8UC3);                        //Image in HSV color space
        Mat threshy (Size(640,480),CV_8UC1);                                //Threshed Image
        // Mat labelImg (Size(640,480),CV_8UC1);        //Image Variable for blobs
        IplImage* histogram= cvCreateImage(cvSize(640,480),8,3);                        //Image histograms
        Mat histograms (Size(640,480),CV_8UC1);         //greyscale image for histogram
        Mat empty (Size(640,480),CV_8UC3);        

        

        // CvBlobs blobs;
        
        while(1)
        {
                cam.RetrieveBuffer(&rawImage);
                memcpy(frame.data, rawImage.GetData(), rawImage.GetDataSize());
                // histogram = empty.clone();
                cvZero(histogram);
                // cvAddS(frame, cvScalar(70,70,70), frame);
                cvtColor(frame,img_bgr,CV_BayerBG2BGR);
                // cout<<"\n1";
                cvtColor(img_bgr,img_hsv,CV_BGR2HSV);        
                // cout<<"\n2";                                        
                //Thresholding the frame for yellow
                inRange(img_hsv, Scalar(20, 100, 20), Scalar(70, 255, 255), threshy);                                        
                // cvInRangeS(img_hsv, cvScalar(0, 120, 100), cvScalar(255, 255, 255), threshy);
                //Filtering the frame - subsampling??
                // smooth(threshy,threshy,CV_MEDIAN,7,7);

                //Finding the blobs
                // unsigned int result=cvLabel(threshy,labelImg,blobs);
                //Filtering the blobs
                // cvFilterByArea(blobs,500,1000);
                //Rendering the blobs
                // cvRenderBlobs(labelImg,blobs,img_bgr,img_bgr);

                CvPoint prev = cvPoint(0,0);

                for(int x=0;x<640;++x)
                {
                        Mat col = threshy.col(x);
                        int y = 480 - countNonZero(col);
                        for(int i=0 ; i<480 ; ++i)
                             histograms.at<uchar>(x,i) = y;
                        CvPoint next = cvPoint(x,y);
                        cvLine(histogram,prev,next,cColor);
                        // cvCircle(histogram,next,2,cColor,3);
                        prev=next;
                }

                //Showing the images
                imshow("Live",img_bgr);
                imshow("Threshed",threshy);
                cvShowImage("Histogram",histogram);

                int c= cvWaitKey(10);

                if(c == 27)
                        break;
        }

        //Cleanup
        // cvReleaseImage(&frame);
        // cvReleaseImage(&threshy);
        // cvReleaseImage(&img_hsv);
        // cvReleaseImage(&labelImg);
        // cvReleaseImage(&histogram);
        cvDestroyAllWindows();
        return 0;
}