Ejemplo n.º 1
0
Archivo: main.cpp Proyecto: Roboy/mocap
int main(int argc, char *argv[]) {
    ros::init(argc, argv, "tracking_node");

    MarkerTracker markerTracker;
    markerTracker.init();

    ros::spin();

    return 0;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
	GLFWwindow* window;
	MarkerTracker markerTracker;

	/* Initialize the library */
	if (!glfwInit())
		return -1;

	// initialize the window system
	/* Create a windowed mode window and its OpenGL context */
	window = glfwCreateWindow(camera_width, camera_height, "Combine", NULL, NULL);

	if (!window)
	{
		glfwTerminate();
		return -1;
	}

	glfwMakeContextCurrent(window);
	glfwSwapInterval(1);

	int window_width, window_height;
	glfwGetFramebufferSize(window, &window_width, &window_height);
	glViewport(0, 0, window_width, window_height);

	// initialize the GL library
	initGL(argc, argv);

	// setup OpenCV
	cv::Mat img_bgr;
	cv::VideoCapture cap;
  cap.set(CV_CAP_PROP_FRAME_WIDTH, camera_width);
  cap.set(CV_CAP_PROP_FRAME_HEIGHT, camera_height);
	initVideoStream(cap);

	/* Loop until the user closes the window */
	while (!glfwWindowShouldClose(window))
	{
		cap >> img_bgr;

		if (img_bgr.empty()){
			std::cout << "Could not query frame. Trying to reinitialize." << std::endl;
			initVideoStream(cap);
			cv::waitKey(1000); // Wait for one sec.
			continue;
		}

		// Track markers 
		markerTracker.find(img_bgr);

		/* Render here */
		display(window, img_bgr);

		/* Swap front and back buffers */
		glfwSwapBuffers(window);

		/* Poll for and process events */
		glfwPollEvents();
	}

	glfwTerminate();

	return 0;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[])
{
	GLFWwindow* window;

    bool game_on = false;
    bool next_game = false;
    bool highscore_time = false;
    float start_game_time = 10000.0;
    float game_duration = 60.0;


	/* Initialize the library */
	if (!glfwInit())
		return -1;


	// initialize the window system
	/* Create a windowed mode window and its OpenGL context */
	window = glfwCreateWindow(camera_width, camera_height, "PokeDigi", NULL, NULL);
	if (!window)
	{
		glfwTerminate();
		return -1;
	}

    //create a random number (0 or 1 - sphere or cube)
    int form;
    int frames_button_0_pressed = 0;
    int frames_botton_1_pressed = 0;

	float falling = -0.12; //arbitrary value that looked ok
    int correct = 0;
    int wrong = 0;

	glfwMakeContextCurrent(window);
	glfwSwapInterval(1);


	int window_width, window_height;
	glfwGetFramebufferSize(window, &window_width, &window_height);
    glViewport(0, 0, window_width, window_height);

    glewExperimental = GL_TRUE;
    glewInit();

    //init freetype resources
    init_resources();

    //init Meshes
    Mesh somethingmon [14] = {Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Agumon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Agumon.png", 20),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Digitamamon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Digitamamon.png", 20),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Gabumon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Gabumon.png", 20),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Hagurumon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Hagurumon.png", 20),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Tentomon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Tentomon.png", 20),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Bakemon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Bakemon.png", 20),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Biyomon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Biyomon.png", 20),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/BR_Bulbasaur.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/BR_Bulbasaur.png", 120),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/BR_Lugia.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/BR_Lugia.png", 600),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Charmander.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Charmander.png", 80),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/BR_Beautifly.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Beautifly.png", 150),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/BR_Shinx.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Shinx.png", 60),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/Pikachu.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Pikachu.png", 80),
                             Mesh("/Users/liesaweigert/ClionProjects/AR/assets/BR_Lumineon.obj",
                                  "/Users/liesaweigert/ClionProjects/AR/assets/Lumineon.png", 120)

    };

	// initialize the GL library
	initGL(argc, argv);

	// setup OpenCV
	Mat img_bgr;
	VideoCapture cap;
	initVideoStream(cap);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(virtual_camera_angle, (double)window_width/(double)window_height, 0.01, 100);

    //set the two values for yes and no
    //sphere = 1228(4648) - cube =1c44(7236) - button for display = 02c2(706)
    Marker buttons[3];
    buttons[0].marker_code = 4648;
    buttons[1].marker_code = 7236;
    buttons[2].marker_code = 90;

    const GLubyte* opengl_version = glGetString(GL_VERSION);
    std::cout << "Using OpenGL Version: " << opengl_version << "\n";

	/* Loop until the user closes the window */
	while (!glfwWindowShouldClose(window))
	{
		cap >> img_bgr;

        flip(img_bgr, img_bgr, 1);

		if (img_bgr.empty()){
			std::cout << "Could not query frame. Trying to reinitialize." << std::endl;
			initVideoStream(cap);
			cv::waitKey(1000); // Wait for one sec.
			continue;
		}

		/* Find the markers in the frame */
		MarkerTracker mt;
        mt.find(img_bgr, buttons, 3);

        //the game starts when both markers/buttons are visible
        if (next_game && !game_on && buttons[0].visible && buttons[1].visible){
            game_on = true;
            form = rand() % 14;
        }

        display(window, img_bgr);

        if(!next_game){
            String new_game = "To start a new game press both buttons!";
            render_text(new_game.c_str(), 200, 300, darkgreen, 48);
            if (!game_on && !buttons[0].visible && !buttons[1].visible && buttons[2].visible) {
                next_game = true;
                start_game_time = glfwGetTime();
            }
        }

        //render correct and wrong answers
        String correct_string = "+" + std::to_string(correct);
        render_text(correct_string.c_str(), 20, 20, green, 48);

        String wrong_string = "-" + std::to_string(wrong);
        render_text(wrong_string.c_str(), 1200, 20, red, 48);

		/* Render here */
        if (game_on && next_game && !highscore_time) {
            display_fallthrough(buttons[2].marker_matrix);
            somethingmon[form].drawMesh(buttons[2].marker_matrix, falling);
            falling += (glfwGetTime() - start_game_time) * 0.00005;
            if (falling >= 0.04){
                game_on = false;
                frames_botton_1_pressed = frames_button_0_pressed = 0;
                falling = -0.12;
                wrong++;
            }
        }

        //see whether one marker is pressed
        if (game_on && !buttons[0].visible){
            frames_button_0_pressed++;
        }
        if(game_on && !buttons[1].visible){
            frames_botton_1_pressed++;
        }

        //after one marker has been pressed for 10 frames the result is
        //evaluated and the game starts over
        if (frames_button_0_pressed > 10 || frames_botton_1_pressed > 10){
            falling = -0.12;
            if (frames_button_0_pressed > 10 && frames_botton_1_pressed > 10){
                wrong++;
            } else if (frames_button_0_pressed > 0 && form < 7){
                correct++;
            } else if (frames_botton_1_pressed > 0 && form >= 7){
                correct++;
            } else wrong++;
            game_on = false;
            frames_botton_1_pressed = frames_button_0_pressed = 0;
        }

        float current_game_time = glfwGetTime() - start_game_time;
        if(current_game_time >= (game_duration - 5) && current_game_time <= game_duration){
            int restTime = game_duration - current_game_time;
            render_text(std::to_string(restTime).c_str(), 600, 300, red, 120);
        }

        if(current_game_time > game_duration && current_game_time < (game_duration + 5)){
            game_on = false;
            frames_botton_1_pressed = frames_button_0_pressed = 0;
            falling = -0.12;
            String highscore = "Your new highscore is: " + std::to_string(correct);
            render_text(highscore.c_str(), 200, 300, darkgreen, 80);
            highscore_time = true;
        }

        if(current_game_time > (game_duration + 5) && highscore_time){
            next_game = false;
            correct = 0;
            wrong = 0;
            highscore_time = false;
        }

        render_text("Pokemon is Copyright Gamefreak, Nintendo and The Pokémon Company 2001-2013", 500, 700, black, 10);
		/* Swap front and back buffers */
		glfwSwapBuffers(window);

		/* Poll for and process events */
		glfwPollEvents();
	}

	//freetype_terminate();
	glfwTerminate();

	return 0;
}