def test_mode(): while True: last_time = time.time() raw_img = cv.imread(image_name) process_image(raw_img, do_roi) print('loop took {} seconds'.format(time.time() - last_time)) if cv.waitKey(25) & 0xFF == ord('q'): cv.destroyAllWindows() break
def real_time_mode(): while True: last_time = time.time() screen = grab_screen(region=(0, 40, 800, 600)) screen = cv.cvtColor(screen, cv.COLOR_BGR2RGB) cv.imshow("Real time screen", screen) process_image(screen, do_roi) print('loop took {} seconds'.format(time.time() - last_time)) if cv.waitKey(25) & 0xFF == ord('q'): cv.destroyAllWindows() break
def test_transform(d, i, tmpdir): path, name = os.path.split(i) destination = os.path.join(tmpdir, d, name) image = (i, destination, settings['IMAGE_PROCESS'][d]) process_image(image, settings) transformed = Image.open(destination) expected_path = os.path.join(path, 'results', d, name) expected = Image.open(expected_path) img_diff = ImageChops.difference(transformed, expected).getbbox() self.assertEqual(img_diff, None)
def main(): in_args = get_input_args() norm_image = process_image(in_args.input) model, arch, class_idx = load_model(in_args.checkpoint) classes, probs = predict(norm_image, model, in_args.top_k, in_args.gpu, in_args.category_names, arch, class_idx) print_predict(classes, probs) pass
def process(self, state): processed_image = process_image(state, flip=self.flip_episode) self.frames.append(processed_image) frame = LazyFrames(list(self.frames)) # frame_np = np.array(frame) # print (frame_np.shape) return frame
def evaluate(individual): """ Evaluacija jedinke, usporedba s pripadnom maskom. :param individual: Jedinka za evaluaciju :return: Evaluacija jedinke """ sum = 0 for i, (name, info) in enumerate(image_process.IMAGES_WITH_INFO.items()): if i == TRAIN_NO: break image, gray_image, mask, no_cells = info processed = image_process.process_image(copy.copy(image), individual) sum += compare(processed, mask, no_cells) return (sum / TRAIN_NO),
def setImage(): global panelA, panelB, panelC, root, individual, currentImage if currentImage is None: return image = currentImage processed = cv2.cvtColor( ipss.process_image(ipss.revert_img(copy.copy(image)), individual), cv2.COLOR_GRAY2RGB) contours = cv2.cvtColor( ipss.draw_contours(ipss.revert_img(copy.copy(image)), ipss.find_contours(processed)), cv2.COLOR_BGR2RGB) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = Image.fromarray(image) processed = Image.fromarray(processed) contours = Image.fromarray(contours) image = ImageTk.PhotoImage(image) processed = ImageTk.PhotoImage(processed) contours = ImageTk.PhotoImage(contours) if panelA is None or panelB is None or panelC is None: panelA = Label(root, image=image) panelA.image = image panelA.pack(side="top", padx=10, pady=10) panelB = Label(root, image=processed) panelB.image = processed panelB.pack(side="right", padx=10, pady=10) panelC = Label(root, image=contours) panelC.image = contours panelC.pack(side="left", padx=10, pady=10) else: panelA.configure(image=image) panelB.configure(image=processed) panelC.configure(image=contours) panelA.image = image panelB.image = processed panelC.image = contours
import joblib import cv2 import image_process from parameters import * import copy import numpy as np import genetics image_process.load('images_serialized/images_with_info.dict') individual = joblib.load('transformations/best.ind') for i, (name, info) in enumerate(image_process.IMAGES_WITH_INFO.items()): if i == TRAIN_NO: break image, gray_image, mask, no_cells = info processed = image_process.process_image(copy.copy(image), individual) background = image_process.kmeans(processed, 1) if background > np.array(128): processed = (255 - processed) cv2.imwrite('results2/' + name + '_image.png', image) cv2.imwrite('results2/' + name + '_mask.png', mask) cv2.imwrite('results2/' + name + '_result.png', processed)