public static void ClassifyFromWebCam(int imageID, bool show, bool classify, bool deskew, bool autoRotate, ref int date, ref String design) { date = 0; design = "null"; String modelDir = "C:/Users/pkrush/Documents/GemHunt/CoinSorter/models"; IntPtr ptr = ClassifyFromWebCam(imageID, show, classify, deskew, autoRotate, modelDir); //the output result should be a structure, it's hard coded for now: double[] result = new double[8]; if (ptr == IntPtr.Zero) { return; } Marshal.Copy(ptr, result, 0, 8); ReleaseMemory(ptr); if ((int)result[0] == 0) { design = "Bad Capture"; return; } design = LabelsDB.GetLabel((int)result[2]); if ((int)result[2] == 1) { date = (int)result[6]; } }
public void ClassifyFiles(String oldImageDirectory, String newImageDirectory, String modelDir, bool toClassify, bool addImagesToDataBase, bool moveImage, bool includeSubDir) { string[] files; if (includeSubDir) { files = Directory.GetFiles(oldImageDirectory, "*.jpg*", SearchOption.AllDirectories); } else { files = Directory.GetFiles(oldImageDirectory, "*.jpg*"); } List <ImageResult> imageResults = new List <ImageResult>(); Dictionary <int, int> images = new Dictionary <int, int>(); foreach (string image_file in files) { int imageID = Convert.ToInt32(image_file.Substring(image_file.Length - 12, 8)); if (toClassify) { IntPtr ptr = ClassifyImage(modelDir, image_file); //the output result should be a structure, it's hard coded for now: double[] result = new double[8]; Marshal.Copy(ptr, result, 0, 8); ReleaseMemory(ptr); imageResults.Add(new ImageResult(imageID, result)); if (moveImage) { FileInfo fi = new FileInfo(image_file); String imageFileDestination = newImageDirectory + "/" + LabelsDB.GetLabel((int)result[0]) + "/" + fi.Name; File.Move(image_file, imageFileDestination); } } } if (addImagesToDataBase) { ImagesDB.AddImages(imageResults); } }