EDN Admin
Well-known member
I want to find only images containing lightnings inside.<br/>
So i loop through all the images in the list and now im giving the user the option to select the threshold so he decide the threshold of the lightning and wich images are with lightnings inside and therfore to save ot hard disk this images.
But i want it to be automatic . The user just click a button it will loop through images and will save to hard disk all the images with lightnings inside.
<br/>
So i did some tests: Threshold/Frames: 60 - 69 , 65 - 53 , 70 - 48 , 75 - 42 , 80 - 33 , 85 - 23 , 90 - 14 , 95 - 6<br/>
<br/>
55 - 78 , 50 - 86 , 45 - 91 , 40 - 97 if the user set the threshold to 40 it will save 97 frames. and if it set to 60 so only 69 frames. But the user cant guess the right threshold.
<br/>
This is the code im using now:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using Polkan.DataSource;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using unfreez_wrapper;
<span style="color:Blue; using WindowsFormsApplication1;
<span style="color:Blue; using DannyGeneral;
<span style="color:Blue; using System.Text.RegularExpressions;
<span style="color:Blue; namespace Extracting_Frames
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Blue; bool isNumericChanged;
<span style="color:Blue; int counter;
<span style="color:Blue; bool secondPass;
<span style="color:Blue; double max = 0;
<span style="color:Blue; double min = 0;
List<<span style="color:Blue; double> myNumbers = <span style="color:Blue; new List<<span style="color:Blue; double>();
StreamReader reader;
List<<span style="color:Blue; double> averages;
<span style="color:Blue; string subDirectoryName;
Options_Menu om;
<span style="color:Blue; public <span style="color:Blue; string _outputDir;
<span style="color:Blue; static <span style="color:Blue; string settings_dir;
<span style="color:Blue; static <span style="color:Blue; string settings_file;
<span style="color:Blue; static OptionsFile setting_file;
<span style="color:Blue; static <span style="color:Blue; string path_settings;
<span style="color:Blue; string averagesListTextFileDirectory;
<span style="color:Blue; string averagesListTextFile;
StreamWriter w;
OpenFileDialog openFileDialog1;
<span style="color:Blue; int Hrs = 0; <span style="color:Green; //number of hours
<span style="color:Blue; int Min = 0; <span style="color:Green; //number of Minutes
<span style="color:Blue; int Sec = 0; <span style="color:Green; //number of Sec
<span style="color:Blue; int timeElapsed;
WmvAdapter f;
<span style="color:Blue; private <span style="color:Blue; string _videoFile;
FileInfo[] _fi = <span style="color:Blue; null;
<span style="color:Blue; delegate <span style="color:Blue; void del1(<span style="color:Blue; object sender, ProgressEventArgs e);
<span style="color:Blue; delegate <span style="color:Blue; void del2(<span style="color:Blue; object sender, EventArgs e);
<span style="color:Blue; delegate <span style="color:Blue; void del3(<span style="color:Blue; object sender, FrameCountEventArgs e);
<span style="color:Green; //Controls
<span style="color:Blue; private System.Windows.Forms.Button button1 = <span style="color:Blue; new System.Windows.Forms.Button();
<span style="color:Blue; private System.Windows.Forms.PictureBox pictureBox1 = <span style="color:Blue; new System.Windows.Forms.PictureBox();
<span style="color:Blue; private System.Windows.Forms.ProgressBar progressBar1 = <span style="color:Blue; new System.Windows.Forms.ProgressBar();
<span style="color:Blue; private System.Windows.Forms.Label label2 = <span style="color:Blue; new System.Windows.Forms.Label();
<span style="color:Blue; private List<<span style="color:Blue; int> _fts;
<span style="color:Blue; public Form1()
{
InitializeComponent();
isNumericChanged = <span style="color:Blue; false;
counter = 0;
secondPass = <span style="color:Blue; false;
openFileDialog1 = <span style="color:Blue; new OpenFileDialog();
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Visible = <span style="color:Blue; true;
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
path_settings = Path.GetDirectoryName(Application.LocalUserAppDataPath);
settings_file = <span style="color:#A31515; "\settings.txt";
settings_dir = path_settings + <span style="color:#A31515; @"settings";
<span style="color:Blue; if (Directory.Exists(settings_dir))
{
}
<span style="color:Blue; else
{
Directory.CreateDirectory(settings_dir);
}
<span style="color:Blue; if (!File.Exists(settings_dir + settings_file))
{
File.Create(settings_dir + settings_file);
}
setting_file = <span style="color:Blue; new OptionsFile(settings_dir + settings_file);
<span style="color:Blue; try
{
label18.Text = Options_DB.get_outputDir();
_outputDir = Options_DB.get_outputDir();
_videoFile = Options_DB.get_loadedVideo();
label13.Text = Options_DB.get_loadedVideo();
numericUpDown1.Value = Options_DB.Get_numericUpDownValue();
}
<span style="color:Blue; catch
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
button1.Enabled = <span style="color:Blue; false;
}
<span style="color:Blue; if (_outputDir == <span style="color:Blue; null || File.Exists(_outputDir))
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
button1.Enabled = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
button1.Enabled = <span style="color:Blue; true;
label18.Text = Options_DB.get_outputDir();
_outputDir = Options_DB.get_outputDir();
_videoFile = Options_DB.get_loadedVideo();
label13.Text = Options_DB.get_loadedVideo();
numericUpDown1.Value = Options_DB.Get_numericUpDownValue();
}
<span style="color:Blue; try
{
StreamWriter sw = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "accessdenied.txt");
sw.Close();
label19.ForeColor = Color.Red;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
<span style="color:Blue; if (_videoFile == <span style="color:Blue; null || !File.Exists(_videoFile))
{
button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
label13.Visible = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
label13.Visible = <span style="color:Blue; true;
button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
DirectoryInfo info = <span style="color:Blue; new DirectoryInfo(_videoFile);
<span style="color:Blue; string dirName = info.Name;
averagesListTextFileDirectory = dirName;
averagesListTextFile = dirName;
subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
reader = <span style="color:Blue; new StreamReader(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt");
<span style="color:Blue; string line;
Regex numberPattern = <span style="color:Blue; new Regex(<span style="color:#A31515; @"^(d|.)+$");
<span style="color:Blue; while ((line = reader.ReadLine()) != <span style="color:Blue; null)
{
<span style="color:Blue; if (numberPattern.IsMatch(line))
{
<span style="color:Blue; double myLine = Convert.ToDouble(line);
myNumbers.Add(myLine);
}
}
reader.Close();
max = myNumbers.Max();
min = myNumbers.Min();
Directory.CreateDirectory(subDirectoryName);
numericUpDown1.Enabled = <span style="color:Blue; false;
openFileDialog1 = <span style="color:Blue; new OpenFileDialog();
timeElapsed = 0;
label1.Visible = <span style="color:Blue; false;
label2.Visible = <span style="color:Blue; false;
label3.Visible = <span style="color:Blue; false;
label4.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
label11.Visible = <span style="color:Blue; false;
label12.Visible = <span style="color:Blue; false;
label10.Text = <span style="color:#A31515; "00:00:00";
checkBox2.Enabled = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
_videoFile = Options_DB.get_loadedVideo();
label13.Text = Options_DB.get_loadedVideo();
DoThresholdCheck();
}
}
<span style="color:Blue; private <span style="color:Blue; void button1_Click(<span style="color:Blue; object sender, EventArgs e)
{
Start(<span style="color:Blue; false);
}
<span style="color:Blue; private <span style="color:Blue; void Start(<span style="color:Blue; bool secondpass)
{
SetPicture(-1);
<span style="color:Blue; if (Directory.Exists(_outputDir) && secondpass == <span style="color:Blue; false)
{
}
<span style="color:Blue; else
{
Directory.CreateDirectory(_outputDir);
}
<span style="color:Blue; string subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
Directory.CreateDirectory(subDirectoryName);
f = <span style="color:Blue; new WmvAdapter(_videoFile,
Path.Combine(subDirectoryName));
f.Secondpass = secondpass;
f.FramesToSave = _fts;
f.FrameCountAvailable += <span style="color:Blue; new WmvAdapter.FrameCountEventHandler(f_FrameCountAvailable);
f.StatusChanged += <span style="color:Blue; new WmvAdapter.EventHandler(f_StatusChanged);
f.ProgressChanged += <span style="color:Blue; new WmvAdapter.ProgressEventHandler(f_ProgressChanged);
<span style="color:Blue; this.Text = <span style="color:#A31515; "Working...";
label5.Visible = <span style="color:Blue; true;
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
Hrs = 0; <span style="color:Green; //number of hours
Min = 0; <span style="color:Green; //number of Minutes
Sec = 0; <span style="color:Green; //number of Sec
timeElapsed = 0;
label10.Text = <span style="color:#A31515; "00:00:00";
label11.Visible = <span style="color:Blue; false;
label12.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.checkBox2.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.checkBox1.Enabled = <span style="color:Blue; false;
timer1.Start();
<span style="color:Green; //this.Enabled = false;
label2.Text = <span style="color:#A31515; "";
label1.Visible = <span style="color:Blue; true;
label2.Visible = <span style="color:Blue; true;
label3.Visible = <span style="color:Blue; true;
label4.Visible = <span style="color:Blue; true;
f.Start();
}
<span style="color:Blue; private <span style="color:Blue; void SetPicture(<span style="color:Blue; int indx)
{
<span style="color:Blue; if (_fi == <span style="color:Blue; null)
{
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
label5.Visible = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
<span style="color:Blue; if (indx >= 0 && indx <= myTrackPanelss1.trackBar1.Maximum && _fi.Length > indx)
{
<span style="color:Blue; try
{
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
<span style="color:Green; // try use a bool flag
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
<span style="color:Blue; using (FileStream fs = <span style="color:Blue; new FileStream(_fi[indx].FullName, FileMode.Open))
{
<span style="color:Blue; this.label8.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label9.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label9.Text = _fi[indx].FullName;
Image img = <span style="color:Blue; null;
Bitmap bmp = <span style="color:Blue; null;
Image imgOLd = <span style="color:Blue; null;
<span style="color:Blue; try
{
label5.Visible = <span style="color:Blue; false;
img = Image.FromStream(fs);
bmp = <span style="color:Blue; new Bitmap(img);
imgOLd = <span style="color:Blue; this.pictureBox1.Image;
<span style="color:Blue; this.pictureBox1.Image = bmp;
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
imgOLd.Dispose();
img.Dispose();
img = <span style="color:Blue; null;
}
<span style="color:Blue; catch
{
<span style="color:Blue; if (img != <span style="color:Blue; null)
img.Dispose();
<span style="color:Blue; if (bmp != <span style="color:Blue; null)
bmp.Dispose();
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
imgOLd.Dispose();
}
}
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
}
<span style="color:Blue; else
{
Image imgOLd = <span style="color:Blue; this.pictureBox1.Image;
<span style="color:Green; //this.pictureBox1.Image = null;
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
{
imgOLd.Dispose();
imgOLd = <span style="color:Blue; null;
}
Application.DoEvents();
}
}
}
<span style="color:Blue; void f_StatusChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del2(f_StatusChanged), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
WmvAdapter f = (WmvAdapter)sender;
averages = f.AveragesList;
<span style="color:Blue; bool secondPass = f.Secondpass;
<span style="color:Green; //free the resources
f.Dispose();
<span style="color:Blue; this.progressBar1.Value = <span style="color:Blue; this.progressBar1.Maximum;
<span style="color:Blue; if (!secondPass)
{
<span style="color:Green; //do the second pass processing
averages = f.AveragesList;
DoCheckResults(_outputDir , averages);
w = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "\" + averagesListTextFileDirectory + "\<span style="color:#A31515; " + averagesListTextFile + ".txt",<span style="color:Blue; false,Encoding.ASCII);
w.WriteLine(<span style="color:#A31515; "DANNY VIDEO META DATArnFORMAT VERSION:1.00rnSOURCE: " + <span style="color:#A31515; "<" + averagesListTextFile + <span style="color:#A31515; " + <span style="color:#A31515; "rnDATA: ");
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < averages.Count; i++)
{
w.WriteLine(averages);
}
w.WriteLine(<span style="color:#A31515; "DATA");
w.Close();
<span style="color:Blue; this.progressBar1.Value = 0;
Start(<span style="color:Blue; true);
}
<span style="color:Blue; else
{
<span style="color:Blue; this.Text = <span style="color:#A31515; "Done";
<span style="color:Blue; this.button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
<span style="color:Green; //this.checkBox2.Enabled = true;
<span style="color:Blue; this.checkBox1.Enabled = <span style="color:Blue; true;
<span style="color:Green; //this.Enabled = true;
timer1.Stop();
<span style="color:Blue; this.progressBar1.Value = 0;
<span style="color:Blue; this.progressBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.label2.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.label4.Visible = <span style="color:Blue; false;
<span style="color:Blue; if (Directory.Exists(subDirectoryName))
{
_fi = <span style="color:Blue; new DirectoryInfo(subDirectoryName).GetFiles(<span style="color:#A31515; "*.bmp");
myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;
<span style="color:Blue; if ( myTrackPanelss1.trackBar1.Maximum > 0)
{
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
}
}
label11.Visible = <span style="color:Blue; true;
label12.Text = f.FramesToSave.Count.ToString();
label12.Visible = <span style="color:Blue; true;
}
}
}
<span style="color:Blue; private <span style="color:Blue; void DoCheckResults(<span style="color:Blue; string outputDir, List<<span style="color:Blue; double> averages)
{
<span style="color:Blue; double max = averages.Max();
<span style="color:Blue; double min = averages.Min();
_fts = <span style="color:Blue; new List<<span style="color:Blue; int>();
<span style="color:Blue; if (Directory.Exists(outputDir))
{
<span style="color:Green; //FileInfo[] allFiles = new DirectoryInfo(outputDir).GetFiles();
<span style="color:Blue; double thershold = (<span style="color:Blue; double)numericUpDown1.Value;
<span style="color:Blue; double max_min_threshold = (thershold/100) * (max-min) + min;
<span style="color:Green; //label13.Text = max_min_threshold.ToString();
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < averages.Count; i++)
{
<span style="color:Blue; if (averages >= max_min_threshold)
{
_fts.Add(i);
}
}
}
}
<span style="color:Blue; void f_ProgressChanged(<span style="color:Blue; object sender, ProgressEventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del1(f_ProgressChanged), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; if (e.FrameID < <span style="color:Blue; this.progressBar1.Maximum)
<span style="color:Blue; this.progressBar1.Value = e.FrameID;
<span style="color:Blue; this.label2.Text = e.FrameID.ToString();
}
}
<span style="color:Blue; void f_FrameCountAvailable(<span style="color:Blue; object sender, FrameCountEventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del3(f_FrameCountAvailable), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; this.progressBar1.Maximum = (<span style="color:Blue; int)e.FrameCount;
<span style="color:Blue; this.label1.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label3.Text = e.FrameCount.ToString();
<span style="color:Blue; this.progressBar1.Enabled = <span style="color:Blue; true;
}
}
<span style="color:Blue; void trackBar1_Scroll(<span style="color:Blue; object sender, EventArgs e)
{
SetPicture( myTrackPanelss1.trackBar1.Value);
}
<span style="color:Blue; private <span style="color:Blue; void loadToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; string directoryName = <span style="color:#A31515; "";
<span style="color:Blue; string file1 = <span style="color:#A31515; "";
DialogResult result1; result1 = <span style="color:Blue; new DialogResult();
openFileDialog1.Title = <span style="color:#A31515; "Select a vide ofile to load";
openFileDialog1.InitialDirectory = "c:\";
openFileDialog1.FileName = <span style="color:Blue; null;
openFileDialog1.Filter = <span style="color:#A31515; "Video File|*.mov;*.avi;*.mp4|Mov Avi Or MP4|*.mov;*.avi;*.mp4";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = <span style="color:Blue; true;
result1 = openFileDialog1.ShowDialog();
<span style="color:Blue; if (result1 == DialogResult.OK)
{
file1 = openFileDialog1.FileName;
_videoFile = file1;
Options_DB.set_loadedVideo(_videoFile);
label1.Visible = <span style="color:Blue; true;
button1.Enabled = <span style="color:Blue; true;
DirectoryInfo inf = <span style="color:Blue; new DirectoryInfo(openFileDialog1.FileName);
directoryName = inf.Name;
label6.Visible = <span style="color:Blue; true;
label13.Visible = <span style="color:Blue; true;
label13.Text = directoryName;
averagesListTextFileDirectory = directoryName;
averagesListTextFile = directoryName;
subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
reader = <span style="color:Blue; new StreamReader(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt");
myNumbers = <span style="color:Blue; new List<<span style="color:Blue; double>();
<span style="color:Blue; string line;
Regex numberPattern = <span style="color:Blue; new Regex(<span style="color:#A31515; @"^(d|.)+$");
<span style="color:Blue; while ((line = reader.ReadLine()) != <span style="color:Blue; null)
{
<span style="color:Blue; if (numberPattern.IsMatch(line))
{
<span style="color:Blue; double myLine = Convert.ToDouble(line);
myNumbers.Add(myLine);
}
}
DoThresholdCheck();
}
<span style="color:Blue; if (result1 == DialogResult.Cancel)
{
<span style="color:Blue; if (file1 == <span style="color:#A31515; "")
{
}
}
}
<span style="color:Blue; private <span style="color:Blue; void timer1_Tick(<span style="color:Blue; object sender, EventArgs e)
{
timeElapsed = timeElapsed + 1;
label10.Text = GetTime(timeElapsed);
}
<span style="color:Blue; public <span style="color:Blue; string GetTime(<span style="color:Blue; int Time)
{
<span style="color:Green; //Seconds
Sec = Time % 60;
<span style="color:Green; //Minutes
Min = ((Time - Sec) / 60) % 60;
<span style="color:Green; //Hours
Hrs = ((Time - (Sec + (Min * 60))) / 3600) % 60;
<span style="color:Blue; return Hrs.ToString(<span style="color:#A31515; "00") + <span style="color:#A31515; ":" +
Min.ToString(<span style="color:#A31515; "00") + <span style="color:#A31515; ":" +
Sec.ToString(<span style="color:#A31515; "00");
}
<span style="color:Blue; private <span style="color:Blue; void Form1_FormClosing(<span style="color:Blue; object sender, FormClosingEventArgs e)
{
<span style="color:Blue; if (MessageBox.Show(<span style="color:#A31515; "Are you Sure you want to Exit. Click Yes to Confirm and No to continue", <span style="color:#A31515; "WinForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
e.Cancel = <span style="color:Blue; false;
Environment.Exit(0);
}
}
<span style="color:Blue; private <span style="color:Blue; void checkBox1_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (checkBox1.Checked)
{
numericUpDown1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
numericUpDown1.Enabled = <span style="color:Blue; false;
}
}
<span style="color:Blue; private <span style="color:Blue; void numericUpDown1_ValueChanged(<span style="color:Blue; object sender, EventArgs e)
{
Options_DB.Set_numericUpDownValue(numericUpDown1.Value);
<span style="color:Blue; this.Text = <span style="color:Blue; new Random().Next().ToString();
<span style="color:Blue; if (timer2.Enabled)
timer2.Stop();
timer2.Start();
}
<span style="color:Blue; private <span style="color:Blue; void timer2_Tick(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; this.timer2.Stop();
myTrackPanelss1.trackBar1.Scroll -= <span style="color:Blue; new EventHandler(trackBar1_Scroll);
DoThresholdCheck();
}
<span style="color:Blue; private <span style="color:Blue; void checkBox2_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (checkBox2.Checked)
{
myTrackPanelss1.panel1.Visible = <span style="color:Blue; true;
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(myTrackPanless1_trackBar1_Scroll);
SetPicture( myTrackPanelss1.trackBar1.Value);
<span style="color:Green; //createAnimatedGif();
}
<span style="color:Blue; else
{
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
SetPicture(myTrackPanelss1.trackBar1.Value);
}
}
<span style="color:Blue; private <span style="color:Blue; void myTrackPanless1_trackBar1_Scroll(<span style="color:Blue; object sender, EventArgs e)
{
SetPicture(myTrackPanelss1.trackBar1.Value);
}
<span style="color:Blue; private <span style="color:Blue; void createAnimatedGif()
{
UnFreezWrapper u = <span style="color:Blue; new UnFreezWrapper();
List<<span style="color:Blue; string> l = <span style="color:Blue; new List<<span style="color:Blue; string>();
<span style="color:Blue; for (<span style="color:Blue; int i = myTrackPanelss1.Start; i <= myTrackPanelss1.End; i++)
{
l.Add(String.Format(<span style="color:#A31515; "{0}{1}", <span style="color:#A31515; "picture", i));
}
u.MakeGIF(l, <span style="color:#A31515; @"d:anima.gif", 8, <span style="color:Blue; true);
}
<span style="color:Blue; private <span style="color:Blue; void DoThresholdCheck()
{
List<<span style="color:Blue; string> fts;
<span style="color:Blue; if (Directory.Exists(subDirectoryName))
{
<span style="color:Blue; if (!File.Exists(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt"))
{
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; bool trackbarTrueFalse = <span style="color:Blue; false ;
fts = <span style="color:Blue; new List<<span style="color:Blue; string>();
<span style="color:Blue; int counter = 0;
<span style="color:Blue; double thershold = (<span style="color:Blue; double)numericUpDown1.Value;
<span style="color:Blue; double max_min_threshold = (thershold / 100) * (max - min) + min;
<span style="color:Green; //label13.Text = max_min_threshold.ToString();
_fi = <span style="color:Blue; new DirectoryInfo(subDirectoryName).GetFiles(<span style="color:#A31515; "*.bmp");
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < myNumbers.Count; i++)
{
<span style="color:Blue; if (myNumbers >= max_min_threshold)
{
<span style="color:Blue; string t = i.ToString(<span style="color:#A31515; "D6") + <span style="color:#A31515; ".bmp";
<span style="color:Blue; if (File.Exists(subDirectoryName + "\" + t))
{
counter++;
button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
trackbarTrueFalse = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
label9.Visible = <span style="color:Blue; false;
trackbarTrueFalse = <span style="color:Blue; false;
button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Value = 0;
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
label5.Visible = <span style="color:Blue; true;
<span style="color:Blue; break;
}
}
}
<span style="color:Blue; if (myTrackPanelss1.trackBar1.Maximum > 0)
{
<span style="color:Blue; if (trackbarTrueFalse == <span style="color:Blue; false)
{
myTrackPanelss1.trackBar1.Value = 0;
}
<span style="color:Blue; else
{
myTrackPanelss1.trackBar1.Maximum = counter;
label21.Text = myTrackPanelss1.trackBar1.Maximum.ToString();
myTrackPanelss1.trackBar1.Value = 0;
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
}
}
<span style="color:Blue; if (_fi.Length >= 0)
{
label15.Text = _fi.Length.ToString();
label15.Visible = <span style="color:Blue; true;
}
}
}
<span style="color:Blue; else
{
button1.Enabled = <span style="color:Blue; true;
}
}
<span style="color:Blue; private <span style="color:Blue; void optionsToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
om = <span style="color:Blue; new Options_Menu();
om.Show();
om.FormClosing += <span style="color:Blue; new FormClosingEventHandler(optionsMenu1_FormClosing);
optionsToolStripMenuItem.Enabled = <span style="color:Blue; false;
om.Location = <span style="color:Blue; new Point(0, 0);
om.tb.TextChanged += <span style="color:Blue; new EventHandler(tb_TextChanged);
}
<span style="color:Blue; private <span style="color:Blue; void optionsMenu1_FormClosing(<span style="color:Blue; object sender, FormClosingEventArgs e)
{
optionsToolStripMenuItem.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; private <span style="color:Blue; void tb_TextChanged(<span style="color:Blue; object sender, EventArgs e)
{
label18.Text = om.tb.Text;
<span style="color:Blue; if (om.enabledOrNot == <span style="color:Blue; true)
{
<span style="color:Blue; try
{
_outputDir = Options_DB.get_outputDir();
StreamWriter sw = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "accessdenied.txt");
sw.Close();
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
}
}
<span style="color:Blue; private <span style="color:Blue; void label11_Click(<span style="color:Blue; object sender, EventArgs e)
{
}
<span style="color:Blue; private <span style="color:Blue; void numericUpDown1_KeyPress(<span style="color:Blue; object sender, KeyPressEventArgs e)
{
numericUpDown1_ValueChanged(<span style="color:Blue; this.numericUpDown1, <span style="color:Blue; new EventArgs());
}
}
}
[/code]
<hr class="sig danieli
View the full article
So i loop through all the images in the list and now im giving the user the option to select the threshold so he decide the threshold of the lightning and wich images are with lightnings inside and therfore to save ot hard disk this images.
But i want it to be automatic . The user just click a button it will loop through images and will save to hard disk all the images with lightnings inside.
<br/>
So i did some tests: Threshold/Frames: 60 - 69 , 65 - 53 , 70 - 48 , 75 - 42 , 80 - 33 , 85 - 23 , 90 - 14 , 95 - 6<br/>
<br/>
55 - 78 , 50 - 86 , 45 - 91 , 40 - 97 if the user set the threshold to 40 it will save 97 frames. and if it set to 60 so only 69 frames. But the user cant guess the right threshold.
<br/>
This is the code im using now:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using Polkan.DataSource;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using unfreez_wrapper;
<span style="color:Blue; using WindowsFormsApplication1;
<span style="color:Blue; using DannyGeneral;
<span style="color:Blue; using System.Text.RegularExpressions;
<span style="color:Blue; namespace Extracting_Frames
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Blue; bool isNumericChanged;
<span style="color:Blue; int counter;
<span style="color:Blue; bool secondPass;
<span style="color:Blue; double max = 0;
<span style="color:Blue; double min = 0;
List<<span style="color:Blue; double> myNumbers = <span style="color:Blue; new List<<span style="color:Blue; double>();
StreamReader reader;
List<<span style="color:Blue; double> averages;
<span style="color:Blue; string subDirectoryName;
Options_Menu om;
<span style="color:Blue; public <span style="color:Blue; string _outputDir;
<span style="color:Blue; static <span style="color:Blue; string settings_dir;
<span style="color:Blue; static <span style="color:Blue; string settings_file;
<span style="color:Blue; static OptionsFile setting_file;
<span style="color:Blue; static <span style="color:Blue; string path_settings;
<span style="color:Blue; string averagesListTextFileDirectory;
<span style="color:Blue; string averagesListTextFile;
StreamWriter w;
OpenFileDialog openFileDialog1;
<span style="color:Blue; int Hrs = 0; <span style="color:Green; //number of hours
<span style="color:Blue; int Min = 0; <span style="color:Green; //number of Minutes
<span style="color:Blue; int Sec = 0; <span style="color:Green; //number of Sec
<span style="color:Blue; int timeElapsed;
WmvAdapter f;
<span style="color:Blue; private <span style="color:Blue; string _videoFile;
FileInfo[] _fi = <span style="color:Blue; null;
<span style="color:Blue; delegate <span style="color:Blue; void del1(<span style="color:Blue; object sender, ProgressEventArgs e);
<span style="color:Blue; delegate <span style="color:Blue; void del2(<span style="color:Blue; object sender, EventArgs e);
<span style="color:Blue; delegate <span style="color:Blue; void del3(<span style="color:Blue; object sender, FrameCountEventArgs e);
<span style="color:Green; //Controls
<span style="color:Blue; private System.Windows.Forms.Button button1 = <span style="color:Blue; new System.Windows.Forms.Button();
<span style="color:Blue; private System.Windows.Forms.PictureBox pictureBox1 = <span style="color:Blue; new System.Windows.Forms.PictureBox();
<span style="color:Blue; private System.Windows.Forms.ProgressBar progressBar1 = <span style="color:Blue; new System.Windows.Forms.ProgressBar();
<span style="color:Blue; private System.Windows.Forms.Label label2 = <span style="color:Blue; new System.Windows.Forms.Label();
<span style="color:Blue; private List<<span style="color:Blue; int> _fts;
<span style="color:Blue; public Form1()
{
InitializeComponent();
isNumericChanged = <span style="color:Blue; false;
counter = 0;
secondPass = <span style="color:Blue; false;
openFileDialog1 = <span style="color:Blue; new OpenFileDialog();
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Visible = <span style="color:Blue; true;
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
path_settings = Path.GetDirectoryName(Application.LocalUserAppDataPath);
settings_file = <span style="color:#A31515; "\settings.txt";
settings_dir = path_settings + <span style="color:#A31515; @"settings";
<span style="color:Blue; if (Directory.Exists(settings_dir))
{
}
<span style="color:Blue; else
{
Directory.CreateDirectory(settings_dir);
}
<span style="color:Blue; if (!File.Exists(settings_dir + settings_file))
{
File.Create(settings_dir + settings_file);
}
setting_file = <span style="color:Blue; new OptionsFile(settings_dir + settings_file);
<span style="color:Blue; try
{
label18.Text = Options_DB.get_outputDir();
_outputDir = Options_DB.get_outputDir();
_videoFile = Options_DB.get_loadedVideo();
label13.Text = Options_DB.get_loadedVideo();
numericUpDown1.Value = Options_DB.Get_numericUpDownValue();
}
<span style="color:Blue; catch
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
button1.Enabled = <span style="color:Blue; false;
}
<span style="color:Blue; if (_outputDir == <span style="color:Blue; null || File.Exists(_outputDir))
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
button1.Enabled = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
button1.Enabled = <span style="color:Blue; true;
label18.Text = Options_DB.get_outputDir();
_outputDir = Options_DB.get_outputDir();
_videoFile = Options_DB.get_loadedVideo();
label13.Text = Options_DB.get_loadedVideo();
numericUpDown1.Value = Options_DB.Get_numericUpDownValue();
}
<span style="color:Blue; try
{
StreamWriter sw = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "accessdenied.txt");
sw.Close();
label19.ForeColor = Color.Red;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
<span style="color:Blue; if (_videoFile == <span style="color:Blue; null || !File.Exists(_videoFile))
{
button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
label13.Visible = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
label13.Visible = <span style="color:Blue; true;
button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
DirectoryInfo info = <span style="color:Blue; new DirectoryInfo(_videoFile);
<span style="color:Blue; string dirName = info.Name;
averagesListTextFileDirectory = dirName;
averagesListTextFile = dirName;
subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
reader = <span style="color:Blue; new StreamReader(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt");
<span style="color:Blue; string line;
Regex numberPattern = <span style="color:Blue; new Regex(<span style="color:#A31515; @"^(d|.)+$");
<span style="color:Blue; while ((line = reader.ReadLine()) != <span style="color:Blue; null)
{
<span style="color:Blue; if (numberPattern.IsMatch(line))
{
<span style="color:Blue; double myLine = Convert.ToDouble(line);
myNumbers.Add(myLine);
}
}
reader.Close();
max = myNumbers.Max();
min = myNumbers.Min();
Directory.CreateDirectory(subDirectoryName);
numericUpDown1.Enabled = <span style="color:Blue; false;
openFileDialog1 = <span style="color:Blue; new OpenFileDialog();
timeElapsed = 0;
label1.Visible = <span style="color:Blue; false;
label2.Visible = <span style="color:Blue; false;
label3.Visible = <span style="color:Blue; false;
label4.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
label11.Visible = <span style="color:Blue; false;
label12.Visible = <span style="color:Blue; false;
label10.Text = <span style="color:#A31515; "00:00:00";
checkBox2.Enabled = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
_videoFile = Options_DB.get_loadedVideo();
label13.Text = Options_DB.get_loadedVideo();
DoThresholdCheck();
}
}
<span style="color:Blue; private <span style="color:Blue; void button1_Click(<span style="color:Blue; object sender, EventArgs e)
{
Start(<span style="color:Blue; false);
}
<span style="color:Blue; private <span style="color:Blue; void Start(<span style="color:Blue; bool secondpass)
{
SetPicture(-1);
<span style="color:Blue; if (Directory.Exists(_outputDir) && secondpass == <span style="color:Blue; false)
{
}
<span style="color:Blue; else
{
Directory.CreateDirectory(_outputDir);
}
<span style="color:Blue; string subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
Directory.CreateDirectory(subDirectoryName);
f = <span style="color:Blue; new WmvAdapter(_videoFile,
Path.Combine(subDirectoryName));
f.Secondpass = secondpass;
f.FramesToSave = _fts;
f.FrameCountAvailable += <span style="color:Blue; new WmvAdapter.FrameCountEventHandler(f_FrameCountAvailable);
f.StatusChanged += <span style="color:Blue; new WmvAdapter.EventHandler(f_StatusChanged);
f.ProgressChanged += <span style="color:Blue; new WmvAdapter.ProgressEventHandler(f_ProgressChanged);
<span style="color:Blue; this.Text = <span style="color:#A31515; "Working...";
label5.Visible = <span style="color:Blue; true;
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
Hrs = 0; <span style="color:Green; //number of hours
Min = 0; <span style="color:Green; //number of Minutes
Sec = 0; <span style="color:Green; //number of Sec
timeElapsed = 0;
label10.Text = <span style="color:#A31515; "00:00:00";
label11.Visible = <span style="color:Blue; false;
label12.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.checkBox2.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.checkBox1.Enabled = <span style="color:Blue; false;
timer1.Start();
<span style="color:Green; //this.Enabled = false;
label2.Text = <span style="color:#A31515; "";
label1.Visible = <span style="color:Blue; true;
label2.Visible = <span style="color:Blue; true;
label3.Visible = <span style="color:Blue; true;
label4.Visible = <span style="color:Blue; true;
f.Start();
}
<span style="color:Blue; private <span style="color:Blue; void SetPicture(<span style="color:Blue; int indx)
{
<span style="color:Blue; if (_fi == <span style="color:Blue; null)
{
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
label5.Visible = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
<span style="color:Blue; if (indx >= 0 && indx <= myTrackPanelss1.trackBar1.Maximum && _fi.Length > indx)
{
<span style="color:Blue; try
{
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
<span style="color:Green; // try use a bool flag
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
<span style="color:Blue; using (FileStream fs = <span style="color:Blue; new FileStream(_fi[indx].FullName, FileMode.Open))
{
<span style="color:Blue; this.label8.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label9.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label9.Text = _fi[indx].FullName;
Image img = <span style="color:Blue; null;
Bitmap bmp = <span style="color:Blue; null;
Image imgOLd = <span style="color:Blue; null;
<span style="color:Blue; try
{
label5.Visible = <span style="color:Blue; false;
img = Image.FromStream(fs);
bmp = <span style="color:Blue; new Bitmap(img);
imgOLd = <span style="color:Blue; this.pictureBox1.Image;
<span style="color:Blue; this.pictureBox1.Image = bmp;
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
imgOLd.Dispose();
img.Dispose();
img = <span style="color:Blue; null;
}
<span style="color:Blue; catch
{
<span style="color:Blue; if (img != <span style="color:Blue; null)
img.Dispose();
<span style="color:Blue; if (bmp != <span style="color:Blue; null)
bmp.Dispose();
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
imgOLd.Dispose();
}
}
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
}
<span style="color:Blue; else
{
Image imgOLd = <span style="color:Blue; this.pictureBox1.Image;
<span style="color:Green; //this.pictureBox1.Image = null;
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
{
imgOLd.Dispose();
imgOLd = <span style="color:Blue; null;
}
Application.DoEvents();
}
}
}
<span style="color:Blue; void f_StatusChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del2(f_StatusChanged), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
WmvAdapter f = (WmvAdapter)sender;
averages = f.AveragesList;
<span style="color:Blue; bool secondPass = f.Secondpass;
<span style="color:Green; //free the resources
f.Dispose();
<span style="color:Blue; this.progressBar1.Value = <span style="color:Blue; this.progressBar1.Maximum;
<span style="color:Blue; if (!secondPass)
{
<span style="color:Green; //do the second pass processing
averages = f.AveragesList;
DoCheckResults(_outputDir , averages);
w = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "\" + averagesListTextFileDirectory + "\<span style="color:#A31515; " + averagesListTextFile + ".txt",<span style="color:Blue; false,Encoding.ASCII);
w.WriteLine(<span style="color:#A31515; "DANNY VIDEO META DATArnFORMAT VERSION:1.00rnSOURCE: " + <span style="color:#A31515; "<" + averagesListTextFile + <span style="color:#A31515; " + <span style="color:#A31515; "rnDATA: ");
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < averages.Count; i++)
{
w.WriteLine(averages);
}
w.WriteLine(<span style="color:#A31515; "DATA");
w.Close();
<span style="color:Blue; this.progressBar1.Value = 0;
Start(<span style="color:Blue; true);
}
<span style="color:Blue; else
{
<span style="color:Blue; this.Text = <span style="color:#A31515; "Done";
<span style="color:Blue; this.button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
<span style="color:Green; //this.checkBox2.Enabled = true;
<span style="color:Blue; this.checkBox1.Enabled = <span style="color:Blue; true;
<span style="color:Green; //this.Enabled = true;
timer1.Stop();
<span style="color:Blue; this.progressBar1.Value = 0;
<span style="color:Blue; this.progressBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.label2.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.label4.Visible = <span style="color:Blue; false;
<span style="color:Blue; if (Directory.Exists(subDirectoryName))
{
_fi = <span style="color:Blue; new DirectoryInfo(subDirectoryName).GetFiles(<span style="color:#A31515; "*.bmp");
myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;
<span style="color:Blue; if ( myTrackPanelss1.trackBar1.Maximum > 0)
{
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
}
}
label11.Visible = <span style="color:Blue; true;
label12.Text = f.FramesToSave.Count.ToString();
label12.Visible = <span style="color:Blue; true;
}
}
}
<span style="color:Blue; private <span style="color:Blue; void DoCheckResults(<span style="color:Blue; string outputDir, List<<span style="color:Blue; double> averages)
{
<span style="color:Blue; double max = averages.Max();
<span style="color:Blue; double min = averages.Min();
_fts = <span style="color:Blue; new List<<span style="color:Blue; int>();
<span style="color:Blue; if (Directory.Exists(outputDir))
{
<span style="color:Green; //FileInfo[] allFiles = new DirectoryInfo(outputDir).GetFiles();
<span style="color:Blue; double thershold = (<span style="color:Blue; double)numericUpDown1.Value;
<span style="color:Blue; double max_min_threshold = (thershold/100) * (max-min) + min;
<span style="color:Green; //label13.Text = max_min_threshold.ToString();
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < averages.Count; i++)
{
<span style="color:Blue; if (averages >= max_min_threshold)
{
_fts.Add(i);
}
}
}
}
<span style="color:Blue; void f_ProgressChanged(<span style="color:Blue; object sender, ProgressEventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del1(f_ProgressChanged), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; if (e.FrameID < <span style="color:Blue; this.progressBar1.Maximum)
<span style="color:Blue; this.progressBar1.Value = e.FrameID;
<span style="color:Blue; this.label2.Text = e.FrameID.ToString();
}
}
<span style="color:Blue; void f_FrameCountAvailable(<span style="color:Blue; object sender, FrameCountEventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del3(f_FrameCountAvailable), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; this.progressBar1.Maximum = (<span style="color:Blue; int)e.FrameCount;
<span style="color:Blue; this.label1.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label3.Text = e.FrameCount.ToString();
<span style="color:Blue; this.progressBar1.Enabled = <span style="color:Blue; true;
}
}
<span style="color:Blue; void trackBar1_Scroll(<span style="color:Blue; object sender, EventArgs e)
{
SetPicture( myTrackPanelss1.trackBar1.Value);
}
<span style="color:Blue; private <span style="color:Blue; void loadToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; string directoryName = <span style="color:#A31515; "";
<span style="color:Blue; string file1 = <span style="color:#A31515; "";
DialogResult result1; result1 = <span style="color:Blue; new DialogResult();
openFileDialog1.Title = <span style="color:#A31515; "Select a vide ofile to load";
openFileDialog1.InitialDirectory = "c:\";
openFileDialog1.FileName = <span style="color:Blue; null;
openFileDialog1.Filter = <span style="color:#A31515; "Video File|*.mov;*.avi;*.mp4|Mov Avi Or MP4|*.mov;*.avi;*.mp4";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = <span style="color:Blue; true;
result1 = openFileDialog1.ShowDialog();
<span style="color:Blue; if (result1 == DialogResult.OK)
{
file1 = openFileDialog1.FileName;
_videoFile = file1;
Options_DB.set_loadedVideo(_videoFile);
label1.Visible = <span style="color:Blue; true;
button1.Enabled = <span style="color:Blue; true;
DirectoryInfo inf = <span style="color:Blue; new DirectoryInfo(openFileDialog1.FileName);
directoryName = inf.Name;
label6.Visible = <span style="color:Blue; true;
label13.Visible = <span style="color:Blue; true;
label13.Text = directoryName;
averagesListTextFileDirectory = directoryName;
averagesListTextFile = directoryName;
subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
reader = <span style="color:Blue; new StreamReader(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt");
myNumbers = <span style="color:Blue; new List<<span style="color:Blue; double>();
<span style="color:Blue; string line;
Regex numberPattern = <span style="color:Blue; new Regex(<span style="color:#A31515; @"^(d|.)+$");
<span style="color:Blue; while ((line = reader.ReadLine()) != <span style="color:Blue; null)
{
<span style="color:Blue; if (numberPattern.IsMatch(line))
{
<span style="color:Blue; double myLine = Convert.ToDouble(line);
myNumbers.Add(myLine);
}
}
DoThresholdCheck();
}
<span style="color:Blue; if (result1 == DialogResult.Cancel)
{
<span style="color:Blue; if (file1 == <span style="color:#A31515; "")
{
}
}
}
<span style="color:Blue; private <span style="color:Blue; void timer1_Tick(<span style="color:Blue; object sender, EventArgs e)
{
timeElapsed = timeElapsed + 1;
label10.Text = GetTime(timeElapsed);
}
<span style="color:Blue; public <span style="color:Blue; string GetTime(<span style="color:Blue; int Time)
{
<span style="color:Green; //Seconds
Sec = Time % 60;
<span style="color:Green; //Minutes
Min = ((Time - Sec) / 60) % 60;
<span style="color:Green; //Hours
Hrs = ((Time - (Sec + (Min * 60))) / 3600) % 60;
<span style="color:Blue; return Hrs.ToString(<span style="color:#A31515; "00") + <span style="color:#A31515; ":" +
Min.ToString(<span style="color:#A31515; "00") + <span style="color:#A31515; ":" +
Sec.ToString(<span style="color:#A31515; "00");
}
<span style="color:Blue; private <span style="color:Blue; void Form1_FormClosing(<span style="color:Blue; object sender, FormClosingEventArgs e)
{
<span style="color:Blue; if (MessageBox.Show(<span style="color:#A31515; "Are you Sure you want to Exit. Click Yes to Confirm and No to continue", <span style="color:#A31515; "WinForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
e.Cancel = <span style="color:Blue; false;
Environment.Exit(0);
}
}
<span style="color:Blue; private <span style="color:Blue; void checkBox1_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (checkBox1.Checked)
{
numericUpDown1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
numericUpDown1.Enabled = <span style="color:Blue; false;
}
}
<span style="color:Blue; private <span style="color:Blue; void numericUpDown1_ValueChanged(<span style="color:Blue; object sender, EventArgs e)
{
Options_DB.Set_numericUpDownValue(numericUpDown1.Value);
<span style="color:Blue; this.Text = <span style="color:Blue; new Random().Next().ToString();
<span style="color:Blue; if (timer2.Enabled)
timer2.Stop();
timer2.Start();
}
<span style="color:Blue; private <span style="color:Blue; void timer2_Tick(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; this.timer2.Stop();
myTrackPanelss1.trackBar1.Scroll -= <span style="color:Blue; new EventHandler(trackBar1_Scroll);
DoThresholdCheck();
}
<span style="color:Blue; private <span style="color:Blue; void checkBox2_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (checkBox2.Checked)
{
myTrackPanelss1.panel1.Visible = <span style="color:Blue; true;
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(myTrackPanless1_trackBar1_Scroll);
SetPicture( myTrackPanelss1.trackBar1.Value);
<span style="color:Green; //createAnimatedGif();
}
<span style="color:Blue; else
{
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
SetPicture(myTrackPanelss1.trackBar1.Value);
}
}
<span style="color:Blue; private <span style="color:Blue; void myTrackPanless1_trackBar1_Scroll(<span style="color:Blue; object sender, EventArgs e)
{
SetPicture(myTrackPanelss1.trackBar1.Value);
}
<span style="color:Blue; private <span style="color:Blue; void createAnimatedGif()
{
UnFreezWrapper u = <span style="color:Blue; new UnFreezWrapper();
List<<span style="color:Blue; string> l = <span style="color:Blue; new List<<span style="color:Blue; string>();
<span style="color:Blue; for (<span style="color:Blue; int i = myTrackPanelss1.Start; i <= myTrackPanelss1.End; i++)
{
l.Add(String.Format(<span style="color:#A31515; "{0}{1}", <span style="color:#A31515; "picture", i));
}
u.MakeGIF(l, <span style="color:#A31515; @"d:anima.gif", 8, <span style="color:Blue; true);
}
<span style="color:Blue; private <span style="color:Blue; void DoThresholdCheck()
{
List<<span style="color:Blue; string> fts;
<span style="color:Blue; if (Directory.Exists(subDirectoryName))
{
<span style="color:Blue; if (!File.Exists(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt"))
{
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; bool trackbarTrueFalse = <span style="color:Blue; false ;
fts = <span style="color:Blue; new List<<span style="color:Blue; string>();
<span style="color:Blue; int counter = 0;
<span style="color:Blue; double thershold = (<span style="color:Blue; double)numericUpDown1.Value;
<span style="color:Blue; double max_min_threshold = (thershold / 100) * (max - min) + min;
<span style="color:Green; //label13.Text = max_min_threshold.ToString();
_fi = <span style="color:Blue; new DirectoryInfo(subDirectoryName).GetFiles(<span style="color:#A31515; "*.bmp");
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < myNumbers.Count; i++)
{
<span style="color:Blue; if (myNumbers >= max_min_threshold)
{
<span style="color:Blue; string t = i.ToString(<span style="color:#A31515; "D6") + <span style="color:#A31515; ".bmp";
<span style="color:Blue; if (File.Exists(subDirectoryName + "\" + t))
{
counter++;
button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
trackbarTrueFalse = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
label9.Visible = <span style="color:Blue; false;
trackbarTrueFalse = <span style="color:Blue; false;
button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Value = 0;
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
label5.Visible = <span style="color:Blue; true;
<span style="color:Blue; break;
}
}
}
<span style="color:Blue; if (myTrackPanelss1.trackBar1.Maximum > 0)
{
<span style="color:Blue; if (trackbarTrueFalse == <span style="color:Blue; false)
{
myTrackPanelss1.trackBar1.Value = 0;
}
<span style="color:Blue; else
{
myTrackPanelss1.trackBar1.Maximum = counter;
label21.Text = myTrackPanelss1.trackBar1.Maximum.ToString();
myTrackPanelss1.trackBar1.Value = 0;
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
}
}
<span style="color:Blue; if (_fi.Length >= 0)
{
label15.Text = _fi.Length.ToString();
label15.Visible = <span style="color:Blue; true;
}
}
}
<span style="color:Blue; else
{
button1.Enabled = <span style="color:Blue; true;
}
}
<span style="color:Blue; private <span style="color:Blue; void optionsToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
om = <span style="color:Blue; new Options_Menu();
om.Show();
om.FormClosing += <span style="color:Blue; new FormClosingEventHandler(optionsMenu1_FormClosing);
optionsToolStripMenuItem.Enabled = <span style="color:Blue; false;
om.Location = <span style="color:Blue; new Point(0, 0);
om.tb.TextChanged += <span style="color:Blue; new EventHandler(tb_TextChanged);
}
<span style="color:Blue; private <span style="color:Blue; void optionsMenu1_FormClosing(<span style="color:Blue; object sender, FormClosingEventArgs e)
{
optionsToolStripMenuItem.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; private <span style="color:Blue; void tb_TextChanged(<span style="color:Blue; object sender, EventArgs e)
{
label18.Text = om.tb.Text;
<span style="color:Blue; if (om.enabledOrNot == <span style="color:Blue; true)
{
<span style="color:Blue; try
{
_outputDir = Options_DB.get_outputDir();
StreamWriter sw = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "accessdenied.txt");
sw.Close();
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
}
}
<span style="color:Blue; private <span style="color:Blue; void label11_Click(<span style="color:Blue; object sender, EventArgs e)
{
}
<span style="color:Blue; private <span style="color:Blue; void numericUpDown1_KeyPress(<span style="color:Blue; object sender, KeyPressEventArgs e)
{
numericUpDown1_ValueChanged(<span style="color:Blue; this.numericUpDown1, <span style="color:Blue; new EventArgs());
}
}
}
[/code]
<hr class="sig danieli
View the full article