Blender mesh 创建点线面 uOQ-CPcaqMo AxazJi3x6js

任务:创建一个半径为2圆环,圆环上均布32个点,显示为点或者线。

1. 点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# give Python access to Blender's functionality
import bpy
# extend Python's math functionality
import math
# extend Python's print functionality
import pprint

# initialize paramaters
vert_count = 32 # show with 16 and 64
angle_step = math.tau / vert_count
radius = 2

# create a list of vert coordinates
vert_coordinates = list()

# repeat code in a loop
for i in range(vert_count):

# calculate current current_angle
current_angle = angle_step * i

# calculate coordinate
x = radius * math.cos(current_angle)
y = radius * math.sin(current_angle)

# visualize what we are doing
bpy.ops.mesh.primitive_ico_sphere_add(radius=0.05, location=(x, y, 0))

# add current coordinate to list
vert_coordinates.append((x, y, 0))

pprint.pprint(vert_coordinates)

2. 线

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# give Python access to Blender's functionality
import bpy
# extend Python's math functionality
import math
import pprint


def get_circle_verts(vert_count, radius):
# initialize paramaters
angle_step = math.tau / vert_count

# create a list of vert coordinates
vert_coordinates = list()

# repeat code in a loop
for i in range(vert_count):

# calculate current current_angle
current_angle = angle_step * i

# calculate coordinate
x = radius * math.cos(current_angle)
y = radius * math.sin(current_angle)

# visualize what we are doing
# bpy.ops.mesh.primitive_ico_sphere_add(radius=0.05, location=(x, y, 0))

# add current coordinate to list
vert_coordinates.append((x, y, 0))

return vert_coordinates


def create_circle_mesh(coordinates, vert_count):
verts = coordinates
faces = []
edges = []

for i in range(vert_count - 1):
current_vert_index = i
next_vert_index = i + 1
edges.append((current_vert_index, next_vert_index))

edges.append((vert_count - 1, 0))

# create a mesh from the vert, edge, and face data
mesh_data = bpy.data.meshes.new("circle_data")
mesh_data.from_pydata(verts, edges, faces)

# create a object using the mesh data
mesh_obj = bpy.data.objects.new("circle_object", mesh_data)

bpy.context.collection.objects.link(mesh_obj)


# initialize paramaters
vert_count = 32
radius = 2

coordinates = get_circle_verts(vert_count, radius)

mesh_obj = create_circle_mesh(coordinates, vert_count)


Final Code:

circle_mesh_part_1 https://gist.github.com/CGArtPython/6e98beb424b6c58bbda0469b2c0434a9
circle_mesh_part_2 https://gist.github.com/CGArtPython/a4dff81d8c233601759dffd48917f296


ref:
Beginner Blender Python Exercise: Circle mesh from scratch
https://www.youtube.com/watch?v=uOQ-CPcaqMo
https://www.youtube.com/watch?v=AxazJi3x6js

Blender Python 配置 (on Windows) YUytEtaVrrc

1. 安装 vscode、 blender

1
2
3
4
5
6
scoop install vscode
scoop install blender

# blender 和内置的 python 路径如下:
# blender path : C:\Users\xxxx\scoop\apps\blender\4.2.3\blender.exe
# blender build-in python path : C:\Users\shenb\scoop\apps\blender\4.2.3\4.2\python\bin\python.exe

在 vscode 中选择 python 解释器,注意选择 blender 内置的 python 路径。

2. 安装自动补全 fake-bpy-module

安装时注意要选用 blender 内置的 python -m pip 安装。

ref: https://github.com/nutti/fake-bpy-module

1
2
3
4
5
C:\Users\shenb\scoop\apps\blender\4.2.3\4.2\python\bin\python.exe -m pip install fake-bpy-module

# 安装常用的其他包:
# C:\Users\shenb\scoop\apps\blender\4.2.3\4.2\python\bin\python.exe -m pip install pandas
# C:\Users\shenb\scoop\apps\blender\4.2.3\4.2\python\bin\python.exe -m pip install matplotlib

3. 安装 vscode 插件: Blender Development

ref: https://marketplace.visualstudio.com/items?itemName=JacquesLucke.blender-development

使用时打开命令面板 Ctrl+Shift+P:

  • Blender: Start command 启动一个 Blender 程序实例。
  • Blender: Run Script command 执行当前的 python 脚本。

