Skip to content

Commit

Permalink
モデル用フォルダを作成し、モデルはそこから読み込むよう変更 #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Ojii committed Jan 7, 2024
1 parent 65b7c80 commit 73d322f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 31 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ jobs:
move opencv/LICENSE Licenses/opencv.txt
move opencv_contrib/LICENSE Licenses/opencv_contrib.txt
move src/build/Release/MotionTrackingMKIIPlus.auf MotionTrackingMKIIPlus.auf
move opencv/data/haarcascades/haarcascade_frontalface_default.xml haarcascade_frontalface_default.xml
move opencv/data/haarcascades/haarcascade_profileface.xml haarcascade_profileface.xml
7z a MotionTrackingMKIIPlus.zip haarcascade_profileface.xml haarcascade_frontalface_default.xml MotionTrackingMKIIPlus.auf README.md README.ja.md Licenses
mkdir MotionTracking_model
move opencv/data/haarcascades/haarcascade_frontalface_default.xml MotionTracking_model/haarcascade_frontalface_default.xml
move opencv/data/haarcascades/haarcascade_profileface.xml MotionTracking_model/haarcascade_profileface.xml
7z a MotionTrackingMKIIPlus.zip haarcascade_profileface.xml haarcascade_frontalface_default.xml MotionTrackingMKIIPlus.auf README.md README.ja.md Licenses MotionTracking_model
- name: Upload artifact
uses: actions/upload-artifact@v4
Expand Down
10 changes: 5 additions & 5 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AviUtlでオブジェクトトラッキングを行うプラグイン


## インストール
zip内の.aufファイルと.xmlファイルを`aviutl.exeと同じディレクトリ`に置いてください。
zip内の.aufファイルとMotionTracking_modelディレクトリを`AviUtlがフィルタプラグインを読み込むお好きなディレクトリ`に置いてください。

AviUtlのフィルタメニューに"MotionTracking MK-II Plus"が追加されていたら成功です。

Expand All @@ -23,7 +23,7 @@ AviUtlのフィルタメニューに"MotionTracking MK-II Plus"が追加され
- goturn.caffemodel
- goturn.prototxt

`aviutl.exeと同じディレクトリ`に置いてください。
`MotionTracking_modelディレクトリ内`に置いてください。

