<?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 Kae-Yang Hsieh on Medium]]></title>
        <description><![CDATA[Stories by Kae-Yang Hsieh on Medium]]></description>
        <link>https://medium.com/@sunny-hsieh?source=rss-6f4054940e1e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OkfIpwUThrJQ-g_-E46DXA.png</url>
            <title>Stories by Kae-Yang Hsieh on Medium</title>
            <link>https://medium.com/@sunny-hsieh?source=rss-6f4054940e1e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 15:38:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sunny-hsieh/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[2023 iQuHack — Covalent x IBM Challenge]]></title>
            <link>https://sunny-hsieh.medium.com/2023-iquhack-covalent-x-ibm-challenge-e22d799abd80?source=rss-6f4054940e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e22d799abd80</guid>
            <dc:creator><![CDATA[Kae-Yang Hsieh]]></dc:creator>
            <pubDate>Sun, 29 Jan 2023 14:38:19 GMT</pubDate>
            <atom:updated>2023-01-29T14:50:32.797Z</atom:updated>
            <content:encoded><![CDATA[<h3>2023 iQuHack — Covalent x IBM Challenge</h3><h3>Introduction</h3><p>PyRoute is a user-centric route optimization and itinerary scheduling solution developed by AmplifiQation.</p><p>Adaptable, and engineered for scalability, PyRoute delivers quantum enhanced tools for:</p><ul><li>Evening and hang-out planning;</li><li>Vacation and business-trip scheduling;</li><li>and logistics and supply-chain management.</li></ul><h3>The Quantum Components</h3><p>pyROUTE leverage fundamental quantum computing principles to accelerate optimization.</p><h3>Random Number Generation</h3><p>By preparing and measuring a Bell State, pyROUTE empowers the user with the truly random options.</p><h3>Quantum-enhanced TSP (traveling salesman problem) solver</h3><p><a href="https://github.com/armorsun/AmplifiQation/blob/main/Quantum%20Enhanced%20TSP%20-%20AmplifiQation.pdf">The quantum-enhanced TSP explanation paper.</a></p><p>By running the Dürr and Høyer algorithm [1] on precomputed Hamiltonian cycles, pyROUTE provides a quantum-enhanced routing optimizer.</p><p>[1] C. Dürr and P. Høyer, “A Quantum Algorithm for Finding the Minimum,” 1996. <a href="https://arxiv.org/abs/quant-ph/9607014">https://arxiv.org/abs/quant-ph/9607014</a>.</p><h3>Teams</h3><p><a href="https://github.com/armorsun/AmplifiQation">PyRoute</a> was developed during MIT iQuHACK 2023 by the AmplifiQation team. More on iQuHACK 2023 <a href="https://www.iquise.mit.edu/iQuHACK/2023-01-27">here</a>.</p><p><a href="https://www.linkedin.com/in/michael-luciuk/">Michael Luciuk</a> (University of Toronto)<br><a href="https://www.linkedin.com/in/chait27/">Chaitanya Kumar Mahajan</a> (University of Toronto)<br><a href="https://www.linkedin.com/in/sunnyhsieh/">Kae-Yang Hsieh</a>(Northeastern University)<br><a href="https://www.linkedin.com/in/veronica-lekhtman-78a2a11b3/">Veronica Lekhtman</a> (Northeastern University)<br><a href="https://www.linkedin.com/in/karishmabhargava-19142123a/">Karishma Bhargava</a> (Northeastern University)</p><h3>iQuHACK 2023</h3><p>iQuHACK is a faced-paced, valuable learning experience accessible to all levels of quantum experience. The AmplifiQation team highly recommends you consider applying for further.</p><p>iQuHACK was made possible by a dedicated organizing committee and generous sponsor supports.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e22d799abd80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving N-Queens Puzzle with Q#]]></title>
            <link>https://sunny-hsieh.medium.com/solving-n-queens-puzzle-with-q-f940b563ee6a?source=rss-6f4054940e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f940b563ee6a</guid>
            <dc:creator><![CDATA[Kae-Yang Hsieh]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 05:43:22 GMT</pubDate>
            <atom:updated>2022-12-14T05:49:51.930Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-3sq5xTmnpjlND-4eNfYw.jpeg" /></figure><p><em>This is a project in the Intro to Quantum Computing course instructed by Professor Mariia Mykhailova</em> <em>at Northeastern University.<br>This post is part of the </em><a href="https://devblogs.microsoft.com/qsharp/q-holiday-calendar-2022/"><em>Q# Holiday Calendar 2022</em></a><em>. Check out the calendar for more great posts!</em></p><h3>What’s the puzzle we are going to solve?</h3><p>In the rules of chess, a queen can move horizontally, vertically, or diagonally to any vacant square on the board. The N-Queens puzzle applies this same rule and challenges players to place N queens on an N x N chessboard without allowing any two queens to attack each other.</p><p>This puzzle was first introduced in the 19th century, and it is NP-complete.</p><p>The project also introduced a variation of the N-Queens puzzle called the N-Queens² puzzle. In this version, every square on the board is occupied by a queen, but there are N different colors of queens, and queens of the same color cannot attack each other.</p><figure><img alt="A valid solution when N = 5, each queen cannot attack each other." src="https://cdn-images-1.medium.com/max/1024/1*af4lD6CmpSK-fNSQP_NrOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJTSJrxYWiU6lH8y7NjULg.png" /><figcaption>A valid solution when N = 5 for standard N-Queens (left) and N-Queens² (right). Each queen with the same color cannot attack the other.</figcaption></figure><h3>Traditional Solution</h3><p>A backtracking algorithm is used to solve the puzzle, and the highest order that has been solved is 27. The time complexity is O(N!), and the space complexity is O(N). A list of solutions is the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*QZBE9tABbhXc_NEXTHfgjA.png" /></figure><h3>Quantum solution</h3><p>Grover’s search algorithm is used to solve the two puzzles, and the steps are described below. Most of the steps are referred from [1].</p><p><strong>N-Queens Puzzle</strong></p><p>The solutions to the puzzle are specific permutations of a N x N chessboard. They can be described with three constraints. First, each row has only one queen. Second, each column has only one queen. Last, each diagonal has either zero or one queen.</p><p>To prepare for the initial state, N x N qubits are allocated to represent a chessboard. A ⎸0⟩ state indicates an empty square, and a ⎸1⟩ state indicates a queen is placed on the square. The initial state of a chessboard when N = 4 can be represented as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/118/1*fY1rgvCtS6HTOVWspgsMMg.png" /></figure><p>Then, the row constraint can be prepared to a W state, which guarantees a row has only one queen. For example, when N = 4, a queen could be in one of the four positions in a row as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*Tf3xmgB7DL57elRr6Y3tOg.png" /></figure><p>The preparation of the W state can be found in <a href="https://github.com/microsoft/QuantumKatas/blob/main/Superposition/Workbook_Superposition_Part2.ipynb">QuantumKatas</a> [5].<br>There are 4 rows, and the state of the chessboard can be represented as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*xrwJwH8oMGIlTworGuKpDg.png" /></figure><p>After the row constraint state is prepared, an oracle is created to apply the restrictions. The results of the column and diagonal checks are stored in the auxiliary qubits. The target qubit will be flipped when the restrictions are fulfilled, which means the auxiliary qubits are all in the ⎸1⟩ state.</p><p>The column constraint is checked by applying a controlled X gate on each square in the same column. The auxiliary qubits will be in the ⎸1⟩ state if the sum of the queens is odd. Since each row state ensures that there are a total of N queens on the board, if any one of the columns has an odd number of queens greater than one, then there must be two or more columns with no queens, and the corresponding auxiliary qubits will be in the ⎸0⟩ state.</p><p>Furthermore, only N-1 columns need to be examined, that is, only N-1 auxiliary qubits need to be allocated. If N 1s add up to N and 0 exists among them, then there must have an even number of 0s. It is impossible that the first N-1 column satisfies the requirement, but the last column has no queen or two more queens. So, only N-1 columns need to be checked. The following figures show how column checks are performed and an example that the column constraint is not satisfied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*6yF5SK-HJAlL4olZFGN8Zg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0osKsk3MNRoVLCi8UZqo3w.png" /><figcaption>The process of column check (left), and a result that the column constraint is not satisfied (right).</figcaption></figure><p>Next, diagonal verifications proceeded between each pair of rows. There are N ⨉ (N-1) / 2 such checks that need to be performed, and the results are stored in auxiliary qubits. The auxiliary qubits are initialized in the ⎸1⟩ states. If two queens are in the same diagonal pair, the corresponding auxiliary qubit will be flipped to the ⎸0⟩ state by a CCNOT gate. If all the auxiliary qubits remain in the ⎸1⟩ state, it means that the diagonal requirement is satisfied. Because each row has only one queen, it is impossible to have more than one diagonal pair of queens, so the auxiliary qubits will not be flipped more than once. The following animation shows examples of diagonal checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Q5dvJyKFKMETRCkYTKJP6A.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*p3BpexmtTN5IVuAN7S7TKg.gif" /><figcaption>The procedure of the checks between each pair of rows (left) and the application of the CCNOT gate (right).</figcaption></figure><p>Finally, the two auxiliary qubit arrays for the column and diagonal checks are concatenated and used to control the target qubit in the oracle. The target qubit will be flipped if all the requirements are satisfied, which indicates that a valid solution to the N-Queens puzzle has been found.</p><pre>// psuedo code<br>operation OracleNQueensConstraint (register: Qubit[], target: Qubit) : Unit is Adj{        <br>      use auxQCol = Qubit[nQueens - 1];<br>      use auxQDia = Qubit[(nQueens * (nQueens - 1)) / 2];<br>      <br>      within {<br>          checkColumn();<br><br>          ApplyToEachA(X, auxQDia);<br>          checkDiagonal();<br>      } apply {<br>          Controlled X(auxQCol + auxQDia, target);<br>      }<br>}</pre><p><strong>N-Queens² Puzzle</strong></p><p>The solutions to the N-Queens² puzzle are also particular permutations of the N ⨉ N chessboard. It requires that each row, column, and diagonal on the chessboard contain queens of different colors.</p><p>To represent the different colors of the queens, multiple qubits are used to represent one queen. For example, when N = 5, three qubits are used to represent the 5 different colors from 0 to 4 using little-endian notation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*IkfmriNDFnxA6crqVplD3w.png" /><figcaption>An example of the conversion from decimal to little endian binary format</figcaption></figure><p>The first step is to allocate N by N by M-color-bit qubits to represent each square on a chessboard. Where N is the number of queens, and M is the number of qubits needed to represent a color.</p><p>Then, each row can be prepared as a combination of different colors of queens. For example, when N = 3, one of the possible row combinations can be represented as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*GgXnwXVNPIjC-N5TxuVJ5Q.png" /></figure><p>As a result, each row has only one queen per color.<br>The preparation of the row state can be found in <a href="https://github.com/microsoft/QuantumKatas/blob/main/Superposition/Workbook_Superposition_Part2.ipynb">QuantumKatas</a> [5].</p><p>There are 3 rows on a chessboard, so the chessboard can be represented as,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*OBpXZbcM6myKmOZ92SXcNg.png" /></figure><p>Similar to the N-Queens puzzle, auxiliary qubits are used in the oracle to store the results of column and diagonal checks. However, this expands to include each color per column. An auxiliary qubit is flipped to ⎸1⟩ when the number of queens of the same color on a column is even. Each column requires N auxiliary qubits to perform the check, and a total of N ⨉ (N-1) qubits are needed for all columns.</p><p>The row state preparation ensures that the colors on each row are different. If one of the columns has an odd number of queens of the same color, there must be at least two columns with no queens of that color. Therefore, only N-1 columns need to be examined, and only N ⨉ (N-1) auxiliary qubits need to be allocated. It is impossible for N-1 columns to have no repeated colors but for the last column to have repeated colors of queens. Figure 6 shows how column checks are performed when N = 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*I9UgAlAAFjAHJzqzA2A_kA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*tpwGnsWtcGvIfy8tR1mVqQ.png" /><figcaption>The process of column check (left), and a result that the column constraint is not satisfied (right).</figcaption></figure><p>Next, diagonal verifications are performed between each pair of rows per color. There are N ⨉ N ⨉ (N-1) / 2 such checks that need to be performed, and the results are stored in auxiliary qubits. These qubits are initialized in the ⎸1⟩ state. If two queens of the same color are on the same diagonal, the corresponding auxiliary qubit is flipped to the ⎸0⟩ state using a controlled bit string gate. If all auxiliary qubits remain in the ⎸1⟩ state, it means that the diagonal requirement has been satisfied. Because each row and column has only one queen per color, it is impossible to have more than one diagonal pair of queens with the same color, so the auxiliary qubits will not be flipped more than once. The following videos are the process of diagonal checks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qunD0EmdeJQHBU4MonPmuQ.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*m-KRrXU-6kkpNz7gS4ybdQ.gif" /><figcaption>The procedure of the checks between each pair of rows (left) and the application results of the controlled bit string gate (right).</figcaption></figure><p>To finish, the two arrays of auxiliary qubits for the column and diagonal checks are combined and used to control the target qubit in the oracle. If all requirements are satisfied, the target qubit will be flipped, indicating that a valid solution to the N-Queens<strong>²</strong> puzzle has been found.</p><pre>// psuedo code<br>operation OracleNQueensSquareConstraint (register: Qubit[], target: Qubit) : Unit is Adj{        <br>      use auxQCol = Qubit[nQueens * (nQueens - 1)];<br>      use auxQDia = Qubit[nQueens * (nQueens * (nQueens - 1)) / 2];<br>      <br>      within {<br>          checkColumn();<br><br>          ApplyToEachA(X, auxQDia);<br>          checkDiagonal();<br>      } apply {<br>          Controlled X(auxQCol + auxQDia, target);<br>      }<br>}</pre><h3>Analysis</h3><p><strong>N-Queens</strong></p><ul><li>The search space size is Nᴺ while each row has N possible combinations, and there are N rows.</li><li>The qubits allocated explicitly are:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*zt7VFusEDG5xNu8XgF7YDA.png" /></figure><ul><li>The operations needed for columns: N ⨉ (N-1)</li><li>The operations needed for diagonal:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*BsccpraiDCE05yRcrVmxaw.png" /></figure><p>N-Queens<strong>²</strong></p><ul><li>The search space size is N!ᴺ while each row has N! possible combinations, and there are N rows.</li><li>The qubits allocated explicitly are:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*x0V-_3RHmNGCabdE4kdu2w.png" /></figure><ul><li>The operations needed for columns: N ⨉ N ⨉ (N-1)</li><li>The operations needed for diagonal:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*BsccpraiDCE05yRcrVmxaw.png" /></figure><p><strong>Comparison</strong></p><p>According to the analysis, the qubits needed for N-Queens<strong>²</strong> are too many for the local environment, so a modified version without the diagonal restriction is executed in the experiments. The following tables show a comparison between different parameters before the experiments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjBaFXviyGgAkvx-j1PBcQ.png" /><figcaption>N-Queens puzzle parameters (left), N-Queens<strong>²</strong> parameters without diagonal restriction (upper right), and N-Queens<strong>²</strong> with diagonal restriction (lower right)</figcaption></figure><h3>Experiments</h3><p>I implement the algorithm with Q# and Quantum Development Kit (QDK), and execute it on Azure Quantum. The full codes is <a href="https://github.com/armorsun/N-Queens-Puzzle">here</a>.</p><p>There are three methods used in the experiments.</p><ul><li><a href="https://learn.microsoft.com/en-us/azure/quantum/machines/sparse-simulator?tabs=tabid-python">Quantum Development Kit (QDK) sparse simulator</a></li><li><a href="https://learn.microsoft.com/en-us/azure/quantum/intro-to-resource-estimation">Azure Resource Estimator</a></li><li><a href="https://learn.microsoft.com/en-us/azure/quantum/provider-rigetti?tabs=tabid-pyquil">Azure Quantum — Rigetti</a></li></ul><h3>Results</h3><p><strong>N-Queens in Local Environment with Sparse Simulator</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*byjyalp0ScUU5ni9xRahtA.png" /><figcaption>N=4</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOjtR35WLwrbkhNhzQYY1Q.png" /><figcaption>N=5</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*2rJXTrR4qGJg1341ReDhgg.png" /><figcaption>N=6</figcaption></figure><p><strong>N-Queens on Azure Resource Estimator</strong></p><p>The full results of <a href="https://github.com/armorsun/N-Queens-Puzzle/blob/main/N-Queens/GroverSearchNQueenResourceEstimationResult_n4.ipynb">N=4</a> and <a href="https://github.com/armorsun/N-Queens-Puzzle/blob/main/N-Queens/GroverSearchNQueenResourceEstimationResult_n5.ipynb">N=5</a> are linked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lsw9IRD5lDi_fEITyI8ZZQ.png" /><figcaption>Parts of the results from Azure Resource Estimator</figcaption></figure><p><strong>N-Queens² without diagonal restriction in Local Environment with Sparse Simulator</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2J8sEsfftfYpl_NlBLCCw.png" /><figcaption>N=3</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5AqvfrQUNHBcVn0Z4i8Gfw.png" /><figcaption>N=4</figcaption></figure><p><strong>Real Hardware (Rigetti Provider)</strong></p><p>The resources estimator shows that only the Rigetti provider has enough qubits to execute the algorithm. However, the code cannot be executed on the Rigetti provider due to some <a href="https://learn.microsoft.com/en-us/azure/quantum/quantum-computing-target-profiles#create-and-run-applications-for-no-control-flow-profile-targets">limitations</a>.</p><h3>Discussions</h3><p>The full-state simulator consumed too many memories for the local environment when N = 4 for the N-Queens solution. The sparse simulator can compute N = 6 without exhausting the hardware. The N-Queens<strong>²</strong> needed even more computing power, and the result of N-Queens<strong>²</strong> with diagonal restriction never be acquired running for days. A modified version without diagonal restriction is executed to verify the algorithm. The sparse simulator can compute N = 3 and N = 4 successfully.</p><p>The resources estimator showed an evaluation before submitting algorithms to real hardware. However, it cannot be verified this time while the algorithm has not been executed on a real quantum computer.</p><h3><strong>Conclusions</strong></h3><p>The time complexity of N-Queens is O(N³), and the space complexity is O(N²). Both of the complexity of N-Queens<strong>²</strong> increased by one, where the time complexity is O(N⁴), and the space complexity is O(N³).<br>The quantum algorithm showed theoretically faster than traditional computing, which reduces the time complexity from O(N!) to O(N³). However, more qubits are required to execute the algorithm to verify it. Also, a quantum counting method will be required when there is no solution number from the traditional computing method when N is greater than 27.</p><p>The N-Queens problem can be applied in load balancing, deadlock prevention, and satellite communication. For satellite communication, the queens can be replaced with satellites, and the configuration of the solution of the N-Queens puzzle will maximize the transmit area.</p><h3><strong>References</strong></h3><p>[1] Jha, R., Das, D., Dash, A., Jayaraman, S., Behera, B. K., &amp; Panigrahi, P. K. (2018). A novel quantum N-Queens solver algorithm and its simulation and application to satellite communication using IBM quantum experience. arXiv preprint arXiv:1806.10221.</p><p>[2] Torggler, V., Aumann, P., Ritsch, H., &amp; Lechner, W. (2019). A quantum n-queens solver. Quantum, 3, 149.</p><p>[3] Del Manzano, H. A., &amp; Echevarıa, C. (2002). Quantum algorithm for n-queens problem. In Computing Research Conference, Mayagüez, Puerto Rico.</p><p>[4] <a href="http://oeis.org/A000170">http://oeis.org/A000170</a></p><p>[5] <a href="https://github.com/microsoft/QuantumKatas">QuantumKatas</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f940b563ee6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Raspberry Pi Lane Tracking Car — install OpenCV]]></title>
            <link>https://sunny-hsieh.medium.com/raspberry-pi-lane-tracking-car-install-opencv-fb97dc4b694a?source=rss-6f4054940e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb97dc4b694a</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[opencv]]></category>
            <dc:creator><![CDATA[Kae-Yang Hsieh]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 11:34:16 GMT</pubDate>
            <atom:updated>2018-02-22T11:34:16.458Z</atom:updated>
            <content:encoded><![CDATA[<h3>OpenCV簡介</h3><p>OpenCV是一個開放原始碼的電腦視覺程式庫，可以用來做影像處理</p><p>接下來會利用RPi處理影像以辨識車道的位置，因此要在RPi上安裝OpenCV</p><h3>安裝步驟</h3><p>登入RPi終端機後，按造順序輸入以下指令：</p><pre>sudo apt-get update<br>sudo apt-get upgrade</pre><h4>安裝相關套件</h4><pre>sudo apt-get install build-essential cmake pkg-config libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk2.0-dev libatlas-base-dev gfortran python2.7-dev python3-dev python3-pip python3-numpy git</pre><p>其中 libjpeg-dev, libtiff5-dev, libjasper-dev, libpng12-dev 是讓opencv可以讀取jpg, png, tiff等照片格式、libavcodec-dev, libavformat-dev, libswscale-dev, libv4l-dev, libxvidcore-dev, libx264-dev 是影像串流相關的程式庫，以及libgtk2.0-dev用來顯示畫面等</p><h4>從原始碼編譯、安裝OpenCV 3</h4><p>下載OpenCV及contrib的原始碼</p><pre>wget -O opencv <a href="https://github.com/opencv/opencv/archive/3.2.0.zip">https://github.com/opencv/opencv/archive/3.2.0.zip</a><br>wget -O opencv_contrib <a href="https://github.com/opencv/opencv_contrib/archive/3.2.0.zip">https://github.com/opencv/opencv_contrib/archive/3.2.0.zip</a></pre><pre>unzip opencv<br>unzip opencv_contrib<br>cd opencv-3.2.0<br>mkdir build<br>cd build</pre><pre>cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=OFF -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.2.0/modules -D BUILD_EXAMPLES=OFF ..</pre><pre>make -j2<br>sudo make install<br>sudo ldconfig</pre><h4>測試是否有安裝成功</h4><pre>python3<br>import cv2<br>cv2.__version__</pre><p>如果有出現’3.2.0&#39; 就是成功囉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb97dc4b694a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Raspberry Pi Lane Tracking Car — 硬體環境建置]]></title>
            <link>https://sunny-hsieh.medium.com/raspberry-pi-lane-tracking-car-%E7%A1%AC%E9%AB%94%E7%92%B0%E5%A2%83%E5%BB%BA%E7%BD%AE-645105ab65d9?source=rss-6f4054940e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/645105ab65d9</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Kae-Yang Hsieh]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 11:31:44 GMT</pubDate>
            <atom:updated>2018-02-22T11:31:44.184Z</atom:updated>
            <content:encoded><![CDATA[<h3>樹莓派(Raspberry Pi 3)簡介</h3><p>樹莓派是一塊名片大小的電路板，可以安裝完整的作業系統，具有一般電腦的功能，也可以從感測器讀取訊號得到如溫度、濕度等資訊，或是輸出訊號控制電燈、馬達等。</p><p>下圖：Raspberry Pi 3 (RPi 3)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*08veDcpm3nlfhL7x.jpg" /></figure><h3>作業系統安裝：</h3><p>RPi 3可以安裝許多種不同的作業系統如windows 10、Raspbian、Ubuntu等，詳細項目請見<a href="https://www.raspberrypi.org/downloads/">官網</a>，這次將安裝擁有最多資源的Raspbian。</p><p>首先到官網下載 <a href="https://www.raspberrypi.org/downloads/raspbian/">Raspbian Jessie</a> (Jessie是版本的名稱)</p><p>若需要有圖形畫面的桌面版本請選左側，若不需要可以選擇右側檔案較小的版本。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*orPfeYd4VNf4yW81.png" /></figure><p>將下載的ZIP檔解壓縮後會得到一個 .img檔</p><p>使用<a href="https://etcher.io/">Etcher</a>將此檔燒錄到SD卡(SD卡至少要4GB)</p><p>為了要可以在開機後使用SSH(一種與RPi溝通的方式)遠端登入，需要在SD卡內增加一個檔名為ssh的空檔案(<strong>無副檔名與內容，不是.txt檔</strong>)</p><p>完成後就可以裝到RPi上囉！</p><h3>硬體裝配：</h3><p>網路孔：接上有線網路，另一端接到路由器或是自己的筆電</p><p>（若另一端連接到路由器，請確認正在使用的電腦也是連在同一個路由器上）</p><p>電源：一般Ardroid充電線即可</p><p>SD卡插槽：插入剛剛燒錄好的SD卡</p><p>完成圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8-ZpNIli179EReKh.jpg" /></figure><h3>系統環境建置：</h3><p>接下來要遠端登入使用RPi，但要先知道RPi在網路上的位置，也就是IP位址</p><h3>使用Angry IP scanner找到RPi的IP（Mac, Linux, Windows均適用）：</h3><ol><li>下載 <a href="http://angryip.org/download/">Angry IP scanner</a></li><li>找到自己的IP:</li></ol><pre>windows: 打開命令提示字元並輸入ipconfig</pre><pre>Linux或是Mac: 打開終端機並輸入ifconfig</pre><p>3. 在Angry IP scanner的IP range兩個欄位輸入找到的前三組數字，最後一組分別是1及255</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/0*hxJkGYhrBBI9Le-M.png" /></figure><p>4. 找到Hostname為raspberrypi的IP並記下來</p><h3>遠端連線登入RPi:</h3><p>windows:</p><ol><li>下載<a href="http://www.putty.org/">Putty</a></li><li>按下左側的Session</li><li>在Hostname欄位填上上面查到的RPi IP</li><li>按下面的open按鈕就會打開一個黑色的視窗寫著login:</li><li>輸入 pi</li><li>接下來要輸入密碼，預設是raspberry (輸入的時候螢幕不會出現任何字，要有信心打的字都是對的XD)</li></ol><p>Linux 或 Mac:</p><ol><li>打開終端機</li><li>輸入 ssh pi@192.168.xx.xx(上面查到的RPi IP)</li><li>接著輸入密碼，預設是raspberry (輸入的時候螢幕不會出現任何字，要有信心打的字都是對的XD)</li></ol><p>如果出現raspberry的終端機畫面就代表成功囉！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=645105ab65d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Raspberry Pi Lane Tracking Car — WiFi設定]]></title>
            <link>https://sunny-hsieh.medium.com/raspberry-pi-lane-tracking-car-wifi%E8%A8%AD%E5%AE%9A-12eb15a18b55?source=rss-6f4054940e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/12eb15a18b55</guid>
            <category><![CDATA[wifi]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Kae-Yang Hsieh]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 11:29:35 GMT</pubDate>
            <atom:updated>2018-02-22T11:29:35.082Z</atom:updated>
            <content:encoded><![CDATA[<p>掃描現有的WiFi</p><pre>sudo iwlist wlan0 scan</pre><p>修改WiFi設定檔</p><pre>sudo nano /etc/wpa_supplicant/wpa_supplicant.conf</pre><p>在檔案裡加入</p><pre>network={<br>    ssid=&quot;WiFi名稱&quot;<br>    psk=&quot;WiFi密碼&quot;<br> }</pre><p>修改完後按 Ctrl+O 確認檔名後按 Enter確認存檔<br> 再按 Ctrl + X 離開</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12eb15a18b55" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>