import os, sys, inspect from src.utils.io import showimage_pil, show_dot, filename2arr, add_boxes from PIL import Image tests_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script directory src/ src_dir = os.path.dirname(tests_dir) xray_dir = os.path.dirname(src_dir) #xray directory os.chdir(xray_dir) sys.path.append(src_dir) import pickle boxes = pickle.load(open('/Users/ruhansa/Desktop/train/result/clf_1_20_np/21_boxes.pkl', "rb")) from src.utils.util import non_max_suppression_merge boxes = non_max_suppression_merge(boxes, 0.9) fn = xray_dir + '/data/LL/21.jpg' img = Image.open(fn) img = add_boxes(boxes, img) img.show() # # img = Image.open(fn) # img = add_boxes(boxes, img) # img.show() # img.save('/Users/ruhansa/Desktop/train/result/1_clf_1_2/boxes.jpg') # import pickle # pickle.dump(aftermath, open('/Users/ruhansa/Desktop/train/result/1_clf_1_2/boxes.pkl', 'wb'))
half_clf = pickle.load(open(fn, "rb")) for i in range(starti, endi+1): testn = str(i) report.write("==================== sample #: " + testn + "==========================\n") t0 = time.time() fn = data_folder + testn + '.jpg' arr = filename2arr(fn) ### step1: get bounding boxes # halves = detect_halves(arr, half_clf, step_size_W=80, step_size_H=80, winH=200, winW=300, report=report) fn = result_dir + '/' + testn + '_half_boxes.pkl' halves = pickle.load(open(fn, "rb")) halves = non_max_suppression_merge(halves, overlapThresh=0) if halves is not None: # 1. detect ROI bbox = get_huge_bounding_box(halves) img1 = Image.fromarray(arr) # fn = result_dir + '/' + testn + '_half_boxes.pkl' # pickle.dump(halves, open(fn, "wb")) img1=add_boxes(halves, img1) img1.show() img1.save(result_dir +'/' + testn +'_half_boxes.jpg') # 2. detect edges ROI = arr[bbox[1]: bbox[3], bbox[0]: bbox[2]] edges, sigma, cur_ROI= best_edges(ROI, threshold=0.02) showimage_pil(edges)