Stemmer.Cvb.ImageDrawer.DrawCircle

Hi Sirs:

I have a problem below, Could anyone help to check? thank you.

I try to draw a circle on my image. My image is 24bit.
When I run the program it show this exception.

2020_01_30_14_16_56_AICapClassifier_偵錯_Microsoft_Visual_Studio

My C# program function:

private void DrawCircleOnImage()
{
try
{
var image = Stemmer.Cvb.Image.FromFile(“123.bmp”);

            Stemmer.Cvb.RgbColor color = Stemmer.Cvb.RgbColor.FromArgb(0, 50, 0, 10);
            Stemmer.Cvb.ImageDrawer.DrawCircle(image, color, 2, 5, 5, 2);

            image.Save("draw circle.png");
        }
        catch (Exception ee)
        {
            MessageBox.Show(ee.ToString());
        }
    }

Hi @Jesse,

yes, there is a bug in the DrawCircle function. Until we fix this you can use this workaround:

using System;
using System.Runtime.InteropServices;

using Stemmer.Cvb;

namespace CvbExtensions
{
  public static class ImageDrawer
  {
    private const int AntiAliasOff = 0;
    private const int NormalDrawMode = 0;

    public static void DrawCircle(Image image, RgbColor color, int thickness, int centerX, int centerY, int radius)
    {
      DrawCircle(image, new double[] { color.R, color.G, color.B }, thickness, centerX, centerY, radius);
    }

    public static void DrawCircle(Image image, double[] intensity, int thickness, int centerX, int centerY, int radius)
    {
      if (image == null)
        throw new ArgumentNullException(nameof(image));
      if (image.Planes.Count != intensity.Length)
        throw new ArgumentException("Intensity array length differs in regard to the number of planes", nameof(intensity));
      for (int i = 0; i < intensity.Length; ++i)
        DrawCircle(image.Planes[i], intensity[i], thickness, centerX, centerY, radius);
    }

    public static void DrawCircle(ImagePlane plane, double intensity, int thickness, int centerX, int centerY, int radius)
    {
      int result = DrawCircleInImage(plane.Parent.Handle, plane.Plane, centerX, centerY, radius, intensity, thickness, NormalDrawMode, AntiAliasOff);
      if (result < 0)
        throw CvbException.FromCvbResult(result);
    }
    
    [DllImport("CVCImg")]
    private static extern int DrawCircleInImage(IntPtr image, int index, int centerX, int centerY, int radius, double intensity, int thickness, int drawMode, int antiAliasMode);
  }
}

Hi Parsd:

Thank you for helping me to check.But I can’t import CVCImg.dll. The path is C:\Program Files\STEMMER IMAGING\Common Vision Blox\CVCImg.dll . In the C# program, cvbres can’t find the class or namespace. Could you teach me how to import the dll and use the DrawCircle function.

Sorry, that was a typo. We use this as an alias for an int internally. Replace the cvbres with an int. I also corrected the class above.

Hi Parsd:

Thank you for helping me. Now I can continute to try my C# project. :blush:

1 Like

Hi Sir:

I want to create a mask image like this.mask

Could you give me some example ? and help me to check my code below, thank you.
my questions:

  1. How to use Stemmer cvb dll to create a black image?
    2.I try to use Stemmer.Cvb.ImageDrawer.FillCircle function to draw fill circle on my image, but it also show this exception.

draw circle exception

My C# Code:

private void CreateMask()
{
try
{
string filepath = “bb.bmp”;
Stemmer.Cvb.Image mask_image = Stemmer.Cvb.Image.FromFile(filepath);

	mask_image.Initialize(0);

	Stemmer.Cvb.ImageDrawer.FillCircle(mask_image.Planes[0], 255, 50, 50, 10);

	mask_image.Save("mask with circle.bmp");
}
catch (Exception ee)
{
	MessageBox.Show(ee.ToString());
}

}