Skip to content

Commit

Permalink
Add command line interface
Browse files Browse the repository at this point in the history
  • Loading branch information
eritpchy committed Mar 22, 2023
1 parent 453ff5e commit d346973
Show file tree
Hide file tree
Showing 26 changed files with 774 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.idea/**
/docker/**
/linux_build/**
/Build/**
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
!.gitignore
# Or directories
!*/

.idea
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ else()
else()
set(wxWidgets_USE_DEBUG OFF)
endif()
find_package(wxWidgets REQUIRED COMPONENTS core base aui)
if(USE_GUI)
find_package(wxWidgets REQUIRED COMPONENTS core base aui)
else()
find_package(wxWidgets REQUIRED COMPONENTS base)
endif(USE_GUI)
find_package(OpenCV REQUIRED)
endif(WIN32)

Expand All @@ -50,5 +54,14 @@ endif(USE_CUDA)
add_subdirectory(Components/IPAlgorithms)
add_subdirectory(Components/OCVVideo)
add_subdirectory(Components/FFMPEGVideo)

if(USE_GUI)
add_definitions(-DUSE_GUI)
option(USE_GUI "Build with GUI support" ON)
add_subdirectory(Interfaces/VideoSubFinderWXW)
else()
add_definitions(-UUSE_GUI)
option(USE_GUI "Build with GUI support" OFF)
add_subdirectory(Interfaces/VideoSubFinderCli)
endif(USE_GUI)

8 changes: 8 additions & 0 deletions Components/FFMPEGVideo/FFMPEGVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ FFMPEGVideo::~FFMPEGVideo()

void FFMPEGVideo::ShowFrame(void *dc)
{
#ifndef USE_GUI
return;
#else
if ((m_show_video) && (dc != NULL))
{
int ret;
Expand Down Expand Up @@ -134,6 +137,7 @@ void FFMPEGVideo::ShowFrame(void *dc)

if (dst_data[0]) av_freep(&dst_data[0]);
}
#endif
}

/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -343,7 +347,9 @@ void FFMPEGVideo::OneStep()

