Exemplo n.º 1
0
/* ------------------------------------------------------------------------
					Test_VideoFile
   ------------------------------------------------------------------------ */
void Test_VideoFile()
{
	CVideoFileWriter vid;

	cout << "Creating test.avi..." << endl;

	const int W = 352;
	const int H = 288;

	vid.open("test.avi", 15, TImageSize(W, H));  // Use default codec
	//	vid.open("test.avi",15,TImageSize(W,H),"XVID");

	for (int i = 1; i < 100; i++)
	{
		CImage img(W, H);

		img.rectangle(0, 0, 320, 200, TColor::black());

		img.drawCircle(
			160 + 50 * cos(0.05 * i), 120 + 50 * sin(0.05 * i), 30,
			TColor(255, 255, 255));

		vid << img;

		cout << "frame " << i << endl;
	}
	vid.close();

	cout << "Video closed " << endl;
}
int main(int argc, char **argv)
{
    try
    {

        string i_rawlogFile;
        string o_videoFile;

        bool batchMode;

        string datasetPath;
        vector<string> v_sessions;
        v_sessions.push_back("session1");
        v_sessions.push_back("session2");
        v_sessions.push_back("session3");

        vector<string> v_sequences;
        v_sequences.push_back("fullhouse");
        v_sequences.push_back("kitchen");
        v_sequences.push_back("room1");
        v_sequences.push_back("room2");
        v_sequences.push_back("room3");
        v_sequences.push_back("bathroom1");
        v_sequences.push_back("bathroom2");
        v_sequences.push_back("corridor");
        v_sequences.push_back("desktops");
        v_sequences.push_back("livingroom");

        v_sensorsToUse.resize(4,true);

        //
        // Load parameters
        //

        bool sensorsReset = false;

        if ( argc >= 3 )
        {
            i_rawlogFile = argv[1];
            o_videoFile = argv[2];

            size_t arg = 3;

            while ( arg < argc )
            {
                if ( !strcmp(argv[arg],"-useDepthImg") )
                {
                    useDepthImg = true;
                }
                else if ( !strcmp(argv[arg],"-batchMode") )
                {
                    batchMode = true;
                    datasetPath = i_rawlogFile;
                }
                else if ( !strcmp(argv[arg],"-sensor") )
                {
                    if ( !sensorsReset )
                    {
                        v_sensorsToUse.clear();
                        v_sensorsToUse.resize(4,false);
                    }

                    sensorsReset = true;

                    string sensorLabel(argv[arg+1]);

                    if ( sensorLabel == "RGBD_1" )
                        v_sensorsToUse[0] = true;
                    else if ( sensorLabel == "RGBD_2" )
                        v_sensorsToUse[1] = true;
                    else if ( sensorLabel == "RGBD_3" )
                        v_sensorsToUse[2] = true;
                    else if ( sensorLabel == "RGBD_4" )
                        v_sensorsToUse[3] = true;
                    else
                    {
                        cout << "[Error] " << argv[arg+1] << "unknown sensor label" << endl;
                        return -1;
                    }

                    arg++;
                }
                else
                {
                    cout << "[Error] " << argv[arg] << " unknown paramter" << endl;
                    return -1;
                }

                arg++;
            }
        }
        else
        {
            cout << "Usage information. Two expected arguments: " << endl <<
                    " \t (1) Input rawlog file / path of the dataset in the system." << endl <<
                    " \t (2) Output video file." << endl;
            cout << "Then, optional parameters:" << endl <<
                    " \t -sensor      : Use information from this sensor." << endl <<
                    " \t -useDepthImg : Use depth images instead of RGB." << endl <<
                    " \t -batchMode   : Create a video with all the sequences into the dataset." << endl <<
                    " \t                If set, then the first app parameter is the dataset path." << endl;
            return 0;
        }

        if ( useDepthImg )
            cout << "[INFO] Using depth image." << endl;
        if ( batchMode )
            cout << "[INFO] Using batch mode." << endl;

        size_t N_sensors = v_sensorsToUse[0] + v_sensorsToUse[1]
                            + v_sensorsToUse[2] + v_sensorsToUse[3];

        CVideoFileWriter  vid;

        size_t imgWidth = ( useDepthImg ) ? 244 : 240;

        size_t width = imgWidth*N_sensors;
        size_t height = 320;

        size_t N_channels = ( useDepthImg ) ? 1 : 3;

        vid.open( o_videoFile,
                  4,
                  TPixelCoord(width,height),
                  "MJPG",
                  (useDepthImg) ? false : true
                );

        vector<CImage> v_images;

        //
        // Batch mode
        //

        if ( !batchMode )
        {
            CRawlog i_rawlog;

            cout << "Working with " << i_rawlogFile << endl;

            if (!i_rawlog.loadFromRawLogFile(i_rawlogFile))
                throw std::runtime_error("Couldn't open rawlog dataset file for input...");

            getImages( i_rawlog, v_images, imgWidth, width, height, N_channels, string(""),N_sensors );

            for ( size_t image_index = 0; image_index < v_images.size(); image_index++ )
                vid << v_images[image_index];

            for ( size_t i = 0; i < 8; i++ )
                vid << v_images[v_images.size()-1];
        }
        else
        {
            for ( size_t session_index = 0; session_index < v_sessions.size(); session_index++ )
                for ( size_t sequece_index = 0; sequece_index < v_sequences.size(); sequece_index++ )
                    for ( size_t rawlog_index = 1; rawlog_index < 4; rawlog_index++ )
                    {
                        CRawlog i_rawlog;

                        std::stringstream ss;
                        ss << rawlog_index;
                        string i_rawlogFileName = datasetPath+"/"+v_sessions[session_index]+"/"+v_sequences[sequece_index]+"/"+ss.str()+".rawlog";
                        string textToAdd = v_sessions[session_index]+" / "+v_sequences[sequece_index] + " / " + ss.str();

                        try {
                        if (i_rawlog.loadFromRawLogFile(i_rawlogFileName))
                        {
                            cout << "Working with: " << i_rawlogFileName << endl;

                            getImages( i_rawlog, v_images,
                                       imgWidth, width,
                                       height, N_channels,
                                       textToAdd, N_sensors );

                            for ( size_t image_index = 0; image_index < v_images.size(); image_index++ )
                                vid << v_images[image_index];

                            for ( size_t i = 0; i < 10; i++ )
                                vid << v_images[v_images.size()-1];

                            v_images.clear();
                        }
                        }
                        catch (...)
                        {

                        }
                    }
        }




        vid.close();

        return 0;

    } catch (exception &e)
    {
        cout << "HOMe exception caught: " << e.what() << endl;
        return -1;
    }
    catch (...)
    {
        printf("Another exception!!");
        return -1;
    }
}