Esempio n. 1
0
std::vector<DkPolyRect> DkPageSegmentation::apply(const cv::Mat& src, bool useLab, const DkPolyRect& oldRect) {

	std::vector<DkPolyRect> pageRects;

	// run the page segmentation
	DkPageSegmentation segM(src, oldRect);
	segM.compute(useLab);
	segM.filterDuplicates();

	//pageRects = segM.getRects();

	DkPolyRect r = segM.getDocumentRect();

	if (!r.empty())
	    pageRects.push_back(r);

	return pageRects;
}
Esempio n. 2
0
/**
* Main function: runs plugin based on its ID
* @param plugin ID
* @param image to be processed
**/
QSharedPointer<nmc::DkImageContainer> DkPageExtractionPlugin::runPlugin(
	const QString &runID, 
	QSharedPointer<nmc::DkImageContainer> imgC, 
	const nmc::DkSaveInfo& saveInfo, 
	QSharedPointer<nmc::DkBatchInfo>& batchInfo) const {

	if (!mRunIDs.contains(runID) || !imgC)
		return imgC;

	cv::Mat img = nmc::DkImage::qImage2Mat(imgC->image());

	// run the page segmentation
	DkPageSegmentation segM(img);
	segM.compute();
	segM.filterDuplicates();

	// crop image
	if(runID == mRunIDs[id_crop_to_page]) {
		imgC->setImage(segM.getCropped(imgC->image()), tr("Page Cropped"));
	}
	// save to metadata
	if(runID == mRunIDs[id_crop_to_metadata]) {
		
		if (segM.getRects().empty())
			imgC = QSharedPointer<nmc::DkImageContainer>();	// notify parent
		else {
			nmc::DkRotatingRect rect = segM.getMaxRect().toRotatingRect();
			
			QSharedPointer<nmc::DkMetaDataT> m = imgC->getMetaData();
			m->saveRectToXMP(rect, imgC->image().size());
		}
	}
	// draw rectangles to the image
	else if(runID == mRunIDs[id_draw_to_page]) {
		
		QImage dImg = imgC->image();
		segM.draw(dImg);
		imgC->setImage(dImg, tr("Page Annotated"));
	}
	else if (runID == mRunIDs[id_eval_page]) {

		QImage dImg = imgC->image();

		QPolygonF gt = readGT(imgC->filePath());
		
		QPen pen(QColor(100, 200, 50));
		pen.setWidth(10);
		QPainter p(&dImg);
		p.setPen(pen);
		p.drawPolygon(gt);
		p.end();

		segM.draw(dImg);
		imgC->setImage(dImg, tr("Result vs GT"));

		double ji = jaccardIndex(imgC->image().size(), gt, segM.getMaxRect().toPolygon());

		QString data = imgC->fileName() + ", " + QString::number(ji) + "\n";
		qDebug() << data;

		QFile file(mResultPath);
		file.open(QIODevice::WriteOnly | QIODevice::Append);
		QTextStream stream(&file);
		stream << data;
		qInfo() << "results written to" << mResultPath;

	}

	// wrong runID? - do nothing
	return imgC;
}