pid_t *collect_processes(struct pc_conditional **pcc) { emutex_lock (&process_kill_command_mutex); pid_t *ret = NULL; process_status_updater pse = function_find_one("einit-process-status-updater", 1, NULL); uint32_t i; if (!pcc) return NULL; if (pse) { struct process_status **nps = pse (ps); free (ps); ps = nps; } if (ps) for (i = 0; pcc[i]; i++) { process_filter pf = NULL; const char *pm[2] = { (pcc[i]->match), NULL }; if (!(pcc[i]->match)) continue; pf = function_find_one("einit-process-filter", 1, pm); if (pf) ret = pf (pcc[i], ret, ps); } emutex_unlock (&process_kill_command_mutex); return ret; }
void LayoutTest::testLayout(const cv::Mat & src) const { // TODOS // - line spacing needs smoothing -> graphcut // - DBScan is very sensitive to the line spacing // Workflow: // - implement noise/text etc classification on SuperPixel level // - smooth labels using graphcut // - perform everything else without noise pixels // Training: // - open mode (whole image only contains e.g. machine printed) // - baseline mode -> overlap with superpixel cv::Mat img = src.clone(); //cv::resize(src, img, cv::Size(), 0.25, 0.25, CV_INTER_AREA); Timer dt; // find super pixels rdf::SuperPixel superPixel(img); if (!superPixel.compute()) qWarning() << "could not compute super pixel!"; QVector<QSharedPointer<Pixel> > sp = superPixel.getSuperPixels(); // find local orientation per pixel rdf::LocalOrientation lo(sp); if (!lo.compute()) qWarning() << "could not compute local orientation"; // smooth estimation rdf::GraphCutOrientation pse(sp); if (!pse.compute()) qWarning() << "could not compute set orientation"; // pixel labeling QSharedPointer<SuperPixelModel> model = SuperPixelModel::read(mConfig.classifierPath()); //FeatureCollectionManager fcm = FeatureCollectionManager::read(mConfig.featureCachePath()); //// train classifier //SuperPixelTrainer spt(fcm); //if (!spt.compute()) // qCritical() << "could not train data..."; //auto model = spt.model(); SuperPixelClassifier spc(src, sp); spc.setModel(model); if (!spc.compute()) qWarning() << "could not classify SuperPixels"; //// find tab stops //rdf::TabStopAnalysis tabStops(sp); //if (!tabStops.compute()) // qWarning() << "could not compute text block segmentation!"; //// find text lines //rdf::TextLineSegmentation textLines(sp); //textLines.addLines(tabStops.tabStopLines(30)); // TODO: fix parameter //if (!textLines.compute()) // qWarning() << "could not compute text block segmentation!"; qInfo() << "algorithm computation time" << dt; // drawing //cv::Mat rImg(img.rows, img.cols, CV_8UC1, cv::Scalar::all(150)); cv::Mat rImg = img.clone(); //// draw edges //rImg = textBlocks.draw(rImg); //rImg = lo.draw(rImg, "1012", 256); //rImg = lo.draw(rImg, "507", 128); //rImg = lo.draw(rImg, "507", 64); //// save super pixel image //rImg = superPixel.drawSuperPixels(rImg); //rImg = tabStops.draw(rImg); //rImg = textLines.draw(rImg); rImg = spc.draw(rImg); QString maskPath = rdf::Utils::instance().createFilePath(mConfig.outputPath(), "-classified"); rdf::Image::save(rImg, maskPath); qDebug() << "debug image added" << maskPath; //// write XML ----------------------------------- //QString loadXmlPath = rdf::PageXmlParser::imagePathToXmlPath(mConfig.imagePath()); //rdf::PageXmlParser parser; //parser.read(loadXmlPath); //auto pe = parser.page(); //pe->setCreator(QString("CVL")); //pe->setImageSize(QSize(img.rows, img.cols)); //pe->setImageFileName(QFileInfo(mConfig.imagePath()).fileName()); //// start writing content //auto ps = PixelSet::fromEdges(PixelSet::connect(sp, Rect(0, 0, img.cols, img.rows))); //if (!ps.empty()) { // QSharedPointer<Region> textRegion = QSharedPointer<Region>(new Region()); // textRegion->setType(Region::type_text_region); // textRegion->setPolygon(ps[0]->convexHull()); // // for (auto tl : textLines.textLines()) { // textRegion->addUniqueChild(tl); // } // pe->rootRegion()->addUniqueChild(textRegion); //} //parser.write(mConfig.xmlPath(), pe); //qDebug() << "results written to" << mConfig.xmlPath(); }
void LayoutTest::layoutToXml() const { QImage imgQt(mConfig.imagePath()); cv::Mat img = Image::qImage2Mat(imgQt); Timer dt; // find super pixels rdf::SuperPixel superPixel(img); if (!superPixel.compute()) qWarning() << "could not compute super pixel!"; QVector<QSharedPointer<Pixel> > sp = superPixel.getSuperPixels(); // find local orientation per pixel rdf::LocalOrientation lo(sp); if (!lo.compute()) qWarning() << "could not compute local orientation"; // smooth estimation rdf::GraphCutOrientation pse(sp); if (!pse.compute()) qWarning() << "could not compute set orientation"; //// find tab stops //rdf::TabStopAnalysis tabStops(sp); //if (!tabStops.compute()) // qWarning() << "could not compute text block segmentation!"; // find text lines rdf::TextLineSegmentation textLines(sp); if (!textLines.compute()) qWarning() << "could not compute text block segmentation!"; qInfo() << "algorithm computation time" << dt; // drawing cv::Mat rImg = img.clone(); // save super pixel image //rImg = superPixel.drawSuperPixels(rImg); //rImg = tabStops.draw(rImg); rImg = textLines.draw(rImg); QString dstPath = rdf::Utils::instance().createFilePath(mConfig.outputPath(), "-textlines"); rdf::Image::save(rImg, dstPath); qDebug() << "debug image saved: " << dstPath; // write XML ----------------------------------- QString loadXmlPath = rdf::PageXmlParser::imagePathToXmlPath(mConfig.imagePath()); rdf::PageXmlParser parser; parser.read(loadXmlPath); auto pe = parser.page(); pe->setCreator(QString("CVL")); pe->setImageSize(QSize(img.rows, img.cols)); pe->setImageFileName(QFileInfo(mConfig.imagePath()).fileName()); // start writing content auto ps = PixelSet::fromEdges(PixelSet::connect(sp)); if (!ps.empty()) { QSharedPointer<Region> textRegion = QSharedPointer<Region>(new Region()); textRegion->setType(Region::type_text_region); textRegion->setPolygon(ps[0]->convexHull()); for (auto tl : textLines.textLines()) { textRegion->addUniqueChild(tl); } pe->rootRegion()->addUniqueChild(textRegion); } parser.write(mConfig.xmlPath(), pe); qDebug() << "results written to" << mConfig.xmlPath(); }