CLionでビルド済み配布OpenCVを利用する

・CMakeLists.txt

include_directories( C:/opencv/build/include )
link_directories( C:/opencv/build/x64/vc15/lib )

add_executable( test opencv_test.cpp )

target_link_libraries( test opencv_world420d.lib)

 

・CLion設定

File->Settings->Build, Execution, Deployment->ToolchainsからVisual Studioを選択し、Visual StudioのバージョンとArchitectureをCMakeLists.txtに合わせる。
 上記の例なら、VS2017-amd64

さらに、CMakeのToolchainの欄を"Visual Studio"に設定。

Open3Dでテクスチャマッピング

import open3d as o3d
import numpy as np
import cv2
from copy import deepcopy


def main():

img = cv2.imread('lenna.bmp')
img = deepcopy(img[:, :, ::-1])

vert = [[-1, 1, 0], [-1, -1, 0], [1, 1, 0], [1, -1, 0]]
faces = [[0, 1, 2], [1, 3, 2]]
uvs = np.array([[0, 0], [0, 1], [1, 0], [0, 1], [1, 1], [1, 0]])

obj = o3d.geometry.TriangleMesh(o3d.utility.Vector3dVector(vert),
o3d.utility.Vector3iVector(faces))
obj.triangle_uvs = o3d.utility.Vector2dVector(uvs)
obj.textures = [o3d.geometry.Image(img)]
obj.triangle_material_ids = o3d.utility.IntVector([0] * len(faces))

obj.compute_vertex_normals()
o3d.visualization.draw_geometries([obj])


if __name__ == '__main__':
main()

 

n_rows = 6
vertices = []
for y in range(n_rows):
for x in range(n_rows):
vertices.append([x - 2.5, 2.5 - y, 0])

uv_unit = 0.2
faces = []
uvs = []
for y in range(n_rows - 1):
for x in range(n_rows - 1):
faces.extend([[y * 6 + x, (y + 1) * 6 + x, y * 6 + x + 1],
[y * 6 + x + 1, (y + 1) * 6 + x, (y + 1) * 6 + x + 1]])
uvs.extend([[x * uv_unit, y * uv_unit], [x * uv_unit, (y + 1) * uv_unit],
[(x + 1) * uv_unit, y * uv_unit], [(x + 1) * uv_unit, y * uv_unit],
[x * uv_unit, (y + 1) * uv_unit], [(x + 1) * uv_unit, (y + 1) * uv_unit]])

ffmpegでGIF変換

・gif→mp4 + crop
ffmpeg -i input.gif -pix_fmt yuv420p -vf crop=640:720:320:0 output.mp4

・パレット作成
ffmpeg -i input.mp4 -vf palettegen palette.png

・mp4→gif + loop無し
ffmpeg -i input.mp4 -i palette.png -filter_complex paletteuse -loop -1 output.gif

音声信号処理のお勉強

・スペクトル解析
スペクトル(スペクトラム
 信号を周波数変換したもの
スペクトログラム
 短時間のスペクトルを時間軸に沿って並べたもの(三次元データ)
対数スペクトル
 スペクトルの対数をとったもの。音源対数スペクトルと声道対数スペクトルの和
ケプストラム
 対数スペクトルを周波数変換したもの。横軸はケフレンシー[ms]
 声道成分が低次に、音源成分高次に分離される
スペクトル包絡
 ケプストラムの高次成分(音源成分)をカットした上で周波数変換したもの
 声道スペクトル
フォルマント
 スペクトル包絡のピーク
メルフィルタバンク
 メル尺度上で均等間隔となるように複数のバンドパスフィルタを並べたもの
メル周波数スペクトラム
 スペクトルにメルフィルタバンクをかけ(20次元に圧縮し)たもの
メル周波数ケプストラム
 メル周波数スペクトラムの対数をとり、周波数変換したもの
メル周波数ケプストラム係数(MFCC)
 メル周波数ケプストラムの低次12次元をとったもの

Blender Pythonスクリプト集

・参考
Blender 2.8 で Python スクリプトを実行してみる


・Sceneの抽出(どちらも同じ)
bpy.context.scene
bpy.data.scenes['Scene']

・Objectsの抽出(どちらも同じ)
bpy.context.scene.objects
bpy.data.objects

・Object種類の抽出
for o in bpy.data.objects:
    print(o.type)
python - How to get the Class of selected object in Blender 2.8? - Blender Stack Exchange

・メッシュの抽出
for mesh in bpy.data.meshes:Blender PythonのMeshデータアクセスのチートシート - Qiita

・マテリアルの抽出
for material in bpy.data.materials:  # 全マテリアル

for o in bpy.data.objects:
    if o.type == 'MESH':
        for m in o.material_slots:  # そのメッシュに使われているマテリアル

・モード切替
for o in bpy.data.objects:
    bpy.context.view_layer.objects.active = o
    bpy.ops.object.mode_set(mode = 'EDIT')  # 戻すときはmode = 'OBJECT'

レンダリング画像のファイル出力(1枚)
bpy.ops.render.render()  # opsはOperator
bpy.data.images['Render Result'].save_render('C:/kaggle/render.png')

レンダリング画像のファイル出力(1枚)
scene = bpy.context.scene
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = 'C:/kaggle/render'
bpy.ops.render.render(write_still=True)

レンダリングの設定
scene = bpy.context.scene
scene.render.image_settings.file_format = 'PNG'
scene.render.filepath = 'C:/kaggle/render'
scene.render.resolution_x = 800  # 解像度
scene.render.resolution_percentage = 100  # プレビュー解像度
scene.render.use_persistent_data = True  # 再レンダリングの効率化
scene.render.film_transparent = True  # 背景の透過
scene.render.dither_intensity = 0.0  # ディザの強さ

・オブジェクトの位置の指定
cube = bpy.data.objects['Cube']
cube.location = (0, 0, 0)

・カメラの姿勢の指定
def look_at(cam, obj):
    # カメラからオブジェクトへのベクトルを算出
    direction = obj.matrix_world.to_translation() - cam.matrix_world.to_translation()
    # カメラの視線方向(-Z)がそのベクトルの向きとなる姿勢をカメラの姿勢とする
    cam.rotation_quaternion = direction.to_track_quat('-Z', 'Y')

python - Pointing the camera in a particular direction programmatically - Blender Stack Exchange

Blenderでワールドマトリクスからオブジェクトの軸方向を取得 - Blenderとか3DCGとか
Blenderのカメラの向きを操作しよう | Rafkaの実験室

・キーフレームの設定

Blender pythonでノードにキーフレームを追加 | ぬの部屋(仮)

・アニメーション確認
for obj in bpy.data.objects:
    fcurves = obj.animation_data.action.fcurves
        for fc in fcurves:
            for kp in fc.keyframe_points:
                data_type = fc.data_path  # location, rotation, scaleなど
                frame = int(kp.co[0])  # フレーム番号
                axis = fc_array_index  # x, y, zなど
                value = kp.co[1]

・ボーン情報の取得①

armature = bpy.data.objects['Armature']
for bone in armature.data.bones:
print(bone.name)
for bone in armature.pose.bones:
print(bone.location)
print(bone.rotation_quaternion)
print(bone.rotation_euler)

 

・ボーン情報の取得②
Blender2.8で利用可能なpythonスクリプトを作る その16(ボーンの操作、ポーズの適用) - MRが楽しい


・最初と最後のキーフレーム番号を取得

Blender でスクリプトを使ってレンダリング - tkaaad97’s diary
frame_start = int(armature.animation_data.action.frame_range[0])
frame_end = int(armature.animation_data.action.frame_range[1])