public void RunNoiseChunkRemovalTestCases(string noiseTestSource, string noiseTestResults) { string[] testCases = Directory.GetFiles(noiseTestSource, "*.bmp"); bool hasErrors = false; bool[] options = new bool[] { false, true }; string[] optionNames = new string[] { "Managed", "Native" }; for (int j = 0; j < options.Length; j++) { foreach (string file in testCases) { string expectedResult = Path.GetFullPath(noiseTestResults + "\\" + Path.GetFileName(file)); lvlTestCaseDescription.Text = string.Format("Test case NoiseChunksRemoval\\{0} ({1})", Path.GetFileName(file), optionNames[j]); lvlTestCaseDescription.Update(); Pixelmap pix = Pixelmap.ConstructFromBitmap((Bitmap)Bitmap.FromFile(file), TangraConfig.ColourChannel.Red); uint[] pixels = pix.Pixels; LargeChunkDenoiser.Process(options[j], pixels, pix.Width, pix.Height); Pixelmap pixExpected = Pixelmap.ConstructFromBitmap((Bitmap)Bitmap.FromFile(expectedResult), TangraConfig.ColourChannel.Red); for (int i = 0; i < pix.Pixels.Length; i++) { if (pix.Pixels[i] != pixExpected.Pixels[i]) { lbErrors.Items.Add(string.Format("NoiseChunk Removal Failed for {0} ({1})", Path.GetFileName(file), optionNames[j])); //Bitmap bmp = Pixelmap.ConstructBitmapFromBitmapPixels(pixels, pix.Width, pix.Height); //bmp.Save(Path.ChangeExtension(expectedResult, ".errbmp")); hasErrors = true; break; } } } } pbar.Value++; if (!hasErrors) { pbarSuccess.Value++; } else { pbarError.Value++; } lblError.Text = string.Format("Errored {0}/{1}", pbarError.Value, pbar.Value); lblSuccessful.Text = string.Format("Successful {0}/{1}", pbarSuccess.Value, pbar.Value); Application.DoEvents(); }
private void btnLoad_Click(object sender, EventArgs e) { if (File.Exists(tbxFileLocation.Text)) { m_Frame = (Bitmap)Bitmap.FromFile(tbxFileLocation.Text); //m_FieldsFrame = BitmapFilter.ToVideoFields(m_Frame); m_Pixelmap = Pixelmap.ConstructFromBitmap(m_Frame, TangraConfig.ColourChannel.GrayScale); m_Image = new AstroImage(m_Pixelmap); m_InitialPixels = m_Image.GetOcrPixels(); pictureBox1.Load(tbxFileLocation.Text); } }
private void ProcessCurrentImage() { if (m_CurrentIndex >= 0 && m_CurrentIndex < m_InputFiles.Count) { string fileName = m_InputFiles[m_CurrentIndex]; lblDisplayedFile.Text = fileName; m_CurrentImage = (Bitmap)Bitmap.FromFile(fileName); m_Pixelmap = Pixelmap.ConstructFromBitmap(m_CurrentImage, TangraConfig.ColourChannel.Red); using (Graphics g = Graphics.FromImage(m_CurrentImage)) { m_Processor.Process(m_Pixelmap.Pixels, m_Pixelmap.Width, m_Pixelmap.Height, g, m_CurrentIndex, m_CurrentIndex % 2 == 0); g.Flush(); } picField.Image = m_CurrentImage; picField.Update(); lblBlockWidth.Text = m_Processor.BlockWidth.ToString(); lblBlockHeight.Text = m_Processor.BlockHeight.ToString(); lblBlockXOffs.Text = m_Processor.BlockOffsetX.ToString(); if (m_Processor.BlockOffsetYOdd != m_Processor.BlockOffsetYEven) { lblBlockYOffs.Text = string.Format("o:{0} e:{1}", m_Processor.BlockOffsetYOdd, m_Processor.BlockOffsetYEven); } else { lblBlockYOffs.Text = m_Processor.BlockOffsetYOdd.ToString(); } PlotDigitPatterns(); if (string.IsNullOrEmpty(m_Processor.CurrentOcredString)) { lblOcredText.Text = ""; } else { lblOcredText.Text = m_Processor.CurrentOcredString; } } }
private void GenerateSimulatedVideo(object state) { InvokeUpdateUI(2, 0, true); try { ModelConfig modelConfig = (ModelConfig)state; TangraVideo.CloseAviFile(); TangraVideo.StartNewAviFile(modelConfig.FileName, 300, 200, 8, 25, false); try { using (Bitmap bmp = new Bitmap(300, 200, PixelFormat.Format24bppRgb)) { AddOnScreenText(bmp, modelConfig, "The simulated video stars from the next frame"); Pixelmap pixmap = Pixelmap.ConstructFromBitmap(bmp, TangraConfig.ColourChannel.Red); TangraVideo.AddAviVideoFrame(pixmap, modelConfig.Gamma, null); } for (int i = 1; i <= modelConfig.TotalFrames; i++) { using (Pixelmap pixmap = GenerateFrame(i * 1.0 / modelConfig.TotalFrames, i, modelConfig)) { TangraVideo.AddAviVideoFrame(pixmap, modelConfig.Gamma, null); } InvokeUpdateUI(2, (int)(100.0 * i / modelConfig.TotalFrames), true); } } finally { TangraVideo.CloseAviFile(); } } finally { InvokeUpdateUI(2, 100, false); } }
public SingleBitmapFileFrameStream(Bitmap bitmap) { try { m_Pixelmap = Pixelmap.ConstructFromBitmap(bitmap, TangraConfig.ColourChannel.Red); } catch (ArgumentException ex) { // If there is something wrong with the Bitmap, then create a blank(black) frame Trace.WriteLine(ex); m_Pixelmap = new Pixelmap( bitmap.Width, bitmap.Height, 8, new uint[bitmap.Width * bitmap.Height], new Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format24bppRgb), new byte[3 * bitmap.Width * bitmap.Height]); } m_FirstFrame = 0; m_LastFrame = 0; m_NumFrames = 1; }
private Pixelmap GenerateFrame(double percentDone, int frameNo, ModelConfig modelConfig) { float I1 = (float)modelConfig.StandardStarIntensity; float I2 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag2); float I3 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag3); float I4 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag4); float I5 = GetPsfMaxForMagnitude(modelConfig.StandardStarIntensity, modelConfig.StandardStarMag, modelConfig.StarMag5); int IPB1 = (int)Math.Round((double)modelConfig.StandardStarIntensity / Math.Pow(10, (modelConfig.PassByMag1 - modelConfig.StandardStarMag) / 2.5)); int IPB2 = (int)Math.Round((double)modelConfig.StandardStarIntensity / Math.Pow(10, (modelConfig.PassByMag2 - modelConfig.StandardStarMag) / 2.5)); float fwhm1 = (float)modelConfig.FWHM; // NOTE: Use the same FWHM to get accurate photometry //float fwhm2 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag2) * FWHM_GAIN_PER_MAG); //float fwhm3 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag3) * FWHM_GAIN_PER_MAG); //float fwhm4 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag4) * FWHM_GAIN_PER_MAG); //float fwhm5 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.StarMag5) * FWHM_GAIN_PER_MAG); float fwhm_pb1 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.PassByMag1) * FWHM_GAIN_PER_MAG); float fwhm_pb2 = (float)(modelConfig.FWHM + (modelConfig.StandardStarMag - modelConfig.PassByMag2) * FWHM_GAIN_PER_MAG); if (modelConfig.FlickeringStdDev > 0) { I1 = (int)Math.Round(VideoModelUtils.Random(I1, modelConfig.FlickeringStdDev)); I2 = (int)Math.Round(VideoModelUtils.Random(I2, modelConfig.FlickeringStdDev)); I3 = (int)Math.Round(VideoModelUtils.Random(I3, modelConfig.FlickeringStdDev)); I4 = (int)Math.Round(VideoModelUtils.Random(I4, modelConfig.FlickeringStdDev)); I5 = (int)Math.Round(VideoModelUtils.Random(I5, modelConfig.FlickeringStdDev)); } int[,] simulatedBackground = new int[300, 200]; for (int x = 0; x < 300; x++) { for (int y = 0; y < 200; y++) { simulatedBackground[x, y] = 0; } } using (Bitmap bmp = new Bitmap(300, 200, PixelFormat.Format24bppRgb)) { if (modelConfig.SimulateMovingBackground) { simulatedBackground = m_BgModelGen.GenerateBackground(modelConfig.PolyBgOrder, modelConfig.PolyBgFreq, modelConfig.PolyBgShift, modelConfig.TotalFrames * percentDone, 110, 100, 35); } VideoModelUtils.GenerateNoise(bmp, simulatedBackground, modelConfig.NoiseMean, modelConfig.NoiseStdDev); VideoModelUtils.GenerateStar(bmp, 25, 160, (float)fwhm1, I1); if (modelConfig.SimulateStar2) { VideoModelUtils.GenerateStar(bmp, 75, 160, (float)fwhm1, I2); } if (modelConfig.SimulateStar3) { VideoModelUtils.GenerateStar(bmp, 125, 160, (float)fwhm1, I3); } if (modelConfig.SimulateStar4) { VideoModelUtils.GenerateStar(bmp, 175, 160, (float)fwhm1, I4); } if (modelConfig.SimulateStar5) { VideoModelUtils.GenerateStar(bmp, 225, 160, (float)fwhm1, I5); } if (modelConfig.SimulatePassBy) { double maxVerticaldistance = Math.Sqrt(modelConfig.MaxDistance * modelConfig.MaxDistance - modelConfig.PassByDist * modelConfig.PassByDist); bool isOcculted = false; if (modelConfig.OccultedNumberOfFrames > 0 && Math.Abs(modelConfig.PassByDist) < 0.2) { int firstOccFrame = (modelConfig.TotalFrames / 2) - modelConfig.OccultedNumberOfFrames; int lastOccFrame = (modelConfig.TotalFrames / 2) - 1; isOcculted = frameNo >= firstOccFrame && frameNo <= lastOccFrame; } if (!isOcculted) { VideoModelUtils.GenerateStar(bmp, 110, 100, fwhm_pb1, IPB1); } VideoModelUtils.GenerateStar(bmp, 110 + (float)modelConfig.PassByDist, (float)(100 - maxVerticaldistance + (2 * maxVerticaldistance) * percentDone), fwhm_pb2, IPB2); } AddOnScreenText(bmp, modelConfig); return(Pixelmap.ConstructFromBitmap(bmp, TangraConfig.ColourChannel.Red)); } }
public Pixelmap GetPixelmap(int index) { Bitmap bmp = (Bitmap)Bitmap.FromFile(m_BmpFilesList[index]); return(Pixelmap.ConstructFromBitmap(bmp, TangraConfig.ColourChannel.Red)); }
private void RunOCRTestCases(string[] testCases) { lbErrors.Items.Clear(); foreach (string folder in testCases) { string folderNameOnly = Path.GetFileName(folder); bool isTvSafeGuess = folderNameOnly.EndsWith("_tvsafe"); bool[] REVERSE_OPTIONS = new bool[] { false, true }; for (int option = 0; option <= 1; option++) { lvlTestCaseDescription.Text = string.Format("Test case {0} {1}", folderNameOnly, (option == 0 ? "" : " (Reversed)")); lvlTestCaseDescription.Update(); List <string> testFiles = TestCaseHelper.LoadTestImages(folder, REVERSE_OPTIONS[option]); var ocrEngine = new IotaVtiOrcManaged(); bool isSuccess = false; bool calibrated = false; bool digitsPlotted = false; for (int i = 0; i < testFiles.Count; i++) { Bitmap bmpOdd = (Bitmap)Bitmap.FromFile(testFiles[i]); i++; Bitmap bmpEven = (Bitmap)Bitmap.FromFile(testFiles[i]); Pixelmap pixelmapOdd = Pixelmap.ConstructFromBitmap(bmpOdd, TangraConfig.ColourChannel.Red); Pixelmap pixelmapEven = Pixelmap.ConstructFromBitmap(bmpEven, TangraConfig.ColourChannel.Red); if (!calibrated) { calibrated = ocrEngine.ProcessCalibrationFrame(i / 2, pixelmapOdd.Pixels, pixelmapEven.Pixels, bmpOdd.Width, bmpOdd.Height, isTvSafeGuess); } if (calibrated) { if (!digitsPlotted) { PlotDigitPatterns(ocrEngine); digitsPlotted = true; } DateTime dt; isSuccess = ocrEngine.ExtractTime(i / 2, 1, pixelmapOdd.Pixels, pixelmapEven.Pixels, bmpOdd.Width, bmpOdd.Height, out dt); if (!isSuccess) { break; } } } pbar.Value++; if (isSuccess) { pbarSuccess.Value++; } else { pbarError.Value++; lbErrors.Items.Add(string.Format("{0}{1} - {2}", folderNameOnly, (option == 0 ? "" : " (Reversed)"), calibrated ? "Error extracting times" : " Failed to calibrate")); } lblError.Text = string.Format("Errored {0}/{1}", pbarError.Value, pbar.Value); lblSuccessful.Text = string.Format("Successful {0}/{1}", pbarSuccess.Value, pbar.Value); Application.DoEvents(); } } lvlTestCaseDescription.Text = ""; }