问题描述
我在将Zxing库与openCvSharp集成时遇到问题。我正在尝试通过相机实时读取条形码。
它在给出的行var r1 = 5
var r2 = 10
signal = highest(r1) >= highest(r2) and lowest(r1) <= lowest(r2)
plotshape(signal,style=shape.triangleup,location=location.abovebar,color=color.green)
上引发异常;
abovebar
如果有人有任何解决方案,建议或想法,我将不胜感激! 完整的代码是:
private
解决方法
根据.Net目标平台,您可以将位图直接与Decode方法一起使用。只有.Net核心/标准版本不直接支持Bitmap类。
static void Main(string[] args)
{
VideoCapture capture = new VideoCapture(0);
BarcodeReader barcodeReader = new BarcodeReader();
using (Window window = new Window("Camera"))
using(Mat image = new Mat())
{
while (true)
{
capture.Read(image); // same as cvQueryFrame
var barcodeBitMap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(image);
Result result = barcodeReader.Decode(barcodeBitMap);
if (result != null)
{
Console.WriteLine("result: " + result.Text);
}
window.ShowImage(image);
Cv2.WaitKey(30);
}
}
}
或者,您可以尝试以下绑定之一
https://www.nuget.org/packages/ZXing.Net.Bindings.OpenCV/
https://www.nuget.org/packages/ZXing.Net.Bindings.OpenCVSharp.V2/
使用它们,您可以实例化另一个BarcodeReader实现,该实现直接支持Mat结构。
static void Main(string[] args)
{
VideoCapture capture = new VideoCapture(0);
BarcodeReader barcodeReader = new ZXing.OpenCV.BarcodeReader();
using (Window window = new Window("Camera"))
using(Mat image = new Mat())
{
while (true)
{
capture.Read(image); // same as cvQueryFrame
Result result = barcodeReader.Decode(image);
if (result != null)
{
Console.WriteLine("result: " + result.Text);
}
window.ShowImage(image);
Cv2.WaitKey(30);
}
}
}