ref:
5 Steps to setup VSCode for Blender Python (on Windows)
https://www.youtube.com/watch?v=YUytEtaVrrc

视频内字幕提取

video-subtitles-ocr

视频字幕提取,基于 opencv 和 paddleocr

视频内字幕提取

这里是针对内封了硬字幕的视频,字幕已经成为了画面的一部分。

思路:简单用 opencv 提取视频内的所有帧,现在可以使用 paddleocr,更加方便一点对图片进行 ocr 识别。

0. 首先需要配置一下

0.1 安装 python 库

  • opencv-python
  • scikit-image
  • paddleocr

ref: https://paddlepaddle.github.io/PaddleOCR/latest/quick_start.html#1-paddlepaddle

阅读全文 »

word 不能直接导入 eps 格式的图片,所以先将 eps 图片转换成 png 格式。

这里使用 python 调用 PIL 读取 eps 图片,直接保存为 png 图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# pip install pillow
# scoop install ghostscript

from PIL import Image

import os

for parent, dirnames, filenames in os.walk(os.getcwd()):
for filename in filenames:
ext = os.path.splitext(filename)[1]
if ext != '.eps':
continue

eps_image = Image.open(filename)
size = eps_image.size
print(filename, size)

eps_image.load(scale=10) # 分辨率增大到10倍
eps_image.save(filename+'.png', quality=100)
  • PIL 默认采用 Ghostscript 处理 eps 图片, 所以先确保安装了 Ghostscript。 scoop install ghostscript
  • eps 为矢量图,默认情况下其尺寸较小,导致保存成图片式分辨率较低,eps_image.load(scale=10) 将分辨率增大到10倍后保存。

下载 bili 视频

1
2
3
4
5
6
7
pip install you-get
# you-get https://www.bilibili.com/video/BV1234567890

pip install yt-dlp
# yt-dlp https://www.bilibili.com/video/BV1234567890

# yt-dlp "https://www.youtube.com/watch?v=GGGGGGGGGGGG" --proxy http://127.0.0.1:7890

视频转音频

1
2
3
4
5
6
scoop install ffmpeg
ffmpeg -i xxx.mp4
# checkout the audio video format
ffmpeg -i xxx.mp4 -acodec copy xxx.aac
ffmpeg -i xxx.mp4 -acodec copy xxx.mp3
ffmpeg -i xxx.mkv -acodec copy xxx.opus

音频转文字 📘

https://github.com/openai/whisper

  1. ** whisper **:

    1
    2
    3
    4
    pip install -U openai-whisper

    whisper audio.flac audio.mp3 audio.wav --model small --device cpu --language zh

  2. ** python **:
    使用 Python 运行 main.py 脚本。

    1
    2
    3
    4
    5
    6
    import whisper

    model = whisper.load_model("small", device="cpu")
    result = model.transcribe(f"123.mp3")

    print(result["text"]))

cat-catch 设置 N_m3u8DL-RE

ref https://github.com/nilaoda/N_m3u8DL-RE
ref https://github.com/xifangczy/cat-catch
ref https://github.com/corbamico/m3u8dl-invoke/

1.1 安装 n-m3u8dl-re

1
scoop install n-m3u8dl-re_x

1.2 新建 m3u8dl 程序

先用 powershell 写一段脚本 n_m3u8dl-re_protocol.ps1 ,然后转换成可执行文件 n_m3u8dl-re_protocol.exe

  • 脚本
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # 接收m3u8://xxxxxx
    param($m3u8url)
    Write-Host "m3u8url: $m3u8url"

    $bs64 = $m3u8url.replace('m3u8dl://', '').replace('/', '')
    $httpurl = [Text.Encoding]::ASCII.GetString([Convert]::FromBase64String($bs64))
    Write-Host "httpurl: $httpurl"

    $path = 'c:\Users\xxxxx\scoop\shims\N_m3u8DL-re.exe'
    $cmd = $path + ' ' + $httpurl
    Write-Host "$cmd"

    Start-Process "$path" "$httpurl" -NoNewWindow
    Start-Sleep 30
  • 转换
    1
    2
    3
    Install-Module ps2exe

    ps2exe n_m3u8dl-re_protocol.ps1 n_m3u8dl-re_protocol.exe
阅读全文 »

matplotlib marker color 字符对照

