2023年7月9日发(作者:)
winform加载中的videoSourcePlayer。公司最近在做⼈脸识别,⽤到了videoSourcePlayer 但是引⼊了之后,⼯具箱中并没有videoSourcePlayer,这时就需要⾃⼰添加选项卡了。很简单⼏步就能完成。⾸先右键⼯具箱--->添加选项卡
名字随便起,我⾥就叫AForge,然后选中选项卡右键选择项
选择dll,点击OK
再次点击添加到选项卡中
就OK了。然后是控件的使⽤。将videoSourcePlayer拖到winform中。进⼊后台代码中
private FilterInfoCollection videoDevices;//获取摄像头private void Form1_Load(object sender, EventArgs e){try{// 枚举所有视频输⼊设备videoDevices = new FilterInfoCollection(nputDevice);if ( == 0)throw new ApplicationException();foreach (FilterInfo device in videoDevices){();}//下拉框⽤来更换摄像头edIndex = 0;}catch (ApplicationException){("未发现摄像头");edIndex = 0;videoDevices = null;}}
//关闭摄像头 private void button2_Click(object sender, EventArgs e) { if (videoSourcePlayer != null && ing) { ToStop(); rStop(); } } //打开摄像头 private void button1_Click(object sender, EventArgs e) { button2_Click(null, null); if (ng() == "未发现摄像头") { ("未发现摄像头", "错误提⽰", , ); return; } VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[edIndex].MonikerString); esolution = apabilities[edIndex]; ource = videoSource; (); } //换摄像头 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (ng() == "未发现摄像头") { ("未发现摄像头"); edIndex = 0; return; } VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[edIndex].MonikerString); if (() == 0) { ("摄像头异常"); edIndex = 0; return; } (); foreach (apabilities FBL in apabilities) { ( + "*" + ); } edIndex = 0; button1_Click(null, null); }总共就4个⽅法,⾸先获取摄像头,然后 打开摄像头 ,关闭摄像头,在更换摄像头中有获取分辨率的⽅法,这样就能打摄像头并在videoSourcePlayer中看到视频了需要获取当前画⾯,就调⽤Bitmap bitmap = rentVideoFrame();基本上在videoSourcePlayer的⽅法中都有,就不赘叙了。
发布者:admin,转转请注明出处:http://www.yc00.com/news/1688907801a182294.html
评论列表(0条)