Exemplo n.º 1
0
DiagramRecognizer::DiagramRecognizer(QWidget *parent) :
	QWidget(parent)
{
	QPushButton *clearButton = new QPushButton(tr("Clear"));
	clearButton->setFont(QFont("Times", 18, QFont::Bold));
	QPushButton *recognizeButton = new QPushButton(tr("Recognize"));
	recognizeButton->setFont(QFont("Times", 18, QFont::Bold));
	QPushButton *recognizeImageButton = new QPushButton(tr("Recognize Image"));
	recognizeImageButton->setFont(QFont("Times", 18, QFont::Bold));

	Output *PrintedDiagram = new Output;

	connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
	connect(recognizeButton, SIGNAL(clicked()), this, SLOT(recognize()));
	connect(recognizeImageButton, SIGNAL(clicked()), this, SLOT(recognizeImage()));

	connect(this, SIGNAL(print(PathVector, Bitmap *, FormSegmentator *)), PrintedDiagram, SLOT(draw(PathVector, Bitmap *, FormSegmentator *)));

	QGridLayout *gridLayout = new QGridLayout;
	gridLayout->addWidget(clearButton, 0, 0);
	gridLayout->addWidget(recognizeButton, 1, 0);
	gridLayout->addWidget(recognizeImageButton, 2, 0);
	gridLayout->addWidget(PrintedDiagram, 1, 1, 3, 1);
	gridLayout->setColumnStretch(1, 10);
	setLayout(gridLayout);

	mRecognized = false;
	mComponentPoint.setX(-1000);
	mComponentPoint.setY(-1000);
	mGesturesManager = new MixedGesturesManager();
	mAbstractRecognizer = new AbstractRecognizer(mGesturesManager,
												 SimpleFormsInitializer::initialForms());
}
Exemplo n.º 2
0
DiagramRecognizer::DiagramRecognizer(QWidget *parent) :
		QMainWindow(parent),
		ui(new Ui::DiagramRecognizer)
{
	ui->setupUi(this);
	connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clear()));
	connect(ui->recognizeButton, SIGNAL(clicked()), this, SLOT(recognize()));
	connect(ui->recognizeImageButton, SIGNAL(clicked()), this, SLOT(recognizeImage()));
	mRecognized = false;
	mLeftButtonPressed = false;
	mComponentPoint.setX(-1000);
	mComponentPoint.setY(-1000);
	mGesturesManager = new MixedGesturesManager();
	mAbstractRecognizer = new AbstractRecognizer(mGesturesManager,
		 SimpleFormsInitializer::initialForms());
}
Exemplo n.º 3
0
	int performFileAction(bool verbose, imago::Settings& vars, const std::string& imageName, const std::string& configName,
						  const std::string& outputName)
	{
		logEnterFunction();

		int result = 0; // ok mark
		imago::VirtualFS vfs;

		vars.general.StartTime = 0; // reset timelimit

		if (vars.general.ExtractCharactersOnly)
		{
			if (verbose)
				printf("Characters extraction from image '%s'\n", imageName.c_str());
		}
		else
		{
			if (verbose)
				printf("Recognition of image '%s'\n", imageName.c_str());
		}

		try
		{
			imago::Image image;	  

			if (vars.general.LogVFSEnabled)
			{
				imago::getLogExt().SetVirtualFS(vfs);
			}

			imago::ImageUtils::loadImageFromFile(image, imageName.c_str());

			if (vars.general.ExtractCharactersOnly)
			{
				imago::Image out;
				imago::prefilterEntrypoint(vars, out, image);
				applyConfig(verbose, vars, configName);
				imago::ChemicalStructureRecognizer _csr;
				_csr.extractCharacters(vars, out);
			}
			else
			{
				RecognitionResult result = recognizeImage(verbose, vars, image, configName);		
				imago::FileOutput fout(outputName.c_str());
				fout.writeString(result.molecule.c_str());
				if (imago::getLogExt().loggingEnabled())
				{
					int molObj = indigoLoadMoleculeFromString(result.molecule.c_str());
					if (molObj != -1)
					{
						indigoSetOption("render-output-format", "png");
						indigoSetOption("render-background-color", "255, 255, 255");
						std::string outputImg = imago::getLogExt().generateImageName();
						indigoRenderToFile(molObj, outputImg.c_str());
						imago::getLogExt().appendImageFile("Result image:", outputImg);
						indigoFree(molObj);
					}
				}
			}

		}
		catch (std::exception &e)
		{
			result = 2; // error mark
			puts(e.what());
		}

		dumpVFS(vfs, "log_vfs.txt");

		return result;
	}