Skip to content

Instantly share code, notes, and snippets.

View Jojozzc's full-sized avatar
🏍️
Racing

Jojo Jojozzc

🏍️
Racing
View GitHub Profile
@Jojozzc
Jojozzc / ndarray2json.py
Last active March 26, 2019 13:36
convert ndarray to json
import json
class NumpyEncoder(json.JSONEncoder):
""" Special json encoder for numpy types """
def default(self, obj):
if isinstance(obj, (np.int_, np.intc, np.intp, np.int8,
np.int16, np.int32, np.int64, np.uint8,
np.uint16, np.uint32, np.uint64)):
return int(obj)
elif isinstance(obj, (np.float_, np.float16, np.float32,
np.float64)):
@Jojozzc
Jojozzc / cv2_cnts_adjust.py
Created January 15, 2019 15:13
Adjust contours in shape1 to fit in shape2, so we can draw contours in any image shaped from original image(shape1).
import numpy as np
def resize_contours(cnts, cnts_origin_shape_WxH:tuple, to_shape_WxH:tuple):
w_resize_rate = to_shape_WxH[0] / cnts_origin_shape_WxH[0]
h_resize_rate = to_shape_WxH[1] / cnts_origin_shape_WxH[1]
rate = (w_resize_rate, h_resize_rate)
for i in range(len(cnts)):
cnt = cnts[i] * rate
cnts[i] = np.array(cnt, dtype='int')
return cnts
@Jojozzc
Jojozzc / cv_helper.py
Created January 18, 2019 13:31
fix ZH path bug
import numpy as np
import cv2
import os
def cv2_imread(filename, mode=-1):
# 0:gray
# 1:rgb
# -1 any, read as the mode of source itself.
# like cv2.imread
cv_img = cv2.imdecode(np.fromfile(filename, dtype=np.uint8), mode)
@Jojozzc
Jojozzc / img_util.py
Created March 10, 2019 07:34
image helper
def color_kinds(img):
color_set = set()
if np.ndim(img) == 2:
channel_num = 1
elif np.ndim(img) >= 3:
channel_num = np.size(img, np.ndim(img) - 1)
else:
print('unknow img format')
return color_set
@Jojozzc
Jojozzc / axis_location_center.m
Created May 26, 2019 05:40
move axis center
clc, clear, close all;
x = -10:0.1:10;
y = 1 ./ (1 + exp(-x)); %sigmoid
plot(x, y);
set(gca,'XAxisLocation','origin','YAxisLocation','origin');
@Jojozzc
Jojozzc / settings.json
Created December 1, 2019 01:45
VSCode setting for matlab, Chinese encoding in windows
{
"files.autoGuessEncoding": false,
"matlab.linterEncoding": "gb2312",
"[matlab]": {
"files.encoding": "gb2312"
}
}