f = 1 fcount = 1 while success: success, img = vidcap.read() if success is False: vidcap.set(cv2.CAP_PROP_POS_FRAMES, 0) break if f in [25, 35, 45, 55, 65]: # print img.type #my_mat_img = npcv.test_np_mat(img) #m2 = cv2.CreateMat(height, width, cv2.CV_32FC3) #m0 = cv2.fromarray(img) #cv2.CvtColor(m0,m2, cv2.CV_GRAY2BGR) my_lap_obj = fv(width, height, 4, sigma_x, sigma_y) ctr = npcv.test_np_mat(np.array(center)) foveated_img = my_lap_obj.foveate(img, ctr) foveated_img = cv2.resize( foveated_img, (224, 224), interpolation=cv2.INTER_NEAREST) # BGR to RGB rgb_img = foveated_img[:, :, ::-1].copy() if not os.path.exists(outdirvidkey + "/frames" + str(fcount) + ".jpg"): Image.fromarray(rgb_img).save(outdirvidkey + "/frames" + str(fcount) + ".jpg") ctr = None # Save image fcount += 1
sigma_x = int(2 * current_BB[2] / resrefactor[0]) sigma_y = int(2 * current_BB[3] / resrefactor[1]) frame_path = frame_dir + str(current_frame) + ".jpg" img = cv2.imread(frame_path) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = cv2.resize(img, (myres[0], myres[1])) height, width, channels = img.shape img = plt.imread( frame_path) # CHECK THAT IMG IS GETTING RESIZED img = cv2.resize(img, (myres[0], myres[1])) my_lap_obj = fv(width, height, 3, sigma_x, sigma_y) foveated_img = my_lap_obj.foveate( img, npcv.test_np_mat(np.array(center))) plt.cla() # Check that output Folder Exists, if not create it BB_counter = 0 outdir = target_dir + video_dir + '/' + str( frames[2]) + '_BB_' + str(current_BB_number) if not os.path.isdir(outdir): os.makedirs(outdir) outimgpath = outdir + '/frame' + str(counter).zfill( 1) + '.jpg' # Convert BGR to RGB #rgb_img = foveated_img[:, :, ::-1].copy() Image.fromarray(foveated_img).save(outimgpath) counter = counter + 1
sigma_y = sigma_y_max # Create the Laplacian blending object my_lap_obj = fv(width, height, levels, sigma_x, sigma_y) try: while True: start = time.time() sigma_x = randint(1, sigma_x_max) sigma_y = randint(1, sigma_y_max) # RANDOM FIXATION POINTS center = [int(width / 2.0), int(height / 2.0)] # Convert np array to cv::Mat object my_mat_img = npcv.test_np_mat(img) # RANDOM FOVEA SIZE #my_lap_obj.update_fovea(width,height,sigma_x,sigma_y) # Foveate the image foveated_img = my_lap_obj.foveate(img, npcv.test_np_mat(np.array(center))) end = time.time() print(end - start) # Display the foveated image plt.imshow(foveated_img) #img.set_data(im)