我正在开发C# WPF汽车车牌识别使用OCR。
流是,我正在从视频流MJPEG获取图片,这些图像应该被传递到OCR以获取版本号和其他细节。
问题是:视频流产生大约30帧/秒,CPU不能处理这么多处理,也需要大约1 Sec来处理1帧,而且当我在队列中得到多个帧时,CPU将被使用70% (英特尔I7第4 G)。
有人能提出解决方案和更好的实现吗?
//This is the queue where it will hold the frames
// produced from the video streaming(video_Newfram1)
private readonly Queue<byte[]> _anpr1Produces = new Queue<byte[]>();
//I am using AForg.Video to read the MJPEG Streaming
//this event will be triggered for every frame
private void video_NewFrame1(object sender, NewFrameEventArgs eventArgs)
{
var frameDataAnpr = new Bitmap(eventArgs.Frame);
AnprCam1.Source = GetBitmapimage(frameDataAnpr);
//add current fram to the queue
_anpr1Produces.Enqueue(imgByteAnpr);
//this worker is the consumer that will
//take the frames from the queue to the OCR processing
if (!_workerAnpr1.IsBusy)
{
_workerAnpr1.RunWorkerAsync(imgByteAnpr);
}
}
//This is the consumer, it will take the frames from the queue to the OCR
private void WorkerAnpr1_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
if (_anpr1Produces.Count <= 0) continue;
BgWorker1(_anpr1Produces.Dequeue());
}
}
//This method will process the frames that sent from the consumer
private void BgWorker1(byte[] imageByteAnpr)
{
var anpr = new cmAnpr("default");
var objgxImage = new gxImage("default");
if (imageByteAnpr != null)
{
objgxImage.LoadFromMem(imageByteAnpr, 1);
if (anpr.FindFirst(objgxImage) && anpr.GetConfidence() >= Configs.ConfidanceLevel)
{
var vehicleNumber = anpr.GetText();
var vehicleType = anpr.GetType().ToString();
if (vehicleType == "0") return;
var imagename = string.Format("{0:yyyy_MMM_dd_HHmmssfff}", currentDateTime) + "-1-" +
vehicleNumber + ".png";
//this task will run async to do the rest of the process which is saving the vehicle image, getting vehicle color, storing to the database ... etc
var tsk = ProcessVehicle("1", vehicleType, vehicleNumber, imageByteAnpr, imagename, currentDateTime, anpr, _anpr1Produces);
}
else
{
GC.Collect();
}
}
}发布于 2017-02-20 02:34:40
你应该做的是:
首先,找出一个帧是否值得处理。如果使用压缩视频流,通常可以快速读取帧的压缩大小。它存储当前帧与前一个帧之间的差异。
当它很小的时候,变化不大(即:没有汽车经过)。
这是一种低科技的方法来做运动检测,甚至不需要解码一个帧,而且它应该非常快。
这样,您可能决定在几毫秒内跳过80%的帧。
偶尔你会得到需要处理的帧。确保您可以缓冲足够的帧,以便您可以继续记录,而您正在进行缓慢的处理。
接下来要做的就是找到一个感兴趣的区域,并首先关注这些领域。你可以简单地观察颜色变化的区域,或者试图找出矩形的形状。
最后,如果您需要处理30 fps,那么处理1秒是很慢的。你需要把事情做得更快,否则你就得建立一个巨大的缓冲区,希望如果路上很忙,你就能赶上。
如果多个核心是可用的,那么一定要正确地使用它们,但是最终,知道哪些图像片段不相关是提高性能的关键。
https://stackoverflow.com/questions/40713461
复制相似问题