示例#1
0
	def setup(cls, path, forceInit=False):
		"""
		D.setup(path, forceInitFlag) -> Do the necessary setup to mount the specified path as a dhtfs file system

		@param path: Path for which to setup
		@type path: str

		@param forceInit: If forceInit is True, do a new setup regardless of whether an older setup is present.
		@type forceInit: bool
		"""

		# If forceInit flag is true, clean up the directory
		if forceInit:
			for root, dirs, files in os.walk(path, topdown=False):
				for name in files:
					os.remove(os.path.join(root, name))
				for name in dirs:
					os.rmdir(os.path.join(root, name))

		# Initialize tagging

		t = Tagging(db_path=path, db_file=cls.DB_FILE)
		t.initDB(forceInit = forceInit)

		# Initialize sequence generator
		seqStore = GPStor(db_path=path, db_file=cls.SEQ_FILE)

		ret, currentSeqNumber = seqStore.getDataRO()

		if (ret != 0) or (not isinstance(currentSeqNumber, long) ) or forceInit:
			seqStore.getDataRW()
			currentSeqNumber = long(0)
			seqStore.writeData(currentSeqNumber)
def collect(path="./img_data/"):
    if not path.endswith("/"):
        path = path + "/"
    files = os.listdir(path)
    files = [
        file for file in files if (not os.path.isdir(file)) and (
            file.endswith("-data.jpg") or file.endswith("-label.npy"))
    ]
    prefixes = set(
        file.replace("-data.jpg", "").replace("-label.npy", "")
        for file in files)

    for idx, prefix in enumerate(prefixes):
        try:
            img_file = cv2.imread(path + prefix + "-data.jpg")
            img_label = np.load(path + prefix + '-label.npy')
            np_image_data = np.asarray(img_file)

            if np.sum(img_label > 8) > 0:
                continue

            print('processing {} ({}/{})'.format(prefix, idx, len(prefixes)))
            tag = Tagging(np_image_data)
            tag.tag(np_image_data, prefix)

            img_label = np.load(path + prefix + '-label.npy')
            print(img_label)

        except FileExistsError as e:
            print(e)
            print("Loading error with prefix =", prefix, ". Skipped.")
            continue
示例#3
0
    def render(self, show=True):
        duration = int(1000 * (time.time() - self.render_timestamp))
        zero_img = np.zeros(self.last_image.shape, np.uint8)
        result = Tagging.attach(
            zero_img,
            BejeweledState.one_hot_state_to_prediction(self._state_queue[0]))

        cv2.putText(result, '%s ms' % duration, (15, 35),
                    cv2.FONT_HERSHEY_SIMPLEX, 1.0, (100, 100, 100), 3)
        if show:
            cv2.imshow('Sprites', result)
            cv2.moveWindow('Sprites', 0, 0)
            cv2.waitKey(1)
        self.render_timestamp = time.time()
        return result
示例#4
0
	def checkSetup(cls, path):
		"""
		D.checkSetup() -> Check whether dhtfs filesystem is setup at path

		@param path: Path to be checked
		@type path: str

		@return: True is dhtfs is setup at path, False otherwise
		@rtype: bool
		"""

		if not Tagging.checkSetup(db_path=path, db_file=cls.DB_FILE):	
			return False
		if not GPStor.checkSetup(db_path=path, db_file=cls.SEQ_FILE):
			return False

		return True