【发布时间】:2021-02-01 12:13:37
【问题描述】:
我正在尝试设置 OpenCvSharp,但到目前为止,尽管遵循了文档,但我什至无法成功编译基本代码示例。我按照OpenCvSharp wiki Windows tutorial 的指示到了发球台。
我从 SourceForge 获得了最新的 OpenCV 二进制文件,并将文件夹添加到我的环境变量和路径中:
接下来,我下载了 OpenCvSharp DLL 文件并将 OpenCvSharp.dll 引用添加到我的示例项目中:
以及将 OpenCvSharpExtern.dll 添加到 EXE 输出目录,但这无济于事,因为我一开始无法编译可执行文件。
我刚刚从 wiki 复制了示例 Program.cs 代码,
using System;
using System.Runtime.InteropServices;
using OpenCvSharp;
namespace WindowsFormsApplication1
{
static class Program
{
static void Main()
{
using (IplImage image = new IplImage(128, 128, BitDepth.U8, 1))
{
image.Zero();
for (int x = 0; x < image.Width; x++)
{
for (int y = 0; y < image.Height; y++)
{
int offset = y * image.WidthStep + x;
byte value = (byte)(x + y);
Marshal.WriteByte(image.ImageData, offset, value);
}
}
using (CvWindow window = new CvWindow(image))
{
CvWindow.WaitKey();
}
}
}
}
}
但是当我尝试编译它时,我得到了 OpenCvSharp 函数和类型的错误:
CS0246 The type or namespace "IplImage" was not found
CS0246 The type or namespace "IplImage" was not found
CS0103 The name "BitDepth" is not defined in current context
CS0246 The type or namespace "CvWindow" was not found
CS0246 The type or namespace "CvWindow" was not found
CS0103 The name "CvWindow" is not defined in current context
引用已到位,并且包中包含using,那么为什么Visual Studio 无法识别定义?
【问题讨论】:
-
最好复制粘贴代码段并翻译 i18n 的错误消息。
标签: c# .net windows opencv visual-studio-2019