Skip to content

Instantly share code, notes, and snippets.

@nixeneko
nixeneko / draw_quad_bspline_w_truetype_points.py
Created Aug 14, 2021
Draw a quadratic B-spline curve with TrueType control points
View draw_quad_bspline_w_truetype_points.py
# coding: utf-8
from PIL import Image, ImageDraw
import math, sys
import time
STEP = 10000
# 9 cps ~ 8 segments
CPS1 = [(10, 10), (10, 990), (250, 500), (500, 990), (750, 500), (990, 990), (990, 10), (500, 500), (10, 10)]
@nixeneko
nixeneko / draw_bspline_polyline.py
Created Aug 14, 2021
Draw a quadratic B-spline curve approximating a linear B-spline curve
View draw_bspline_polyline.py
# coding: utf-8
from PIL import Image, ImageDraw
import math
STEP = 10000
# 14 cps ~ 13 segments
CPS = [(10, 10), (10, 990), (990, 990), (970, 10), (40, 70), (120, 970), (970, 820), (760, 40), (70, 280), (300, 910), (890, 670), (500, 160), (160, 500), (0, 0)]
@nixeneko
nixeneko / face_detection.py
Created Aug 7, 2018
OpenCV/DNN object detection (Darknet YOLOv3) test
View face_detection.py
import cv2 as cv
import argparse
import sys
import numpy as np
MODEL = "yolov3-face_final.weights"
CFG = "yolov3-face.cfg"
SCALE = 0.00392 # 1/255, 入力のスケール
INP_SHAPE = (416, 416) #入力サイズ
MEAN = 0
@nixeneko
nixeneko / readType2CharStr.py
Created Jun 16, 2018
Convert Type 2 Charstring to human-readable commands.
View readType2CharStr.py
#!/usr/bin/env python3
# coding: utf-8
# Input Type 2 Charstring hex dump (space-separated)
T2CHARSTR = "85 D2 F7 22 CC F7 90 DE 71 D1 12 F7 A1 D3 52 CE 52 D2 F5 D0 F7 93 D7 13 D9 80 F9 15 CC 15 53 5E A1 BE B3 B8 A8 BE BA B8 7E 74 B6 1F 4A 75 64 62 46 1B 13 D3 80 FB A3 F8 D4 15 3A 0A 13 E3 80 80 89 67 88 5D 1E 58 82 51 85 6B 89 73 8A 78 8A 75 8C 93 39 18 13 E5 80 31 0A 13 D9 80 24 0A B1 8C B7 8E B8 1E E8 E2 F7 14 EA E7 1B DD C8 3F FB 10 59 89 5C 85 61 1F 9E 60 5B 96 56 1B 26 44 51 3C 27 DB 62 EA EF C6 BB DF AC 1F A8 73 A9 6E A8 6A B5 CC 18 69 AF 67 AC 63 A7 08 94 BB 8F C2 C9 1A F7 38 44 F7 0C FB 1A 1E 13 D5 80 FB 00 FB 0F 33 40 37 1F 8C 9C 8D 9B 8C 9B 08 13 D3 80 B8 0A" #ね
#T2CHARSTR = "86 89 92 D0 93 C3 90 A3 19 2C 8E 05 90 72 8A 71 74 1A 0B"
#T2CHARSTR = "C9 93 E1 97 B8 90 89 6C 89 6B 89 6B 59 3D FB 06 FB 2E 54 46 BD 46 18 0B"
#T2CHARSTR = "BB CD CC EA BB D4 08 7C 8A 7E 81 1A 89 FB 02 8B 5A 8A 2C 08 7B 89 6E 8A 7D 1E E2 06 89 9D 89 A4 8A 9C 08 87 E4 8B C7 E5 1A 0B"
#T2CHARSTR = "9A A3 9C A6 97 9D 08 0E"
@nixeneko
nixeneko / readDICT.py
Last active Jun 14, 2018
Convert DICT binary to human-readable key-value pairs.
View readDICT.py
#!/usr/bin/env python3
# coding: utf-8
# Print human-readable key-value pairs.
# output: val_a1 val_a2 ... <key_a> val_b1 ... <key_b>
# input DICT data (space-separated hex string)
DICTSTR = "F8 1B F8 1C 8B 0C 1E F8 1D 01 F8 1E 02 F8 1F 03 F8 18 04 FB 2A 0C 03 FE 7E FE AC 1D 00 00 0B 70 1D 00 00 07 10 05 8C 96 1D 00 8D 83 C8 0E 1E 1A 00 4F 0C 1F 1D 00 00 FF FF 0C 22 1D 00 00 3C B6 0F 1D 00 00 3C BB 0C 25 1D 00 DC 32 6B 0C 24 1D 00 00 3E 13 11"
#DICTSTR = "F8 2E 0C 26 A1 1D 00 EB 78 6C 12"
#DICTSTR = "FB 8E 8B 1D 00 00 05 46 8B 06 D3 0A D5 0B 8C 0C 11 FA 7C 14 A1 13"
@nixeneko
nixeneko / time_popcount.py
Created Mar 2, 2018
Calculate the execution times of popcount functions
View time_popcount.py
# coding: utf-8
def dummy(n):
return 0
def popcnt0(n):
c = 0
for i in range(64):
c += (n >> i) & 1
@nixeneko
nixeneko / shiftfontoutline.py
Created Dec 11, 2017
Draw font outline and shifted outlines
View shiftfontoutline.py
# coding: utf-8
from fontTools.ttLib import TTFont
from PIL import Image, ImageDraw
import math
INFILE = "mplus-1p-regular.ttf"
ttf = TTFont(INFILE)
tags = ttf.reader.tables
@nixeneko
nixeneko / cutdetection.py
Created Sep 4, 2017
Cut detection in movies using OpenCV
View cutdetection.py
# coding: utf-8
import cv2
import numpy as np
INFILE = "gochiusa#1.mp4" # movie file
THRESH = 55.55679398148148 # threshold
ESC_KEY = 27 # Escキー
INTERVAL= 1 # 待ち時間
@nixeneko
nixeneko / fizzbuzz.tex
Last active Aug 4, 2017
a fizzbuzz implementation on TeX. tested on zelatex/
View fizzbuzz.tex
\documentclass[a4paper]{bxjsarticle}
\usepackage{zxjatype}
\usepackage{url}
\usepackage{here}
\usepackage{amsmath}
\usepackage{polyglossia}
%\setdefaultlanguage{english}
\setjamainfont{ipam.ttf}
\setjasansfont{ipag.ttf}
\setjamonofont{ipag.ttf}