programmatically added annotation - location wrong

Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.

Moderator: Alex

Post Reply
Neralem
Posts: 4
Joined: Thu Jun 06, 2019 10:30 am

programmatically added annotation - location wrong

Post by Neralem » Thu Jun 06, 2019 10:44 am

Hi,

i'm sending images to a REST API and receiving some information like boundingboxes related to this image. Those bb's are described over x,y,with,height in Pixels. Now i want to add rectangle annotations with a transparent filling to visualize those bb's and show the result in an WpfAnnotationViewer.

My code looks similar to this:

Code: Select all

AnnotationDataController annotationDataController = new AnnotationDataController(new ImageCollection { new VintasoftImage(ocrImagePathTextBox.Text, true) });
AnnotationViewController annotationViewController = new AnnotationViewController(annotationDataController);

Rect bb = ...; // Let this be the position and size of the bb in Pixels.

RectangleAnnotationData annotationData = new RectangleAnnotationData();
annotationData.Location = new System.Drawing.PointF(
    (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(bb.X, UnitOfMeasure.Pixels, annotationDataController.Images[0].Resolution.Horizontal),
    (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(bb.Y, UnitOfMeasure.Pixels, фnnotationDataController.Images[0].Resolution.Vertical));
annotationData.Size = new System.Drawing.SizeF(
    (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(bb.Width, UnitOfMeasure.Pixels, annotationDataController.Images[0].Resolution.Horizontal),
    (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(bb.Height, UnitOfMeasure.Pixels, annotationDataController.Images[0].Resolution.Vertical));
annotationData.FillBrush = new AnnotationSolidBrush(System.Drawing.Color.Transparent);
annotationDataController.GetAnnotations(0).Add(annotationData);
annotationViewController.BurnAnnotationCollectionOnImage(0);

AnnotationViewer.Images = annotationDataController.Images;
The annotation is allways on the wrong position. The bb values i retrieve are correct. I've tested those with an graphic programm and added some manually. It seems that the x and y values are allways too small.
What am i doing wrong here?

Thanks a lot.

Alex
Site Admin
Posts: 1720
Joined: Thu Jul 10, 2008 2:21 pm

Re: programmatically added annotation - location wrong

Post by Alex » Thu Jun 06, 2019 5:19 pm

Hi,

The Location property of rectangle-based annotation defines the rectangle center.

Here is correct code:

Code: Select all

...
    annotationData.Location = new System.Drawing.PointF(
        (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(bb.X + bb.Width / 2, UnitOfMeasure.Pixels, annotationDataController.Images[0].Resolution.Horizontal),
        (float)UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(bb.Y + bb.Height / 2, UnitOfMeasure.Pixels, annotationDataController.Images[0].Resolution.Vertical));
...
Please update your code and let me know if you will have any question or problem.

Best regards, Alexander

Neralem
Posts: 4
Joined: Thu Jun 06, 2019 10:30 am

Re: programmatically added annotation - location wrong

Post by Neralem » Fri Jun 14, 2019 2:31 pm

Thank you Alex. This works. Couldn't find that hint in the documentation. Maybe someone forgot to write that down?^^

Post Reply