본문 바로가기

Python

Copy files in a directory to another directory from shutil import copy # base-network dir base_net_dir = '/home/dooseop/PycharmProjects/Proj075/TORCS_trained_net/ID0_epoch_5_steer' # create destination folder net_dir = os.path.join(learning_params['net_dir'], run_id) if not tf.gfile.Exists(net_dir): tf.gfile.MakeDirs(net_dir) if (isLane): source = os.listdir(base_net_dir) for files in source: copy(os.path.join(base_net_dir, files), net_dir) 더보기
Get file list in a directory from os import listdir from os.path import isfile, join onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))] 더보기
Perspective transform import numpy as np import cv2 import matplotlib.pyplot as plt img = cv2.imread('D:/21_pycharm_project/Proj02/mark4.bmp') rows,cols,ch = img.shape # input potision pts1 = np.float32([[98,21],[187,21],[96,102],[188,102]]) # output position pts2 = np.float32([[128,21],[157,21],[96,102],[188,102]]) # get perspective transform matrix M = cv2.getPerspectiveTransform(pts1,pts2) # warp dst = cv2.warpPer.. 더보기
how to plot a histogram : matplotlib import matplotlib.pyplot as plt# the histogram of the data bins = [] for i in range(-1000, 1001): bins.append(i) values, bins, patches = plt.hist(np.squeeze(np.array(steers)), np.squeeze(np.array(bins)), normed=False) plt.xlabel('Steering Angle (x1000.0)') plt.ylabel('Occurrence') plt.grid(True) plt.axis([-500, 500, 0, 1000]) plt.show() # for CDF plot cdf = [] acc_value = 0 for i in range(0, len.. 더보기
How to resize an image : skimage library ** 파이썬 이미지 크기 변형하기 **In matlab, it is very easy to resize an image. However, in python, you need to know which library do I have to import before resizing. In python, skimage library supports resizing an image like matlab. Here is an example. Enjoy!from skimage.transform import resize import skimage.io as io img = io.imread(file_name) img_resize = resize(img, (target_height, target_width)) 더보기
How to show an image : skimage library In matlab, it is very easy to show an image. However, in python, you need to know which library do I have to import before plotting the graph. In python, skimage library supports showing an image like matlab. Here is an example. Enjoy! import skimage.io as io img = io.imread(file_name) io.imshow(img) io.show() 더보기
How to plot a graph : mathplotlib library In matlab, it is very easy to plot a graph. However, in python, you need to know which library do I have to import before plotting the graph. In python, mathplotlib library supports plotting a graph like matlab. Here is an example. Enjoy! import numpy as np import math import matplotlib.pyplot as plt x = range(0, 100) # x-axis (index) y = np.zeros(100) # y-axis (value) for i in range(0, 100): y[.. 더보기
[NYU depth] How to read NYU depth dataset in python NYU depth v2 dataset can be downloaded from http://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html They provide images and corresponding depth-map (aligned and in-painted) for training and testing. The data is stored in the format of mat. The following code shows how to read the images and corresponding depth-map in python. Enjoy. // CODES ////////////////////////////////////// import skimage.i.. 더보기
How to write values in csv files * 파이썬에서 csv 파일 쓰기 *** Assume you want to write numbers from 1 to 8 along the first column of a csv file; // CODE /////////////////////////// import csv fp = open('/home/test.csv','w') // csvWriter = csv.writer(fp, lineterminator = '\n') for i in range(1,9): csvWriter.writerow([i]) fp.close() 더보기
How to read values from csv files * 파이썬에서 csv파일 읽기 *** Assme you have test.csv file that stores some values; You can read the values in python using the following example code // CODE //////////////////////////////////// import tensorflow as tf import numpy as np import skimage.io as io import csv import os def get_csv_reader(filename, delimiter): reader = [] if not os.path.isfile(filename): print("No such file or directory!") e.. 더보기