{"id":1095731,"date":"2025-01-08T14:54:04","date_gmt":"2025-01-08T06:54:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1095731.html"},"modified":"2025-01-08T14:54:06","modified_gmt":"2025-01-08T06:54:06","slug":"python%e5%a6%82%e4%bd%95%e8%af%bb%e5%8f%96%e7%83%ad%e6%88%90%e5%83%8f%e6%91%84%e5%83%8f%e6%9c%ba-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1095731.html","title":{"rendered":"python\u5982\u4f55\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211246\/8c7dc730-1922-410f-b02e-589cc7eeeefc.webp\" alt=\"python\u5982\u4f55\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\" \/><\/p>\n<p><p> <strong>\u8981\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\uff0c\u4f7f\u7528OpenCV\u5e93\u3001Thermal SDK\u3001FLIR Tools\u7b49\u5de5\u5177<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u6bd4\u5982\u4f7f\u7528OpenCV\u5e93\u3001Thermal SDK\u3001FLIR Tools\u7b49\u3002<strong>\u5176\u4e2d\uff0c\u901a\u8fc7OpenCV\u5e93\u8bfb\u53d6\u6444\u50cf\u5934\u6570\u636e\u662f\u6700\u4e3a\u5e38\u7528\u7684\u65b9\u6cd5<\/strong>\u3002OpenCV\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u63a5\u53e3\u548c\u51fd\u6570\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bfb\u53d6\u548c\u5904\u7406\u6444\u50cf\u5934\u6570\u636e\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528OpenCV\u5e93\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u6240\u9700\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86\u6240\u9700\u7684\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p>pip install opencv-python-headless<\/p>\n<p>pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u8fde\u63a5\u70ed\u6210\u50cf\u6444\u50cf\u673a<\/h3>\n<\/p>\n<p><p>\u70ed\u6210\u50cf\u6444\u50cf\u673a\u901a\u5e38\u901a\u8fc7USB\u63a5\u53e3\u8fde\u63a5\u5230\u8ba1\u7b97\u673a\u3002\u786e\u4fdd\u6444\u50cf\u673a\u5df2\u7ecf\u6b63\u786e\u8fde\u63a5\uff0c\u5e76\u4e14\u8ba1\u7b97\u673a\u8bc6\u522b\u5230\u4e86\u8be5\u8bbe\u5907\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528OpenCV\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528OpenCV\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\u6570\u636e\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u6253\u5f00\u6444\u50cf\u5934<\/strong><\/h2>\n<p>cap = cv2.VideoCapture(0)<\/p>\n<p>if not cap.isOpened():<\/p>\n<p>    print(&quot;\u65e0\u6cd5\u6253\u5f00\u6444\u50cf\u5934&quot;)<\/p>\n<p>    exit()<\/p>\n<p>while True:<\/p>\n<p>    # \u8bfb\u53d6\u4e00\u5e27<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        print(&quot;\u65e0\u6cd5\u63a5\u6536\u5e27&quot;)<\/p>\n<p>        break<\/p>\n<p>    # \u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\u50cf<\/p>\n<p>    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)<\/p>\n<p>    # \u663e\u793a\u56fe\u50cf<\/p>\n<p>    cv2.imshow(&#39;Thermal Camera&#39;, gray)<\/p>\n<p>    # \u6309\u4e0b &#39;q&#39; \u952e\u9000\u51fa<\/p>\n<p>    if cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(1) &amp; 0xFF == ord(&#39;q&#39;):<\/p>\n<p>        break<\/p>\n<h2><strong>\u91ca\u653e\u6444\u50cf\u5934\u5e76\u5173\u95ed\u6240\u6709\u7a97\u53e3<\/strong><\/h2>\n<p>cap.release()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u70ed\u6210\u50cf\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u70ed\u6210\u50cf\u6444\u50cf\u673a\u91c7\u96c6\u7684\u6570\u636e\u901a\u5e38\u662f\u6e29\u5ea6\u6570\u636e\uff0c\u9700\u8981\u8fdb\u884c\u9002\u5f53\u7684\u5904\u7406\u548c\u5206\u6790\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528OpenCV\u548cNumPy\u5e93\u6765\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1. \u6e29\u5ea6\u6570\u636e\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>\u70ed\u6210\u50cf\u6444\u50cf\u673a\u8f93\u51fa\u7684\u6570\u636e\u901a\u5e38\u662f\u539f\u59cb\u6e29\u5ea6\u6570\u636e\uff0c\u9700\u8981\u8fdb\u884c\u8f6c\u6362\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u6e29\u5ea6\u6570\u636e\u8f6c\u6362\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def temperature_conversion(raw_data):<\/p>\n<p>    # \u5047\u8bbe\u539f\u59cb\u6570\u636e\u4e3a16\u4f4d\u65e0\u7b26\u53f7\u6574\u6570<\/p>\n<p>    # \u5c06\u5176\u8f6c\u6362\u4e3a\u6e29\u5ea6\u6570\u636e\uff08\u5355\u4f4d\uff1a\u6444\u6c0f\u5ea6\uff09<\/p>\n<p>    temp_data = raw_data \/ 100.0<\/p>\n<p>    return temp_data<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u53ef\u89c6\u5316\u6e29\u5ea6\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u76f4\u89c2\u5730\u5c55\u793a\u6e29\u5ea6\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4f2a\u5f69\u8272\u56fe\u50cf\u3002OpenCV\u63d0\u4f9b\u4e86 <code>applyColorMap<\/code> \u51fd\u6570\uff0c\u53ef\u4ee5\u5c06\u7070\u5ea6\u56fe\u50cf\u8f6c\u6362\u4e3a\u4f2a\u5f69\u8272\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        break<\/p>\n<p>    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)<\/p>\n<p>    # \u6e29\u5ea6\u6570\u636e\u8f6c\u6362<\/p>\n<p>    temp_data = temperature_conversion(gray)<\/p>\n<p>    # \u5c06\u6e29\u5ea6\u6570\u636e\u8f6c\u6362\u4e3a\u4f2a\u5f69\u8272\u56fe\u50cf<\/p>\n<p>    color_map = cv2.applyColorMap(cv2.convertScaleAbs(temp_data, alpha=0.03), cv2.COLORMAP_JET)<\/p>\n<p>    cv2.imshow(&#39;Thermal Camera&#39;, color_map)<\/p>\n<p>    if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):<\/p>\n<p>        break<\/p>\n<p>cap.release()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5176\u4ed6\u65b9\u6cd5\u548c\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528OpenCV\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\u548c\u5de5\u5177\u6765\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528FLIR Tools<\/h4>\n<\/p>\n<p><p>FLIR Tools\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\u96c6\uff0c\u7528\u4e8e\u8bfb\u53d6\u548c\u5904\u7406FLIR\u70ed\u6210\u50cf\u6444\u50cf\u673a\u7684\u6570\u636e\u3002\u53ef\u4ee5\u901a\u8fc7FLIR Tools\u63d0\u4f9b\u7684SDK\u6765\u8bfb\u53d6\u6444\u50cf\u673a\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u5b89\u88c5FLIR Tools SDK\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bfb\u53d6\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flirpy.camera.boson import Boson<\/p>\n<p>camera = Boson()<\/p>\n<p>while True:<\/p>\n<p>    frame = camera.grab()<\/p>\n<p>    cv2.imshow(&#39;Thermal Camera&#39;, frame)<\/p>\n<p>    if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):<\/p>\n<p>        break<\/p>\n<p>camera.close()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528Thermal SDK<\/h4>\n<\/p>\n<p><p>\u4e00\u4e9b\u70ed\u6210\u50cf\u6444\u50cf\u673a\u5236\u9020\u5546\u63d0\u4f9b\u4e86\u81ea\u5df1\u7684SDK\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e9bSDK\u8bfb\u53d6\u6570\u636e\u3002\u5177\u4f53\u7684\u4f7f\u7528\u65b9\u6cd5\u53ef\u4ee5\u53c2\u8003\u76f8\u5173SDK\u7684\u6587\u6863\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u4ecb\u7ecd\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f7f\u7528Python\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\u7684\u6570\u636e\u3002\u65e0\u8bba\u662f\u4f7f\u7528OpenCV\u5e93\u8fd8\u662f\u5176\u4ed6\u5de5\u5177\uff0c\u5173\u952e\u5728\u4e8e\u6b63\u786e\u8fde\u63a5\u8bbe\u5907\u5e76\u8fdb\u884c\u9002\u5f53\u7684\u6570\u636e\u5904\u7406\u548c\u53ef\u89c6\u5316\u3002\u5e0c\u671b\u672c\u6587\u7684\u4ecb\u7ecd\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u80fd\u591f\u987a\u5229\u8bfb\u53d6\u548c\u5904\u7406\u70ed\u6210\u50cf\u6444\u50cf\u673a\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u8bbf\u95ee\u70ed\u6210\u50cf\u6444\u50cf\u673a\u7684\u6570\u636e\uff1f<\/strong><br \/>\u8981\u4f7f\u7528Python\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\u7684\u6570\u636e\uff0c\u9996\u5148\u9700\u8981\u786e\u8ba4\u6444\u50cf\u673a\u7684\u63a5\u53e3\u7c7b\u578b\uff08\u5982USB\u3001IP\u7b49\uff09\u3002\u82e5\u662fUSB\u8bbe\u5907\uff0c\u53ef\u4ee5\u4f7f\u7528OpenCV\u5e93\u6765\u6355\u83b7\u89c6\u9891\u6d41\u3002\u5bf9\u4e8eIP\u6444\u50cf\u673a\uff0c\u53ef\u4ee5\u4f7f\u7528requests\u5e93\u83b7\u53d6\u56fe\u50cf\u6570\u636e\u3002\u786e\u4fdd\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\uff0c\u5982OpenCV\u548crequests\uff0c\u5e76\u6839\u636e\u6444\u50cf\u673a\u7684API\u6587\u6863\u8fdb\u884c\u9002\u5f53\u7684\u914d\u7f6e\u3002<\/p>\n<p><strong>\u70ed\u6210\u50cf\u6444\u50cf\u673a\u7684\u8f93\u51fa\u683c\u5f0f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u70ed\u6210\u50cf\u6444\u50cf\u673a\u901a\u5e38\u8f93\u51fa\u7684\u683c\u5f0f\u5305\u62ecJPEG\u3001PNG\u548cTIFF\u7b49\u56fe\u50cf\u683c\u5f0f\uff0c\u4ee5\u53ca\u4e00\u4e9b\u7279\u5b9a\u7684\u70ed\u56fe\u6570\u636e\u683c\u5f0f\u3002\u67d0\u4e9b\u8bbe\u5907\u53ef\u80fd\u8fd8\u63d0\u4f9b\u6570\u636e\u6d41\u683c\u5f0f\uff0c\u5982H264\u7f16\u7801\u7684\u6d41\u5a92\u4f53\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u683c\u5f0f\u8fdb\u884c\u540e\u7eed\u5904\u7406\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5904\u7406\u70ed\u6210\u50cf\u6570\u636e\u65f6\uff0c\u6709\u54ea\u4e9b\u5e38\u7528\u7684\u5e93\u63a8\u8350\uff1f<\/strong><br \/>\u5904\u7406\u70ed\u6210\u50cf\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u5e93\u6765\u5e2e\u52a9\u5206\u6790\u548c\u53ef\u89c6\u5316\u6570\u636e\u3002NumPy\u662f\u5904\u7406\u6570\u503c\u8ba1\u7b97\u7684\u5f3a\u5927\u5de5\u5177\uff0cPandas\u9002\u5408\u6570\u636e\u5206\u6790\uff0cMatplotlib\u548cSeaborn\u5219\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u3002\u5bf9\u4e8e\u56fe\u50cf\u5904\u7406\uff0cOpenCV\u548cPIL\uff08Pillow\uff09\u90fd\u662f\u975e\u5e38\u5b9e\u7528\u7684\u9009\u62e9\uff0c\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u5904\u7406\u70ed\u56fe\u50cf\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a\uff0c\u4f7f\u7528OpenCV\u5e93\u3001Thermal SDK\u3001FLIR Tools\u7b49\u5de5\u5177 \u8981\u8bfb\u53d6\u70ed\u6210\u50cf\u6444\u50cf\u673a [&hellip;]","protected":false},"author":3,"featured_media":1095742,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095731"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1095731"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095731\/revisions"}],"predecessor-version":[{"id":1095744,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095731\/revisions\/1095744"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1095742"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1095731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1095731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1095731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}