void Interface::connection(void) { QObject::connect(clearButton, SIGNAL(clicked()), this, SLOT(clearImage())); QObject::connect(saveButton, SIGNAL(clicked()), this, SLOT(saveImage())); QObject::connect(evaluateButton, SIGNAL(clicked()), this, SLOT(evaluateImage())); QObject::connect(penWidthSlider, SIGNAL(sliderReleased()), this, SLOT(penWidthChanged())); }
int main(int argc, char *argv[]) { spawn_worker_threads(2); gui_init(&argc, &argv); progress = gui_progress; Image im = Image::read(argv[1]); gui_status("looking for pois"); std::vector<float> scales; scales.push_back(1); scales.push_back(3); scales.push_back(8); Array2D<float> eval = evaluateImage(im, scales, 16); POIvec all = extractPOIs(eval, 30); POIvec pois = filterPOIs(all, 60) ; ImageDisplaySlot evalds("evaluation", rgba(1,0,0,1)); evalds.ci = gui_upload(visualizeEvaluation(eval)); evalds.activate(); ImageDisplaySlot imds("image & pois", rgba(.1,1,.1,.5)); imds.ci = gui_upload(im); imds.ps = std::vector<Point>(pois.begin(), pois.end()); imds.bind(); gui_status("building proximity info"); ProximityMap pm; pm.resize(im.getWidth(), im.getHeight(), 1, 8); pm.build(pois); ImageDisplaySlot proxds("proximity", rgba(1,1,1,1)); proxds.ci = gui_upload(pm.visualize()); proxds.ps = imds.ps; proxds.dotsize = 3; proxds.bind(); info("done"); pause(); return 0; }
void FindImageInstance::startExecution() { bool ok = true; mSource = evaluateListElement<Source>(ok, sources, QStringLiteral("source")); mImageToFind = evaluateImage(ok, QStringLiteral("imageToFind")); mIfFound = evaluateIfAction(ok, QStringLiteral("ifFound")); mIfNotFound = evaluateIfAction(ok, QStringLiteral("ifNotFound")); mPositionVariableName = evaluateVariable(ok, QStringLiteral("position")); mMethod = evaluateListElement<Method>(ok, methods, QStringLiteral("method")); mWindowRelativePosition = evaluateBoolean(ok, QStringLiteral("windowRelativePosition")); mConfidenceMinimum = evaluateInteger(ok, QStringLiteral("confidenceMinimum")); mMaximumMatches = evaluateInteger(ok, QStringLiteral("maximumMatches")); mDownPyramidCount = evaluateInteger(ok, QStringLiteral("downPyramidCount")); mSearchExpansion = evaluateInteger(ok, QStringLiteral("searchExpansion")); mConfidenceVariableName = evaluateVariable(ok, QStringLiteral("confidence")); mSearchDelay = evaluateInteger(ok, QStringLiteral("searchDelay")); if(!ok) return; validateParameterRange(ok, mConfidenceMinimum, QStringLiteral("confidenceMinimum"), tr("minimum confidence"), 0, 100); validateParameterRange(ok, mMaximumMatches, QStringLiteral("maximumMatches"), tr("maximum matches"), 1); validateParameterRange(ok, mDownPyramidCount, QStringLiteral("downPyramidCount"), tr("downsampling"), 1); validateParameterRange(ok, mSearchExpansion, QStringLiteral("searchExpansion"), tr("search expansion"), 1); if(!ok) return; if(mImageToFind.isNull()) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Invalid image to find")); return; } startSearching(); }
void FindImageInstance::startSearching() { mOpenCVAlgorithms->cancelSearch(); mImagesToSearchIn.clear(); switch(mSource) { case ScreenshotSource: mImagesToSearchIn = ActionTools::ScreenShooter::captureScreens(); break; case WindowSource: { bool ok = true; QString windowName = evaluateString(ok, QStringLiteral("windowName")); if(!ok) return; mWindows = ActionTools::WindowHandle::findWindows(QRegExp(windowName, Qt::CaseSensitive, QRegExp::WildcardUnix)); if(mWindows.isEmpty()) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Unable to find any window named %1").arg(windowName)); return; } mImagesToSearchIn = ActionTools::ScreenShooter::captureWindows(mWindows); } break; case ImageSource: { bool ok = true; QImage imageToSearchIn = evaluateImage(ok, QStringLiteral("imageToSearchIn")); if(!ok) return; if(imageToSearchIn.isNull()) { emit executionException(ActionTools::ActionException::InvalidParameterException, tr("Invalid image to search in")); return; } mImagesToSearchIn.append(std::make_pair(QPixmap::fromImage(imageToSearchIn), imageToSearchIn.rect())); } break; } QList<QImage> sourceImages; sourceImages.reserve(mImagesToSearchIn.size()); for(const auto &imageToSearchIn: mImagesToSearchIn) sourceImages.append(imageToSearchIn.first.toImage()); if(!mOpenCVAlgorithms->findSubImageAsync(sourceImages, mImageToFind, mConfidenceMinimum, mMaximumMatches, mDownPyramidCount, mSearchExpansion, static_cast<ActionTools::OpenCVAlgorithms::AlgorithmMethod>(mMethod))) { emit executionException(ErrorWhileSearchingException, tr("Error while searching: %1").arg(mOpenCVAlgorithms->errorString())); return; } }
void MultiDataInputInstance::startExecution() { bool ok = true; QString question = evaluateString(ok, QStringLiteral("question")); mMode = evaluateListElement<Mode>(ok, modes, QStringLiteral("mode")); mItems = evaluateItemList(ok, QStringLiteral("items")); QString defaultValue = evaluateString(ok, QStringLiteral("defaultValue")); mVariable = evaluateVariable(ok, QStringLiteral("variable")); QString windowTitle = evaluateString(ok, QStringLiteral("windowTitle")); QImage windowIcon = evaluateImage(ok, QStringLiteral("windowIcon")); mMaximumChoiceCount = evaluateInteger(ok, QStringLiteral("maximumChoiceCount")); if(!ok) return; if(mDialog) delete mDialog; mDialog = new QDialog; mDialog->setWindowFlags(mDialog->windowFlags() | Qt::WindowContextHelpButtonHint); auto layout = new QVBoxLayout(mDialog); mDialog->setLayout(layout); mDialog->setWindowTitle(windowTitle); if(!windowIcon.isNull()) mDialog->setWindowIcon(QIcon(QPixmap::fromImage(windowIcon))); QLabel *questionLabel = new QLabel(mDialog); questionLabel->setText(question); layout->addWidget(questionLabel); switch(mMode) { case ComboBoxMode: case EditableComboBoxMode: { mComboBox = new QComboBox(mDialog); mComboBox->addItems(mItems); int currentItem = mComboBox->findText(defaultValue); if(currentItem == -1) currentItem = 0; mComboBox->setCurrentIndex(currentItem); mComboBox->setEditable(mMode == EditableComboBoxMode); layout->addWidget(mComboBox); } break; case ListMode: { mListWidget = new QListWidget(mDialog); if(mMaximumChoiceCount <= 1) mListWidget->setSelectionMode(QAbstractItemView::SingleSelection); else mListWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); mListWidget->addItems(mItems); QList<QListWidgetItem *> defaultItem = mListWidget->findItems(defaultValue, Qt::MatchExactly); if(!defaultItem.isEmpty()) mListWidget->setCurrentItem(defaultItem.first()); layout->addWidget(mListWidget); if(mMaximumChoiceCount > 1) connect(mListWidget, &QListWidget::itemSelectionChanged, this, &MultiDataInputInstance::listItemSelectionChanged); } break; case CheckboxMode: layout->addLayout(createRadioButtonsOrCheckboxes<QCheckBox>(defaultValue, mMaximumChoiceCount <= 1)); break; case RadioButtonMode: layout->addLayout(createRadioButtonsOrCheckboxes<QRadioButton>(defaultValue, true)); break; } if(mMode != ListMode) layout->addStretch(1); QDialogButtonBox *dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, mDialog); layout->addWidget(dialogButtonBox); connect(dialogButtonBox, &QDialogButtonBox::accepted, mDialog, &QDialog::accept); connect(dialogButtonBox, &QDialogButtonBox::rejected, mDialog, &QDialog::reject); connect(mDialog, &QDialog::accepted, this, &MultiDataInputInstance::accepted); connect(mDialog, &QDialog::rejected, this, &MultiDataInputInstance::rejected); for(QLabel *label: mDialog->findChildren<QLabel*>()) label->setOpenExternalLinks(true); mDialog->show(); }
void MessageBoxInstance::startExecution() { bool ok = true; QString message = evaluateString(ok, "message"); QString title = evaluateString(ok, "title"); Icon icon = evaluateListElement<Icon>(ok, icons, "icon"); TextMode textMode = evaluateListElement<TextMode>(ok, textmodes, "textMode"); Buttons button = evaluateListElement<Buttons>(ok, buttons, "type"); QImage customIcon = evaluateImage(ok, "customIcon"); QImage windowIcon = evaluateImage(ok, "windowIcon"); mIfYes = evaluateIfAction(ok, "ifYes"); mIfNo = evaluateIfAction(ok, "ifNo"); mMessageBox = 0; if(!ok) return; mMessageBox = new QMessageBox(); mMessageBox->setIcon(messageBoxIcon(icon)); mMessageBox->setWindowModality(Qt::NonModal); mMessageBox->setText(message); mMessageBox->setWindowTitle(title); mMessageBox->setWindowFlags(mMessageBox->windowFlags() | Qt::WindowContextHelpButtonHint); switch(textMode) { case HtmlTextMode: mMessageBox->setTextFormat(Qt::RichText); break; case PlainTextMode: mMessageBox->setTextFormat(Qt::PlainText); break; case AutoTextMode: default: mMessageBox->setTextFormat(Qt::AutoText); break; } if(!customIcon.isNull()) mMessageBox->setIconPixmap(QPixmap::fromImage(customIcon)); if(!windowIcon.isNull()) mMessageBox->setWindowIcon(QPixmap::fromImage(windowIcon)); switch(button) { case OkButton: mMessageBox->setStandardButtons(QMessageBox::Ok); break; case YesNoButtons: mMessageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No); break; } mMessageBox->adjustSize(); QRect screenGeometry = QApplication::desktop()->availableGeometry(); mMessageBox->move(screenGeometry.center()); mMessageBox->move(mMessageBox->pos().x() - mMessageBox->width()/2, mMessageBox->pos().y() - mMessageBox->height()/2); mMessageBox->open(this, SLOT(buttonClicked())); }