Commit 5195da04 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix motion tracker broken on reset or subsequent analyse requests, remove...

Fix motion tracker broken on reset or subsequent analyse requests, remove Boosting algorithm (not ported to MLT's filter)
Fixes #1204 #1209
parent a24b8fe2
......@@ -9,7 +9,7 @@
<parameter type="fixed" name="out" max="99999" min="0" default="%out">
<name>Out</name>
</parameter>
<parameter type="multiswitch" name="level&#10;alpha" value="1&#10;0=1;-1=0" min="1&#10;0=1;-1=0" max="0=1;-1=0&#10;1">
<parameter type="multiswitch" name="level&#10;alpha" default="1&#10;0=1;-1=0" min="1&#10;0=1;-1=0" max="0=1;-1=0&#10;1">
<name>Fade to Black</name>
</parameter>
</effect>
<!DOCTYPE kpartgui>
<group>
<effect tag="opencv.tracker" id="opencv.tracker" condition="results" sync_in_out="1">
<name>Motion Tracker</name>
<description>Select a zone to follow its movements</description>
<author>Jean-Baptiste Mardelle</author>
<parameter type="geometry" name="rect" default="50%,50%:25%x25%" fixed="1" opacity="false" conditional="1">
<name>Rectangle</name>
</parameter>
<parameter type="list" name="algo" default="KCF" paramlist="KCF;MIL;BOOSTING;TLD" conditional="1">
<paramlistdisplay>KCF,MIL,Boosting,TLD</paramlistdisplay>
<name>Tracker algorithm</name>
</parameter>
<parameter type="constant" name="steps" default="5" min="0" max="120">
<name>Keyframes spacing</name>
<comment>Defines the frequency of stored keyframes. A keyframe is created every steps frames.</comment>
</parameter>
<parameter type="list" name="shape" default="0" paramlist="0;1;2">
<paramlistdisplay>Rectangle,Ellipse,Arrow</paramlistdisplay>
<name>Frame shape</name>
</parameter>
<parameter type="constant" name="shape_width" max="100" min="-1" default="1" suffix="pixels">
<name>Shape width</name>
</parameter>
<parameter type="color" name="shape_color" default="0xff0000ff">
<name>Shape color</name>
</parameter>
<parameter type="constant" name="blur" max="200" min="0" default="0">
<name>Blur</name>
</parameter>
<parameter type="list" name="blur_type" default="0" paramlist="0;1">
<paramlistdisplay>Median Blur,Gaussian Blur</paramlistdisplay>
<name>Blur type</name>
</parameter>
<parameter type="readonly" name="results" value="">
<name>Tracking data</name>
<comment>Click to copy to clipboard</comment>
</parameter>
<parameter type="filterjob" filtertag="opencv.tracker" consumer="null" consumerparams=" all=1 terminate_on_pause=1">
<name conditional="Reset">Analyse</name>
<jobparam name="conditionalinfo">Filter is in preview mode. Click Analyse to see real effect</jobparam>
<jobparam name="key">results</jobparam>
<jobparam name="finalfilter">opencv.tracker</jobparam>
<jobparam name="displaydataname">Motion tracking</jobparam>
</parameter>
</effect>
<effect tag="opencv.tracker" id="opencv.tracker" condition="results" sync_in_out="1" version="2">
<name>Motion Tracker</name>
<description>Select a zone to follow its movements</description>
<author>Jean-Baptiste Mardelle</author>
<parameter type="animatedrect" name="results" default="50% 50% 25% 25%" opacity="false" conditional="1">
<parameter type="animatedrect" name="results" opacity="false" conditional="1" default="50% 50% 25% 25%">
<name>Rectangle</name>
</parameter>
<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>
<parameter type="listdependency" name="algo" default="KCF" paramlist="KCF;CSRT;MOSSE;MIL;MEDIANFLOW;DaSIAM" conditional="1">
<paramlistdisplay>KCF,CSRT,MOSSE,MIL,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>
......@@ -79,6 +34,8 @@
</parameter>
<parameter type="hidden" name="modelsfolder" default="">
</parameter>
<parameter type="hidden" name="rect" default="50% 50% 25% 25%">
</parameter>
<parameter type="filterjob" filtertag="opencv.tracker" consumer="null" consumerparams="all=1 terminate_on_pause=1 audio_off=1 no_meta=1 real_time=-1">
<name conditional="Reset">Analyse</name>
<jobparam name="conditionalinfo">Filter is in preview mode. Click Analyse to see real effect</jobparam>
......@@ -89,4 +46,3 @@
<jobparam name="displaydataname">Motion tracking</jobparam>
</parameter>
</effect>
</group>
......@@ -341,11 +341,13 @@ void AssetParameterModel::internalSetParameter(const QString &name, const QStrin
if (m_fixedParams.count(name) == 0) {
m_params[name].value = paramValue;
if (m_keyframes) {
// This is a fake query to force the animation to be parsed
(void)m_asset->anim_get_int(name.toLatin1().constData(), 0, -1);
KeyframeModel *km = m_keyframes->getKeyModel(paramIndex);
if (km) {
km->refresh();
} else {
qDebug()<<"====ERROR KFMODEL NOT FOUND FOR: "<<paramIndex;
qDebug()<<"====ERROR KFMODEL NOT FOUND FOR: "<<name<<", "<<paramIndex;
}
//m_keyframes->refresh();
}
......@@ -527,9 +529,14 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
return values.join(QLatin1Char('\n'));
}
QString value(m_asset->get(paramName.toUtf8().constData()));
return value.isEmpty() ? (element.attribute(QStringLiteral("value")).isNull() ? parseAttribute(m_ownerId, QStringLiteral("default"), element)
: element.attribute(QStringLiteral("value")))
: value;
if (value.isEmpty()) {
if (element.hasAttribute("default")) {
return parseAttribute(m_ownerId, QStringLiteral("default"), element);
} else {
value = element.attribute(QStringLiteral("value"));
}
}
return value;
}
case ListValuesRole:
return element.attribute(QStringLiteral("paramlist")).split(QLatin1Char(';'));
......
......@@ -83,9 +83,47 @@ ButtonParamWidget::ButtonParamWidget(std::shared_ptr<AssetParameterModel> model,
// emit the signal of the base class when appropriate
connect(this->m_button, &QPushButton::clicked, this, [&, filterData, filterAddedParams, consumerParams, defaultValue]() {
// Trigger job
bool isTracker = m_model->getAssetId() == QLatin1String("opencv.tracker");
if (!m_displayConditional) {
QVector<QPair<QString, QVariant>> values;
values << QPair<QString, QVariant>(m_keyParam,defaultValue);
if (isTracker) {
// Tracker needs some special config on reset
QString current = m_model->getAsset()->get(m_keyParam.toUtf8().constData());
if (!current.isEmpty()) {
// Extract first keyframe
current = current.section(QLatin1Char('='), 1);
current = current.section(QLatin1Char(';'), 0, 0);
}
if (current.isEmpty()) {
if (defaultValue.contains(QLatin1Char('%'))) {
QSize pSize = pCore->getCurrentFrameDisplaySize();
QStringList numbers = defaultValue.split(QLatin1Char(' '));
int ix = 0;
for ( QString &val : numbers) {
if (val.endsWith(QLatin1Char('%'))) {
val.chop(1);
double n = val.toDouble()/100.;
if (ix %2 == 0) {
n *= pSize.width();
} else {
n *= pSize.height();
}
ix++;
current.append(QString("%1 ").arg(qRound(n)));
} else {
current.append(QString("%1 ").arg(val));
}
}
} else {
current = defaultValue;
}
}
values << QPair<QString, QVariant>(QString("rect"),current);
values << QPair<QString, QVariant>(m_keyParam,current);
values << QPair<QString, QVariant>(QString("_reset"),1);
} else {
values << QPair<QString, QVariant>(m_keyParam,defaultValue);
}
auto *command = new AssetUpdateCommand(m_model, values);
pCore->pushUndo(command);
return;
......@@ -118,8 +156,10 @@ ButtonParamWidget::ButtonParamWidget(std::shared_ptr<AssetParameterModel> model,
}
for (const auto &param : qAsConst(filterLastParams)) {
if (param.first != m_keyParam) {
fParams.insert({param.first, param.second});
} else {
if (!isTracker || param.first != QLatin1String("rect")) {
fParams.insert({param.first, param.second});
}
} else if (isTracker) {
QString initialRect = param.second.toString();
if (initialRect.contains(QLatin1Char('='))) {
initialRect = initialRect.section(QLatin1Char('='), 1);
......@@ -127,7 +167,6 @@ ButtonParamWidget::ButtonParamWidget(std::shared_ptr<AssetParameterModel> model,
if (initialRect.contains(QLatin1Char(';'))) {
initialRect = initialRect.section(QLatin1Char(';'), 0, 0);
}
qDebug()<<"=== PASSING INITIAL RECT: "<<initialRect;
fParams.insert({QStringLiteral("rect"), initialRect});
}
}
......
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