今天在官网下载了最新版本的C# SDK,使用emgucv播放USB相机视频。测试结果与官方相差很大,官方是720P视频30ms,我电脑的实际结果是78ms-100ms。
这是我电脑配置:
这是源代码,请官网大神相助
BaiduApi.cs class BaiduApi { private static readonly ILog log = LogManager.GetLogger(typeof(BaiduApi)); // sdk初始化 [DllImport("BaiduFaceApi.dll", EntryPoint = "sdk_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] private static extern int sdk_init(bool id_card); // 是否授权 [DllImport("BaiduFaceApi.dll", EntryPoint = "is_auth", CharSet = CharSet.Ansi , CallingConvention = CallingConvention.Cdecl)] private static extern bool is_auth(); [DllImport("BaiduFaceApi.dll", EntryPoint = "track_by_buf", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr track_by_buf(byte[] image, int size, int max_track_num); internal bool isAuth() { return is_auth(); } internal void sdkInit() { log.Info("开始初始化"); int init = sdk_init(false); log.InfoFormat("初始化结果:{0}",init); } private Stopwatch watch = Stopwatch.StartNew(); internal string TrackFace(byte[] bytes) { watch.Reset(); watch.Start(); int max_track_num = 5; // 设置最多检测人数(多人脸检测),默认为1,最多可设为10 IntPtr ptr = track_by_buf(bytes, bytes.Length, max_track_num); string buf = Marshal.PtrToStringAnsi(ptr); log.DebugFormat("track bytes :{0}", buf); log.DebugFormat("耗时:{0}", watch.ElapsedMilliseconds); return buf; } }
Main.cs public partial class Main : Form { private static readonly ILog log = LogManager.GetLogger(typeof(Main)); private Capture capture; private BaiduApi baiduApi; private MCvFont f = new MCvFont(FONT.CV_FONT_HERSHEY_SIMPLEX, 1, 1); public Main() { InitializeComponent(); baiduApi = new BaiduApi(); capture = new Capture() { FlipType = FLIP.HORIZONTAL }; Application.Idle += new EventHandler(ProcessFram); } private void ProcessFram(object sender, EventArgs arg) { Image frame = capture.QueryFrame(); if (frame != null) { string json = baiduApi.TrackFace(ImageUtil.img2byte(frame.Bitmap)); imageBox1.Image = frame; } } private void Form1_Load(object sender, EventArgs e) { if (!baiduApi.isAuth()) { baiduApi.sdkInit(); } } }
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
这还是有一定配置要求的。你这个不该用离线sdk,问问工单有没有私有化部署服务提供
你CPU运算不了1帧处理1帧,那先不说渲染UI,光处理计算都来不及
其实项目现在用于闸机上的工控机为了保证散热,都是低电压的CPU J1900,内存4G,性能都很低。现在我笔记本虽然是低电压,应该也会强很多。
之所以采用 emgucv采流,是因为emgucv不仅支持文件视频,也支持rtsp,后期可以用视频文件做测试,也可以用rtsp做大屏监控。
您的意思是采流时,有可以当前帧没处理完,第二帧可能会同时来处理?
另外,usb取流,c# 离线sdk里就自带了。
看你代码你每一帧你自己把性能损失在了emgucv的采流上,采下来的流都在进行img2byte的转换然后去跑TrackFace。
虽然不敢说sdk内部是否和你一样是这样子做,但是至少可见的代码里整个回调也没做抽帧。
只要你cpu1帧里没处理完上一帧的计算,你的这个性能只会迅速下滑,而且是累计式的。
本身软件性能就跟配置有关系。依赖于机器视觉的算法需要进行计算。
你既然都贴出配置了,那肯定知道配置影响到了性能,那何必在标题里怪罪SDK呢?
开发环境和线上环境基本上做不到保持一致这道理应该了解吧。
要知道现在I9都出来了,你拿一张低电压版的I5还想要求高性能。
兄弟,我只能说 鱼和熊掌不可兼得