def imageToFeatures(im): rim = resizeToArea(im) cim = toCylindrical(rim) segments, nSeg = segmentation(cim) colorF = colorFeatures(cim, rim, (segments, nSeg)) textureF = textureFeatures(cim) compositionF = compositionFeatures(rim, segments) print(".", end="") sys.stdout.flush() return np.concatenate((colorF, textureF, compositionF))
def hisi(input, use_quadratic=True): print() print("====== HISI ======") print() #paramaters settings num_objects = 0 max_num_objects = 10 max_num_bounds = 1000 # repesent the maximum size of an object (security) min_num_bounds = 7 # represent the minimum border of boundaries before being considred as an object, in order to avoid "noisy pixel" 4 = 1 pixel, 6 = 2 pixels thresh_bound = 0.25 # todo change max bound as a function of the image size ? max_induc_bound = 3 if np.shape(input)[0] > 100: max_induc_bound = 14 print("max induc bound: ", max_induc_bound) boundaries = get_boundaries(input) output_img = [] output_bound = [] output_img.append(np.copy(input)) output_bound.append(np.copy(boundaries)) # plt.figure() # plt.imshow(show_matrix(input, boundaries)) # plt.show() segmentation(input, boundaries, thresh_bound, max_induc_bound, min_num_bounds, max_num_bounds, num_objects, max_num_objects, output_img, output_bound, use_quadratic) print() print("====== Finish ======") return output_img, output_bound
def transform(self, X, y=None): t0_tot = time.time() self.true_idx = [] self.n_too_small = 0 self.filter_time = 0 self.segment_time = 0 self.smileTime = 0 for i, sig in enumerate(X): if i % 100 == 0: print('\n' * 30) print(i) print('\n' * 30) t0 = time.time() filtered_sig = filter_sig(sig, width=self.width, ripple_db=self.ripple_db, cutoff_hz=self.cutoff_hz) self.filter_time += time.time() - t0 self.debug = filtered_sig # To remove self.debug_i = i # To remove t0 = time.time() segmented_sig = segmentation(filtered_sig) self.segment_time += time.time() - t0 segmented_sig = list(filter(lambda x: len(x) > 1600, segmented_sig)) if not segmented_sig: segmented_sig = [filtered_sig] for syllabe in segmented_sig: print(len(syllabe)) t0 = time.time() df = runOpenSmile(syllabe) self.smileTime += time.time() - t0 self.mfcc_shape.append(df.shape[0]) self.true_idx.append(i) yield aggregateMfcc(df, use_kurt=self.use_kurt, use_skew=self.use_skew) print('Filter time :', self.filter_time) print('Segment time:', self.segment_time) print('Smile time:', self.smileTime) print('Total time:', time.time() - t0_tot)
def transform_one_signal(self, sig, i): if i % 100 == 0: print('\n' * 30) print(i) print('\n' * 30) t0 = time.time() filtered_sig = filter_sig(sig, width=self.width, ripple_db=self.ripple_db, cutoff_hz=self.cutoff_hz) self.filter_time += time.time() - t0 self.debug = filtered_sig # To remove self.debug_i = i # To remove t0 = time.time() segmented_sig = segmentation(filtered_sig) self.segment_time += time.time() - t0 segmented_sig = list(filter(lambda x: len(x) > 1600, segmented_sig)) if not segmented_sig: segmented_sig = [filtered_sig] self.true_idx.extend([i] * len(segmented_sig)) return Parallel(n_jobs=self.n_jobs)( delayed(transform_one_syllabe(self, syllabe, i)) for syllabe in segmented_sig)
def run(): segmentation(image='./src/test9.png') test_list_images(model='final_model_5.h5')
def callback_cloud(self, msg): cloud_points = list( pc2.read_points(msg, field_names=("x", "y", "z", "intensity"), skip_nans=True)) bbox_3d, obj_points = segmentation(cloud_points) fields = [ PointField('x', 0, PointField.FLOAT32, 1), PointField('y', 4, PointField.FLOAT32, 1), PointField('z', 8, PointField.FLOAT32, 1), PointField('intensity', 16, PointField.FLOAT32, 1) ] if obj_points: obj_types, obj_classified = classification(obj_points) rospy.loginfo('obj_classified: {}'.format( [obj_types[i] for i in obj_classified])) if sum(obj_classified == 0) > 0: pedestrian_points = [ obj for indx, obj in enumerate(obj_points) if obj_classified[indx] == 0 ] pedestrian_cloud = np.row_stack(pedestrian_points) pc_pedestrian = pc2.create_cloud(msg.header, fields, pedestrian_cloud) else: pc_pedestrian = pc2.create_cloud(msg.header, fields, []) if sum(obj_classified == 1) > 0: car_points = [ obj for indx, obj in enumerate(obj_points) if obj_classified[indx] == 1 ] car_cloud = np.row_stack(car_points) pc_car = pc2.create_cloud(msg.header, fields, car_cloud) # publish the centers of the vehicle object as geometry_msgs.PoseArray car_poses = [ np.mean(bbox, axis=0) for indx, bbox in enumerate(bbox_3d) if obj_classified[indx] == 1 ] car_PoseArray = self.Arr2poseArray(car_poses) car_PoseArray.header = msg.header else: pc_car = pc2.create_cloud(msg.header, fields, []) car_PoseArray = PoseArray() car_PoseArray.header = msg.header if sum(obj_classified == 2) > 0: cyclist_points = [ obj for indx, obj in enumerate(obj_points) if obj_classified[indx] == 2 ] cyclist_cloud = np.row_stack(cyclist_points) pc_cyclist = pc2.create_cloud(msg.header, fields, cyclist_cloud) else: pc_cyclist = pc2.create_cloud(msg.header, fields, []) if sum(obj_classified == 3) > 0: misc_points = [ obj for indx, obj in enumerate(obj_points) if obj_classified[indx] == 3 ] misc_cloud = np.row_stack(misc_points) pc_misc = pc2.create_cloud(msg.header, fields, misc_cloud) else: pc_misc = pc2.create_cloud(msg.header, fields, []) else: pc_pedestrian = pc2.create_cloud(msg.header, fields, []) pc_car = pc2.create_cloud(msg.header, fields, []) pc_cyclist = pc2.create_cloud(msg.header, fields, []) pc_misc = pc2.create_cloud(msg.header, fields, []) self._pub1.publish(pc_pedestrian) self._pub2.publish(pc_car) self._pub3.publish(pc_cyclist) self._pub4.publish(pc_misc) self._pub5.publish(car_PoseArray)
# check if screenshot or photograph if find_scan_screenshot(img) == 1: img_rotated = skew_correction(new_img) else: #img_rotated = new_img img_rotated = skew_correction_scanned(new_img) # img_rotated = new_img img_rotated[img_rotated == 1] = 255 plt.imshow(img_rotated, cmap='gray') plt.title("skew corrected image") plt.show() # plt.imsave("misc/skew_corrected_image.png",img_rotated,cmap='gray') # character segmentation centroids, bboxs, convex_hulls, imgs = segmentation(img_rotated) #draw bounding box and show different segments draw_bounding_box(img_rotated, bboxs) #for i in range(0,len(imgs)): # str_ele2 = skimage.morphology.selem.disk(2) # str_ele = skimage.morphology.selem.square(3) # imgs[i] = skimage.morphology.binary_erosion(imgs[i],selem=str_ele2) # imgs[i] = skimage.morphology.binary_dilation(imgs[i],selem=str_ele) #plt.imshow(imgs[i],cmap='gray') #shift centroid origin centroids_new = create_new_centroids(centroids, bboxs, imgs) detected_chars = [] #character identification and matching