RaspberryPi

安装 下载 Raspberry Pi Imager 烧录镜像 对于 Pi Zero W,目前烧录成功的镜像是 bullseye 32 bits:2024-03-12-raspios-bullseye-armhf-lite.img.xz,下载地址: Raspberry Pi - Operating system images 烧录时可以选择配置用户名密码,新的版本已经不再使用默认的 pi/raspberry 作为默认账密 烧录时可以配置 WiFi,iPhone 热点可用;配置勾选允许 SSH 登录 USB 连接 SSH 在文件 config.txt 中最后加上一行 dtoverlay=dwc2,表示开启 DesignWare USB 2.0 driver 在文件 cmdline.txt, 中的 rootwait 后面加上 modules-load=dwc2,g_ether,进入 USB Ethernet adapter 模式 常见问题 树莓派无法启动:检测 USB 线的问题,可能换成较粗较短的线后启动成功 配置了 USB 连接 SSH 后仍然无法连接 USB 线只支持供电不支持传输数据,换条 USB 线后解决 是否连接在树莓派的 data Micro USB 口上 WiFi 无法连接 iPhone 热点在开启一段时间后可能不再发送广播帧,需要手段开关 iPhone 热点后,然后在树莓派上 sudo wpa_cli -i wlan0 reconfigure WiFi 扫描 WiFi sudo apt update sudo apt install wireless-tools sudo iwlist wlan0 scan 连接 WiFi 在 /etc/wpa_supplicant/wpa_supplicant.conf 中加上 network={ ssid="your_ssid" psk="your_password" } 重启无线服务 sudo wpa_cli -i wlan0 reconfigure 检查是否连接成功 ifconfig wlan0 如有必要,可以手动更新 IP 租约 sudo dhclient -r wlan0 sudo dhclient wlan0 接口图 ...

January 1, 2000

RaspberryPi - Camera

