2\u3001\u8fdb\u884cUSB\u6444\u50cf\u5934\u7c7b\u5c01\u88c5<\/strong><\/div>\na\u3001\u521d\u59cb\u5316\uff0c\u521d\u59cb\u5316\u65f6\u8981\u6ce8\u610f\uff0c\u52a0\u8f7d\u7684\u8bbe\u5907\u5206\u8fa8\u7387\u9700\u8981\u4eba\u5de5\u914d\u7f6e\uff0c\u5982\u679c\u914d\u7f6e\u5206\u8fa8\u7387\u4e0d\u5b58\u5728\u9700\u8981\u4ece\u9ed8\u8ba4\u7684\u5206\u8fa8\u7387\u4e2d\u9009\u62e9<\/p>\n
\r\nvideoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);\r\n if (videoDevices.Count > 0 && videoDevices.Count >= CameraIndex)\r\n {\r\n FilterInfo info = videoDevices[videoDevices.Count - 1];\r\n videoSource = new VideoCaptureDevice(info.MonikerString);\r\n if (videoSource.VideoCapabilities.Length > 0)\r\n {\r\n VideoCapabilities tmp = videoSource.VideoCapabilities.\r\n First(x => x.FrameSize.Width == LocalSize.Width &&\r\n x.FrameSize.Height == LocalSize.Height);\r\n if (tmp != null)\r\n {\r\n videoSource.SnapshotResolution = tmp;\r\n videoSource.VideoResolution = tmp;\r\n }\r\n else\r\n {\r\n int index = (videoSource.VideoCapabilities.Length + 1) \/ 2;\r\n tmp = videoSource.VideoCapabilities[index];\r\n }\r\n videoSourcePlayer.VideoSource = videoSource;\r\n videoSourcePlayer.Start();\r\n videoSource.NewFrame += new NewFrameEventHandler(Video_NewFrame);\r\n }\r\n }\r\n }\r\n catch (Exception ex)\r\n {\r\n LogHelper.Debug(ex);\r\n}<\/pre>\nb\u3001\u7ed1\u5b9a\u56de\u8c03\u65b9\u6cd5\uff0c\u6b64\u65b9\u6cd5\u5728\u6444\u50cf\u5934\u6210\u529f\u9884\u89c8\u4e4b\u540e\u4f1a\u5b9e\u65f6\u8fd4\u56de\u6570\u636e\u5e27\uff0c\u5c01\u88c5\u65f6\u53ef\u4ee5\u4f20\u5165PictureBox\uff0c\u628a\u56de\u8c03\u65cb\u8f6c\u540e\u7684\u56fe\u7247\u663e\u793a\u5728\u6b64\u63a7\u4ef6\u4e0a<\/p>\n
\r\nprivate void Video_NewFrame(object sender, NewFrameEventArgs eventArgs)\r\n {\r\n try\r\n {\r\n Bitmap video = (Bitmap)eventArgs.Frame.Clone();\r\n BmpRotate(video);\r\n if (UsbVideo != null)\r\n UsbVideo.Image = video;\r\n }\r\n catch (Exception ex)\r\n {\r\n LogHelper.Debug(ex);\r\n }\r\n }\r\n \r\n \/\/\/ \r\n \/\/\/ \u56fe\u50cf\u65cb\u8f6c\r\n \/\/\/ <\/summary>\r\n \/\/\/ \r\n private void BmpRotate(Bitmap _bmp)\r\n {\r\n try\r\n {\r\n if (CameraRotate == \"0\")\r\n {\r\n }\r\n else if (CameraRotate == \"90\")\r\n {\r\n _bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);\r\n }\r\n else if (CameraRotate == \"180\")\r\n {\r\n _bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);\r\n }\r\n else if (CameraRotate == \"270\")\r\n {\r\n _bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);\r\n }\r\n }\r\n catch (Exception ex)\r\n {\r\n LogHelper.Debug(ex);\r\n }\r\n}<\/pre>\nc\u3001\u6293\u56fe\u4e8b\u4ef6\uff0c\u624b\u52a8\u6293\u56fe\u4e8b\u4ef6\uff0c\u901a\u8fc7\u8c03\u7528GetCurrentVideoFrame()\u65b9\u6cd5\u83b7\u53d6Bitmap\u56fe\u7247<\/p>\n
\r\npublic Bitmap GetCurrentVideoFrame()\r\n {\r\n Bitmap bmp = null;\r\n try\r\n {\r\n bmp = videoSourcePlayer.GetCurrentVideoFrame();\r\n BmpRotate(bmp);\r\n }\r\n catch (Exception ex)\r\n {\r\n LogHelper.Debug(ex);\r\n }\r\n return bmp;\r\n }<\/pre>\nd\u3001\u6444\u50cf\u5934\u91cd\u8fde\uff0c\u6b64\u7c7b\u5e93\u4e2dvideoSourcePlayer\u6709\u4e2a\u5c5e\u6027IsRunning\u53ef\u4ee5\u5224\u65ad\u662f\u5426USB\u6444\u50cf\u5934\u9884\u89c8\u4e2d\uff0c\u53ef\u4ee5\u5bf9\u8bbe\u5907\u8fdb\u884c\u91cd\u8fde<\/p>\n
private FilterInfoCollection videoDevices = null; \/\/\u6444\u50cf\u5934\u8bbe\u5907\r\npublic VideoCaptureDevice videoSource = null; \/\/\u89c6\u9891\u7684\u6765\u6e90\u9009\u62e9\r\nprivate VideoSourcePlayer videoSourcePlayer = new VideoSourcePlayer();\r\npublic Bitmap img = null;\r\npublic int CameraIndex = 1;\r\n \/\/\/ \r\n \/\/\/ \u9ed8\u8ba4\u5206\u8fa8\u7387\r\n \/\/\/ <\/summary>\r\n public Size LocalSize = new Size(640, 480);\r\n bool isHave = false;\r\n public string CameraRotate = \"0\";\r\n private System.Windows.Forms.PictureBox UsbVideo = null;\r\n public void ReConnect()\r\n {\r\n try\r\n {\r\n if (!videoSourcePlayer.IsRunning)\r\n {\r\n videoSource.Stop();\r\n videoSource.Start();\r\n }\r\n }\r\n catch (Exception)\r\n {\r\n }\r\n}<\/pre>\n\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
C#\u8c03\u7528USB\u6444\u50cf\u5934\u4f7f\u7528AForge\u7c7b\u5e93\u8fdb\u884c\u5f00\u53d1\uff0c\u4f9b\u5927\u5bb6\u53c2\u8003\uff0c\u5177\u4f53\u5185\u5bb9\u5982\u4e0b \u53f3\u51fb\u5de5\u7a0b\uff0c\u5728\u7ba1\u7406NuGet\u7a0b\u5e8f\u5305\u4e2d […]<\/p>\n","protected":false},"author":362,"featured_media":42146,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-239128","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=239128"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239128\/revisions"}],"predecessor-version":[{"id":239133,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/239128\/revisions\/239133"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/42146"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=239128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=239128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=239128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}