Skip to content

Commit

Permalink
矩形の色相を変えられるように #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Ojii committed May 11, 2024
1 parent de44d9c commit 791d123
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ CJKファイル名もサポートされています。
5. DaSiamRPN
6. Nano
7. Vit
###### Rect Hue
Object SelectionやView Resultで表示される矩形の色相を指定します
##### Save EXOのオプション
- As English EXO? : 英語版パッチを当てた拡張編集用のexoを出力するか
- As Sub-filter/部分フィルター? : 部分フィルタとして出力するか
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ Auto correct for single sandwiched error result.
Support CJK filename
#### Options
##### Method
Specifies the algorithm to be used in the analysis.
1. Multi Instance Learning
2. KCF
3. CSRT
4. GOTURN
5. DaSiamRPN
6. Nano
7. Vit
##### Rect Hue
Specifies the hue of the rectangle displayed in Object Selection and View Result.
##### Save EXO Options
- As English EXO? : Output exo for English patched exedit.
- As Sub-filter/部分フィルター? : Output as a sub filter.
Expand Down
72 changes: 56 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ HINSTANCE hModuleDLL = nullptr;
constexpr TCHAR* track_method[] = { "MIL", "KCF", "CSRT", "GOTURN", "DaSiamRPN", "Nano", "Vit"};
constexpr int METHOD_N = sizeof(track_method) / sizeof(TCHAR*);

constexpr TCHAR* track_name[] = { "Method" }; // トラックバーの名前
constexpr int track_default[] = { 3 }; // トラックバーの初期値
constexpr int track_s[] = { 1 }; // トラックバーの下限値
constexpr int track_e[] = { METHOD_N }; // トラックバーの上限値
constexpr TCHAR* track_name[] = { "Method", "Rect Hue" }; // トラックバーの名前
constexpr int track_default[] = { 3, 120 }; // トラックバーの初期値
constexpr int track_s[] = { 1, 0 }; // トラックバーの下限値
constexpr int track_e[] = { METHOD_N, 359 }; // トラックバーの上限値
constexpr int TRACK_N = sizeof(track_name) / sizeof(TCHAR*);

static_assert(TRACK_N == sizeof(track_default) / sizeof(int), "size of track_default mismatch with TRACK_N");
Expand Down Expand Up @@ -75,7 +75,7 @@ FILTER_DLL filter = {
func_proc, // フィルタ処理関数へのポインタ (NULLなら呼ばれません)
NULL, // 開始時に呼ばれる関数へのポインタ (NULLなら呼ばれません)
NULL, // 終了時に呼ばれる関数へのポインタ (NULLなら呼ばれません)
NULL, // 設定が変更されたときに呼ばれる関数へのポインタ (NULLなら呼ばれません)
func_update, // 設定が変更されたときに呼ばれる関数へのポインタ (NULLなら呼ばれません)
func_WndProc, // 設定ウィンドウにウィンドウメッセージが来た時に呼ばれる関数へのポインタ (NULLなら呼ばれません)
NULL, NULL, // システムで使いますので使用しないでください
NULL, // 拡張データ領域へのポインタ (FILTER_FLAG_EX_DATAが立っている時に有効)
Expand Down Expand Up @@ -137,9 +137,42 @@ EXTERN_C FILTER_DLL __declspec(dllexport) ** __stdcall GetFilterTableList(void)
return (FILTER_DLL**)&filterlist;
}

static cv::Scalar hue_to_scalar(int hue)
{
hue = hue % 360;

if (hue < 60)
return cv::Scalar(255, hue * 255 / 60, 0);
else if (hue < 120)
return cv::Scalar((120-hue) * 255 / 60, 255, 0);
else if (hue < 180)
return cv::Scalar(0, 255, (hue - 120) * 255 / 60);
else if (hue < 240)
return cv::Scalar(0, (240 - hue) * 255 / 60, 255);
else if (hue < 300)
return cv::Scalar((hue - 240) * 255 / 60, 0, 255);
else
return cv::Scalar(255, 0, (360 - hue) * 255 / 60);
}