ref: https://matplotlib.org/stable/api/colors_api.html
ref: https://matplotlib.org/stable/gallery/color/named_colors.html

1
2
3
4
5
6
7
8
9
10
11

import matplotlib.pyplot as plt
import matplotlib.colors as mcolors

for (k, v) in mcolors.BASE_COLORS.items():
v = "#" + "".join(format(round(val * 255), "02x") for val in v)
print(f'<font color="{v}"> {k:<10} ■ </font>')

for (k, v) in mcolors.TABLEAU_COLORS.items():
print(f'<font color="{v}"> {k:<10} ■ </font>')

mcolors.BASE_COLORS (8)

████ b
████ g
████ r
████ c
████ m
████ y
████ k
████ w

mcolors.TABLEAU_COLORS (10)

████ tab:blue
████ tab:orange
████ tab:green
████ tab:red
████ tab:purple
████ tab:brown
████ tab:pink
████ tab:gray
████ tab:olive
████ tab:cyan

阅读全文 »

Python f-string 备忘单

ref https://fstring.help/cheat/

ref https://cheatography.com/brianallan/cheat-sheets/python-f-strings-basics/
ref https://cheatography.com/brianallan/cheat-sheets/python-f-strings-number-formatting/

数字

num format
%d 整数
%e 科学计数
%f 浮点
% 百分数
%b 二进制
%o 八进制
%x 十六进制
%c Unicode

integer = 123
number_ = 9876.6789
percent = 0.98765

