예제 #1
0
파일: Man.cpp 프로젝트: Flavkupe/nao-man
void
Man::waitForImage ()
{
  try {
    const unsigned char *data;
#ifndef MAN_IS_REMOTE
    ALVisionImage *image = NULL;
#else
    ALValue image;
    image.arraySetSize(6);
#endif

    SleepMs(100);
    data = NULL;

#ifndef MAN_IS_REMOTE
#ifdef DEBUG_IMAGE_REQUESTS
    printf("Requesting local image of size %ix%i, color space %i\n",
           IMAGE_WIDTH, IMAGE_HEIGHT, NAO_COLOR_SPACE);
#endif

    // Attempt to retrive the next image
    try {
      image = (ALVisionImage*) (lem->call<int>("fetchNextLocal"));
    }catch (ALError &e) {
      log->error("NaoMain", "Could not call the fetchNextLocal method of the "
          "NaoCam module");
    }
    if (image != NULL)
      data = image->getFrame();

#else
#ifdef DEBUG_IMAGE_REQUESTS
    printf("Requesting remote image of size %ix%i, color space %i\n",
           IMAGE_WIDTH, IMAGE_HEIGHT, NAO_COLOR_SPACE);
#endif

    // Attempt to retrive the next image
    try {
      image = lem->call<ALValue>("fetchNextRemote");
    }catch (ALError &e) {
      log->error("NaoMain", "Could not call the fetchNextRemote method of the "
          "NaoCam module");
    }
    data = static_cast<const unsigned char *>(image[5].GetBinary());

#endif

    if (data != NULL) {
      // Update Sensors image pointer
      sensors.lockImage();
      sensors.setImage(data);
      sensors.releaseImage();
    }
 
  }catch (ALError &e) {
    log->error("NaoMain", "Caught an error in run():\n" + e.toString());
  }
}
예제 #2
0
void ALImageTranscriber::waitForImage ()
{
    try {
#ifndef MAN_IS_REMOTE
#ifdef DEBUG_IMAGE_REQUESTS
        printf("Requesting local image of size %ix%i, color space %i\n",
               IMAGE_WIDTH, IMAGE_HEIGHT, NAO_COLOR_SPACE);
#endif
        ALVisionImage *ALimage = NULL;

        // Attempt to retrieve the next image
        try {
            ALimage = (ALVisionImage*) (camera->call<int>("getDirectRawImageLocal",lem_name));
        }catch (ALError &e) {
            log->error("NaoMain", "Could not call the getImageLocal method of the "
                       "NaoCam module");
        }
        if (ALimage != NULL) {
            memcpy(&image[0], ALimage->getFrame(), IMAGE_BYTE_SIZE);
            //image = ALimage->getFrame();
        }
        else
            cout << "\tALVisionImage from camera was null!!" << endl;

#ifdef DEBUG_IMAGE_REQUESTS
        //You can get some informations of the image.
        int width = ALimage->fWidth;
        int height = ALimage->fHeight;
        int nbLayers = ALimage->fNbLayers;
        int colorSpace = ALimage->fColorSpace;
        long long timeStamp = ALimage->fTimeStamp;
        int seconds = (int)(timeStamp/1000000LL);
        printf("Retrieved an image of dimensions %ix%i, color space %i,"
               "with %i layers and a time stamp of %is \n",
               width, height, colorSpace,nbLayers,seconds);
#endif

#else//Frame is remote:
#ifdef DEBUG_IMAGE_REQUESTS
        printf("Requesting remote image of size %ix%i, color space %i\n",
               IMAGE_WIDTH, IMAGE_HEIGHT, NAO_COLOR_SPACE);
#endif
        ALValue ALimage;
        ALimage.arraySetSize(7);

        // Attempt to retrive the next image
        try {
            ALimage = camera->call<ALValue>("getDirectRawImageRemote",
                                            lem_name);
        }catch (ALError &e) {
            log->error("NaoMain", "Could not call the getImageRemote method of the "
                       "NaoCam module");
        }

        //image = static_cast<const unsigned char*>(ALimage[6].GetBinary());
        memcpy(&image[0], ALimage[6].GetBinary(), IMAGE_BYTE_SIZE);
#ifdef DEBUG_IMAGE_REQUESTS
        //You can get some informations of the image.
        int width = (int) ALimage[0];
        int height = (int) ALimage[1];
        int nbLayers = (int) ALimage[2];
        int colorSpace = (int) ALimage[3];
        long long timeStamp = ((long long)(int)ALimage[4])*1000000LL +
            ((long long)(int)ALimage[5]);
        int seconds = (int)(timeStamp/1000000LL);
        printf("Retrieved an image of dimensions %ix%i, color space %i,"
               "with %i layers and a time stamp of %is \n",
               width, height, colorSpace,nbLayers,seconds);
#endif

#endif//IS_REMOTE

        if (image != NULL) {
            // Update Sensors image pointer
            sensors->lockImage();
            sensors->setImage(image);
            sensors->releaseImage();
        }

    }catch (ALError &e) {
        log->error("NaoMain", "Caught an error in run():\n" + e.toString());
    }
}