Example #1
0
/*!
 * Read the first frame from an Analyze 7.5 database into IMG data structure.
 *
 * @param fname Name of Analyze database from which IMG contents will be read
 * @param img pointer to the initiated but not preallocated IMG data
 * @return errstatus, which is STATUS_OK (0) when call was successful,
 * and >0 in case of an error.
 */
int imgReadAnalyzeFirstFrame(const char *fname, IMG *img) {
  int ret=0;

  if(IMG_TEST) printf("\nimgReadAnalyzeFirstFrame(%s, *img)\n", fname);
  /* Check the input */
  if(img==NULL) return STATUS_FAULT;
  if(img->status!=IMG_STATUS_INITIALIZED) return STATUS_FAULT;
  imgSetStatus(img, STATUS_FAULT);
  if(fname==NULL) return STATUS_FAULT;

  /* Read header information from file */
  ret=imgReadAnalyzeHeader(fname, img); if(ret) return(ret);
  if(IMG_TEST>3) imgInfo(img);

  /* Allocate memory for one frame */
  img->dimt=1;
  ret=imgAllocate(img, img->dimz, img->dimy, img->dimx, img->dimt);
  if(ret) return STATUS_NOMEMORY;

  /* Read the first frame */
  ret=imgReadAnalyzeFrame(fname, 1, img, 0); if(ret) return(ret); 

  /* All went well */
  imgSetStatus(img, STATUS_OK);
  return STATUS_OK;
}
Example #2
0
QPolygonF DkPageExtractionPlugin::readGT(const QString& imgPath) const {

	QFileInfo imgInfo(imgPath);

	QFileInfo xmlFileI(imgInfo.absolutePath(), imgInfo.baseName() + ".xml");

	if (!xmlFileI.exists()) {
		qWarning() << "no xml file found: " << xmlFileI.absoluteFilePath();
		return QPolygonF();
	}
	QFile xmlFile(xmlFileI.absoluteFilePath());
	if (!xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
		qWarning() << "could not load" << xmlFileI.absoluteFilePath();
		return QPolygonF();
	}

	QXmlStreamReader xmlReader(&xmlFile);
	QPolygonF rect;

	while (!xmlReader.atEnd() && !xmlReader.hasError()) {

		QString tag = xmlReader.qualifiedName().toString();

		if (xmlReader.tokenType() == QXmlStreamReader::StartElement && tag == "dmrz") {
			
			for (int idx = 0; idx < 4; idx++) {

				QPoint p;
				p.setX(xmlReader.attributes().value("x" + QString::number(idx)).toInt());
				p.setY(xmlReader.attributes().value("y" + QString::number(idx)).toInt());
				rect << p;
			}
		}
		xmlReader.readNext();
	}

	return rect;
}