当前位置: 首页 > wzjs >正文

两栏式网站做企业推广

两栏式网站,做企业推广,搬家网站建设公司,怎么做学校官方网站1.首先创建ConsoleApp,.Net 9.0,不要创建WinForm 。WInForm帧率和实际对不上,有延时。 2.下载opencvsharp。 3.下载openh264-1.8.0-win32.dll , openh264-1.8.0-win64.dll .放在根目录。 https://github.com/cisco/openh264 using OpenCv…

1.首先创建ConsoleApp,.Net 9.0不要创建WinFormWInForm帧率和实际对不上,有延时

2.下载opencvsharp。

3.下载openh264-1.8.0-win32.dll  ,  openh264-1.8.0-win64.dll .放在根目录。

https://github.com/cisco/openh264

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;namespace ConsoleApp1
{internal class Program{private const int CameraIndex = 0;private const double Fps = 30.0;// private static readonly OpenCvSharp.Size FrameSize = new OpenCvSharp.Size(1280, 720);private static readonly OpenCvSharp.Size FrameSize = new OpenCvSharp.Size(640, 480);private const int ReconnectInterval = 3000; // 重试间隔(ms)private const int MaxReconnectAttempts = 5; // 最大重试次数static void Main(string[] args){int reconnectAttempts = 0;bool isRecording = true;while (isRecording && reconnectAttempts < MaxReconnectAttempts){try{using (var capture = new VideoCapture(CameraIndex))using (var writer = new VideoWriter()){if (!InitializeCamera(capture)){reconnectAttempts++;Thread.Sleep(ReconnectInterval);continue;}string OutputFile = System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + "_output.avi";if (!InitializeVideoWriter(writer, OutputFile, Fps, FrameSize)){Console.WriteLine("无法初始化视频写入器!");return;}Console.WriteLine("开始录制,按ESC键停止...");reconnectAttempts = 0; // 重置重试计数器using (var window = new Window("摄像头画面"))using (var frame = new Mat()){while (true){// 检查摄像头是否仍然连接if (!capture.IsOpened()){Console.WriteLine("检测到摄像头断开连接!");break;}// 捕获帧capture.Read(frame);DateTime now = DateTime.Now;Cv2.PutText(frame, now.ToString("yyyy-MM-dd HH:mm:ss"), new Point(10, 30),HersheyFonts.HersheySimplex, 0.6, Scalar.White, 1);if (frame.Empty()){Console.WriteLine("接收到空帧,可能摄像头已断开!");break;}// 显示帧window.ShowImage(frame);// 写入帧到文件writer.Write(frame);// 按ESC键退出if (Cv2.WaitKey(10) == 27){isRecording = false;break;}}}}}catch (Exception ex){Console.WriteLine($"发生错误: {ex.Message}");}if (isRecording && reconnectAttempts < MaxReconnectAttempts){Console.WriteLine($"尝试重新连接({reconnectAttempts + 1}/{MaxReconnectAttempts})...");reconnectAttempts++;Thread.Sleep(ReconnectInterval);}}if (reconnectAttempts >= MaxReconnectAttempts){Console.WriteLine($"已达到最大重试次数({MaxReconnectAttempts}),停止尝试。");}Console.WriteLine("程序结束");}static bool InitializeCamera(VideoCapture capture){if (!capture.IsOpened()){Console.WriteLine("无法打开摄像头!");return false;}// 设置摄像头参数capture.Set(VideoCaptureProperties.FrameWidth, FrameSize.Width);capture.Set(VideoCaptureProperties.FrameHeight, FrameSize.Height);capture.Set(VideoCaptureProperties.Fps, Fps);// 验证实际设置的值double actualWidth = capture.Get(VideoCaptureProperties.FrameWidth);double actualHeight = capture.Get(VideoCaptureProperties.FrameHeight);Console.WriteLine($"摄像头分辨率: {actualWidth}x{actualHeight}");return true;}static bool InitializeVideoWriter(VideoWriter writer, string filename, double fps, Size frameSize){// 尝试几种常见的编码格式Dictionary<string, FourCC> _codecs = new Dictionary<string, FourCC>(){{"X264", FourCC.X264},{"XVID", FourCC.XVID},{"MJPG", FourCC.MJPG},{"H264", FourCC.H264},{"MP4V", FourCC.MP4V},{"DIVX", FourCC.DIVX}};foreach (var codec in _codecs){writer.Open(filename, codec.Value, fps, frameSize, true);if (writer.IsOpened()){Console.WriteLine($"使用编码器: {codec.Key}");return true;}}Console.WriteLine("无法找到合适的视频编码器!");return false;}}
}

4.运行。

整个工程打包下载:

【免费】opencvsharpusb摄像头录像c#H264编码资源-CSDN文库

http://www.dtcms.com/wzjs/1515.html

相关文章:

  • 南昌公司网站建设模板佛山网络排名优化
  • 成都中方互动科技有限公司丽水百度seo
  • 网站做301的坏处企业网站注册域名的步骤
  • 网站建设公司华网天下官网自动发外链工具
  • .net 网站开发权限设计谷歌关键词搜索量数据查询
  • 怎么把网站改为正在建设中企排排官网
  • 网络营销seo培训seo综合查询工具
  • 个人网站源码下载阿里大数据平台
  • 龙华做棋牌网站建设找哪家效益快网络推广属于什么行业
  • 鄄城菏泽网站建设深圳网络推广公司
  • 做儿童网站国内的搜索引擎有哪些
  • 番禺做网站设计关键词排名是由什么决定的
  • 彩票网站开发dadi163快速提高关键词排名的软件
  • 手机支付网站开发seo优化名词解释
  • 网站关键词设置几个网络服务合同
  • 企业网站的分类凯里seo排名优化
  • 公司起名字大全免费2022网站建设方案优化
  • 淘宝网页版登录黑帽seo技术有哪些
  • 广州荔湾做网站公安卓手机优化
  • 深圳网站制作公司方案百度推广渠道代理
  • 温州网站建设小程序关于市场营销的培训课程
  • 云浮网站建设咨询怎么推广比较好
  • 渭南汽车网站制作教育培训机构推荐
  • 用什么做淘宝客网站好福州短视频seo公司
  • 哪里可以做公司网站备案公司开发设计推荐
  • 学校网站建设说明沈阳百度快照优化公司
  • WordPress建站布置简述seo和sem的区别与联系
  • 河南网站建设推广运营西安seo教程
  • 公司基本资料模板搜索引擎优化的方法和技巧
  • 做美剧盗版网站昆明做网站的公司