get paid

Get paid for the tasks you do online
顯示具有 python教學 標籤的文章。 顯示所有文章
顯示具有 python教學 標籤的文章。 顯示所有文章

2020年11月17日 星期二

Pyinstaller 打包 結果花很多時間才執行

 昨天因工作需求,  用了 pandas , OS 這幾個 library ,

因為要讓同事的 windows 跑 ,  且他的電腦沒有 python 環境 

於是直覺就用 Pyinstaller 打包 ,  原本用 -F 包單個 file , 但要快 3 分鐘才開始run 

google 一下發現是因為 -F (one file) 需要先去下載 library , 可能 pandas 這個 library 太大了

所以會等比較久

後來改成 -D 就快很多 , 但也要等快 1 秒才執行

不過以這工具來說 ok 了 


2020年10月13日 星期二

python 正規化 re 的簡介

 正規化檢查是很常用的功能, 如輸入檢查 

如你是要使用者輸入如 mac address 會 IP address 時 會用來檢查輸入正不正確


import re

pattern = r"([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}"
if re.fullmatch(pattern, macaddr):
print("mac address correct")


其中 pattern 是 Mac address 格式的檢查 ,  Mac 固定式 0 ~F 12 碼 , 每兩碼要用 : 隔開

後面的定義很像文字天書 , 但等一下有快速的方法 寫出來

re.fullmatch (pattern, macaddr)  中 macaddr 是我在其他地方要求別人輸入的 Mac address 

我需要檢查使用者輸入是否正確 

如果這確 re.fullmatch 就會 return ture 

 

最後要如何快速查到你的檢查碼(pattern)呢 ?

我們可以直接用下面網址查詢別人查過的表示法即可

https://regex101.com/





2020年6月26日 星期五

yolov3 vs SSD 辨識心得

之前的案子需要用人型偵測
原很一開始使用 SSD , 但經過兩個星期測試有時候會把較大的物體辨識成兩個
不過辨識時間相當的快
以我用 Tx2 來看可以到 30~40 frame

連假時 把辨識模組改成 yolov3 , 辨識的準確度提高了不少

但式 frame rate 只剩下不到 5 張.

不過以我的應用來看這樣子是夠用的
接來先用 yolov3 跑個一個月看看


2020年5月24日 星期日

利用 imagezmq 影像串流

imagezmq 套件 讓人輕易的可以將遠端的影像串流傳送到server 上

目前有一個專案 , 需要將 Tx2 上處理過的影像傳到 座位上以方便監控

使用 imagezmq 開發讓事情變得很間單

架構如下

Tx2 (imagezmq client) --> Server ( imagezmq server)

Client 端的 程式


#192.168.31.210 是 server (要接收串流的 IP 位置) 5555 是指定的 port .
 
sender = imagezmq.ImageSender(connect_to='tcp://192.168.31.210:5555')
 
rpi_name = socket.gethostname() # 抓取系統的名稱, 如果有多台裝置傳到 server 端 server 
才可以分辨 誰是誰

picam = VideoStream(usePiCamera=True).start()
 
time.sleep(2.0)  # allow camera sensor to warm up

while True:  # send images as stream until Ctrl-C
      image = picam.read() # 讀取 camera 的 frame
      sender.send_image(rpi_name, image) # 把影像送出



Server 端的程式

import cv2
import imagezmq
image_hub = imagezmq.ImageHub()
while True:  # show streamed images until Ctrl-C
  rpi_name, image = image_hub.recv_image()
  cv2.imshow(rpi_name, image) # 1 window for each RPi
  cv2.waitKey(1)
  image_hub.send_reply(b'OK')


有沒有很簡單

詳細內容可以參考
原作者的 git

https://github.com/jeffbass/imagezmq



2020年4月12日 星期日

barcode detection and decoder -- pyzbar

前面提到如何安裝 pyzbar , 使用上也很簡單

sample code 如下

from pyzbar import pyzbar # 這邊要記住我 import 的方式

import cv2

image = cv2.imread("images.png")

barcodes = pyzbar.decode(image)


