Skip to content

Instantly share code, notes, and snippets.

View Jojozzc's full-sized avatar
🏍️
Racing

Jojo Jojozzc

🏍️
Racing
View GitHub Profile
@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"
}
}
@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 / 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 / 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 / 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 / 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 / cvt_unix_like_path.py
Created January 8, 2019 09:21
convert path to unix-like path
def cvt_unix_like_path(path):
if path is None:
return None
path = str(path)
unix_p_temp = path.replace('\\', '/')
unix_p = ''
pre = ''
for ch in unix_p_temp:
if not (ch == '/'):
unix_p = unix_p + ch
@Jojozzc
Jojozzc / disp_multiple_images.py
Created December 29, 2018 11:15 — forked from soply/disp_multiple_images.py
Plot multiple images with matplotlib in a single figure. Titles can be given optionally as second argument.
import matplotlib.pyplot as plt
import numpy as np
def show_images(images, cols = 1, titles = None):
"""Display a list of images in a single figure with matplotlib.
Parameters
---------
images: List of np.arrays compatible with plt.imshow.
@Jojozzc
Jojozzc / gpu_monitor.py
Created December 28, 2018 11:26
get gpu memory usage rate by python
import os
# GPU 00000000:88:00.0
# FB Memory Usage
# Total : 8119 MiB
# Used : 2 MiB
# Free : 8117 MiB
# BAR1 Memory Usage
# Total : 256 MiB
# Used : 5 MiB
# Free : 251 MiB
@Jojozzc
Jojozzc / file_count.py
Last active December 28, 2018 02:12
File count
# Usage:
# $python file_count.py [option]
# options:
# -r count recursively
# -s[dir] workdir
# eg.
# #work on curent workdir:
# $python file_count.py
# #count recursively