Emgu 3.0 缺少 MCvFont 库

MCvFont library is missing at Emgu 3.0

我在 Visual Studio 2010 上将我的项目与 Emgu 3.0 集成在一起,并且我正在处理检测对象项目,但是当我像下面一行那样使用 MCvFont 时,我收到错误消息,因为库丢失了,这库已从最新版本的 Emgu 中删除或什么?

 MCvFont f2 = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX, 1.0, 1.0);

Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_TRIPLEX 在 Emgu 3.0 中可以是 Emgu.CV.CvEnum.FontFace.HersheyTriplex

MCvFont 出现在 Emgu.CV.Structure Emgu_2.4.10, 但它在 Emgu_3.0.0 处丢失。我在 emgu 版本历史中检查了这个。

您可以通过添加到 Emgu_2.4.10 的引用 Emgu.CV 来修复此代码, 抓住这个 dll https://dropmefiles.com/AZvmM

可以找到将 2.4.x 代码转换为 3.0 的说明 http://www.emgu.com/wiki/index.php/Tutorial#Upgrading_from_Emgu_CV_2.x_to_3.x

你做人脸识别还是眼睛识别? 这是我在 Whosebug 上的第一个答案:)

CvInvoke.PutText(img,
"Hello, world", 
new System.Drawing.Point(10, 80), 
FontFace.HersheyComplex, 1.0, 
new Bgr(0, 255, 0).MCvScalar);

参考: http://www.emgu.com/wiki/index.php/Hello_World_in_CSharp#Emgu_CV_3.0_2

我不想添加额外的 dll 以向后兼容 2.x 版本的 Emgu,以便在 3.x 版本的 Emgu 中编写代码。正如@Константин Марков 在他的回答中指出的那样,MCvFont 不再是 Emgu 3.x 版本库的一部分。

我假设您的最终目标是在图像中写一些文本。所以,如果您不介意更改您的代码,您需要重写它才能使用 CvInvoke.PutText 方法来实现该目标。

根据上述方法的官方文档page,CvInvoke.PutText

Renders the text in the image with the specified font and color. The printed text is clipped by ROI rectangle. Symbols that do not belong to the specified font are replaced with the rectangle symbol.

这是 C# 中的方法签名

public static void PutText(
    IInputOutputArray img,
    string text,
    Point org,
    FontFace fontFace,
    double fontScale,
    MCvScalar color,
    int thickness = 1,
    LineType lineType = LineType.EightConnected,
    bool bottomLeftOrigin = false
)

下面是方法中每个参数的说明

  • img
    • 类型:Emgu.CV.IInputOutputArray
    • 描述:输入图片
  • 正文
    • 类型:System.String
    • 描述:要打印的字符串
  • 组织
    • 类型:System.Drawing.Point
    • 描述:第一个字母bottom-left角的坐标
  • fontFace
    • 类型:Emgu.CV.CvEnum.FontFace
    • 描述:字体类型。
  • fontScale
    • 类型:System.Double
    • 说明:字体比例因子乘以 font-specific 基本大小。
  • 颜色
    • 类型:Emgu.CV.Structure.MCvScalar
    • 描述:文字颜色
  • 厚度(可选)
    • 类型:System.Int32
    • 说明:用于绘制文本的线条粗细。
  • 线型(可选)
    • 类型:Emgu.CV.CvEnum.LineType
    • 描述:线型
  • bottomLeftOrigin(可选)
    • 类型:System.Boolean
    • 说明:为真时,图像数据原点在bottom-left角。否则,它在 top-left 角。

这是直接取自此 source

的代码示例
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using System.Drawing;

...

//Create a 3 channel image of 400x200
using (Mat img = new Mat(200, 400, DepthType.Cv8U, 3)) 
{
   img.SetTo(new Bgr(255, 0, 0).MCvScalar); // set it to Blue color

   //Draw "Hello, world." on the image using the specific font
   CvInvoke.PutText(
      img, 
      "Hello, world", 
      new System.Drawing.Point(10, 80), 
      FontFace.HersheyComplex, 
      1.0, 
      new Bgr(0, 255, 0).MCvScalar);

   //Show the image using ImageViewer from Emgu.CV.UI
   ImageViewer.Show(img, "Test Window");
}