var num format f-string output
integer 123 d f’{integer:d}’ 123
integer 123 b f’{integer:b}’ 1111011
integer 123 8b f’{integer:8b}’ 1111011
integer 123 _b f’{integer:_b}’ 111_1011
integer 123 09_b f’{integer:09_b}’ 0111_1011
integer 123 o f’{integer:o}’ 173
integer 123 #o f’{integer:#o}’ 0o173
integer 123 x f’{integer:x}’ 7b
integer 123 #x f’{integer:#x}’ 0x7b
integer 123 08x f’{integer:08x}’ 0000007b
integer 123 c f’{integer:c}’ {
number_ 9876.6789 f f’{number_:f}’ 9876.678900
number_ 9876.6789 .2f f’{number_:.2f}’ 9876.68
number_ 9876.6789 09.2f f’{number_:09.2f}’ 009876.68
number_ 9876.6789 09.5f f’{number_:09.5f}’ 9876.67890
number_ 9876.6789 .2f f’{number_:.2f}’ 9876.68
percent 0.98765 % f’{percent:%}’ 98.765000%
percent 0.98765 9.5% f’{percent:9.5%}’ 98.76500%
percent 0.98765 09.4% f’{percent:09.4%}’ 098.7650%
percent 0.98765 09.5% f’{percent:09.5%}’ 98.76500%
number_ 9876.6789 .2e f’{number_:.2e}’ 9.88e+03
number_ 9876.6789 09.2e f’{number_:09.2e}’ 09.88e+03

string = “Python”

var num format f-string output
string Python 20 f’{string:20}’ Python
string Python >20 f’{string:>20}’ Python
string Python <20 f’{string:<20}’ Python
string Python ^20 f’{string:^20}’ Python
string Python >>20 f’{string:>>20}’ >>>>>>>>>>>>>>Python
string Python <<20 f’{string:<<20}’ Python<<<<<<<<<<<<<<
string Python ^^20 f’{string:^^20}’ ^^^^^^^Python^^^^^^^
string Python =^20 f’{string:=^20}’ =======Python=======
阅读全文 »

radioactivedecay 用于放射性核素衰变的简单分析计算的开源包,支持放射性核素、亚稳态和分支衰变的衰变链。

https://github.com/radioactivedecay/radioactivedecay

安装:pip install radioactivedecay

1. 绘制衰变链

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#%%
import radioactivedecay as rd
import matplotlib.pyplot as plt

# 创建一个放射性核素: Nuclide
ncld = rd.Nuclide('U-235')
half = ncld.half_life('readable') # 半衰期
prog = ncld.progeny() # 衰变产物
frac = ncld.branching_fractions() # 占比
mode = ncld.decay_modes() # 衰变射线类型

print(ncld, mode, prog, frac, half, sep='\n')

# 绘制衰变链
ncld.plot()

#%%
# 列出多个核算衰变类型
NUCs = ['U-235',
'Pu-239']

for name in NUCs:
ncld = rd.Nuclide(name)
half = ncld.half_life('readable')
prog = ncld.progeny()
frac = ncld.branching_fractions()
mode = ncld.decay_modes()
print(ncld, mode, prog, frac, half, sep='\n')

fig, ax = ncld.plot()
fig.savefig(f'decay_chains_{name}.png', dpi=300)

阅读全文 »

pandas 合并数据常用的两个函数:

刚好有一个对比 RNN 和 LSTM 神经网络运行结果的场景分别用到了这两个函数:

  • 采用 concat 合并两个csv表; csv表为两次运行结果的,列名基本一致。
  • 采用 merge 合并模型运行条件类似的表, 用于对比数据
阅读全文 »

一、WSL 安装 Ubuntu22.04

  1. 启用 WSL

  2. 打开 Microsoft Store,安装 Ubuntu22.04

  3. 设置源,更新
    ref: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

更新:sudo apt update

升级:sudo apt upgrade

  1. 安装 ZSH、oh-my-zsh

参考 zsh & oh-my-zsh 安装配置

二、安装 openmc

ref: https://docs.openmc.org/en/stable/quickinstall.html

  1. 参照 Installing from Source on Ubuntu,安装 openmc。

    安装完成后,运行 openmc 试一下, 提示错误: 找不到材料数据卡 cross_sections.xml

  2. 下载材料数据集

    1
    2
    3
    4
    git clone https://github.com/openmc-dev/data openmc-dev_data

    cd openmc-dev_data
    python3 convert_nndc71.py
    阅读全文 »

ref: https://github.com/ScoopInstaller/Scoop/issues/4390

0. 问题: scoop 本身不支持安装包有解压密码的自动解压。

scoop 本身不支持安装包有解压密码的自动解压。因此在安装 MAS 时会卡在解压处,无法继续安装。

1. 7z 命令手册

7z 命令是支持的: 7z x FILENAME.7z -pPWD -oOUTDIR

2. 查 Scoop 源码的解压函数

找到 Scoop 源码里的 “~\scoop\apps\scoop\current\lib\decompress.ps1” 文件。
文件封装了 Expand-7zipArchive 函数命令, 但参数没有能将密码传入的方法。

3. 试 Scoop 的 pre_install

Scoop Wiki 里提到了 pre_install 等说法。

在 MAS.json 中加入:

1
"pre_install": "7z x $dir\\$fname -p1234 $('-o' + $dir)"

尝试了很多次还是不起作用,Scoop的策略是遇到压缩包先执行解压、再做后续的事情。所以这一句不会被执行,安装程序依旧卡在解压处,无法继续安装。

阅读全文 »

1. 客户端 VSCode 安装 Remote 插件

安装插件, 略

添加远程连接 aaa@192.168.1.xxx, 连接、等待, 输入密码

2. 连接时可能连不上,并出现警告

警告: The remote host may not meet VS Code Server's prerequisitesfor glibc and libstdc++

阅读全文 »

从在线日历获取事件

Outlook 查看日历链接: 设置-日历-共享日历-发布日历,可以看到如下链接:

https://outlook.live.com/owa/calendar/d82e6afe-XXXX-XXXX/cid-YYYY/calendar.ics

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from ics import Calendar
import requests

# Parse the URL
url = "https://outlook.live.com/owa/calendar/d82e6afe--XXXX-XXXX/cid-YYYY/calendar.ics"
cal = Calendar(requests.get(url).text)


#%%
# Print all the events
events = sorted(cal.events)
for event in events:
print(event.begin , event.name )

#%%
timeline = cal.timeline
for tl in timeline:
print(tl.begin , tl.name )

# %%
# 获取今天及之后的事件
from ics import Calendar
import requests
import arrow

cal = Calendar(requests.get(url).text)

today = arrow.now()
print(today)
today = arrow.now().replace(hour=0, minute=0, second=0, microsecond=0)
print(today)
today = arrow.now().span('day')[0]
print(today)

evts = cal.timeline.start_after(today)

for evt in evts:
print(evt.begin.strftime("%Y-%m-%d %a %H:%M"), evt.name )

ref: (https://github.com/ScoopInstaller/Scoop/wiki/App-Manifests)

尝试自己制作一个安装配置文件, 软件是 N_m3u8DL-RE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
"version": "v0.2.0-beta",
"description": "Cross-Platform, modern and powerful stream downloader for MPD/M3U8/ISM",
"homepage": "https://github.com/nilaoda/N_m3u8DL-RE",
"license": "MIT",
"suggest": {
"ffmpeg": [
"ffmpeg",
"ffmpeg-nightly"
]
},
"url": "https://github.com/nilaoda/N_m3u8DL-RE/releases/download/v0.2.0-beta/N_m3u8DL-RE_Beta_win-x64_20230628.zip",
"hash": "9e3133f03e112cc57f34bf04234b7857ae7c997c214f0eb510a120739c388652",
"bin": [
"N_m3u8DL-RE_Beta_win-x64/N_m3u8DL-RE.exe",
[
"N_m3u8DL-RE.exe",
"N_m3u8DL_RE"
]
],
"checkver": {
"url": "https://api.github.com/repos/nilaoda/N_m3u8DL-RE/releases",
"regex": "releases/download/(?<tag>[vV]?[\\w-.]+)/N_m3u8DL-RE_Beta_win-x64_(?<date>[\\d.-]+).zip",
"replace": "${tag}"
},
"autoupdate": {
"url": "https://github.com/nilaoda/N_m3u8DL-RE/releases/download/$matchTag/N_m3u8DL-RE_Beta_win-x64_$matchDate.zip"
}
}

阅读全文 »

1 安装 zsh

1
2
3
4
5
sudo apt install zsh

# echo $SHELL # 显示当前 shell 类型
# cat /etc/shells # 显示可使用的 shell
# chsh -s /bin/zsh # 将 zsh 设为默认终端

2 安装 ohmyzsh

ref: https://ohmyz.sh/

  • 用 wget 安装。
    1
    sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

有时候会出现 443 网路错误,可手动下载、安装 install.sh

1
nano zsh-install.sh

打开 https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh
将安装代码全部复制进去

1
2
sudo chmod +x zsh-install.sh
./zsh-install.sh

3 安装 ohmyzsh (gitee 源)

ref: https://gitee.com/mirrors/oh-my-zsh.git

1
sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"

4 配置 ohmyzsh (gitee 源)

  • 打开配置文件

    1
    nano ~/.zshrc
  • 修改如下:

    1
    2
    3
    4
    5
    # 主题
    ZSH_THEME="ys"

    # 插件
    plugins=(git zsh-autosuggestions zsh-syntax-highlighting )
  • 也可以用命令修改:

    1
    2
    sed -i 's/^ZSH_THEME=.*/ZSH_THEME="ys"/g' .zshrc
    sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g' .zshrc
  • 下载插件

    1
    2
    3
    git clone https://gitee.com/mirrors/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

    git clone https://gitee.com/mirrors/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

    ref: https://github.com/zsh-users/zsh-autosuggestions

ref: https://github.com/zsh-users/zsh-syntax-highlighting

  • 加载配置文件, 使生效
    1
    source ~/.zshrc

===

1
2
3
4
5
6
7
8
9
10
11
12
sudo apt install zsh -y
sudo apt install git -y

sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"

sed -i 's/^ZSH_THEME=.*/ZSH_THEME="ys"/g' .zshrc
sed -i 's/^plugins=.*/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g' .zshrc

git clone https://gitee.com/mirrors/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://gitee.com/mirrors/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

source ~/.zshrc

用 raspberry pico w 和墨水屏做一个 mnist-clock

1. 墨水屏

2. pico w 基本配置

2.1 刷固件

  • https://micropython.org/download/rp2-pico-w/

  • 下载类似rp2-pico-w-20221107-unstable-v1.19.1-616-g5987130af.uf2

  • 首次将 pico w 连接电脑之后,会以U盘形式弹出来,把固件拖进去。

  • 已经刷过固件的,按着板子上的 BOOTTSEL 按钮连接电脑。

重新上电,固件就自动刷好了。

2.2 开发环境 thonny

  • 安装 thonny, scoop install thonny
  • Thonny IED: 打开 ‘运行’ - ‘配置解释器’, 配置一下
  • 运行一下板载的 LED 测试程序:
1
2
3
4
5
6
7
8
9
from machine import Pin 
import time

led = Pin('LED', Pin.OUT)
while(True):
led.on()
time.sleep(1)
led.off()
time.sleep(1)

可以看到板载的 LED 在闪烁。

阅读全文 »