private async void ConvertImage(ImageStatsCollectingData srcData) { Interlocked.Increment(ref totalFilesProcessed); int perc = Convert.ToInt32(100.0d * (double)totalFilesProcessed / (double)totalFilesCountToProcess); Console.WriteLine(DateTime.Now.ToString("s") + " : " + perc + "% : started processing file " + Environment.NewLine + srcData.filename); Dictionary <string, object> taskParameters = new Dictionary <string, object>(); foreach (string key in defaultProperties.Keys) { taskParameters.Add(key, defaultProperties[key]); } Stopwatch sw = new Stopwatch(); sw.Start(); taskParameters.Add("Stopwatch", sw); taskParameters.Add("logFileName", errorLogFilename); taskParameters.Add("currentFullFileName", srcData.filename); ImageStatsDataCalculationResult currImageConversionResult = await ConvertImageTask(taskParameters); #region process result currImageConversionResult.stopwatch.Stop(); if (currImageConversionResult.calcResult) { string currentFullFileName = currImageConversionResult.imgFilename; string strPerfCountersData = currentFullFileName + ";" + currImageConversionResult.stopwatch.ElapsedMilliseconds + ";" + (currImageConversionResult.procTotalProcessorTimeEnd - currImageConversionResult.procTotalProcessorTimeStart).TotalMilliseconds + Environment.NewLine; ServiceTools.logToTextFile(strPerformanceCountersStatsFile, strPerfCountersData, true); ImageStatsCollectingData foundDataObj = lStatsCalculation.Find(obj => obj.filename == currentFullFileName); foundDataObj.State = ImageStatsCollectingState.Finished; Console.WriteLine(DateTime.Now.ToString("s") + " : finished processing file " + Environment.NewLine + currentFullFileName); } else { string currentFullFileName = currImageConversionResult.imgFilename; ImageStatsCollectingData foundDataObj = lStatsCalculation.Find(obj => obj.filename == currentFullFileName); foundDataObj.State = ImageStatsCollectingState.Error; Console.WriteLine("ERROR processing file " + Path.GetFileName(currentFullFileName)); try { #region report error ServiceTools.logToTextFile(errorLogFilename, "Error processing file: " + Environment.NewLine + currentFullFileName + Environment.NewLine + "message: " + ServiceTools.GetExceptionMessages(currImageConversionResult.exception) + Environment.NewLine + ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "Stack trace: " + Environment.NewLine + Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true); #endregion report error } catch (Exception ex) { return; } } #endregion process result }
private void CurrImageProcessing(ImageStatsCollectingData dat) { string strSaveControlImagesToPath = ""; string currentFullFileName = dat.filename; if (defaultProperties.ContainsKey("SaveControlImagesToPath")) { strSaveControlImagesToPath = (string)defaultProperties["SaveControlImagesToPath"]; } else { strSaveControlImagesToPath = "same as source image"; } try { Image <Bgr, byte> currImg = new Image <Bgr, byte>(currentFullFileName); ImageProcessing imgP = new ImageProcessing(currImg, true); #region debugging output control images #if DEBUG if (strSaveControlImagesToPath != "") { string strControlImageFileName = ""; if (strSaveControlImagesToPath == "same as source image") { strControlImageFileName = Path.GetDirectoryName(currentFullFileName); strControlImageFileName += ((strControlImageFileName.Last() == Path.DirectorySeparatorChar) ? ("") : (Path.DirectorySeparatorChar.ToString())); strControlImageFileName += Path.GetFileNameWithoutExtension(currentFullFileName) + "-control.jpg"; } else { if (Directory.Exists(strSaveControlImagesToPath)) { strControlImageFileName = strSaveControlImagesToPath + ((strSaveControlImagesToPath.Last() == Path.DirectorySeparatorChar) ? ("") : (Path.DirectorySeparatorChar.ToString())) + Path.GetFileNameWithoutExtension(currentFullFileName) + "-control.jpg"; } else { strControlImageFileName = ""; } } if (strControlImageFileName != "") { // save control image imgP.significantMaskImageOctLined.Save(strControlImageFileName); } } #endif #endregion debugging output control images string csvDataStr = Path.GetFileName(currentFullFileName) + ";" + imgP.imageRD.ToCSVstring(";"); ServiceTools.logToTextFile(outputDataFile, csvDataStr + Environment.NewLine, true); ImageStatsCollectingData foundDataObj = lStatsCalculation.Find(obj => obj.filename == currentFullFileName); foundDataObj.State = ImageGrIxStatsCollectingState.Finished; foundDataObj.rd = imgP.imageRD; Console.WriteLine("finished processing file " + Environment.NewLine + currentFullFileName); Console.WriteLine("remains: " + lStatsCalculation.FindAll( imgStats => imgStats.State == ImageGrIxStatsCollectingState.Queued).Count + " of " + lStatsCalculation.Count); } catch (Exception ex) { return; } }
private void ProcessImage(ImageStatsCollectingData srcData) { Interlocked.Increment(ref totalFilesProcessed); int perc = Convert.ToInt32(100.0d * (double)totalFilesProcessed / (double)totalFilesCountToProcess); Console.WriteLine(DateTime.Now.ToString("s") + " : " + perc + "% : started processing file " + Environment.NewLine + srcData.filename); Dictionary <string, object> optionalParameters = new Dictionary <string, object>(); optionalParameters.Add("logFileName", errorLogFilename); // найти и записать данные GPS GPSdata currimageGPS = ServiceTools.FindProperGPSdataForImage(srcData.filename, null, defaultProperties, ref NVdataFilesAlreadyReadDateTimeSpans, ref NVdataFilesAlreadyReadData); if (currimageGPS != null) { ServiceTools.WriteObjectToXML(currimageGPS, ConventionalTransitions.ConcurrentGPSdataFileName(srcData.filename, strConcurrentGPSdataXMLfilesPath)); } // найти и записать данные SDC и Cloud Cover DateTime curDateTime = GetImageDateTime(srcData.filename); if (!lMissionObservedData.Any()) { return; } lMissionObservedData.Sort((obsRecord1, obsRecord2) => { double dev1 = Math.Abs((obsRecord1.dateTime - curDateTime).TotalMilliseconds); double dev2 = Math.Abs((obsRecord2.dateTime - curDateTime).TotalMilliseconds); return((dev1 >= dev2) ? (1) : (-1)); }); MissionsObservedData closestObservedDatum = lMissionObservedData[0]; if ((closestObservedDatum.dateTime - curDateTime).TotalSeconds > 600) { return; } SunDiskConditionData currImageSDC = new SunDiskConditionData() { filename = srcData.filename, sunDiskCondition = closestObservedDatum.SDC }; ServiceTools.WriteObjectToXML(currImageSDC, ConventionalTransitions.SunDiskConditionFileName(srcData.filename, SunDiskConditionXMLdataFilesDirectory)); // find grixyrgbStatsXMLfile SkyImageIndexesStatsData currImageStatsData = null; string currImageStatsDataXMLfile = ""; if (Directory.Exists(imageYRGBstatsXMLdataFilesDirectory)) { List <string> foundXMLfiles = Directory.EnumerateFiles(imageYRGBstatsXMLdataFilesDirectory, ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(srcData.filename, "", false), SearchOption.AllDirectories).ToList(); if (foundXMLfiles.Any()) { // возьмем первый попавшийся currImageStatsDataXMLfile = foundXMLfiles[0]; currImageStatsData = (SkyImageIndexesStatsData) ServiceTools.ReadObjectFromXML(currImageStatsDataXMLfile, typeof(SkyImageIndexesStatsData)); } } SkyImagesDataWith_Concurrent_Stats_CloudCover_SDC currImageData = new SkyImagesDataWith_Concurrent_Stats_CloudCover_SDC () { skyImageFullFileName = srcData.filename, skyImageFileName = Path.GetFileName(srcData.filename), currImageDateTime = curDateTime, observedCloudCoverData = new ObservedClCoverData() { dt = closestObservedDatum.dateTime, CloudCoverTotal = closestObservedDatum.CloudCoverTotal, CloudCoverLower = closestObservedDatum.CloudCoverLower }, concurrentDataXMLfile = "", concurrentData = new ConcurrentData() { filename = "", datetimeUTC = currimageGPS.DateTimeUTC, GPSdata = "", GPSLat = currimageGPS.Lat, GPSLon = currimageGPS.Lon, GPSDateTimeUTC = currimageGPS.DateTimeUTC, PressurePa = closestObservedDatum.pressure, gps = currimageGPS }, grixyrgbStatsXMLfile = currImageStatsDataXMLfile, grixyrgbStats = currImageStatsData, SDCvalue = closestObservedDatum.SDC }; ServiceTools.WriteObjectToXML(currImageData, ConventionalTransitions.SkyImagesDataWithConcurrentStatsCloudCoverAndSDC_FileName(srcData.filename, strSkyImagesDataWithConcurrentStatsCloudCoverAndSDCDirectory)); }
private void ProcessImage(ImageStatsCollectingData srcData) { Interlocked.Increment(ref totalFilesProcessed); int perc = Convert.ToInt32(100.0d * (double)totalFilesProcessed / (double)totalFilesCountToProcess); Console.WriteLine(DateTime.Now.ToString("s") + " : " + perc + "% : started processing file " + Environment.NewLine + srcData.filename); Dictionary <string, object> optionalParameters = new Dictionary <string, object>(); optionalParameters.Add("ImagesRoundMasksXMLfilesMappingList", ImagesRoundMasksXMLfilesMappingList); Stopwatch sw = new Stopwatch(); sw.Start(); optionalParameters.Add("Stopwatch", sw); optionalParameters.Add("logFileName", errorLogFilename); ImageStatsDataCalculationResult currImageProcessingResult = ImageProcessing.CalculateImageStatsData(srcData.filename, optionalParameters); currImageProcessingResult.stopwatch.Stop(); if (currImageProcessingResult.calcResult) { string currentFullFileName = currImageProcessingResult.imgFilename; string strPerfCountersData = currentFullFileName + ";" + currImageProcessingResult.stopwatch.ElapsedMilliseconds + ";" + (currImageProcessingResult.procTotalProcessorTimeEnd - currImageProcessingResult.procTotalProcessorTimeStart).TotalMilliseconds + Environment.NewLine; ServiceTools.logToTextFile(strPerformanceCountersStatsFile, strPerfCountersData, true); //string strImageGrIxMedianP5DataFileName = // ConventionalTransitions.ImageGrIxMedianP5DataFileName(currentFullFileName, imageMP5statsXMLdataFilesDirectory); //ServiceTools.WriteObjectToXML(currImageProcessingResult.mp5Result, strImageGrIxMedianP5DataFileName); string strImageGrIxYRGBDataFileName = ConventionalTransitions.ImageGrIxYRGBstatsDataFileName(currentFullFileName, imageYRGBstatsXMLdataFilesDirectory, true, currPath2Process); ServiceTools.WriteObjectToXML(currImageProcessingResult.grixyrgbStatsData, strImageGrIxYRGBDataFileName); ImageStatsCollectingData foundDataObj = lStatsCalculation.Find(obj => obj.filename == currentFullFileName); foundDataObj.State = ImageStatsCollectingState.Finished; foundDataObj.GrIxMedianValue = currImageProcessingResult.mp5Result.GrIxStatsMedian; foundDataObj.GrIxPerc5Value = currImageProcessingResult.mp5Result.GrIxStatsPerc5; Console.WriteLine(DateTime.Now.ToString("s") + " : finished processing file " + Environment.NewLine + currentFullFileName); } else { string currentFullFileName = currImageProcessingResult.imgFilename; ImageStatsCollectingData foundDataObj = lStatsCalculation.Find(obj => obj.filename == currentFullFileName); foundDataObj.State = ImageStatsCollectingState.Error; Console.WriteLine("ERROR processing file " + Path.GetFileName(currentFullFileName)); try { //report full error to error log file #region report error #if (DEBUG && MONO) ServiceTools.logToTextFile(errorLogFilename, "Error processing file: " + Environment.NewLine + currentFullFileName + Environment.NewLine + "messages: " + ServiceTools.GetExceptionMessages(currImageProcessingResult.exception) + Environment.NewLine + "Stack trace: " + Environment.NewLine + Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true); #else #if MONO ServiceTools.logToTextFile(errorLogFilename, "Error processing file: " + Environment.NewLine + currentFullFileName + Environment.NewLine + "messages: " + ServiceTools.GetExceptionMessages(currImageProcessingResult.exception) + Environment.NewLine + "Stack trace: " + Environment.NewLine + Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true); #else ServiceTools.logToTextFile(errorLogFilename, "Error processing file: " + Environment.NewLine + currentFullFileName + Environment.NewLine + "message: " + ServiceTools.GetExceptionMessages(currImageProcessingResult.exception) + Environment.NewLine + ServiceTools.CurrentCodeLineDescription() + Environment.NewLine + "Stack trace: " + Environment.NewLine + Environment.StackTrace + Environment.NewLine + Environment.NewLine, true, true); #endif #endif #endregion report error } catch (Exception ex) { return; } } }