开启摄像头 调出配置面板 sudo raspi-config 如图所示将camera选项中设置为enable 拍照 raspistill -v -o test.jpg # 新版本使用 libcamera libcamera-still -o test.jpg 常用命令 # 两秒钟(时间单位为毫秒)延迟后拍摄一张照片,并保存为 image.jpg raspistill -t 2000 -o image.jpg # 拍摄一张自定义大小的照片。 raspistill -t 2000 -o image.jpg -w 640 -h 480 # 降低图像质量,减小文件尺寸 raspistill -t 2000 -o image.jpg -q 5 # 强制使预览窗口出现在坐标为 100,100 的位置,并且尺寸为宽 300 和高 200 像素。 raspistill -t 2000 -o image.jpg -p 100,100,300,200 # 禁用预览窗口 raspistill -t 2000 -o image.jpg -n # 将图像保存为 PNG 文件(无损压缩格式,但是要比 JPEG 速度慢)。注意,当选择图像编码时,文件扩展名将被忽略。 raspistill -t 2000 -o image.png –e png # 向 JPEG 文件中添加一些 EXIF 信息。该命令将会把作者名称标签设置为 Dreamcolor,GPS 海拔高度为 123.5米。 raspistill -t 2000 -o image.jpg -x IFD0.Artist=Dreamcolor -x GPS.GPSAltitude=1235/10 # 设置浮雕风格图像特效 raspistill -t 2000 -o image.jpg -ifx emboss # 设置 YUV 图像的 U 和 V 通道为指定的值(128:128 为黑白图像) raspistill -t 2000 -o image.jpg -cfx 128:128 # 仅显示两秒钟预览图像,而不对图像进行保存。 raspistill -t 2000 # 间隔获取图片,在 10 分钟(10 分钟 = 600000 毫秒)的时间里,每 10 秒获取一张,并且命名为 image_number_1_today.jpg,image_number_2_today.jpg... 的形式。 raspistill -t 600000 -tl 10000 -o image_num_%d_today.jpg # 获取一张照片并发送至标准输出设备 raspistill -t 2000 -o - # 获取一张照片并保存为一个文件 raspistill -t 2000 -o - > my_file.jpg 预览参数与命令 -p, --preview : 预览窗口大小设置 <x,y,w,h> -f, --fullscreen : 全屏幕预览模式 -op, --opacity : 预览窗口透明度 (0-255) -n, --nopreview : 不显示预览窗口 预览参数与命令2 -gs, -glscene : GL屏幕尺寸等参数 -gw, -glwin : GL窗口参数 图像参数与命令 -?, --help : 帮助文档 -w, --width : 设置图像宽度 <尺寸> -h, --height : 设置图像高度 <尺寸> -q, --quality : 设置jpeg品质 <0到100> -r, --raw : 增加raw原始拜尔数据到JPEG元数据 -o, --output : 输出文件名 <文件名>,如果要写到stdout,使用`-o -`,如果不特别指定,图像文件不会被保存 -l, --latest : 链接最近的完整图像到指定文件 <文件名> -v, --verbose : 在运行摄像头时输出详细信息 -t, --timeout : 拍照和关闭时的延时指定,未指定时默认是5s -th, --thumb : 设置预览图(小图)参数(包括X、Y、品质)或者不设置 -d, --demo : 运行一个demo模式(cycle through range of camera options, no capture),括号里的我可以理解成循环测试模式吗? -e, --encoding : 编码来输出指定格式文件 (jpg, bmp, gif, png) -x, --exif :将可交换图像文件应用到捕获中(格式:`key=value`)或者不设置 -tl, --timelapse : 间隔拍摄,每<ms>拍摄一张图片 -fp, --fullpreview : 用静态捕捉分辨率运行预览(可能会减小预览帧率) -k, --keypress : 按键触发,按`ENTER`键拍照,按`X`然后`ENTER`键退出 -s, -signal : 信号触发,等待另一个进程信号来拍摄一张照片 -g, -gl : 绘制预览到文本,而不是使用视频渲染组件(啥意思?) -gc, --glcapture : 捕获GL帧buffer而不是摄像机图像 -set, --settings : 检索摄像机设置值然后写出到stdout -cs, --camselect : 选择摄像头设备 <数字>,默认0 -bm, --burst : 运行burst capture mode 图像参数与命令2 -sh, --sharpness : 设置图像锐度 (-100 到 100) -co, --contrast : 设置图像对比度 (-100 到 100) -br, --brightness : 设置图像亮度 (0 到 100) -sa, --saturation : 设置图像饱和度 (-100 到 100) -ISO, --ISO : 设置摄像头感光度 -vs, --vstab : Turn on video stabilisation 开启摄像头防抖模式(是这个意思吗?) -ev, --ev : 设置EV补偿 -ex, --exposure : 设置曝光模式(参见提示) -awb, --awb : 设置AWB模式(参见提示) -ifx, --imxfx : 设置图像效应(参见提示) -cfx, --colfx : 设置色彩效应(参见提示) -mm, --metering : 设置测光模式(参见提示) -rot, --rotation : 设置图像旋转 (0到359) -hf, --hflip : 设置水平翻转 horizontal flip -vf, --vflip : 设置垂直翻转 vertical flip -roi, --roi : 设置interest区域 (啥叫interset?) --ss, --shutter : 设置快门速度,微秒 --awbg, --awbgains : 设置AWB阈值, AWB模式必须关闭 --drc, --drc : 设置DRC水平 曝光模式选项 auto : 自动曝光模式 night : 夜间拍摄模式 nightpreview : 夜间预览拍摄模式 backlight : 逆光拍摄模式 spotlight : 聚光灯拍摄模式 sports : 运动拍摄模式 snow : 雪景拍摄模式 beach : 海滩拍摄模式 verylong : 长时间曝光拍摄模式 fixedfps : 帧约束拍摄模式 antishake : 防抖模式 fireworks : 烟火拍摄模式 自动白平衡选项 off : 关闭白平衡测算 auto : 自动模式(默认) sun : 日光模式 cloud : 多云模式 shade : 阴影模式 tungsten : 钨灯模式 fluorescent : 荧光灯模式 incandescent : 白炽灯模式 flash : 闪光模式 horizon : 地平线模式 图像特效选项 none : 无特效(默认) negative : 反色图像 solarise : 曝光过度图像 posterize : 色调图像 whiteboard : 白板特效 blackboard : 黑板特效 sketch : 素描风格特效 denoise : 降噪图像 emboss : 浮雕图像 oilpaint : 油画风格特效 hatch : 草图特效 gpen : 马克笔特效 pastel : 柔化风格特效 watercolour : 水彩风格特效 film : 胶片颗粒风格特效 blur : 模糊图像 saturation : 色彩饱和图像 colourswap : 暂未可用 washedout : 暂未可用 posterise : 暂未可用 colourpoint : 暂未可用 colourbalance : 暂未可用 cartoon : 暂未可用 测光模式选项 average : 全画面平衡测光 spot : 点测光 backlit : 模拟背光图像 matrix : 阵列测光 录像 # 下面这句命令会按照默认配置(长度5秒,分辨率1920x1080,比特率 17Mbps)拍摄一段视频。 raspivid -o test.h264 # 如果你想改变拍摄时长,只要通过 "-t" 选项来设置你想要的长度就行了(单位是毫秒)。 raspivid -o test.h264 -t 10000 #使用 "-w" 和 "-h" 选项将分辨率降为 1280x720... raspivid -o test.h264 -t 10000 -w 1280 -h 720 raspivid -v -o test.h264 -t 10000 -n -pf baseline -w 640 -h 480 -fps 10 raspivid 的输出是一段未压缩的 H.264 视频流,而且这段视频不含声音。为了能被通常的视频播放器所播放,这个 raw 的 H.264 视频还需要转换。可以使用 gpac 包中所带有的 MP4Box 应用。 ...