### Method 5 (DaSiamRPN)用
[こちらのURL](https://github.com/opencv/opencv/blob/4.x/samples/dnn/dasiamrpn_tracker.cpp)のソースコードにコメントアウトとして記載されているURLより
Expand All @@ -32,22 +32,22 @@ AviUtlのフィルタメニューに"MotionTracking MK-II Plus"が追加され
- dasiamrpn_kernel_r1.onnx
- dasiamrpn_kernel_cls1.onnx

をダウンロードし、`aviutl.exeと同じディレクトリ`に置いてください。
をダウンロードし、`MotionTracking_modelディレクトリ内`に置いてください。

### Method 6 (Nano)用
[こちらのURL](https://github.com/HonglinChu/SiamTrackers/tree/18b7791360acb3f6d276d47376a6f1ed516f1628/NanoTrack/models/nanotrackv2)より

- nanotrack_backbone_sim.onnx
- nanotrack_head_sim.onnx

をダウンロードし、`aviutl.exeと同じディレクトリ`に置いてください。
をダウンロードし、`MotionTracking_modelディレクトリ内`に置いてください。

### Method 7 (Vit)用
[こちらのURL](https://github.com/opencv/opencv_extra/blob/4.x/testdata/dnn/onnx/models/vitTracker.onnx)より

- vitTracker.onnx

をダウンロードし、`aviutl.exeと同じディレクトリ`に置いてください。
をダウンロードし、`MotionTracking_modelディレクトリ内`に置いてください。

## ヘルパープラグイン
一つのAUFファイルに2つのヘルパープラグインを同梱しています。
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ AviUtl object tracking (rubbish) plugin based on LKT/optical flow. Use OpenCV 4.


## Installation
Dump the .AUF and .XML files into
`AviUtl's root folder`
Dump the .AUF and MotionTracking_model folder into
`your favorite folder where AviUtl loads filter plug-ins`

The menu name should be "MotionTracking MK-II Plus"

Additional work is required if Methods 4, 5, or 6 are to be used.
Additional work is required if Methods 4, 5, 6 or 7 are to be used.

### For Method 4 (GOTURN)
1. Download each data from [this URL](https://github.com/opencv/opencv_extra/tree/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking)
2. Extract the splited ZIP file
3. Dump the
- goturn.caffemodel
- goturn.prototxt
into `AviUtl's root folder`
into `MotionTracking_model folder`

### For Method 5 (DaSiamRPN)
1. Download the following file from the URL listed as a comment out in the source code at [this URL](https://github.com/opencv/opencv/blob/4.x/samples/dnn/dasiamrpn_tracker.cpp)
Expand All @@ -33,22 +33,22 @@ Additional work is required if Methods 4, 5, or 6 are to be used.
- dasiamrpn_kernel_r1.onnx
- dasiamrpn_kernel_cls1.onnx

2. Dump each files into `AviUtl's root folder`
2. Dump each files into `MotionTracking_model folder`

### For Method 6 (Nano)
1. Download the following file from [this URL](https://github.com/HonglinChu/SiamTrackers/tree/18b7791360acb3f6d276d47376a6f1ed516f1628/NanoTrack/models/nanotrackv2)

- nanotrack_backbone_sim.onnx
- nanotrack_head_sim.onnx

2. Dump each files into `AviUtl's root folder`
2. Dump each files into `MotionTracking_model folder`

### For Method 7 (Vit)
1. Download the following file from [this URL](https://github.com/opencv/opencv_extra/blob/4.x/testdata/dnn/onnx/models/vitTracker.onnx)

- vitTracker.onnx

2. Dump each files into `AviUtl's root folder`
2. Dump each files into `MotionTracking_model folder`

## Helper Plugins
The single AUF actually contains two more helper plugins:
Expand Down
54 changes: 38 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "opencv2\video\tracking.hpp"
#include "resource.h"

HINSTANCE hModuleDLL = nullptr;

#define METHOD_N 7
TCHAR* track_method[] = { "MIL", "KCF", "CSRT", "GOTURN", "DaSiamRPN", "Nano", "Vit"};

Expand Down Expand Up @@ -164,6 +166,7 @@ typedef struct{
int vi_end;
}FRMGROUP;

std::string modelDir;


//---------------------------------------------------------------------
Expand All @@ -172,6 +175,20 @@ typedef struct{
FILTER_DLL* filterlist[] = { &filter, &filter_hsv, &filter_bgs, NULL };
EXTERN_C FILTER_DLL __declspec(dllexport) ** __stdcall GetFilterTableList(void)
{
char path[MAX_PATH * 2];
if (GetModuleFileNameA(hModuleDLL, path, MAX_PATH * 2))
{
char* p = path;
while (*p != '\0')
p++;
while (*p != '\\')
p--;
p++;
*p = '\0';
modelDir = std::string(path);
modelDir += "MotionTracking_Model\\";
}

return (FILTER_DLL**)&filterlist;
}

Expand Down Expand Up @@ -493,25 +510,25 @@ BOOL func_WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, void *e
case 3:
{
auto params = cv::TrackerGOTURN::Params();
params.modelBin = "goturn.caffemodel";
params.modelTxt = "goturn.prototxt";
params.modelBin = modelDir + "goturn.caffemodel";
params.modelTxt = modelDir + "goturn.prototxt";
tracker = cv::TrackerGOTURN::create(params);
break;
}
case 4:
{
auto params = cv::TrackerDaSiamRPN::Params();
params.model = "dasiamrpn_model.onnx";
params.kernel_r1 = "dasiamrpn_kernel_r1.onnx";
params.kernel_cls1 = "dasiamrpn_kernel_cls1.onnx";
params.model = modelDir + "dasiamrpn_model.onnx";
params.kernel_r1 = modelDir + "dasiamrpn_kernel_r1.onnx";
params.kernel_cls1 = modelDir + "dasiamrpn_kernel_cls1.onnx";
tracker = cv::TrackerDaSiamRPN::create(params);
break;
}
case 5:
{
auto params = cv::TrackerNano::Params();
params.backbone = "nanotrack_backbone_sim.onnx";
params.neckhead = "nanotrack_head_sim.onnx";
params.backbone = modelDir + "nanotrack_backbone_sim.onnx";
params.neckhead = modelDir + "nanotrack_head_sim.onnx";
tracker = cv::TrackerNano::create(params);
break;
}
Expand All @@ -522,7 +539,7 @@ BOOL func_WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, void *e
//https://github.com/opencv/opencv_zoo/blob/main/models/object_tracking_vittrack/object_tracking_vittrack_2023sep.onnx

auto params = cv::TrackerVit::Params();
params.net = "vitTracker.onnx";
params.net = modelDir + "vitTracker.onnx";
tracker = cv::TrackerVit::create(params);
break;
}
Expand Down Expand Up @@ -1073,14 +1090,8 @@ BOOL func_proc(FILTER *fp, FILTER_PROC_INFO *fpip)
//Check if XML exists in root or plugin folder
cv::CascadeClassifier frontface = cv::CascadeClassifier::CascadeClassifier();
cv::CascadeClassifier profileface = cv::CascadeClassifier::CascadeClassifier();
if (!frontface.load("haarcascade_frontalface_default.xml"))
{
frontface.load("./plugins/haarcascade_frontalface_default.xml");
}
if (!profileface.load("haarcascade_profileface.xml"))
{
profileface.load("./plugins/haarcascade_profileface.xml");
}
frontface.load(modelDir + "haarcascade_frontalface_default.xml");
profileface.load(modelDir + "haarcascade_profileface.xml");
//if XML loaded, proceed
if (!frontface.empty() && !profileface.empty())
{
Expand Down Expand Up @@ -1410,3 +1421,14 @@ BOOL bgs_func_proc(FILTER *fp, FILTER_PROC_INFO *fpip)
}
return FALSE;
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hModuleDLL = hinstDLL;
break;
}
return TRUE;
}

0 comments on commit 73d322f

Please sign in to comment.