} /* 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 */
} /* 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 */
} /* 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*/
} /* 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 */
} /* 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 */
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 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 */