Hong En
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Lab08:opencv、虛擬環境、colab大雜燴 ## 無人載具的視覺辨識應用-PBL應用 **無人載具(AGV/AMR)** 的應用已經廣泛擴展到各種工業和物流領域,並且視覺辨識技術在這些應用中發揮著關鍵作用。這篇文章將介紹無人載具的視覺辨識應用,並提供一個實例,講述如何結合視覺辨識和物件辨識技術,以實現自主導航、障礙物避免和任務執行。 **視覺辨識技術的基本原理**: 視覺辨識技術利用相機或攝像頭來捕捉環境中的圖像,並使用機器學習算法來識別和分類物體。這些技術可以檢測物體的**位置、形狀、大小和顏色**,並為無人載具提供寶貴的感知信息。 **無人載具的自主導航**: 為了實現自主導航,無人載具必須能夠識別和理解其周圍環境。視覺辨識技術可以幫助車輛識別地標、標誌、障礙物和其他車輛。例如,在工廠內,無人載具可以使用攝像頭來辨識地板上的標誌,以確定其位置,然後選擇最佳的路徑前進。 **物件辨識技術** : 物件辨識技術是視覺辨識的一個子領域,它專注於識別和分類特定物體。在無人載具應用中,這意味著辨識貨物、設備或其他物體,以便在製造和物流過程中執行任務。例如,AGV可以使用物件辨識技術來確認貨物的位置,然後進行拾取和運送。 **實例**:無人載具在倉儲中的應用: 假設一個大型倉庫需要有效地管理和運送各種貨物,包括不同尺寸和形狀的箱子。為了實現這一目標,AGV/AMR配備了攝像頭和物件辨識技術。當一個新的貨物到達倉庫時,AGV使用其攝像頭捕捉圖像,然後利用物件辨識技術識別貨物的種類、尺寸和位置。然後,它使用自主導航技術找到貨物的位置,進行拾取並將其運送到目的地。這樣的系統可以大幅提高倉庫操作的效率,並減少人力成本。 **未來發展**: 隨著機器學習和視覺辨識技術的不斷進步,無人載具的應用領域將繼續擴展。將來,無人載具將能夠更智能地辨識和適應各種情境,實現更高級的任務執行。 ## opencv OpenCV的全稱是Open Source Computer Vision Library,是一個跨平台的電腦視覺庫。 ### 套件安裝 ```bash= # python版本須為3.7版 pip install opencv-contrib-python==3.4.2.17 ``` ### 套件引入 ``` bash= import cv2 ``` ### 讀檔 cv2.imread('檔案路徑') [參考網址](https://docs.opencv.org/4.x/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56) ``` python= image = cv2.imread("data\\Sun.jpg") ``` ### 顯示圖片 cv2.imshow('視窗名稱',變數名稱) [參考網址]( https://docs.opencv.org/4.x/d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563) ``` python= import cv2 image = cv2.imread("TW.jpg") #先讀取圖片 cv2.imshow("Sun", image) #顯示圖片 cv2.waitKey(0) #等待 enter被按下 cv2.destroyAllWindows() #關閉opencv開啟的視窗 ``` ### 查看圖片大小 ``` python= image = cv2.imread("TW.jpg") #先讀取圖片 print(image.shape) ``` ### 圖片轉灰階 cv2.cvtColor(變數名稱, cv2.COLOR_BGR2GRAY) [參考網址](https://docs.opencv.org/3.4/d8/d01/group__imgproc__color__conversions.html#ga397ae87e1288a81d2363b61574eb8cab) ``` python= import cv2 image = cv2.imread("TW.jpg") #先讀取圖片 gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) #把image這個檔案從BGR轉成灰階,放到gray這個變數 cv2.imshow("Sun", image) cv2.imshow("gray", gray) cv2.waitKey(0) #等待 enter被按下 cv2.destroyAllWindows() #關閉opencv開啟的視窗 ``` ### 把BGR三種分開 ``` python= import cv2 import numpy as np image = cv2.imread("TW.jpg") #先讀取圖片 B,G,R = cv2.split(image) #split BGR channel zeros = np.zeros(image.shape[:2],dtype="uint8") # create與image一樣大小的0矩陣 cv2.imshow("B channel", cv2.merge([B, zeros, zeros])) # show (B, 0, 0) image cv2.imshow("G channel", cv2.merge([zeros, G, zeros])) # show (0, G, 0) image cv2.imshow("R channel", cv2.merge([zeros, zeros, R])) # show (0, 0, R) image cv2.waitKey(0) cv2.destroyAllWindows() ``` ### 使用鏡頭 * 拍一張 ``` python= import cv2 cap = cv2.VideoCapture(0) if not cap.isOpened(): print("Cannot open camera") exit ret, frame = cap.read() if ret: cv2.imshow('live', frame) cv2.waitKey(0) cv2.destroyAllWindows() ``` * 持續拍 ``` python= import cv2 cap = cv2.VideoCapture(0) if not cap.isOpened(): print("Cannot open camera") exit while True: ret, frame = cap.read() if not ret: break gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('live', frame) #cv2.imshow('live', gray) if cv2.waitKey(1) == ord('q'): break cap.release() cv2.destroyAllWindows() ``` ## PATH 環境變數 環境變數中比較重要的就是 PATH。 它代表著「系統要到哪些路徑底下找執行檔 * windows * ![](https://i.imgur.com/2KNDsSv.png) * 樹梅派 echo $PATH ## anaconda Anaconda 提供快速建置 Python 資料科學和機器學習環境,可安裝超過 250 種資料科學 和 conda 套件(package),以及 Windows、Linux和MacOS上的虛擬環境管理 (virtual environment manager)。 為什麼需要虛擬環境?這就像是為了這次的學習建立一個遊樂場,在這個場子裡,可以翻滾、可以東敲西打,不用擔心把場地搞亂了無法收拾,只要離開虛擬環境,再造下一個就好了。在實務上,有時會碰到不同專案會使用不同的套件,甚至使用相同套件但是使用不同版本的情況。為了讓各個專案可以在同一台電腦上開發且各自環境設定不會互相干擾,虛擬環境就可以派上用場。為每個專案建立各自的虛擬環境,在開發時啟動專屬的虛擬環境,就不用擔心干擾到別的專案。 [anaconda官網](https://www.anaconda.com/products/distribution) <font color='red' size='24'>使用者名稱不可中文、空格、符號</font> * 如果使用者名稱有英文 有兩種解決方式 1. 創一個新的 2. 使用[virtualenv](https://virtualenv.pypa.io/en/latest/user_guide.html) * 記得要打勾,其他都直接next ![](https://i.imgur.com/stbPFMl.png) * 要找到這個綠色的 ![](https://i.imgur.com/10RKArM.png) * 點左邊environment後,中間下面有功能列 ![](https://i.imgur.com/z2rdHyW.png) * 取名原則:版本+功能 ![](https://i.imgur.com/pBBGVgi.png) * cmd、terminal左邊的括號代表目前在使用哪一個環境,可以透過點擊右下角來接換版本 ![](https://i.imgur.com/qaIh8TW.png) * 指定開啟使用該環境的terminal ![](https://i.imgur.com/aw6UYmO.png) 類似的工具:[virtualenv](https://virtualenv.pypa.io/en/latest/user_guide.html) ## ipynb(Jupyiter notebook檔案) * 超級好用的debug工具 * 可以逐段執行程式碼 * 可以用markdown語法來寫註解、說明 * vscode可以開啟他 ## Google Colab 由 Google 提供開發者虛擬主機,讓大家可以在雲端運行及編輯的一個執行環境。 可以進行資料分析及機器學習的工具。只需簡單的安裝及設定就可以完全免費使用,也可以免費存取 GPU 等運算資源。 給免費仔的資源 * 2vCPU @ 2.2GHz * 13GB RAM * 100GB Free Space * GPU * idle cut-off 90 minutes * maximum 12 hours * 優點 * 環境幫你弄好了 (AI、機器學習、深度學習、資料處理等) * 可以連接雲端硬碟 * 不會占用你的電腦資源 * 可以隨便亂搞 * 缺點 * 給免費仔的資源不多 * 會把你切掉 * GPU有使用上限 ## lab08 **作業繳交注意事項:** 1. moodle平台不用繳交任何檔案,請上傳至github。 2. deadline為 <font color="red">2023/12/26(二)23:59</font>,以github上傳時間為主。 5. 資料夾內需包含:程式碼、讀取的圖片、截圖。 7. 本次lab請加上些許備註(解釋你的程式碼在做啥)。 * 資料夾名稱:「lab13」 * 程式碼名稱:「<a>lab08.py</a>」or 「<a>lab08.ipynb</a>」 ### 作業要求 1. 請使用自己的電腦,建立一個python版本為3.7的虛擬環境,截圖你的cmd 2. 讀取這張[圖片](https://drive.google.com/file/d/1bQ-17rZIAz5zKnbSAHMzJdrOKQr-M422/view?usp=sharing),在不使用cv2函式的狀況下轉為灰階圖片 <font color=red size=24>其實可以產生正確的圖片,兩種結果都會給分</font> * gray = (r+g+b)/3 ![](https://i.imgur.com/bbcJHRt.png) ![](https://i.imgur.com/CxoR6Xr.png) 4. 將灰階圖片(用cv2 function產生的圖片)進行二值化,調整到只保留台灣的部分 ![](https://i.imgur.com/LlprQHi.png) 執行程式後,要跳出4張照片 1. 原始照片 2. 使用函式灰階照片 3. 不使用函式灰階照片 4. 二值化照片 ### 補充 使用電腦上傳檔案至github方式 1. 把檔案丟到樹梅派再上傳(不建議 這學期後你們就沒有pi了) 2. 使用[git bash](https://gitforwindows.org/) 3. 使用github 網站 1. 新增資料夾方式 * 點擊create new file * ![](https://i.imgur.com/Wfcbb8N.png) * 在檔名的地方,打上資料夾名稱+斜線,github就會自動幫你新增資料夾 * ![](https://i.imgur.com/aHE7Pyi.png) * 把程式碼貼上,或是先隨便建立一個檔案之後再刪掉,因為github不允許只建立資料夾 2. 新增檔案方式 * 點擊到欲上傳檔案的地方,然後點擊uploade file * ![](https://i.imgur.com/upi9XL1.png)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully