added support for FexTracker

added "Track this line" button in bottom right corner of video box
added 2 new button bitmaps
added function to display tracked points for current line as overlay in VideoDisplay

Originally committed to SVN as r35.
This commit is contained in:
tentacle 2006-01-28 19:48:35 +00:00
parent 732aa4a1ba
commit 3e6637cb26
12 changed files with 156 additions and 2 deletions

View file

@ -47,6 +47,8 @@
////////////////////// AssDialogue //////////////////////
// Constructs AssDialogue
AssDialogue::AssDialogue() {
Tracker = 0;
Type = ENTRY_DIALOGUE;
group = _T("[Events]");
@ -67,6 +69,8 @@ AssDialogue::AssDialogue() {
AssDialogue::AssDialogue(wxString _data,bool IsSSA) {
Tracker = 0;
Type = ENTRY_DIALOGUE;
group = _T("[Events]");
data = _data;

View file

@ -42,6 +42,7 @@
#include <vector>
#include "ass_entry.h"
#include "ass_time.h"
class FexTracker;
//////////////
@ -165,6 +166,7 @@ public:
wxString Actor; // Actor name
wxString Effect; // Effect name
wxString Text; // Raw text data
FexTracker *Tracker; // Point tracker
bool Parse(bool IsSSA=false); // Parses raw ASS data into everything else
void ParseASSTags(); // Parses text to generate block information (doesn't update data)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -105,6 +105,7 @@ private:
void OnVideoPlayLine(wxCommandEvent &event);
void OnVideoStop(wxCommandEvent &event);
void OnVideoToggleScroll(wxCommandEvent &event);
void OnVideoTrackPoints(wxCommandEvent &event);
void OnKeyDown(wxKeyEvent &event);
@ -321,6 +322,7 @@ enum {
Video_Play_Line,
Video_Stop,
Video_Auto_Scroll,
Video_Track_Points,
Menu_File_Recent = 2000,
Menu_Video_Recent = 2200,

View file

@ -40,6 +40,7 @@
#include <wx/mimetype.h>
#include <wx/filename.h>
#include <wx/tglbtn.h>
#include <wx/rawbmp.h>
#include "subs_grid.h"
#include "frame_main.h"
#include "video_display.h"
@ -71,6 +72,8 @@
#include "toggle_bitmap.h"
#include "dialog_hotkeys.h"
#include "dialog_timing_processor.h"
#include "FexTracker.h"
#include "FexTrackingFeature.h"
////////////////////
@ -83,6 +86,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_BUTTON(Video_Play_Line, FrameMain::OnVideoPlayLine)
EVT_BUTTON(Video_Stop, FrameMain::OnVideoStop)
EVT_TOGGLEBUTTON(Video_Auto_Scroll, FrameMain::OnVideoToggleScroll)
EVT_BUTTON(Video_Track_Points, FrameMain::OnVideoTrackPoints)
EVT_CLOSE(FrameMain::OnCloseWindow)
@ -1123,6 +1127,47 @@ void FrameMain::OnVideoToggleScroll(wxCommandEvent &event) {
}
///////////////////
// Track current line
void FrameMain::OnVideoTrackPoints(wxCommandEvent &event) {
videoBox->videoDisplay->Stop();
// Get line
AssDialogue *curline = SubsBox->GetDialogue(EditBox->linen);
if (!curline) return;
// Get Video
bool usedDirectshow;
VideoProvider *movie = new VideoProvider(videoBox->videoDisplay->videoName, wxString(_T("")), 1.0,usedDirectshow,true);
// Create Tracker
if( curline->Tracker ) delete curline->Tracker;
curline->Tracker = new FexTracker( movie->GetWidth(), movie->GetHeight(), 250 );
curline->Tracker->minFeatures = 250;
// Allocate temp image
float* FloatImg = new float[ movie->GetWidth()*movie->GetHeight() ];
int StartFrame = VFR_Output.CorrectFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.CorrectFrameAtTime(curline->End.GetMS(),false);
for( int Frame = StartFrame; Frame <= EndFrame; Frame ++ )
{
wxString Text;
Text = wxString::Format( _T("Tracking ... %.2f %%"), float(Frame-StartFrame)/(EndFrame-StartFrame)*100.0f );
videoBox->videoDisplay->DrawText( wxPoint(20,20), Text );
movie->GetFloatFrame( FloatImg, Frame );
curline->Tracker->ProcessImage( FloatImg );
}
delete FloatImg;
delete movie;
videoBox->videoDisplay->RefreshVideo();
}
///////////////////////////////
// Choose a different language
void FrameMain::OnChooseLanguage (wxCommandEvent &event) {

View file

@ -79,6 +79,8 @@ shift_to_frame_disable BITMAP "bitmaps/shift_to_frame_disable.bmp"
button_play BITMAP "bitmaps/button_play.bmp"
button_stop BITMAP "bitmaps/button_stop.bmp"
button_track_points BITMAP "bitmaps/button_track_points.bmp"
button_bold BITMAP "bitmaps/button_bold.bmp"
button_italics BITMAP "bitmaps/button_italics.bmp"
button_underline BITMAP "bitmaps/button_underline.bmp"

View file

@ -59,6 +59,8 @@ VideoBox::VideoBox(wxPanel *parent) {
AutoScroll = new ToggleBitmap(videoPage,Video_Auto_Scroll,wxBITMAP(toggle_video_autoscroll),wxSize(30,-1));
AutoScroll->SetToolTip(_("Toggle autoscroll of video"));
AutoScroll->SetValue(Options.AsBool(_T("Sync video with subs")));
wxBitmapButton *VideoTrackPointsButton = new wxBitmapButton(videoPage,Video_Track_Points,wxBITMAP(button_track_points),wxDefaultPosition,wxSize(25,-1));
VideoTrackPointsButton->SetToolTip(_("Track point movements in video"));
// Seek
videoSlider = new VideoSlider(videoPage,-1);
@ -93,6 +95,7 @@ VideoBox::VideoBox(wxPanel *parent) {
videoBottomSizer->Add(AutoScroll,0,wxTOP|wxBOTTOM|wxALIGN_CENTER|wxEXPAND,2);
videoBottomSizer->Add(VideoPosition,1,wxLEFT|wxALIGN_CENTER,5);
videoBottomSizer->Add(VideoSubsPos,1,wxALIGN_CENTER,0);
videoBottomSizer->Add(VideoTrackPointsButton,0,wxTOP|wxBOTTOM|wxALIGN_CENTER,2);
VideoSizer = new wxBoxSizer(wxVERTICAL);
VideoSizer->Add(videoDisplay,0,wxEXPAND,0);
VideoSizer->Add(videoSliderSizer,0,wxEXPAND,0);

View file

@ -53,6 +53,8 @@
#include <wx/clipbrd.h>
#include <wx/filename.h>
#include <wx/config.h>
#include "FexTracker.h"
#include "FexTrackingFeature.h"
///////
@ -275,6 +277,8 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
// Draw frame
dc.DrawBitmap(GetFrame(frame_n),0,0);
// Draw the control points for FexTracker
DrawTrackingOverlay( dc );
// Current position info
if (x >= 0 && x < w && y >= 0 && y < h) {
@ -523,6 +527,44 @@ void VideoDisplay::OnCopyCoords(wxCommandEvent &event) {
}
//////////////////
// Draw Tracking Overlay
void VideoDisplay::DrawTrackingOverlay( wxDC &dc )
{
if( IsPlaying ) return;
// Get line
AssDialogue *curline = grid->GetDialogue(grid->editBox->linen);
if( !curline || !curline->Tracker ) return;
int StartFrame = VFR_Output.CorrectFrameAtTime(curline->Start.GetMS(),true);
int EndFrame = VFR_Output.CorrectFrameAtTime(curline->End.GetMS(),false);
if( frame_n<StartFrame || frame_n>EndFrame ) return;
int localframe = frame_n - StartFrame;
if( curline->Tracker->GetFrame() <= localframe ) return;
dc.SetPen(wxPen(wxColour(255,255,255),1));
dc.SetLogicalFunction(wxINVERT);
for( int i=0;i<curline->Tracker->GetCount();i++ )
{
FexTrackingFeature* f = (*curline->Tracker)[i];
if( f->StartTime > localframe ) continue;
int llf = localframe - f->StartTime;
if( f->Pos.size() <= llf ) continue;
vec2 pt = f->Pos[llf];
pt.x *= provider->GetZoom();
pt.y *= provider->GetZoom();
pt.x = int(pt.x);
pt.y = int(pt.y);
dc.DrawLine( pt.x-2, pt.y, pt.x+3, pt.y );
dc.DrawLine( pt.x, pt.y-2, pt.x, pt.y+3 );
}
}
//////////////////
// Refresh screen
void VideoDisplay::RefreshVideo() {
@ -530,6 +572,29 @@ void VideoDisplay::RefreshVideo() {
wxClientDC dc(this);
dc.BeginDrawing();
dc.DrawBitmap(GetFrame(),0,0);
// Draw the control points for FexTracker
DrawTrackingOverlay( dc );
dc.EndDrawing();
}
//////////////////
// DrawVideoWithOverlay
void VideoDisplay::DrawText( wxPoint Pos, wxString text ) {
// Draw frame
wxClientDC dc(this);
dc.BeginDrawing();
dc.SetBrush(wxBrush(wxColour(128,128,128),wxSOLID));
dc.DrawRectangle( 0,0, provider->GetWidth(), provider->GetHeight() );
dc.SetTextForeground(wxColour(64,64,64));
dc.DrawText(text,Pos.x+1,Pos.y-1);
dc.DrawText(text,Pos.x+1,Pos.y+1);
dc.DrawText(text,Pos.x-1,Pos.y-1);
dc.DrawText(text,Pos.x-1,Pos.y+1);
dc.SetTextForeground(wxColour(255,255,255));
dc.DrawText(text,Pos.x,Pos.y);
dc.EndDrawing();
}

View file

@ -89,6 +89,8 @@ private:
void OnCopyCoords(wxCommandEvent &event);
void OnPlayTimer(wxTimerEvent &event);
void DrawTrackingOverlay( wxDC &dc );
public:
VideoProvider *provider;
@ -119,6 +121,7 @@ public:
void JumpToTime(int ms);
void RefreshSubtitles();
void RefreshVideo();
void DrawText( wxPoint Pos, wxString Text );
void UpdatePositionDisplay();
void SetAspectRatio(int type);
void SetZoom(double value);

View file

@ -57,15 +57,22 @@ VideoProvider::VideoProvider(wxString _filename, wxString _subfilename, double _
dar = GetSourceWidth()/(double)GetSourceHeight();
SubtitledVideo = ApplySubtitles(subfilename, RGB32Video);
if( _subfilename == _T("") ) SubtitledVideo = RGB32Video;
else SubtitledVideo = ApplySubtitles(subfilename, RGB32Video);
/*
if( _zoom == 1.0 ) ResizedVideo = SubtitledVideo;
else ResizedVideo = ApplyDARZoom(zoom, dar, SubtitledVideo);
*/
ResizedVideo = ApplyDARZoom(zoom, dar, SubtitledVideo);
vi = ResizedVideo->GetVideoInfo();
}
VideoProvider::~VideoProvider() {
RGB32Video = NULL;
SubtitledVideo = NULL;
ResizedVideo = NULL;
delete data;
if( data ) delete data;
}
void VideoProvider::RefreshSubtitles() {
@ -228,6 +235,25 @@ wxBitmap VideoProvider::GetFrame(int n, bool force) {
return wxBitmap(last_frame);
}
void VideoProvider::GetFloatFrame(float* Buffer, int n) {
wxMutexLocker lock(AviSynthMutex);
PVideoFrame frame = ResizedVideo->GetFrame(n,env);
int rs = vi.RowSize();
const unsigned char* src = frame->GetReadPtr();
int srcpitch = frame->GetPitch();
for( int i = 0; i < vi.height; i++ )
{
for( int x=0; x<vi.width;x++ )
{
Buffer[(vi.height-i-1)*vi.width+x] = src[x*4+0]*0.3 + src[x*4+1]*0.4 + src[x*4+2]*0.3;
}
src+=srcpitch;
}
}
void VideoProvider::LoadVSFilter() {
// Loading an avisynth plugin multiple times does almost nothing

View file

@ -84,6 +84,7 @@ public:
void SetZoom(double _zoom);
wxBitmap GetFrame(int n) { return GetFrame(n,false); };
void GetFloatFrame(float* Buffer, int n);
// properties
int GetPosition() { return last_fnum; };
@ -92,6 +93,7 @@ public:
int GetWidth() { return vi.width; };
int GetHeight() { return vi.height; };
double GetZoom() { return zoom; };
int GetSourceWidth() { return RGB32Video->GetVideoInfo().width; };
int GetSourceHeight() { return RGB32Video->GetVideoInfo().height; };