先用 cv2 讀出要辨識的 image

再用 pyzbar.decode 讀出 照片中的 barcodes 有哪些

 barcodes 內會把照片所有辨識出的 barcode , 內容與位置都會用 dict 格式純在 list

內容如下

也就是說每個 barcode , 都會有對應的 data ( qrcode 的內容)
type :(qrcode 的 type)
rect ( qrcode 的位置 x,y, w,h)
polygon 折式qrcode 四點的位置)



[
    Decoded(
        data=b'Foramenifera', type='CODE128',
        rect=Rect(left=37, top=550, width=324, height=76),
        polygon=[
            Point(x=37, y=551), Point(x=37, y=625), Point(x=361, y=626),
            Point(x=361, y=550)
        ]
    )
    Decoded(
        data=b'Rana temporaria', type='CODE128',
        rect=Rect(left=4, top=0, width=390, height=76),
        polygon=[
            Point(x=4, y=1), Point(x=4, y=75), Point(x=394, y=76),
            Point(x=394, y=0)
        ]
    )
]

python barcode detection and decoder -- pybar 安裝

用 python 便是一些基礎的東西 越來越簡單, 原本有個專案要辨識 barcode , 本想自己硬幹

但發現有現成 performance 也很好的 Library pybar

可以做 barcode detection 與 decoder ...

但 pybar 不能直接 install , 需要現下載 zbar , windows 已經包含在 wheel 內不需再按裝, 但需要有  Visual C++ Redistributable Packages for Visual Studio 2013.

Mac 與 Linux follow 下面方式下窄即可 (出處:https://pypi.org/project/pyzbar/)
Mac OS X:
brew install zbar
Linux:
sudo apt-get install libzbar0
Install this Python wrapper; use the second form to install dependencies of the command-line scripts:
pip install pyzbar

2019年10月10日 星期四

一直想做 pyqt5 的 教學影片 , 但一直沒空

剛好趁連假 用最簡單方式 介紹 pyqt 的 hello world.


https://www.youtube.com/watch?v=oNzKoUCAX3I

有興趣的可以訂閱 分享

我會陸續更新

2019年9月7日 星期六

Python 教學 ---字串處理

字串相加與列印

str3 = str1 + ' ' + str2 # 字串連接 print(str3) #列印第二個字元 print(str3[1]) #重 0 開始計算

常用字串函數

upper() # 轉成大寫
rjust() # 右邊填空白字元




Python 教學--數字處理

基本運算

x=99 print(x) print(x + 1) # 加法 print(x - 1) # 減法: print(x * 2) # 乘法: print(x / 2) # 除法: print(x // 2) # 整數除法 print(x % 2) # 餘數: print(x ** 2) # 指數:

 位移

y=5 print (bin(y)) # y 的二進制 print(y<<1) print(bin(y<<1))

布林運算


print( x == y) print( x!= y) print(x > y)




Python 教學 --- Python 基礎知識 2


整數 int a=10
浮點數 float b=3.14
負數 complex c=1+2j
字串 str d=‘python’





Python 教學 --- Python 基礎知識 1

Python 基礎知識

Python 使用縮排(Indentation)來管理程式區塊
所以不能任意縮排, 需要對齊
使用 #來做註解

Python 開發的好習慣

正確縮排
所有的變數命名都要有意義
做註解






python 教學 ---- What is Python

What is Python

What is Python

Guido van Rossum 1991 年開發完成是一種直譯程式語言
開源 , 免費的程式語言
設計哲學是「優雅」、「明確」、「簡單」
可讀性和簡潔的語法,開發容易,
豐富的模組,減低開發時間
被業界廣泛使用(Google, Banks …)

Python Environment

Anaconda 是最廣泛使用的開發環境
已經包含Python 直譯器與常用的Libraries

Anacoda 下載
https://www.anaconda.com





Ether.FI 神卡 https://www.ether.fi/@46933474

 Ether.FI 真的是神卡 有買US Amazon  或穩定幣的很適合辦一張 我的推薦碼 https://www.ether.fi/@46933474