From 676e0d5428f10659380662cfec0dd3d62836d91c Mon Sep 17 00:00:00 2001 From: George Hotz Date: Fri, 24 Apr 2020 08:58:18 -0700 Subject: [PATCH] remove unused code old-commit-hash: da5cb1842ae4bd0f57dff9e0d0b9cd7e04aa09e3 --- common/log_compressor.py | 92 -------------------------------- common/transformations/camera.py | 79 --------------------------- 2 files changed, 171 deletions(-) delete mode 100644 common/log_compressor.py diff --git a/common/log_compressor.py b/common/log_compressor.py deleted file mode 100644 index 29ec3f0cb0..0000000000 --- a/common/log_compressor.py +++ /dev/null @@ -1,92 +0,0 @@ -import sys -import json -# pip2 install msgpack-python -import msgpack -import zlib -import os -import logging - -from Crypto.Cipher import AES - -ext = ".gz" -SWAG = '\xde\xe2\x11\x15VVC\xf2\x8ep\xd7\xe4\x87\x8d,9' - -def compress_json(in_file, out_file): - logging.debug("compressing %s -> %s", in_file, out_file) - - errors = 0 - - good = [] - last_can_time = 0 - with open(in_file, 'r') as inf: - for ln in inf: - ln = ln.rstrip() - if not ln: continue - try: - ll = json.loads(ln) - except ValueError: - errors += 1 - continue - if ll is None or ll[0] is None: - continue - if ll[0][1] == 1: - # no CAN in hex - ll[1][2] = ll[1][2].decode("hex") - # relativize the CAN timestamps - this_can_time = ll[1][1] - ll[1] = [ll[1][0], this_can_time - last_can_time, ll[1][2]] - last_can_time = this_can_time - good.append(ll) - - logging.debug("compressing %s -> %s, read done", in_file, out_file) - data = msgpack.packb(good) - data_compressed = zlib.compress(data) - # zlib doesn't care about this - data_compressed += "\x00" * (16 - len(data_compressed)%16) - aes = AES.new(SWAG, AES.MODE_CBC, "\x00"*16) - data_encrypted = aes.encrypt(data_compressed) - with open(out_file, "wb") as outf: - outf.write(data_encrypted) - - logging.debug("compressing %s -> %s, write done", in_file, out_file) - - return errors - -def decompress_json_internal(data_encrypted): - aes = AES.new(SWAG, AES.MODE_CBC, "\x00"*16) - data_compressed = aes.decrypt(data_encrypted) - data = zlib.decompress(data_compressed) - msgs = msgpack.unpackb(data) - good = [] - last_can_time = 0 - for ll in msgs: - if ll[0][1] == 1: - # back into hex - ll[1][2] = ll[1][2].encode("hex") - # derelativize CAN timestamps - last_can_time += ll[1][1] - ll[1] = [ll[1][0], last_can_time, ll[1][2]] - good.append(ll) - return good - -def decompress_json(in_file, out_file): - logging.debug("decompressing %s -> %s", in_file, out_file) - f = open(in_file) - data_encrypted = f.read() - f.close() - - good = decompress_json_internal(data_encrypted) - out = '\n'.join(map(lambda x: json.dumps(x), good)) + "\n" - logging.debug("decompressing %s -> %s, writing", in_file, out_file) - f = open(out_file, 'w') - f.write(out) - f.close() - logging.debug("decompressing %s -> %s, write finished", in_file, out_file) - -if __name__ == "__main__": - for dat in sys.argv[1:]: - print(dat) - compress_json(dat, "/tmp/out"+ext) - decompress_json("/tmp/out"+ext, "/tmp/test") - os.system("diff "+dat+" /tmp/test") - diff --git a/common/transformations/camera.py b/common/transformations/camera.py index 9ee1b62a8a..5ca9eb57d5 100644 --- a/common/transformations/camera.py +++ b/common/transformations/camera.py @@ -146,82 +146,3 @@ def pretransform_from_calib(calib): camera_frame_from_calib_frame = get_camera_frame_from_calib_frame(camera_frame_from_road_frame) return np.linalg.inv(camera_frame_from_calib_frame) -def transform_img_M(size, - augment_trans=np.array([0,0,0]), - augment_eulers=np.array([0,0,0]), - from_intr=eon_intrinsics, - to_intr=eon_intrinsics, - pretransform=None): - import cv2 # pylint: disable=import-error - cy = from_intr[1,2] - def get_M(h=1.22): - quadrangle = np.array([[0, cy + 20], - [size[1]-1, cy + 20], - [0, size[0]-1], - [size[1]-1, size[0]-1]], dtype=np.float32) - quadrangle_norm = np.hstack((normalize(quadrangle, intrinsics=from_intr), np.ones((4,1)))) - quadrangle_world = np.column_stack((h*quadrangle_norm[:,0]/quadrangle_norm[:,1], - h*np.ones(4), - h/quadrangle_norm[:,1])) - rot = orient.rot_from_euler(augment_eulers) - to_extrinsics = np.hstack((rot.T, -augment_trans[:,None])) - to_KE = to_intr.dot(to_extrinsics) - warped_quadrangle_full = np.einsum('jk,ik->ij', to_KE, np.hstack((quadrangle_world, np.ones((4,1))))) - warped_quadrangle = np.column_stack((warped_quadrangle_full[:,0]/warped_quadrangle_full[:,2], - warped_quadrangle_full[:,1]/warped_quadrangle_full[:,2])).astype(np.float32) - M = cv2.getPerspectiveTransform(quadrangle, warped_quadrangle.astype(np.float32)) - return M - - M = get_M() - if pretransform is not None: - M = M.dot(pretransform) - return M - -def transform_img(base_img, - augment_trans=np.array([0,0,0]), - augment_eulers=np.array([0,0,0]), - from_intr=eon_intrinsics, - to_intr=eon_intrinsics, - output_size=None, - pretransform=None, - yuv=False, - alpha=1.0, - beta=0, - blur=0): - import cv2 # pylint: disable=import-error - cv2.setNumThreads(1) - - if yuv: - base_img = cv2.cvtColor(base_img, cv2.COLOR_YUV2RGB_I420) - - size = base_img.shape[:2] - if not output_size: - output_size = size[::-1] - - M = transform_img_M(size, augment_trans, augment_eulers, from_intr, to_intr, pretransform) - augmented_rgb = cv2.warpPerspective(base_img, M, output_size, borderMode=cv2.BORDER_REPLICATE) - - # brightness and contrast augment - augmented_rgb = np.clip((float(alpha)*augmented_rgb + beta), 0, 255).astype(np.uint8) - - # gaussian blur - if blur > 0: - augmented_rgb = cv2.GaussianBlur(augmented_rgb,(blur*2+1,blur*2+1),cv2.BORDER_DEFAULT) - - if yuv: - augmented_img = cv2.cvtColor(augmented_rgb, cv2.COLOR_RGB2YUV_I420) - else: - augmented_img = augmented_rgb - return augmented_img - - -def yuv_crop(frame, output_size, center=None): - # output_size in camera coordinates so u,v - # center in array coordinates so row, column - import cv2 # pylint: disable=import-error - rgb = cv2.cvtColor(frame, cv2.COLOR_YUV2RGB_I420) - if not center: - center = (rgb.shape[0]/2, rgb.shape[1]/2) - rgb_crop = rgb[center[0] - output_size[1]/2: center[0] + output_size[1]/2, - center[1] - output_size[0]/2: center[1] + output_size[0]/2] - return cv2.cvtColor(rgb_crop, cv2.COLOR_RGB2YUV_I420)