{"id":1391,"date":"2022-06-08T22:28:33","date_gmt":"2022-06-08T14:28:33","guid":{"rendered":"http:\/\/www.m8box.cn:8081\/?p=1391"},"modified":"2022-06-09T13:33:13","modified_gmt":"2022-06-09T05:33:13","slug":"%e5%9c%a8%e8%a3%85%e6%9c%89raspbian-stretch%e7%b3%bb%e7%bb%9f%e7%9a%84%e6%a0%91%e8%8e%93%e6%b4%be%e4%b8%8a%e5%ae%89%e8%a3%85opencv3python","status":"publish","type":"post","link":"http:\/\/yh.m8box.cn:8081\/?p=1391","title":{"rendered":"\u5728\u88c5\u6709Raspbian Stretch\u7cfb\u7edf\u7684\u6811\u8393\u6d3e\u4e0a\u5b89\u88c5OpenCV3+python"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"1391\" class=\"elementor elementor-1391\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-567eb840 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"567eb840\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-74942b88\" data-id=\"74942b88\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2eaded8c elementor-widget elementor-widget-text-editor\" data-id=\"2eaded8c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<style>\/*! elementor - v3.16.0 - 20-09-2023 *\/\n.elementor-widget-text-editor.elementor-drop-cap-view-stacked .elementor-drop-cap{background-color:#69727d;color:#fff}.elementor-widget-text-editor.elementor-drop-cap-view-framed .elementor-drop-cap{color:#69727d;border:3px solid;background-color:transparent}.elementor-widget-text-editor:not(.elementor-drop-cap-view-default) .elementor-drop-cap{margin-top:8px}.elementor-widget-text-editor:not(.elementor-drop-cap-view-default) .elementor-drop-cap-letter{width:1em;height:1em}.elementor-widget-text-editor .elementor-drop-cap{float:left;text-align:center;line-height:1;font-size:50px}.elementor-widget-text-editor .elementor-drop-cap-letter{display:inline-block}<\/style>\t\t\t\t<p>\u00a0\u9996\u5148\u6211\u4eec\u8981\u6ce8\u610f\u7684\u662f\u4f60\u7684<a href=\"\\\">\u6811\u8393\u6d3e<\/a>\u786c\u4ef6\u7248\u672c\u8ddf\u7cfb\u7edf\u7248\u672c\uff0c\u6211\u4eec\u8fd9\u6b21\u5b9e\u9a8c\u4e2d\u7528\u7684\u662fraspberry 4B\u7248\u672c\u7684\u786c\u4ef6\uff0c3B++\u4e5f\u540c\u6837\u9002\u7528\u4e8e\u672c\u5b9e\u9a8c\uff0c\u4f46\u662f\u4e4b\u4e0b\u7684\u7248\u672c\u6ca1\u6709\u6d4b\u8bd5\uff0c\u53ef\u80fd\u53ef\u4ee5\uff0c\u4f46\u662f\u5b89\u88c5\u65f6\u95f4\u4f1a\u6bd4\u8f83\u957f\u3002\u6211\u4eec\u7528\u7684\u7cfb\u7edf\u7248\u672c\u662fRaspbian Strech,\u4e0b\u8f7d\u5730\u5740<a href=\"\\\" target=\"\\\" rel=\"\\\">Raspbian Stretch<\/a>\u3002\u8bf7\u6ce8\u610fRaspbian Jessie\u4e0d\u9002\u7528\u4e8e\u672c\u5b9e\u9a8c\uff0c\u5efa\u8bae\u5b89\u88c5Stretch\u7248\u672c\uff0c\u5177\u4f53\u7684\u7cfb\u7edf\u5b89\u88c5\u8bf7\u53c2\u8003\u5b98\u7f51<\/p><p><strong>\u6ce8\u610f<\/strong>\uff1a\u5982\u679c\u4f60\u662f\u4ecejessie\u5347\u7ea7\u5230Stretch\u7248\u672c\u7684\uff0c\u53ef\u4ee5\u4f1a\u5728\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u9519\u8bef\uff0c\u5efa\u8bae\u5168\u65b0\u5b89\u88c5\u4e00\u4e2aStretch\u7cfb\u7edf\u3002<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0 \u6211\u5c06\u4f1a\u4e3b\u8981\u4f7f\u7528SSH\u6765\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528SSH\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u7269\u7406\u673a\u6253\u5f00\u4e00\u4e2a\u7ec8\u7aef\u3002\u5982\u679cSSH\u8fde\u63a5\u4e0d\u4e0a\uff0c\u53ef\u4ee5\u7528\u547d\u4ee4\u4e0b\u9762\u547d\u4ee4\u542f\u52a8ssh\u670d\u52a1\u3002<\/p><pre><code>$ sudo service ssh start<\/code><\/pre><h3>\u00a0 \u00a0\u5f00\u59cb\u5b89\u88c5<\/h3><p>\u7b2c\u4e00\u6b65\uff1a\u6269\u5145\u6587\u4ef6\u7cfb\u7edf<\/p><p>\u5982\u679c\u8fd9\u662f\u4f60\u5168\u65b0\u5b89\u88c5\u7684\u7cfb\u7edf\uff0c\u90a3\u4e48\u4f60\u5e94\u8be5\u9996\u5148\u6269\u5145\u4e00\u4e0b\u6587\u4ef6\u7cfb\u7edf\u6765\u4f7f\u4f60SD\u5361\u4e0a\u6240\u6709\u7a7a\u95f4\u90fd\u53ef\u4ee5\u7528\u3002\u5982\u679c\u4f60\u662f\u7528NOOBS\u5b89\u88c5\u7684\u7cfb\u7edf\uff0c\u90a3\u4e48\u8fd9\u4e00\u6b65\u53ef\u4ee5\u7701\u53bb\uff0c\u4ed6\u5df2\u7ecf\u66ff\u4f60\u505a\u597d\u4e86\u8fd9\u4e00\u6b65\u3002\u9996\u5148\u6267\u884c\u4e0b\u9762\u547d\u4ee4\uff1a<\/p><pre><code>$ sudo raspi-config<\/code><\/pre><p>\u7136\u540e\u9009\u62e9\u201cAdvanced Options\u201d\u9009\u9879<\/p><p>\u9009\u4e2d\u201cA1. Expand File System\u201d\u7136\u540e\u6309\u56de\u8f66\u952e\u3002\u6700\u540e\u9009\u6700\u4e0b\u9762\u7684FInish\u7136\u4faf\u56de\u8f66\u3002\u5b83\u4f1a\u63d0\u793a\u4f60\u91cd\u542f\uff0c\u5982\u679c\u4f60\u6ca1\u6709\u9009\u62e9\u91cd\u542f\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u7528\u4e0b\u9762\u547d\u4ee4\u91cd\u542f\uff1a<\/p><pre><code>$ sudo reboot<\/code><\/pre><p>\u91cd\u542f\u4e4b\u540e\uff0c\u68c0\u67e5\u662f\u5426\u6269\u5145\u6210\u529f\u3002\u6267\u884cdf -h\u547d\u4ee4\u5e94\u8be5\u662f\u5982\u4e0b\u7ed3\u679c\uff1a<\/p><pre><code>$ df -h\nFilesystem      Size  Used Avail Use% Mounted on\n\/dev\/root        30G  4.2G   24G  15% \/\ndevtmpfs        434M     0  434M   0% \/dev\ntmpfs           438M     0  438M   0% \/dev\/shm\ntmpfs           438M   12M  427M   3% \/run\ntmpfs           5.0M  4.0K  5.0M   1% \/run\/lock\ntmpfs           438M     0  438M   0% \/sys\/fs\/cgroup\n\/dev\/mmcblk0p1   42M   21M   21M  51% \/boot\ntmpfs            88M     0   88M   0% \/run\/user\/1000<\/code><\/pre><p>\u4f60\u53ef\u4ee5\u770b\u5230\uff0c\u6587\u4ef6\u7cfb\u7edf\u5df2\u7ecf\u5305\u542b\u4e86\u6240\u6709\u768432G\u7a7a\u95f4\u3002\u5982\u679c\u4f60\u7528\u7684\u5185\u5b58\u5361\u662f8G\u7684\uff0c\u90a3\u4f60\u7684\u7cfb\u7edf\u53ef\u4ee5\u80fd\u5df2\u7ecf\u5360\u7528\u4e86\u4e00\u534a\u7684\u7a7a\u95f4\uff0c\u53ef\u4ee5\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u6765\u5220\u6389\u4e00\u4e9b\u6ca1\u7528\u7684\u4e1c\u897f\u3002<\/p><pre><code>$ sudo apt-get purge wolfram-engine\n$ sudo apt-get purge libreoffice*\n$ sudo apt-get clean\n$ sudo apt-get autoremove<\/code><\/pre><p>\u5220\u5b8c\u8fd9\u4e9b\uff0c\u5dee\u4e0d\u591a\u53ef\u4ee5\u7701\u51fa1G\u7a7a\u95f4\u3002<\/p><p>\u7b2c\u4e8c\u6b65 \u5b89\u88c5\u4f9d\u8d56<\/p><p>\u00a0\u7531\u4e8e\u6811\u8393\u6d3e\u7684\u56fd\u5916\u6e90\u6709\u4e00\u4e2a\u5730\u5740\u6211\u4eec\u6253\u4e0d\u5f00\uff0c\u6240\u4ee5\u5c31\u5148\u628a\u6e90\u6362\u6210\u56fd\u5185\u963f\u91cc\u7684\u955c\u50cf\u6e90\u3002<\/p><p>\u7f16\u8f91 \/etc\/apt\/sources.list \u6587\u4ef6<\/p><pre><code>$ sudo nano \/etc\/apt\/sources.list<\/code><\/pre><p>\u8fdb\u5165\u4e4b\u540e\u5c06\u539f\u6709\u5185\u5bb9\u5168\u90e8\u6ce8\u91ca\u6389\uff0c\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a<\/p><pre><code>deb http:\/\/mirrors.aliyun.com\/raspbian\/raspbian\/ stretch main non-free contrib rpi\ndeb-src http:\/\/mirrors.aliyun.com\/raspbian\/raspbian\/ stretch main non-free contrib rpi<\/code><\/pre><p>\u7136\u540e\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa\u3002\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u66f4\u65b0\u7cfb\u7edf\u3002<\/p><pre><code>$ sudo apt-get update &amp;&amp; sudo apt-get upgrade<\/code><\/pre><p>\u8fd9\u65f6\u5019\u6211\u4eec\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u5f00\u53d1\u5de5\u5177\uff0c\u6bd4\u5982CMake\uff0c\u5e2e\u52a9\u6211\u4eec\u914d\u7f6e<a href=\"\\\" target=\"\\\" rel=\"\\\" data-report-click=\"\\\" data-tit=\"\\\" data-pretit=\"\\\">OpenCV<\/a>\u7684\u7f16\u8bd1\u8fc7\u7a0b\u3002<\/p><pre><code> $ sudo apt-get install build-essential cmake pkg-config<\/code><\/pre><p>\u4e0b\u9762\u6211\u4eec\u56fe\u50cf\u548cI\/O\u5305\uff0c\u6765\u4f7f\u6811\u8393\u6d3e\u53ef\u4ee5\u52a0\u8f7d\u591a\u79cd\u683c\u5f0f\u7684\u56fe\u7247\uff0c\u6bd4\u5982JPEG, PNG, TIFF\u7b49\u3002<\/p><pre><code>$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev<\/code><\/pre><p>\u6211\u4eec\u4e0d\u4ec5\u9700\u8981\u56fe\u50cfI\/O\u5305\uff0c\u8fd8\u9700\u8981\u89c6\u9891I\/O\u5305\uff0c\u8fd9\u4e9b\u5305\u53ef\u4ee5\u8ba9\u6211\u4eec\u4ece\u591a\u79cd\u683c\u5f0f\u7684\u6587\u4ef6\u4e2d\u8bfb\u5165\u89c6\u9891\uff0c\u751a\u81f3\u53ef\u4ee5\u4ece\u6444\u50cf\u5934\u8bfb\u5165\u89c6\u9891\u6d41\u3002<\/p><pre><code>$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev\n$ sudo apt-get install libxvidcore-dev libx264-dev<\/code><\/pre><p>\u6211\u4eec\u8fd8\u9700\u8981\u4e00\u4e2a\u540d\u4e3a\u00a0highgui \u7684\u6a21\u5757\uff0c\u5b83\u53ef\u4ee5\u8ba9\u6211\u4eec\u7684OpenCV\u89c6\u9891\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\uff0c\u4e3a\u4e86\u5b89\u88c5highgui\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5GTK\u5f00\u53d1\u5e93\uff1a<\/p><pre><code>$ sudo apt-get install libgtk2.0-dev libgtk-3-dev<\/code><\/pre><p>\u8bb8\u591aOpenCV\u91cc\u7684\u64cd\u4f5c\uff08\u77e9\u9635\u64cd\u4f5c\uff09\u53ef\u4ee5\u901a\u8fc7\u5b89\u88c5\u989d\u5916\u7684\u4f9d\u8d56\u6765\u4f18\u5316\uff1a<\/p><pre><code>$ sudo apt-get install libatlas-base-dev gfortran<\/code><\/pre><p>\u8fd9\u4e9b\u4f18\u5316\u5e93\u975e\u5e38\u9002\u5408\u4e8e\u6811\u8393\u6d3e\u8fd9\u79cd\u786c\u4ef6\u786c\u4ef6\u6027\u80fd\u5403\u7d27\u7684\u8bbe\u5907\u3002<\/p><p>\u7136\u540e\u6211\u4eec\u6765\u5b89\u88c5python2.7\u548cpython3 \u7684OpenCV\u5934\u6587\u4ef6\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u53ef\u4ee5\u7f16\u8bd1\u53ef\u4ee5\u7528python\u8c03\u7528\u7684OpenCV\u4e86\u3002<\/p><pre><code>$ sudo apt-get install python2.7-dev python3-dev<\/code><\/pre><p>\u5982\u679c\u4f60\u7528\u7684\u662f\u5168\u65b0\u5b89\u88c5\u7684\u7cfb\u7edf\uff0c\u7cfb\u7edf\u91cc\u5e94\u8be5\u5df2\u7ecf\u9644\u5e26\u4e86python2.7\u548cpython3.5\uff0c\u5982\u679c\u4f60\u7565\u8fc7\u8fd9\u4e00\u6b65\uff0c\u5f53\u4f60\u4e0b\u9762\u7528make\u547d\u4ee4\u7f16\u8bd1OpenCV\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0Python.h\u00a0header file not being found \u8fd9\u79cd\u9519\u8bef\u3002<\/p><h2>\u7b2c\u4e09\u6b65 \u4e0b\u8f7dOpenCV\u6e90\u4ee3\u7801<\/h2><p>\u5b89\u88c5\u5b8c\u4f9d\u8d56\u4e4b\u540e\u6211\u4eec\u4ecegithub\u5e93\u4e0b\u8f7d3.3.0\u00a0\u7248\u672c\u7684\u6e90\u7801\u6587\u4ef6\uff0c<\/p><pre><code>$ cd ~\n$ wget -O opencv.zip https:\/\/github.com\/Itseez\/opencv\/archive\/3.3.0.zip\n$ unzip opencv.zip<\/code><\/pre><p>\u5982\u679c \u4e0b\u8f7d\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u4e0b\u8f7d\u5931\u8d25\u6216\u8005\u4e0b\u8f7d\u592a\u6162\uff0c\u53ef\u4ee5\u4ece<a href=\"\\\">\u8fd9\u91cc<\/a>\u4e0b\u8f7d\u4e4b\u540e\u4e0a\u4f20\u5230\u6811\u8393\u6d3e \/home\/pi\u76ee\u5f55\u4e2d\u53bb\u3002<\/p><p>\u6211\u4eec\u8fd8\u9700\u8981\u4e0b\u8f7d\u5b89\u88c5\u4e0b\u9762\u8fd9\u4e2a\u5e93\u7684\u4ee3\u7801\uff1a<\/p><pre><code>$ wget -O opencv_contrib.zip https:\/\/github.com\/Itseez\/opencv_contrib\/archive\/3.3.0.zip\n$ unzip opencv_contrib.zip<\/code><\/pre><p>\u540c\u6837\u7684\u5982\u679c\u4e0b\u8f7d\u5931\u8d25\uff0c\u53ef\u4ee5\u76f4\u63a5\u70b9\u51fb<a href=\"\\\">\u8fd9\u91cc<\/a>\u6765\u4e0b\u8f7d\u540e\u4e0a\u4f20\u5230\u6811\u8393\u6d3e\/home\/pi\u76ee\u5f55\u53bb\u3002<\/p><p>\u5982\u679c\u8fd9\u4e24\u4e2a\u6587\u4ef6\u662f\u81ea\u5df1\u624b\u5de5\u4e0b\u8f7d\u4e4b\u540e\u4e0a\u4f20\u5230\u6811\u8393\u6d3e\u7684\uff0c\u522b\u5fd8\u4e86\u5c06\u4ed6\u4eec\u89e3\u538b\u4e00\u4e0b\u4ed6\u4eec\u3002<\/p><p><strong>\u6ce8\u610f\uff1a\u4f60\u7684opencv\u00a0\u548c\u00a0opencv_contrib\u00a0\u7248\u672c\u4e00\u5b9a\u8981\u76f8\u540c\uff0c\u5426\u5219\u4e2d\u95f4\u53ef\u80fd\u4f1a\u6709\u5176\u4ed6\u4e0d\u53ef\u9884\u77e5\u7684\u9519\u8bef\u3002<\/strong><\/p><h3>\u7b2c\u56db\u6b65\uff1a\u5b89\u88c5python\u76f8\u5173\u73af\u5883<\/h3><p>\u5728\u8fd9\u4e2a\u5b9e\u9a8c\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528python2.7\u548cpython3\u4e24\u4e2a\u7248\u672c\u6765\u5b89\u88c5\u3002\u9996\u5148\u6211\u4eec\u6765\u5b89\u88c5\uff08\u6216\u66f4\u65b0\uff09pip\u5de5\u5177\u3002<\/p><pre><code>$ wget https:\/\/bootstrap.pypa.io\/get-pip.py\n$ sudo python get-pip.py\n$ sudo python3 get-pip.py<\/code><\/pre><p>\u4e0b\u9762\u6211\u4eec\u8981\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5OpenCV\uff0c\u865a\u62df\u73af\u5883\u7684\u597d\u5904\u6709\u5f88\u591a\uff0c\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u81ea\u5df1\u53bb\u4e86\u89e3\u4e00\u4e0b<a href=\"\\\">give this excellent blog post on RealPython a read<\/a>\uff0c\u6211\u5f3a\u70c8\u5efa\u8bae\u4f60\u4e5f\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u7cfb\u7edf\u73af\u5883\u4e2d\u5b89\u88c5\u3002\u6211\u4eec\u5b89\u88c5\u4e24\u4e2apython\u5305virtualenv\u00a0\u548c\u00a0virtualenvwrapper\u00a0\u3002<\/p><pre><code>$ sudo pip install virtualenv virtualenvwrapper\n$ sudo rm -rf ~\/.cache\/pip<\/code><\/pre><p>\u5b89\u88c5\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u66f4\u65b0\u6211\u4eec\u7684\u73af\u5883\u53d8\u91cf\u6765\u4f7f\u4ed6\u4eec\u751f\u6548\uff1a<\/p><pre><code>$ echo -e \\\"n# virtualenv and virtualenvwrapper\\\" &gt;&gt; ~\/.profile\n$ echo \\\"export WORKON_HOME=$HOME\/.virtualenvs\\\" &gt;&gt; ~\/.profile\n$ echo \\\"source \/usr\/local\/bin\/virtualenvwrapper.sh\\\" &gt;&gt; ~\/.profile<\/code><\/pre><p>\u8fd9\u51e0\u4e2a\u547d\u4ee4\u5b9e\u9645\u4e0a\u662f\u5728\u00a0~\/.profile\u00a0\u6587\u4ef6\u4e2d\u589e\u52a0\u4e86\u4e09\u884c\u547d\u4ee4\uff0c\u6765\u4f7f\u6bcf\u6b21\u8fdb\u5165shell\u7684\u65f6\u5019\u90fd\u80fd\u4f7f\u7528\u865a\u62df\u73af\u5883\u7684\u547d\u4ee4\u3002\u5982\u679c\u4f60\u6bd4\u8f83\u719f\u6089vi\u7b49\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f60\u540c\u6837\u53ef\u4ee5\u76f4\u63a5\u5728~\/.profile\u00a0\u6587\u4ef6\u672b\u5c3e\u589e\u52a0\u4e0b\u9762\u4e09\u884c\uff1a<\/p><pre><code># virtualenv and virtualenvwrapper\nexport WORKON_HOME=$HOME\/.virtualenvs\nsource \/usr\/local\/bin\/virtualenvwrapper.sh<\/code><\/pre><p>\u8fd9\u4e2a~\/.profile\u00a0\u4f1a\u5728\u6bcf\u6b21\u767b\u5165shell\u7684\u65f6\u5019\u81ea\u52a8\u6267\u884c\uff0c\u4f46\u4f60\u73b0\u5728\u521a\u521a\u589e\u52a0\u7684\u547d\u4ee4\u8fd8\u6ca1\u6709\u6267\u884c\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u91cd\u65b0\u767b\u5165shell\u6216\u8005\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u6765\u4f7f~\/.profile\u00a0\u7acb\u5373\u751f\u6548\uff1a<\/p><pre><code>$ source ~\/.profile<\/code><\/pre><p><strong>\u6ce8\u610f\uff1a\u5efa\u8bae\u4f60\u6bcf\u6b21\u767b\u5165\u7684\u65f6\u5019\u90fd\u624b\u52a8\u6267\u884c\u4e00\u4e0b\u4e0a\u9762\u7684\u547d\u4ee4\u6765\u4fdd\u8bc1\u7cfb\u7edf\u53d8\u91cf\u5df2\u7ecf\u6b63\u5e38\u8f7d\u5165\u3002<\/strong><\/p><p>\u7136\u540e\uff0c\u521b\u5efa\u4e00\u4e2apython3\u7684\u865a\u62df\u73af\u5883\uff1a<\/p><pre><code>$ mkvirtualenv cv -p python3<\/code><\/pre><p><strong>\u6216\u8005<\/strong>python2\u7684\u865a\u62df\u73af\u5883\uff1a<\/p><pre><code>$ mkvirtualenv cv -p python2<\/code><\/pre><p>\u521b\u5efa\u865a\u62df\u73af\u5883\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u5165\u865a\u62df\u73af\u5883\uff0c\u6211\u4eec\u4ee5\u540e\u90fd\u53ef\u4ee5\u4e0b\u9762\u547d\u4ee4\u6765\u8fdb\u5165\u865a\u62df\u73af\u5883\uff1a<\/p><pre><code>$ source ~\/.profile\n$ workon cv<\/code><\/pre><p>\u8fd9\u4e2a\u65f6\u5019\u5728\u4f60\u7684\u6811\u8393\u6d3e\u7ec8\u7aef\u547d\u4ee4\u63d0\u793a\u7b26\u4e4b\u524d\u5e94\u8be5\u6709\u4e00\u4e2a\u00a0(cv)\u00a0\uff0c\u8fd9\u4e2a\u8868\u793a\u6211\u4eec\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u6211\u4eec\u5728\u8fd9\u4e2a\u73af\u5883\u4e2d\u6240\u6267\u884c\u7684\u6240\u6709python\uff0cpip\u547d\u4ee4\u90fd\u662f\u6267\u884c\u7684\u865a\u62df\u73af\u5883\u4e2d\u7684\u547d\u4ee4\u3002<\/p><p>\u00a0\u5982\u679c\u6ca1\u6709\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u5f88\u7b80\u5355\uff0c\u6267\u884c\u4e0a\u9762\u8bf4\u7684\u00a0source\u00a0\u548c\u00a0workon\u00a0\u547d\u4ee4\u5c31\u884c\u4e86\u3002<\/p><h3>\u5728\u6811\u8393\u6d3e\u4e0a\u5b89\u88c5numpy\u00a0<\/h3><p>\u4f60\u73b0\u5728\u5e94\u8be5\u5728cv\u7684\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4ece\u8fd9\u4ee5\u540e\u7684\u64cd\u4f5c\u90fd\u5e94\u8be5\u5728cv\u865a\u62df\u73af\u5883\u4e2d\u3002<\/p><p>\u5b89\u88c5OpenCV\u4f9d\u8d56\u4e00\u4e2a\u53ebnumpy\u7684\u5e93\uff0c\u8fd9\u4e2a\u5e93\u662f\u7528\u6765\u8fdb\u884c\u6570\u503c\u5904\u7406\u7684\u3002<\/p><pre><code>$ pip install numpy<\/code><\/pre><p>pip\u8fd9\u4e2anumpy\u53ef\u80fd\u4f1a\u5931\u8d25\uff0c\u5982\u679c\u5931\u8d25\u4e86\u53ef\u4ee5\u76f4\u63a5\u4ece\u5b98\u7f51\u4e0b\u8f7d\u5b89\u88c5\u5305\u5b89\u88c5\u3002\u5b89\u88c5\u7684\u65f6\u5019\u8bb0\u5f97\u4e5f\u5728cv\u73af\u5883\u4e2d\u5b89\u88c5\u3002<\/p><h2>\u7b2c\u4e94\u6b65 \u7f16\u8bd1\u5b89\u88c5OpenCV<\/h2><p><strong>\u6ce8\u610f\u00a0<\/strong>\u6b64\u65f6\u4e00\u5b9a\u8981\u5728cv\u865a\u62df\u73af\u5883\u4e2d\u3002<\/p><p>\u786e\u5b9a\u5728CV\u865a\u62df\u73af\u5883\u4e2d\u4e4b\u540e\u7ee7\u7eed\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u8fdb\u884c\u7f16\u8bd1\u524d\u7684\u51c6\u5907:<\/p><ol hidden=\"\"><li>\u00a0<\/li><li>\u00a0$ cd ~\/opencv-3.3.0\/<\/li><li>\u00a0$ mkdir build<\/li><li>\u00a0$ cd build<\/li><li>\u00a0$ cmake -D CMAKE_BUILD_TYPE=RELEASE<\/li><li>\u00a0-D CMAKE_INSTALL_PREFIX=\/usr\/local<\/li><li>\u00a0-D INSTALL_PYTHON_EXAMPLES=ON<\/li><li>\u00a0-D OPENCV_EXTRA_MODULES_PATH=~\/opencv_contrib-3.3.0\/modules<\/li><li>\u00a0-D BUILD_EXAMPLES=ON ..<\/li><li>\u00a0<\/li><\/ol><p>\u4e0b\u9762\u7684\u5185\u5bb9\u5206python2 \u548cpython3\uff0c\u5982\u679c\u4f60\u662fpython2\u4e0b\u7f16\u8bd1OpenCV\uff0c\u90a3\u4e48\u6267\u884c\u5b8c\u4e0a\u9762\u547d\u4ee4\u4e4b\u540e\u5c4f\u5e55\u4e0a\u5e94\u8be5\u662f\u4e0b\u9762\u8fd9\u6837\uff0c\u5c24\u5176\u662fInterpreter\u00a0,\u00a0Libraries\u00a0,\u00a0numpy\u00a0\u548c\u00a0packages\u00a0path\u00a0\u8fd9\u51e0\u9879:<\/p><p><a href=\"http:\/\/img.m8box.cn:8082\/a\/2022\/06\/07\/629f37c601e00.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"http:\/\/img.m8box.cn:8082\/a\/2022\/06\/07\/629f37c601e00.png\" width=\"768\" height=\"473\" \/><\/a><\/p><p>\u5982\u679c\u4f60\u662fpython3\u4e0b\u7f16\u8bd1OpenCV\uff0c\u90a3\u4e48\u6267\u884c\u5b8c\u4e0a\u9762\u547d\u4ee4\u4e4b\u540e\u5c4f\u5e55\u4e0a\u5e94\u8be5\u662f\u4e0b\u9762\u8fd9\u6837\uff0c\u540c\u6837\u7684\u662f\u6ce8\u610fInterpreter\u00a0,\u00a0Libraries\u00a0,\u00a0numpy\u00a0\u548c\u00a0packages\u00a0path\u00a0\u8fd9\u51e0\u9879:<\/p><p><a href=\"http:\/\/img.m8box.cn:8082\/a\/2022\/06\/07\/629f37c4dbe59.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"http:\/\/img.m8box.cn:8082\/a\/2022\/06\/07\/629f37c4dbe59.png\" width=\"768\" height=\"511\" \/><\/a><\/p><p>\u4e00\u5b9a\u8981\u6ce8\u610f\uff0cInterpreter\u00a0\u548cnumpy\u00a0\u4e24\u9879\u7684\u4f4d\u7f6e\u90fd\u5728\u4f60\u7684\u865a\u62df\u73af\u5883\u7684\u8def\u5f84\u4e0b\u3002<\/p><p>\u5982\u679c\u8fd9\u4e24\u9879\u6ca1\u6709\u5728\u865a\u62df\u73af\u5883\u7684\u8def\u5f84\u4e0b\uff0c\u90a3\u4e48\u51e0\u4e4e\u53ef\u4ee5\u786e\u5b9a\u662f\u56e0\u4e3a\u4f60\u6ca1\u6709\u5728cv\u865a\u62df\u73af\u5883\u4e0b\u64cd\u4f5c\u3002\u53ea\u8981\u8fdb\u5165cv\u865a\u62df\u73af\u5883\uff0c\u91cd\u65b0\u6267\u884c\u4e00\u4e0b\u4e0a\u8ff0\u547d\u4ee4\u5c31\u597d\u4e86\u3002<\/p><p>\u914d\u7f6e\u865a\u62df\u5185\u5b58<\/p><p>\u7f16\u8bd1OpenCV\u9700\u8981\u5927\u91cf\u7684\u5185\u5b58\uff0c\u6240\u4ee5\u6211\u4eec\u63d0\u524d\u5c06\u865a\u62df\u5185\u5b58\u589e\u52a0\u52301g\uff0c\u5426\u5219\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u51fa\u73b0\u5047\u6b7b\u3002\u4e0d\u77e5\u9053\u4ec0\u4e48\u662f\u865a\u62df\u5185\u5b58\u7684\uff0c\u53ef\u4ee5\u81ea\u5df1\u53bb\u767e\u5ea6\u4e0b\uff0c\u7f16\u8bd1\u5b8c\u8bb0\u5f97\u6539\u56de\u6765\u3002\u5426\u5219\u5bf9\u786c\u76d8\u635f\u8017\u633a\u5927\u7684\u3002\u4fee\u6539\/etc\/dphys-swapfile\u00a0\u6587\u4ef6\u6765\u66f4\u6539\u865a\u62df\u5185\u5b58\u5927\u5c0f\uff1a<\/p><ol hidden=\"\"><li>\u00a0# set size to absolute value, leaving empty (default) then uses computed value<\/li><li>\u00a0# you most likely don\\&#8217;t want this, unless you have an special disk situation<\/li><li>\u00a0# CONF_SWAPSIZE=100<\/li><li>\u00a0CONF_SWAPSIZE=1024<\/li><\/ol><p>\u627e\u5230<\/p><pre><code>CONF_SWAPSIZE=100<\/code><\/pre><p>\u8fd9\u4e00\u9879\uff0c\u6ce8\u91ca\u6389\uff0c\u6539\u6210<\/p><pre><code>CONF_SWAPSIZE=1024<\/code><\/pre><p>\u7b49\u7f16\u8bd1\u5b8c\u4e86\u628a1024\u54ea\u884c\u6ce8\u91ca\u6389\uff0c100\u54ea\u884c\u53bb\u6389\u6ce8\u91ca\u7b26\u5c31\u884c\u4e86\u3002<\/p><p>\u7136\u540e\u6267\u884c\u4e0b\u9762\u547d\u4ee4\u4f7f\u865a\u62df\u5185\u5b58\u8bbe\u7f6e\u751f\u6548\u3002<\/p><pre><code>$ sudo \/etc\/init.d\/dphys-swapfile restart\n<\/code><\/pre><p>\u73b0\u5728\uff0c\u6211\u4eec\u5df2\u7ecf\u505a\u597d\u4e86\u6240\u6709\u7684\u7f16\u8bd1\u51c6\u5907\u5de5\u4f5c\uff0c\u4e0b\u9762\u8fdb\u884c\u7f16\u8bd1\uff1a<\/p><pre><code>$ make -j4<\/code><\/pre><p>\u7b49\u7f16\u8bd1\u5b8c\u4e4b\u540e\uff0c\u7535\u8111\u5c4f\u5e55\u4e0a\u5e94\u8be5\u663e\u793a\u4e0b\u9762\u8fd9\u6837\uff1a<\/p><p><a href=\"http:\/\/img.m8box.cn:8082\/a\/2022\/06\/07\/629f37c5aee5a.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium\" src=\"http:\/\/img.m8box.cn:8082\/a\/2022\/06\/07\/629f37c5aee5a.png\" width=\"796\" height=\"492\" \/><\/a><\/p><p>\u5269\u4e0b\u8981\u505a\u7684\uff0c\u5c31\u662f\u5728\u4f60\u7684\u6811\u8393\u6d3e\u4e0a\u5b89\u88c5OpenCV3\uff1a<\/p><pre>$sudo make install<code><\/code><br \/>$sudo ldconfig<\/pre><h3>\u7b2c\u516d\u6b65 \u5b8c\u6210\u5b89\u88c5 \u00a0 \u00a0<\/h3><p>\u5b89\u88c5\u51e0\u4e4e\u5b8c\u6210\u4e86\uff0c\u4f46\u662f\u8fd8\u6709\u51e0\u6b65\u9700\u8981\u4f60\u6765\u505a\uff1a<\/p><p><strong>python2.7\uff1a<\/strong><\/p><p>\u521b\u5efa\u8f6f\u8fde\u63a5\uff1a<\/p><pre>$cd ~\/.virtualenvs\/cv\/lib\/python2.7\/site-packages\/<code><\/code><br \/>$ln -s \/usr\/local\/lib\/python2.7\/site-packages\/cv2.so cv2.so<\/pre><p>python3.5\uff1a<\/p><pre>$ cd \/usr\/local\/lib\/python3.5\/site-packages\/<code><\/code><br \/>$ sudo mv cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so<\/pre><p>\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\uff0cpython3\u7684\u7f16\u8bd1\u51fa\u6765\uff0c\u6587\u4ef6\u540d\u4e0d\u662fcv2\uff0c\u53ef\u80fd\u662f\u4e2a\u7f16\u8bd1\u5668\u9519\u8bef\uff1f\uff1f\u6211\u4e5f\u4e0d\u77e5\u9053\uff0c\u4f46\u662f\uff0c\u597d\u5728\u4e0d\u5f71\u54cd\u4f7f\u7528\u3002\u50cf\u4e0a\u9762\u8fd9\u6837\u6539\u4e00\u4e0b\u540d\u5c31\u884c\u4e86\u3002<\/p><p>\u63a5\u7740\uff0c\u521b\u5efa\u8f6f\u8fde\u63a5\uff1a<\/p><pre>$ cd ~\/.virtualenvs\/cv\/lib\/python3.5\/site-packages\/<code><\/code><br \/>$ ln -s \/usr\/local\/lib\/python3.5\/site-packages\/cv2.so cv2.so<\/pre><h3>\u7b2c\u4e03\u6b65 \u6d4b\u8bd5\u4e00\u4e0b\u4f60\u7684OpenCV<\/h3><p>\u606d\u559c\u4f60\uff0c\u4f60\u73b0\u5728\u5df2\u7ecf\u5728\u4f60\u7684\u00a0Raspberry Pi 4 \u00a0 Raspbian Stretch\u7cfb\u7edf\u4e0a\u6210\u529f\u5b89\u88c5\u4e86OpenCV3\uff0c\u4f46\u662f\uff0c\u5e86\u795d\u4e4b\u524d\uff0c\u5148\u770b\u4e00\u4e0b\u5b83\u662f\u4e0d\u662f\u80fd\u771f\u6b63\u7684\u6b63\u786e\u8fd0\u884c\uff1a<\/p><p>\u540c\u6837\u8981\u5148\u8fdb\u5165cv\u865a\u62df\u73af\u5883\uff08\u5982\u679c\u5df2\u7ecf\u5728\u4e86\u5c31\u7701\u7565\u8fd9\u4e00\u6b65\uff09\uff0c\u8bb0\u4f4f\uff0c\u4ee5\u540e\u7528OpenCV\u7684\u65f6\u5019\u90fd\u8981\u5728cv\u865a\u62df\u73af\u5883\u4e2d\uff1a<\/p><pre>$ source ~\/.profile<code><\/code><br \/>$ workon cv<\/pre><p>\u4e0b\u9762\u8bd5\u8bd5\u5427\uff1a<\/p><pre>&gt;&gt;&gt; import cv2<code><\/code><br \/>&gt;&gt;&gt; cv2.__version__<br \/>\\'3.3.0\\'<br \/>&gt;&gt;&gt;<\/pre><p>\u5982\u679c\u4f60\u7684\u7ec8\u7aef\u663e\u793a\u7684\u8ddf\u4e0b\u9762\u7684\u4e00\u6837\uff0c\u90a3\u4e48\u606d\u559c\u4f60\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u5b89\u88c5OpenCV\u5728\u4f60\u7684\u6811\u8393\u6d3e\u4e0a\u4e86\u3002<\/p><p>\u4e00\u65e6OpenCV\u5b89\u88c5\u5b8c\u6210\u4e86\uff0c\u4f60\u5c31\u53ef\u4ee5\u5220\u6389opencv-3.3.0\u00a0andopencv_contrib-3.3.0\u00a0\u8fd9\u4e24\u4e2a\u76ee\u5f55\u4e86\uff0c\u4f46\u662f\u4e00\u5b9a\u8981\u786e\u8ba4\u5b89\u88c5\u6210\u529f\u4e86\uff0c\u5426\u5219\uff0c\u91cd\u65b0\u4e0b\u8f7d\u7f16\u8bd1\u8fd9\u4e24\u4e2a\u6587\u4ef6\u53ef\u80fd\u4f1a\u6d6a\u8d39\u4f60\u597d\u51e0\u4e2a\u5c0f\u65f6\u3002<\/p><p>\u6700\u540e\uff0c\u4e0d\u8981\u5fd8\u4e86\u4fee\u6539\/etc\/dphys-swapfile\u628a\u865a\u62df\u5185\u5b58\u6539\u56de\u6765\uff1a<\/p><pre># set size to absolute value, leaving empty (default) then uses computed value<code><\/code><br \/># you most likely don\\'t want this, unless you have an special disk situation<br \/>CONF_SWAPSIZE=100<br \/># CONF_SWAPSIZE=1024<\/pre><p>\u7136\u540e\u91cd\u542f\u670d\u52a1\u4f7f\u865a\u62df\u5185\u5b58\u751f\u6548\uff1a<\/p><pre>$ sudo \/etc\/init.d\/dphys-swapfile stop<code><\/code><br \/>$ sudo \/etc\/init.d\/dphys-swapfile start<\/pre><p>\u7ed3\u675f\u3002<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\u00a0\u9996\u5148\u6211\u4eec\u8981\u6ce8\u610f\u7684\u662f\u4f60\u7684\u6811\u8393\u6d3e\u786c\u4ef6\u7248\u672c\u8ddf\u7cfb\u7edf\u7248\u672c\uff0c\u6211\u4eec\u8fd9\u6b21\u5b9e\u9a8c\u4e2d\u7528\u7684\u662fraspberry 4B\u7248\u672c\u7684\u786c\u4ef6\uff0c3B &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/yh.m8box.cn:8081\/?p=1391\"> <span class=\"screen-reader-text\">\u5728\u88c5\u6709Raspbian Stretch\u7cfb\u7edf\u7684\u6811\u8393\u6d3e\u4e0a\u5b89\u88c5OpenCV3+python<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1437,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-1391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-raspi","category-facerecog"],"_links":{"self":[{"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=\/wp\/v2\/posts\/1391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1391"}],"version-history":[{"count":10,"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=\/wp\/v2\/posts\/1391\/revisions"}],"predecessor-version":[{"id":1479,"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=\/wp\/v2\/posts\/1391\/revisions\/1479"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=\/wp\/v2\/media\/1437"}],"wp:attachment":[{"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1391"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yh.m8box.cn:8081\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}