1.打开视觉计数包装机图像
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "jpg图片|*.JPG|png图片|*.PNG|jpeg图片|*.JPEG";
openFile.Title = "打开图像文件";
if (openFile.ShowDialog() == DialogResult.OK)
{
sw.Restart();
string mage = openFile.FileName;
imagein = Cv2.ImRead(mage);
imageout = yolov3_model(imagein);
pictureBox1.Image = imageout.ToBitmap();
label2.Text = "取图" + sw.ElapsedMilliseconds.ToString("f2") + "ms";
}
}2.识别数量处理图像
private Mat yo_model(Mat imgSrc)
{
Mat org = new Mat();
org = imgSrc;
const float threshold = 0.5f;
const float nmsThreshold = 0.3f;
var cfg = Path.Combine(Location1, Cfg);
var model = Path.Combine(Location1, Weight);
var net = CvDnn.ReadNetFromDarknet(cfg, model);
var blob = CvDnn.BlobFromImage(org, 1.0 / 255, new OpenCvSharp.Size(416, 416), new Scalar(), true, false);
net.SetInput(blob);
var outNames = net.GetUnconnectedOutLayersNames();
var outs = outNames.Select(_ => new Mat()).ToArray();
net.Forward(outs, outNames);
org = GetResult(outs, org, threshold, nmsThreshold);
GC.Collect();
return org;
继续阅读
我的微信
这是我的微信扫一扫
我的微信
微信号已复制
我的微信公众号
我的微信公众号扫一扫
我的公众号
公众号已复制
评论