if (m_show_video)
{
#ifdef USE_GUI
((wxWindow*)m_pVideoWindow)->Refresh(true);
#endif
}
}
else
Expand Down Expand Up @@ -897,7 +903,9 @@ bool FFMPEGVideo::SetVideoWindowPlacement(void *pVideoWindow)
m_pVideoWindow ? m_show_video = true : m_show_video = false;
if (m_show_video)
{
#ifdef USE_GUI
((wxWindow*)m_pVideoWindow)->Refresh(true);
#endif
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions Components/FFMPEGVideo/FFMPEGVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Video.h"
#include "opencv2/opencv.hpp"
#include <wx/wx.h>
#include "wx.h"

extern "C"
{
Expand Down
1 change: 1 addition & 0 deletions Components/FFMPEGVideo/FFMPEGVideoLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "Video.h"
#include <wx/wx.h>
#include "wx.h"

extern wxString g_hw_device;
extern wxString g_filter_descr;
Expand Down
1 change: 1 addition & 0 deletions Components/IPAlgorithms/IPAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <math.h>
#include <emmintrin.h>
#include <wx/wx.h>
#include "wx.h"
#include <wx/regex.h>
#include <chrono>
#include <iostream>
Expand Down
1 change: 1 addition & 0 deletions Components/IPAlgorithms/MyClosedFigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DataTypes.h"
#include <vector>
#include <wx/wx.h>
#include "wx.h"

using namespace std;

Expand Down
11 changes: 9 additions & 2 deletions Components/IPAlgorithms/SSAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ int g_max_dl_up = 40;

double g_video_contrast = 1.0; //1.0 default without change
double g_video_gamma = 1.0; //1.0 default without change
bool g_save_images = true;
vector<wxString> g_file_names_vector;

CVideo *g_pV;

Expand Down Expand Up @@ -607,6 +609,12 @@ class RunSearch
bool convert_to_lab = m_convert_to_lab;

m_thrs_save_images.emplace_back(shared_custom_task([ImBGR, ImISA, ImILA, name, w, h, W, H, xmin, xmax, ymin, ymax, convert_to_lab]() mutable {
g_file_names_vector.push_back(name);
fprintf(stderr, "Frame: %s\n", name.ToStdString().c_str());
fflush(stderr);
if (g_save_images == false) {
return;
}
{
simple_buffer<u8> ImTMP_BGR(W * H * 3);
ImBGRToNativeSize(ImBGR, ImTMP_BGR, w, h, W, H, xmin, xmax, ymin, ymax);
Expand Down Expand Up @@ -1233,7 +1241,7 @@ s64 FastSearchSubtitles(wxThread *pThr, CVideo *pV, s64 Begin, s64 End)

while (((CurPos < End) || (End < 0)) && (g_RunSubSearch == 1) && (CurPos != prevPos))
{
if (pThr->TestDestroy())
if (pThr && pThr->TestDestroy())
{
g_RunSubSearch = 0;
break;
Expand Down Expand Up @@ -1406,7 +1414,6 @@ s64 FastSearchSubtitles(wxThread *pThr, CVideo *pV, s64 Begin, s64 End)
create_new_threads = 1;
}
}

if ((g_RunSubSearch == 0) || (found_sub == 0) || ((CurPos >= End) && (End >= 0)) || (CurPos == prevPos))
{
break;
Expand Down
3 changes: 3 additions & 0 deletions Components/IPAlgorithms/SSAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Video.h"
#include <wx/string.h>
#include <chrono>
#include <vector>

using namespace std;

Expand All @@ -34,6 +35,8 @@ extern double g_tp; //text percent
extern double g_mtpl; //min text len (in percent)
extern double g_veple; //vedges points line error
extern double g_ilaple; //ILA points line error
extern bool g_save_images;
extern vector<wxString> g_file_names_vector;

extern bool g_use_ISA_images_for_search_subtitles;
extern bool g_use_ILA_images_for_search_subtitles;
Expand Down
1 change: 1 addition & 0 deletions Components/Include/DataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <time.h>
#include <memory.h>
#include <wx/wx.h>
#include "wx.h"
#include "opencv2/imgcodecs.hpp"
#include <condition_variable>
#include <queue>
Expand Down
15 changes: 15 additions & 0 deletions Components/Include/wx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <string>
#include <string.h>

#define wxMessageBox1(message) do { \
wxString content = message; \
printf(content.c_str()); \
} while(0)

#define wxMessageBox(message, title) do { \
wxString content = wxString(title) + " " + wxString(message) + "\n"; \
printf(content.c_str()); \
} while(0)

using namespace std;
22 changes: 20 additions & 2 deletions Components/OCVVideo/OCVVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ OCVVideo::OCVVideo()

m_type = 0;

#ifdef USE_GUI
m_pBmp = NULL;
m_pBmpScaled = NULL;
#endif

m_pVideoWindow = NULL;

Expand All @@ -48,6 +50,7 @@ OCVVideo::~OCVVideo()
m_VC.release();
}

#ifdef USE_GUI
if (m_pBmp != NULL)
{
delete m_pBmp;
Expand All @@ -59,12 +62,16 @@ OCVVideo::~OCVVideo()
delete m_pBmpScaled;
m_pBmpScaled = NULL;
}
#endif
}

/////////////////////////////////////////////////////////////////////////////

void OCVVideo::ShowFrame(cv::Mat &img, void *dc, int left, int top, int width, int height)
{
#ifndef USE_GUI
return;
#else
if ((!img.empty()) && m_VC.isOpened() && m_show_video && (dc != NULL))
{
int img_w = img.cols, img_h = img.rows, num_pixels = img_w*img_h;
Expand Down Expand Up @@ -109,16 +116,19 @@ void OCVVideo::ShowFrame(cv::Mat &img, void *dc, int left, int top, int width, i
}
}
}
#endif
}

/////////////////////////////////////////////////////////////////////////////

bool OCVVideo::OpenMovie(wxString csMovieName, void *pVideoWindow, int type)
{
cv::String movie_name(csMovieName.ToUTF8());

m_VC.open(movie_name);
bool res = m_VC.isOpened();

fprintf(stderr, "m_VC.isOpened(): %d path: %s %s\n",res, csMovieName.ToStdString().c_str(), strerror(errno));
fflush(stderr);
if (res)
{
m_MovieName = csMovieName;
Expand Down Expand Up @@ -164,7 +174,9 @@ bool OCVVideo::OpenMovie(wxString csMovieName, void *pVideoWindow, int type)

if (m_show_video)
{
#ifdef USE_GUI
((wxWindow*)m_pVideoWindow)->Refresh(true);
#endif
}
}

Expand All @@ -179,7 +191,9 @@ bool OCVVideo::SetVideoWindowPlacement(void *pVideoWindow)
m_pVideoWindow ? m_show_video = true : m_show_video = false;
if (m_show_video)
{
#ifdef USE_GUI
((wxWindow*)m_pVideoWindow)->Refresh(true);
#endif
}
return true;
}
Expand Down Expand Up @@ -292,8 +306,10 @@ void OCVVideo::OneStep()
m_ImageGeted = true;

if (m_show_video)
{
{
#ifdef USE_GUI
((wxWindow*)m_pVideoWindow)->Refresh(true);
#endif
}
}
else
Expand Down Expand Up @@ -527,7 +543,9 @@ void *ThreadRunVideo::Entry()
}
m_pVideo->m_Pos = m_pVideo->m_VC.get(cv::CAP_PROP_POS_MSEC);

#ifdef USE_GUI
((wxWindow*)m_pVideo->m_pVideoWindow)->Refresh(true);
#endif
int dt = (m_pVideo->m_Pos - startPos) - (int)(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start_t).count());
if (dt > 0)
{
Expand Down
3 changes: 3 additions & 0 deletions Components/OCVVideo/OCVVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Video.h"
#include "opencv2/opencv.hpp"
#include <wx/wx.h>
#include "wx.h"
#include <mutex>

class OCVVideo;
Expand Down Expand Up @@ -57,8 +58,10 @@ class OCVVideo: public CVideo
int m_type; //video open type
bool m_show_video;
bool m_play_video;
#ifdef USE_GUI
wxBitmap *m_pBmp;
wxBitmap *m_pBmpScaled;
#endif
double m_frameNumbers;
double m_fps;
cv::Mat m_cur_frame;
Expand Down
Loading

0 comments on commit d346973

Please sign in to comment.