Commit 8df33bb0 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Various fixes for motion tracker effect, add the new DaSIAM model, requires to...

Various fixes for motion tracker effect, add the new DaSIAM model, requires to download some extra model files
parent 00ff8378
......@@ -51,9 +51,10 @@
<parameter type="geometry" name="rect" default="50% 50% 25% 25%" fixed="1" opacity="false" conditional="1">
<name>Rectangle</name>
</parameter>
<parameter type="list" name="algo" default="KCF" paramlist="KCF;CSRT;MOSSE;MIL;BOOSTING;TLD" conditional="1">
<paramlistdisplay>KCF,CSRT,MOSSE,MIL,Boosting,TLD</paramlistdisplay>
<parameter type="listdependency" name="algo" default="KCF" paramlist="KCF;CSRT;MOSSE;MIL;BOOSTING;MEDIANFLOW;DaSIAM" conditional="1">
<paramlistdisplay>KCF,CSRT,MOSSE,MIL,Boosting,MedianFlow,DaSIAM</paramlistdisplay>
<name>Tracker algorithm</name>
<paramdependencies value="DaSIAM" files="dasiamrpn_model.onnx;dasiamrpn_kernel_r1.onnx;dasiamrpn_kernel_cls1.onnx" folder="/opencvmodels">Required model files for DaSiam Tracker not found in &lt;a href="file://%folder"&gt;models folder&lt;/a&gt;. Check our &lt;a href="https://kdenlive.org"&gt;wiki&lt;/a&gt; for instructions.</paramdependencies>
</parameter>
<parameter type="constant" name="steps" default="5" min="0" max="120">
<name>Keyframes spacing</name>
......@@ -76,6 +77,8 @@
<paramlistdisplay>Median Blur,Gaussian Blur</paramlistdisplay>
<name>Blur type</name>
</parameter>
<parameter type="hidden" name="modelsfolder" default="">
</parameter>
<parameter type="readonly" name="results" value="">
<name>Tracking data</name>
<comment>Click to copy to clipboard</comment>
......
......@@ -30,6 +30,7 @@ set(kdenlive_SRCS
assets/view/widgets/keyframeimport.cpp
assets/view/widgets/keyframewidget.cpp
assets/view/widgets/listparamwidget.cpp
assets/view/widgets/listdependencyparamwidget.cpp
assets/view/widgets/geometryeditwidget.cpp
assets/view/widgets/positioneditwidget.cpp
assets/view/widgets/coloreditwidget.cpp
......
......@@ -153,6 +153,7 @@ AssetParameterModel::AssetParameterModel(std::unique_ptr<Mlt::Properties> asset,
case ParamType::Double:
case ParamType::Hidden:
case ParamType::List:
case ParamType::ListWithDependency:
// Despite its name, a list type parameter is a single value *chosen from* a list.
// If it contains a non-“.” decimal separator, it is very likely wrong.
// Fall-through, treat like Double
......@@ -548,10 +549,25 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
}
case ListValuesRole:
return element.attribute(QStringLiteral("paramlist")).split(QLatin1Char(';'));
case InstalledValuesRole:
return m_asset->get("kdenlive:paramlist");
case ListNamesRole: {
QDomElement namesElem = element.firstChildElement(QStringLiteral("paramlistdisplay"));
return i18n(namesElem.text().toUtf8().data()).split(QLatin1Char(','));
}
case ListDependenciesRole: {
QDomNodeList dependencies = element.elementsByTagName(QStringLiteral("paramdependencies"));
if (!dependencies.isEmpty()) {
QDomDocument doc;
QDomElement d = doc.createElement(QStringLiteral("deps"));
doc.appendChild(d);
for (int i = 0; i < dependencies.count(); i++) {
d.appendChild(doc.importNode(dependencies.at(i), true));
}
return doc.toString();
}
return QVariant();
}
case NewStuffRole:
return element.attribute(QStringLiteral("newstuff"));
case ModeRole:
......@@ -616,6 +632,9 @@ ParamType AssetParameterModel::paramTypeFromStr(const QString &type)
if (type == QLatin1String("list")) {
return ParamType::List;
}
if (type == QLatin1String("listdependency")) {
return ParamType::ListWithDependency;
}
if (type == QLatin1String("urllist")) {
return ParamType::UrlList;
}
......
......@@ -39,6 +39,7 @@ typedef QVector<QPair<QString, QVariant>> paramVector;
enum class ParamType {
Double,
List, // Value can be chosen from a list of pre-defined ones
ListWithDependency, // Value can be chosen from a list of pre-defined ones. Some values might not be available due to missing dependencies
UrlList, // File can be chosen from a list of pre-defined ones or a custom file can be used (like url)
Bool,
Switch,
......@@ -106,7 +107,9 @@ public:
ValueRole,
AlphaRole,
ListValuesRole,
InstalledValuesRole,
ListNamesRole,
ListDependenciesRole,
NewStuffRole,
ModeRole,
FactorRole,
......
......@@ -34,6 +34,7 @@
#include "hideparamwidget.hpp"
#include "keyframewidget.hpp"
#include "listparamwidget.h"
#include "listdependencyparamwidget.h"
#include "lumaliftgainparam.hpp"
#include "positioneditwidget.hpp"
#include "slidewidget.hpp"
......@@ -85,6 +86,9 @@ AbstractParamWidget *AbstractParamWidget::construct(const std::shared_ptr<AssetP
case ParamType::Double:
widget = new DoubleParamWidget(model, index, parent);
break;
case ParamType::ListWithDependency:
widget = new ListDependencyParamWidget(model, index, parent);
break;
case ParamType::List:
widget = new ListParamWidget(model, index, parent);
break;
......
/***************************************************************************
* Copyright (C) 2021 by Jean-Baptiste Mardelle *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "listdependencyparamwidget.h"
#include "assets/model/assetparametermodel.hpp"
#include "core.h"
#include "mainwindow.h"
#include <QDomDocument>
#include <QDomElement>
#include <QStandardPaths>
#include <QDir>
#include <kio_version.h>
#if KIO_VERSION > QT_VERSION_CHECK(5, 70, 0)
#include <KIO/OpenUrlJob>
#include <KIO/JobUiDelegate>
#else
#include <KRun>
#endif
ListDependencyParamWidget::ListDependencyParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent)
: AbstractParamWidget(std::move(model), index, parent)
{
setupUi(this);
// Get data from model
QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString();
// setup the comment
setToolTip(comment);
m_infoMessage->hide();
connect(m_infoMessage, &KMessageWidget::linkActivated, [this](const QString &contents) {
#if KIO_VERSION > QT_VERSION_CHECK(5, 70, 0)
auto *job = new KIO::OpenUrlJob(QUrl(contents));
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
// methods like setRunExecutables, setSuggestedFilename, setEnableExternalBrowser, setFollowRedirections
// exist in both classes
job->start();
#else
new KRun(QUrl(contents), this);
#endif
});
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_list->setIconSize(QSize(50, 30));
setMinimumHeight(m_list->sizeHint().height());
// setup the name
m_labelName->setText(m_model->data(m_index, Qt::DisplayRole).toString());
QString dependencies = m_model->data(m_index, AssetParameterModel::ListDependenciesRole).toString();
if (!dependencies.isEmpty()) {
// We have conditionnal dependencies, some values in the list might not be available. Check if the dependencies were already parsed
QStringList checkedNames = m_model->data(m_index, AssetParameterModel::InstalledValuesRole).toStringList();
QDomDocument doc;
doc.setContent(dependencies);
QDomNodeList deps = doc.elementsByTagName(QLatin1String("paramdependencies"));
for (int i = 0; i < deps.count(); i++) {
const QString modelName = deps.at(i).toElement().attribute(QLatin1String("value"));
QString infoText = deps.at(i).toElement().text();
const QString folder = deps.at(i).toElement().attribute(QLatin1String("folder"));
if (!folder.isEmpty()) {
m_dependencyFiles.insert(modelName, {folder, deps.at(i).toElement().attribute(QLatin1String("files")).split(QLatin1Char(';'))});
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + folder);
infoText.replace(QLatin1String("\%folder"), dir.absolutePath());
}
m_dependencyInfos.insert(modelName, infoText);
}
}
slotRefresh();
// emit the signal of the base class when appropriate
connect(this->m_list, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, [this](int) {
const QString val = m_list->itemData(m_list->currentIndex()).toString();
emit valueChanged(m_index, val, true);
checkDependencies(val);
});
}
void ListDependencyParamWidget::setCurrentIndex(int index)
{
m_list->setCurrentIndex(index);
}
void ListDependencyParamWidget::setCurrentText(const QString &text)
{
m_list->setCurrentText(text);
}
void ListDependencyParamWidget::addItem(const QString &text, const QVariant &value)
{
m_list->addItem(text, value);
}
void ListDependencyParamWidget::setItemIcon(int index, const QIcon &icon)
{
m_list->setItemIcon(index, icon);
}
void ListDependencyParamWidget::setIconSize(const QSize &size)
{
m_list->setIconSize(size);
}
void ListDependencyParamWidget::slotShowComment(bool /*show*/)
{
}
QString ListDependencyParamWidget::getValue()
{
return m_list->currentData().toString();
}
void ListDependencyParamWidget::checkDependencies(const QString &val)
{
bool missingDep = false;
if (m_dependencyInfos.contains(val)) {
// Check dependency
if (m_dependencyFiles.contains(val)) {
QPair<QString, QStringList> fileData = m_dependencyFiles.value(val);
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + fileData.first);
if (fileData.first == QLatin1String("/opencvmodels")) {
m_model->setParameter(QStringLiteral("modelsfolder"), dir.absolutePath(), false);
}
for (const QString &file : fileData.second) {
if (!dir.exists(file)) {
m_infoMessage->setText(m_dependencyInfos.value(val));
m_infoMessage->animatedShow();
setMinimumHeight(m_list->sizeHint().height() + m_infoMessage->sizeHint().height());
emit updateHeight();
missingDep = true;
break;
}
}
}
}
if (!missingDep) {
m_infoMessage->hide();
setMinimumHeight(m_list->sizeHint().height());
emit updateHeight();
}
}
void ListDependencyParamWidget::slotRefresh()
{
const QSignalBlocker bk(m_list);
m_list->clear();
QStringList names = m_model->data(m_index, AssetParameterModel::ListNamesRole).toStringList();
QStringList values = m_model->data(m_index, AssetParameterModel::ListValuesRole).toStringList();
QString value = m_model->data(m_index, AssetParameterModel::ValueRole).toString();
if (value != m_lastProcessedAlgo) {
// Ensure dependencies are met
checkDependencies(value);
}
m_lastProcessedAlgo = value;
if (values.first() == QLatin1String("%lumaPaths")) {
// Special case: Luma files
// Create thumbnails
if (pCore->getCurrentFrameSize().width() > 1000) {
// HD project
values = MainWindow::m_lumaFiles.value(QStringLiteral("16_9"));
} else if (pCore->getCurrentFrameSize().height() > 1000) {
values = MainWindow::m_lumaFiles.value(QStringLiteral("9_16"));
} else if (pCore->getCurrentFrameSize().height() == pCore->getCurrentFrameSize().width()) {
values = MainWindow::m_lumaFiles.value(QStringLiteral("square"));
} else if (pCore->getCurrentFrameSize().height() == 480) {
values = MainWindow::m_lumaFiles.value(QStringLiteral("NTSC"));
} else {
values = MainWindow::m_lumaFiles.value(QStringLiteral("PAL"));
}
m_list->addItem(i18n("None (Dissolve)"));
for (int j = 0; j < values.count(); ++j) {
const QString &entry = values.at(j);
const QString name = values.at(j).section(QLatin1Char('/'), -1);
m_list->addItem(pCore->nameForLumaFile(name), entry);
if (!entry.isEmpty() && (entry.endsWith(QLatin1String(".png")) || entry.endsWith(QLatin1String(".pgm")))) {
if (MainWindow::m_lumacache.contains(entry)) {
m_list->setItemIcon(j + 1, QPixmap::fromImage(MainWindow::m_lumacache.value(entry)));
}
}
}
if (!value.isEmpty() && values.contains(value)) {
m_list->setCurrentIndex(values.indexOf(value) + 1);
}
} else {
if (names.count() != values.count()) {
names = values;
}
for (int i = 0; i < names.count(); i++) {
m_list->addItem(names.at(i), values.at(i));
}
if (!value.isEmpty()) {
int ix = m_list->findData(value);
if (ix > -1) {
m_list->setCurrentIndex(ix);
}
}
}
}
/***************************************************************************
* Copyright (C) 2021 by Jean-Baptiste Mardelle *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef LISTDEPPARAMWIDGET_H
#define LISTDEPPARAMWIDGET_H
#include "assets/view/widgets/abstractparamwidget.hpp"
#include "ui_listdependencyparamwidget_ui.h"
#include <QVariant>
#include <QWidget>
class AssetParameterModel;
/** @brief This class represents a parameter that requires
the user to choose a value from a list
*/
class ListDependencyParamWidget : public AbstractParamWidget, public Ui::ListDependencyParamWidget_UI
{
Q_OBJECT
public:
/** @brief Constructor for the widgetComment
@param name String containing the name of the parameter
@param comment Optional string containing the comment associated to the parameter
@param parent Parent widget
*/
ListDependencyParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent);
/** @brief Set the index of the current displayed element
@param index Integer holding the index of the target element (0-indexed)
*/
void setCurrentIndex(int index);
/** @brief Set the text currently displayed on the list
@param text String containing the text of the element to show
*/
void setCurrentText(const QString &text);
/** @brief Add an item to the list.
@param text String to be displayed in the list
@param value Underlying value corresponding to the text
*/
void addItem(const QString &text, const QVariant &value = QVariant());
/** @brief Set the icon of a given element
@param index Integer holding the index of the target element (0-indexed)
@param icon The corresponding icon
*/
void setItemIcon(int index, const QIcon &icon);
/** @brief Set the size of the icons shown in the list
@param size Target size of the icon
*/
void setIconSize(const QSize &size);
/** @brief Returns the current value of the parameter
*/
QString getValue();
public slots:
/** @brief Toggle the comments on or off
*/
void slotShowComment(bool show) override;
/** @brief refresh the properties to reflect changes in the model
*/
void slotRefresh() override;
private:
QString m_lastProcessedAlgo;
QMap<QString, QString> m_dependencyInfos;
QMap<QString, QPair<QString,QStringList> >m_dependencyFiles;
void checkDependencies(const QString &val);
};
#endif
......@@ -125,7 +125,6 @@ void FilterTask::run()
pCore->taskManager.taskDone(m_owner.second, this);
return;
}
length = producer->get_playtime();
if (length == 0) {
length = producer->get_length();
......@@ -169,6 +168,9 @@ void FilterTask::run()
qDebug()<<" = = = = = CONFIGURING FILTER PARAMS = = = = = ";
for (const auto &it : m_filterParams) {
qDebug()<<". . ."<<it.first<<" = "<<it.second;
if (it.first == QLatin1String("in") || it.first == QLatin1String("out")) {
continue;
}
if (it.second.type() == QVariant::Double) {
filter.set(it.first.toUtf8().constData(), it.second.toDouble());
} else {
......@@ -218,7 +220,6 @@ void FilterTask::run()
dom.clear();
// Step 2: process the xml file and save in another .mlt file
QProcess filterProcess;
QStringList args({QStringLiteral("progress=1"), sourceFile.fileName()});
m_jobProcess.reset(new QProcess);
QObject::connect(this, &AbstractTask::jobCanceled, m_jobProcess.get(), &QProcess::kill, Qt::DirectConnection);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment