{"id":992952,"date":"2024-12-27T08:42:06","date_gmt":"2024-12-27T00:42:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/992952.html"},"modified":"2024-12-27T08:42:08","modified_gmt":"2024-12-27T00:42:08","slug":"python%e5%a6%82%e4%bd%95%e7%a6%bb%e7%ba%bf%e5%ae%89%e8%a3%85opencv","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/992952.html","title":{"rendered":"python\u5982\u4f55\u79bb\u7ebf\u5b89\u88c5opencv"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25070552\/4379849b-af38-4639-9f13-b7f8c185443b.webp\" alt=\"python\u5982\u4f55\u79bb\u7ebf\u5b89\u88c5opencv\" \/><\/p>\n<p><p> <strong>\u8981\u5728\u79bb\u7ebf\u73af\u5883\u4e2d\u5b89\u88c5OpenCV\u7684Python\u5e93\uff0c\u60a8\u9700\u8981\u63d0\u524d\u4e0b\u8f7dOpenCV\u7684\u8f6e\u5b50\u6587\u4ef6\u3001\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u9879\u4e5f\u5df2\u4e0b\u8f7d\u3001\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\u3002<\/strong>\u5176\u4e2d\uff0c\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u9879\u5b8c\u6574\u3001\u63d0\u524d\u4e0b\u8f7d\u9002\u5408\u60a8\u7cfb\u7edf\u548cPython\u7248\u672c\u7684OpenCV\u8f6e\u5b50\u6587\u4ef6\u662f\u5173\u952e\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u6bcf\u4e2a\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4e0b\u8f7dOpenCV\u8f6e\u5b50\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5728\u5177\u5907\u7f51\u7edc\u8fde\u63a5\u7684\u73af\u5883\u4e2d\uff0c\u9996\u5148\u9700\u8981\u4e0b\u8f7dOpenCV\u7684Python\u8f6e\u5b50\u6587\u4ef6\uff08whl\u6587\u4ef6\uff09\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee<a href=\"https:\/\/pypi.org\/project\/opencv-python\/#files\">PyPI\u5b98\u65b9\u7f51\u7ad9<\/a>\u627e\u5230\u9002\u5408\u60a8Python\u7248\u672c\u548c\u7cfb\u7edf\u67b6\u6784\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u9009\u62e9\u9002\u5f53\u7684\u7248\u672c\uff1a<\/strong> \u5728PyPI\u4e0a\u641c\u7d22opencv-python\uff0c\u5e76\u627e\u5230\u4e0e\u60a8\u7684Python\u7248\u672c\u548c\u64cd\u4f5c\u7cfb\u7edf\u517c\u5bb9\u7684.whl\u6587\u4ef6\u3002\u6ce8\u610f\uff0c\u6587\u4ef6\u540d\u4e2d\u5305\u542b\u7684\u4fe1\u606f\uff0c\u5982cp36\u8868\u793aPython 3.6\uff0cwin_amd64\u8868\u793a\u9002\u7528\u4e8e64\u4f4dWindows\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e0b\u8f7d\u6587\u4ef6\uff1a<\/strong> \u9009\u62e9\u5408\u9002\u7684\u6587\u4ef6\u5e76\u4e0b\u8f7d\u5230\u672c\u5730\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4e0b\u8f7d\u4f9d\u8d56\u9879<\/h3>\n<\/p>\n<p><p>OpenCV\u53ef\u80fd\u4f9d\u8d56\u4e8e\u5176\u4ed6\u7684\u4e00\u4e9bPython\u5305\u3002\u56e0\u6b64\u5728\u79bb\u7ebf\u5b89\u88c5\u65f6\uff0c\u9700\u8981\u786e\u4fdd\u8fd9\u4e9b\u4f9d\u8d56\u5305\u4e5f\u88ab\u4e0b\u8f7d\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528pip\u4e0b\u8f7d\u4f9d\u8d56\u9879\uff1a<\/strong> \u5728\u6709\u7f51\u7edc\u7684\u73af\u5883\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u67e5\u770bOpenCV\u7684\u4f9d\u8d56\u9879\u5e76\u4e0b\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip download opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4e0b\u8f7dOpenCV\u53ca\u5176\u6240\u6709\u4f9d\u8d56\u9879\u5230\u5f53\u524d\u76ee\u5f55\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u624b\u52a8\u67e5\u627e\u4f9d\u8d56\uff1a<\/strong> \u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u624b\u52a8\u67e5\u627e\u67d0\u4e9b\u4f9d\u8d56\u9879\uff0c\u53ef\u4ee5\u901a\u8fc7\u9605\u8bfbOpenCV\u7684\u5b98\u65b9\u6587\u6863\u6216\u5728PyPI\u9875\u9762\u4e0a\u67e5\u770b\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u5c06\u6587\u4ef6\u8f6c\u79fb\u5230\u79bb\u7ebf\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u5c06\u4e0b\u8f7d\u7684.whl\u6587\u4ef6\u4ee5\u53ca\u4f9d\u8d56\u9879\u6587\u4ef6\u901a\u8fc7USB\u5b58\u50a8\u8bbe\u5907\u6216\u5176\u4ed6\u65b9\u5f0f\u8f6c\u79fb\u5230\u9700\u8981\u5b89\u88c5OpenCV\u7684\u79bb\u7ebf\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b89\u88c5OpenCV\u548c\u4f9d\u8d56\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u79bb\u7ebf\u73af\u5883\u4e2d\uff0c\u6253\u5f00\u547d\u4ee4\u884c\u5e76\u5bfc\u822a\u5230\u5b58\u653e.whl\u6587\u4ef6\u7684\u76ee\u5f55\u3002\u7136\u540e\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u4f9d\u8d56\u9879\uff1a<\/strong> \u9996\u5148\u5b89\u88c5\u6240\u6709\u4e0b\u8f7d\u7684\u4f9d\u8d56\u9879\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install some_dependency.whl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06<code>some_dependency.whl<\/code>\u66ff\u6362\u4e3a\u60a8\u4e0b\u8f7d\u7684\u4f9d\u8d56\u9879\u6587\u4ef6\u540d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5OpenCV\uff1a<\/strong> \u4f9d\u8d56\u9879\u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5OpenCV\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv_python-&lt;version&gt;-cp&lt;version&gt;-cp&lt;version&gt;-&lt;platform&gt;.whl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06\u6587\u4ef6\u540d\u66ff\u6362\u4e3a\u60a8\u5b9e\u9645\u4e0b\u8f7d\u7684OpenCV.whl\u6587\u4ef6\u540d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u9a8c\u8bc1\u5b89\u88c5<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u786e\u4fddOpenCV\u5df2\u6b63\u786e\u5b89\u88c5\uff0c\u60a8\u53ef\u4ee5\u6253\u5f00Python\u5e76\u5c1d\u8bd5\u5bfc\u5165OpenCV\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p>print(cv2.__version__)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u5e76\u4e14\u6253\u5370\u51fa\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660eOpenCV\u5df2\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7248\u672c\u517c\u5bb9\u6027\u95ee\u9898\uff1a<\/strong> \u5982\u679c\u5b89\u88c5\u65f6\u51fa\u73b0\u7248\u672c\u4e0d\u517c\u5bb9\u7684\u95ee\u9898\uff0c\u786e\u4fdd\u60a8\u4e0b\u8f7d\u7684.whl\u6587\u4ef6\u4e0ePython\u7248\u672c\u548c\u7cfb\u7edf\u67b6\u6784\u5339\u914d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f9d\u8d56\u9879\u7f3a\u5931\uff1a<\/strong> \u5982\u679c\u5728\u5bfc\u5165OpenCV\u65f6\u51fa\u73b0\u4f9d\u8d56\u9879\u7f3a\u5931\u9519\u8bef\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u624b\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5\u8fd9\u4e9b\u7f3a\u5931\u7684\u4f9d\u8d56\u9879\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8def\u5f84\u95ee\u9898\uff1a<\/strong> \u786e\u4fddpip\u6307\u5411\u7684\u662f\u60a8\u6b63\u5728\u4f7f\u7528\u7684Python\u7248\u672c\uff08\u53ef\u4ee5\u4f7f\u7528<code>python -m pip install ...<\/code>\u6765\u786e\u4fdd\u4f7f\u7528\u6b63\u786e\u7684Python\u73af\u5883\uff09\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5728\u6ca1\u6709\u4e92\u8054\u7f51\u8fde\u63a5\u7684\u73af\u5883\u4e2d\u6210\u529f\u5b89\u88c5OpenCV\u3002\u63d0\u524d\u51c6\u5907\u597d\u6240\u6709\u9700\u8981\u7684\u6587\u4ef6\u548c\u4f9d\u8d56\u9879\u662f\u5173\u952e\u6240\u5728\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u60c5\u51b5\u4e0b\u5b89\u88c5OpenCV\uff1f<\/strong><br \/>\u5728\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u73af\u5883\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u6709\u7f51\u7edc\u8fde\u63a5\u7684\u8ba1\u7b97\u673a\u4e0a\u4e0b\u8f7dOpenCV\u7684\u76f8\u5173\u5b89\u88c5\u5305\uff0c\u5e76\u5c06\u5176\u8f6c\u79fb\u5230\u76ee\u6807\u8ba1\u7b97\u673a\u8fdb\u884c\u5b89\u88c5\u3002\u53ef\u4ee5\u901a\u8fc7PyPI\u7f51\u7ad9\u4e0b\u8f7d\u9884\u7f16\u8bd1\u7684.whl\u6587\u4ef6\uff0c\u6216\u8005\u4eceOpenCV\u7684GitHub\u9875\u9762\u83b7\u53d6\u6e90\u4ee3\u7801\u3002\u786e\u4fdd\u4e0b\u8f7d\u4e0ePython\u7248\u672c\u548c\u64cd\u4f5c\u7cfb\u7edf\u76f8\u5339\u914d\u7684\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5b89\u88c5OpenCV\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4f9d\u8d56\u9879\uff1f<\/strong><br \/>\u5728\u79bb\u7ebf\u5b89\u88c5OpenCV\u65f6\uff0c\u786e\u4fdd\u63d0\u524d\u4e0b\u8f7d\u6240\u6709\u5fc5\u9700\u7684\u4f9d\u8d56\u9879\uff0c\u4f8b\u5982NumPy\u7b49\u3002\u53ef\u4ee5\u5728\u6709\u7f51\u7edc\u7684\u8ba1\u7b97\u673a\u4e0a\u4f7f\u7528\u547d\u4ee4<code>pip show opencv-python<\/code>\u67e5\u770bOpenCV\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5e76\u4e0b\u8f7d\u76f8\u5e94\u7684\u5305\u6587\u4ef6\u3002\u5c06\u8fd9\u4e9b\u6587\u4ef6\u4e0eOpenCV\u4e00\u8d77\u8f6c\u79fb\u5230\u76ee\u6807\u8ba1\u7b97\u673a\uff0c\u786e\u4fdd\u5b89\u88c5\u987a\u5229\u8fdb\u884c\u3002<\/p>\n<p><strong>\u5982\u4f55\u9a8c\u8bc1OpenCV\u662f\u5426\u6210\u529f\u5b89\u88c5\uff1f<\/strong><br \/>\u5728\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728Python\u73af\u5883\u4e2d\u8f93\u5165<code>import cv2<\/code>\u6765\u68c0\u67e5OpenCV\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002\u5982\u679c\u6ca1\u6709\u51fa\u73b0\u9519\u8bef\u63d0\u793a\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>cv2.__version__<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u5b89\u88c5\u7684OpenCV\u7248\u672c\uff0c\u786e\u4fdd\u5176\u7b26\u5408\u9884\u671f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728\u79bb\u7ebf\u73af\u5883\u4e2d\u5b89\u88c5OpenCV\u7684Python\u5e93\uff0c\u60a8\u9700\u8981\u63d0\u524d\u4e0b\u8f7dOpenCV\u7684\u8f6e\u5b50\u6587\u4ef6\u3001\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u9879\u4e5f\u5df2\u4e0b\u8f7d\u3001 [&hellip;]","protected":false},"author":3,"featured_media":992964,"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\/992952"}],"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=992952"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/992952\/revisions"}],"predecessor-version":[{"id":992965,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/992952\/revisions\/992965"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/992964"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=992952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=992952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=992952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}