using System;
using System.Drawing;
using Sid;
namespace WAv2_examples
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Blocks()
{
string dir = "c:/c#/optic_flow_test_data/blocks/";
int N = 8;
string[] filenames = new string[N];
for(int i = 1; i <= N; i++)
filenames[i-1] = dir + "blocks."+i+".gif";
WAdetector WA = new WAdetector();
float[,,] f = WA.WAComputeOpticalFlow(filenames);
float[,,] quiver_data = new float[f.GetLength(0),f.GetLength(1),2];
for(int y = 0; y < quiver_data.GetLength(0); y++)
for(int x = 0; x < quiver_data.GetLength(1); x++)
{
quiver_data[y,x,0] = f[y,x,0]*f[y,x,2];
quiver_data[y,x,1] = f[y,x,1]*f[y,x,2];
}
Bitmap bmp = WAdetector.Quiver(quiver_data);
int date = DateTime.Now.Year*1000 + DateTime.Now.Month*100 + DateTime.Now.Day;
int time = DateTime.Now.Hour*1000 + DateTime.Now.Minute*100 + DateTime.Now.Second;
string filename = dir + "blocks_flow-" + date + "-" + time + ".bmp";
bmp.Save(filename);
}
static void Grid()
{
string dir = "c:/c#/optic_flow_test_data/grid/";
int N = 8;
string[] filenames = new string[N];
for(int i = 0; i < N; i++)
filenames[i] = dir + "grid."+i+".gif";
WAdetector WA = new WAdetector();
float[,,] f = WA.WAComputeOpticalFlow(filenames);
float[,,] quiver_data = new float[f.GetLength(0),f.GetLength(1),2];
for(int y = 0; y < quiver_data.GetLength(0); y++)
for(int x = 0; x < quiver_data.GetLength(1); x++)
{
quiver_data[y,x,0] = f[y,x,0]*f[y,x,2];
quiver_data[y,x,1] = f[y,x,1]*f[y,x,2];
}
Bitmap bmp = WAdetector.Quiver(quiver_data);
int date = DateTime.Now.Year*1000 + DateTime.Now.Month*100 + DateTime.Now.Day;
int time = DateTime.Now.Hour*1000 + DateTime.Now.Minute*100 + DateTime.Now.Second;
string filename = dir + "grid_flow-" + date + "-" + time + ".bmp";
bmp.Save(filename);
}
static void Vcbox()
{
string dir = "c:/c#/optic_flow_test_data/vcbox/";
int N = 8;
string[] filenames = new string[N];
for(int i = 0; i < N; i++)
filenames[i] = dir + "vcbox."+i+".gif";
WAdetector WA = new WAdetector();
float[,,] f = WA.WAComputeOpticalFlow(filenames);
float[,,] quiver_data = new float[f.GetLength(0),f.GetLength(1),2];
for(int y = 0; y < quiver_data.GetLength(0); y++)
for(int x = 0; x < quiver_data.GetLength(1); x++)
{
quiver_data[y,x,0] = f[y,x,0]*f[y,x,2];
quiver_data[y,x,1] = f[y,x,1]*f[y,x,2];
}
Bitmap bmp = WAdetector.Quiver(quiver_data);
int date = DateTime.Now.Year*1000 + DateTime.Now.Month*100 + DateTime.Now.Day;
int time = DateTime.Now.Hour*1000 + DateTime.Now.Minute*100 + DateTime.Now.Second;
string filename = dir + "vcbox_flow-" + date + "-" + time + ".bmp";
bmp.Save(filename);
}
static void Complex()
{
string dir = "c:/c#/optic_flow_test_data/complex/";
int N = 8;
string[] filenames = new string[N];
for(int i = 0; i < N; i++)
filenames[i] = dir + "anim."+(i+10)+".tif";
WAdetector WA = new WAdetector();
float[,,] f = WA.WAComputeOpticalFlow(filenames);
float[,,] quiver_data = new float[f.GetLength(0),f.GetLength(1),2];
for(int y = 0; y < quiver_data.GetLength(0); y++)
for(int x = 0; x < quiver_data.GetLength(1); x++)
{
quiver_data[y,x,0] = f[y,x,0]*f[y,x,2];
quiver_data[y,x,1] = f[y,x,1]*f[y,x,2];
}
Bitmap bmp = WAdetector.Quiver(quiver_data);
int date = DateTime.Now.Year*1000 + DateTime.Now.Month*100 + DateTime.Now.Day;
int time = DateTime.Now.Hour*1000 + DateTime.Now.Minute*100 + DateTime.Now.Second;
string filename = dir + "complex_flow-" + date + "-" + time + ".bmp";
bmp.Save(filename);
}
static void Medium()
{
string dir = "c:/c#/optic_flow_test_data/medium/";
int N = 8;
string[] filenames = new string[N];
for(int i = 0; i < N; i++)
filenames[i] = dir + "anim."+(i+10)+".tif";
WAdetector WA = new WAdetector();
float[,,] f = WA.WAComputeOpticalFlow(filenames);
float[,,] quiver_data = new float[f.GetLength(0),f.GetLength(1),2];
for(int y = 0; y < quiver_data.GetLength(0); y++)
for(int x = 0; x < quiver_data.GetLength(1); x++)
{
quiver_data[y,x,0] = f[y,x,0]*f[y,x,2];
quiver_data[y,x,1] = f[y,x,1]*f[y,x,2];
}
Bitmap bmp = WAdetector.Quiver(quiver_data);
int date = DateTime.Now.Year*1000 + DateTime.Now.Month*100 + DateTime.Now.Day;
int time = DateTime.Now.Hour*1000 + DateTime.Now.Minute*100 + DateTime.Now.Second;
string filename = dir + "medium_flow-" + date + "-" + time + ".bmp";
bmp.Save(filename);
}
static void Simple()
{
string dir = "c:/c#/optic_flow_test_data/simple/"; // the directory where images are stored
int N = 8; // number of files we wish to read for optical flow estimation
string[] filenames = new string[N];
for(int i = 0; i < N; i++)
filenames[i] = dir + "anim."+(i+10)+".tif";
WAdetector WA = new WAdetector();
float[,,] f = WA.WAComputeOpticalFlow(filenames); // compute optical flow for the sequence of images specified in filenames
float[,,] quiver_data = new float[f.GetLength(0),f.GetLength(1),2]; // for the quiver plot
for(int y = 0; y < quiver_data.GetLength(0); y++)
for(int x = 0; x < quiver_data.GetLength(1); x++)
{
quiver_data[y,x,0] = f[y,x,0]*f[y,x,2]; // scale vx by weight w
quiver_data[y,x,1] = f[y,x,1]*f[y,x,2]; // scale vy by weight w
}
Bitmap bmp = WAdetector.Quiver(quiver_data); // creates a bitmap to visualize the data in quiver_data
int date = DateTime.Now.Year*1000 + DateTime.Now.Month*100 + DateTime.Now.Day; // get date in yyyymmdd format
int time = DateTime.Now.Hour*1000 + DateTime.Now.Minute*100 + DateTime.Now.Second; // get time in hhmmss format
string filename = dir + "simple_flow-" + date + "-" + time + ".bmp";
bmp.Save(filename); // save the quiver plot
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("simple...");
Simple();
Console.WriteLine("medium...");
Medium();
Console.WriteLine("complex...");
Complex();
Console.WriteLine("vcbox...");
Vcbox();
Console.WriteLine("grid...");
Grid();
Console.WriteLine("blocks...");
Blocks();
Console.WriteLine("done!");
Console.ReadLine();
}
}
}