private DaVinciAPI.ImageInfo getCurrentFrame() { if (this.videoFile == null) { MessageBox.Show("No video file loaded!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(queryFrame); } DaVinciAPI.ImageEventHandler queryFrameHandler = new DaVinciAPI.ImageEventHandler(GetImgData); GCHandle gcImageEventHandler = GCHandle.Alloc(queryFrameHandler); DaVinciAPI.NativeMethods.SetScriptVideoImgHandler(queryFrameHandler); DaVinciAPI.NativeMethods.ShowVideoFrame(vidInst, this.launchTimeTrackBar.Value); if (queryFrame.iplImage == null || queryFrame.mat == null) { MessageBox.Show("Invalid frame", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(queryFrame); } else { return(queryFrame); } }
private void videoLoad() { foreach (conftype confItem in configList) { if (confItem.name.Equals("RecordedVideoType")) { if (confItem.value.Trim().Length > 0) { this.videoFile = Path.ChangeExtension(videoFile, "." + confItem.value.Trim().ToLower()); } break; } } if (File.Exists(videoFile)) { // Resume //this.timeStampList = null; //this.qs_trace = null; int initFrameIndex = 0; int frameCount = 0; vidInst = DaVinciAPI.NativeMethods.OpenVideo(videoFile, ref frameCount); try { DaVinciAPI.ImageEventHandler qScriptImageEventHandler = new DaVinciAPI.ImageEventHandler(DisplayImgLaunchTimeVideo); GCHandle gcImageEventHandler = GCHandle.Alloc(qScriptImageEventHandler); DaVinciAPI.NativeMethods.SetScriptVideoImgHandler(qScriptImageEventHandler); DaVinciAPI.NativeMethods.ShowVideoFrame(vidInst, initFrameIndex); if (frameCount >= 1) { this.launchTimeTrackBar.Maximum = frameCount - 1; } else { this.launchTimeTrackBar.Maximum = 0; } this.launchTimeTrackBar.Value = 0; this.launchTimeTrackBar.Enabled = true; this.toolStripVideo.Enabled = true; this.buttonSelectFrame.Enabled = true; } catch { MessageBox.Show("Video file \"" + videoFile + "\" cannot be loaded!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.launchTimeTrackBar.Enabled = false; this.toolStripVideo.Enabled = false; this.buttonSelectFrame.Enabled = false; return; } } else { MessageBox.Show("Video file \"" + videoFile + "\" doesn't exist!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.launchTimeTrackBar.Enabled = false; this.toolStripVideo.Enabled = false; this.buttonSelectFrame.Enabled = false; return; } }
private void launchTimeTrackBar_ValueChanged(object sender, EventArgs e) { if (!File.Exists(CreateTestSelect.fpsForm.GetAVIFile())) { return; } // change image frame DaVinciAPI.ImageEventHandler qScriptImageEventHandler = new DaVinciAPI.ImageEventHandler(DisplayImgLaunchTimeVideo); GCHandle gcImageEventHandler = GCHandle.Alloc(qScriptImageEventHandler); DaVinciAPI.NativeMethods.SetScriptVideoImgHandler(qScriptImageEventHandler); DaVinciAPI.NativeMethods.ShowVideoFrame(vidInst, this.trackBar.Value); }
static int Main(String[] args) { int retVal = 0; Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); string version = AssemblyName.GetAssemblyName(asm.Location).Version.ToString(); Console.WriteLine("DaVinci Version: " + AssemblyName.GetAssemblyName(asm.Location).Version + "\n\n"); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); string daVinciHome = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if (args.Length == 0) { if (!FolderPermissionCheck(daVinciHome)) { MessageBox.Show("No Access Permission for DaVinci Home, The Application will Exit."); return(retVal); } consoleMode = false; Thread initThread; initThread = (new Thread(() => { retVal = DaVinciAPI.NativeMethods.Init(daVinciHome, args.Length, args); //TODO: check the return of Init //if (retVal != 0) //{ // Console.WriteLine("Unable to initialize DaVinci library!"); // DaVinciAPI.NativeMethods.Shutdown(); // return retVal; //} })); initThread.Name = "Init Thread"; initThread.Start(); using (var splashScreen = new SplashScreen(version)) { splashScreen.Show(); while (initThread.IsAlive) { Application.DoEvents(); } if (!initThread.IsAlive) { splashScreen.SetInitEnd(); Thread.Sleep(1000); splashScreen.Close(); } } Application.EnableVisualStyles(); imageEventHandler = new DaVinciAPI.ImageEventHandler(DisplayImage); DaVinciAPI.NativeMethods.SetImageEventHandler(imageEventHandler); messageEventHandler = new DaVinciAPI.MessageEventHandler(DisplayMessage); DaVinciAPI.NativeMethods.SetMessageEventHandler(messageEventHandler); drawDotEventHandler = new DaVinciAPI.DrawDotEventHandler(drawDot); DaVinciAPI.NativeMethods.SetDrawDotHandler(drawDotEventHandler); drawLinesEventHandler = new DaVinciAPI.DrawLinesEventHandler(drawLines); DaVinciAPI.NativeMethods.SetDrawLinesHandler(drawLinesEventHandler); Application.Run(mainWindowInst); // Release native resources DaVinciAPI.NativeMethods.Shutdown(); } else { if (!FolderPermissionCheck(daVinciHome)) { Console.WriteLine("No Access Permission for DaVinci Home, The Application will Exit.\n"); return(retVal); } Console.CancelKeyPress += new ConsoleCancelEventHandler(CancelKeyHandler); consoleMode = true; retVal = DaVinciAPI.NativeMethods.Init(daVinciHome, args.Length, args); if (retVal != 0) { Console.WriteLine("Unable to initialize DaVinci library!"); DaVinciAPI.NativeMethods.Shutdown(); return(retVal); } DaVinciAPI.TestConfiguration testConfiguration = DaVinciAPI.NativeMethods.GetTestConfiguration(); testStatusHandler = new DaVinciAPI.TestStatusEventHandler(TestStatusEventHandler); DaVinciAPI.NativeMethods.SetTestStatusEventHandler(testStatusHandler); if (testConfiguration.suppressImageBox == DaVinciAPI.BoolType.BoolFalse) { OpenImageViewer(); imageEventHandler = new DaVinciAPI.ImageEventHandler(DisplayImage); DaVinciAPI.NativeMethods.SetImageEventHandler(imageEventHandler); } // start the specified test from command line DaVinciAPI.NativeMethods.StartTest(""); WaitForTestStop(); DaVinciAPI.NativeMethods.Shutdown(); if (testConfiguration.suppressImageBox == DaVinciAPI.BoolType.BoolFalse) { CloseImageViewer(); } Console.CancelKeyPress -= new ConsoleCancelEventHandler(CancelKeyHandler); } return(retVal); }
private void videoLoad() { foreach (conftype confItem in configList) { if (confItem.name.Equals("RecordedVideoType")) { if (confItem.value.Trim().Length > 0) { this.videoFile = Path.ChangeExtension(videoFile, "." + confItem.value.Trim().ToLower()); } break; } } if (File.Exists(videoFile)) { // Resume //this.timeStampList = null; //this.qs_trace = null; int initFrameIndex = 0; int frameCount = 0; vidInst = DaVinciAPI.NativeMethods.OpenVideo(videoFile, ref frameCount); try { DaVinciAPI.ImageEventHandler qScriptImageEventHandler = new DaVinciAPI.ImageEventHandler(DisplayImgLaunchTimeVideo); GCHandle gcImageEventHandler = GCHandle.Alloc(qScriptImageEventHandler); DaVinciAPI.NativeMethods.SetScriptVideoImgHandler(qScriptImageEventHandler); DaVinciAPI.NativeMethods.ShowVideoFrame(vidInst, initFrameIndex); if (frameCount >= 1) { this.trackBar.Maximum = frameCount - 1; } else { this.trackBar.Maximum = 0; } this.trackBar.Value = 0; } catch { MessageBox.Show("Video file \"" + videoFile + "\" cannot be loaded!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } else { MessageBox.Show("Video file \"" + videoFile + "\" doesn't exist!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (File.Exists(timeFile)) { // load time stamp file TimeStampFileReader qtsReader = new TimeStampFileReader(timeFile); this.timeStampList = qtsReader.getTimeStampList(); if (this.timeStampList.Count <= this.trackBar.Maximum) { Console.WriteLine("Warning: Time Stamp file \"" + timeFile + "\" has less time stamps than video!"); double time = this.timeStampList[this.timeStampList.Count - 1]; for (int i = this.timeStampList.Count; i <= this.trackBar.Maximum; i++) { this.timeStampList.Add(time); } } else if (this.timeStampList.Count > this.trackBar.Maximum + 1) { Console.WriteLine("Warning: Time Stamp file \"" + timeFile + "\" has more time stamps than video."); this.timeStampList.RemoveRange(this.trackBar.Maximum + 1, this.timeStampList.Count - this.trackBar.Maximum - 1); } } else { Console.WriteLine("Time Stamp file \"" + timeFile + "\" doesn't exist!"); } }