{"id":68783,"date":"2026-01-30T18:09:17","date_gmt":"2026-01-30T10:09:17","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/68783.html"},"modified":"2026-01-30T18:09:17","modified_gmt":"2026-01-30T10:09:17","slug":"opencv%e5%ae%9e%e6%97%b6%e6%91%84%e5%83%8f%e5%a4%b4%e5%a4%84%e7%90%86%ef%bc%9a%e6%9b%9d%e5%85%89%e8%b0%83%e8%8a%82%e3%80%81%e9%99%8d%e5%99%aa%e4%b8%8e%e4%ba%8c%e5%80%bc%e5%8c%96%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/68783.html","title":{"rendered":"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218"},"content":{"rendered":"<h2 id=\"%E5%89%8D%E8%A8%80\">\u524d\u8a00<\/h2>\n<p>\u5728\u8ba1\u7b97\u673a\u89c6\u89c9\u5b66\u4e60\u8fc7\u7a0b\u4e2d&#xff0c;\u5b9e\u65f6\u6444\u50cf\u5934\u89c6\u9891\u6d41\u5904\u7406\u662f\u6700\u57fa\u7840\u4e5f\u6700\u6838\u5fc3\u7684\u5e94\u7528\u573a\u666f\u4e4b\u4e00\u3002\u672c\u6587\u57fa\u4e8eOpenCV-Python\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u6444\u50cf\u5934\u5b9e\u65f6\u5904\u7406demo&#xff0c;\u6db5\u76d6\u66dd\u5149\u53c2\u6570\u52a8\u6001\u8c03\u8282\u3001\u53cc\u8fb9\u6ee4\u6ce2\u964d\u566a\u3001\u7070\u5ea6\u8f6c\u6362\u4e0e\u4e8c\u503c\u5316\u7b49\u6838\u5fc3\u529f\u80fd&#xff0c;\u9002\u5408OpenCV\u5165\u95e8\u5b66\u4e60\u8005\u7406\u89e3\u89c6\u9891\u6d41\u5904\u7406\u7684\u57fa\u672c\u6d41\u7a0b\u548c\u5173\u952eAPI\u7528\u6cd5&#xff0c;\u4e5f\u662f\u535a\u4e3b\u51c6\u5907\u7535\u8d5b\u65f6\u8ba4\u4e3a\u975e\u5e38\u597d\u7528\u7684\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\u3002<\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E5%89%8D%E8%A8%80-toc\" style=\"margin-left:0px\">\u524d\u8a00<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E5%8A%9F%E8%83%BD%E6%95%B4%E4%BD%93%E8%AF%B4%E6%98%8E-toc\" style=\"margin-left:40px\">\u4e00\u3001\u529f\u80fd\u6574\u4f53\u8bf4\u660e<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87-toc\" style=\"margin-left:40px\">\u4e8c\u3001\u73af\u5883\u51c6\u5907<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E4%BB%A3%E7%A0%81%E9%80%90%E8%A1%8C%E8%A7%A3%E6%9E%90-toc\" style=\"margin-left:40px\">\u4e09\u3001\u4ee3\u7801\u9010\u884c\u89e3\u6790<\/p>\n<p id=\"3.1%20%E5%9F%BA%E7%A1%80%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%9A%E6%91%84%E5%83%8F%E5%A4%B4%E8%B0%83%E7%94%A8%E4%B8%8E%E7%AA%97%E5%8F%A3%E5%88%9B%E5%BB%BA-toc\" style=\"margin-left:80px\">3.1 \u57fa\u7840\u521d\u59cb\u5316&#xff1a;\u6444\u50cf\u5934\u8c03\u7528\u4e0e\u7a97\u53e3\u521b\u5efa<\/p>\n<p id=\"3.2%20%E6%9B%9D%E5%85%89%E5%8F%82%E6%95%B0%E5%8A%A8%E6%80%81%E8%B0%83%E8%8A%82%EF%BC%9A%E6%BB%91%E5%8A%A8%E6%9D%A1%E7%BB%91%E5%AE%9A-toc\" style=\"margin-left:80px\">3.2 \u66dd\u5149\u53c2\u6570\u52a8\u6001\u8c03\u8282&#xff1a;\u6ed1\u52a8\u6761\u7ed1\u5b9a<\/p>\n<p id=\"3.3%20%E9%99%8D%E5%99%AA%E5%8F%82%E6%95%B0%E5%8A%A8%E6%80%81%E8%B0%83%E8%8A%82%EF%BC%9A%E5%8F%8C%E8%BE%B9%E6%BB%A4%E6%B3%A2%E6%BB%91%E5%8A%A8%E6%9D%A1-toc\" style=\"margin-left:80px\">3.3 \u964d\u566a\u53c2\u6570\u52a8\u6001\u8c03\u8282&#xff1a;\u53cc\u8fb9\u6ee4\u6ce2\u6ed1\u52a8\u6761<\/p>\n<p id=\"3.4%20%E8%A7%86%E9%A2%91%E6%B5%81%E5%BE%AA%E7%8E%AF%E5%A4%84%E7%90%86%EF%BC%9A%E6%A0%B8%E5%BF%83%E9%80%BB%E8%BE%91-toc\" style=\"margin-left:80px\">3.4 \u89c6\u9891\u6d41\u5faa\u73af\u5904\u7406&#xff1a;\u6838\u5fc3\u903b\u8f91<\/p>\n<p id=\"3.5%20%E8%B5%84%E6%BA%90%E9%87%8A%E6%94%BE%EF%BC%9A%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E4%B8%8E%E6%94%B6%E5%B0%BE-toc\" style=\"margin-left:80px\">3.5 \u8d44\u6e90\u91ca\u653e&#xff1a;\u5f02\u5e38\u5904\u7406\u4e0e\u6536\u5c3e<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C%E4%B8%8E%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:40px\">\u56db\u3001\u8fd0\u884c\u6548\u679c\u4e0e\u5e38\u89c1\u95ee\u9898<\/p>\n<p id=\"4.1%20%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C-toc\" style=\"margin-left:80px\">4.1 \u8fd0\u884c\u6548\u679c<\/p>\n<p id=\"4.2%20%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-toc\" style=\"margin-left:80px\">4.2 \u5e38\u89c1\u95ee\u9898\u89e3\u51b3<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E6%89%A9%E5%B1%95%E4%B8%8E%E4%BC%98%E5%8C%96%E6%96%B9%E5%90%91-toc\" style=\"margin-left:40px\">\u4e94\u3001\u6269\u5c55\u4e0e\u4f18\u5316\u65b9\u5411<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:40px\">\u516d\u3001\u603b\u7ed3<\/p>\n<p id=\"%E9%99%84%EF%BC%9A%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81-toc\" style=\"margin-left:40px\">\u9644&#xff1a;\u5b8c\u6574\u4ee3\u7801<\/p>\n<p id=\"%E8%A1%A5%E5%85%85%E8%AF%B4%E6%98%8E-toc\" style=\"margin-left:80px\">\u8865\u5145\u8bf4\u660e<\/p>\n<hr id=\"hr-toc\" \/>\n<p>\u8bba\u6587\u6295\u7a3f&#xff1a; \u7b2c\u4e8c\u5c4a\u8ba1\u7b97\u673a\u89c6\u89c9\u7814\u7a76\u8fdb\u5c55\u4e0e\u5e94\u7528\u56fd\u9645\u5b66\u672f\u4f1a\u8bae (ACVRA 2026) \u5927\u4f1a\u5b98\u7f51&#xff1a;https:\/\/ais.cn\/u\/2YrM7j \u5927\u4f1a\u65f6\u95f4&#xff1a;2026\u5e742\u67086-8\u65e5 \u5927\u4f1a\u5730\u70b9&#xff1a;\u4e2d\u56fd-\u6b66\u6c49<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"633\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100914-697c834ac9b2c.png\" width=\"969\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"813\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100915-697c834b0bade.png\" width=\"972\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"216\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100915-697c834b46e3c.png\" width=\"948\" \/><\/p>\n<h3 id=\"%E4%B8%80%E3%80%81%E5%8A%9F%E8%83%BD%E6%95%B4%E4%BD%93%E8%AF%B4%E6%98%8E\">\u4e00\u3001\u529f\u80fd\u6574\u4f53\u8bf4\u660e<\/h3>\n<p>\u672c\u4ee3\u7801\u5b9e\u73b0\u7684\u6838\u5fc3\u529f\u80fd&#xff1a;<\/p>\n<li>\n<p>\u8c03\u7528\u7535\u8111\u672c\u5730\u6444\u50cf\u5934&#xff0c;\u5b9e\u65f6\u8bfb\u53d6\u89c6\u9891\u6d41\u5e76\u663e\u793a\u539f\u59cb\u753b\u9762&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7\u6ed1\u52a8\u6761\u52a8\u6001\u8c03\u8282\u6444\u50cf\u5934\u66dd\u5149\u53c2\u6570&#xff0c;\u5b9e\u65f6\u9884\u89c8\u66dd\u5149\u8c03\u6574\u6548\u679c&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5bf9\u539f\u59cb\u753b\u9762\u8fdb\u884c\u53cc\u8fb9\u6ee4\u6ce2\u964d\u566a\u5904\u7406&#xff0c;\u5355\u72ec\u7a97\u53e3\u663e\u793a\u964d\u566a\u540e\u6548\u679c&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5c06\u964d\u566a\u540e\u7684\u56fe\u50cf\u8f6c\u4e3a\u7070\u5ea6\u56fe&#xff0c;\u5e76\u901a\u8fc7\u9608\u503c\u5904\u7406\u751f\u6210\u4e8c\u503c\u56fe\u50cf&#xff0c;\u5355\u72ec\u7a97\u53e3\u5c55\u793a&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301\u6309\u952e\u9000\u51fa&#xff0c;\u81ea\u52a8\u91ca\u653e\u6444\u50cf\u5934\u8d44\u6e90\u5e76\u5173\u95ed\u6240\u6709\u7a97\u53e3\u3002<\/p>\n<\/li>\n<h3 id=\"%E4%BA%8C%E3%80%81%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87\">\u4e8c\u3001\u73af\u5883\u51c6\u5907<\/h3>\n<p>\u5728\u8fd0\u884c\u4ee3\u7801\u524d&#xff0c;\u9700\u786e\u4fdd\u73af\u5883\u5df2\u5b89\u88c5\u5bf9\u5e94\u4f9d\u8d56&#xff1a;<\/p>\n<p># \u5b89\u88c5OpenCV-Python<br \/>\npip install opencv-python<br \/>\n# \u9a8c\u8bc1\u5b89\u88c5&#xff08;\u53ef\u9009&#xff09;<br \/>\npython -c &#034;import cv2; print(cv2.__version__)&#034; <\/p>\n<p>\u6ce8\u610f&#xff1a;\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf&#xff08;Windows\/macOS\/Linux&#xff09;\u7684\u6444\u50cf\u5934\u8c03\u7528\u903b\u8f91\u4e00\u81f4&#xff0c;\u4f46\u90e8\u5206\u8bbe\u5907\u53ef\u80fd\u9700\u8981\u8c03\u6574\u6444\u50cf\u5934ID&#xff08;\u901a\u5e380\u4e3a\u5185\u7f6e\u6444\u50cf\u5934&#xff0c;1\u4e3a\u5916\u63a5\u6444\u50cf\u5934&#xff09;\u3002<\/p>\n<h3 id=\"%E4%B8%89%E3%80%81%E4%BB%A3%E7%A0%81%E9%80%90%E8%A1%8C%E8%A7%A3%E6%9E%90\">\u4e09\u3001\u4ee3\u7801\u9010\u884c\u89e3\u6790<\/h3>\n<h4 id=\"3.1%20%E5%9F%BA%E7%A1%80%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%9A%E6%91%84%E5%83%8F%E5%A4%B4%E8%B0%83%E7%94%A8%E4%B8%8E%E7%AA%97%E5%8F%A3%E5%88%9B%E5%BB%BA\">3.1 \u57fa\u7840\u521d\u59cb\u5316&#xff1a;\u6444\u50cf\u5934\u8c03\u7528\u4e0e\u7a97\u53e3\u521b\u5efa<\/h4>\n<p>import cv2<\/p>\n<p>def main():<br \/>\n    # \u6444\u50cf\u5934\u8bbe\u5907\u7f16\u53f7&#xff0c;\u901a\u5e380\u4e3a\u5185\u7f6e\u6444\u50cf\u5934&#xff0c;1\u4e3a\u5916\u63a5<br \/>\n    camera_id &#061; 0<br \/>\n    # \u521b\u5efaVideoCapture\u5bf9\u8c61&#xff0c;\u7ed1\u5b9a\u6444\u50cf\u5934<br \/>\n    cap &#061; cv2.VideoCapture(camera_id)<\/p>\n<p>    # \u68c0\u67e5\u6444\u50cf\u5934\u662f\u5426\u6210\u529f\u6253\u5f00<br \/>\n    if not cap.isOpened():<br \/>\n        print(&#034;Error: Could not open camera.&#034;)<br \/>\n        return<\/p>\n<p>    # \u521b\u5efa\u663e\u793a\u7a97\u53e3&#xff08;WINDOW_NORMAL\u652f\u6301\u7a97\u53e3\u5927\u5c0f\u8c03\u6574&#xff09;<br \/>\n    cv2.namedWindow(&#039;Camera Feed&#039;, cv2.WINDOW_NORMAL)  # \u539f\u59cb\u753b\u9762\u7a97\u53e3<br \/>\n    cv2.namedWindow(&#039;Denoised&#039;, cv2.WINDOW_NORMAL)     # \u964d\u566a\u540e\u7a97\u53e3<br \/>\n    cv2.namedWindow(&#039;Binary&#039;, cv2.WINDOW_NORMAL)       # \u4e8c\u503c\u5316\u7a97\u53e3 <\/p>\n<ul>\n<li>\n<p>cv2.VideoCapture(camera_id)&#xff1a;\u521b\u5efa\u89c6\u9891\u6355\u83b7\u5bf9\u8c61&#xff0c;\u53c2\u6570\u4e3a\u6444\u50cf\u5934\u8bbe\u5907ID&#xff0c;\u82e5\u8c03\u7528\u5931\u8d25\u9700\u68c0\u67e5\u6444\u50cf\u5934\u662f\u5426\u88ab\u5360\u7528\u6216ID\u662f\u5426\u6b63\u786e&#xff1b;<\/p>\n<\/li>\n<li>\n<p>cap.isOpened()&#xff1a;\u6821\u9a8c\u6444\u50cf\u5934\u662f\u5426\u6210\u529f\u6253\u5f00&#xff0c;\u662f\u907f\u514d\u7a0b\u5e8f\u5d29\u6e83\u7684\u5173\u952e\u5224\u65ad&#xff1b;<\/p>\n<\/li>\n<li>\n<p>cv2.namedWindow()&#xff1a;\u521b\u5efa\u663e\u793a\u7a97\u53e3&#xff0c;cv2.WINDOW_NORMAL\u53c2\u6570\u5141\u8bb8\u624b\u52a8\u8c03\u6574\u7a97\u53e3\u5927\u5c0f&#xff08;\u9ed8\u8ba4WINDOW_AUTOSIZE\u4e3a\u56fa\u5b9a\u5927\u5c0f&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"3.2%20%E6%9B%9D%E5%85%89%E5%8F%82%E6%95%B0%E5%8A%A8%E6%80%81%E8%B0%83%E8%8A%82%EF%BC%9A%E6%BB%91%E5%8A%A8%E6%9D%A1%E7%BB%91%E5%AE%9A\">3.2 \u66dd\u5149\u53c2\u6570\u52a8\u6001\u8c03\u8282&#xff1a;\u6ed1\u52a8\u6761\u7ed1\u5b9a<\/h4>\n<p>    # \u521d\u59cb\u66dd\u5149\u503c&#xff08;\u4e0d\u540c\u6444\u50cf\u5934\u53d6\u503c\u8303\u56f4\u4e0d\u540c&#xff0c;\u9700\u81ea\u884c\u6d4b\u8bd5&#xff09;<br \/>\n    initial_exposure_value &#061; -6<br \/>\n    cap.set(cv2.CAP_PROP_EXPOSURE, initial_exposure_value)<\/p>\n<p>    # \u5b9a\u4e49\u66dd\u5149\u8c03\u6574\u56de\u8c03\u51fd\u6570<br \/>\n    def on_exposure_change(value):<br \/>\n        # \u6ed1\u52a8\u6761\u53d6\u503c\u8303\u56f4\u662f0-20&#xff0c;\u8f6c\u6362\u4e3a\u5b9e\u9645\u66dd\u5149\u503c&#xff08;-10 ~ 10&#xff09;<br \/>\n        cap.set(cv2.CAP_PROP_EXPOSURE, value &#8211; 10)<\/p>\n<p>    # \u521b\u5efa\u66dd\u5149\u8c03\u8282\u6ed1\u52a8\u6761&#xff1a;\u53c2\u6570&#xff08;\u6ed1\u52a8\u6761\u540d&#xff0c;\u7ed1\u5b9a\u7a97\u53e3&#xff0c;\u521d\u59cb\u503c&#xff0c;\u6700\u5927\u503c&#xff0c;\u56de\u8c03\u51fd\u6570&#xff09;<br \/>\n    cv2.createTrackbar(&#039;Exposure&#039;, &#039;Camera Feed&#039;, 10, 20, on_exposure_change)<br \/>\n    # \u8bbe\u7f6e\u6ed1\u52a8\u6761\u521d\u59cb\u4f4d\u7f6e&#xff08;\u5bf9\u5e94\u521d\u59cb\u66dd\u5149\u503c&#xff09;<br \/>\n    cv2.setTrackbarPos(&#039;Exposure&#039;, &#039;Camera Feed&#039;, initial_exposure_value &#043; 10) <\/p>\n<p>\u6838\u5fc3\u77e5\u8bc6\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>cv2.CAP_PROP_EXPOSURE&#xff1a;\u6444\u50cf\u5934\u66dd\u5149\u5c5e\u6027\u5e38\u91cf&#xff0c;\u4e0d\u540c\u8bbe\u5907\u7684\u66dd\u5149\u503c\u8303\u56f4\u4e0d\u540c&#xff08;\u901a\u5e38\u4e3a\u8d1f\u6570&#xff0c;\u503c\u8d8a\u5c0f\u66dd\u5149\u8d8a\u4f4e&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>cv2.createTrackbar()&#xff1a;\u521b\u5efa\u6ed1\u52a8\u6761&#xff0c;\u9700\u7ed1\u5b9a\u5230\u6307\u5b9a\u7a97\u53e3&#xff0c;\u6ed1\u52a8\u65f6\u89e6\u53d1\u56de\u8c03\u51fd\u6570&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u56de\u8c03\u51fd\u6570on_exposure_change&#xff1a;\u6ed1\u52a8\u6761\u7684\u53d6\u503c\u4f1a\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165&#xff0c;\u6b64\u5904\u901a\u8fc7value &#8211; 10\u5c06\u6ed1\u52a8\u6761\u76840-20\u8303\u56f4\u8f6c\u6362\u4e3a\u5b9e\u9645\u66dd\u5149\u503c\u7684-10~10\u8303\u56f4&#xff0c;\u9002\u914d\u6444\u50cf\u5934\u66dd\u5149\u53c2\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"3.3%20%E9%99%8D%E5%99%AA%E5%8F%82%E6%95%B0%E5%8A%A8%E6%80%81%E8%B0%83%E8%8A%82%EF%BC%9A%E5%8F%8C%E8%BE%B9%E6%BB%A4%E6%B3%A2%E6%BB%91%E5%8A%A8%E6%9D%A1\">3.3 \u964d\u566a\u53c2\u6570\u52a8\u6001\u8c03\u8282&#xff1a;\u53cc\u8fb9\u6ee4\u6ce2\u6ed1\u52a8\u6761<\/h4>\n<p>    # \u5b9a\u4e49\u964d\u566a\u53c2\u6570\u56de\u8c03\u51fd\u6570<br \/>\n    def on_denoise_change(value):<br \/>\n        nonlocal denoise_value  # \u58f0\u660e\u4f7f\u7528\u5916\u90e8\u7684denoise_value\u53d8\u91cf<br \/>\n        denoise_value &#061; value<\/p>\n<p>    # \u521d\u59cb\u964d\u566a\u53c2\u6570<br \/>\n    denoise_value &#061; 10<br \/>\n    # \u521b\u5efa\u964d\u566a\u8c03\u8282\u6ed1\u52a8\u6761<br \/>\n    cv2.createTrackbar(&#039;Denoise&#039;, &#039;Denoised&#039;, 10, 100, on_denoise_change)<br \/>\n    cv2.setTrackbarPos(&#039;Denoise&#039;, &#039;Denoised&#039;, denoise_value) <\/p>\n<ul>\n<li>\n<p>nonlocal\u5173\u952e\u5b57&#xff1a;\u7528\u4e8e\u5728\u5d4c\u5957\u51fd\u6570\u4e2d\u4fee\u6539\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf&#xff08;\u82e5\u7528global\u5219\u662f\u4fee\u6539\u5168\u5c40\u53d8\u91cf&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6ed1\u52a8\u6761\u6700\u5927\u503c\u8bbe\u4e3a100&#xff1a;\u53cc\u8fb9\u6ee4\u6ce2\u7684\u6838\u5927\u5c0f\u53c2\u6570\u4e0d\u5b9c\u8fc7\u5927&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u753b\u9762\u6a21\u7cca\u8fc7\u5ea6\u4e14\u5904\u7406\u901f\u5ea6\u53d8\u6162\u3002<\/p>\n<\/li>\n<\/ul>\n<h4 id=\"3.4%20%E8%A7%86%E9%A2%91%E6%B5%81%E5%BE%AA%E7%8E%AF%E5%A4%84%E7%90%86%EF%BC%9A%E6%A0%B8%E5%BF%83%E9%80%BB%E8%BE%91\">3.4 \u89c6\u9891\u6d41\u5faa\u73af\u5904\u7406&#xff1a;\u6838\u5fc3\u903b\u8f91<\/h4>\n<p>    try:<br \/>\n        while True:<br \/>\n            # \u8bfb\u53d6\u4e00\u5e27\u56fe\u50cf&#xff1a;ret\u4e3a\u662f\u5426\u8bfb\u53d6\u6210\u529f&#xff0c;frame\u4e3a\u5e27\u6570\u636e&#xff08;BGR\u683c\u5f0f&#xff09;<br \/>\n            ret, frame &#061; cap.read()<br \/>\n            if not ret:<br \/>\n                print(&#034;Failed to grab frame&#034;)<br \/>\n                break<\/p>\n<p>            # \u663e\u793a\u539f\u59cb\u753b\u9762<br \/>\n            cv2.imshow(&#039;Camera Feed&#039;, frame)<\/p>\n<p>            # \u53cc\u8fb9\u6ee4\u6ce2\u964d\u566a&#xff1a;\u53c2\u6570&#xff08;\u56fe\u50cf&#xff0c;\u6838\u5927\u5c0f&#xff0c;\u989c\u8272\u7a7a\u95f4\u6807\u51c6\u5dee&#xff0c;\u50cf\u7d20\u7a7a\u95f4\u6807\u51c6\u5dee&#xff09;<br \/>\n            denoised &#061; cv2.bilateralFilter(frame, denoise_value, 75, 75)<br \/>\n            # \u663e\u793a\u964d\u566a\u540e\u753b\u9762<br \/>\n            cv2.imshow(&#039;Denoised&#039;, denoised)<\/p>\n<p>            # \u7070\u5ea6\u8f6c\u6362&#xff1a;BGR&#xff08;OpenCV\u9ed8\u8ba4&#xff09;\u8f6cGRAY<br \/>\n            gray &#061; cv2.cvtColor(denoised, cv2.COLOR_BGR2GRAY)<\/p>\n<p>            # \u4e8c\u503c\u5316\u5904\u7406&#xff1a;\u53c2\u6570&#xff08;\u7070\u5ea6\u56fe&#xff0c;\u9608\u503c&#xff0c;\u6700\u5927\u503c&#xff0c;\u4e8c\u503c\u5316\u65b9\u5f0f&#xff09;<br \/>\n            _, binary &#061; cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)<br \/>\n            # \u663e\u793a\u4e8c\u503c\u5316\u753b\u9762<br \/>\n            cv2.imshow(&#039;Binary&#039;, binary)<\/p>\n<p>            # \u6309\u952e\u68c0\u6d4b&#xff1a;\u6bcf1ms\u68c0\u6d4b\u4e00\u6b21&#xff0c;\u6309\u4e0bq\u952e\u9000\u51fa<br \/>\n            key &#061; cv2.waitKey(1) &amp; 0xFF<br \/>\n            if key &#061;&#061; ord(&#039;q&#039;):<br \/>\n                break <\/p>\n<p>\u6838\u5fc3API\u89e3\u6790&#xff1a;<\/p>\n<li>\n<p>cap.read()&#xff1a;\u9010\u5e27\u8bfb\u53d6\u89c6\u9891\u6d41&#xff0c;\u8fd4\u56de\u503cret\u4e3a\u5e03\u5c14\u578b&#xff08;\u662f\u5426\u8bfb\u53d6\u6210\u529f&#xff09;&#xff0c;frame\u4e3a\u5f53\u524d\u5e27\u7684\u56fe\u50cf\u6570\u636e&#xff08;OpenCV\u9ed8\u8ba4BGR\u989c\u8272\u7a7a\u95f4&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>cv2.bilateralFilter()&#xff1a;\u53cc\u8fb9\u6ee4\u6ce2&#xff0c;\u76f8\u6bd4\u5747\u503c\u6ee4\u6ce2\u3001\u9ad8\u65af\u6ee4\u6ce2&#xff0c;\u80fd\u5728\u964d\u566a\u7684\u540c\u65f6\u4fdd\u7559\u56fe\u50cf\u8fb9\u7f18\u7ec6\u8282&#xff0c;\u53c2\u6570\u8bf4\u660e&#xff1a;<\/p>\n<li>\n<p>\u7b2c1\u4e2a\u53c2\u6570&#xff1a;\u8f93\u5165\u56fe\u50cf&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7b2c2\u4e2a\u53c2\u6570&#xff1a;\u6ee4\u6ce2\u6838\u5927\u5c0f&#xff08;\u9700\u4e3a\u5947\u6570&#xff0c;\u503c\u8d8a\u5927\u964d\u566a\u6548\u679c\u8d8a\u5f3a&#xff0c;\u4f46\u5904\u7406\u901f\u5ea6\u8d8a\u6162&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7b2c3\u4e2a\u53c2\u6570&#xff1a;\u989c\u8272\u7a7a\u95f4\u6807\u51c6\u5dee&#xff08;\u503c\u8d8a\u5927&#xff0c;\u5141\u8bb8\u66f4\u591a\u989c\u8272\u5dee\u5f02\u7684\u50cf\u7d20\u53c2\u4e0e\u6ee4\u6ce2&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7b2c4\u4e2a\u53c2\u6570&#xff1a;\u50cf\u7d20\u7a7a\u95f4\u6807\u51c6\u5dee&#xff08;\u503c\u8d8a\u5927&#xff0c;\u6ee4\u6ce2\u8303\u56f4\u8d8a\u5927&#xff09;&#xff1b;<\/p>\n<\/li>\n<\/li>\n<li>\n<p>cv2.cvtColor()&#xff1a;\u989c\u8272\u7a7a\u95f4\u8f6c\u6362&#xff0c;COLOR_BGR2GRAY\u5c06BGR\u5f69\u8272\u56fe\u8f6c\u4e3a\u7070\u5ea6\u56fe&#xff1b;<\/p>\n<\/li>\n<li>\n<p>cv2.threshold()&#xff1a;\u56fa\u5b9a\u9608\u503c\u4e8c\u503c\u5316&#xff0c;127\u4e3a\u9608\u503c&#xff0c;255\u4e3a\u6700\u5927\u503c&#xff0c;THRESH_BINARY\u8868\u793a&#xff1a;<\/p>\n<li>\n<p>\u50cf\u7d20\u503c &gt; 127 \u2192 255&#xff08;\u767d\u8272&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u50cf\u7d20\u503c \u2264 127 \u2192 0&#xff08;\u9ed1\u8272&#xff09;&#xff1b;<\/p>\n<\/li>\n<\/li>\n<li>\n<p>cv2.waitKey(1)&#xff1a;\u6309\u952e\u68c0\u6d4b&#xff0c;\u53c2\u6570\u4e3a\u7b49\u5f85\u65f6\u95f4&#xff08;ms&#xff09;&#xff0c;\u8fd4\u56de\u6309\u952e\u7684ASCII\u7801&#xff0c;&amp; 0xFF\u7528\u4e8e\u517c\u5bb9\u4e0d\u540c\u5e73\u53f0\u7684\u6309\u952e\u503c\u3002<\/p>\n<\/li>\n<h4 id=\"3.5%20%E8%B5%84%E6%BA%90%E9%87%8A%E6%94%BE%EF%BC%9A%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E4%B8%8E%E6%94%B6%E5%B0%BE\">3.5 \u8d44\u6e90\u91ca\u653e&#xff1a;\u5f02\u5e38\u5904\u7406\u4e0e\u6536\u5c3e<\/h4>\n<p>    finally:<br \/>\n        # \u91ca\u653e\u6444\u50cf\u5934\u8d44\u6e90<br \/>\n        cap.release()<br \/>\n        # \u5173\u95ed\u6240\u6709\u521b\u5efa\u7684\u7a97\u53e3<br \/>\n        cv2.destroyAllWindows()<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    main() <\/p>\n<ul>\n<li>\n<p>finally\u4ee3\u7801\u5757&#xff1a;\u65e0\u8bba\u5faa\u73af\u6b63\u5e38\u9000\u51fa\u8fd8\u662f\u5f02\u5e38\u4e2d\u65ad&#xff0c;\u90fd\u4f1a\u6267\u884c\u8d44\u6e90\u91ca\u653e&#xff0c;\u907f\u514d\u6444\u50cf\u5934\u88ab\u5360\u7528&#xff1b;<\/p>\n<\/li>\n<li>\n<p>cap.release()&#xff1a;\u91ca\u653eVideoCapture\u5bf9\u8c61&#xff0c;\u5fc5\u987b\u8c03\u7528&#xff0c;\u5426\u5219\u540e\u7eed\u65e0\u6cd5\u518d\u6b21\u8c03\u7528\u6444\u50cf\u5934&#xff1b;<\/p>\n<\/li>\n<li>\n<p>cv2.destroyAllWindows()&#xff1a;\u5173\u95ed\u6240\u6709OpenCV\u521b\u5efa\u7684\u7a97\u53e3&#xff0c;\u6e05\u7406\u5185\u5b58\u3002<\/p>\n<\/li>\n<\/ul>\n<h3 id=\"%E5%9B%9B%E3%80%81%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C%E4%B8%8E%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98\">\u56db\u3001\u8fd0\u884c\u6548\u679c\u4e0e\u5e38\u89c1\u95ee\u9898<\/h3>\n<h4 id=\"4.1%20%E8%BF%90%E8%A1%8C%E6%95%88%E6%9E%9C\">4.1 \u8fd0\u884c\u6548\u679c<\/h4>\n<p>\u542f\u52a8\u7a0b\u5e8f\u540e&#xff0c;\u4f1a\u5f39\u51fa3\u4e2a\u7a97\u53e3&#xff1a;<\/p>\n<ul>\n<li>\n<p>Camera Feed&#xff1a;\u539f\u59cb\u6444\u50cf\u5934\u753b\u9762&#xff0c;\u5e26\u6709\u66dd\u5149\u8c03\u8282\u6ed1\u52a8\u6761&#xff1b;<\/p>\n<\/li>\n<li>\n<p>Denoised&#xff1a;\u964d\u566a\u540e\u7684\u753b\u9762&#xff0c;\u5e26\u6709\u964d\u566a\u53c2\u6570\u6ed1\u52a8\u6761&#xff1b;<\/p>\n<\/li>\n<li>\n<p>Binary&#xff1a;\u4e8c\u503c\u5316\u540e\u7684\u9ed1\u767d\u753b\u9762\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u62d6\u52a8\u6ed1\u52a8\u6761\u53ef\u5b9e\u65f6\u8c03\u6574\u66dd\u5149\u548c\u964d\u566a\u6548\u679c&#xff0c;\u6309\u4e0bq\u952e\u9000\u51fa\u7a0b\u5e8f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"762\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100915-697c834b660d3.png\" width=\"942\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"762\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100915-697c834bcdae1.png\" width=\"960\" \/><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"468\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100916-697c834c1206b.png\" width=\"450\" \/><\/p>\n<h4 id=\"4.2%20%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3\">4.2 \u5e38\u89c1\u95ee\u9898\u89e3\u51b3<\/h4>\n<li>\n<p>\u6444\u50cf\u5934\u65e0\u6cd5\u6253\u5f00&#xff1a;<\/p>\n<li>\n<p>\u68c0\u67e5\u6444\u50cf\u5934\u662f\u5426\u88ab\u5176\u4ed6\u7a0b\u5e8f\u5360\u7528&#xff08;\u5982\u5fae\u4fe1\u3001Zoom&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u8c03\u6574camera_id\u4e3a1\u62162&#xff0c;\u5c1d\u8bd5\u5916\u63a5\u6444\u50cf\u5934&#xff1b;<\/p>\n<\/li>\n<li>\n<p>Linux\/macOS\u9700\u8d4b\u4e88\u6444\u50cf\u5934\u6743\u9650&#xff1a;sudo chmod 777 \/dev\/video0\u3002<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u66dd\u5149\u8c03\u8282\u65e0\u6548\u679c&#xff1a;<\/p>\n<li>\n<p>\u90e8\u5206\u7b14\u8bb0\u672c\u6444\u50cf\u5934\u4e0d\u652f\u6301\u624b\u52a8\u8c03\u8282\u66dd\u5149&#xff0c;\u9700\u66f4\u6362\u6444\u50cf\u5934&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u8c03\u6574\u6ed1\u52a8\u6761\u7684\u53d6\u503c\u8303\u56f4&#xff08;\u5982\u5c0620\u6539\u4e3a30&#xff09;&#xff0c;\u9002\u914d\u4e0d\u540c\u6444\u50cf\u5934\u7684\u66dd\u5149\u53c2\u6570\u8303\u56f4\u3002<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u753b\u9762\u5361\u987f&#xff1a;<\/p>\n<li>\n<p>\u964d\u4f4e\u53cc\u8fb9\u6ee4\u6ce2\u7684\u6838\u5927\u5c0f&#xff08;\u51cf\u5c0fdenoise_value\u7684\u6700\u5927\u503c&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5173\u95ed\u5176\u4ed6\u5360\u7528CPU\/GPU\u7684\u7a0b\u5e8f&#xff0c;\u51cf\u5c11\u8d44\u6e90\u6d88\u8017\u3002<\/p>\n<\/li>\n<\/li>\n<h3 id=\"%E4%BA%94%E3%80%81%E6%89%A9%E5%B1%95%E4%B8%8E%E4%BC%98%E5%8C%96%E6%96%B9%E5%90%91\">\u4e94\u3001\u6269\u5c55\u4e0e\u4f18\u5316\u65b9\u5411<\/h3>\n<li>\n<p>\u81ea\u9002\u5e94\u9608\u503c\u4e8c\u503c\u5316&#xff1a;\u66ff\u6362\u56fa\u5b9a\u9608\u503c\u4e3acv2.adaptiveThreshold()&#xff0c;\u9002\u914d\u4e0d\u540c\u5149\u7167\u73af\u5883&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5e27\u7387\u663e\u793a&#xff1a;\u6dfb\u52a0\u5e27\u7387\u8ba1\u7b97\u903b\u8f91&#xff0c;\u5728\u753b\u9762\u4e0a\u663e\u793a\u5b9e\u65f6FPS&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u56fe\u50cf\u4fdd\u5b58&#xff1a;\u6dfb\u52a0\u6309\u952e\u89e6\u53d1\u529f\u80fd&#xff0c;\u4fdd\u5b58\u5f53\u524d\u5e27\u7684\u539f\u59cb\/\u964d\u566a\/\u4e8c\u503c\u5316\u56fe\u50cf&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u8272\u5f69\u7a7a\u95f4\u5207\u6362&#xff1a;\u589e\u52a0HSV\u3001YCrCb\u7b49\u8272\u5f69\u7a7a\u95f4\u7684\u8f6c\u6362\u548c\u663e\u793a&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u65f6\u8fb9\u7f18\u68c0\u6d4b&#xff1a;\u5728\u4e8c\u503c\u5316\u57fa\u7840\u4e0a\u6dfb\u52a0Canny\u8fb9\u7f18\u68c0\u6d4b&#xff0c;\u589e\u5f3a\u7279\u5f81\u63d0\u53d6\u80fd\u529b\u3002<\/p>\n<\/li>\n<h3 id=\"%E5%85%AD%E3%80%81%E6%80%BB%E7%BB%93\">\u516d\u3001\u603b\u7ed3<\/h3>\n<p>\u672c\u6587\u901a\u8fc7\u4e00\u4e2a\u5b8c\u6574\u7684OpenCV\u6444\u50cf\u5934\u5904\u7406demo&#xff0c;\u8bb2\u89e3\u4e86\u89c6\u9891\u6d41\u8bfb\u53d6\u3001\u53c2\u6570\u52a8\u6001\u8c03\u8282\u3001\u56fe\u50cf\u6ee4\u6ce2\u3001\u989c\u8272\u7a7a\u95f4\u8f6c\u6362\u548c\u4e8c\u503c\u5316\u7b49\u6838\u5fc3\u77e5\u8bc6\u70b9\u3002\u5173\u952e\u8981\u70b9&#xff1a;<\/p>\n<li>\n<p>OpenCV\u5904\u7406\u6444\u50cf\u5934\u89c6\u9891\u6d41\u7684\u6838\u5fc3\u6d41\u7a0b\u662f\u300c\u6253\u5f00\u6444\u50cf\u5934\u2192\u9010\u5e27\u8bfb\u53d6\u2192\u5904\u7406\u2192\u663e\u793a\u2192\u91ca\u653e\u8d44\u6e90\u300d&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6ed1\u52a8\u6761\u7ed3\u5408\u56de\u8c03\u51fd\u6570\u53ef\u5b9e\u73b0\u53c2\u6570\u52a8\u6001\u8c03\u8282&#xff0c;\u63d0\u5347\u4ea4\u4e92\u6027&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u53cc\u8fb9\u6ee4\u6ce2\u662f\u517c\u987e\u964d\u566a\u548c\u8fb9\u7f18\u4fdd\u7559\u7684\u4f18\u8d28\u6ee4\u6ce2\u7b97\u6cd5&#xff0c;\u9002\u5408\u5b9e\u65f6\u89c6\u9891\u5904\u7406&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u4e8c\u503c\u5316\u662f\u56fe\u50cf\u5206\u5272\u548c\u7279\u5f81\u63d0\u53d6\u7684\u57fa\u7840&#xff0c;\u9700\u6839\u636e\u573a\u666f\u9009\u62e9\u56fa\u5b9a\u9608\u503c\u6216\u81ea\u9002\u5e94\u9608\u503c\u3002<\/p>\n<\/li>\n<p>\u901a\u8fc7\u672c\u6848\u4f8b\u7684\u5b66\u4e60&#xff0c;\u53ef\u638c\u63e1OpenCV\u5b9e\u65f6\u89c6\u9891\u5904\u7406\u7684\u57fa\u672c\u6846\u67b6&#xff0c;\u4e3a\u540e\u7eed\u7684\u4eba\u8138\u68c0\u6d4b\u3001\u7269\u4f53\u8ddf\u8e2a\u7b49\u9ad8\u7ea7\u5e94\u7528\u6253\u4e0b\u57fa\u7840\u3002<\/p>\n<h3 id=\"%E9%99%84%EF%BC%9A%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81\">\u9644&#xff1a;\u5b8c\u6574\u4ee3\u7801<\/h3>\n<p>import cv2<\/p>\n<p>def main():<br \/>\n    # \u6444\u50cf\u5934\u8bbe\u5907\u7f16\u53f7&#xff0c;\u901a\u5e38\u662f0\u62161<br \/>\n    camera_id &#061; 0<br \/>\n    # \u521b\u5efaVideoCapture\u5bf9\u8c61<br \/>\n    cap &#061; cv2.VideoCapture(camera_id)<\/p>\n<p>    # \u68c0\u67e5\u662f\u5426\u6210\u529f\u6253\u5f00\u6444\u50cf\u5934<br \/>\n    if not cap.isOpened():<br \/>\n        print(&#034;Error: Could not open camera.&#034;)<br \/>\n        return<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u7a97\u53e3\u6765\u663e\u793a\u89c6\u9891\u6d41<br \/>\n    cv2.namedWindow(&#039;Camera Feed&#039;, cv2.WINDOW_NORMAL)<br \/>\n    cv2.namedWindow(&#039;Denoised&#039;, cv2.WINDOW_NORMAL)<br \/>\n    cv2.namedWindow(&#039;Binary&#039;, cv2.WINDOW_NORMAL)<\/p>\n<p>    # \u521d\u59cb\u66dd\u5149\u503c<br \/>\n    initial_exposure_value &#061; -6<br \/>\n    cap.set(cv2.CAP_PROP_EXPOSURE, initial_exposure_value)<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u6ed1\u52a8\u6761<br \/>\n    def on_exposure_change(value):<br \/>\n        # \u66f4\u65b0\u66dd\u5149\u503c<br \/>\n        cap.set(cv2.CAP_PROP_EXPOSURE, value &#8211; 10)<\/p>\n<p>    # \u521b\u5efa\u6ed1\u52a8\u6761&#xff0c;\u521d\u59cb\u4f4d\u7f6e\u8bbe\u4e3a\u4e2d\u95f4\u503c<br \/>\n    cv2.createTrackbar(&#039;Exposure&#039;, &#039;Camera Feed&#039;, 10, 20, on_exposure_change)<br \/>\n    cv2.setTrackbarPos(&#039;Exposure&#039;, &#039;Camera Feed&#039;, initial_exposure_value &#043; 10)<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u6ed1\u52a8\u6761\u6765\u8c03\u6574\u53cc\u8fb9\u6ee4\u6ce2\u7684\u53c2\u6570<br \/>\n    def on_denoise_change(value):<br \/>\n        nonlocal denoise_value<br \/>\n        denoise_value &#061; value<\/p>\n<p>    denoise_value &#061; 10<br \/>\n    cv2.createTrackbar(&#039;Denoise&#039;, &#039;Denoised&#039;, 10, 100, on_denoise_change)<br \/>\n    cv2.setTrackbarPos(&#039;Denoise&#039;, &#039;Denoised&#039;, denoise_value)<\/p>\n<p>    try:<br \/>\n        while True:<br \/>\n            # \u8bfb\u53d6\u4e00\u5e27\u56fe\u50cf<br \/>\n            ret, frame &#061; cap.read()<br \/>\n            if not ret:<br \/>\n                print(&#034;Failed to grab frame&#034;)<br \/>\n                break<\/p>\n<p>            # \u663e\u793a\u539f\u59cb\u56fe\u50cf<br \/>\n            cv2.imshow(&#039;Camera Feed&#039;, frame)<\/p>\n<p>            # \u5e94\u7528\u53cc\u8fb9\u6ee4\u6ce2\u8fdb\u884c\u964d\u566a&#xff08;\u6838\u5927\u5c0f\u9700\u4e3a\u5947\u6570&#xff0c;\u907f\u514d\u62a5\u9519&#xff09;<br \/>\n            denoise_ksize &#061; denoise_value if denoise_value % 2 &#061;&#061; 1 else denoise_value &#043; 1<br \/>\n            denoise_ksize &#061; max(1, denoise_ksize)  # \u786e\u4fdd\u6838\u5927\u5c0f\u81f3\u5c11\u4e3a1<br \/>\n            denoised &#061; cv2.bilateralFilter(frame, denoise_ksize, 75, 75)<\/p>\n<p>            # \u663e\u793a\u964d\u566a\u540e\u7684\u56fe\u50cf<br \/>\n            cv2.imshow(&#039;Denoised&#039;, denoised)<\/p>\n<p>            # \u5c06\u56fe\u50cf\u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\u50cf<br \/>\n            gray &#061; cv2.cvtColor(denoised, cv2.COLOR_BGR2GRAY)<\/p>\n<p>            # \u5e94\u7528\u9608\u503c\u5904\u7406&#xff0c;\u5f97\u5230\u4e8c\u503c\u56fe\u50cf<br \/>\n            _, binary &#061; cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)<\/p>\n<p>            # \u663e\u793a\u4e8c\u503c\u56fe\u50cf<br \/>\n            cv2.imshow(&#039;Binary&#039;, binary)<\/p>\n<p>            # \u83b7\u53d6\u6309\u952e\u8f93\u5165<br \/>\n            key &#061; cv2.waitKey(1) &amp; 0xFF<\/p>\n<p>            # \u6309\u4e0b &#039;q&#039; \u952e\u9000\u51fa\u5faa\u73af<br \/>\n            if key &#061;&#061; ord(&#039;q&#039;):<br \/>\n                break<\/p>\n<p>    finally:<br \/>\n        # \u5728\u6700\u540e\u91ca\u653e\u8d44\u6e90\u548c\u5173\u95ed\u7a97\u53e3<br \/>\n        cap.release()<br \/>\n        cv2.destroyAllWindows()<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    main() <\/p>\n<h4 id=\"%E8%A1%A5%E5%85%85%E8%AF%B4%E6%98%8E\">\u8865\u5145\u8bf4\u660e<\/h4>\n<p>\u4f18\u5316\u540e\u7684\u4ee3\u7801\u4fee\u590d\u4e86\u53cc\u8fb9\u6ee4\u6ce2\u6838\u5927\u5c0f\u4e3a\u5076\u6570\u65f6\u7684\u62a5\u9519\u95ee\u9898&#xff0c;\u589e\u52a0\u4e86\u53c2\u6570\u5408\u6cd5\u6027\u6821\u9a8c&#xff0c;\u63d0\u5347\u4e86\u7a0b\u5e8f\u7684\u5065\u58ee\u6027\u3002\u5728CSDN\u53d1\u5e03\u65f6&#xff0c;\u53ef\u642d\u914d\u8fd0\u884c\u6548\u679c\u622a\u56fe&#xff08;\u59823\u4e2a\u7a97\u53e3\u7684\u5b9e\u9645\u663e\u793a\u6548\u679c&#xff09;&#xff0c;\u5e76\u5728\u8bc4\u8bba\u533a\u4e0e\u8bfb\u8005\u4e92\u52a8\u89e3\u7b54\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00<br \/>\n\u5728\u8ba1\u7b97\u673a\u89c6\u89c9\u5b66\u4e60\u8fc7\u7a0b\u4e2d&#xff0c;\u5b9e\u65f6\u6444\u50cf\u5934\u89c6\u9891\u6d41\u5904\u7406\u662f\u6700\u57fa\u7840\u4e5f\u6700\u6838\u5fc3\u7684\u5e94\u7528\u573a\u666f\u4e4b\u4e00\u3002\u672c\u6587\u57fa\u4e8eOpenCV-Python\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u6444\u50cf\u5934\u5b9e\u65f6\u5904\u7406demo&#xff0c;\u6db5\u76d6\u66dd\u5149\u53c2\u6570\u52a8\u6001\u8c03\u8282\u3001\u53cc\u8fb9\u6ee4\u6ce2\u964d\u566a\u3001\u7070\u5ea6\u8f6c\u6362\u4e0e\u4e8c\u503c\u5316\u7b49\u6838\u5fc3\u529f\u80fd&#xff0c;\u9002\u5408OpenCV\u5165\u95e8\u5b66\u4e60\u8005\u7406\u89e3\u89c6\u9891\u6d41\u5904\u7406\u7684\u57fa\u672c\u6d41\u7a0b\u548c\u5173\u952eAPI\u7528\u6cd5&#xff0c;\u4e5f\u662f\u535a\u4e3b\u51c6\u5907\u7535\u8d5b\u65f6\u8ba4\u4e3a\u975e\u5e38\u597d\u7528\u7684\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\u3002<br \/>\n\u76ee\u5f55<br \/>\n\u524d\u8a00<br \/>\n\u4e00\u3001\u529f\u80fd\u6574\u4f53\u8bf4\u660e<br \/>\n\u4e8c\u3001\u73af\u5883\u51c6\u5907<br \/>\n\u4e09\u3001\u4ee3\u7801\u9010\u884c\u89e3\u6790<br \/>\n3.1 \u57fa\u7840<\/p>\n","protected":false},"author":2,"featured_media":68777,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1460,50,523],"topic":[],"class_list":["post-68783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-opencv","tag-50","tag-523"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/68783.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00 \u5728\u8ba1\u7b97\u673a\u89c6\u89c9\u5b66\u4e60\u8fc7\u7a0b\u4e2d&#xff0c;\u5b9e\u65f6\u6444\u50cf\u5934\u89c6\u9891\u6d41\u5904\u7406\u662f\u6700\u57fa\u7840\u4e5f\u6700\u6838\u5fc3\u7684\u5e94\u7528\u573a\u666f\u4e4b\u4e00\u3002\u672c\u6587\u57fa\u4e8eOpenCV-Python\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u6444\u50cf\u5934\u5b9e\u65f6\u5904\u7406demo&#xff0c;\u6db5\u76d6\u66dd\u5149\u53c2\u6570\u52a8\u6001\u8c03\u8282\u3001\u53cc\u8fb9\u6ee4\u6ce2\u964d\u566a\u3001\u7070\u5ea6\u8f6c\u6362\u4e0e\u4e8c\u503c\u5316\u7b49\u6838\u5fc3\u529f\u80fd&#xff0c;\u9002\u5408OpenCV\u5165\u95e8\u5b66\u4e60\u8005\u7406\u89e3\u89c6\u9891\u6d41\u5904\u7406\u7684\u57fa\u672c\u6d41\u7a0b\u548c\u5173\u952eAPI\u7528\u6cd5&#xff0c;\u4e5f\u662f\u535a\u4e3b\u51c6\u5907\u7535\u8d5b\u65f6\u8ba4\u4e3a\u975e\u5e38\u597d\u7528\u7684\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\u3002 \u76ee\u5f55 \u524d\u8a00 \u4e00\u3001\u529f\u80fd\u6574\u4f53\u8bf4\u660e \u4e8c\u3001\u73af\u5883\u51c6\u5907 \u4e09\u3001\u4ee3\u7801\u9010\u884c\u89e3\u6790 3.1 \u57fa\u7840\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/68783.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-30T10:09:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100914-697c834ac9b2c.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/68783.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/68783.html\",\"name\":\"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-30T10:09:17+00:00\",\"dateModified\":\"2026-01-30T10:09:17+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/68783.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/68783.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/68783.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/68783.html","og_locale":"zh_CN","og_type":"article","og_title":"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00 \u5728\u8ba1\u7b97\u673a\u89c6\u89c9\u5b66\u4e60\u8fc7\u7a0b\u4e2d&#xff0c;\u5b9e\u65f6\u6444\u50cf\u5934\u89c6\u9891\u6d41\u5904\u7406\u662f\u6700\u57fa\u7840\u4e5f\u6700\u6838\u5fc3\u7684\u5e94\u7528\u573a\u666f\u4e4b\u4e00\u3002\u672c\u6587\u57fa\u4e8eOpenCV-Python\u5b9e\u73b0\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u6444\u50cf\u5934\u5b9e\u65f6\u5904\u7406demo&#xff0c;\u6db5\u76d6\u66dd\u5149\u53c2\u6570\u52a8\u6001\u8c03\u8282\u3001\u53cc\u8fb9\u6ee4\u6ce2\u964d\u566a\u3001\u7070\u5ea6\u8f6c\u6362\u4e0e\u4e8c\u503c\u5316\u7b49\u6838\u5fc3\u529f\u80fd&#xff0c;\u9002\u5408OpenCV\u5165\u95e8\u5b66\u4e60\u8005\u7406\u89e3\u89c6\u9891\u6d41\u5904\u7406\u7684\u57fa\u672c\u6d41\u7a0b\u548c\u5173\u952eAPI\u7528\u6cd5&#xff0c;\u4e5f\u662f\u535a\u4e3b\u51c6\u5907\u7535\u8d5b\u65f6\u8ba4\u4e3a\u975e\u5e38\u597d\u7528\u7684\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\u3002 \u76ee\u5f55 \u524d\u8a00 \u4e00\u3001\u529f\u80fd\u6574\u4f53\u8bf4\u660e \u4e8c\u3001\u73af\u5883\u51c6\u5907 \u4e09\u3001\u4ee3\u7801\u9010\u884c\u89e3\u6790 3.1 \u57fa\u7840","og_url":"https:\/\/www.wsisp.com\/helps\/68783.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-30T10:09:17+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130100914-697c834ac9b2c.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/68783.html","url":"https:\/\/www.wsisp.com\/helps\/68783.html","name":"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-30T10:09:17+00:00","dateModified":"2026-01-30T10:09:17+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/68783.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/68783.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/68783.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"OpenCV\u5b9e\u65f6\u6444\u50cf\u5934\u5904\u7406\uff1a\u66dd\u5149\u8c03\u8282\u3001\u964d\u566a\u4e0e\u4e8c\u503c\u5316\u5b9e\u6218"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/68783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=68783"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/68783\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/68777"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=68783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=68783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=68783"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=68783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}