def augment(img_data, config, augment=True): assert 'filepath' in img_data assert 'bboxes' in img_data assert 'width' in img_data assert 'height' in img_data img_data_aug = copy.deepcopy(img_data) img = cv2.imread(img_data_aug['filepath']) if augment: rows, cols = img.shape[:2] if config.use_horizontal_flips and np.random.randint(0, 2) == 0: img = cv2.flip(img, 1) for bbox in img_data_aug['bboxes']: x1 = bbox['x1'] x2 = bbox['x2'] bbox['x2'] = cols - x1 bbox['x1'] = cols - x2 if config.use_vertical_flips and np.random.randint(0, 2) == 0: img = cv2.flip(img, 0) for bbox in img_data_aug['bboxes']: y1 = bbox['y1'] y2 = bbox['y2'] bbox['y2'] = rows - y1 bbox['y1'] = rows - y2 if config.rot_90: angle = np.random.choice([0,90,180,270],1)[0] if angle == 270: img = np.transpose(img, (1,0,2)) img = cv2.flip(img, 0) elif angle == 180: img = cv2.flip(img, -1) elif angle == 90: img = np.transpose(img, (1,0,2)) img = cv2.flip(img, 1) elif angle == 0: pass for bbox in img_data_aug['bboxes']: x1 = bbox['x1'] x2 = bbox['x2'] y1 = bbox['y1'] y2 = bbox['y2'] if angle == 270: bbox['x1'] = y1 bbox['x2'] = y2 bbox['y1'] = cols - x2 bbox['y2'] = cols - x1 elif angle == 180: bbox['x2'] = cols - x1 bbox['x1'] = cols - x2 bbox['y2'] = rows - y1 bbox['y1'] = rows - y2 elif angle == 90: bbox['x1'] = rows - y2 bbox['x2'] = rows - y1 bbox['y1'] = x1 bbox['y2'] = x2 elif angle == 0: pass img_data_aug['width'] = img.shape[1] img_data_aug['height'] = img.shape[0] return img_data_aug, img
model_classifier.load_weights(C.model_path, by_name=True) model_rpn.compile(optimizer='sgd', loss='mse') model_classifier.compile(optimizer='sgd', loss='mse') all_imgs, _, _ = get_data(options.test_path) test_imgs = [s for s in all_imgs if s['imageset'] == 'test'] T = {} P = {} for idx, img_data in enumerate(test_imgs): print('{}/{}'.format(idx, len(test_imgs))) st = time.time() filepath = img_data['filepath'] img = cv.imread(filepath) X, fx, fy = format_img(img, C) if K.image_dim_ordering() == 'tf': X = np.transpose(X, (0, 2, 3, 1)) # get the feature maps and output from the RPN [Y1, Y2, F] = model_rpn.predict(X) R = roi_helpers.rpn_to_roi(Y1, Y2, C, K.image_dim_ordering(), overlap_thresh=0.7)
Lgeo_range = np.linspace(4 * 1e-12, 6 * 1e-12, Lgeo_numpoints) Cgeo_range = np.linspace(50 * 1e-12, 65 * 1e-12, Cgeo_numpoints) Ic_range = np.linspace(20 * 1e-6, 50 * 1e-6, Ic_numpoints) """ Lgeo_numpoints = 1 Cgeo_numpoints = 1 Ic_numpoints = 1 Lgeo_range = np.linspace(19/2*1e-12, 19*1e-12, 1) Cgeo_range = np.linspace(30*1e-12, 30*1e-12, 1) Ic_range = np.linspace(23*1e-6, 23*1e-6, 1) """ if __name__ == "__main__" and (len(sys.argv) == 2): argv_filepath = sys.argv[1] actual_filepath = "%s" % argv_filepath # why did I do it this way? raw_image_gray = cv2.imread(actual_filepath, 0) ROI, corner_vals = user_defined_rectangle(None, raw_image=raw_image_gray) x1 = float(corner_vals[0]) x2 = float(corner_vals[1]) y1 = float(corner_vals[2]) y2 = float(corner_vals[3]) cropped_image_to_threshold = raw_image_gray[ROI[1]:ROI[1] + ROI[3], ROI[0]:ROI[0] + ROI[2]] binary_image, threshold_value = user_defined_threshold( None, cropped_image_to_threshold) # skeletonize here skeleton = skeletonize(binary_image)
for c in self.clipboard_get(type='image/png'): if c == ' ': try: b.append(int(h, 0)) except Exception as e: print('Exception:{}'.format(e)) h = '' else: h += c except tk.TclError as e: b = None print('TclError:{}'.format(e)) finally: if b is not None: with Image.open(io.BytesIO(b)) as img: print('{}'.format(img)) self.label.image = ImageTk.PhotoImage( img.resize((100, 100), Image.LANCZOS)) self.label.configure(image=self.label.image) # Main if __name__ == '__main__': # Read image im = cv2.imread('zbar-test.jpg') decodedObjects = decode(im) display(im, decodedObjects)
import sys, opencv as cv img = cv.imread(sys.argv[1], 1) cv.imshow("original", img) gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) gray = cv.GaussianBlur(gray, (7, 7), 1.5) edges = cv.Canny(gray, 0, 50) cv.imshow("edges", edges) cv.waitKey()
import opencv as cv2 import numpy as np import time imgF = cv2.imread("/home/vishav/Documents/Project/DepthCal/Data/front.png", 0) imgR = cv2.imread("/home/vishav/Documents/Project/DepthCal/Data/rear.png", 0) imgF = cv2.resize(imgF, (480, 720)) imgR = cv2.resize(imgR, (480, 720)) imgF = imgF[300:338, 230:279] imgR = imgR[227:260, 289:327] start = time.time() dC = -50 f = 532 liF = [] for i in range(imgF.shape[0]): for j in range(imgF.shape[1]): if imgF[i][j] >= 180 and imgF[i][j] <= 255: imgF[i][j] = 255 else: imgF[i][j] = 0 liF.append(i) fy0 = min(liF) fy1 = max(liF) liR = [] for i in range(imgR.shape[0]):