2023年10月4日 星期三

Linux kernel : SPI device 兩種存取模式


Raw SPI Device Access

 $ sudo modprobe spi_bcm2835

 $ ls -l /dev/spidev*

crw-rw---- 1 root spi 153, 0 Nov 19 11:13 /dev/spidev0.0

crw-rw---- 1 root spi 153, 1 Nov 19 11:13 /dev/spidev0.1

Now everything is ready to access the SPI devices from a user-space application using the SPIDEV interface. There is abundant documentation in the Internet on how to use SPIDEV in application code. 



Access SPI Flash as MTD

sudo modprobe mtd
sudo modprobe spi-nor
sudo insmod m25p80.ko


/ # cat /proc/mtd
dev: size erasesize name
mtd0: 00020000 00020000 "flash_uboot_env"
mtd1: 00a00000 00020000 "flash_linux_image"
mtd2: 005e0000 00020000 "flash_jffs2"
mtd3: 00100000 00010000 "spi_flash_part0"
mtd4: 00300000 00010000 "spi_flash_part1"

2023年9月1日 星期五

[Linux 系統程式設計] Pipe 與 fork


(1) 先產生Pipe再做fork 和 fork 再產生Pipe 差別在哪?

先產生Pipe 再Fork ==> parent/Child 可以交換資料
先 Fork 再產生pipe  ==> parent/Child 各自應用, 而不是要交換資料 , pipe換成一般檔案也是相同的概念



 





2023年8月1日 星期二

LabelImg 的安裝與使用


LabelImg Tool:  Annotations are saved as XML files in PASCAL VOC format, the format used by ImageNet. Besides, it also supports YOLO and CreateML formats.


下載 LabelImg ,  
git clone https://github.com/HumanSignal/labelImg.git

若沒有Python Qt, 則須安裝好QT5 
  
pip install pyqt5_tools

接著再執行label Image 的工具
#For QT5 use this command,
pyrcc5 -o libs/resources.py resources.qrc
python labelImg.py


對某一個物件在所有圖片都標注完之後(記得存檔), 再回頭來標注另一個物件會比較快, 因為每框選一個物件,都要從下拉選擇選擇label 反而比較花時間!一個圖檔可能會有多個物件, 這些框選的資訊都記錄在對應的.txt 中。1.jpg -------> 1.txt2.jpg -------> 2.txt3.jpg -------> 3.txt .... ....
在yolo 模型, 其.txt 檔的內容, 每一列代表一個框框的資訊, 但以normalized的資訊來表示. 框框的物件座標資訊(x,y,w,h)都是相對於原始圖片的長宽,所以這些座標資訊都是介於0~1的數字class_id x y w hclass_id x y w h....#轉成0~1def convert(size, box): dw = 1./(size[0]) #圖片的寛 dh = 1./(size[1]) #圖片的高 x = (box[0] + box[1])/2.0 - 1 y = (box[2] + box[3])/2.0 - 1 w = box[1] - box[0] h = box[3] - box[2] x = x*dw w = w*dw y = y*dh h = h*dh return (x,y,w,h)
#yolo偵測到的物件其座標資訊須再乘回比例才可以得到原始圖片的座標資訊=========LabelImg 快速鍵,可以加快你標記的速度
Ctrl + uLoad all of the images from a directory
從目錄加載所有圖像
Ctrl + rChange the default annotation target dir
更改默認註釋目標目錄
Ctrl + sSave  儲存
Ctrl + dCopy the current label and rect box
複製當前標籤和框
Ctrl + Shift + dDelete the current image
刪除當前圖像
SpaceFlag the current image as verified
將當前圖像標記為已驗證
wCreate a rect box
創建一個框
dNext image  下一張圖片
aPrevious image  上一張圖片
delDelete the selected rect box
刪除選中的矩形框
Ctrl++Zoom in  放大
Ctrl–Zoom out  縮小
↑ → ↓ ←Keyboard arrows to move selected rect box




"Flag the current image as verified" ,會出現綠色背景, 讓你可以快速事後檢查有沒有可能有遺漏的標記。
若有綠色背景, 表示你已驗證過這張圖片已經檢查過了.



2023年7月31日 星期一

Raspberry 的預設帳號Pi 不存在了



基於安全性考量,Raspberry Pi 2022年開始的預載的OS image ,不再含有預設的pi 帳號了

在 SD 卡的boot 分割區 (SD 卡插在 Windows 上可以看到檔案系統), 建立一個名為userconf或userconf.txt的文件.

userconf.txt 的內容, 其中pi: <encrypted password>

此處以raspberry 作為密碼的編碼, 可以用其他Linux 機器產生 encrypted password

echo 'raspberry' | openssl passwd -6 -stdin

如此又可以回到帳號 pi 預設密碼為 raspberry 所習慣的環境了~

userconf.txt 的內容如下
 




2023年1月14日 星期六

[Python] 動態繪製不同尺寸的ASCII-table


作業描述: 能動態繪製不同尺寸的ASCII-table

Task Decription:

1. Generate a random list of size 50.It contains random values from 1 to 50.
2. Dynamically draw a ASCII table  according to the dimensions  of  table

The end result will look like below



2022年12月31日 星期六

佈署AI模型於Web 上


目標: 用瀏覽器上傳圖案到Web後端進行預測, 並將模型預測結果回傳至瀏覽器。


#teachable machine #Flask  #Keras 

#Install required packages
pip install flask==2.1.1
pip install Pillow==9.1.0
pip install tensorflow==2.3.1
pip install keras==2.4.3






專案目錄結構如下, 其中model 資料匣 要放置AI 模型檔及Label 文字檔。凡應用是上傳圖片,由模型預測分類結果的, 都可以套用本專案程式架構。在不想改程式碼, 就直接模型檔名改成keras_model.h5 ,類別的文字檔改成 labels.txt。 


 執行主程式 main.py 後, 會載入模型同時啓動Web Server (Flask) 



P.S. 此處 model 資料匣的所放的AI模型, 是直接使用 Teachable Machine 來建立模型。為了方便套用至其他的應用程式, 從teacbable machine 複製來的程式碼, 將其程式架構改寫為 Class 的方式,會比較好用。而且主程式會顯得很簡潔也會易於日後程式維護。aimodel.py 程式碼參考如下: