<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by dilina nuwan on Medium]]></title>
        <description><![CDATA[Stories by dilina nuwan on Medium]]></description>
        <link>https://medium.com/@dilinanuwan?source=rss-8950e45bd77e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*33XfVJms_gWCBKMr</url>
            <title>Stories by dilina nuwan on Medium</title>
            <link>https://medium.com/@dilinanuwan?source=rss-8950e45bd77e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:17:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dilinanuwan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Install OpenCv on Ubuntu 18.04 (Sinhala)]]></title>
            <link>https://medium.com/@dilinanuwan/install-opencv-on-ubuntu-18-04-sinhala-622b2d91195?source=rss-8950e45bd77e------2</link>
            <guid isPermaLink="false">https://medium.com/p/622b2d91195</guid>
            <category><![CDATA[sinhala]]></category>
            <category><![CDATA[install-opencv]]></category>
            <category><![CDATA[sri-lanka]]></category>
            <category><![CDATA[moslk]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[dilina nuwan]]></dc:creator>
            <pubDate>Tue, 14 Aug 2018 03:53:30 GMT</pubDate>
            <atom:updated>2018-08-14T03:53:30.662Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mig0qVFR7Pj-n5fmNhUTMQ.jpeg" /></figure><p>Ubuntu 18.04 වල සම්පුර්නෙන්ම Python 2.7 අයින් කරලයි තියෙන්නේ, ඒ නිසා අපිට OpenCV install කරන්න වෙන්නේ Python 3 වලටයි. මුලින් ම අපි බලමු ඔයාගේ system එකේ install කරලා තියන python version එක මොකද්ද කියලා.</p><pre>$ python3 --version<br>Python 3.6.5</pre><p>අපි දැන් Python 3 shell එක test කරමු</p><pre>$ python3<br>&gt;&gt; print(&quot;OpenCV + Ubuntu 18.04!&quot;)<br>OpenCV + Ubuntu 18.04!<br>&gt;&gt; quit()</pre><p>ලේසී නේද? අපි දැන් OpenCV install කරන්න පටන් ගමු.</p><h3>STEP 1: Install OpenCV dependencies</h3><p>මුලින් ම අපේ system එකේ තියෙන pre-installed packages/libraries ටික refresh/update කරගන්න ඕන.</p><pre>$ sudo apt-get update<br>$ sudo apt-get upgrade</pre><p>Installing developer tools</p><pre>$ sudo apt-get install build-essential cmake unzip pkg-config</pre><p>දැන් අපි OpenCV සදහා අවෂ්‍ය libraries, install කරගමු.</p><p>OpenCV කියන්නේ image processing library එකක් නිසා එකට image file formats පාවිච්චි කරන්න ඕන වෙනවා (උදා:- JPEG, PNG, TIFF, etc). ඒ නිසා අපි පහතින් සදහන් වෙන image I/O packages install කරන්න ඕන.</p><pre>$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev</pre><p>ඒ වගේම අපිට video formats සදහා අවශ්‍ය වෙන I/O packages install කරන්න ඕන.</p><pre>$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev</pre><pre>$ sudo apt-get install libxvidcore-dev libx264-dev</pre><p>OpenCV වල තියෙන HighGUI Module හදලා තියෙන්නේ GTK library එකෙනුයි. highgui module එකෙන් කෙරෙන්නේ opencv වලදී අවශ්‍ය වෙන සාමාන්‍ය විදියේ images, keypresses/mouse click, UI sliders සහ trackbars නිර්මාණය කිරීමට පහසු කිරීමයි. නමුත් හුගක් advance GUIs නිර්මාණයේදී මේ GTK Library එක වෙනුවට TK, Wx හෝ QT Libraries ය්හොදාගනී.</p><p>දැන් GTK Library එක install කරගමු.</p><pre>$ sudo apt-get install libgtk-3-dev</pre><p>මේ පහතින් install කරන library දෙකෙන් opencv වල functions optimize වෙයි.</p><pre>$ sudo apt-get install libatlas-base-dev gfortran</pre><p>අන්තිම වශයෙන් අපි Python 3 සදහා headers සහ libraries install කරගන්නවා.</p><pre>$ sudo apt-get install python3-dev</pre><h3>STEP 2: Downloading OpenCV</h3><p>මුලින්ම අපි අපේ ubuntu system එකේ root folder එකට යා යුතුයි.</p><pre>$ cd ~</pre><p>දැන් මේ folder එකට අපි OpenCV download කරගත යුතුයි.</p><pre>$ wget -O opencv.zip <a href="https://github.com/opencv/opencv/archive/3.4.1.zip">https://github.com/opencv/opencv/archive/3.4.1.zip</a><br>$ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.4.1.zip</pre><p>දැන් අපි මේ download කරගත්තු folders දෙක unzip කරගමු.</p><pre>$ unzip opencv.zip<br>$ unzip opencv_contrib.zip</pre><h3>STEP 3: Config Python 3 Environment</h3><p>අපි මුලින්ම Python 3 සදහා PIP (Python Package Manager) එක install කරගමු.</p><pre>$ wget <a href="https://bootstrap.pypa.io/get-pip.py">https://bootstrap.pypa.io/get-pip.py</a><br>$ sudo python3 get-pip.py</pre><p><strong>Virtual Environments?</strong></p><p>අපිට මේ වැඩේ ඉස්සරහට කරන යන්න මේ vertual environments කියන දේ ගැන ඉගන ගන්න වෙනවා.</p><p>හිතන්න ඔයා Python 3 සමග OpenCV ඔයාගේ system එකේ install කරලා තියෙනවා. ඔයාට මේ system එකට NumPy 1.0 කියන plugin එක install කරන්න ඕන වෙනවා. එත් ඔයාගේ අනිත් programes run වෙන්න ඕන වෙන්නේ NumPy 2.0, මේ වගේ වෙලාවක ඔයාට ලේසියෙන් vertual environments දෙකක් බාවිතා කරලා මේ plugin එක install කරගන්න පුළුවන්.</p><p>දැන් අපි <a href="https://virtualenv.pypa.io/en/latest/">virtualenv</a> සහ <a href="https://virtualenvwrapper.readthedocs.org/en/latest/">virtualenvwrapper</a> install කරගමු.</p><pre>$ sudo pip install virtualenv virtualenvwrapper<br>$ sudo rm -rf ~/get-pip.py ~/.cache/pip</pre><p>අපි දැන් Ubuntu system එකේ තියෙන ~/.bashrc file එක edit කරගන්න ඕන. මේ සදහා අපි terminal editor එකක් බාවිතා කරනවා.</p><pre>$ sudo nano ~/.bashrc</pre><p>දැන් මේ පහතින් සදහන් වෙන කේතයන් copy කර paste කරන්න.</p><pre># virtualenv and virtualenvwrapper<br>export WORKON_HOME=$HOME/.virtualenvs<br>export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3<br>source /usr/local/bin/virtualenvwrapper.sh</pre><p>මින් පසු පහත command එක බවිතා කර bashrc file එක source කරගත යුතුයි.</p><pre>$ source ~/.bashrc</pre><h4>OpenCV සදහා virtual environment එකක් සාදාගමු.</h4><pre>$ mkvirtualenv cv -p python3</pre><p>අපි මෙතන cv කියලා virtual environment එකක් හදාගෙන තියෙන්නේ. ඕගොල්ලොන්ට කැමති නමක් මේ virtual environment එකට දාගන්න පුළුවන් cv වෙනුවට.</p><p>පහත ආකාරයෙන් අපිට මේ virtual environment එකට ඇතුලු වෙන්න පුළුවන්.</p><pre>$ workon cv</pre><p>අපේ virtual environment එක හරියට නිර්මාණය වෙලානම් අපිට පහත ආකාරයෙන් බලාගන්න පුළුවන්.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*LINmPn2Pw34I7uNE.jpg" /><figcaption>මේවගේ ඔයාගෙත් bash command එක ඉස්සරහින් (cv) කියලා පෙන්නනවනම් ඔයා ඉන්නේ virtual environment එක ඇතුලෙයි</figcaption></figure><p>අපි දැන් virtual environment එකට පලවෙනි package එක install කරන්නයි යන්නේ.</p><pre>$ pip install numpy</pre><h3>STEP 4: Config and install OpenCv</h3><p>මුලින් ම අපි OpenCV compile කරන්න කලින් පෙර සදහන් කර පරිදි bash command එක ඉදිරියෙන් (cv) සද්හන් වෙලාද බැලිය යුතුයි. එසේ නැත්තම් නැවත [ workon cv ] command එක run කරන්න.</p><p>දැන් අපි compile කරන්න පටන් ගමු. මුලින්ම අපේ opencv folder එක එතුලට යන්න ඕන.</p><pre>$ cd ~/opencv-3.4.1/</pre><p>මේ folder එක එතුලේ අපි build කියලා folder එකක් හදාගන්න ඕන.</p><pre>$ mkdir build<br>$ cd build</pre><p>දැන් මේ folder එක එතුලේ cmake කරන්න ගමු.</p><pre>$ cmake -D CMAKE_BUILD_TYPE=RELEASE \<br>-D CMAKE_INSTALL_PREFIX=/usr/local \<br>-D INSTALL_PYTHON_EXAMPLES=ON \<br>-D INSTALL_C_EXAMPLES=OFF \<br>-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.1/modules \<br>-D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \<br>-D BUILD_EXAMPLES=ON ..</pre><p>ඕගොල්ලොන්ට මේ වෙලාවේදි</p><blockquote><strong><em>stdlib.h: No such file or directory</em></strong></blockquote><p>මේවගේ error එකක් අවොත් මේ build folder එක delete කරලා අලුතින් build folder එකක් හදන්න.හදලා ඉහත cmake command එකට</p><pre><em>-D ENABLE_PRECOMPILED_HEADERS=OFF </em></pre><p>type කරලා නැවත run කරන්න.</p><h4>Compiling OpenCV</h4><p>ඔයාගේ පරිගණකයේ තියෙන processor cores ගණන අනුව පහත command එක වෙනස් වෙයි. ඔයාගේ පරිගණකයේ cores 4 ක් නම් තියෙන්නේ make -j4 ලෙස යොදා ගත හැක. ඔයාගේ පරිගණකයේ cores 2 ක් නම් තියෙන්නේ make -j2 ලෙස යොදා ගත හැක, මේ වගේ “-j ” අකුරට ඉදිරියෙන් cores ගණන සදහන් කර run කර හැක.</p><pre>$ make -j4</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*GpRItCZNQbEZm_Ta.jpg" /></figure><p>ඉහත compiling එක 100% අවසන් උනාට පස්සේ පහත ආකාරයට install කලයුතුයි.</p><pre>$ sudo make install<br>$ sudo ldconfig</pre><p>දැන් ඔයාගේ පරිගණකයේ OpenCV install වෙලයි තියෙන්නේ. එක verify කරලා බලන්නේ පහත ආකාරයටයි.</p><pre>$ pkg-config --modversion opencv<br>3.4.1</pre><h3>STEP 5: Finishing up</h3><pre>$ ls /usr/local/lib/python3.6/site-packages/<br>cv2.cpython-36m-x86_64-linux-gnu.so</pre><pre>$ cd /usr/local/lib/python3.6/site-packages/<br>$ sudo mv cv2.cpython-36m-x86_64-linux-gnu.so cv2.so<br>$ cd ~/.virtualenvs/cv/lib/python3.6/site-packages/<br>$ ln -s /usr/local/lib/python3.6/site-packages/cv2.so cv2.so</pre><h3>Testing</h3><pre>$ cd ~<br>$ workon cv<br>$ python</pre><pre>Python 3.6.5 (default, Apr 1 2018, 05:46:30)<br>[GCC 7.3.0] on linux<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>&gt;&gt;&gt; import cv2<br>&gt;&gt;&gt; cv2.__version__<br>&#39;3.4.1&#39;<br>&gt;&gt;&gt; quit()</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=622b2d91195" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>