コード例 #1
0
ファイル: ALImageTranscriber.cpp プロジェクト: Lrosias/nbites
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
        ALImage *ALimage = NULL;

        // Attempt to retrieve the next image
        try {
            ALimage =
                reinterpret_cast<ALImage*>(
                    camera->getDirectRawImageLocal( lem_name));
        }catch (ALError &e) {
            log->error("NaoMain",
                       "Could not call the getImageLocal method of the "
                       "NaoCam module");
        }



        if (ALimage != NULL){
            // Synchronize noggin's information about joint angles with the motion
            // thread's information
            //we need to update the joint values before we copy the image
            //since it takes a long time to copy it
            sensors->updateVisionAngles();

            sensors->lockImage();
#ifdef CAN_SAVE_FRAMES
            // we make a local of the nao image for logging purposes
            if (sensors->getWriteableNaoImage() != NULL) {
                _copy_image(ALimage->getData(), sensors->getWriteableNaoImage());
                ImageAcquisition::acquire_image_fast(table, params,
                                                     sensors->getNaoImage(), image);
            } else {
                ImageAcquisition::acquire_image_fast(table, params,
                                                     ALimage->getData(), image);

            }
#else
            ImageAcquisition::acquire_image_fast(table, params,
                                                 ALimage->getData(), image);
#endif
            sensors->releaseImage();
            //we're done with the aldebaran buffer
            this->releaseImage();

        } else {
            cout << "\tALImage 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->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);
#ifdef CAN_SAVE_FRAMES
            sensors->notifyNewNaoImage();
#endif
            sensors->releaseImage();
        }

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