Example #1
0
FileCaptureInterface::FramePair FileCaptureInterface::getFrame()
{
    FramePair result;

    string name0 = getImageFileName(mCount, 0);
    string name1 = getImageFileName(mCount, 1);

    if (mVerbose) {
        printf("Grabbing frame from file: %s\n", name0.c_str());
    }

    result.bufferLeft = BufferFactory::getInstance()->loadG12Bitmap(name0);

    if (result.bufferLeft)
    {
        if (mVerbose) {
            printf("Grabbing frame from file: %s\n", name1.c_str());
        }

        result.bufferRight = BufferFactory::getInstance()->loadG12Bitmap(name1);
    }

    if (!result.bufferLeft || !result.bufferRight)
    {
        result.freeBuffers();
        if (mVerbose) {
            printf("File not found, resetting to first image in the sequence.\n");
        }
        resetImageFileCounter();
        return getFrame();
    }

    increaseImageFileCounter();
    return result;
}
Example #2
0
FileCaptureInterface::FramePair FileCaptureInterface::getFrame()
{
    FramePair result;

    string name0 = getImageFileName(mCount, 0);
    string name1 = getImageFileName(mCount, 1);

    mVerbose = true;
    if (mVerbose) {
        printf("Grabbing frame from file: %s (%s)\n"
               , name0.c_str()
               , mIsRgb ? "rgb" : "gray");
    }

    if (mIsRgb) {
        result.rgbBufferLeft = BufferFactory::getInstance()->loadRGB24Bitmap(name0);
        result.bufferLeft    = result.rgbBufferLeft->toG12Buffer();

        result.rgbBufferRight = BufferFactory::getInstance()->loadRGB24Bitmap(name1);
        result.bufferRight    = result.rgbBufferRight->toG12Buffer();

    } else {
        result.bufferLeft = BufferFactory::getInstance()->loadG12Bitmap(name0);
        result.bufferRight = BufferFactory::getInstance()->loadG12Bitmap(name1);
    }


  /*  if (result.bufferLeft)
    {
        if (mVerbose) {
            printf("Grabbing frame from file: %s\n", name1.c_str());
        }

        result.bufferRight = BufferFactory::getInstance()->loadG12Bitmap(name1);
    }*/

    if (result.bufferLeft == NULL && result.bufferRight == NULL)
    {
        result.freeBuffers();
        if (mVerbose) {
            printf("Files not found, resetting to first image in the sequence.\n");
        }
        resetImageFileCounter();
        return getFrame();
    }

    increaseImageFileCounter();
    return result;
}
void ossimQtIcpDialog::outputImagePressed()
{
   if (!theOutputImageField)
   {
      return;
   }

   QString qs = theOutputImageField->text();

   // Make sure output filename is not the same as input.
   QString source_file = getImageFileName();
   if (source_file == qs)
   {
      QString caption = "Sorry:";
      QString text = "Output file cannot be the same as input file.";
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      theOutputImageField->setText("");
      return;      
   }
   
   theOutputImageField->setText(qs);
}
Example #4
0
void captureSingleFrame(int)
{
	int num = findUniqueFileName();

	XnChar csImageFileName[XN_FILE_MAX_PATH];
	XnChar csDepthFileName[XN_FILE_MAX_PATH];
	XnChar csIRFileName[XN_FILE_MAX_PATH];
	getImageFileName(num, csImageFileName);
	getDepthFileName(num, csDepthFileName);
	getIRFileName(num, csIRFileName);

	const ImageMetaData* pImageMD = getImageMetaData();
	if (pImageMD != NULL)
	{
		xnOSSaveFile(csImageFileName, pImageMD->Data(), pImageMD->DataSize());
	}

	const IRMetaData* pIRMD = getIRMetaData();
	if (pIRMD != NULL)
	{
		xnOSSaveFile(csIRFileName, pIRMD->Data(), pIRMD->DataSize());
	}

	const DepthMetaData* pDepthMD = getDepthMetaData();
	if (pDepthMD != NULL)
	{
		xnOSSaveFile(csDepthFileName, pDepthMD->Data(), pDepthMD->DataSize());
	}
	
	g_Capture.nCapturedFrameUniqueID = num + 1;

// 	displayMessage("Frames saved with ID %d", num);
	printf("Frames saved with ID %d\n", num);
}
Example #5
0
QString FileInfo::getDebugInfo() const
{
    const QString str = "\n\tContainer: " + getContainerPath()
            + "\n\tPath: " + getPath()
            + "\n\tImageFileName: " + getImageFileName()
            + "\n\tZipPath: " + getArchiveContainerPath()
            + "\n\tIsInArchive: " + (isInArchive() ? "true" : "false")
            + "\n\tContainer Name: " + getContainerName();
    return str;
}
void ossimQtIgenController::updateOutputFilenameFromWriter()
{
   if (!theDialog || !theDialog->theOutputFileLineEdit || !theWriter)
   {
      return;
   }

   ossimFilename writersOutputFile = theWriter->getFilename();
   if (writersOutputFile.empty())
   {
      return;
   }
   
   QString fileName = writersOutputFile.c_str();
   
   if (fileName == getOutputFile())
   {
      return;
   }
   
   // Make sure output filename is not the same as input.
#if 0
   QString source_file = getImageFileName();
   if (source_file == fileName)
   {
      QString caption = "Sorry:";
      QString text = "Output file cannot be the same as input file.";
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      return;      
   }
#endif

   // Check to see if file exist and prompt user for overwrite.
   if (writersOutputFile.exists())
   {
      QString caption("Question:");
      QString text = "Overwrite existing file:  ";
      text += fileName;
      int answer = QMessageBox::question( theDialog,
                                          caption,
                                          text,
                                          QMessageBox::Yes,
                                          QMessageBox::No);
      if (answer == QMessageBox::No)
      {
         theDialog->theOutputFileLineEdit->setText("");
         return;
      }
   }
   
   theDialog->theOutputFileLineEdit->setText(fileName);
}
Example #7
0
bool Ally::init()
{
    if (Sprite::initWithFile(getImageFileName()))
    {
        return true;
    }
    else
    {
        return false;
    }
}
Example #8
0
int findUniqueFileName()
{
	xnOSCreateDirectory(CAPTURED_FRAMES_DIR_NAME);

	int num = g_Capture.nCapturedFrameUniqueID;

	XnBool bExist = FALSE;
	XnStatus nRetVal = XN_STATUS_OK;
	XnChar csImageFileName[XN_FILE_MAX_PATH];
	XnChar csDepthFileName[XN_FILE_MAX_PATH];
	XnChar csIRFileName[XN_FILE_MAX_PATH];

	while (true)
	{
		// check image
		getImageFileName(num, csImageFileName);

		nRetVal = xnOSDoesFileExist(csImageFileName, &bExist);
		if (nRetVal != XN_STATUS_OK)
			break;

		if (!bExist)
		{
			// check depth
			getDepthFileName(num, csDepthFileName);

			nRetVal = xnOSDoesFileExist(csDepthFileName, &bExist);
			if (nRetVal != XN_STATUS_OK || !bExist)
				break;
		}

		if (!bExist)
		{
			// check IR
			getIRFileName(num, csIRFileName);

			nRetVal = xnOSDoesFileExist(csIRFileName, &bExist);
			if (nRetVal != XN_STATUS_OK || !bExist)
				break;
		}
		++num;
	}
	return num;
}
void ossimQtIcpDialog::outputImageClicked()
{
   if (!theOutputImageField)
   {
      return;
   }
   
   QFileDialog* fd = new QFileDialog( this, "file dialog", TRUE );
   fd->setMode( QFileDialog::AnyFile );
   
   QString fileName;
   
   if ( fd->exec() == QDialog::Accepted )
   {
      fileName = fd->selectedFile();
   }
   delete fd;
   fd = NULL;
   
   if (fileName.isEmpty())
   {
      return;
   }
   
   // Make sure output filename is not the same as input.
   QString source_file = getImageFileName();
   if (source_file == fileName)
   {
      QString caption = "Sorry:";
      QString text = "Output file cannot be the same as input file.";
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      theOutputImageField->setText("");
      return;      
   }
   
   theOutputImageField->setText(fileName);
}
Example #10
0
void ossimQtIcpDialog::updateOutputFilenameFromWriter()
{
   if (!theOutputImageField || !theWriter)
   {
      return;
   }

   ossimFilename writersOutputFile = theWriter->getFilename();
   if (writersOutputFile.empty())
   {
      return;
   }
   
   QString fileName = writersOutputFile.c_str();
   
   if (fileName == theOutputImageField->text())
   {
      return;
   }
   
   // Make sure output filename is not the same as input.
   QString source_file = getImageFileName();
   if (source_file == fileName)
   {
      QString caption = "Sorry:";
      QString text = "Output file cannot be the same as input file.";
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      theOutputImageField->setText("");
      return;      
   }
   
   theOutputImageField->setText(fileName);
}
Example #11
0
void ossimQtIcpDialog::saveClicked()
{
   if ( !theOutputImageField || !theWriter || !theChain )
   {
      return;
   }

   // Make sure the output rectangle is up to date.
   if (updateOuputRect() == false)
   {
      return;
   }
   
   // Make sure output file is not empty.
   QString output_file = theOutputImageField->text();
   if (output_file.isEmpty())
   {
      QString caption = "Sorry:";
      QString text = "You must set an output file name.";
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      return;
   }

   // Check to see if file exist and prompt user for overrite.
   ossimFilename f = output_file.ascii();
   if (f.exists())
   {
      QString caption("Question:");
      QString text = "Overwrite existing file:  ";
      text += output_file;
      int answer = QMessageBox::question( this,
                                          caption,
                                          text,
                                          QMessageBox::Yes,
                                          QMessageBox::No);
      if (answer == QMessageBox::No)
      {
         theOutputImageField->setText("");
         return;
      }
   }

   // Make sure output filename is not the same as input.
   QString source_file = getImageFileName();
   if (source_file == output_file)
   {
      QString caption = "Sorry:";
      QString text = "Output file cannot be the same as input file.";
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      theOutputImageField->setText("");
      return;      
   }

   // Connect it up to the source.
   theWriter->connectMyInputTo(0, theChain);

   // Make a progress dialog.
   ossimQtProgressDialog* pd = new ossimQtProgressDialog("");
   pd->setMinimumDuration(250); // Update 4 times a second.

   //---
   // Connect the progress dialog's signal "canceled()" up to our slot
   // "saveCanceled()" so that we can tell the writer to abort.
   //---
   connect( pd, SIGNAL(canceled()), this, SLOT(abortClicked()) );
   
   theWriter->addListener(pd); // Progress dialog listens to writer...

   // Set up the progress dialog...
   QString qs = "Processing file ";
   qs += output_file        ;
   pd->setLabelText(qs);
   pd->show();
   
   //---
   // Process the tile...
   //---
   theWriter->open(output_file.ascii());
   theWriter->initialize();
   theWriter->setAreaOfInterest(theOutputImageRect);

   // Process the image...
   bool exceptionCaught = false;
   try
   {
      theWriter->execute();
   }
   catch(std::exception& e)
   {
      pd->close();
      QString caption = "Exception caught!\n";
      QString text = e.what();
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      exceptionCaught = true;
   }
   catch (...)
   {
      pd->close();
      QString caption = "Unknown exception caught!\n";
      QString text = "";
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
      exceptionCaught = true;
   }

   theWriter->close();

   if (exceptionCaught)
   {
      int status = remove(output_file.ascii()); // 0 == success, -1 failure
      
      QString caption = "Processing of file aborted!";
      QString text = "File:  ";
      text += output_file;
      if (status == 0)
      {
         text += "\nFile removed successfully...";
      }
      
      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
   }
   else if (pd->wasCanceled()) // Check for cancelation.
   {
      pd->close();

      int status = remove(output_file.ascii()); // 0 == success, -1 failure
         
      QString caption = "Processing of file aborted!";
      QString text = "File:  ";
      text += output_file;
      if (status == 0)
      {
         text += "\nFile removed successfully...";
      }

      QMessageBox::information( this,
                                caption,
                                text,
                                QMessageBox::Ok );
   }

   theWriter->removeListener(pd);

   // Cleanup...
   delete pd;
   pd = NULL;
}
Example #12
0
ossimQtIcpDialog::ossimQtIcpDialog(QWidget* parent,
                                   ossimImageChain* image_chain)
   : QDialog(parent, "ossimQtIcpDialog", true, WDestructiveClose),
     theChain(image_chain),
     theWriter(NULL),
     theMainVBox(NULL),
     
     theHBox1(NULL),
     theSourceImageGroupBox(NULL),         
     theSourceImageLabel(NULL),
     
     theHBox2(NULL),
     theStartLineGroupBox(NULL),
     theStartLineField(NULL),
     theStopLineGroupBox(NULL),   
     theStopLineField(NULL),
     
     theHBox3(NULL),
     theStartSampleGroupBox(NULL),
     theStartSampleField(NULL),
     theStopSampleGroupBox(NULL),   
     theStopSampleField(NULL),
     
     theHBox4(NULL),
     theOutputImageGroupBox(NULL),      
     theOutputImageField(NULL),
     theOutputImageButton(NULL),
     
     theHBox5(NULL),
     theOutputImageTypeGroupBox(NULL),
     theOutputImageWriterMenu(NULL),
     theEditOutputImageWriterButton(NULL),
     
     theHBox6(NULL),
     theSaveButton(NULL),
     theCloseButton(NULL),
     theSourceImageRect(),
     theOutputImageRect()
{
   setCaption("Export Image");
   

   // Main vertical box.
   theMainVBox = new QVBoxLayout(this);

   // First row, display source image file name.
   theHBox1 = new QHBoxLayout(theMainVBox);
   
   theSourceImageGroupBox = new QGroupBox(1,
                                          Qt::Horizontal,
                                          "source image",
                                          this,
                                          "theSourceImageGroupBox");
   theSourceImageGroupBox->setAlignment(Qt::AlignHCenter);
   QString s = getImageFileName();
   theSourceImageLabel = new QLabel(s,
                                    theSourceImageGroupBox,
                                    "theSourceImageLabel");
   theHBox1->addWidget(theSourceImageGroupBox);
   // End of first row.

   // Second row, start line, stop line.
   theHBox2 = new QHBoxLayout(theMainVBox);
   theStartLineGroupBox = new QGroupBox(1, Qt::Horizontal, "start line", this);
   theStartLineGroupBox->setAlignment(Qt::AlignHCenter);
   theStartLineField = new QLineEdit(theStartLineGroupBox, "theStartLineField");
   theHBox2->addWidget(theStartLineGroupBox);

   // Make the stop line box.
   theStopLineGroupBox = new QGroupBox(1, Qt::Horizontal, "stop line", this);
   theStopLineGroupBox->setAlignment(Qt::AlignHCenter);
   theStopLineField = new QLineEdit(theStopLineGroupBox, "theStopLineField");
   theHBox2->addWidget(theStopLineGroupBox);
   // End of second row.

   // Third row, start sample, stop sample.
   theHBox3 = new QHBoxLayout(theMainVBox);

   // Make the start sample box.
   theStartSampleGroupBox =
      new QGroupBox(1, Qt::Horizontal, "start sample", this);
   theStartSampleGroupBox->setAlignment(Qt::AlignHCenter);
   theStartSampleField = new QLineEdit(theStartSampleGroupBox,
                                       "theStartSampleField");
   theHBox3->addWidget(theStartSampleGroupBox);

   // Make the stop sample box.
   theStopSampleGroupBox =
      new QGroupBox(1, Qt::Horizontal, "stop sample", this);
   theStopSampleGroupBox->setAlignment(Qt::AlignHCenter);
   theStopSampleField = new QLineEdit(theStopSampleGroupBox,
                                      "theStopSampleField");
   theHBox3->addWidget(theStopSampleGroupBox);

   // End of third row...

   // Fourth row, output file, file dialog button.
   theHBox4 = new QHBoxLayout(theMainVBox);
   theOutputImageGroupBox =
      new QHGroupBox("output image", this, "theOutputImageGroupBox");
   theOutputImageGroupBox->setAlignment(Qt::AlignHCenter);
   theOutputImageField = new QLineEdit(theOutputImageGroupBox,
                                       "theOutputImageField");
   theOutputImageButton = new QPushButton( theOutputImageGroupBox,
                                           "theOutputImageButton" );
   theOutputImageButton->setText( "..." );
   theOutputImageButton->setDefault(false);
   theOutputImageButton->setAutoDefault(false);
   theHBox4->addWidget(theOutputImageGroupBox);
   // End of fourth row...
   
   // Fifth row.
   theHBox5 = new QHBoxLayout(theMainVBox);
   theOutputImageTypeGroupBox =
      new QHGroupBox("output image type", this, "theOutputImageTypeGroupBox");
   theOutputImageTypeGroupBox->setAlignment(Qt::AlignHCenter);
   
   theOutputImageWriterMenu = new QComboBox(theOutputImageTypeGroupBox,
                                       "theOutputWriterBox");
   buildWriterMenu();
   theEditOutputImageWriterButton =
      new QPushButton( theOutputImageTypeGroupBox,
                       "theEditOutputImageWriterButton" );
   theEditOutputImageWriterButton->setText( "edit writer" );
   theEditOutputImageWriterButton->setDefault(false);
   theEditOutputImageWriterButton->setAutoDefault(false);
   theHBox5->addWidget(theOutputImageTypeGroupBox);

   // Sixth row.
   theHBox6 = new QHBoxLayout(theMainVBox);

   theSaveButton = new QPushButton( this, "theSaveButton" );
   theSaveButton->setText( "Save" );
   theSaveButton->setDefault(false);
   theSaveButton->setAutoDefault(false);   
   
   theCloseButton = new QPushButton( this, "theCloseButton" );
   theCloseButton->setText( "Close" );
   theCloseButton->setDefault(false);
   theCloseButton->setAutoDefault(false);   

   theHBox6->addWidget(theSaveButton);
   theHBox6->addWidget(theCloseButton);

   //---
   // Connect all the signals to slots...
   //
   // NOTE:
   // If a push button is set to "default" or "auto default" it will always
   // call that slot when return is pressed in the dialog.
   // Since this isn't what I want all defaults are set to off!
   //---
   connect( theStartLineField, SIGNAL ( returnPressed() ),
            this, SLOT ( startLinePressed() ) );
   
   connect( theStopLineField, SIGNAL ( returnPressed() ),
            this, SLOT ( stopLinePressed() ) );
   
   connect( theStartSampleField, SIGNAL ( returnPressed() ),
            this, SLOT ( startSamplePressed() ) );
   
   connect( theStopSampleField, SIGNAL ( returnPressed() ),
            this, SLOT ( stopSamplePressed() ) );

   connect( theOutputImageField, SIGNAL ( returnPressed() ),
            this, SLOT ( outputImagePressed() ) );

   connect( theOutputImageButton, SIGNAL ( clicked() ),
            this, SLOT ( outputImageClicked() ) );

   connect( theOutputImageWriterMenu, SIGNAL ( activated( const QString& ) ),
            this, SLOT ( outputImageWriterMenuActivated( const QString& ) ) );

   connect( theEditOutputImageWriterButton,
            SIGNAL ( clicked() ),
            this,
            SLOT ( editOutputImageWriterClicked() ) );

   connect( theSaveButton, SIGNAL ( clicked() ),
            this, SLOT ( saveClicked() ) );
   
   connect( theCloseButton, SIGNAL ( clicked() ),
            this, SLOT ( closeClicked() ) );

   initializeDialog();
}
string EmergenceLog::getImageFilePath(long logLineNum)
{
    return getImagesDirPath() + getImageFileName(logLineNum);
}
string ImageFileCaptureInterface::getImageFileName(uint imageNumber, uint channelNumber)
{
    // TODO: How to replace this with C++ construct? I.e. MFC's CString has a method Format() for this, but std::string doesn't. :(
    char pathName[256];

    if (mPathFmt.find("%0.0s") != string::npos)             // format comes from GUI with constant pair for debugging
    {
        snprintf2buf(pathName, mPathFmt.c_str(), "", channelNumber);// str + int (the way to disable pair switching over series)
    }
    else if (mPathFmt.find("%") != string::npos)            // format comes from GUI with series processing
    {
        // TODO: it would be good here to check that format expects exactly 2 integers
        snprintf2buf(pathName, mPathFmt.c_str(), imageNumber, channelNumber); // expects 2 ints
    }
    else if (!mPathFmt.empty())                             // format comes as a ready path, only from some tests
    {
        // one exclusion is possible here: when ctor got a direct path to the file!
        QFileInfo fi(mPathFmt.c_str());
        if (fi.isFile() && fi.exists()) {
            return mPathFmt;                                // return immediately the initial path as it's not a format
        }

        // mPathFmt has a real folder path
        if (mPathFmt[mPathFmt.length() - 1] != '/') {       // append slash at the end if absent
            mPathFmt += '/';
        }
        mPathFmt += sPgmImageFileFmt;                       // add default format to the pathFmt

        return getImageFileName(imageNumber, channelNumber);
    }

    if (imageNumber == 1 && mPathPrefix.empty() && !QFile::exists(pathName))
    {
        /**
         * We're to check correctness of the current directory, but we need a path to "data" folder with image files.
         *
         *       "../"  - Bin directory curDir
         *    "../../"  - OpenCL project curDir
         * "../../../"  - MSVC sets curDir to the project dir (= "hostSoft")
         *
         * \note  But from another side it's dangerously to scan up to 3 levels by trying to find a requested file.\n
         *        especially if there's a special folder structure with different series...
         *        Therefore for Unix it's applied only for one parent as we run from the bin directory, \n
         *        but usually use images by path like this: "data/pair".
         */
        string path(pathName);
        string prefix;

#ifdef WIN32
        cuint numRecursiveFoldersToCheck = 3;
#else
        cuint numRecursiveFoldersToCheck = 1;               // one check for parent dir is ok or also dangerously?
#endif
        for (unsigned k = 0; k < numRecursiveFoldersToCheck; k++)
        {
            path  .insert(0, "../");
            prefix.insert(0, "../");                        // try at folder one step up

            if (QFile::exists(path.c_str()))
            {
                mPathPrefix.assign(prefix);
                break;
            }
        }
    }

    return mPathPrefix + pathName;
}
Example #15
0
int main(int argc, char* argv[])
{
   int status = PV_SUCCESS;

   PV::PV_Init * pv_init = new PV_Init(&argc, &argv);
   pv_init -> initialize(argc, argv);
   // Build the column from the params file
   PV::ParamGroupHandler * customGroupHandler[1];
   customGroupHandler[0] = new PASCALCustomGroupHandler();
   PV::HyPerCol * hc = build(argc, argv, pv_init, customGroupHandler, 1);
   assert(hc->getStartTime()==hc->simulationTime());

   double startTime = hc->getStartTime();
   double stopTime = hc->getStopTime();
   double dt = hc->getDeltaTime();
   double displayPeriod = stopTime - startTime;
   const int rank = hc->columnId();
   InterColComm * icComm = hc->icCommunicator();

//   // These variables are only used by the root process, but must be defined here
//   // since they need to persist from one if(rank==0) statement to the next.
//   char * imageLayerName = NULL;
//   char * resultLayerName = NULL;
//   char * resultTextFile = NULL;
//   char * octaveCommand = NULL;
//   char * octaveLogFile = NULL;
//   char * classNames = NULL;
//   char * evalCategoryIndices = NULL;
//   char * displayCategoryIndices = NULL;
//   char * highlightThreshold = NULL;
//   char * heatMapThreshold = NULL;
//   char * heatMapMaximum = NULL;
//   char * drawBoundingBoxes = NULL;
//   char * boundingBoxThickness = NULL;
//   char * dbscanEps = NULL;
//   char * dbscanDensity = NULL;
//   char * heatMapMontageDir = NULL;
//   char * displayCommand = NULL;
   int layerNx, layerNy, layerNf;
   int imageNx, imageNy, imageNf;
   int bufferNx, bufferNy, bufferNf;
   size_t imageBufferSize;
   uint8_t * imageBuffer;
   int octavepid = 0; // pid of the child octave process.

   PV::ImageFromMemoryBuffer * imageLayer = NULL;
   for (int k=0; k<hc->numberOfLayers(); k++) {
      PV::HyPerLayer * l = hc->getLayer(k);
      PV::ImageFromMemoryBuffer * img_buffer_layer = dynamic_cast<PV::ImageFromMemoryBuffer *>(l);
      if (img_buffer_layer) {
         if (imageLayer!=NULL) {
            if (hc->columnId()==0) {
               fprintf(stderr, "%s error: More than one ImageFromMemoryBuffer (\"%s\" and \"%s\").\n",
                     argv[0], imageLayer->getName(), img_buffer_layer->getName());
            }
            MPI_Barrier(hc->icCommunicator()->communicator());
            exit(EXIT_FAILURE);
         }
         else {
            imageLayer = img_buffer_layer;
         }
      }
   }
//
//   BaseLayer * imageBaseLayer = hc->getLayerFromName(imageLayerName);
//   if (imageBaseLayer==NULL)
//   {
//      if (rank==0) {
//         fprintf(stderr, "%s error: no layer matches imageLayerName = \"%s\"\n", argv[0], imageLayerName);
//      }
//      status = PV_FAILURE;
//   }
//   ImageFromMemoryBuffer * imageLayer = dynamic_cast<ImageFromMemoryBuffer *>(imageBaseLayer);
//   if (imageLayer==NULL)
//   {
//      if (rank==0) {
//         fprintf(stderr, "%s error: imageLayerName = \"%s\" is not an ImageFromMemoryBuffer layer\n", argv[0], imageLayerName);
//      }
//      status = PV_FAILURE;
//   }
//
//   BaseLayer * resultBaseLayer = hc->getLayerFromName(resultLayerName);
//   if (resultBaseLayer==NULL)
//   {
//      if (rank==0) {
//         fprintf(stderr, "%s error: no layer matches resultLayerName = \"%s\"\n", argv[0], resultLayerName);
//      }
//      status = PV_FAILURE;
//   }
//   HyPerLayer * resultLayer = dynamic_cast<HyPerLayer *>(resultBaseLayer);
//   if (resultLayer==NULL)
//   {
//      if (rank==0) {
//         fprintf(stderr, "%s error: resultLayerName = \"%s\" is not a HyPerLayer\n", argv[0], resultLayerName);
//      }
//      status = PV_FAILURE;
//   }

   if (rank==0) {
      if (status != PV_SUCCESS) { exit(EXIT_FAILURE); }

//      // clobber octave logfile and result text file unless starting from a checkpoint
//      if (hc->getCheckpointReadDir()==NULL) {
//         FILE * octavefp = fopen(octaveLogFile, "w");
//         fclose(octavefp);
//         if (resultTextFile) {
//            FILE * resultTextFP = fopen(resultTextFile, "w")
//            fclose(resultTextFP);
//         }
//      }

      layerNx = imageLayer->getLayerLoc()->nxGlobal;
      layerNy = imageLayer->getLayerLoc()->nyGlobal;
      layerNf = imageLayer->getLayerLoc()->nf;

      imageNx = layerNx;
      imageNy = layerNy;
      imageNf = 3;

      bufferNx = layerNx;
      bufferNy = layerNy;
      bufferNf = imageNf;

      imageBufferSize = (size_t)bufferNx*(size_t)bufferNy*(size_t)bufferNf;
      imageBuffer = NULL;
      GDALAllRegister();
//      struct stat heatMapMontageStat;
//      status = stat(heatMapMontageDir, &heatMapMontageStat);
//      if (status!=0 && errno==ENOENT) {
//         status = mkdir(heatMapMontageDir, 0770);
//         if (status!=0) {
//            fprintf(stderr, "Error: Unable to make heat map montage directory \"%s\": %s\n", heatMapMontageDir, strerror(errno));
//            exit(EXIT_FAILURE);
//         }
//         status = stat(heatMapMontageDir, &heatMapMontageStat);
//      }
//      if (status!=0) {
//         fprintf(stderr, "Error: Unable to get status of heat map montage directory \"%s\": %s\n", heatMapMontageDir, strerror(errno));
//         exit(EXIT_FAILURE);
//      }
//      if (!(heatMapMontageStat.st_mode & S_IFDIR)) {
//         fprintf(stderr, "Error: Heat map montage \"%s\" is not a directory\n", heatMapMontageDir);
//         exit(EXIT_FAILURE);
//      }
   }

   // Main loop: get an image, load it into the image layer, do HyPerCol::run(), lather, rinse, repeat
   char * imageFile = getImageFileName(icComm);
   while(imageFile!=NULL && imageFile[0]!='\0')
   {
      startTime = hc->simulationTime();
      stopTime = startTime + displayPeriod;
      setImageLayerMemoryBuffer(hc->icCommunicator(), imageFile, imageLayer, &imageBuffer, &imageBufferSize);
      hc->run(startTime, stopTime, dt);

//      int numParams = 20;
//      int params[numParams];
//
//      char const * imagePvpFile = rank ? 0 : imageLayer->getOutputStatePath();
//      char const * resultPvpFile = rank ? 0 : resultLayer->getOutputStatePath();
//      PV_Stream * imagePvpStream = NULL;
//      PV_Stream * resultPvpStream = NULL;
//
//      if (rank==0) {
//         imageLayer->flushOutputStateStream();
//         imagePvpStream = PV_fopen(imagePvpFile, "r", false/*verifyWrites*/);
//      }
//      status = pvp_read_header(imagePvpStream, hc->icCommunicator(), params, &numParams);
//      if (status!=PV_SUCCESS)
//      {
//         fprintf(stderr, "pvp_read_header for imageLayer \"%s\" outputfile \"%s\" failed.\n", imageLayer->getName(), imagePvpFile);
//         exit(EXIT_FAILURE);
//      }
//      if (rank==0) { PV_fclose(imagePvpStream); }
//      assert(numParams==20);
//      int imageFrameNumber = params[INDEX_NBANDS];
//
//      if (rank==0) {
//         resultLayer->flushOutputStateStream();
//         resultPvpStream = PV_fopen(resultPvpFile, "r", false/*verifyWrites*/);
//      }
//      status = pvp_read_header(resultPvpStream, hc->icCommunicator(), params, &numParams);
//      if (status!=PV_SUCCESS)
//      {
//         fprintf(stderr, "pvp_read_header for resultLayer \"%s\" outputfile \"%s\" failed.\n", resultLayer->getName(), resultPvpFile);
//         exit(EXIT_FAILURE);
//      }
//      if (rank==0) { PV_fclose(resultPvpStream); }
//      assert(numParams==20);

//      if (rank==0) {
//         int resultFrameNumber = params[INDEX_NBANDS];
//         char * basename = strrchr(imageFile, '/');
//         if (basename==NULL) { basename=imageFile; } else { basename++; }
//         basename = strdup(basename);
//         char * dot = strrchr(basename, '.');
//         if (dot) { *dot = '\0'; } // delete extension
//         std::stringstream montagePath("");
//         montagePath << heatMapMontageDir << "/" << basename << ".png";
//         free(basename);
//         std::cout << "output file is " << montagePath.str() << std::endl;
//
//         if (octavepid>0)
//         {
//            int waitstatus;
//            int waitprocess = waitpid(octavepid, &waitstatus, 0);
//            if (waitprocess < 0 && errno != ECHILD)
//            {
//               fprintf(stderr, "waitpid failed returning %d: %s (%d)\n", waitprocess, strerror(errno), errno);
//               exit(EXIT_FAILURE);
//            }
//            octavepid = 0;
//         }
//         fflush(stdout); // so that unflushed buffer isn't copied to child process
//         octavepid = fork();
//         if (octavepid < 0)
//         {
//            fprintf(stderr, "fork() error: %s\n", strerror(errno));
//            exit(EXIT_FAILURE);
//         }
//         else if (octavepid==0) {
//            /* child process */
//            std::stringstream octavecommandstream("");
//            octavecommandstream << octaveCommand <<
//                  " --eval 'load CurrentModel/ConfidenceTables/confidenceTable.mat; heatMapMontage(" <<
//                  "\"" << imagePvpFile << "\"" << ", " <<
//                  "\"" << resultPvpFile << "\"" << ", " <<
//                  "\"" << PV_DIR << "/mlab/util" << "\"" << ", " <<
//                  imageFrameNumber << ", " <<
//                  resultFrameNumber << ", " <<
//                  "confidenceTable, " <<
//                  "\"" << classNames << "\"" << ", " <<
//                  "\"" << resultTextFile << "\"" << ", " <<
//                  evalCategoryIndices << ", " <<
//                  displayCategoryIndices << ", " <<
//                  highlightThreshold << ", " <<
//                  heatMapThreshold << ", " <<
//                  heatMapMaximum << ", " <<
//                  drawBoundingBoxes << ", " <<
//                  boundingBoxThickness << ", " <<
//                  dbscanEps << ", " <<
//                  dbscanDensity << ", " <<
//                  "\"" << montagePath.str() << "\"" << ", " <<
//                  "\"" << displayCommand << "\"" <<
//                  ");'" <<
//                  " >> " << octaveLogFile << " 2>&1";
//            std::ofstream octavelogstream;
//            octavelogstream.open(octaveLogFile, std::fstream::out | std::fstream::app);
//            octavelogstream << "Calling octave with the command\n";
//            octavelogstream << octavecommandstream.str() << "\n";
//            octavelogstream.close();
//            int systemstatus = system(octavecommandstream.str().c_str()); // Analysis of the result of the current frame
//            octavelogstream.open(octaveLogFile, std::fstream::out | std::fstream::app);
//            octavelogstream << "Octave heatMapMontage command returned " << systemstatus << "\n";
//            octavelogstream.close();
//
//            exit(EXIT_SUCCESS); /* child process exits */
//         }
//         else {
//            /* parent process */
//         }
//      }
//
      free(imageFile);
      imageFile = getImageFileName(hc->icCommunicator());
   }

   delete hc;
   free(imageFile);
   delete customGroupHandler[0];
   delete pv_init;
   return status==PV_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
}