January 1, 2000

Ray

Documents Documentation Install pip install ray # with client pip install ray[client] Architecture Client Mode: Ray Client Deploy Kubernetes Kuberay Github - Kuberay Kuberay is a Kubernetes operator, it defines custom resource definitions (CRDs) for RayCluster, RayJob and RayService. helm repo add kuberay https://ray-project.github.io/kuberay-helm/ helm repo update # Install both CRDs and KubeRay operator v1.3.0. helm install kuberay-operator kuberay/kuberay-operator --version 1.3.0 RayCluster create a ray cluster # deploy a ray cluster helm install raycluster kuberay/ray-cluster --version 1.3.0 # check ray cluster kubectl get rayclusters # get pods kubectl get pods --selector=ray.io/cluster=raycluster-kuberay forward ray cluster ports ...

January 1, 2000

Redis

Install Ubuntu sudo apt-get update sudo apt-get install redis Set password in redis.conf requirepass YOUR_PASSWORD Docker docker run --name redis -d --restart unless-stopped \ -p 6379:6379 \ -v /data/redis:/data \ -v $(pwd)/redis.conf:/usr/local/etc/redis/redis.conf \ redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes TLS Genenrate certtificates # Generate a private key and a self-signed certificate: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 # Remove the passphrase from the key: openssl rsa -in key.pem -out key.pem # Concatenate the private key and the public certificate into a single .pem file cat key.pem cert.pem > redis.pem Run redis server with TLS ...

January 1, 2000

Regex

Regex 基础 Literal Characters 普通字符: “a” 转义字符: "\", "^", "$", ".", "|", "?", "*", "+", "()", "[]", "{}" “.“匹配任一字符 “gr.y"可以匹配"gray”,“grey"或"gr%y” 应尽量少使用”.“来匹配 除了换行符 “?”, “*”, “+”, “{n}“表示 Repetition "?" 表示0次或1次,例如 colou?r 匹配 color 或 colour "*" 表示0次或多次 "+" 表示1次或多次 "{n}" 表示n次,"{n,m}" 表示n到m次 例子:<[A-Za-z][A-Za-z0-9]*> 表示 "*" 前面的 [A-Za-z0-9] 重复0次或多次,可以匹配 xml 中的一个 tag “[]” 表示 Character Sets 用中括号括起来的一组字符,匹配其中一个char: ex: gr[ae]y: 匹配"gray"或"grey” 在中括号中使用 "-" 来表示一个范围: ex: [0-9a-zA-Z]匹配一个字母或数字 在中括号中使用 "^" 来表示去掉某些字符: ex: “q[^u]“表示"q"后面不接"u"字符 “|” 表示 Alternation 例如"cat|dog"可以匹配"cat"或"dog” 可以连续使用,例如"cat|dog|fish” 使用括号将选择括起,例如 cat|dog food 匹配 cat 或 dog food,而 (cat|dog) food 匹配 cat food 或 dog food Anchors "^" 匹配一行之首 "&" 匹配一行之尾 "\b" 匹配一个单词之首或之尾,例如 \bhi\b 可以匹配 say hi tom 中的 hi Shorthand Character Classes "\d" 表示一个数字字符 "\w" 表示一个字母字符,包括 a-z,A-Z 和"_",等价于[a-zA-Z_] "\s" 表示一个空白字符,包括空格、tab、换行符 Non-Printable Characters "\t"、"\n" 等,使用 "\uFFFF" 或 "\x{FFFF}" 表示 unicode 字符 Greedy and Lazy Repetition 上面的 "?", "*", "+" 默认为贪婪匹配,例如 <.+> 会匹配 <EM>first</EM> 而不是其中的 <EM> 在 quantifier 后面加上 "?" 改变为懒惰匹配,例如 <.+?> 会匹配 <EM> Grouping and Capturing 用小括号将一组字符组合,在匹配后可以 capture 该组 使用 Set(?:Value)? 创建 group 但是不会创建 capturing group Backreferences ([abc]=\1) 可以匹配 a=a,b=b,c=c等 Lookaround 匹配一个 group 周边的字符 q(?=u) 匹配 question 中的 "q" "q(?!u)" 匹配 "Iraq" 中的 "q" "(?<=a>)b" 匹配 "abc" 中的 "b" 常用 多行匹配 "." 不能匹配换行符,(?:.|\n) 指定了一个非捕获组,来匹配换行符 ...

