Posts

Showing posts from June, 2022

pyqt5 讀取相機鏡頭的 frame 時,螢幕畫面會一直閃

Image
問題: 工作上遇到了用 pyqt5 顯示畫面,結果螢幕一直閃的問題。 一開始以為是線程的問題,在 vs code 用 debug 模式看半天,把 code 都 print 出來,發現還是無解。 後來又以為是 .ui 檔圖層沒有設定好的問題,圖層調了半天也無解。 最後被同事一語道破:你處理 rgb frame 的時候有沒有 sleep ? 我: ?? 解法: 在 qt 需要顯示 rgb frame 的地方,我們會用 while 迴圈一直去跑,因為讀取的速度太快,qt 來不及處理畫面顯示就跳下一張 frame ,所以會一直閃。 所以每處理完,顯示完一張 frame 之後讓他睡個 0.015 秒,問題解決! 上 code: (以下為示意 code 沒辦法真的跑起來噢!) 設定 QT image →顯示 rgb frame def qt_show_rgb_frame(rgb_frame): ... # rgb_frame 前處理成 rgbImage convertToQtFormat = QImage( rgbImage.data, w, h, bytesPerLine, QImage.Format_RGB888 ) display_frame = convertToQtFormat.scaled(800, 480) self.controller.setFrameImage.emit(display_frame) 用 while 迴圈跑 show_rgb_frame(rgb_frame) 時,每跑完一個迴圈要 sleep 0.015 秒 import time while True: rgb_frame = self.rgb_camera.read() ... # 其他邏輯 self.view.qt_show_rgb_frame(rgb_frame) # 顯示 qt rgb frame 的 function time.sleep(0.015) # 讓它睡! 同事真的太強大了

Ubuntu 20 建立 virtual environment,更換不同 python 版本

除了好用的 poetry 之外,另一個我也常用的虛擬環境是 virtualenv 安裝 python3.6 简单的 ubuntu20安装python3.6(已验证) 安裝 pip 安裝 pip3  # 才可以使用 pip3 install $ sudo apt install python3-pip 版本升級 pip3 install —upgrade pip 查看目前 pip 版本 python3 -m pip —version >>> 21.0.1 安裝 virtualenv pip3 install virtualenv sudo apt install python3-venv 建立虛擬環境 在 home 目錄建立 .virtualenvs $ mkdir .virtualenvs 執行法 1 需要安裝好欲使用之 python 版本後,就可以指定版本開啟虛擬環境,安裝方式可以參考 這一篇 $ python3.6 -m venv ~/.virtualenvs/<虛擬環境名稱> 如果此法失敗,出現error ex: $ python3 -m venv .virtualenvs/cv3 Error: Command '['/home/seraphine/.virtualenvs/cv3/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1 執行法 2 $ sudo apt-get install python3.6-venv $ virtualenv -p /usr/bin/python3.6 .virtualenvs/<虛擬環境名稱> $ source ~/.virtualenvs/<虛擬環境名稱>/bin/activate python 版本更換 查看有哪些版本 $ update-alternatives --list python 設定更換的版本 $ sudo update-alternatives --insta...

Poetry - 實用的套件管理工具

使用心得 自己覺得一個不錯的虛擬環境控管工具,推薦給大家 使用起來像是以一個專案(資料夾)為單位,在資料夾裡面對套件的安裝做操作。 同個資料夾可以同時有不同版本的 python 安裝環境。 poetry 主要有兩個檔案 pyproject.toml pyproject.toml 每次對套件有所修改時,都會自動更新檔案,不用怕忘記把套件 dump 出來! 安裝 可以參考 官往文件 以下為 Ubuntu 的例子 $ curl -sSL <https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py> | python3 - # Welcome to Poetry! This will download and install the latest version of Poetry, a dependency and package manager for Python. It will add the poetry command to Poetry's bin directory, located at: $HOME/.poetry/bin This path will then be added to your PATH environment variable by modifying the profile file located at: $HOME/.profile You can uninstall at any time by executing this script with the --uninstall option, and these changes will be reverted. Installing version: 1.1.6 - Downloading poetry-1.1.6-linux.tar.gz (72.33MB) Poetry (1.1.6) is installed now. Great! To get started you need Poetry's bin directory ($HOME/.poetry/bin) in your PATH environment var...

kubernetes - mongo, mongo-express & node.js app: three pods connection practice

Image
Practice1: Three containers in one pod clone data from github GitHub - chi811008/kubernetes: k8s practice 1. Prepare one deployment 💡 k is abbreviation from kubectl three containers in one pod deployment three-container.yaml apiVersion: apps/v1 kind: Deployment metadata: name: mongo-app-deploy labels: app: mongo spec: replicas: 1 selector: matchLabels: app: mongo template: metadata: labels: app: mongo spec: containers: - name: mongo image: mongo env: - name: MONGO_INITDB_ROOT_USERNAME value: admin - name: MONGO_INITDB_ROOT_PASSWORD value: password ports: - containerPort: 27001 - name: mongo-express image: mongo-express ports: - containerPort: 8081 env: - name: ME_CONFIG_MONGODB_ADMINUSERNAME value: admin - name: ME_CONFIG_MONGODB_ADMINPASSWORD value: password - name: ME_CO...