Created
January 15, 2019 15:13
-
-
Save Jojozzc/c3d9f8b62ab8802e79af80ac49260864 to your computer and use it in GitHub Desktop.
Adjust contours in shape1 to fit in shape2, so we can draw contours in any image shaped from original image(shape1).
This file contains 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 | |
def test(): | |
cnts_path = '../high_speed_train/newUITestData2/.DETECTION_RESULT/K696+203_S0_P001_T235240784_ZCA1_jpg/cnts.npy' | |
cnts = np.load(cnts_path) | |
print(cnts.dtype) | |
# print(cnts) | |
print(len(cnts)) | |
res = resize_contours(cnts, (6600, 3300), (800, 600)) | |
print(res) | |
if __name__ == '__main__': | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment