Exemple #1
0
// private mode (--private):
//	mount tmpfs over /home/user,
// 	tmpfs on top of  /root in nonroot mode,
// 	set skel files,
// 	restore .Xauthority
void fs_private(void) {
	char *homedir = cfg.homedir;
	assert(homedir);
	uid_t u = getuid();
	gid_t g = getgid();

	int xflag = store_xauthority();

	// mask /home
	if (arg_debug)
		printf("Mounting a new /home directory\n");
	if (mount("tmpfs", "/home", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=755,gid=0") < 0)
		errExit("mounting home directory");

	// mask /root
	if (arg_debug)
		printf("Mounting a new /root directory\n");
	if (mount("tmpfs", "/root", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=700,gid=0") < 0)
		errExit("mounting home directory");

	if (u != 0) {
		// create /home/user
		if (arg_debug)
			printf("Create a new user directory\n");
		int rv = mkdir(homedir, S_IRWXU);
		if (rv == -1)
			errExit("mkdir");
		if (chown(homedir, u, g) < 0)
			errExit("chown");
	}
	
	skel(homedir, u, g);
	if (xflag)
		copy_xauthority();
}
Exemple #2
0
int main(int argc, char** argv) {
	if (argc != 2) {
		return -1;
	}

	cv::Mat img = cv::imread(argv[1], 0);

	cv::imshow("original", img);
	cv::waitKey();

	cv::threshold(img, img, 127, 255, cv::THRESH_BINARY);
	cv::Mat skel(img.size(), CV_8UC1, cv::Scalar(0));
	cv::Mat temp;
	cv::Mat eroded;

	cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));

	while (true) {
		cv::erode(img, eroded, element);
		cv::dilate(eroded, temp, element); // temp = open(img)
		cv::subtract(img, temp, temp);
		cv::bitwise_or(skel, temp, skel);
		eroded.copyTo(img);

		if (cv::countNonZero(img) == 0) {
			break;
		}

	}

	cv::imshow("Skeleton", skel);
	cv::waitKey();

}
bool
UsdMayaPrimReaderSkeleton::Read(UsdMayaPrimReaderContext* context)
{
    UsdSkelSkeleton skel(_GetArgs().GetUsdPrim());
    if (!TF_VERIFY(skel))
        return false;

    if (UsdSkelSkeletonQuery skelQuery = _cache.GetSkelQuery(skel)) {

        MObject parentNode = context->GetMayaNode(
            skel.GetPrim().GetPath().GetParentPath(), true);

        // Build out a joint hierarchy.
        VtArray<MObject> joints;
        if (UsdMayaTranslatorSkel::CreateJointHierarchy(
                skelQuery, parentNode, _GetArgs(), context, &joints)) {

            // Add a dagPose node to hold the rest pose.
            // This is not necessary for skinning to function i Maya, but is not
            // necessary in order to properly round-trip the Skeleton's
            // restTransforms, and is a requirement of some exporters.
            // The dagPose command also will not work without this.  
            MObject bindPose;
            if (UsdMayaTranslatorSkel::CreateBindPose(
                    skelQuery, joints, context, &bindPose)) {
                return true;
            }
        }
    }
    return false;
}
Exemple #4
0
Mat visionUtils::skeletonDetect(Mat threshImage, int imgBlurPixels, bool displayFaces)
{
    // Finds skeleton of white objects in black image, using erode / dilate morph operations
    cv::threshold(threshImage, threshImage, 127, 255, THRESH_BINARY);
    if (displayFaces) imshow("Skel in",threshImage);
    Mat skel(threshImage.size(), CV_8UC1, Scalar(0));
    Mat temp;
    Mat eroded;

    Mat element = getStructuringElement(MORPH_CROSS, Size(3, 3));

    bool done;
    do
    {
        cv::erode(threshImage, eroded, element);
        cv::dilate(eroded, temp, element);
        cv::subtract(threshImage, temp, temp);
        cv::bitwise_or(skel, temp, skel);
        eroded.copyTo(threshImage);
        done = (cv::countNonZero(threshImage) == 0);
    } while (!done);
    if (displayFaces) imshow("Skel raw",skel);
    // Blur to reduce noise
    GaussianBlur(skel, skel, Size(imgBlurPixels,imgBlurPixels), 1, 1);
    return skel;
}
Exemple #5
0
// private mode (--private-home=list):
// 	mount homedir on top of /home/user,
// 	tmpfs on top of  /root in nonroot mode,
// 	tmpfs on top of /tmp in root mode,
// 	set skel files,
// 	restore .Xauthority
void fs_private_home_list(void) {
	char *homedir = cfg.homedir;
	char *private_list = cfg.home_private_keep;
	assert(homedir);
	assert(private_list);

	int xflag = store_xauthority();
	int aflag = store_asoundrc();

	uid_t uid = getuid();
	gid_t gid = getgid();

	// create /run/firejail/mnt/home directory
	mkdir_attr(RUN_HOME_DIR, 0755, uid, gid);
	fs_logger_print();	// save the current log

	if (arg_debug)
		printf("Copying files in the new home:\n");

	// copy the list of files in the new home directory
	char *dlist = strdup(cfg.home_private_keep);
	if (!dlist)
		errExit("strdup");
	
	char *ptr = strtok(dlist, ",");
	duplicate(ptr);
	while ((ptr = strtok(NULL, ",")) != NULL)
		duplicate(ptr);

	fs_logger_print();	// save the current log
	free(dlist);

	if (arg_debug)
		printf("Mount-bind %s on top of %s\n", RUN_HOME_DIR, homedir);

	if (mount(RUN_HOME_DIR, homedir, NULL, MS_BIND|MS_REC, NULL) < 0)
		errExit("mount bind");

	if (uid != 0) {
		// mask /root
		if (arg_debug)
			printf("Mounting a new /root directory\n");
		if (mount("tmpfs", "/root", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=700,gid=0") < 0)
			errExit("mounting home directory");
	}
	else {
		// mask /home
		if (arg_debug)
			printf("Mounting a new /home directory\n");
		if (mount("tmpfs", "/home", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=755,gid=0") < 0)
			errExit("mounting home directory");
	}

	skel(homedir, uid, gid);
	if (xflag)
		copy_xauthority();
	if (aflag)
		copy_asoundrc();
}
Exemple #6
0
// private mode (--private=homedir):
// 	mount homedir on top of /home/user,
// 	tmpfs on top of  /root in nonroot mode,
// 	set skel files,
// 	restore .Xauthority
void fs_private_homedir(void) {
	char *homedir = cfg.homedir;
	char *private_homedir = cfg.home_private;
	assert(homedir);
	assert(private_homedir);
	
	int xflag = store_xauthority();
	int aflag = store_asoundrc();
	
	uid_t u = getuid();
	gid_t g = getgid();
	struct stat s;
	if (stat(homedir, &s) == -1) {
		fprintf(stderr, "Error: cannot find user home directory\n");
		exit(1);
	}
	

	// mount bind private_homedir on top of homedir
	if (arg_debug)
		printf("Mount-bind %s on top of %s\n", private_homedir, homedir);
	if (mount(private_homedir, homedir, NULL, MS_NOSUID | MS_NODEV | MS_BIND | MS_REC, NULL) < 0)
		errExit("mount bind");
	fs_logger3("mount-bind", private_homedir, cfg.homedir);
	fs_logger2("whitelist", cfg.homedir);
// preserve mode and ownership
//	if (chown(homedir, s.st_uid, s.st_gid) == -1)
//		errExit("mount-bind chown");
//	if (chmod(homedir, s.st_mode) == -1)
//		errExit("mount-bind chmod");

	if (u != 0) {
		// mask /root
		if (arg_debug)
			printf("Mounting a new /root directory\n");
		if (mount("tmpfs", "/root", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_STRICTATIME | MS_REC,  "mode=700,gid=0") < 0)
			errExit("mounting home directory");
		fs_logger("tmpfs /root");
	}
	else {
		// mask /home
		if (arg_debug)
			printf("Mounting a new /home directory\n");
		if (mount("tmpfs", "/home", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_STRICTATIME | MS_REC,  "mode=755,gid=0") < 0)
			errExit("mounting home directory");
		fs_logger("tmpfs /home");
	}
	

	skel(homedir, u, g);
	if (xflag)
		copy_xauthority();
	if (aflag)
		copy_asoundrc();
}
Exemple #7
0
// private mode (--private=homedir):
// 	mount homedir on top of /home/user,
// 	tmpfs on top of  /root in nonroot mode,
// 	tmpfs on top of /tmp in root mode,
// 	set skel files,
// 	restore .Xauthority
void fs_private_homedir(void) {
	char *homedir = cfg.homedir;
	char *private_homedir = cfg.home_private;
	assert(homedir);
	assert(private_homedir);
	
	int xflag = store_xauthority();
	
	uid_t u = getuid();
	gid_t g = getgid();
	struct stat s;
	if (stat(homedir, &s) == -1) {
		exechelp_logerrv("firejail", FIREJAIL_ERROR, "Error: cannot find user home directory\n");
		exit(1);
	}
	

	// mount bind private_homedir on top of homedir
	if (arg_debug)
		printf("Mount-bind %s on top of %s\n", private_homedir, homedir);
	if (mount(private_homedir, homedir, NULL, MS_BIND|MS_REC, NULL) < 0)
		errExit("mount bind");
// preserve mode and ownership
//	if (chown(homedir, s.st_uid, s.st_gid) == -1)
//		errExit("mount-bind chown");
//	if (chmod(homedir, s.st_mode) == -1)
//		errExit("mount-bind chmod");

	if (u != 0) {
		// mask /root
		if (arg_debug)
			printf("Mounting a new /root directory\n");
		if (mount("tmpfs", "/root", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=700,gid=0") < 0)
			errExit("mounting home directory");
	}
	else {
		// mask /home
		if (arg_debug)
			printf("Mounting a new /home directory\n");
		if (mount("tmpfs", "/home", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=755,gid=0") < 0)
			errExit("mounting home directory");

		// mask /tmp only in root mode; KDE keeps all kind of sockets in /tmp!
		if (arg_debug)
			printf("Mounting a new /tmp directory\n");
		if (mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=777,gid=0") < 0)
			errExit("mounting tmp directory");
	}
	

	skel(homedir, u, g);
	if (xflag)
		copy_xauthority();
}
Exemple #8
0
void Skeletonize(const DataTypes::BinaryImage& inputImage, DataTypes::BinaryImage& outputImage, int iterations)
{
	
	
	static DataTypes::BinaryImage tempImage;
	tempImage.rows = tempImage.maxRows;
	tempImage.cols = tempImage.maxCols;

	static DataTypes::BinaryImage erodedImage;
	erodedImage.rows = erodedImage.maxRows;
	erodedImage.cols = erodedImage.maxCols;

	static DataTypes::BinaryImage skelImage;
	skelImage.rows = skelImage.maxRows;
	skelImage.cols = skelImage.maxCols;

	inputImage.CopyTo(outputImage);
	
	for(int y=0; y<skelImage.rows; y++)
	{
		for(int x=0; x<skelImage.cols; x++)
		{
			skelImage.data[y][x] = false;
		}
	}
	
	
	//cv::Mat skel(img.size(), CV_8UC1, cv::Scalar(0));
	cv::Mat img(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)outputImage.data);
	cv::Mat skel(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)skelImage.data);
	cv::Mat temp(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)tempImage.data);
	cv::Mat eroded(DEPTH_RES_Y, DEPTH_RES_X, CV_8U, (void*)erodedImage.data);
 
	cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
 
	bool done;		
	do
	{
	  cv::erode(img, eroded, element);
	  cv::dilate(eroded, temp, element); // temp = open(img)
	  cv::subtract(img, temp, temp);
	  cv::bitwise_or(skel, temp, skel);
	  eroded.copyTo(img);
 
	  done = (cv::norm(img) == 0);
	} while (!done);


	skelImage.CopyTo(outputImage);
	return;

}
Mat Normalized::Skeleton(Mat img)
{
	Mat skel(img.size(), CV_8UC1, cv::Scalar(0));
	int morph_element = MORPH_CLOSE;
	int operation = MORPH_RECT;
	int morph_size = 1;
	Mat element = getStructuringElement(operation, cv::Size(2 * morph_size + 1, 2 * morph_size + 1), cv::Point(morph_size, morph_size));

	// Apply the specified morphology operation
	morphologyEx(img, skel, morph_element, element);

	return skel;
}
void Skeletonization3D::generate_skeletonization() {
	skel_arr.clear();
	//Save number of cameras and total number of frames
	n_cameras = camera_arr.size();
	n_frames = camera_arr[0]->get_total_frame_num();

	//Create a Skeleton2D for each camera
	for (constCamVecIte i = camera_arr.begin(); i != camera_arr.end(); ++i) {
		Skeletonization2DPtr skel(new Skeletonization2D(*i));
		skel->generate_skeletonization();
		skel_arr.push_back(skel);
	}
	skel3d_merged_array.resize(n_frames);
	skel2d_cam_array.resize(n_frames * n_cameras);
}
void imageProcess::skelMaker() {
	cv::Mat skel(frame->size(), CV_8U, cv::Scalar(0));
	cv::Mat temp(frame->size(), CV_8U);
	cv::Mat eroded(frame->size(), CV_8U);
	cv::Mat original(frame->size(), CV_8U);
	frame->copyTo(original);
	cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
	bool done;
	do
	{
		cv::erode(original, eroded, element);
		cv::dilate(eroded, temp, element); // temp = open(img)
		cv::subtract(original, temp, temp);
		cv::bitwise_or(skel, temp, skel);
		eroded.copyTo(original);

		done = (cv::countNonZero(original) == 0);
	} while (!done);
	//Copy the skeleton to the output variable
	skel.copyTo(*frame);
}
/*
 * !not in use!
 * creates the skeleton of a given bw-matrix
 * this function has side-effects and manipulates the paramter
 */
void make_skelekton(Mat img) {

	Mat skel(img.size(), CV_8UC1, cv::Scalar(0));
	Mat temp;
	Mat eroded;

	Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));

	bool done;
	do {
		erode(img, eroded, element);
		dilate(eroded, temp, element); // temp = open(img)
		subtract(img, temp, temp);
		bitwise_or(skel, temp, skel);
		eroded.copyTo(img);

		done = (countNonZero(img) == 0);
	} while (!done);

	skel.copyTo(img);
}
Exemple #13
0
// private mode: mount tmpfs over /home
void fs_private(void) {
	char *homedir = cfg.homedir;
	assert(homedir);
	uid_t u = getuid();
	gid_t g = getgid();

	int xflag = fs_store_xauthority();

	// mask /home
	if (arg_debug)
		printf("Mounting a new /home directory\n");
	if (mount("tmpfs", "/home", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=755,gid=0") < 0)
		errExit("mounting home directory");

	// mask /root
	if (arg_debug)
		printf("Mounting a new /root directory\n");
	if (mount("tmpfs", "/root", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=700,gid=0") < 0)
		errExit("mounting home directory");

	if (u != 0) {
		// create /home/user
		if (arg_debug)
			printf("Create a new user directory\n");
		mkdir(homedir, S_IRWXU);
		if (chown(homedir, u, g) < 0)
			errExit("chown");
	}
	else {
		// mask tmp only in root mode; KDE keeps all kind of sockets in /tmp!
		if (arg_debug)
			printf("Mounting a new /tmp directory\n");
		if (mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=777,gid=0") < 0)
			errExit("mounting tmp directory");
	}
	
	skel(homedir, u, g);
	if (xflag)
		fs_copy_xauthority();
}
Exemple #14
0
Skeleton KinectComp::GetSkeleton(unsigned long id)
{
	if (mpKinect == NULL)
	{
		PrintMessage(DEBUG_MESSAGE("Can't get a handle of Kinect API").c_str());
		Skeleton skel;
		const Position invalidPosition(std::numeric_limits<float>::quiet_NaN()
			, std::numeric_limits<float>::quiet_NaN()
			, std::numeric_limits<float>::quiet_NaN());
		skel.result = Skeleton::NOT_TRACKED;
		skel.position = invalidPosition;
		for (int i = 0; i < Skeleton::JOINT_COUNT; i++)
		{
			skel.joints[i] = invalidPosition;
		}
		return skel;
	}

	Skeleton skel(id);
	if (mpKinect->GetSkeleton(skel, id) != API_SUCCESS)
	{
		PrintMessage(DEBUG_MESSAGE("Can't get skeleton").c_str());
		const Position invalidPosition(std::numeric_limits<float>::quiet_NaN()
			, std::numeric_limits<float>::quiet_NaN()
			, std::numeric_limits<float>::quiet_NaN());
		skel.userID = id;
		skel.result = Skeleton::NOT_TRACKED;
		skel.position = invalidPosition;
		for (int i = 0; i < Skeleton::JOINT_COUNT; i++)
		{
			skel.joints[i] = invalidPosition;
		}
	}

	return skel;
}
Exemple #15
0
// private mode (--private-home=list):
// 	mount homedir on top of /home/user,
// 	tmpfs on top of  /root in nonroot mode,
// 	tmpfs on top of /tmp in root mode,
// 	set skel files,
// 	restore .Xauthority
void fs_private_home_list(void) {
	char *homedir = cfg.homedir;
	char *private_list = cfg.home_private_keep;
	assert(homedir);
	assert(private_list);
	
	int xflag = store_xauthority();
	
	uid_t u = getuid();
	gid_t g = getgid();
	struct stat s;
	if (stat(homedir, &s) == -1) {
		exechelp_logerrv("firejail", FIREJAIL_ERROR, "Error: cannot find user home directory\n");
		exit(1);
	}

	// create /tmp/firejail/mnt/home directory
	fs_build_mnt_dir();
	int rv = mkdir(HOME_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
	if (rv == -1)
		errExit("mkdir");
	if (chown(HOME_DIR, u, g) < 0)
		errExit("chown");
	if (chmod(HOME_DIR, 0755) < 0)
		errExit("chmod");
	
	// copy the list of files in the new home directory
	// using a new child process without root privileges
	pid_t child = fork();
	if (child < 0)
		errExit("fork");
	if (child == 0) {
		if (arg_debug)
			printf("Copying files in the new home:\n");
		
		// drop privileges
		if (setgroups(0, NULL) < 0)
			errExit("setgroups");
		if (setgid(getgid()) < 0)
			errExit("setgid/getgid");
		if (setuid(getuid()) < 0)
			errExit("setuid/getuid");
		
		// copy the list of files in the new home directory
		char *dlist = strdup(cfg.home_private_keep);
		if (!dlist)
			errExit("strdup");
	
		char *ptr = strtok(dlist, ",");
		duplicate(ptr);
	
		while ((ptr = strtok(NULL, ",")) != NULL)
			duplicate(ptr);
		free(dlist);	
		exit(0);
	}
	// wait for the child to finish
	waitpid(child, NULL, 0);

	// mount bind private_homedir on top of homedir
	char *newhome;
	if (asprintf(&newhome, "%s%s", HOME_DIR, cfg.homedir) == -1)
		errExit("asprintf");

	if (arg_debug)
		printf("Mount-bind %s on top of %s\n", newhome, homedir);
	if (mount(newhome, homedir, NULL, MS_BIND|MS_REC, NULL) < 0)
		errExit("mount bind");
// preserve mode and ownership
//	if (chown(homedir, s.st_uid, s.st_gid) == -1)
//		errExit("mount-bind chown");
//	if (chmod(homedir, s.st_mode) == -1)
//		errExit("mount-bind chmod");

	if (u != 0) {
		// mask /root
		if (arg_debug)
			printf("Mounting a new /root directory\n");
		if (mount("tmpfs", "/root", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=700,gid=0") < 0)
			errExit("mounting home directory");
	}
	else {
		// mask /home
		if (arg_debug)
			printf("Mounting a new /home directory\n");
		if (mount("tmpfs", "/home", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=755,gid=0") < 0)
			errExit("mounting home directory");

		// mask /tmp only in root mode; KDE keeps all kind of sockets in /tmp!
		if (arg_debug)
			printf("Mounting a new /tmp directory\n");
		if (mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC,  "mode=777,gid=0") < 0)
			errExit("mounting tmp directory");
	}

	skel(homedir, u, g);
	if (xflag)
		copy_xauthority();

}