private void LoadImageDepthStats(PicesDataBase threadConn, String cruiseName, String stationName, String deploymentNum, ref List <ImagesDepthStats> downCast, ref List <ImagesDepthStats> upCast ) { String sqlStr = "call ImagesStatsByUpAndDownCast("; sqlStr += "\"" + cruiseName + "\"" + ", "; sqlStr += "\"" + stationName + "\"" + ", "; sqlStr += "\"" + deploymentNum + "\"" + ", "; if (mlClass == null) { sqlStr += "\"\", "; } else { sqlStr = "\"" + mlClass.Name + "\"" + ", "; } sqlStr += "1.0);"; downCast = null; upCast = null; String[] cols = { "UpCast", "BucketIdx", "BucketDepth", "ImageCount", "TotalPixelCount" }; String[][] results = threadConn.QueryStatement(sqlStr, cols); if (results == null) { RunLogAddMsg("Error Retrieving Images Cout Statistics."); RunLogAddMsg(threadConn.LastErrorDesc()); return; } downCast = new List <ImagesDepthStats> (); upCast = new List <ImagesDepthStats> (); foreach (String[] row in results) { bool goingUp = (row[0] == "1"); int bucketIdx = PicesKKStr.StrToInt(row[1]); float bucketDepth = PicesKKStr.StrToFloat(row[2]); int imageCount = PicesKKStr.StrToInt(row[3]); int totalPixelCount = PicesKKStr.StrToInt(row[4]); ImagesDepthStats stats = new ImagesDepthStats(goingUp, bucketIdx, bucketDepth, imageCount, totalPixelCount); if (!goingUp) { downCast.Add(stats); } else { upCast.Add(stats); } } return; } /* LoadImageDepthStats */
} /* 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 */
} /* UpdateProcess */ private void UpdateProcessAdd(PicesDataBase updDbConn) { updDbConn.MLClassInsert(newClassEntry); if (updDbConn.Valid()) { RunLogAddMsg("Class [" + newClassEntry.Name + "] Inserted into database." + "\n"); } else { RunLogAddMsg("Error inserting Class [" + newClassEntry.Name + "] into database." + "\n"); RunLogAddMsg(updDbConn.LastErrorDesc() + "\n"); } }
} /* ImportImage */ private void ImportValidatedClassAssignmentsDir(PicesDataBase threadConn, String dirName ) { RunLogAddMsg("Dir[" + dirName + "]" + "\n"); String[] fileNames = null; try { fileNames = Directory.GetFiles(dirName); } catch (Exception e) { RunLogAddMsg("\n" + "Error retrieving file info for Directory[" + dirName + "]" + "\n"); RunLogAddMsg("Exception[" + e.ToString() + "]" + "\n\n"); fileNames = null; } if (fileNames != null) { String className = PicesClass.GetClassNameFromDirName(dirName); PicesClass mlClass = null; int numThisDir = 0; int numFailedThisDir = 0; foreach (String fn in fileNames) { String ext = OSservices.GetFileExtension(fn).ToLower(); if ((ext == "bmp") || (ext == "jpg")) { String rn = OSservices.GetRootName(fn); if (mlClass == null) { mlClass = GetClassFromName(threadConn, className); } if (importImages) { numThisDir++; ImportImage(threadConn, fn); } else { //rn = "TRAIN_" + rn; threadConn.ImagesUpdateValidatedAndPredictClass(rn, mlClass, 1.0f); if (threadConn.Successful()) { numThisDir++; } else { numFailedThisDir++; RunLogAddMsg("Dir[" + dirName + "] RootName[" + rn + "] Failed" + "\n"); RunLogAddMsg(threadConn.LastErrorDesc() + "\n"); } } if ((numThisDir % 100) == 0) { RunLogAddMsg("Dir[" + dirName + "] Files Updated[" + numThisDir.ToString("###,##0") + "]" + "\n"); } } } RunLogAddMsg("Dir[" + dirName + "] Files Updated[" + numThisDir.ToString("###,##0") + "]" + "\n"); totalImagesUpdated += numThisDir; } if (!cancelImporting) { String[] directories = null; try { directories = Directory.GetDirectories(dirName); } catch (Exception) { directories = null; } if (directories != null) { foreach (String subDir in directories) { if ((subDir == ".") || (subDir == "..")) { continue; } ImportValidatedClassAssignmentsDir(threadConn, subDir); if (cancelImporting) { break; } } } } } /* ImportValidatedClassAssignmentsDir */
private void ImportImage(PicesDataBase threadConn, String fileName ) { String rootName = OSservices.GetRootName(fileName); String picesRootName = sipperFileName + "_" + rootName; PicesDataBaseImage dbi = threadConn.ImageLoad(picesRootName); if (dbi != null) { return; } PicesRaster r = new PicesRaster(fileName); r = r.Padded(2); PicesFeatureVector fv = new PicesFeatureVector(r, picesRootName, null, runLog); fv.ExampleFileName = picesRootName; int imageId = 0; bool successful = false; uint centroidRow = (uint)(0.5f + fv.CentroidRow); uint centroidCol = (uint)(0.5f + fv.CentroidCol); if ((centroidRow < 0) || (centroidRow > r.Height)) { centroidRow = (uint)(r.Height / 2); } if ((centroidCol < 0) || (centroidCol > r.Width)) { centroidCol = (uint)(r.Width / 2); } threadConn.ImageInsert(r, picesRootName, sipperFileName, 0, 0, 0, (uint)r.Height, (uint)r.Width, (uint)fv.OrigSize, 3, extractionLogEntryId.LogEntryId, extractionLogEntryId.LogEntryId, centroidRow, centroidCol, unknownClass, 1.0f, null, 0.0f, null, 0.0f, // depth, 0.0f, // Image Size null, ref imageId, ref successful ); if (successful) { threadConn.FeatureDataInsertRow(sipperFileName, fv); } else { RunLogAddMsg("RootName[" + rootName + "] Failed: " + threadConn.LastErrorDesc() + "\n"); } } /* ImportImage */