This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clc, clear, close all; | |
x = -10:0.1:10; | |
y = 1 ./ (1 + exp(-x)); %sigmoid | |
plot(x, y); | |
set(gca,'XAxisLocation','origin','YAxisLocation','origin'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"files.autoGuessEncoding": false, | |
"matlab.linterEncoding": "gb2312", | |
"[matlab]": { | |
"files.encoding": "gb2312" | |
} | |
} |
OlderNewer