def parseBed2Json(bedfile): # test if the file exitst try: # try resolve path and get the absolute path my_abs_path_file = Path(bedfile).resolve() ###### Open bed file and parse to json ##### jsonData = [] # open bed file infile = open(bedfile, 'r').readlines() # read header header = infile.pop(0).strip('\n').split("\t") for line in infile: # get row and convert to array data = line.strip('\n').split("\t") # test if the row is complete and have the same size as the header if len(data) == len(header): datadict = {} # iterate over my bedfile row for i, element in enumerate(data): datadict[header[i]] = element # push into array the dictionary structure jsonData.append(datadict) ######## write into file the json structure # bed filename (without path) filename = PurePosixPath(my_abs_path_file).name # json file name jsonFile = filename + ".json" # test if file ends with .bed if filename.endswith('.bed'): jsonFile = filename.split(".bed")[0] + ".json" with open(jsonFile, 'w') as outfile: json.dump(jsonData, outfile, indent=4) outfile.close() except FileNotFoundError: print("your file does not exist")
from pathlib import PurePosixPath tag_path = 'apriltag-imgs/tag36h11/' tag_pattern = 'tag36_11_*.png' #tag_pattern = 'tag36_11_00000.png' resized_tags_folder = 'tag36h11_big/' ouput_folder = 'output/' pathlist = Path(tag_path).rglob(tag_pattern) for img_path in pathlist: # because path is object not string img_fn = str(img_path) bfn = PurePosixPath(img_fn).stem tagid = bfn.split('_')[2] # don't create resized image if already exists r_img_path = Path(resized_tags_folder + bfn + '.jpg') if (r_img_path.exists() == False): # load image img = cv2.imread(img_fn,0) # crop border crop_img = img[1:1+8, 1:1+8] # resize to something really big r_img = cv2.resize(crop_img,(2000,2000),fx=0, fy=0, interpolation = cv2.INTER_NEAREST) cv2.imwrite(str(r_img_path),r_img)