<?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 天道酬勤 on Medium]]></title>
        <description><![CDATA[Stories by 天道酬勤 on Medium]]></description>
        <link>https://medium.com/@bob800530?source=rss-ccc14e7dd816------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*80DI3L9jKJ8HX7tQyaPmwA.jpeg</url>
            <title>Stories by 天道酬勤 on Medium</title>
            <link>https://medium.com/@bob800530?source=rss-ccc14e7dd816------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 16:55:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bob800530/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[Xcode — 零秒排版 ＋ 版面整理]]></title>
            <link>https://medium.com/@bob800530/xcode-%E9%9B%B6%E7%A7%92%E6%8E%92%E7%89%88-%E7%89%88%E9%9D%A2%E6%95%B4%E7%90%86-60d16efd61c2?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/60d16efd61c2</guid>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Sun, 10 Sep 2023 16:02:22 GMT</pubDate>
            <atom:updated>2023-09-10T16:02:22.348Z</atom:updated>
            <content:encoded><![CDATA[<h3>Xcode — 零秒排版 ＋ 版面整理</h3><h4>排版</h4><p>Step 1: Command + A 全選程式碼</p><p>Step 2: Control + I 自動排版</p><p><strong>版面整理</strong></p><p>XCode -&gt; Behaviors -&gt; Edit Behaviors -&gt; Text Editing</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXa7avBqfFGqy3WPcCL6gw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*SjFKegtX_cqVdLH17vjXVg.png" /></figure><p><strong>參考資料</strong></p><p><a href="https://www.youtube.com/watch?v=EQkqXED8U_0&amp;t=1182s">https://www.youtube.com/watch?v=EQkqXED8U_0&amp;t=1182s</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60d16efd61c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hough Transform]]></title>
            <link>https://medium.com/@bob800530/hough-transform-cf6cb8337eac?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf6cb8337eac</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[hough-transform]]></category>
            <category><![CDATA[edge-computing]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Wed, 03 Jul 2019 13:25:28 GMT</pubDate>
            <atom:updated>2019-07-03T13:28:44.013Z</atom:updated>
            <content:encoded><![CDATA[<h3>[邊緣偵測]直線搜查家 - Hough Transform</h3><p>Hough Transform</p><h3>簡介</h3><p>霍夫轉換為一個偵測直線的影像處理演算法，常搭配Sobel, Canny濾波器用於邊緣偵測。</p><h3>理論分析</h3><blockquote><strong>直線的方程式有許多種表達方式</strong></blockquote><p><strong>1.點斜式 :</strong></p><p>第一種為高中所學<strong>點斜式</strong>，真是一個既熟悉又陌生的名詞阿!!</p><p><strong>y = mx +b, m=斜率, b=截距</strong></p><p>斜率控制直線的方向，截距控制直線的高低</p><p><strong>2.Hesse normal form</strong></p><p>Hesse normal form根據<strong>原點到直線</strong>的<strong>最短距離</strong>與<strong>角度</strong>，來定義一條獨一無二的直線</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*5zaioCLeWxiVRrivFpsF8g.png" /></figure><p>其中<strong>rho</strong> = <strong>原點到直線</strong>的<strong>最短直線距離</strong>,<strong> theta </strong>=<strong> 最短直線與X軸的夾角</strong></p><blockquote><strong>一個點可以為無限多條直線的交點</strong></blockquote><p>從左下圖可以看出來<strong>一個點可以為無限多條直線的交點</strong>，這些線透過x,y座標轉換到rho,theta座標後，就成了右下方的曲線</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/0*-o4XL357c_cE5QCl.jpg" /><figcaption>rho_theta座標轉換</figcaption></figure><p>當有某一條直線可以通過多個<strong>紅點</strong>時，轉換後的曲線，就會有<strong>交點，</strong>這個<strong>交點</strong>的rho,theta轉換回x,y座標後，就成了一條通過多個<strong>紅點</strong>的線。</p><p>根據以上描述，可以推斷出來，Hough轉換就是一個<strong>找尋rho,theta座標交點</strong>的演算法，找到這個<strong>交點</strong>，<strong>轉換回x,y座標</strong>，就會變成一條直線了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*JkLuL90xFe2NcdnS.jpg" /><figcaption>多點rho_theta座標轉換</figcaption></figure><h3>影片展示</h3><p>從 <a href="https://www.youtube.com/channel/UCSd_7rz5nzSnzUYbjaCXC5g">Thales Sehn Körting</a>這位作者的<a href="https://www.youtube.com/watch?v=4zHbI-fFIlI&amp;t=69s"><strong>Hough轉換展示影片</strong></a>中的3:33秒後可以看到實際Hough轉換的展示</p><p>Step 1: 從左上到右下依序掃描出可能經過每個點的直線，並轉換到rho, theta坐標系。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v9CI9WnHEa7BSJMFT26QDQ.png" /></figure><p>Step 2: 掃描完後，挑選rho,theta中被掃過最多次的點，再將其轉換到x,y坐標系，繪製出來，就找到一條直線了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6tgF6MHmRaxhI7bK9EUKsw.png" /></figure><h3><strong>參考資料</strong></h3><p>Udacity</p><p><a href="http://140.115.11.235/~chen/course/vision/ch8/ch8.htm">第八單元 Hough轉換</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F4zHbI-fFIlI%3Fstart%3D69%26feature%3Doembed%26start%3D69&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D4zHbI-fFIlI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F4zHbI-fFIlI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/04f682750203f0bcbe7e8be0aca50fb5/href">https://medium.com/media/04f682750203f0bcbe7e8be0aca50fb5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf6cb8337eac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[OpenCV] 實作邊緣偵測-Canny演算法]]></title>
            <link>https://medium.com/@bob800530/opencv-%E5%AF%A6%E4%BD%9C%E9%82%8A%E7%B7%A3%E5%81%B5%E6%B8%AC-canny%E6%BC%94%E7%AE%97%E6%B3%95-d6e0b92c0aa3?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6e0b92c0aa3</guid>
            <category><![CDATA[edge-computing]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[filters]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 13:18:49 GMT</pubDate>
            <atom:updated>2019-07-03T13:30:06.591Z</atom:updated>
            <content:encoded><![CDATA[<h3>邊緣偵測懶人包-Canny演算法</h3><p>邊緣偵測-Canny演算法理論</p><h3><strong>簡介</strong></h3><p>Canny演算法是一個相當著名的邊緣檢測算法，優點如下</p><ul><li><strong><em>低錯誤率</em></strong> — 偵測出的亮點大都屬於邊緣。</li><li><strong><em>定位準確</em></strong> — 標識出的邊緣與實際邊緣接近。</li><li><strong><em>解析度高 </em></strong>— 邊緣線條細緻 。</li></ul><blockquote>Canny演算法是如何做到<strong><em>低錯誤率</em></strong><em>、</em><strong><em>定位準確、解析度高</em></strong><em>這些特點的呢?</em>以下將一一解答</blockquote><h3>理論</h3><p>Canny演算法是一個複合性的邊緣偵測演算法，結合了<strong>Gaussian Filter</strong>、<strong>梯度偵測、非最大值抑制、判斷邊界</strong>四個演算法去實踐邊緣偵測</p><h3>流程</h3><h4>Step 1: Filter out any noise</h4><p>運用Gaussian Filter濾除雜訊，以下為Kernel=5的高斯矩陣。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/0*6smJAJ0ntyKvsujP.png" /><figcaption>Gaussian矩陣(Kernel = 5)</figcaption></figure><blockquote>對高斯濾波器不熟悉的讀者可以參考以下的連結</blockquote><p><a href="https://medium.com/@bob800530/python-gaussian-filter-%E6%A6%82%E5%BF%B5%E8%88%87%E5%AF%A6%E4%BD%9C-676aac52ea17">[Python]Gaussian Filter-概念與實作</a></p><h4>Step 2: Find the intensity gradient of the image</h4><p>透過Sobel濾波器濾出邊緣的強度及方向</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/164/0*eqfM-L7wzCBi7e6l.png" /><figcaption>Sobel x, y兩方向濾波器</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/122/0*qAxtW1pSvoCIDSjk.png" /><figcaption>邊緣的強度及方向</figcaption></figure><h4><strong>Step 3: </strong><em>Non-maximum</em> suppression</h4><p><strong><em>3.1尋找最大梯度方向</em></strong></p><p>為了簡化計算，梯度的方向約略分成四種，0度、45度、90度、135度</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*ivhjZY4nyLdEAaCyueOpXw.png" /></figure><p><strong><em>3.2最大值抑制</em></strong></p><p>利用最大值抑制的演算法，去尋找個方向梯度變化最大的點，以下圖為例</p><p>已經確定此梯度方向為45度，就逐步尋找矩陣內，45度方向強度最大的點，其餘45度方向的點皆歸0，就如同下方的最大值示意圖</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*OAJYyCAtA69PJSzIpny2wA.png" /><figcaption>最大值抑制示意圖</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*OAL1KWoRoICjUfkaMr0meg.png" /><figcaption>最大值抑制運用</figcaption></figure><h4>Step 4: <em>Connect Weak Edge</em></h4><p>透過Connect Weak Edge將線連起來，設定高界線與低界線，依循這樣的機制，找出邊緣。</p><p>a.高於高界線:一定是邊緣</p><p>b.低於低界線:一定不是邊緣</p><p>c.介於高界線與低界線:若附近有兩點高於高界線的點，則此點也視為邊緣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*QDjt8mKdbueT1o0JZazVFg.png" /></figure><h4>結論</h4><p>Canny是一個複合型的邊緣偵測演算法，在找尋邊緣時，相當簡單易用，一口氣把濾雜訊的Gassian跟邊緣偵測的Sobel兩個截然不同的濾波器都作進去，直接一個函式找出邊緣。</p><p>但相對的，Canny濾波器在實作上也相對沒那麼靈活，無法像Sobel跟高斯可以搭配各種不同的影像處理演算法。</p><h3>參考資料</h3><p><a href="https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.html#explanation">Canny Edge Detector - OpenCV 2.4.13.7 documentation</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPtSgA19sC5g%3Fstart%3D227%26feature%3Doembed%26start%3D227&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPtSgA19sC5g&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPtSgA19sC5g%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e646e5f361d40d8e31f28be407d2dc5/href">https://medium.com/media/1e646e5f361d40d8e31f28be407d2dc5/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6e0b92c0aa3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Driving Car -Project 5 卡爾曼濾波與自駕車的運用]]></title>
            <link>https://medium.com/@bob800530/self-driving-car-project-5-%E5%8D%A1%E7%88%BE%E6%9B%BC%E6%BF%BE%E6%B3%A2%E8%88%87%E8%87%AA%E9%A7%95%E8%BB%8A%E7%9A%84%E9%81%8B%E7%94%A8-3c324e656d5d?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c324e656d5d</guid>
            <category><![CDATA[kalman-filter]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Mon, 01 Apr 2019 14:55:46 GMT</pubDate>
            <atom:updated>2019-04-01T14:55:46.450Z</atom:updated>
            <content:encoded><![CDATA[<p>卡爾曼濾波</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TKh3wUPhg1SRzTQDfgoViQ.png" /></figure><p>Github: <a href="https://github.com/bob800530/CarND-Extended-Kalman-Filter-Project">https://github.com/bob800530/CarND-Extended-Kalman-Filter-Project</a></p><h3><strong>簡介</strong></h3><p><strong><em>雷達與光達</em></strong></p><p>現今的自駕車除了使用<strong>雷達</strong>來探測物體外，還有使用另一種Sensor那就是<strong>光達</strong>， <strong>光達</strong>是一種光學遙感技術，它通過向目標照射一束光，通常是一束脈衝雷射來測量目標的距離等參數。<strong>光達</strong>在還用於<strong>機載雷射地圖測繪</strong>、<strong>雷射測高</strong>、<strong>雷射雷達等高線繪製</strong>等等具體應用中。</p><p>然而，<strong>光達的</strong>偵測精度較雷達高，但<strong>光達</strong>也有它的弱點，像是</p><ol><li>無法跟雷達一樣透過繞射偵測物體</li><li>容易被塵土、細小碎片干擾</li><li>無法偵測速度</li></ol><p>因此一輛優秀的自駕車，須具備光達及雷達兩項Sensor。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*-11I9um1rnS3vund.jpg" /><figcaption>光學雷達在雕像古冢國家保護區擷取影像</figcaption></figure><p><strong><em>Extended Kalman Filter</em></strong></p><p>世界上任何測量儀器都還是會有誤差，<strong>光達</strong>與<strong>雷達</strong>也不例外，而<strong>卡爾曼濾波</strong>就是用來濾除這些誤差的濾波器，藉由預測量與觀測量的變化，逐步修正其測量到的誤差。</p><p>若是當狀態轉換和觀測模型不是線性函數時，就需要用<strong>Extended Kalman Filter</strong>的幫忙了。</p><h4><strong>實際演練</strong></h4><p>課程中一步步推導Kalman濾波的公式，並教導如何將其運用於C/C++，學會基本的使用後，套用到下圖的遊戲中，必須能夠準確地預測出正確的路徑。</p><p>其中紅點跟藍點分別是<strong>光達</strong>跟<strong>雷達</strong>觀測到的位置，藉由這些觀測數據，必須求出正確的<strong>位置</strong>及<strong>速度</strong>，其中<strong>光達</strong>可直接偵測到物體的x,y座標，而<strong>雷達</strong>則是偵測到物體的rho,phi, rho_dot，<strong>雷達</strong>需先將rho,phi, rho_dot轉換成x,y後，才能匯入Kalman Filter並計算正確的位置及速度。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TKh3wUPhg1SRzTQDfgoViQ.png" /></figure><h4>心得</h4><p>這個的Project有別於前四個Project，使用的是C++而非Python，對於本來就熟悉C++的我順手許多，有更多時間去推導並學習複雜的Extend Kalman Filter，完成Project後，深深的感受到，C/C++在韌體上的地位是無可取代的，任何需要Real-time即時偵測的感測器，C/C++絕對是值得考慮的語言之一。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c324e656d5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Driving Car Project 4 — 自動駕駛實作]]></title>
            <link>https://medium.com/@bob800530/self-driving-car-project-4-%E8%87%AA%E5%8B%95%E9%A7%95%E9%A7%9B%E5%AF%A6%E4%BD%9C-9921e79b4fd?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/9921e79b4fd</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 14:13:33 GMT</pubDate>
            <atom:updated>2019-03-28T14:14:49.311Z</atom:updated>
            <content:encoded><![CDATA[<h3>Self-Driving Car Project 4 — 自動駕駛實作</h3><p>Behavior Cloning</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F94P0fuTkO1E%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D94P0fuTkO1E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F94P0fuTkO1E%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/96f9c47b3182cf301e9ac45ead793211/href">https://medium.com/media/96f9c47b3182cf301e9ac45ead793211/href</a></iframe><p>Github: <a href="https://github.com/bob800530/CarND-Behavioral-Cloning-P3">https://github.com/bob800530/CarND-Behavioral-Cloning-P3</a></p><h4>簡介</h4><p>正式上路前，課程先讓我們藉由遊戲中的場景，實踐<strong>自動駕駛</strong>的技術，利用當前的影像，<strong>預測方向盤該旋轉的角度</strong>，畢竟遊戲中車子亂跑不會怎樣，現實中若是誤動作，那後果可不堪設想。</p><p>Project 4課程運用到的技術跟Project 3幾乎一樣，有 <strong>類神經網路</strong>、<strong>深度學習</strong>、<strong>卷積網路</strong>等<strong>機器學習演算法</strong>，不同的是，大多數的演算法都是由<strong>Keras</strong>呼叫，在使用上顯得容易許多。</p><h4>資料的來源</h4><p><strong>特徵值</strong>的來源為行車鏡頭錄製的<strong>影像</strong>，<strong>標籤</strong>則是<strong>操作的行為</strong></p><p>遊戲中的汽車配有<strong>三個鏡頭</strong>，行進間每個鏡頭都會不斷地收集<strong>影像</strong></p><p>藉由收集的影像，與當時的操作<strong>行為</strong>，像是<strong>方向盤角度(Steering Angle)</strong>、<strong>油門(Throttle)</strong>、<strong>剎車(Break)</strong>、<strong>速度(Speed)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*RAFMJNkNNZ6NHLyoF1u0rg.jpeg" /></figure><h4>模型架構及訓練的策略</h4><p>模型的依然是選用課程推薦的Lenet，對影像作多次的Convolution及Pooling擷取深度的特徵，最後利用類神經演算法進行訓練。</p><p>為了避免過度訓練，加入<strong> 30%的Dropout Rate</strong>，在做類神經演算法，每次只使用30%的特徵值，可<strong>避免單一特徵值的權重過高</strong>，<strong>主導整個模型的訓練結果</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-OUXqCr1Po2PTVanSkNM-g.png" /></figure><h4><strong>訓練結果及心得</strong></h4><p>當初剛做這個Project時，車子只會在原地打轉，隨著不斷的Debug，才能順利前進，但偶而還是會掉到河裡XD，直到後來使用了三個鏡頭的資料及運用反轉圖片的方法增加資料量後，才順利跑完全程!!</p><p>訓練模型的準確度為98.32%，驗證資料的準確度為97.88%</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9921e79b4fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Driving Car Project 3 — 交通號誌辨識實作]]></title>
            <link>https://medium.com/@bob800530/self-driving-car-project-3-%E4%BA%A4%E9%80%9A%E8%99%9F%E8%AA%8C%E8%BE%A8%E8%AD%98%E5%AF%A6%E4%BD%9C-8ad4e0a3b38d?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ad4e0a3b38d</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Sun, 24 Mar 2019 12:57:56 GMT</pubDate>
            <atom:updated>2019-03-24T12:57:56.089Z</atom:updated>
            <content:encoded><![CDATA[<h3>Self-Driving Car Project 3 — 交通號誌辨識實作</h3><p>交通號誌辨識實作</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*BGBbQb7yiqzK-OWPNLjT-Q.jpeg" /></figure><p><strong>Github: </strong><a href="https://github.com/bob800530/CarND-Traffic-Sign-Classifier-Project/blob/master/writeup_template.md">https://github.com/bob800530/CarND-Traffic-Sign-Classifier-Project/blob/master/writeup_template.md</a></p><h4>前言</h4><p>實作這個專題前，可以先想想看，<strong>人類是如何用眼睛辨識交通號誌的?</strong></p><p>人類的眼睛能夠藉由號誌的<strong>形狀</strong>、<strong>數字</strong>、<strong>顏色</strong>、<strong>文字</strong>等特徵，去判斷這個號誌究竟代表甚麼意義，<strong>那機器呢?</strong></p><h4>簡介</h4><p>這個專題中運用到相當多的技巧，來完成<strong>機器視覺</strong>這件事，除了<strong>影像處理</strong>外，加入了<strong>類神經網路</strong>、<strong>深度學習</strong>、<strong>卷積網路</strong>等<strong>機器學習演算法</strong>，為了實踐這些<strong>演算法</strong>，選用<strong>Python</strong>對一連串的圖片進行處理，並呼叫<strong>Tensorflow</strong>函式庫，進行<strong>模型訓練</strong>。</p><h4>程式碼講解</h4><h4>Step 0: Load The Data</h4><p>讀取課程提供的pickle檔，快速的將多張圖片的<strong>特徵值</strong>、<strong>標籤</strong>讀入變數之中。</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74f79fda4e4ea8787c4240848795dccf/href">https://medium.com/media/74f79fda4e4ea8787c4240848795dccf/href</a></iframe><h4>Step 1: Dataset Summary &amp; Exploration</h4><p>在做訓練之前，先檢視看看，究竟讀了些甚麼資料進來</p><ol><li>訓練資料 : 34799張 32*32像素的圖片</li><li>測試資料 : 12630張 32*32像素的圖片</li></ol><pre>Number of training examples = 34799<br>Number of testing examples = 12630<br>Image data shape = (32, 32, 3)<br>Number of classes = 43</pre><p>一共有43種交通號誌</p><p>以下為每種號誌的分布狀況</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*43-qQFPPtPm9qU7pz1OxCQ.png" /></figure><h4>Step 2: Design and Test a Model Architecture</h4><p>選擇的模型為Lenet訓練模型</p><p>此模型大略上來說可以切成三個部分</p><ol><li>Convolution(卷積): 擷取圖片中的特徵值</li><li>Max-Pool(池化): 降低訓練的資料量，增加訓練的速度</li><li>Dense: 將資料攤成一維陣列，並開始疊代</li></ol><p>此模型主要藉由<strong>提升訓練的深度</strong>來<strong>增加模型的準確率，</strong>需要做多次的<strong>卷積</strong>，但為了避免訓練時間過長，需要透過<strong>池化</strong>，來<strong>減低訓練的時間</strong>。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jhm0o5zBTYLs0KxL32SrQA.png" /></figure><h4>Step 3: Train, Validate and Test the Model</h4><p>確立模型後，<strong>如何訓練也是一門學問!</strong>一股腦把資料有時並不是個好作法</p><p>為了設計出更好的訓練流程，會加入Epoch, Batch, Drop rate</p><p><strong>1.Batch</strong></p><blockquote><strong>為何不能一口氣將資料丟給模型處理呢?</strong></blockquote><p>記憶體的容量可能會不足，因此會把資料切成很多組，依序放入模型中訓練，這個組數就稱為<strong>Batch</strong></p><p><strong>2.Epoch</strong></p><p>提升訓練的次數，可提升模型的準確率，而訓練的次數就稱為<strong>Epoch</strong></p><pre>Training...<br><br>EPOCH 1 ... Validation Accuracy = 0.685 Training Accuracy = 0.622<br><br>EPOCH 2 ... Validation Accuracy = 0.836 Training Accuracy = 0.801<br><br>EPOCH 3 ... Validation Accuracy = 0.887 Training Accuracy = 0.867<br><br>EPOCH 4 ... Validation Accuracy = 0.911 Training Accuracy = 0.900<br><br>EPOCH 5 ... Validation Accuracy = 0.924 Training Accuracy = 0.920<br><br>EPOCH 6 ... Validation Accuracy = 0.929 Training Accuracy = 0.935</pre><p><strong>3.Drop rate</strong></p><p>防止過度訓練，會加入Drop rate，每次訓練時，<strong>不參考全部的特徵值</strong>，避免少數特徵值，就可以決定結果</p><p>1. 400 -&gt; 120這個類神經網路，只會留80%的特徵值下來</p><p>2. 120 -&gt; 84這個類神經網路，只會留60%的特徵值下來</p><pre>train_accuracy = evaluate(X_train,y_train, 0.8, 0.6)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zyNiboiEb8E4RkpIiLoSIA.png" /></figure><h4>Result</h4><p>經過一連串的訓練後，達到了94.3%的成功率，相當的高!</p><pre>Test Accuracy = 0.943</pre><h4>心得</h4><p>這個專案在我心目中是最難的一個，要在短時間內將<strong>類神經網路</strong>、<strong>深度學習</strong>、<strong>卷積網路理論</strong>應用在實務上，真的完全費盡我所有下班時間，即使現在已經做完這個Project，理論上仍然還有許多不懂的地方，由此可知，想成為一個厲害的AI工程師，可真是不簡單啊!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ad4e0a3b38d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Driving Car Project 2 — Advanced Lane finding 實作]]></title>
            <link>https://medium.com/@bob800530/self-driving-car-project-2-advanced-lane-finding-%E5%AF%A6%E4%BD%9C-a93ee20c1275?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/a93ee20c1275</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Wed, 20 Mar 2019 15:13:52 GMT</pubDate>
            <atom:updated>2019-03-20T15:13:52.952Z</atom:updated>
            <content:encoded><![CDATA[<h3>Self-Driving Car Project 2 — Advanced Lane finding 實作</h3><p>Advanced Lane finding</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FWUY5YdGOJxM%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DWUY5YdGOJxM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FWUY5YdGOJxM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b64d1be10e87a12b075c97b7ca3bc717/href">https://medium.com/media/b64d1be10e87a12b075c97b7ca3bc717/href</a></iframe><p>Github: <a href="https://github.com/bob800530/CarND-Advanced-Lane-Lines">https://github.com/bob800530/CarND-Advanced-Lane-Lines</a></p><h4>簡介</h4><p>上一篇<a href="https://medium.com/@bob800530/self-driving-car-project1-lane-finding-%E4%BB%8B%E7%B4%B9-9b57ca14e60c"><strong><em>Self-Driving Car Project1- Lane Finding實作</em></strong></a>，說明了該如何用<strong>灰階</strong>、<strong>高斯模糊</strong>、<strong>邊緣偵測</strong>、<strong>霍夫轉換</strong>等演算法實作出車道辨識，但Project 1 的方法只能用於辨識直線車道，當遇到陰影時，也容易誤判。</p><p>在<strong>Project 2-Advanced Lane finding</strong>加入以下幾種演算法，來克服<strong>彎道</strong>及<strong>陰影</strong>等容易引起誤判的環境。</p><ol><li><strong>Camera Calibration</strong>校正鏡頭造成的扭曲</li><li><strong>Sobel濾波器</strong>強化邊緣的效果</li><li>使用不同於RGB的Color Space，如HSV, HLS來<strong>克服遇到陰影會偵測不到車道線</strong>的問題</li><li>運用<strong>Sliding Window</strong>的方式取得車道線的位置，並求出二次回歸線的係數</li><li>計算<strong>曲率</strong>，判斷車子偏向哪邊</li></ol><h4>程式碼</h4><blockquote>Step 1: 為了取得最正確的圖片，必須先校正相機魚眼效果的失真</blockquote><p>我們先用這台相機對從<strong>各個角度</strong>對黑白棋盤拍照，<strong>藉由校正這些圖片，來建立適當的方程式</strong>，因應之後實際車道的圖片。</p><pre>ret, corners = cv2.findChessboardCorners(gray, (9,6),None)</pre><p>cv2.findChessboardCorners用來找尋Original_Image的交接點</p><pre>ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, img_size,None,None)</pre><p>cv2.calibrateCamera(偵測到的交接點, 期望的交接點矩陣, 圖片大小) 可回傳Camera Matrix (mtx)和 distortion Coefficient(dist)</p><pre>undistort_img = cv2.undistort(img, mtx, dist, None, mtx)</pre><p>藉由求得的<strong>mtx</strong>跟<strong>dist</strong>，僅需將對應的參數放入cv2.undistort()函式中，就可以求得校正後的圖片了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ItOxUlFyxxpMegac4-LYQ.png" /></figure><blockquote>Step 2. 運用<strong>Sobel濾波器</strong>及<strong>HLS轉換</strong>求出車道線的邊緣</blockquote><pre>grad_x = abs_sobel_thresh(img, orient=’x’, sobel_kernel=15, thresh=(30, 100))</pre><pre>grad_y = abs_sobel_thresh(img, orient=’y’, sobel_kernel=15, thresh=(30, 100)) </pre><pre>mag_binary = mag_thres(img, sobel_kernel=15, thresh=(50, 100)) </pre><pre>dir_binary = dir_thresh(img, sobel_kernel=15, thresh=(0.7, 1.3))</pre><p>Sobel濾波器可用於偵測x, y向的梯度，亦或是結合x, y軸的變化率，算出magnitude及direction方向的能量大小。</p><pre>hls_binary = hls_select(img, thresh=(170, 255))</pre><p>HSL即<strong>色相</strong>、<strong>飽和度</strong>、<strong>亮度</strong>（英語：Hue, Saturation, Lightness）</p><p>使用hls座標轉換，在天色過暗時，依然可以透過<strong>飽和度(Saturation)</strong>及<strong>色相(Hue)</strong>，偵測車道線，算是一個<strong>簡單用實用的技巧</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjR8fxUfASKOTeRE2khFww.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0X5rLjsPNJ9R4VQ4RmbkMw.png" /></figure><blockquote>Step 3.<strong> 座標轉換</strong>-轉換成<strong>鳥瞰圖</strong></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2092eb4630f4b218ed68c8bd5f2a56f8/href">https://medium.com/media/2092eb4630f4b218ed68c8bd5f2a56f8/href</a></iframe><p>src為<strong>Original Image</strong>中梯形的座標點</p><p>dst為<strong>Perspective Image</strong>中矩形的座標點</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NZAbL-ET7u2jWhL4T-FNA.png" /></figure><pre>M = cv2.getPerspectiveTransform(src, dst)</pre><p><strong>M</strong>為cv2.getPerspectiveTransform求得的<strong>轉換矩陣</strong>，今後只要利用這個轉換矩陣就可以輕鬆地把Original Image轉成Perspective Image</p><pre>perspective_img = cv2.warpPerspective(img, M, img_size)</pre><p>將<strong>Original Image</strong>及<strong>轉換矩陣M</strong>放入<strong>cv2.warpPerspective</strong>後，可求得<strong>perspective_img</strong></p><blockquote>Step 4.<strong> </strong>用<strong>二次回歸</strong>求得車道線</blockquote><p>經過Step2, Step3後，可以求得<strong>只有邊緣的車道線鳥瞰圖</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce0fe9f43d1c4cdb6fc226b971e0e88e/href">https://medium.com/media/ce0fe9f43d1c4cdb6fc226b971e0e88e/href</a></iframe><p>藉由<strong>find_lane_pixel()</strong>此函式，可將圖切成<strong>兩邊</strong>，一邊有<strong>九個window</strong>，透過這些window來<strong>偵測車道線的pixel</strong>。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ttOQvcJmKgeJSzsu7kZAPQ.png" /></figure><pre>left_fit = np.polyfit(lefty, leftx, 2)<br>right_fit = np.polyfit(righty, rightx, 2) <br>left_fitx = left_fit[0]*ploty**2 + left_fit[1]*ploty + left_fit[2] right_fitx = right_fit[0]*ploty**2 + right_fit[1]*ploty + right_fit[2]</pre><p>將<strong>車道線的pixel</strong>放入<strong>np.polyfit()</strong>函式中，運算後可得<strong>車道線的回歸曲線</strong></p><blockquote>Step 5.<strong> </strong>求得<strong>曲率</strong>，判斷彎道方向</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*8PQAbIe5s52hVkvqD-wB8A.png" /></figure><p>利用Step 4求得的車道線方程式，求出車道線的<strong>曲率</strong>，完成後把它加入影像中，<strong>這樣就大功告成了</strong>。</p><pre>left_curverad = ((1 + (2*left_fit_cr[0]*y_eval*ym_per_pix + left_fit_cr[1])**2)**1.5) / np.absolute(2*left_fit_cr[0]) </pre><pre>right_curverad = ((1 + (2*right_fit_cr[0]*y_eval*ym_per_pix + right_fit_cr[1])**2)**1.5) / np.absolute(2*right_fit_cr[0])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPBY9FPZf-_DC6eL4EmkFA.jpeg" /></figure><h4>心得</h4><p><strong>Project 2-Advanced Lane finding</strong>是最後一個完成的Project，第一次交的時候有很多不足的地方，像是遇到陰影時無法持續追蹤車道線，曲率計算錯誤等等，結果當然就是被退件摟!</p><p>然而Udacity退件後，助教也提供了很多實用的建議給我，也讓我順利完成這個Project，我想這才是這個平台最難能可貴的地方吧!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a93ee20c1275" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Driving Car Project1- Lane Finding 介紹]]></title>
            <link>https://medium.com/@bob800530/self-driving-car-project1-lane-finding-%E4%BB%8B%E7%B4%B9-9b57ca14e60c?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b57ca14e60c</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Tue, 12 Mar 2019 15:30:24 GMT</pubDate>
            <atom:updated>2019-03-14T14:24:00.325Z</atom:updated>
            <content:encoded><![CDATA[<h3>Self-Driving Car Project1- <strong>Lane Finding實作</strong></h3><p>Lane Finding</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIVJBh6mqMcQ%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIVJBh6mqMcQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIVJBh6mqMcQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a69c859d1a38931cd2b7fde444455e7e/href">https://medium.com/media/a69c859d1a38931cd2b7fde444455e7e/href</a></iframe><p><strong>Github: </strong><a href="https://github.com/bob800530/Find_lane_line"><strong>https://github.com/bob800530/Find_lane_line</strong></a></p><h4>簡介</h4><p>本魯最近買了一台Mazda CX-5，這台車具備了車道偏移警示的功能，識別上還滿準確的。也因如此，在做這個Project時，特別地有感觸，也好奇做出來的東西，會不會跟車上那台車道攝影機一樣厲害。（以上絕非置入ＸＤ）</p><p>這是Self-Driving Car的第一個Project，剛開始還不熟悉時，常常把路邊的草跟白色的車當成車道線，想藉由調高Threshold的方式來偵測車道又常常偵測不到。</p><p>後來把先前上過的課程<strong>耐心地</strong>重新複習一遍，並加入多種影像處理後，才一步步完成，其中會運用<strong>灰階</strong>、<strong>高斯模糊</strong>、<strong>邊緣偵測</strong>、<strong>霍夫轉換</strong>等演算法。並非想像中的直觀，在這過程中讓我了解到</p><blockquote>＂對於一個軟體工程師而言，耐心也是相當重要滴＂</blockquote><h4>程式碼</h4><p><strong>Github: </strong><a href="https://github.com/bob800530/Find_lane_line/blob/master/P1.ipynb"><strong>https://github.com/bob800530/Find_lane_line/blob/master/P1.ipynb</strong></a></p><p><strong>1.Converted the images to grayscale:</strong> OpenCV將圖片由RGB轉成灰階</p><pre><strong>def</strong> grayscale(img):<br>    <strong>return</strong> cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*b-yaa23PxLoQyywIo6Dfvw.jpeg" /></figure><p><strong>2.Use GaussianBlur to filter noise in image:</strong> 低通濾波器GaussianBlur濾除雜訊</p><pre><strong>def</strong> gaussian_blur(img, kernel_size):<br>    <em>&quot;&quot;&quot;Applies a Gaussian Noise kernel&quot;&quot;&quot;</em><br>    <strong>return</strong> cv2.GaussianBlur(img, (kernel_size, kernel_size), 0)</pre><p><strong>3.Use Canny to detect the edges of image:</strong> Canny演算法是一個複合性的邊緣偵測演算法，結合了<strong>Gaussian Filter</strong>、<strong>梯度偵測、非最大值抑制、判斷邊界</strong>四個演算法去實踐邊緣偵測</p><pre><strong>def</strong> canny(img, low_threshold, high_threshold):<br>    <em>&quot;&quot;&quot;Applies the Canny transform&quot;&quot;&quot;</em><br>    <strong>return</strong> cv2.Canny(img, low_threshold, high_threshold)</pre><p><strong>4.Use a four sided polygon to mask two lane lines: </strong>僅偵測車道線可能會出現的那個矩形</p><pre><strong>def</strong> region_of_interest(img, vertices):<br>    <em>...</em><br>        <br>    <em>#filling pixels inside the polygon defined by &quot;vertices&quot; with the fill color    </em><br>    cv2.fillPoly(mask, vertices, ignore_mask_color)<br>    <br>    <em>#returning the image only where mask pixels are nonzero</em><br>    masked_image = cv2.bitwise_and(img, mask)<br>    <strong>return</strong> masked_image</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*myoFHrLBl-AeMF35Yied8A.png" /></figure><p><strong>5.Use Hough to find two lane lines: </strong>運用Hough轉換，在球坐標系中找線</p><pre><strong>def</strong> hough_lines(img, rho, theta, threshold, min_line_len, max_line_gap):<br>    <em>&quot;&quot;&quot;</em><br><em>    `img` should be the output of a Canny transform.</em><br><em>        </em><br><em>    Returns an image with hough lines drawn.</em><br><em>    &quot;&quot;&quot;</em><br>    <strong>lines = cv2.HoughLinesP(img, rho, theta, threshold, np.array([]), minLineLength=min_line_len, maxLineGap=max_line_gap)</strong><br>    line_img = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8)<br>    draw_lines(line_img, lines)<br>    <strong>return</strong> line_img</pre><p><strong>6. Extend two land lines: </strong>延伸車道線增加視覺效果</p><p>運用高中所學的<strong>點斜式</strong>延伸所偵測到的直線，完成一張圖片的車道辨識。</p><p>影片則可視為多個圖片的組成，亦可藉由這個pipeline 求出車道線。</p><pre><strong>def</strong> draw_extend_line(extend_img,x1, y1, x2, y2):   <br>    m =  (y2-y1) / (x2 - x1)<br>    bot_d = 540 - y1<br>    top_d = y1 - 350<br>    <strong>if</strong> abs(m)&gt;.3 <strong>and</strong> abs(m)&lt;3:  <br>        bot_x = int(x1 + bot_d/m);<br>        top_x = int(x1 - top_d/m);     <br>        cv2.line(extend_img,(bot_x,540),(top_x,350),(255,0,255),10)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*mBZFCC_AGjwxYB_21q7G4w.jpeg" /></figure><h4>結論</h4><p>才第一個Project就學到這麼多影像處理的技巧，一方面覺得這堂課真的太硬了，另一方面又覺得<strong>999美金</strong>花的好值得阿!!! 或許這就是用自己薪水付學費的好處吧。呵呵</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b57ca14e60c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Udacity Self-Driving Car 感想]]></title>
            <link>https://medium.com/@bob800530/udacity-self-driving-car-%E6%84%9F%E6%83%B3-34b25a8a8848?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/34b25a8a8848</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Tue, 12 Mar 2019 12:57:53 GMT</pubDate>
            <atom:updated>2019-08-29T15:52:25.866Z</atom:updated>
            <content:encoded><![CDATA[<h3>Udacity Self-Driving Car term1 課後感想</h3><p>充實 夢想 熱情</p><h4>簡介</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*px1DhpnRRKhMF4fFcgduJQ.jpeg" /></figure><p>四個月前小弟在網路上看到了一個關於道路偏移＋物件偵測的影片，當時我把它紀錄起來並寫成一篇<a href="https://medium.com/@bob800530/opencv-tensorflow-%E9%81%93%E8%B7%AF%E5%81%8F%E7%A7%BB-%E7%89%A9%E4%BB%B6%E5%81%B5%E6%B8%AC%E5%BD%B1%E7%89%87%E8%BD%89%E8%BC%89-b424ec20b2ab"><strong>分享文</strong></a>。</p><p><a href="https://medium.com/@bob800530/opencv-tensorflow-%E9%81%93%E8%B7%AF%E5%81%8F%E7%A7%BB-%E7%89%A9%E4%BB%B6%E5%81%B5%E6%B8%AC%E5%BD%B1%E7%89%87%E8%BD%89%E8%BC%89-b424ec20b2ab">[Opencv + Tensorflow] 道路偏移+物件偵測影片轉載</a></p><p>而後我上網查了一些關於自動駕駛的資訊，意外發現Udacity有堂名為<a href="https://classroom.udacity.com/courses/ud013-preview/lessons/c3bf3e77-b094-45f4-857b-0ab6d332dabe/concepts/abf9f517-99ca-4fbb-9553-c833f6e503c2">Self-Driving Car</a>的課程，這堂課是由一個名為Sebastian Thrun的工程師所建立，Sebastian曾經領導過Google X 內的自駕車專案，這門課有別於一般的線上課程，加入了許多實作練習，讓每一位學生都能都投入其中，並且真正學到自動駕駛會用到的技術。</p><p>看到這邊我實在讓我很心動，不過價格實在有點高阿~~<strong> 999美金，我的老天鵝阿!</strong>，猶豫了三天後，我還是註冊下去了，<strong>這999美金是阻擋不了我對自動駕駛的熱情的。</strong></p><blockquote><strong>人生有夢，築夢踏實</strong></blockquote><h4>心得</h4><p>本魯為一位普通的軟體工程師，平時上班已經耗了一大半的力氣，下班後還需要完成<a href="https://classroom.udacity.com/courses/ud013-preview/lessons/c3bf3e77-b094-45f4-857b-0ab6d332dabe/concepts/abf9f517-99ca-4fbb-9553-c833f6e503c2">Self-Driving Car</a>的課程，在這期間我犧牲了許多與朋友、家人相處的時光，一方面感受到專案進度的壓力，另一方面又覺得自己為什麼要搞得自己那麼辛苦?</p><blockquote><strong>一切都是因為熱情阿!!! 兄弟</strong></blockquote><p>堅持下去的結果，就是<strong>&quot;變強”</strong>，這堂課有非常多的實作課程，一共有五個project需要完成</p><ol><li><a href="https://medium.com/@bob800530/self-driving-car-project1-lane-finding-%E4%BB%8B%E7%B4%B9-9b57ca14e60c"><strong>Lane Finding</strong></a><strong>: </strong>運用python, openCV及基本的影像處理，完成車道偵測。</li><li><a href="https://medium.com/@bob800530/self-driving-car-project-2-advanced-lane-finding-%E5%AF%A6%E4%BD%9C-a93ee20c1275"><strong>Advanced Lane Finding</strong></a><strong>:</strong>加入更多影像處理演算法，如: Canny, Hough等等，使車子能辨認更多變的車道。</li><li><a href="https://medium.com/@bob800530/self-driving-car-project-3-%E4%BA%A4%E9%80%9A%E8%99%9F%E8%AA%8C%E8%BE%A8%E8%AD%98%E5%AF%A6%E4%BD%9C-8ad4e0a3b38d"><strong>Traffic Sign Classifier</strong></a><strong>:</strong>運用Google的Tensorflow API識別交通號誌</li><li><a href="https://medium.com/@bob800530/self-driving-car-project-4-%E8%87%AA%E5%8B%95%E9%A7%95%E9%A7%9B%E5%AF%A6%E4%BD%9C-9921e79b4fd"><strong>Behavioral Cloning</strong></a><strong>: </strong>運用 Keras訓練遊戲中的汽車駕駛行為，訓練出來的模型需能夠跑完一圈，不偏離車道。</li><li><a href="https://medium.com/@bob800530/self-driving-car-project-5-%E5%8D%A1%E7%88%BE%E6%9B%BC%E6%BF%BE%E6%B3%A2%E8%88%87%E8%87%AA%E9%A7%95%E8%BB%8A%E7%9A%84%E9%81%8B%E7%94%A8-3c324e656d5d"><strong>Extended Kalman Filter</strong></a><strong>: </strong>利用卡爾曼濾波器，處理自動車上的各種Sensor的偵測誤差，達到預測路徑的目的。</li></ol><p>以上五個Project，大多都是用Python完成，對於平常只會C/C++的我，可說是非常吃力，要用一個不熟悉的語言，完成自己不曾接觸過的事物。</p><blockquote>最後能完成，其實連我自己都有點意料之外</blockquote><p>這門課不僅僅讓我知道該如何在短時間內學習一個新的程式語言，也讓我體悟到，<strong>”人生不能只打穩贏的仗”、</strong>&quot;<strong>只要不放棄，一切都有可能&quot;</strong>，身為一個工程師，就是要有不懼困難的精神，接下來的五篇網誌，我會一一向大家介紹各個Project是如何完成的，及其中的歷程。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34b25a8a8848" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Python]Gaussian Filter-概念與實作]]></title>
            <link>https://medium.com/@bob800530/python-gaussian-filter-%E6%A6%82%E5%BF%B5%E8%88%87%E5%AF%A6%E4%BD%9C-676aac52ea17?source=rss-ccc14e7dd816------2</link>
            <guid isPermaLink="false">https://medium.com/p/676aac52ea17</guid>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[天道酬勤]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 16:18:59 GMT</pubDate>
            <atom:updated>2018-12-02T16:18:59.298Z</atom:updated>
            <content:encoded><![CDATA[<p>實作 Gaussian Filter</p><h3>前言</h3><p>作影像處理的專題時，時常看到 <strong>Gaussian Filter</strong>，究竟何謂<strong>Gaussian Filter</strong>呢? 這篇文章將會從<strong>概念帶入到實作</strong>一一為大家解答。</p><blockquote>要弄懂Gaussian Filter之前，一定要弄懂 <strong>Image Filter</strong>及<strong>高斯函數</strong>，以下是傳送門!</blockquote><p><strong>1.一維高斯函數</strong>:</p><p><a href="https://medium.com/@bob800530/python-gaussian-noise-6e69d0787c25">Python - Gaussian noise</a></p><p><strong>2.Image Filter</strong>:</p><p>影像處理的領域中，存在許多不同種類的濾波器，大致上可以分成以下兩種</p><p>a.<strong>平滑化(濾除雜訊):</strong>均值濾波器, 中值濾波器, <strong>Gaussian Filter</strong></p><p>b.銳化(強化邊緣): Laplace Filter, Sobel Filter</p><p>有興趣的人可以參考<a href="http://ccy.dd.ncu.edu.tw/~chen/course/vision/ch5/ch5.htm"><strong>空間濾波</strong></a>這個網站，其中介紹了多種濾波器及程式碼</p><h3><strong>概念</strong></h3><p>剛開始接觸 Gaussian Filter ，不斷地從Gaussian Filter的數學式去探究它的原理</p><p>後來發現從<strong>用途-</strong>&gt;<strong>生成矩陣</strong>-&gt;<strong>數學式</strong>反推去理解Gaussian Filter才是最快的方式。</p><h4>1. Gaussian Filter的用途</h4><p><strong>減少圖像雜訊</strong>以及<strong>降低細節層次</strong>，其視覺效果就像是經過一個半透明屏幕在觀察圖像。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*vKlJ1z2sGrD-FHItEqOhgA.png" /><figcaption><strong>經過Gaussian Filter後的圖像</strong></figcaption></figure><blockquote><strong>為何Gaussian Filter能夠將圖形模糊化呢?</strong></blockquote><h4>2. Gaussian Filter矩陣</h4><p>以下<strong>近似3*3 Gaussian Filter</strong>的<strong>generalized weighted smoothing filter</strong>矩陣， 圖像與<strong>3*3 Gaussian Filter</strong>做卷積將會達到<strong>濾除雜訊</strong>、<strong>低通</strong>、<strong>模糊化</strong>的效果。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/159/1*YglKeZTo6RlGPthPSjmBHw.png" /><figcaption><strong>generalized weighted smoothing filter</strong></figcaption></figure><blockquote><strong>為何對這個矩陣卷積就能將圖片模糊化?</strong></blockquote><p>卷積後會從九個點變一個點，當然會模糊化阿!!</p><blockquote><strong>為何九個點變一個點，但是我的圖片的總尺寸依然不變?</strong></blockquote><p>簡單來說圖片的每一點都會跟矩陣的中心點卷積一次，也就是Sliding window的概念。邊角的點，由於周圍沒有點可以卷積，則補0。若想進一步了解我相當推薦以下這個教學影片。</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FC_zFhWdM4ic%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DC_zFhWdM4ic&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FC_zFhWdM4ic%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/018c6f9b30ec2b3a418059ced82bd295/href">https://medium.com/media/018c6f9b30ec2b3a418059ced82bd295/href</a></iframe><blockquote><strong>如果要將圖片模糊化，為何不9個點相加除以9就好了?</strong></blockquote><p>不論是對任何圖像作低通，都不希望圖像<strong>失真</strong>，而<strong>降低圖像失真</strong>最好的辦法就是<strong>增加圖像中心點的權重</strong>，所以中心點的權重最高，越往邊角權重就越低!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/152/1*XdEg-1NI9EGNK3O0O_av7Q.png" /><figcaption>全平均矩陣</figcaption></figure><blockquote><strong>那該如何決定權重的比例呢?</strong></blockquote><p>好問題! 讓我們看第三點<strong>Gaussian Filter數學函式</strong></p><h4>3. Gaussian Filter數學函式</h4><p>實際的<strong>Gaussian Filter</strong>由此方程式產生</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*2xnfNXq_unnHzOQHJgpP3A.png" /><figcaption>Gassian Function</figcaption></figure><p>簡化計算，假設sigma = 0.707(根號0.5)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*RJpQtrtRrOy2C1bvnZeYZA.png" /><figcaption>Gassian Function, sigma = 1</figcaption></figure><p>Gaussian Filter的中心點(x,y)須為(0,0)，下例為一個3*3的(x,y)值矩陣</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/259/1*xS_sqenLZFDuGAdST2mIpw.png" /><figcaption>Gassian Function, sigma = 1</figcaption></figure><p>將此矩陣的x,y值套入<strong>Gaussian Function</strong>並<strong>正規化</strong>後就可以得到3*3的<strong>Gaussian filter</strong>了!</p><p>計算過程請點此<a href="https://docs.google.com/spreadsheets/d/1HDosoi3RrPLLogbDzuii-rSVCQZs1XLkuVzP_8bR-J0/edit?usp=sharing"><strong>連結</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*jT161zGZgYUg-hp-Nk88iQ.png" /><figcaption>3*3 Gaussian filter</figcaption></figure><p>得到高斯函數後，就可以開始對圖像作<strong>卷積</strong>摟，若想知道<strong>卷積</strong>詳細原理，請容我再次推薦這部影片:<a href="https://www.youtube.com/watch?v=C_zFhWdM4ic"><strong>How Blurs &amp; Filters Work — Computerphile</strong></a>!!</p><h3>實作</h3><p>分成兩個部分來介紹</p><ol><li>如何產生Gaussian Filter矩陣?</li><li>如何用此Gaussian Filter矩陣，對圖片卷積，效果為何 ?</li></ol><blockquote><strong>如何產生Gaussian Filter矩陣?</strong></blockquote><p>為了提升可讀性，假設sigma = 0.707(根號0.5)，得到以下方程式</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*RJpQtrtRrOy2C1bvnZeYZA.png" /><figcaption>Gassian Function, sigma = 1</figcaption></figure><p>與Gaussian Filter卷積後會進行正規化，前面的常數1/(2*pi)也不用考慮</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/197/1*tPYJWuiPp3eVf2g0MM1FqQ.png" /></figure><p><strong><em>以下為程式碼與執行結果</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/431332546090642a4f17535281240a55/href">https://medium.com/media/431332546090642a4f17535281240a55/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*LwaFjoTlJ0D-q1FdogtiPQ.png" /></figure><p>跑完結果後，別忘了打開Gaussian Kernel與上述的3*3 Gaussian Filter比較看看是否一樣歐!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*9MwIPoRHoPTyRUK4SMVG4Q.png" /><figcaption>3*3 Gaussian Kernel</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*jT161zGZgYUg-hp-Nk88iQ.png" /><figcaption>3*3 Gaussian filter</figcaption></figure><blockquote><strong>如何用此Gaussian Filter矩陣，對圖片卷積，效果為何 ?</strong></blockquote><p>此照片從<a href="https://www.flickr.com/photos/37195641@N03/14141670382/sizes/n/">Flicker的可商業用途圖片</a>取材，原圖中的陽光灑在青綠色的草地上相當的美</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*9vTyATWMyuRwTu0A5t7y5A.jpeg" /></figure><p>為了實驗Gaussian Filter，我在圖片中加了些雜訊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*K2DysNdJf_-CfEm_x1cCMw.jpeg" /><figcaption>加入雜訊</figcaption></figure><p>Gaussian Filter能夠有效的模糊及去雜訊，那就試試看吧!!</p><p><strong>Step 1: </strong>為了讓讀者更容易體解，先將圖片轉成灰階，把RGB簡化成灰階，這樣便不用對RGB做三次convolution</p><pre>gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*LST6Dd5WX-R2QzO7qXaIOw.jpeg" /><figcaption>雜訊+灰階</figcaption></figure><p><strong>Step2: 用剛剛求得的 3*3 </strong>gaussian_kernel對圖片做Convolution</p><pre>grad = signal.convolve2d(gray, gaussian_kernel, boundary=’symm’, mode=’same’)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*3_OMaqKGeWIeWl6-SiYCug.jpeg" /><figcaption>濾除雜訊+灰階</figcaption></figure><p>相較於使用Gaussian Filter前的圖片的確<strong>少了很多顆粒感</strong>，但也<strong>變模糊</strong>了，正因如此，才需要理解Gaussian Filter的理論，sigma該怎麼調?該用幾乘幾的Gaussian Filter? 是否該結合其他的影像處理技術?，這些都相當值得探討，未來我也會將新學到的技術PO到網誌上與大家分享!!</p><p><strong><em>以下為程式碼</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bfe088fbf74c73eb2584b6d4c964485/href">https://medium.com/media/6bfe088fbf74c73eb2584b6d4c964485/href</a></iframe><h3>參考文獻</h3><p><a href="https://morvanzhou.github.io/tutorials/data-manipulation/plt/3-5-3d/">3D 数据 - Matplotlib | 莫烦Python</a></p><p><a href="http://subsurfwiki.org/wiki/Gaussian_filter">http://subsurfwiki.org/wiki/Gaussian_filter</a></p><ul><li><a href="http://jermmy.xyz/2017/10/28/2017-10-28-mutil-modal-gaussian/">多维高斯分布</a></li><li><a href="http://jermmy.xyz/2017/03/19/2017-3-19-covariance-matrix/">协方差矩阵</a></li><li><a href="https://blog.csdn.net/ZYTTAE/article/details/41087179">二维高斯函数 - ZYTTAE的专栏 - CSDN博客</a></li><li><a href="https://zh.wikipedia.org/wiki/%E9%AB%98%E6%96%AF%E6%A8%A1%E7%B3%8A">高斯模糊 - 维基百科，自由的百科全书</a></li></ul><p><a href="http://ccy.dd.ncu.edu.tw/~chen/course/vision/ch5/ch5.htm">http://ccy.dd.ncu.edu.tw/~chen/course/vision/ch5/ch5.htm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=676aac52ea17" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>