January 1, 2000

Reinforcement Learning

References Github - awesome-rl Github - awesome-deep-rl Github - rl-book Unity ML-Agents Toolkit Github - train_your_own_game_AI Gymnasium Github - CleanRL Frameworks Github - CleanRL Github - Stable Baselines3 Autonomous Vehicle Github - CARLA Github - CARLA-SB3-RL-Training-Environment LLM Github - trl Github - Verl Github - ROLL

January 1, 2000

ROS

Install Docker ROS Docker docker pull ros:noetic Ubuntu Ubuntu install of ROS Noetic # NOTICE: ROS Noetic is only available for Ubuntu 20.04 sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add - sudo apt update sudo apt install ros-noetic-ros-base Environment setup: source /opt/ros/noetic/setup.bash # or echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc source ~/.bashrc

January 1, 2000

Scraper

Scraper [TOC] urllib Python built-in lib for web requesting Import from urllib.request import urlopen from urllib.request import urlretrieve from urllib.error import HTTPError Open url page = urlopen(URL) Requests HTTP for human Import import requests get/post r = requests.get(URL) r = requests.post(URL) Add Headers headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', 'Accept': 'text/html, application/xhtml+xml, application/xml; q=0.9, img/webp,*/*; q=0.8', 'Host': 'www.zhihu.com', 'Referer': 'https://www.zhihu.com/'} r = requests.get(URL, headers=headers) Add cookies cookies = dict(cookies_are='working') r = requests.get(URL, cookies=cookies) # using cookie jar jar = requests.cookies.RequestsCookieJar() jar.set('tasty_cookie', 'yum', domain='httpbin.org', path='/cookies') jar.set('gross_cookie', 'blech', domain='httpbin.org', path='/elsewhere') r = requests.get(url, cookies=jar) Check results ...

January 1, 2000

Server

修改hostname vi /etc/hostname vi /etc/hosts 修改时区 # 查看时区 timedatectl timedatectl list-timezones | grep -i shanghai # 修改时区 sudo timedatectl set-timezone Asia/Shanghai 创建用户 # 创建用户 sudo adduser yzchen # 添加sudoer sudo su chmod +w /etc/sudoers visudo # 相当于vi /etc/sudoers ## 添加以下行 username ALL=(ALL) ALL chmod -w /etc/sudoers ssh免密登录 创建密钥 ssh-keygen 复制公钥到要登录的服务器 ssh-copy-id username@host bashrc配置 配置语言 export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 常用alias alias quick-push="git add --all && git commit -m 'update' && git push -u origin master" alias json_pp="json_pp -json_opt pretty,utf8" 国内源 Mirrors 中科大 清华 pip 临时使用 ...

January 1, 2000

ShortCuts

ShortCuts Ctrl + A: 跳到行首 Ctrl + E: 跳到行尾 Ctrl + W: 清除到上一个单词 # 回到上次所在的目录 cd - # 输入上一个命令 !! clear/Ctrl+L clear the screen history Display the contents of the history list Ctrl+A Move cursor to the beginning of the line Ctrl+E Move cursor to the end of the line Alt+F Move cursor forward one word Alt+B Move cursor backward one word Ctrl+K Kill text from the cursor location to the end of line Ctrl+U Kill text from the cursor location to the beginning of the line Ctrl+Y Yank text from the kill-ring and insert it at the cursor location <tab> <tab> Display list of possible completions Alt+* Insert all possible completions Signals Ctrl-C: 发送 SIGINT,停止进程,可以被进程捕获 Ctrl-Z: 发送 SIGTSTP,暂停进程 Ctrl-\: 发送 SIGQUIT

January 1, 2000