آموزش نصب OpenCV بر روی Raspbian در رسبری پای
نصب openCV بر روی سیستم عامل Raspbian، شامل مراحل زیادی است و به تبع آن وقت زیادی (در حدود چندین ساعت) می خواهد. حتماً از کارت حافظه ای با حجم بیشتر از ۸GB استفاده کنید (ترجیحاً ۳۲GB). همچنین OpenCV را بر روی Python 2.7 نصب خواهیم کرد.
مرحله اول: نصب پکیج ها و کتابخانه های ضروری
در ابتدا لازم است پکیج های موجود را به روز رسانی کنیم. از دستورات زیر استفاده نمایید:
1 2 3 |
<span style="font-family: tahoma; font-size: small;"><span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> update</span> </span><span style="font-family: tahoma; font-size: small;"><span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> upgrade</span> </span><span style="font-family: tahoma; font-size: small;"><span class="pln">sudo rpi</span><span class="pun">-</span><span class="pln">update</span></span> |
توجه کنید در صورتی که در هنگام اجرای دستور sudo rpi-update به مشکل بر خورد کردید آن را به sudo UPDATE_SELF=0 rpi-update تغییر دهید. سپس یک بار برد را Reboot کنید تا تغییرات جدید اعمال شوند.
1 |
<span style="font-family: tahoma; font-size: small;"><span class="pln">sudo reboot</span></span> |
اکنون برخی از ابزارهای توسعه دهنده را نصب می کنیم:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">apt</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-r"><span class="kwd">get</span></span> <span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">build</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">essential </span></span><span class="crayon-e"><span class="pln">git </span></span><span class="crayon-e"><span class="pln">cmake </span></span><span class="crayon-v"><span class="pln">pkg</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">config</span> </span></span> |
حال کتابخانه های مربوط به بارگذاری عکس با فرمت های مختلف را نصب می کنیم:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">apt</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-r"><span class="kwd">get</span></span> <span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">libjpeg</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">libtiff5</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">libjasper</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">libpng12</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">dev</span> </span></span> |
همچنین کتابخانه هایی برای بار گذاری ویدئو:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">apt</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-r"><span class="kwd">get</span></span> <span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">libavcodec</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">libavformat</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">libswscale</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">libv4l</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">dev</span></span></span> <span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">apt</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-r"><span class="kwd">get</span></span> <span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">libxvidcore</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">libx264</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">dev</span></span></span> |
دستور زیر کتابخانه های مربوط به کامپایل کردن ماژول های openCV را بر روی برد نصب می کند:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">apt</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-r"><span class="kwd">get</span></span> <span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">libgtk2</span></span><span class="crayon-sy"><span class="pun">.</span></span><span class="crayon-cn"><span class="lit">0</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">dev</span> </span></span> |
عملگرهای دیگر نظیر عملگرهای ماتریسی با دستور زیر دانلود و نصب خواهند شد:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">apt</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-r"><span class="kwd">get</span></span> <span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">libatlas</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="kwd">base</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">gfortran</span> </span></span> |
حال نوبت به نصب Python 2.7 می رسد:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">apt</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-r"><span class="kwd">get</span></span> <span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">python2</span></span><span class="crayon-sy"><span class="pun">.</span></span><span class="crayon-cn"><span class="lit">7</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-e"><span class="pln">dev </span></span><span class="crayon-v"><span class="pln">python3</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">dev</span> </span></span> |
تا اینجا پکیج ها و کتابخانه های اولیه را دانلود و نصب کردیم. در مرحله بعدی قصد داریم کدهای مربوط به Open cv را دانلود و نصب نماییم.
مرحلع دوم: دریافت کدهای سورس مربوط به OpenCV
در این قسمت کدهای سورس مربوط به OpenCV ورژن ۳٫۰٫۰ را دانلود می کنیم:
1 2 3 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-r"><span class="pln">cd</span></span> <span class="crayon-o"><span class="pun">~</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-v"><span class="pln">wget</span></span> <span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">O</span></span> <span class="crayon-v"><span class="pln">opencv</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">zip</span></span> <span class="crayon-v"><span class="pln">https</span></span><span class="crayon-o"><span class="pun">:</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">github</span></span><span class="crayon-e"><span class="com">.com</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">Itseez</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">opencv</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">archive</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-cn"><span class="com">3.0.0.zip</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">unzip </span></span><span class="crayon-v"><span class="pln">opencv</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">zip</span></span></span> |
برای آنکه OpenCV به طور کامل و با تمام ملزوماتش نصب شود لازم است فایل opencv_contrib هم دانلود کنیم. این فایل شامل امکانات SIFT و SURF است:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln"> </span></span><span class="crayon-v"><span class="pln">wget</span></span> <span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">O</span></span> <span class="crayon-v"><span class="pln">opencv_contrib</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">zip</span></span> <span class="crayon-v"><span class="pln">https</span></span><span class="crayon-o"><span class="pun">:</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">github</span></span><span class="crayon-e"><span class="com">.com</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">Itseez</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">opencv_contrib</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">archive</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-cn"><span class="com">3.0.0.zip</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">unzip </span></span><span class="crayon-v"><span class="pln">opencv_contrib</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">zip</span></span></span> |
مرحله سوم: نصب Python
در این مرحله پکیج های مربوط به opencv را برای Python دانلود و نصب می کنیم:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">wget </span></span><span class="crayon-v"><span class="pln">https</span></span><span class="crayon-o"><span class="pun">:</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-v"><span class="com">bootstrap</span></span><span class="crayon-e"><span class="com">.pypa</span></span><span class="crayon-e"><span class="com">.io</span></span><span class="crayon-o"><span class="com">/</span></span><span class="crayon-r"><span class="com">get</span></span><span class="crayon-o"><span class="com">-</span></span><span class="crayon-v"><span class="com">pip</span></span><span class="crayon-e"><span class="com">.py</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-e"><span class="pln">python </span></span><span class="crayon-r"><span class="kwd">get</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">pip</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">py</span></span></span> |
برخی اوقات ممکن است از ورژن های مختلف Python و با پکیج های متفاوت استفاده نمایید. virtualenv و virtualenvwrapper مشکل متفاوت بودن کدهای برنامه های نوشته شده با ورژن های مختلف را بر طراف خواهد کرد:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-e"><span class="pln">pip </span></span><span class="crayon-e"><span class="pln">install </span></span><span class="crayon-e"><span class="pln">virtualenv </span></span><span class="crayon-i"><span class="pln">virtualenvwrapper</span></span></span> <span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-r"><span class="pln">rm</span></span> <span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">rf</span></span> <span class="crayon-o"><span class="pun">~</span></span><span class="crayon-o"><span class="str">/</span></span><span class="crayon-e"><span class="str">.cache</span></span><span class="crayon-o"><span class="str">/</span></span><span class="crayon-v"><span class="pln">pi</span></span></span> |
اکنون لازم است فایل profile./~ را آپدیت کنیم:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-v"><span class="pln">nano </span><span class="pun">.</span><span class="pln">profile</span> </span></span> |
در پنجره باز شده و در آخر فایل (پایین آخزین خط نوشته شده)، عبارات زیر را وارد کنید:
1 2 3 4 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-c"><span class="com"># virtualenv and virtualenvwrapper</span> <span class="kwd">export</span><span class="pln"> WORKON_HOME</span><span class="pun">=</span><span class="pln">$HOME</span><span class="pun">/.</span><span class="pln">virtualenv</span> <span class="pln">source </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">virtualenvwrapper</span><span class="pun">.</span><span class="pln">sh</span> </span></span> |
سپس کلید ctrl+x را فشرده و بعد از آن کلید y را به منظور ذخیره کردن فایل فشار دهید. سپس با فشردن کلید Enter از آن فایل خارج شوید. پس از به روز رسانی profile./~، نوبت به بارگذاری مجدد آن می رسد تا تغییرات اثر خود را بگذارند:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-v"><span class="pln">source</span></span> <span class="crayon-o"><span class="pun">~</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">profile</span> </span></span> |
در مرحله بعدی باید virtual environment را برای Python بسازیم:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">mkvirtualenv </span></span><span class="crayon-v"><span class="pln">cv</span> </span></span> |
توجه کنید اگر سیستم را Reboot کردید و یا از ترمینال خارج شدید لازم است مجدداً profile./~ را بارگذاری کنید. برای این کار:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-v"><span class="pln">source</span></span> <span class="crayon-o"><span class="pun">~</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">profile</span> <span class="pln">workon cv</span></span></span> |
توجه کنید که بعد از نوشتن عبارت workon cv، عبارت cv اول هر خط نمایش داده خواهد شد.
حال نوبت به دانلود و نصب NumPy می رسد:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">pip </span></span><span class="crayon-e"><span class="pln">install </span></span><span class="crayon-v"><span class="pln">numpy</span> </span></span> |
این روند تقریباً ۲۰ دقیقه طول خواهد کشید.
مرحله چهارم: کامپایل کردن و نصب OpenCV
ابتدا مطمئن شوید در حالت virtual environment هستید:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-v"><span class="pln">workon cv</span> </span></span> |
اکنون فایلی به منظور کامپایل کردن کدهای سورسی که قبلاً دانلود کردیم ایجاد می کنیم:
1 2 3 4 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-r"><span class="pln">cd</span></span> <span class="crayon-o"><span class="pun">~</span></span><span class="crayon-o"><span class="str">/</span></span><span class="crayon-v"><span class="str">opencv</span></span><span class="crayon-o"><span class="str">-</span></span><span class="crayon-cn"><span class="str">3.0.0</span></span><span class="crayon-o"><span class="str">/</span> </span><span class="crayon-r"><span class="pln">mkdir</span></span> <span class="crayon-i"><span class="pln">build</span> </span><span class="crayon-r"><span class="pln">cd</span></span> <span class="crayon-i"><span class="pln">build</span> </span></span> |
دستور زیر را به طور کامل در پنجره Terminal وارد کرده و سپس کلید Enter را فشار دهید:
1 2 3 4 5 6 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-v"><span class="pln">cmake</span></span> <span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">D</span></span> <span class="crayon-v"><span class="pln">CMAKE_BUILD_TYPE</span></span><span class="crayon-o"><span class="pun">=</span></span><span class="crayon-i"><span class="pln">RELEASE</span></span> <span class="crayon-sy"><span class="pln">\</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">D</span></span> <span class="crayon-v"><span class="pln">CMAKE_INSTALL_PREFIX</span></span><span class="crayon-o"><span class="pun">=</span></span><span class="crayon-o"><span class="str">/</span></span><span class="crayon-v"><span class="str">usr</span></span><span class="crayon-o"><span class="str">/</span></span><span class="crayon-i"><span class="kwd">local</span></span> <span class="crayon-sy"><span class="pln">\</span></span></span> <span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">D</span></span> <span class="crayon-v"><span class="pln">INSTALL_C_EXAMPLES</span></span><span class="crayon-o"><span class="pun">=</span></span><span class="crayon-i"><span class="pln">ON</span></span> <span class="crayon-sy"><span class="pln">\</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">D</span></span> <span class="crayon-v"><span class="pln">INSTALL_PYTHON_EXAMPLES</span></span><span class="crayon-o"><span class="pun">=</span></span><span class="crayon-i"><span class="pln">ON</span></span> <span class="crayon-sy"><span class="pln">\</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">D</span></span> <span class="crayon-v"><span class="pln">OPENCV_EXTRA_MODULES_PATH</span></span><span class="crayon-o"><span class="pun">=</span></span><span class="crayon-o"><span class="pun">~</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">opencv_contrib</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-cn"><span class="lit">3.0</span><span class="pun">.</span><span class="lit">0</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-i"><span class="pln">modules</span></span> <span class="crayon-sy"><span class="pln">\</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-i"><span class="pln">D</span></span> <span class="crayon-v"><span class="pln">BUILD_EXAMPLES</span></span><span class="crayon-o"><span class="pun">=</span></span><span class="crayon-i"><span class="pln">ON</span></span> <span class="crayon-sy"><span class="pun">.</span></span><span class="crayon-sy"><span class="pun">.</span></span></span> |
اکنون نوبت به کامپایل کردن کدهای سورس می رسد. برای این کار می توان از چهار هسته موجود در پردازنده برد Raspberry pi استفاده نمود تا عملیات کامپایل کردن زمان کمتری بگیرد (حدود دو ساعت زمان می خواهد):
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-r"><span class="pln">make</span></span> <span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">j4</span> </span></span> |
در صورتی که در هنگام کامپایل کردن به مشکل برخورد کردید، برای کامپایل از یک هسته استفاده کنید (زمان بیشتری خواهد گرفت):
1 2 3 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-r"><span class="pln">make</span></span> <span class="crayon-i"><span class="pln">clean</span> </span><span class="crayon-r"><span class="pln">make</span> </span></span> |
پس از موفقیت آمیز بودن عملیات کامپایل کردن، نوبت به نصب OpenCV می رسد:
1 2 3 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-r"><span class="pln">make</span></span> <span class="crayon-i"><span class="pln">install</span> </span><span class="crayon-e"><span class="pln">sudo </span></span><span class="crayon-v"><span class="pln">ldconfig</span> </span></span> |
پس از اتمام نصب، OpenCV باید در آدرس usr/local/lib/python2.7/site–packages نصب شده باشد. برای اطمبنان از این امر از دستور زیر استفاده کنید:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span id="crayon-572b4be6bc8c4789749054" class="crayon-syntax crayon-syntax-inline crayon-theme-classic crayon-theme-classic-inline crayon-font-monaco"></span><span class="pln">cd </span><span class="pun">~</span> </span><span style="font-family: tahoma; font-size: small;"><span class="crayon-r"><span class="pln">ls</span></span> <span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">l</span></span> <span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">usr</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="kwd">local</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">lib</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">python2</span></span><span class="crayon-sy"><span class="pun">.</span></span><span class="crayon-cn"><span class="lit">7</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">site</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">packages</span></span><span class="crayon-o"><span class="pun">/</span></span></span> |
و نتیجه زیر ظاهر خواهد شد:
1 2 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-i"><span class="pln">total</span></span> <span class="crayon-cn"><span class="lit">1636</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">rw</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">r</span></span><span class="crayon-o"><span class="pun">--</span></span><span class="crayon-v"><span class="pln">r</span></span><span class="crayon-o"><span class="pun">--</span></span> <span class="crayon-cn"><span class="lit">1</span></span> <span class="crayon-e"><span class="pln">root </span></span><span class="crayon-i"><span class="pln">staff</span></span> <span class="crayon-cn"><span class="lit">1675144</span></span> <span class="crayon-i"><span class="typ">Oct</span></span> <span class="crayon-cn"><span class="lit">17</span></span> <span class="crayon-cn"><span class="lit">15</span></span><span class="crayon-o"><span class="pun">:</span></span><span class="crayon-cn"><span class="lit">25</span></span> <span class="crayon-v"><span class="pln">cv2</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">so</span></span></span> |
اکنون باید OpenCV را به virtual environment متصل کنیم:
1 2 3 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-r"><span class="pln">cd</span></span> <span class="crayon-o"><span class="pun">~</span></span><span class="crayon-o"><span class="str">/</span></span><span class="crayon-e"><span class="str">.virtualenvs</span></span><span class="crayon-o"><span class="str">/</span></span><span class="crayon-v"><span class="pln">cv</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">lib</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">python2</span></span><span class="crayon-sy"><span class="pun">.</span></span><span class="crayon-cn"><span class="lit">7</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">site</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">packages</span></span><span class="crayon-o"><span class="pun">/</span> </span><span class="crayon-r"><span class="pln">ln</span></span> <span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">s</span></span> <span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">usr</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="kwd">local</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">lib</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">python2</span></span><span class="crayon-sy"><span class="pun">.</span></span><span class="crayon-cn"><span class="lit">7</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">site</span></span><span class="crayon-o"><span class="pun">-</span></span><span class="crayon-v"><span class="pln">packages</span></span><span class="crayon-o"><span class="pun">/</span></span><span class="crayon-v"><span class="pln">cv2</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">so</span></span> <span class="crayon-v"><span class="pln">cv2</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">so</span> </span></span> |
نصب OpenCV به طور کامل انجام شد. برای اطمینان از این امر می توان دستورات زیر را در پنجره Terminal تایپ کنید:
1 2 3 4 |
<span style="font-family: tahoma; font-size: small;"><span class="crayon-e"><span class="pln">workon </span></span><span class="crayon-i"><span class="pln">cv</span> </span></span><span style="font-family: tahoma; font-size: small;"><span class="crayon-v"><span class="pln">python</span></span></span> <span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">>>></span></span> <span class="crayon-e"><span class="kwd">import</span> </span><span class="crayon-v"><span class="pln">cv2</span></span></span> <span style="font-family: tahoma; font-size: small;"><span class="crayon-o"><span class="pun">>>></span></span> <span class="crayon-v"><span class="pln">cv2</span></span><span class="crayon-e"><span class="pun">.</span><span class="pln">__version__</span></span></span> |
دستور __cv2.__version، ورزن نصب شده از OpenCV را نشان خواهد داد.