代码:
using System;
using OpenCvSharp;
using OpenCvSharp.Extensions;
using OpenCvSharp.XFeatures2D;
using static OpenCvSharp.Cv2;
namespace Mycv
{
public class cvGO
{
public float Color_Inrange(Bitmap srcbmp, out Bitmap dstbmp, int[] value_Low, int[] value_High)
{
using (Mat src = BitmapConverter.ToMat(srcbmp))
using (Mat dst = new Mat())
{
Scalar cvL = new Scalar(value_Low[0], value_Low[1], value_Low[2]);
Scalar cvH = new Scalar(value_High[0], value_High[1], value_High[2]);
InRange(src, cvL, cvH, dst);
dstbmp = dst.ToBitmap();
return (CountNonZero(dst) / (src.Width * src.Height * 1.0f) * 100);
}
}
}
}
效果图: