{"id":1084904,"date":"2025-01-08T13:11:23","date_gmt":"2025-01-08T05:11:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1084904.html"},"modified":"2025-01-08T13:11:25","modified_gmt":"2025-01-08T05:11:25","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python3%e4%b8%ad%e5%ae%89%e8%a3%85opencv-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1084904.html","title":{"rendered":"\u5982\u4f55\u5728python3\u4e2d\u5b89\u88c5opencv"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24195035\/3957b7d0-9a50-4364-ad30-4ae277a7f0cd.webp\" alt=\"\u5982\u4f55\u5728python3\u4e2d\u5b89\u88c5opencv\" \/><\/p>\n<p><p> <strong>\u5728Python3\u4e2d\u5b89\u88c5OpenCV\u7684\u6b65\u9aa4\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528pip\u5b89\u88c5\u3001\u9009\u62e9\u5408\u9002\u7684\u7248\u672c\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u9a8c\u8bc1\u5b89\u88c5\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<strong>\u4f7f\u7528pip\u5b89\u88c5<\/strong>\u662f\u6700\u5e38\u89c1\u4e14\u4fbf\u6377\u7684\u65b9\u6cd5\u3002\u8be6\u7ec6\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528pip\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u3002<\/li>\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5e76\u56de\u8f66\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4e0b\u8f7d\u5e76\u5b89\u88c5OpenCV\u7684\u6700\u65b0\u7248\u672c\u3002\u5982\u679c\u4f60\u9700\u8981\u989d\u5916\u7684\u529f\u80fd\uff0c\u5982\u5bf9\u89c6\u9891\u6587\u4ef6\u7684\u652f\u6301\uff0c\u53ef\u4ee5\u5b89\u88c5\u6269\u5c55\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python-headless<\/p>\n<p>pip install opencv-contrib-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u9009\u62e9\u5408\u9002\u7684\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u65f6\u7279\u5b9a\u9879\u76ee\u9700\u8981\u7279\u5b9a\u7248\u672c\u7684OpenCV\u3002\u53ef\u4ee5\u5728\u5b89\u88c5\u547d\u4ee4\u4e2d\u6307\u5b9a\u7248\u672c\u53f7\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python==4.5.2.52<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5b89\u88c5\u6307\u5b9a\u7248\u672c\u7684OpenCV\u3002<\/p>\n<\/p>\n<p><p><strong>\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u67d0\u4e9b\u64cd\u4f5c\u7cfb\u7edf\uff0c\u53ef\u80fd\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u4ee5\u786e\u4fddOpenCV\u5e93\u80fd\u591f\u88ab\u6b63\u786e\u8c03\u7528\u3002\u901a\u5e38\u5728Windows\u7cfb\u7edf\u4e2d\u53ef\u80fd\u9700\u8981\u6b64\u6b65\u9aa4\u3002\u53ef\u901a\u8fc7\u4ee5\u4e0b\u8def\u5f84\u8fdb\u884c\u914d\u7f6e\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u8ba1\u7b97\u673a\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li>\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\uff0c\u627e\u5230\u5e76\u7f16\u8f91\u201cPath\u201d\u53d8\u91cf\uff0c\u5c06OpenCV\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u8fdb\u53bb\u3002<\/li>\n<\/ul>\n<p><p><strong>\u9a8c\u8bc1\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u7b80\u5355\u7684Python\u811a\u672c\u6765\u9a8c\u8bc1OpenCV\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/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\u811a\u672c\u8fd0\u884c\u540e\u8f93\u51fa\u4e86OpenCV\u7684\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528pip\u5b89\u88c5<\/h3>\n<\/p>\n<p><p><strong>\u4f7f\u7528pip\u5b89\u88c5\u662f\u6700\u7b80\u5355\u548c\u6700\u5e38\u89c1\u7684\u65b9\u6cd5<\/strong>\u3002Pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4e0b\u8f7d\u548c\u5b89\u88c5\u5404\u79cdPython\u5305\uff0c\u5305\u62ecOpenCV\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00\u547d\u4ee4\u884c\u6216\u7ec8\u7aef<\/strong>\uff1a\u6839\u636e\u4f60\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u6253\u5f00\u547d\u4ee4\u884c\uff08Windows\uff09\u6216\u7ec8\u7aef\uff08MacOS\u548cLinux\uff09\u3002<\/li>\n<li><strong>\u8f93\u5165\u5b89\u88c5\u547d\u4ee4<\/strong>\uff1a\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5e76\u6309\u56de\u8f66\u952e\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4e0b\u8f7d\u5e76\u5b89\u88c5OpenCV\u7684\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u989d\u5916\u7684\u529f\u80fd\uff0c\u5982\u5bf9\u89c6\u9891\u6587\u4ef6\u7684\u652f\u6301\uff0c\u53ef\u4ee5\u5b89\u88c5\u6269\u5c55\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python-headless<\/p>\n<p>pip install opencv-contrib-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u6ce8\u610f<\/strong>\uff1a<code>opencv-python-headless<\/code>\u662f\u4e00\u4e2a\u4e0d\u5305\u542bGUI\u529f\u80fd\u7684\u7248\u672c\uff0c\u9002\u7528\u4e8e\u670d\u52a1\u5668\u73af\u5883\uff0c\u800c<code>opencv-contrib-python<\/code>\u5305\u542b\u4e86\u66f4\u591a\u7684\u9644\u52a0\u6a21\u5757\u548c\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u9009\u62e9\u5408\u9002\u7684\u7248\u672c<\/h3>\n<\/p>\n<p><p><strong>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u7684\u9879\u76ee\u53ef\u80fd\u9700\u8981\u7279\u5b9a\u7248\u672c\u7684OpenCV<\/strong>\u3002\u53ef\u4ee5\u5728\u5b89\u88c5\u547d\u4ee4\u4e2d\u6307\u5b9a\u7248\u672c\u53f7\u6765\u5b89\u88c5\u6240\u9700\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u8981\u5b89\u88c54.5.2.52\u7248\u672c\u7684OpenCV\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python==4.5.2.52<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684\u9879\u76ee\u4f7f\u7528\u6307\u5b9a\u7684OpenCV\u7248\u672c\uff0c\u907f\u514d\u56e0\u4e3a\u7248\u672c\u5dee\u5f02\u5bfc\u81f4\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p><strong>\u5728\u67d0\u4e9b\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u7279\u522b\u662fWindows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf<\/strong>\u3002\u8fd9\u4e00\u6b65\u9aa4\u53ef\u4ee5\u786e\u4fddOpenCV\u5e93\u80fd\u591f\u88ab\u6b63\u786e\u8c03\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6253\u5f00\u7cfb\u7edf\u5c5e\u6027<\/strong>\uff1a\u53f3\u952e\u70b9\u51fb\u201c\u6b64\u7535\u8111\u201d\u6216\u201c\u8ba1\u7b97\u673a\u201d\uff0c\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n<li><strong>\u8fdb\u5165\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e<\/strong>\uff1a\u70b9\u51fb\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/li>\n<li><strong>\u7f16\u8f91\u73af\u5883\u53d8\u91cf<\/strong>\uff1a\u5728\u201c\u7cfb\u7edf\u5c5e\u6027\u201d\u7a97\u53e3\u4e2d\uff0c\u70b9\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n<li><strong>\u4fee\u6539Path\u53d8\u91cf<\/strong>\uff1a\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u90e8\u5206\uff0c\u627e\u5230\u5e76\u7f16\u8f91\u201cPath\u201d\u53d8\u91cf\uff0c\u5c06OpenCV\u7684\u5b89\u88c5\u8def\u5f84\u6dfb\u52a0\u8fdb\u53bb\u3002<\/li>\n<\/ol>\n<p><p>\u4f8b\u5982\uff0c\u5982\u679cOpenCV\u5b89\u88c5\u5728<code>C:\\Python\\Lib\\site-packages\\cv2<\/code>\uff0c\u5219\u5c06\u8be5\u8def\u5f84\u6dfb\u52a0\u5230Path\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u9a8c\u8bc1\u5b89\u88c5<\/h3>\n<\/p>\n<p><p><strong>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\u6765\u9a8c\u8bc1OpenCV\u662f\u5426\u5b89\u88c5\u6210\u529f<\/strong>\u3002<\/p>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u4e2d\uff0c\u542f\u52a8Python\u89e3\u91ca\u5668\uff0c\u5e76\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/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\u811a\u672c\u8fd0\u884c\u540e\u8f93\u51fa\u4e86OpenCV\u7684\u7248\u672c\u53f7\uff0c\u5219\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002\u5426\u5219\uff0c\u8bf7\u68c0\u67e5\u524d\u9762\u7684\u6b65\u9aa4\uff0c\u786e\u4fdd\u6240\u6709\u547d\u4ee4\u548c\u914d\u7f6e\u90fd\u6b63\u786e\u65e0\u8bef\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u5b89\u88c5OpenCV\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u7684\u95ee\u9898\u3002\u4e0b\u9762\u5217\u51fa\u4e86\u4e00\u4e9b\u53ef\u80fd\u7684\u95ee\u9898\u53ca\u5176\u89e3\u51b3\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>1. pip\u7248\u672c\u8fc7\u4f4e<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684pip\u7248\u672c\u8fc7\u4f4e\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5b89\u88c5\u5931\u8d25\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5347\u7ea7pip\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install --upgrade pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u7f51\u7edc\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u4e0b\u8f7d\u548c\u5b89\u88c5OpenCV\u5305\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u7f51\u7edc\u95ee\u9898\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u56fd\u5185\u955c\u50cf\u6e90\u6765\u52a0\u5feb\u4e0b\u8f7d\u901f\u5ea6\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u963f\u91cc\u4e91\u7684\u955c\u50cf\u6e90\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python -i https:\/\/mirrors.aliyun.com\/pypi\/simple\/<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u6743\u9650\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u624d\u80fd\u5b89\u88c5\u5305\u3002\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4. \u4f9d\u8d56\u5305\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\uff0cOpenCV\u4f9d\u8d56\u7684\u4e00\u4e9b\u5305\u53ef\u80fd\u6ca1\u6709\u6b63\u786e\u5b89\u88c5\u3002\u53ef\u4ee5\u5c1d\u8bd5\u91cd\u65b0\u5b89\u88c5\u4f9d\u8d56\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p>pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u5b89\u88c5OpenCV\u7684\u5176\u4ed6\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528pip\u5b89\u88c5OpenCV\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5b89\u88c5OpenCV\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4ece\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5\uff0c\u6216\u8005\u4f7f\u7528Anaconda\u6765\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>1. \u4ece\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u4ece\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5OpenCV\u53ef\u4ee5\u8ba9\u4f60\u81ea\u5b9a\u4e49\u5b89\u88c5\u9009\u9879\uff0c\u6ee1\u8db3\u7279\u5b9a\u9700\u6c42\u3002\u9996\u5148\uff0c\u9700\u8981\u4eceOpenCV\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6e90\u7801\uff0c\u7136\u540e\u4f7f\u7528CMake\u548c\u7f16\u8bd1\u5668\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n<\/p>\n<p><p>\u8be6\u7ec6\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4e0b\u8f7d\u6e90\u7801<\/strong>\uff1a\u4eceOpenCV\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6e90\u7801\u5305\uff0c\u5e76\u89e3\u538b\u5230\u672c\u5730\u3002<\/li>\n<li><strong>\u5b89\u88c5CMake<\/strong>\uff1aCMake\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684\u6784\u5efa\u5de5\u5177\uff0c\u53ef\u4ee5\u4eceCMake\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5b89\u88c5\u3002<\/li>\n<li><strong>\u8fd0\u884cCMake<\/strong>\uff1a\u5728\u6e90\u7801\u76ee\u5f55\u4e2d\u8fd0\u884cCMake\uff0c\u751f\u6210\u7f16\u8bd1\u6587\u4ef6\u3002<\/li>\n<li><strong>\u7f16\u8bd1\u548c\u5b89\u88c5<\/strong>\uff1a\u4f7f\u7528\u7f16\u8bd1\u5668\uff08\u5982GCC\u6216MSVC\uff09\u7f16\u8bd1\u6e90\u7801\uff0c\u5e76\u5b89\u88c5OpenCV\u3002<\/li>\n<\/ol>\n<p><h4>2. \u4f7f\u7528Anaconda\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>Anaconda\u662f\u4e00\u4e2a\u6d41\u884c\u7684Python\u53d1\u884c\u7248\uff0c\u5305\u542b\u4e86\u5927\u91cf\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u7684\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528Anaconda\u7684\u5305\u7ba1\u7406\u5de5\u5177conda\u6765\u5b89\u88c5OpenCV\u3002<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u4e0b\u8f7d\u5e76\u5b89\u88c5Anaconda<\/strong>\uff1a\u4eceAnaconda\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5Anaconda\u3002<\/li>\n<li><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong>\uff1a\u4f7f\u7528conda\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">conda create -n myenv python=3.8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong>\uff1a\u6fc0\u6d3b\u521a\u521b\u5efa\u7684\u865a\u62df\u73af\u5883\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">conda activate myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u5b89\u88c5OpenCV<\/strong>\uff1a\u5728\u865a\u62df\u73af\u5883\u4e2d\u4f7f\u7528conda\u5b89\u88c5OpenCV\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">conda install -c conda-forge opencv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python3\u4e2d\u5b89\u88c5OpenCV\u662f\u4e00\u4e2a\u76f8\u5bf9\u7b80\u5355\u7684\u8fc7\u7a0b\uff0c\u4e3b\u8981\u5305\u62ec\u4f7f\u7528pip\u5b89\u88c5\u3001\u9009\u62e9\u5408\u9002\u7684\u7248\u672c\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u548c\u9a8c\u8bc1\u5b89\u88c5\u3002\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u4f60\u7684Python\u9879\u76ee\u4e2d\u4f7f\u7528OpenCV\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u662f\u4f7f\u7528pip\u5b89\u88c5\uff0c\u8fd8\u662f\u4ece\u6e90\u7801\u7f16\u8bd1\u5b89\u88c5\uff0c\u6216\u8005\u4f7f\u7528Anaconda\u5b89\u88c5\uff0c\u90fd\u53ef\u4ee5\u6839\u636e\u4f60\u7684\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u53c2\u8003\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6cd5\u90e8\u5206\uff0c\u627e\u5230\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u8bb2\u89e3\uff0c\u4f60\u80fd\u591f\u987a\u5229\u5b89\u88c5OpenCV\uff0c\u5e76\u5728\u4f60\u7684\u9879\u76ee\u4e2d\u53d1\u6325\u5176\u5f3a\u5927\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python3\u4e2d\u5b89\u88c5OpenCV\u7684\u6700\u4f73\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Python3\u4e2d\u5b89\u88c5OpenCV\u7684\u6700\u4f73\u65b9\u5f0f\u901a\u5e38\u662f\u4f7f\u7528pip\u5de5\u5177\u3002\u60a8\u53ef\u4ee5\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>pip install opencv-python<\/code>\u3002\u5982\u679c\u60a8\u9700\u8981\u989d\u5916\u7684\u529f\u80fd\uff0c\u5982\u56fe\u50cf\u5904\u7406\u6216\u8ba1\u7b97\u673a\u89c6\u89c9\u7279\u6027\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5b89\u88c5<code>opencv-python-headless<\/code>\uff0c\u5176\u547d\u4ee4\u4e3a\uff1a<code>pip install opencv-python-headless<\/code>\u3002<\/p>\n<p><strong>\u5b89\u88c5OpenCV\u540e\u5982\u4f55\u9a8c\u8bc1\u5b89\u88c5\u662f\u5426\u6210\u529f\uff1f<\/strong><br \/>\u9a8c\u8bc1OpenCV\u662f\u5426\u6210\u529f\u5b89\u88c5\u7684\u65b9\u6cd5\u76f8\u5bf9\u7b80\u5355\u3002\u60a8\u53ef\u4ee5\u5728Python\u4ea4\u4e92\u5f0f\u73af\u5883\u6216\u811a\u672c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import cv2\nprint(cv2.__version__)\n<\/code><\/pre>\n<p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u6d88\u606f\u5e76\u4e14\u663e\u793a\u4e86\u7248\u672c\u53f7\uff0c\u8bf4\u660eOpenCV\u5df2\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u679c\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u9047\u5230\u9519\u8bef\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5728\u5b89\u88c5OpenCV\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\uff0c\u5e38\u89c1\u7684\u95ee\u9898\u5305\u62ec\u4f9d\u8d56\u9879\u7f3a\u5931\u6216\u7f51\u7edc\u8fde\u63a5\u95ee\u9898\u3002\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6848\uff1a  <\/p>\n<ol>\n<li>\u786e\u4fdd\u60a8\u7684pip\u7248\u672c\u662f\u6700\u65b0\u7684\uff0c\u4f7f\u7528\u547d\u4ee4<code>pip install --upgrade pip<\/code>\u8fdb\u884c\u66f4\u65b0\u3002  <\/li>\n<li>\u68c0\u67e5\u60a8\u7684Python\u73af\u5883\u662f\u5426\u6b63\u786e\u914d\u7f6e\uff0c\u786e\u4fdd\u60a8\u6b63\u5728\u4f7f\u7528\u6b63\u786e\u7684Python\u7248\u672c\u3002  <\/li>\n<li>\u5982\u679c\u51fa\u73b0\u7f51\u7edc\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u56fd\u5185\u955c\u50cf\u6e90\uff0c\u4f8b\u5982\u6e05\u534e\u5927\u5b66\u7684\u955c\u50cf\uff0c\u547d\u4ee4\u4e3a\uff1a<code>pip install -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple opencv-python<\/code>\u3002<br \/>\u8fd9\u4e9b\u6b65\u9aa4\u901a\u5e38\u53ef\u4ee5\u5e2e\u52a9\u60a8\u89e3\u51b3\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u7684\u95ee\u9898\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u5728Python3\u4e2d\u5b89\u88c5OpenCV\u7684\u6b65\u9aa4\u4e3b\u8981\u5305\u62ec\uff1a\u4f7f\u7528pip\u5b89\u88c5\u3001\u9009\u62e9\u5408\u9002\u7684\u7248\u672c\u3001\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3001\u9a8c\u8bc1\u5b89\u88c5\u3002 \u5176 [&hellip;]","protected":false},"author":3,"featured_media":1084916,"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\/1084904"}],"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=1084904"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084904\/revisions"}],"predecessor-version":[{"id":1084920,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1084904\/revisions\/1084920"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1084916"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1084904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1084904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1084904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}