public DisplayPicesImages(PicesDataBase _dbConn, PicesImageSizeDistribution _sizeDistribution, int _selectedSizeIndex, float _depthMin, float _depthMax, PicesDataBaseImageList _picesImages ) { InitializeComponent(); thumbNails = new List <FlowLayoutPanel> (); dbConn = _dbConn; sizeDistribution = _sizeDistribution; picesImages = _picesImages; selectedSizeIndex = _selectedSizeIndex; depthMin = _depthMin; depthMax = _depthMax; float[] startValues = sizeDistribution.SizeStartValues(); float[] endValues = sizeDistribution.SizeEndValues(); if ((selectedSizeIndex >= 0) && (selectedSizeIndex < startValues.Length)) { String t = "Size Range [" + startValues[selectedSizeIndex].ToString("###,##0.000") + " - " + endValues[selectedSizeIndex].ToString("#,###,##0.000") + "]"; if (depthMax > 0.0f) { t = t + " Depth Range [" + depthMin.ToString("##0.0") + " - " + depthMax.ToString("##0.0") + "]"; } Text = t; } UpdateDisplayTimer.Enabled = true; }
} /* SaveImagesByClass */ private void SaveImagesInList(PicesDataBaseImageList list, String dirName ) { dirName = OSservices.AddSlash(dirName); curDir = dirName; foreach (PicesDataBaseImage i in list) { if (cancelRequested) { break; } String fullName = dirName + i.ImageFileName + ".bmp"; PicesRaster r = dbConn.ImageFullSizeFind(i.ImageFileName); if (r == null) { imagesFailedToExtract++; } else { r.Save(fullName); } imagesSaved++; } } /* SaveImagesInList */
private void DisplayImagesForDepthBin(Object sender, EventArgs e) { if ((selectedDepthBin < 0) || (sizeDistribution == null) || (selectedDepthBin >= sizeDistribution.NumDepthBins)) { return; } float sizeStart = 0.0f; float sizeEnd = 0.0f; uint imageCount = 0; sizeDistribution.GetSizeBucketStats((uint)selectedSizeBucket, ref imageCount, ref sizeStart, ref sizeEnd); char castChar = 'B'; if (cast == "Down") { castChar = 'D'; } else if (cast == "Up") { castChar = 'U'; } float depthMin = selectedDepthBin * sizeDistribution.DepthBinSize; float depthMax = depthMin + sizeDistribution.DepthBinSize; PicesDataBaseImageList images = mainWinConn.ImagesQueryDeploymentSizeRange(cruise, station, deployment, classToPlot, castChar, statistic, sizeStart, sizeEnd, depthMin, depthMax, 1000, true); DisplayPicesImages dpi = new DisplayPicesImages(mainWinConn, sizeDistribution, selectedSizeBucket, depthMin, depthMax, images); dpi.ShowDialog(this); }
} /* DeriveRandomDistByDepth */ private PicesDataBaseImageList GetDatabaseImageRecords(PicesDataBase threadConn, List <ImageEntry> images ) { RunLogAddMsg("Extracting Images from the database." + "\n"); PicesDataBaseImageList dataBaseImages = new PicesDataBaseImageList(); foreach (ImageEntry ie in images) { if (cancelHarvesting) { break; } PicesDataBaseImage dbi = threadConn.ImageLoad(ie.imageId); if (dbi == null) { RunLogAddMsg("GetDatabaseImageRecords ***ERROR*** Could not get ImageId[" + ie.imageId + "]" + "\n"); } else { dataBaseImages.Add(dbi); if ((dataBaseImages.Count % 100) == 0) { RunLogAddMsg("Images Extracted " + dataBaseImages.Count + " of " + images.Count + "\n"); } } } return(dataBaseImages); } /* GetDatabaseImageRecords */
} /* RetrievePlanktonDataBySipperFiles */ private PicesDataBaseImageList RetrievePlanktonDataByGroup() { backGroundStatus = "Group [" + group.Name + "]"; PicesDataBaseImageList data = dbConn.ImagesQueryByGrouop(this.group, CruiseName.Text, StationName.Text, DeploymentNum.Text, SipperFile.Text, mlClass, classKeyToUse, probMin, probMax, sizeMin, sizeMax, depthMin, depthMax, 0, // Restart Image Id -1, // limit (Max number Images to load. false // false = Do not include Thumbnail ); if (data != null) { imagesLoaded += (uint)data.Count; } return(data); } /* RetrievePlanktonDataByGroup */
} /* SaveImagesByDepthImcrements */ private void SaveImagesByClass() { images.Sort(PicesDataBaseImageList.SortOrderType.soClassName, false); int idx = 0; PicesDataBaseImage i = images[0]; while ((idx < images.Count) && (!cancelRequested)) { String className = i.Class1Name; String curClassName = className; curDir = OSservices.AddSlash(DestinationDirectory.Text) + className; try { Directory.CreateDirectory(curDir); } catch (Exception) {} PicesDataBaseImageList imagesThisClass = new PicesDataBaseImageList(); while ((idx < images.Count) && (!cancelRequested) && (className == curClassName)) { imagesThisClass.Add(i); idx++; if (idx < images.Count) { i = images[idx]; className = i.Class1Name; } } SaveImagesInList(imagesThisClass, curDir); } } /* SaveImagesByClass */
} /* ChartContextMenu */ private void DisplayImagesForASizeBucket(Object sender, EventArgs e) { if ((selectedSizeBucket < 0) || (bucketsDisplayed == null) || (selectedSizeBucket >= bucketsDisplayed.NumSizeBuckets)) { return; } float sizeStart = 0.0f; float sizeEnd = 0.0f; uint imageCount = 0; bucketsDisplayed.GetSizeBucketStats((uint)selectedSizeBucket, ref imageCount, ref sizeStart, ref sizeEnd); char castChar = 'B'; if (cast == "Down") { castChar = 'D'; } else if (cast == "Up") { castChar = 'U'; } PicesDataBaseImageList images = mainWinConn.ImagesQueryDeploymentSizeRange(cruise, station, deployment, classToPlot, castChar, statistic, sizeStart, sizeEnd, 0.0f, 0.0f, 1000, true); DisplayPicesImages dpi = new DisplayPicesImages(mainWinConn, bucketsDisplayed, selectedSizeBucket, 0.0f, 0.0f, images); dpi.ShowDialog(this); }
} /* ImageEntry */ private void HarvestImages() { PicesDataBase.ThreadInit(); harvestingRunning = true; harvestingCompleted = false; PicesDataBase threadConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); List <ImageEntry> allImages = null; List <ImageEntry>[] imagesByDepth = null; double[] depthTimeProfile = null; double[] fracPartByDepth = null; List <ImageEntry> randDistByDepth = null; //if (!cbOilDeployments.Checked) allImages = LoadAllImages(threadConn); //else // allImages = LoadOilDeploymentImages(); if (!cancelHarvesting) { if (weight) { depthTimeProfile = LoadDepthTimeProfile(threadConn); if (!cancelHarvesting) { imagesByDepth = DeriveImagesByDepth(allImages, depthTimeProfile.Length); fracPartByDepth = DeriveFracPartByDepth(depthTimeProfile, imagesByDepth); randDistByDepth = DeriveRandomDistByDepth(imagesByDepth, fracPartByDepth); harvestedImages = GetDatabaseImageRecords(threadConn, randDistByDepth); UpdateImageGroupTables(threadConn, harvestedImages); RunLogAddMsg("\n" + "Harvesting Completed Successfully." + "\n"); } } else { harvestedImages = DeriveRandomDistribution(threadConn, allImages); if (!cancelHarvesting) { UpdateImageGroupTables(threadConn, harvestedImages); } } if (!cancelHarvesting) { harvestingCompleted = true; } } threadConn.Close(); threadConn = null; GC.Collect(); PicesDataBase.ThreadEnd(); harvestingRunning = false; } /* HarvestImages */
} /* CancelLoadWait */ /// <summary> Return to caller list of images that have been loaded so far by the LoadImagesThread. </summary> /// <remarks> /// Images are loaded by a seprate thread; these images are loaded into <paramref name="loadedImages"/>. Images /// accumulate into it until ther are retrived by this method. /// </remarks> /// <returns> List of images loaded since the last call. </returns> public PicesDataBaseImageList GetImagesAlreadyLoaded() { blocker.StartBlock(); PicesDataBaseImageList imagesToReturn = loadedImages; loadedImages = new PicesDataBaseImageList(); blocker.EndBlock(); return(imagesToReturn); }
} /* SaveImagesByGroup */ private void SaveOneBatchOfImages(PicesDataBaseImageList batch) { if (saveByDepthIncrements) { SaveImagesByDepthImcrements(batch); } else { SaveImagesByClass(batch); } }
} /* SaveImagesBySipperFiles */ private void SaveImagesForOneSipperFile(String dirPath, PicesSipperFile sf, Dictionary <string, int> imagesPerClass ) { uint lastImageId = 0; sipperFileName = sf.SipperFileName; while (!cancelRequested) { int limit = -1; if (mlClass == null) { // With out the Class Key; mySql will probably not be able to restart the query from a known spot and // get all the images that is intended. So in this case we want to retrieve all images that meet the // criteria from this SIPPER file. limit = -1; } PicesDataBaseImageList nextBunch = dbConn.ImagesQuery (null, // ImageGroup sipperFileName, mlClass, classKeyToUse, probMin, probMax, sizeMin, sizeMax, depthMin, depthMax, lastImageId, limit, false // false = Don't load Thumbnail images. ); if ((nextBunch == null) || (nextBunch.Count < 1)) { break; } SaveOneBatchOfImages(dirPath, imagesPerClass, nextBunch); lastImageId = nextBunch[nextBunch.Count - 1].ImageId; nextBunch = null; if ((nextBunch == null) || (nextBunch.Count < limit) || (limit < 0)) { // Since we loaded less images than 'limit' was set for we are done loading images from this sipperFileName. break; } nextBunch = null; } } /* SaveImagesForOneSipperFile */
} /* SaveSampleImages */ private PicesDataBaseImageList RetrievePlanktonDataBySipperFiles() { PicesDataBaseImageList data = new PicesDataBaseImageList(); String[] sipperFileNames = null; if (String.IsNullOrEmpty(sipperFileName)) { sipperFileNames = dbConn.SipperFileGetList(cruise, station, deployment); } else { sipperFileNames = new String[1]; sipperFileNames[0] = sipperFileName; } if (sipperFileNames != null) { for (int idx = 0; (idx < sipperFileNames.Length) && (!cancelRequested); idx++) { String curSipperFileName = sipperFileNames[idx]; backGroundStatus = "Loading[" + (idx + 1).ToString() + " of " + sipperFileNames.Length.ToString() + "] File[" + curSipperFileName + "]"; PicesDataBaseImageList dataThisSipperFile = dbConn.ImagesQuery(null, curSipperFileName, mlClass, classKeyToUse, probMin, probMax, sizeMin, sizeMax, depthMin, depthMax, 0, // Restart ImageId -1, // limit (Max number of images). false // false = Do not include Thumbnail. ); if (dataThisSipperFile != null) { imagesLoaded += (uint)dataThisSipperFile.Count; foreach (PicesDataBaseImage i in dataThisSipperFile) { data.Add(i); } } } } return(data); } /* RetrievePlanktonDataBySipperFiles */
} /* GetDatabaseImageRecords */ private void UpdateImageGroupTables(PicesDataBase threadConn, PicesDataBaseImageList harvestedImages ) { RunLogAddMsg("Create Image Group Entries" + "\n"); PicesDataBaseImageGroup existingGroup = threadConn.ImageGroupLoad(groupName); if (existingGroup != null) { // Since the group already exists we will have to delete it. threadConn.ImageGroupDelete(existingGroup.ImageGroupId); } String description = "Created by Harvester" + "\n" + "DateTime" + "\t" + DateTime.Now.ToLongDateString() + "\n" + "NumImages" + "\t" + harvestedImages.Count.ToString("#,###,##0") + "\n"; PicesDataBaseImageGroup group = new PicesDataBaseImageGroup(-1, groupName, description, (uint)harvestedImages.Count); threadConn.ImageGroupInsert(group); int idx = 0; while (idx < harvestedImages.Count) { PicesDataBaseImageList updateGroup = new PicesDataBaseImageList(); while ((idx < harvestedImages.Count) && (updateGroup.Count < 50)) { updateGroup.Add(harvestedImages[idx]); idx++; } threadConn.ImageGroupEntriesInsert(group.ImageGroupId, updateGroup); RunLogAddMsg("Added To ImageGroup[" + idx + "] of [" + harvestedImages.Count + "]" + "\n"); } if (threadConn.Valid()) { RunLogAddMsg("Image Group Tables Updated" + "\n"); } else { RunLogAddMsg("\n" + "\n" + "Image Group Tables Update FAILED ***ERROR***" + "\n" ); } } /* UpdateImageGroupTables*/
} /* CancelHarvestingProcess */ private List <ImageEntry> LoadAllImages(PicesDataBase threadConn) { RunLogAddMsg("Loading Source Images\n"); List <ImageEntry> allImages = new List <ImageEntry> (); foreach (String sipperFileName in sipperFileNames) { if (cancelHarvesting) { break; } RunLogAddMsg("Loading Sipper File[" + sipperFileName + "]" + "\n"); PicesDataBaseImageList images = threadConn.ImagesQuery(null, // ImageGroup sipperFileName, selClass, // classKeyToUse, // 0.0f, 1.0f, // Prob Min and Max sizeMin, sizeMax, // Size Min and Max 0, 0, // Depth Min and Max 0, // restartImageFileName -1, // limit to load -1 = Load All false // false = Don't load thumbnail ); if (images == null) { RunLogAddMsg("Loading Sipper File[" + sipperFileName + "] No images found in database." + "\n"); } else { foreach (PicesDataBaseImage i in images) { float depth = i.Depth; if (depth >= minimumDepth) { allImages.Add(new ImageEntry(i.ImageId, depth)); } } RunLogAddMsg("Loading Sipper File[" + sipperFileName + "] [" + images.Count.ToString("##,###,##0") + "] Loaded" + "\n"); } } return(allImages); } /* LoadAllImages */
public DialogResult Show(IWin32Window parent, PicesDataBaseImageList images ) { VerifyImagesDeletion vi = new VerifyImagesDeletion(); vi.Images(images); vi.ShowDialog(parent); if (vi.DeletionOk()) { return(DialogResult.Yes); } else { return(DialogResult.No); } }
//SMP751001034_02_00025491_3588 private void SaveSampleImages(PicesDataBaseImageList planktonData) { PicesClassList classes = planktonData.ExtractListOfClasses(); if (classes == null) { return; } String sampleDir = OSservices.AddSlash(OSservices.GetPathPartOfFile(dataFileName)) + OSservices.GetRootName(dataFileName) + "_SampleImages"; sampleDir = OSservices.AddSlash(sampleDir); OSservices.CreateDirectoryPath(sampleDir); foreach (PicesClass pc in classes) { String classSampleDir = OSservices.AddSlash(sampleDir + pc.Name); OSservices.CreateDirectoryPath(classSampleDir); PicesDataBaseImageList examplesThisClass = planktonData.ExtractExamplesForAGivenClass(pc); examplesThisClass.RandomizeOrder(); int numWritten = 0; foreach (PicesDataBaseImage i in examplesThisClass) { String imageRootName = OSservices.GetRootName(i.ImageFileName); PicesRaster fullSizeImage = dbConn.ImageFullSizeFind(imageRootName); if (fullSizeImage != null) { String imageFileName = classSampleDir + imageRootName + ".bmp"; fullSizeImage.Save(imageFileName); ++numWritten; } if (numWritten >= includeSampleImagesNumPerClass) { break; } } } } /* SaveSampleImages */
} /* ValidateGroupName */ private void UpdateDatabase() { PicesDataBaseImageGroup ig = new PicesDataBaseImageGroup(-1, GroupName.Text, Description.Text, 0); dbConn.ImageGroupInsert(ig); if (!dbConn.Valid()) { MessageBox.Show(this, "Error Creating new Image Group" + "\n" + dbConn.LastErrorDesc(), "Assign Selected Images to Group", MessageBoxButtons.OK ); } else { int zed = 0; while (zed < selImages.Count) { PicesDataBaseImageList subSet = new PicesDataBaseImageList(); while ((subSet.Count < 100) && (zed < selImages.Count)) { subSet.Add(selImages[zed]); ++zed; } dbConn.ImageGroupEntriesInsert(ig.ImageGroupId, subSet); if (!dbConn.Valid()) { break; } } if (dbConn.Valid()) { newGroupCreated = true; MessageBox.Show(this, "Group[" + GroupName.Text + "] Created successfully.", "Assign Selected Images to Group", MessageBoxButtons.OK); } else { MessageBox.Show(this, "Error Creating new Image Group" + "\n" + dbConn.LastErrorDesc(), "Assign Selected Images to Group", MessageBoxButtons.OK); } } } /* UpdateDatabase */
public AssignSelectedImagesToGroup(PicesDataBaseImageList _selImages, String _suggestedGroupName ) { selImages = _selImages; InitializeComponent(); GroupName.Text = CleanUpGroupName(_suggestedGroupName); runLog = new PicesRunLog(); dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog); if (dbConn == null) { dbConn = new PicesDataBase(runLog); } if (selImages == null) { MessageBox.Show(this, "Assign Group to Selected Images", "There are no images currently selected.", MessageBoxButtons.OK); Close(); } }
public SaveImagesToDisk(PicesDataBase _dbConn, String _cruise, String _station, String _deployment, String _sipperFileName, PicesDataBaseImageList _images ) { dbConn = _dbConn; images = _images; cruise = _cruise; station = _station; deployment = _deployment; sipperFileName = _sipperFileName; runLog = new PicesRunLog(); InitializeComponent(); DestinationDirectory.Text = OSservices.AddSlash(OSservices.AddSlash(PicesSipperVariables.HomeDir()) + "SavedImages"); OSservices.CreateDirectoryPath(DestinationDirectory.Text); // PicesTempDirectory ()); if (!String.IsNullOrEmpty(cruise)) { DestinationDirectory.Text += cruise; if (!String.IsNullOrEmpty(station)) { DestinationDirectory.Text += "-" + station; if (!String.IsNullOrEmpty(deployment)) { DestinationDirectory.Text += "-" + deployment; if (!String.IsNullOrEmpty(sipperFileName)) { DestinationDirectory.Text += "-" + sipperFileName; } } } } ImageCount.Text = images.Count.ToString("###,##0"); }
} /* SaveImagesForOneSipperFile */ private void SaveImagesByGroup() { uint lastImageId = 0; sipperFileStatus = "Group [" + group.Name + "]"; while (!cancelRequested) { int limit = -1; PicesDataBaseImageList nextBunch = dbConn.ImagesQueryByGrouop (group, cruise, station, deployment, sipperFileName, mlClass, classKeyToUse, probMin, probMax, sizeMin, sizeMax, depthMin, depthMax, lastImageId, limit, // Max # of rows to return. -1 indicates no limit., false // false = Don't Load IncludeThumbnail ); if ((nextBunch == null) || (nextBunch.Count < 1)) { // Sine we loaded less images than 'limit' was set for we are done loading images from this sipperFileName. break; } // Get the 'lastImagId' before calling 'SaveOneBatchOfImages' which will sort it into a different order. if (nextBunch.Count > 0) { lastImageId = nextBunch[nextBunch.Count - 1].ImageId; } SaveOneBatchOfImages(nextBunch); nextBunch = null; } } /* SaveImagesByGroup */
} /* DeriveFracPartByDepth */ private PicesDataBaseImageList DeriveRandomDistribution(PicesDataBase connThread, List <ImageEntry> images ) { RunLogAddMsg("Extracting Images Randomly." + "\n"); PicesDataBaseImageList randDist = new PicesDataBaseImageList(); DateTime d = DateTime.Now; int miliSecsInDay = d.Millisecond + d.Second * 1000 + d.Minute * 60000 + d.Hour * 360000; Random randomGenerator = new Random(miliSecsInDay); RandomSortImageEntryList(images, randomGenerator); foreach (ImageEntry ie in images) { PicesDataBaseImage dbi = connThread.ImageLoad(ie.imageId); if (dbi == null) { RunLogAddMsg("DeriveRandomDistribution ***ERROR*** Could not get ImageId[" + ie.imageId + "]" + "\n"); } else { randDist.Add(dbi); if ((randDist.Count % 100) == 0) { RunLogAddMsg("Images Extracted " + randDist.Count + " of " + images.Count + "\n"); } } if (randDist.Count >= howManyToHarvest) { break; } } return(randDist); } /* DeriveRandomDistribution */
PlanktonClassStatisticsLoader statsLoader = null; // To determine total number of images that will be saved. public SaveImagesToDisk2(PicesDataBase _dbConn, PicesDataBaseImageList _images, // If '_images' is not null then you do not need to include any of the following parameters. PicesDataBaseImageGroup _group, String _cruise, String _station, String _deployment, String _sipperFileName, PicesClass _mlClass, char _classKeyToUse, float _probMin, float _probMax, int _sizeMin, int _sizeMax, float _depthMin, float _depthMax ) { dbConn = _dbConn; images = (_images == null) ? null : _images; group = _group; cruise = (_cruise == null) ? "" : _cruise; station = (_station == null) ? "" : _station; deployment = (_deployment == null) ? "" : _deployment; sipperFileName = (_sipperFileName == null) ? "" : _sipperFileName; mlClass = _mlClass; classKeyToUse = _classKeyToUse; probMin = _probMin; probMax = _probMax; sizeMin = _sizeMin; sizeMax = _sizeMax; depthMin = _depthMin; depthMax = _depthMax; runLog = new PicesRunLog(); InitializeComponent(); }
private void BackGroundThread() { PicesDataBase.ThreadInit(); backGroundThreadRunning = true; imagesLoaded = 0; if (group != null) { planktonData = RetrievePlanktonDataByGroup(); } else { planktonData = RetrievePlanktonDataBySipperFiles(); } if (!cancelRequested) { backGroundStatus = "Saving Data File"; String pathName = OSservices.GetPathPartOfFile(dataFileName); if (!String.IsNullOrEmpty(pathName)) { OSservices.CreateDirectoryPath(pathName); } if (IncludeSampleImages.Checked) { SaveSampleImages(planktonData); } SavePlanktonDataFile(planktonData); } PicesDataBase.ThreadEnd(); backgroundThreadCompleted = true; backGroundThreadRunning = false; } /* BackGroundThread */
private void SaveImagesByDepthImcrements() { images.Sort(PicesDataBaseImageList.SortOrderType.soDepth, false); int idx = 0; PicesDataBaseImage i = images[0]; while ((idx < images.Count) && (!cancelRequested)) { int depthIndex = DepthIndex(i.Depth); int curDepthIndex = depthIndex; int fromDepth = depthIndex * increments; int toDepth = (depthIndex + 1) * increments; String depthSubDirName = fromDepth.ToString("000") + "-" + toDepth.ToString("000"); curDir = OSservices.AddSlash(DestinationDirectory.Text) + depthSubDirName; try { Directory.CreateDirectory(curDir); } catch (Exception) {} PicesDataBaseImageList imagesThisDepthIndex = new PicesDataBaseImageList(); while ((idx < images.Count) && (!cancelRequested) && (depthIndex == curDepthIndex)) { imagesThisDepthIndex.Add(i); idx++; if (idx < images.Count) { i = images[idx]; depthIndex = DepthIndex(i.Depth); } } SaveImagesInList(imagesThisDepthIndex, curDir); } } /* SaveImagesByDepthImcrements */
private void SaveOneBatchOfImages(String dirPath, Dictionary <String, int> imagesPerClass, PicesDataBaseImageList batch ) { if (classKeyToUse == 'V') { batch.Sort(PicesDataBaseImageList.SortOrderType.soValidatedClassName, false); } else { batch.Sort(PicesDataBaseImageList.SortOrderType.soClassName, false); } int idx = 0; PicesDataBaseImage i = batch[0]; while ((idx < batch.Count) && (!cancelRequested)) { String className = i.Class1Name; if (classKeyToUse == 'V') { className = i.ValidatedClassName; } String curClassName = className; String classDir = OSservices.AddSlash(dirPath) + className; try { OSservices.CreateDirectoryPath(classDir); } catch (Exception) {} int countThisClass = 0; if (imagesPerClass.ContainsKey(curClassName)) { countThisClass = imagesPerClass[curClassName]; } else { imagesPerClass.Add(curClassName, 0); } int lastFoldNum = -1; String foldDir = ""; while ((idx < batch.Count) && (!cancelRequested) && (className == curClassName)) { int foldNum = countThisClass / imagsPerDir; if (foldNum != lastFoldNum) { foldDir = OSservices.AddSlash(classDir) + curClassName + "_" + foldNum.ToString("000"); OSservices.CreateDirectoryPath(foldDir); lastFoldNum = foldNum; } String fullName = OSservices.AddSlash(foldDir) + i.ImageFileName + ".bmp"; PicesRaster r = dbConn.ImageFullSizeFind(i.ImageFileName); if (r == null) { imagesFailedToExtract++; } else { r.Save(fullName); } imagesSaved++; // Get the next image to save. idx++; if (idx < batch.Count) { i = batch[idx]; className = i.Class1Name; if (classKeyToUse == 'V') { className = i.ValidatedClassName; } } countThisClass++; } imagesPerClass[curClassName] = countThisClass; } } /* SaveOneBatchOfImages */
} /* LoadImagesForSelectedGroup */ private void LoadImagesForOneSipperFile(String sipperFileName) { curSipperFileName = sipperFileName; uint lastImageId = restartImageId; while (!cancelRequested) { int limit = 100; if (mlClass == null) { // With out the Class Key; mySql will probably not be able to restart the query from a know spot and // get all the images that is intended. So in this case we want to retrieve all images that meet the // criteria from this SIPPER file. limit = -1; } PicesDataBaseImageList nextBunch = dbConn.ImagesQuery (null, // ImageGroup sipperFileName, mlClass, classKeyToUse, probMin, probMax, sizeMin, sizeMax, depthMin, depthMax, lastImageId, limit, true // Load Thumbnail image also. ); if ((nextBunch == null) || (nextBunch.Count < 1)) { return; } blocker.StartBlock(); if (loadedImages == null) { loadedImages = new PicesDataBaseImageList(); } uint largestImageId = nextBunch[0].ImageId; foreach (PicesDataBaseImage i in nextBunch) { if (i.ImageId != lastImageId) { loadedImages.Add(i); imagesLoadedCount++; } if (i.ImageId > largestImageId) { largestImageId = i.ImageId; } } lastImageId = largestImageId; blocker.EndBlock(); if ((nextBunch.Count < limit) || (limit < 0)) { // Sine we loaded less images than 'limit' was set for we are done loading images from this sipperFileName. break; } nextBunch = null; } curSipperFileName = ""; } /* LoadImagesForOneSipperFile */
private void SavePlanktonDataFile(PicesDataBaseImageList planktonData) { String errMsg = ""; StreamWriter sw = null; try { sw = new StreamWriter(dataFileName); } catch (Exception e1) { errMsg = e1.ToString(); } if (sw == null) { errMsg = "Could not open Data File[" + dataFileName + "]\n" + errMsg; return; } sw.WriteLine("//This file was generated by the PICESComander application."); sw.WriteLine(); sw.WriteLine("DateTime" + "\t" + DateTime.Now.ToString("yyyy/MM/dd - hh:mm:ss")); sw.WriteLine("DataBase" + "\t" + dbConn.ServerDescription()); sw.WriteLine("MachineName" + "\t" + System.Environment.MachineName); sw.WriteLine(); sw.WriteLine("//Selection Criteria"); WriteValue(sw, "GroupName", GroupName.Text); WriteValue(sw, "CruiseName", CruiseName.Text); WriteValue(sw, "StationName", StationName.Text); WriteValue(sw, "DeploymentNum", DeploymentNum.Text); WriteValue(sw, "SipperFile", SipperFile.Text); if (mlClass != null) { WriteValue(sw, "MLClass", mlClass.Name); } sw.WriteLine("Probability Min-Max" + "\t" + (100.0f * probMin).ToString("##0.00") + "\t" + (100.0f * probMax).ToString("##0.00")); if ((depthMin > 0.0f) || (depthMax > 0.0f)) { sw.WriteLine("Depth" + "\t" + depthMin.ToString("###0.00") + "\t" + depthMax.ToString("###0.00")); } if ((sizeMin > 0) || (sizeMax > 0)) { sw.WriteLine("Size" + "\t" + sizeMin.ToString("#####0") + "\t" + sizeMax.ToString("######0")); } sw.WriteLine("ClassKeyToUse" + "\t" + classKeyToUse.ToString()); sw.WriteLine(); sw.WriteLine("Count" + "\t" + planktonData.Count); sw.WriteLine(); sw.WriteLine("//Following specifies column headers."); sw.Write("ImageFileName"); sw.Write("\t"); sw.Write("Class1Name"); sw.Write("\t"); sw.Write("Class1Prob"); sw.Write("\t"); sw.Write("Class2Name"); sw.Write("\t"); sw.Write("Class2Prob"); sw.Write("\t"); sw.Write("Depth(M)"); sw.Write("\t"); sw.Write("PixelCount"); sw.Write("\t"); sw.Write("Height"); sw.Write("\t"); sw.Write("Width"); sw.Write("\t"); sw.Write("TopLeftRow"); sw.Write("\t"); sw.Write("TopLeftCol"); sw.Write("\t"); sw.Write("CtdDate"); sw.Write("\t"); sw.Write("Latitude"); sw.Write("\t"); sw.Write("Longitude"); sw.Write("\t"); sw.Write("Temperature(C)"); sw.WriteLine(); planktonData.Sort(PicesDataBaseImageList.SortOrderType.soSpatial, false); PicesInstrumentData id = null; uint nextScanLineThreshold = 0; String lastSipperFileName = ""; foreach (PicesDataBaseImage i in planktonData) { if ((i.TopLeftRow >= nextScanLineThreshold) || (i.SipperFileName != lastSipperFileName) ) { uint scanLineCleared = 0; uint scanLine = i.TopLeftRow; scanLine = 4096 * (uint)(scanLine / 4096); id = dbConn.InstrumentDataGetByScanLine(i.SipperFileName, scanLine); lastSipperFileName = i.SipperFileName; if (id == null) { scanLineCleared = scanLine; } else { scanLineCleared = id.ScanLine; if (scanLineCleared > scanLine) { if ((scanLineCleared - scanLine) > 4096) { id = null; } } } nextScanLineThreshold = scanLineCleared + 4096; } sw.Write(i.ImageFileName); sw.Write("\t"); sw.Write(i.Class1Name); sw.Write("\t"); sw.Write(i.Class1Prob.ToString("p")); sw.Write("\t"); sw.Write(i.Class2Name); sw.Write("\t"); sw.Write(i.Class2Prob.ToString("p")); sw.Write("\t"); sw.Write(i.Depth); sw.Write("\t"); sw.Write(i.PixelCount); sw.Write("\t"); sw.Write(i.Height); sw.Write("\t"); sw.Write(i.Width); sw.Write("\t"); sw.Write(i.TopLeftRow); sw.Write("\t"); sw.Write(i.TopLeftCol); if (id != null) { sw.Write("\t"); sw.Write(id.CtdDate.ToString("yyyy/MM/dd - HH:mm:ss")); sw.Write("\t"); sw.Write(id.Latitude); sw.Write("\t"); sw.Write(id.Longitude); sw.Write("\t"); sw.Write(id.Temperature); } sw.WriteLine(); ++imagesWritten; } sw.WriteLine("//All Data Written."); sw.Close(); }
public void Images(PicesDataBaseImageList _images) { images = _images; }
private void LoadImagesForSelectedGroup() { curSipperFileName = ""; uint lastImageId = restartImageId; while (!cancelRequested) { int limit = 100; PicesDataBaseImageList nextBunch = dbConn.ImagesQueryByGrouop (selectedImageGroup, cruiseName, stationName, deploymentNum, sipperFileName, mlClass, classKeyToUse, probMin, probMax, sizeMin, sizeMax, depthMin, depthMax, lastImageId, limit, // Max # of rows to return. -1 indicates no limit., true // true = IncludeThumbnail ); if ((nextBunch == null) || (nextBunch.Count < 1)) { return; } blocker.StartBlock(); if (loadedImages == null) { loadedImages = new PicesDataBaseImageList(); } uint largestImageId = nextBunch[0].ImageId; foreach (PicesDataBaseImage i in nextBunch) { if (i.ImageId != lastImageId) { loadedImages.Add(i); imagesLoadedCount++; } if (i.ImageId > largestImageId) { largestImageId = i.ImageId; } } lastImageId = largestImageId; blocker.EndBlock(); if ((nextBunch.Count < limit) || (limit < 0)) { // Sine we loaded less images than 'limit' was set for we are done loading images from this sipperFileName. break; } nextBunch = null; } } /* LoadImagesForSelectedGroup */