public override IEnumerator Initialize(Detector detector, int discrete) { WindowsNativePlatform.detector = detector; //load our lib! string affdexDataPath = Application.streamingAssetsPath + "/affdex-data-3"; Debug.Log("Hi! It's Greg."); affdexDataPath = affdexDataPath.Replace('/', '\\'); Debug.Log("affdexDataPath is..."); Debug.Log(affdexDataPath); nativeHandle = affdexInitialize(discrete, affdexDataPath); FaceResults faceFound = new FaceResults(this.onFaceFound); FaceResults faceLost = new FaceResults(this.onFaceLost); ImageResults imageResults = new ImageResults(this.onImageResults); h1 = GCHandle.Alloc(faceFound, GCHandleType.Pinned); h2 = GCHandle.Alloc(faceLost, GCHandleType.Pinned); h3 = GCHandle.Alloc(imageResults, GCHandleType.Pinned); int status = affdexRegisterListeners(nativeHandle, imageResults, faceFound, faceLost); Debug.Log("Registered listeners: " + status); yield break; }
public async Task <ImageResults> RefreshDataAsync() { items = new ImageResults(); var url = Constants.Url; var uri = new Uri(string.Format(url, string.Empty)); try { var response = await _client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); items = JsonConvert.DeserializeObject <ImageResults>(content); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR {0}", ex.Message); } return(items); }
public override IEnumerator Initialize(Detector detector, int discrete) { OSXNativePlatform.detector = detector; String adP = Application.streamingAssetsPath; String affdexDataPath = Path.Combine(adP, "affdex-data-osx"); int status = 0; Debug.Log("Initializing detector"); try { nativeHandle = affdexInitialize(discrete, affdexDataPath); } catch (Exception e) { Debug.LogException(e); } Debug.Log("Initialized detector: " + status); FaceResults faceFound = new FaceResults(this.onFaceFound); FaceResults faceLost = new FaceResults(this.onFaceLost); ImageResults imageResults = new ImageResults(this.onImageResults); h1 = GCHandle.Alloc(faceFound, GCHandleType.Pinned); h2 = GCHandle.Alloc(faceLost, GCHandleType.Pinned); h3 = GCHandle.Alloc(imageResults, GCHandleType.Pinned); status = affdexRegisterListeners(nativeHandle, imageResults, faceFound, faceLost); Debug.Log("Registered listeners: " + status); yield break; }
public override IEnumerator Initialize(Detector detector, int discrete) { AndroidNativePlatform.detector = detector; // assemble the destination path where the data files will go affdexDataDir = Path.Combine(Application.persistentDataPath, "affdex-data"); // Copy data files out of StreamingAssets to the destination path (if necessary) // Wait for it to complete before continuing yield return(StartCoroutine(CopyAssets())); // native call nativeHandle = affdexInitialize(discrete, affdexDataDir); // allocate and pin memory for the listeners FaceResults faceFound = new FaceResults(this.onFaceFound); FaceResults faceLost = new FaceResults(this.onFaceLost); ImageResults imageResults = new ImageResults(this.onImageResults); h1 = GCHandle.Alloc(faceFound, GCHandleType.Pinned); h2 = GCHandle.Alloc(faceLost, GCHandleType.Pinned); h3 = GCHandle.Alloc(imageResults, GCHandleType.Pinned); // native call affdexRegisterListeners(nativeHandle, imageResults, faceFound, faceLost); }
public void Initialize(Detector detector, int discrete) { WindowsNativePlatform.detector = detector; //load our lib! String adP = Application.streamingAssetsPath; String affdexDataPath = Path.Combine(adP, "affdex-data"); // Application.streamingAssetsPath + "/affdex-data"; //String affdexDataPath = Application.dataPath + "/affdex-data"; affdexDataPath = affdexDataPath.Replace('/', '\\'); int status = initialize(discrete, affdexDataPath); Debug.Log("Initialized detector: " + status); FaceResults faceFound = new FaceResults(this.onFaceFound); FaceResults faceLost = new FaceResults(this.onFaceLost); ImageResults imageResults = new ImageResults(this.onImageResults); h1 = GCHandle.Alloc(faceFound, GCHandleType.Pinned); h2 = GCHandle.Alloc(faceLost, GCHandleType.Pinned); h3 = GCHandle.Alloc(imageResults, GCHandleType.Pinned); status = registerListeners(imageResults, faceFound, faceLost); Debug.Log("Registered listeners: " + status); }
public override IEnumerator Initialize(Detector detector, int discrete) { iOSNativePlatform.detector = detector; String adP = Application.streamingAssetsPath; String affdexDataPath = Path.Combine(adP, "affdex-data-ios"); int status = 0; try { nativeHandle = affdexInitialize(discrete, affdexDataPath); } catch (Exception e) { Debug.LogException(e); } Debug.Log("Initialized detector: " + status); mFaceFound = new FaceResults(this.onFaceFound); mFaceLost = new FaceResults(this.onFaceLost); mImageResults = new ImageResults(this.onImageResults); Debug.Log("mFaceFound = " + mFaceFound + ", mFaceLost = " + mFaceLost + ", mImageResults = " + mImageResults); // SCP - TEMPORARY status = affdexRegisterListeners(nativeHandle, ImageCallbackProc, FaceFoundCallbackProc, FaceLostCallbackProc); Debug.Log("Registered listeners: " + status); yield break; }
public List <string> GetImageIds(ImageResults items) { var list = new List <string>(); foreach (var item in items.objects) { string input = item.image; int index = input.LastIndexOf("/") + 1; if (index > 0) { input = input.Substring(index, input.Length - index); list.Add(input); } } return(list); }
void ResultEventHandler(object sender, ResultEventArgs args) { var result = args.Result; int index = 0; lock (ImageResults) { foreach (var image in ImageResults) { if (image.Path == result.Path) { index = ImageResults.IndexOf(image); break; } } Dispatcher.UIThread.InvokeAsync(() => { lock (ImageResults) { ImageResults[index] = new MNISTModelResultDb(result); ImageClasses[result.Class].Add(new MNISTModelResultDb(result)); ClassesInfo[result.Class] = ClassInfoProcess(result.Class, ImageClasses[result.Class].Count); processed++; ProdProgressInfo(); } }); Task.Run(() => { lock (dbContext) { Bitmap resImage = new Bitmap(result.Path); Blob resBlob = new Blob { Bytes = ImageToByteArray(resImage) }; dbContext.ClassifiedImages.Add(new ClassifiedImage { Path = result.Path, Class = result.Class, Confidence = result.Confidence, RetrieveCount = 0, Image = resBlob }); dbContext.Blobs.Add(resBlob); dbContext.SaveChanges(); } }); } }
public async Task PredImages(string dirPath) { var imagePaths = await Task.Run <IEnumerable <string> >(() => { return(Directory.EnumerateFiles(dirPath)); }); ImageResults.Clear(); Source = new CancellationTokenSource(); foreach (var imageClass in ImageClasses) { imageClass.Clear(); ClassesInfo[ImageClasses.IndexOf(imageClass)] = ClassInfoProcess(ImageClasses.IndexOf(imageClass), 0); } foreach (var imagePath in imagePaths) { ImageResults.Add(new MNISTModelResult(imagePath)); } await Task.Run(() => model.PredImages(dirPath, Source.Token)); }
void ResultEventHandler(object sender, ResultEventArgs args) { var result = args.Result; int index = 0; lock (ImageResults) { foreach (var image in ImageResults) { if (image.Path == result.Path) { index = ImageResults.IndexOf(image); break; } } Dispatcher.UIThread.InvokeAsync(() => { lock (ImageResults) { ImageResults[index] = new MNISTModelResult(result); ImageClasses[result.Class].Add(new MNISTModelResult(result)); ClassesInfo[result.Class] = ClassInfoProcess(result.Class, ImageClasses[result.Class].Count); } }); } }
private static extern int affdexRegisterListeners(IntPtr handle, [MarshalAs(UnmanagedType.FunctionPtr)] ImageResults imageCallback, [MarshalAs(UnmanagedType.FunctionPtr)] FaceResults foundCallback, [MarshalAs(UnmanagedType.FunctionPtr)] FaceResults lostCallback);
public async Task PredImages(string dirPath) { var imagePaths = await Task.Run <IEnumerable <string> >(() => { return(Directory.EnumerateFiles(dirPath)); }); ImageResults.Clear(); Source = new CancellationTokenSource(); foreach (var imageClass in ImageClasses) { imageClass.Clear(); ClassesInfo[ImageClasses.IndexOf(imageClass)] = ClassInfoProcess(ImageClasses.IndexOf(imageClass), 0); } ParallelOptions options = new ParallelOptions(); options.CancellationToken = Source.Token; processed = 0; numOfImages = imagePaths.Count(); ProdProgressInfo(); dbContext = new ImageDbContext(); await Task.Run(() => { Parallel.ForEach(imagePaths, options, (imagePath) => { List <string> imagesToClassify = new List <string>(); if (Source.Token.IsCancellationRequested) { return; } MNISTModelResultDb dbImage = null; dbImage = FindImageInDb(imagePath); if (dbImage != null) { Dispatcher.UIThread.InvokeAsync(() => { lock (ImageResults) { ImageResults.Add(dbImage); ImageClasses[dbImage.Class].Add(dbImage); ClassesInfo[dbImage.Class] = ClassInfoProcess(dbImage.Class, ImageClasses[dbImage.Class].Count); processed++; ProdProgressInfo(); } }); } else { Dispatcher.UIThread.InvokeAsync(() => { lock (ImageResults) { ImageResults.Add(new MNISTModelResultDb(imagePath)); } }); imagesToClassify.Add(imagePath); model.PredImages(imagesToClassify, Source.Token).Wait(); } }); }); }
public ImageResultsAdapter(Context context, ImageResults images, List <string> imageUrls) { this.context = context; _images = images; _imageUrls = imageUrls; }