Example #1
0
int main(int argc, char *argv[]) {
  DriverCreator *fake_factory = 
    new DriverCreatorOf<FakeFrameGrabber>("fake_grabber","grabber","FakeFrameGrabber");
  Drivers::factory().add(fake_factory); // hand factory over to YARP

  PolyDriver dd("fake_grabber");
  if (!dd.isValid()) {
    printf("fake_grabber not available\n");
    return 1;
  }
  IFrameGrabberImage *grabber;
  dd.view(grabber);
  if (grabber==NULL) {
    printf("*** Device failed to supply images\n");
    return 1;
  }
  printf("*** Device can supply images\n");
  ImageOf<PixelRgb> img;
  if (grabber->getImage(img)) {
    printf("*** Got a %dx%d image\n", img.width(), img.height());
  } else {
    printf("Failed to read an image\n");
    return 1;
  }
  return 0;
}
Example #2
0
bool DevicePipe::updateService() {
    IFrameGrabberImage *imgSource;
    IAudioGrabberSound *sndSource;
    IAudioVisualGrabber *imgSndSource;
    IAudioVisualStream *sourceType;

    IAudioRender *sndSink;
    IFrameWriterImage *imgSink;
    IFrameWriterAudioVisual *imgSndSink;
    IAudioVisualStream *sinkType;

    source.view(imgSource);
    source.view(sndSource);
    source.view(imgSndSource);
    source.view(sourceType);

    sink.view(imgSink);
    sink.view(sndSink);
    sink.view(imgSndSink);
    sink.view(sinkType);

    if (sourceType!=NULL) {
        if (!(sourceType->hasAudio()&&sourceType->hasVideo())) {
            imgSndSource = NULL;
        }
    }
    if (sinkType!=NULL) {
        if (!(sinkType->hasAudio()&&sinkType->hasVideo())) {
            imgSndSink = NULL;
        }
    }


    if (imgSndSource!=NULL&&imgSndSink!=NULL) {
        ImageOf<PixelRgb> tmp;
        Sound tmpSound;
        imgSndSource->getAudioVisual(tmp,tmpSound);
        imgSndSink->putAudioVisual(tmp,tmpSound);
        printf("piped %dx%d image, %dx%d sound\n",
               tmp.width(), tmp.height(),
               tmpSound.getSamples(), tmpSound.getChannels());
    } else if (imgSource!=NULL&&imgSink!=NULL) {
        ImageOf<PixelRgb> tmp;
        imgSource->getImage(tmp);
        imgSink->putImage(tmp);
        printf("piped %dx%d image\n", tmp.width(), tmp.height());
    } else if (sndSource!=NULL&&sndSink!=NULL) {
        Sound tmp;
        sndSource->getSound(tmp);
        sndSink->renderSound(tmp);
        printf("piped %dx%d sound\n", tmp.getSamples(), tmp.getChannels());
    } else {
        printf("Don't know how to pipe between these devices.\n");
        printf("Piping is very limited at the moment.\n");
        printf("You're probably better off writing some short custom code.\n");
        return false;
    }
    return true;
}
Example #3
0
int main() {
    Network::setLocalMode(true);

    FakeFrameGrabber fake;
    fake.start();
    
    PolyDriver dd("(device test_grabber) (local /client) (remote /server)");
    
    if (!dd.isValid()) {
        printf("Device not available\n");
        exit(1);
    }
    
    printf("*** Device created\n");
    
    IFrameGrabberImage *grabber;
    dd.view(grabber);
    
    if (grabber!=NULL) {
        printf("*** It can supply images\n");
        ImageOf<PixelRgb> img;
        if (grabber->getImage(img)) {
            printf("*** Got a %dx%d image\n", img.width(), img.height());
        } else {
            printf("*** Failed to actually read an image\n");
        }

        IFrameGrabberControls *ctrl;
        dd.view(ctrl);
        if (ctrl!=NULL) {
            printf("*** It can be controlled as a framegrabber\n");
            double x = ctrl->getBrightness();
            printf("*** brightness before setting is reported as %g\n", x);
            ctrl->setBrightness(100);
            printf("*** brightness set\n");
            x = ctrl->getBrightness();
            printf("*** brightness after setting reported as %g\n", x);
        } else {
            printf("*** It can <<<<<NOT>>>>> be controlled as a framegrabber\n");
        }

    } else {
        printf("*** It can <<<<<NOT>>>>> supply images\n");
    }

    IPidControl *pid;
    dd.view(pid);
    
    if (pid!=NULL) {
        printf("*** It can do PID control\n");
    } else {
        printf("*** It can <<<<<NOT>>>>> do PID control\n");
    }

    return 0;
}
Example #4
0
 void testBasic() {
     report(0,"a very basic driver instantiation test");
     PolyDriver dd;
     Property p;
     p.put("device","test_grabber");
     bool result;
     result = dd.open(p);
     checkTrue(result,"open reported successful");
     IFrameGrabberImage *grabber = NULL;
     result = dd.view(grabber);
     checkTrue(result,"interface reported");
     ImageOf<PixelRgb> img;
     grabber->getImage(img);
     checkTrue(img.width()>0,"interface seems functional");
     result = dd.close();
     checkTrue(result,"close reported successful");
 }
Example #5
0
int main(int argc, char *argv[]) {
    Network yarp;

    // give YARP a factory for creating instances of FakeFrameGrabber
    DriverCreator *fakey_factory = 
        new DriverCreatorOf<FakeFrameGrabber>("fakey",
                                              "grabber",
                                              "FakeFrameGrabber");
    Drivers::factory().add(fakey_factory); // hand factory over to YARP

    // use YARP to create and configure an instance of FakeFrameGrabber
    Property config;
    if (argc==1) {
        // no arguments, use a default
        config.fromString("(device fakey) (w 640) (h 480)");
    } else {
        // expect something like "--device fakey --w 640 --h 480"
        //                    or "--device dragonfly"
        //                    or "--device test_grabber --period 0.5 --mode [ball]"
        config.fromCommand(argc,argv);
    }
    PolyDriver dd(config);
    if (!dd.isValid()) {
        printf("Failed to create and configure a device\n");
        return 1;
    }
    IFrameGrabberImage *grabberInterface;
    if (!dd.view(grabberInterface)) {
        printf("Failed to view device through IFrameGrabberImage interface\n");
        return 1;
    }

    ImageOf<PixelRgb> img;
    grabberInterface->getImage(img);
    printf("Got a %dx%d image\n", img.width(), img.height());

    dd.close();

    return 0;
}