def read_image_sequence(self, video_name: str): self.set_image_sequence_name(video_name) # Set video directory video_dir = os_path_join( self.im_seqs_dir, video_name ) # List all the images included inside the video directory images_names = os_listdir(video_dir) # Sort the images with respect to their name sorted_images_names = sorted(images_names) # Read every image and store it in a list. # Turn this list to a numpy array. """ In an example the colors where not right self.image_sequence = np_array( [self.image_handler.load_image(os_path_join(video_dir, img_name)) for img_name in sorted_images_names] ) """ self.image_sequence = np_array( [cv2_imread(os_path_join(video_dir, img_name)) for img_name in sorted_images_names] ) return self.image_sequence
def img_load(path, w, h, resize=True): img = cv2_imread(path) if len(img.shape) == 2: img = np.dstack((img, img, img)) if resize: img = cv2_resize(img, (w, h)).astype(np.uint8) img = cvtColor(img, COLOR_BGR2RGB) return img
def read_image_sequence(self, video_name: str): self.set_image_sequence_name(video_name) # Set video directory video_dir = os_path_join(self.im_seqs_dir, video_name) # List all the images included inside the video directory images_names = os_listdir(video_dir) # Sort the images with respect to their name sorted_images_names = sorted(images_names) # Read every image and store it in a list. # Turn this list to a numpy array. self.left_sequence = np_array([ cv2_imread(os_path_join(video_dir, img_name)) for img_name in sorted_images_names if img_name.endswith('L.jpg') ]) self.right_sequence = np_array([ cv2_imread(os_path_join(video_dir, img_name)) for img_name in sorted_images_names if img_name.endswith('R.jpg') ]) return self.left_sequence, self.right_sequence
def image_search(self, path, threshold=0.7, max_n=50): """ Search similar logos @param: path : the complete path to the image file @returns: two list of 'Logo' instance, where the first one contains good matches, and the second normal ones """ im = cv2_imread(path) if im is None: print("No image at '%s' ,match failed!" % path) return [], [] im = im[:,:,::-1] # BGR -> RGB logo_inds_s, scores_s = self._image_search_sift(im, max_n=50) logo_inds_c, scores_c = self._image_search_color(im, max_n=50) scores = {} r = 0.5 # the ratio between color score and sift score for ind, score in zip(logo_inds_s, scores_s): scores.setdefault(ind, 0) scores[ind] += r * score for ind, score in zip(logo_inds_c, scores_c): scores.setdefault(ind, 0) scores[ind] += (1-r) * score logo_inds = np.array(scores.keys()) scores = np.array(scores.values()) # get max_n max_n = min(np.sum(scores > threshold / 4), max_n) inds = np.argpartition(scores, -max_n)[-max_n:] inds = inds[np.argsort(scores[inds])][::-1] scores = scores[inds] logo_inds = logo_inds[inds] logo_inds += 1 # ind begins with 1 logos = self.get_logos_from_db(logo_inds) good = [] normal = [] for logo, score in zip(logos, scores): (good if score > threshold else normal).append(logo) return good, normal
def load_path(path): img = cv2_imread(path) if len(img.shape) == 2: img = np.dstack((img, img, img)) img = cvtColor(img, COLOR_BGR2RGB) return img
def get_im_cv2_1024(path): img = cv2_imread(path) resized = cv2_resize(img, (1024, 1024), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_512(path): img = cv2_imread(path) resized = cv2_resize(img, (512, 512), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_256(path): img = cv2_imread(path) resized = cv2_resize(img, (256, 256), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_64(path): img = cv2_imread(path) resized = cv2_resize(img, (64, 64), cv2_INTER_AREA) return [path, resized]
def get_im_cv2_32(path): img = cv2_imread(path) resized = cv2_resize( img, (32, 32), cv2_INTER_AREA) #use cv2_resize(img, (64, 64), cv2_INTER_AREA) return [path, resized]