static void update_object_selection_window(int x1, int y1, int x2, int y2, FILTER* fp)
{
//update only if visible
if(!static_cast<bool>(cv::getWindowProperty("Object Selection", cv::WND_PROP_VISIBLE)))
return;

//draw the bounding box
cv::Mat currentFrame;
ocvImage.copyTo(currentFrame);
cv::rectangle(currentFrame, cv::Point(x1, y1), cv::Point(x2, y2), hue_to_scalar(fp->track[1]), 2);

imshow("Object Selection", currentFrame);
}

// Mouse callback function for object selection
static void onMouse(int event, int x, int y, int, void*)
static void onMouse(int event, int x, int y, int, void* fp_v)
{
FILTER* fp = reinterpret_cast<FILTER*>(fp_v);
switch (event)
{
case cv::EVENT_LBUTTONDOWN:
Expand All @@ -162,12 +195,7 @@ static void onMouse(int event, int x, int y, int, void*)

if (startSel && !selectObj)
{
//draw the bounding box
cv::Mat currentFrame;
ocvImage.copyTo(currentFrame);
cv::rectangle(currentFrame, cv::Point((int)boundingBox.x, (int)boundingBox.y), cv::Point(x, y), cv::Scalar(0, 255, 0), 2);

imshow("Object Selection", currentFrame);
update_object_selection_window(boundingBox.x, boundingBox.y, x, y, fp);
}
break;
}
Expand Down Expand Up @@ -321,7 +349,19 @@ static void groupObject(std::vector<FRMFIX> &fixedframes, std::vector<FRMGROUP>
//BOOL func_init(FILTER *fp);

//BOOL func_exit(FILTER *fp);
//BOOL func_update(FILTER *fp, int status);
BOOL func_update(FILTER *fp, int status)
{
if (status == FILTER_UPDATE_STATUS_TRACK + 1)
{
if (selectObj)
update_object_selection_window(boundingBox.x, boundingBox.y, boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height, fp);

// View Result
if (fp->track[2])
return TRUE;
}
return FALSE;
}
BOOL func_WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, void *editp, FILTER *fp)
{
if (!fp->exfunc->is_filter_active(fp) || !fp->exfunc->is_editing(editp))
Expand All @@ -336,7 +376,7 @@ BOOL func_WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, void *e
case MID_FILTER_BUTTON: //Object selection
{
int srcw, srch;
if (!fp->exfunc->get_select_frame(editp, &selA, &selB))
if (!fp->exfunc->get_select_frame(editp, &selA, &selB))
{
MessageBox(NULL, "Cannot get selected frame number", "AviUtl API Error", MB_OK);
return FALSE;
Expand All @@ -360,7 +400,7 @@ BOOL func_WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, void *e
cvBuffer.copyTo(ocvImage);

cv::namedWindow("Object Selection", cv::WINDOW_KEEPRATIO);
cv::setMouseCallback("Object Selection", onMouse, 0);
cv::setMouseCallback("Object Selection", onMouse, fp);
cv::resizeWindow("Object Selection", srcw, srch);
cv::imshow("Object Selection", ocvImage);
return TRUE;
Expand Down Expand Up @@ -917,7 +957,7 @@ BOOL func_proc(FILTER *fp, FILTER_PROC_INFO *fpip)

if (track_found[fpip->frame - selA])
{
cv::rectangle(disp, track_result[fpip->frame - selA], cv::Scalar(255, 0, 0), 2, 1);
cv::rectangle(disp, track_result[fpip->frame - selA], hue_to_scalar(fp->track[1]), 2, 1);
cv::putText(disp, "OK", cv::Point(0, 50), cv::FONT_HERSHEY_PLAIN, 2.0, cv::Scalar(0, 255, 0), 2);
}
else
Expand Down

0 comments on commit 791d123

Please sign in to comment.