def copy_frames(self, demonstration, frm, l1_cluster, l2_cluster, surgeme):

        from_path = (
            constants.PATH_TO_DATA
            + constants.NEW_FRAMES_FOLDER
            + demonstration
            + "_"
            + constants.CAMERA
            + "/"
            + utils.get_frame_fig_name(frm)
        )

        to_path = (
            constants.PATH_TO_CLUSTERING_RESULTS
            + self.trial
            + "/"
            + l1_cluster
            + "/"
            + l2_cluster
            + "_"
            + str(surgeme)
            + "_"
            + demonstration
            + "_"
            + utils.get_frame_fig_name(frm)
        )

        utils.sys_copy(from_path, to_path)
def run_video_with_bsub(cap, func, kernel = None, params = None):
	if params is not None:
		fgbg = func(params[0], params[1], params[2], params[3])
	else:
		fgbg = func()
	SAVE_PATH = constants.PATH_TO_DATA + constants.NEW_BGSUB_FOLDER + "Suturing_E003_capture2/"
	i = 1
	while(1):
		ret, frame = cap.read()
		print i
		fgmask = fgbg.apply(frame)
		mask_rbg = cv2.cvtColor(fgmask, cv2.COLOR_GRAY2BGR)
		draw = frame & mask_rbg
		if frame == None and mask_rbg == None:
			sys.exit()
		if kernel is not None:
			fgmask = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel)

		# cv2.namedWindow("frame", cv2.WND_PROP_FULLSCREEN)
		# cv2.setWindowProperty("frame", cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN)
		cv2.imshow('frame', draw)
		cv2.imwrite(SAVE_PATH + utils.get_frame_fig_name(i), draw)
		k = cv2.waitKey(30) & 0xff
		i += 1
		if k == 27:
			break

	cap.release()
	cv2.destroyAllWindows()
Beispiel #3
0
    def copy_frames(self, demonstration, frm, l1_cluster, l2_cluster, surgeme):

        from_path = constants.PATH_TO_DATA + constants.NEW_FRAMES_FOLDER + demonstration + "_" + constants.CAMERA + "/" + utils.get_frame_fig_name(
            frm)

        to_path = constants.PATH_TO_CLUSTERING_RESULTS + self.trial + "/" + l1_cluster + "/" + l2_cluster + "_" + str(
            surgeme) + "_" + demonstration + "_" + utils.get_frame_fig_name(
                frm)

        utils.sys_copy(from_path, to_path)
	def copy_milestone_frames(self, matrix, list_of_cp_key, gmm):
		neigh = neighbors.KNeighborsClassifier(n_neighbors = 1)
		neigh.fit(matrix, list_of_cp_key)
		milestone_closest_cp = neigh.predict(gmm.means_)

		assert len(milestone_closest_cp) == self.n_components_L2

		for cp in milestone_closest_cp:
			demonstration = self.map_cp2demonstrations[cp]
			surgeme = self.map_frm2surgeme[demonstration][self.map_cp2frm[cp]]
			frm = utils.get_frame_fig_name(self.map_cp2frm[cp])

			from_path = constants.PATH_TO_DATA + constants.NEW_FRAMES_FOLDER + demonstration +"_" + constants.CAMERA + "/" + frm

			to_path = constants.PATH_TO_CLUSTERING_RESULTS + self.trial + "/milestones/" + self.map_cp2milestones[cp] + "_" + str(surgeme) + "_" + demonstration + "_" + frm

			utils.sys_copy(from_path, to_path)
Beispiel #5
0
	def copy_milestone_frames(self, matrix, list_of_cp_key, gmm):
		neigh = neighbors.KNeighborsClassifier(n_neighbors = 1)
		neigh.fit(matrix, list_of_cp_key)
		milestone_closest_cp = neigh.predict(gmm.means_)

		assert len(milestone_closest_cp) == 3

		for cp in milestone_closest_cp:
			demonstration = self.map_cp2demonstrations[cp]
			surgeme = self.map_frm2surgeme[demonstration][self.map_cp2frm[cp]]
			frm = utils.get_frame_fig_name(self.map_cp2frm[cp])

			from_path = constants.PATH_TO_DATA + constants.NEW_FRAMES_FOLDER + demonstration +"_capture2/" + frm

			to_path = constants.PATH_TO_CLUSTERING_RESULTS + self.trial + "/milestones/" + self.map_cp2milestones[cp] + "_" + str(surgeme) + "_" + demonstration + "_" + frm

			utils.sys_copy(from_path, to_path)
Beispiel #6
0
def generate_train_val_test_files(list_of_videos):
    list_of_data = []

    for video in list_of_videos:
        for camera in ["capture1", "capture2"]:
            os.chdir(constants.PATH_TO_DATA)
            transcriptions_file = TRANSCRIPTIONS_FOLDER + video + ".txt"
            with open(transcriptions_file, "rb") as f:
                for line in f:
                    line = line.split()
                    start = int(line[0])
                    end = int(line[1])
                    surgeme = line[2]
                    label = constants.map_surgeme_label[surgeme]
                    i = start
                    while i <= end:
                        data = constants.PATH_TO_DATA + constants.NEW_FRAMES_FOLDER + video + "_" + camera + "/" + utils.get_frame_fig_name(
                            i) + " " + str(label) + " \n"
                        list_of_data.append(data)
                        i += 1
    random.shuffle(list_of_data)

    N = len(list_of_data)

    train, test = train_test_split(list_of_data,
                                   test_size=constants.train_test_ratio)

    val = test[:len(test) / 2]
    test = test[len(test) / 2:]

    train_file_name = constants.PATH_TO_DATA + "train.txt"
    val_file_name = constants.PATH_TO_DATA + "val.txt"
    test_file_name = constants.PATH_TO_DATA + "test.txt"

    IPython.embed()

    write_to_file(train_file_name, train)
    write_to_file(val_file_name, val)
    write_to_file(test_file_name, test)
def generate_train_val_test_files(list_of_videos):
	list_of_data = []

	for video in list_of_videos:
		for camera in ["capture1", "capture2"]:
			os.chdir(constants.PATH_TO_DATA)
			transcriptions_file = TRANSCRIPTIONS_FOLDER + video + ".txt"
			with open(transcriptions_file, "rb") as f:
				for line in f:
					line = line.split()
					start = int(line[0])
					end = int(line[1])
					surgeme = line[2]
					label = constants.map_surgeme_label[surgeme]
					i = start
					while i <= end:
						data = constants.PATH_TO_DATA + constants.NEW_FRAMES_FOLDER + video + "_" + camera + "/" + utils.get_frame_fig_name(i) + " "+ str(label) + " \n"
						list_of_data.append(data)
						i += 1
	random.shuffle(list_of_data)

	N = len(list_of_data)

	train, test = train_test_split(list_of_data, test_size = constants.train_test_ratio)

	val = test[:len(test)/2]
	test = test[len(test)/2:]

	train_file_name = constants.PATH_TO_DATA + "train.txt"
	val_file_name = constants.PATH_TO_DATA + "val.txt"
	test_file_name = constants.PATH_TO_DATA + "test.txt"

	IPython.embed()

	write_to_file(train_file_name, train)
	write_to_file(val_file_name, val)
	write_to_file(test_file_name, test)