public static ImageAnnotation AddAnnotation(string library, Bitmap image, IBoundingBox region, JObject data) { CouchDatabase db = GetDatabase(library); string imgid = AddImage(db, image); ImageAnnotation toAdd = new ImageAnnotation(region, data, imgid); if (HasDocument(db, toAdd.Id)) { throw new InvalidOperationException("There already exists an annotation for this image with this location. Retreive that annotation and update its data accordingly."); } CouchDbAnnotation ca = new CouchDbAnnotation(); ca.data = toAdd.Data; ca.top = toAdd.Region.Top; ca.left = toAdd.Region.Left; ca.width = toAdd.Region.Width; ca.height = toAdd.Region.Height; ca.screenshotId = toAdd.ImageId; ca.type = "annotation"; Document <CouchDbAnnotation> document = new Document <CouchDbAnnotation>(ca); document.Id = toAdd.Id; db.CreateDocument(document); return(toAdd); }
public static List <ImageAnnotation> GetAllAnnotationsForImage(string library, string imageId, IBoundingBox region) { CouchClient client = new CouchClient(); CouchDatabase db = GetDatabase(library); var options = new ViewOptions(); options.Key.Add(imageId); options.IncludeDocs = true; var cannotations = db.View <CouchDbAnnotation>("by_screenshot", options, "annotations"); List <ImageAnnotation> annotations = new List <ImageAnnotation>(); foreach (CouchDbAnnotation ca in cannotations.Items) { BoundingBox bb = new BoundingBox(ca.left, ca.top, ca.width, ca.height); if (BoundingBox.Equals(region, bb)) { ImageAnnotation ia = new ImageAnnotation(bb, ca.data, ca.screenshotId); annotations.Add(ia); } } return(annotations); }
public static ImageAnnotation AddAnnotation(string library, Bitmap image, IBoundingBox region, JObject data) { CouchDatabase db = GetDatabase(library); string imgid = AddImage(db, image); ImageAnnotation toAdd = new ImageAnnotation(region, data, imgid); if (HasDocument(db, toAdd.Id)) throw new InvalidOperationException("There already exists an annotation for this image with this location. Retreive that annotation and update its data accordingly."); CouchDbAnnotation ca = new CouchDbAnnotation(); ca.data = toAdd.Data; ca.top = toAdd.Region.Top; ca.left = toAdd.Region.Left; ca.width = toAdd.Region.Width; ca.height = toAdd.Region.Height; ca.screenshotId = toAdd.ImageId; ca.type = "annotation"; Document<CouchDbAnnotation> document = new Document<CouchDbAnnotation>(ca); document.Id = toAdd.Id; db.CreateDocument(document); return toAdd; }
public static ImageAnnotation GetAnnotation(string library, Bitmap image, IBoundingBox region) { CouchDatabase db = GetDatabase(library); string imgid = ImageAnnotation.GetImageId(image); ImageAnnotation ia = new ImageAnnotation(region, null, imgid); try { CouchDbAnnotation ca = db.GetDocument <CouchDbAnnotation>(ia.Id); return(new ImageAnnotation(region, ca.data, imgid)); } catch { return(null); } }
public static ImageAnnotation GetAnnotation(string library, Bitmap image, IBoundingBox region) { CouchDatabase db = GetDatabase(library); string imgid = ImageAnnotation.GetImageId(image); ImageAnnotation ia = new ImageAnnotation(region, null, imgid); try { CouchDbAnnotation ca = db.GetDocument<CouchDbAnnotation>(ia.Id); return new ImageAnnotation(region, ca.data, imgid); } catch { return null; } }
private static string AddImage(CouchDatabase db, Bitmap image) { string imgid = ImageAnnotation.GetImageId(image); if (!HasDocument(db, imgid)) { JObject imgJson = new JObject(); imgJson["_id"] = imgid; imgJson["type"] = "screenshot"; Document doc = new Document(imgJson); db.CreateDocument(doc); System.Drawing.Bitmap bmp = Bitmap.ToSystemDrawingBitmap(image); ImageConverter converter = new ImageConverter(); byte[] imgbytes = (byte[])converter.ConvertTo(bmp, typeof(byte[])); db.AddAttachment(imgid, imgbytes, "image", "image/png"); } return(imgid); }
public static IEnumerable <ImageAnnotation> GetAnnotations(string library) { List <ImageAnnotation> annotations = new List <ImageAnnotation>(); if (library != null) { CouchDatabase db = GetDatabase(library); var options = new ViewOptions(); options.IncludeDocs = true; var cannotations = db.View <CouchDbAnnotation>("all", options, "annotations"); foreach (CouchDbAnnotation ca in cannotations.Items) { BoundingBox bb = new BoundingBox(ca.left, ca.top, ca.width, ca.height); ImageAnnotation ia = new ImageAnnotation(bb, ca.data, ca.screenshotId); annotations.Add(ia); } } return(annotations); }
public static IEnumerable<ImageAnnotation> GetAnnotations(string library) { List<ImageAnnotation> annotations = new List<ImageAnnotation>(); if (library != null) { CouchDatabase db = GetDatabase(library); var options = new ViewOptions(); options.IncludeDocs = true; var cannotations = db.View<CouchDbAnnotation>("all", options, "annotations"); foreach (CouchDbAnnotation ca in cannotations.Items) { BoundingBox bb = new BoundingBox(ca.left, ca.top, ca.width, ca.height); ImageAnnotation ia = new ImageAnnotation(bb, ca.data, ca.screenshotId); annotations.Add(ia); } } return annotations; }
public Example(Image image, string annotationLib, ImageAnnotation annotation) { Img = image.Source; Annotation = annotation; AnnotationLibrary = annotationLib; }
public static List<ImageAnnotation> GetAllAnnotationsForImage(string library, string imageId, IBoundingBox region) { CouchClient client = new CouchClient(); CouchDatabase db = GetDatabase(library); var options = new ViewOptions(); options.Key.Add(imageId); options.IncludeDocs = true; var cannotations = db.View<CouchDbAnnotation>("by_screenshot", options, "annotations"); List<ImageAnnotation> annotations = new List<ImageAnnotation>(); foreach (CouchDbAnnotation ca in cannotations.Items) { BoundingBox bb = new BoundingBox(ca.left, ca.top, ca.width, ca.height); if (BoundingBox.Equals(region, bb)) { ImageAnnotation ia = new ImageAnnotation(bb, ca.data, ca.screenshotId); annotations.Add(ia); } } return annotations; }