def recursive_dive(base_path,dictionary): listDir = os.listdir(base_path) for filename in listDir: if os.path.isdir(os.path.join(base_path,filename)): recursive_dive(os.path.join(base_path,filename),dictionary) else : if fnmatch.fnmatch(filename,'*.png'): image = cv2.imread(os.path.join(base_path,filename)) dictionary.update({filename:get_dominant_color(image)}) print filename
def load_skin_from_image(self, filepath): ''' Load theme from given image. @param filepath: The file path of image. ''' # Init. skin_dir = os.path.join(self.user_skin_dir, str(uuid.uuid4())) skin_image_file = os.path.basename(filepath) config_file = os.path.join(skin_dir, "config.ini") dominant_color = get_dominant_color(filepath) similar_color = find_similar_color(dominant_color)[0] default_config = [ ("theme", [("theme_name", similar_color)]), ("application", [("app_id", self.app_given_id), ("app_version", self.app_given_version)]), ("background", [("image", skin_image_file), ("x", "0"), ("y", "0"), ("scale_x", "1.0"), ("scale_y", "1.0"), ("dominant_color", dominant_color)]), ("action", [("deletable", "True"), ("editable", "True"), ("vertical_mirror", "False"), ("horizontal_mirror", "False")])] # Create skin directory. create_directory(skin_dir, True) # Copy skin image file. shutil.copy(filepath, skin_dir) # Touch skin config file. touch_file(config_file) # Write default skin config information. Config(config_file, default_config).write() if self.reload_skin(os.path.basename(skin_dir)): self.apply_skin() return (True, skin_dir, skin_image_file) else: return (False, skin_dir, skin_image_file)
def readFrame(vidcap): # get the current frame global success success, image = vidcap.read() if(success == False): return False # capture the first frame of the given time interval if count % interval == 0: print('read frame %d'%count) # convert the image to the hsv color space hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # get scaled down dimensions width = int(hsv_image.shape[1]*scale_percent/100) height = int(hsv_image.shape[0]*scale_percent/100) # find the dominant color dom_color = d.get_dominant_color(hsv_image, k, (width, height)) # create a square showing dominant color of equal size to input image dom_color_hsv = np.full((frame_height, frame_width, 3), dom_color, dtype='uint8') # convert to bgr color space for display dom_color_bgr = cv2.cvtColor(dom_color_hsv, cv2.COLOR_HSV2BGR) global output_image if output_image is None: # create a new image if there isn't one already output_image = dom_color_bgr else : # append the new frame to the end of the barcode output_image = np.hstack((output_image, dom_color_bgr)) # repeat the process if grayscale is set to true if grayscale: grayscale_hsv = np.full((frame_height, frame_width, 3), (0,0,dom_color[2]), dtype='uint8') grayscale_bgr = cv2.cvtColor(grayscale_hsv, cv2.COLOR_HSV2BGR) global grayscale_image if grayscale_image is None: grayscale_image = grayscale_bgr else: grayscale_image = np.hstack((grayscale_image, grayscale_bgr))