Exemple #1
0
int main()
{
	VideoCapture capture("bike.avi");
	if (!capture.isOpened()) return 1;
	double rate = capture.get(CV_CAP_PROP_FPS);
	bool stop(false);
	Mat frame;
	namedWindow("Extractor Frame");
	int delay = 1000 / rate;
	while (!stop)
	{
		//if (!capture.read(frame)) break;
		capture >> frame;
		imshow("Extractor Frame", frame);
		//ÒýÈëÑÓ³Ù
		if (waitKey(delay) >= 0) stop = true;
	
	}
	capture.release();
	//test
	VideoCapture capture1;
	Mat frame1;
	capture1.open("bike.avi");
	namedWindow("test");
	while (!stop)
	{
		capture1 >> frame1;
		imshow("test", frame1);
		if (waitKey(delay) >= 0) stop = true;
	}
	int n = capture1.get(CV_CAP_PROP_FRAME_COUNT);
	cout << n << endl;
	capture1.release();
	//second test
	VideoProcessor process;
	process.setInput("bike.avi");
	process.displayInput("Input Video");
	process.displayOutput("Output Video");
	// Play the video at the original frame rate
	process.setDelay(1000. / process.getFrameRate());
	// Set the frame processor callback function
	process.setFrameprocessor(canny);
	process.run();
	waitKey();

	// Second test
	// Create instance
	//	VideoProcessor processor;
	// Open video file
	VideoProcessor1 processor;
	processor.setInput("bike.avi");
	// Get basic info about video file
	cv::Size size = processor.getFrameSize();
	std::cout << size.width << " " << size.height << std::endl;
	std::cout << processor.getFrameRate() << std::endl;
	std::cout << processor.getTotalFrameCount() << std::endl;
	std::cout << processor.getFrameNumber() << std::endl;
	std::cout << processor.getPositionMS() << std::endl;

	// No processing
	processor.dontCallProcess();
	// Output filename
	//	processor.setOutput("../output/bikeOut",".jpg");
	char codec[4];
	processor.setOutput("bike2.avi", processor.getCodec(codec), processor.getFrameRate());
	std::cout << "Codec: " << codec[0] << codec[1] << codec[2] << codec[3] << std::endl;

	// Position the stream at frame 300
	//	processor.setFrameNumber(300);
	//	processor.stopAtFrameNo(120);

	// Declare a window to display the video
	processor.displayInput("Current Frame");
	processor.displayOutput("Output Frame");

	// Play the video at the original frame rate
	processor.setDelay(1000. / processor.getFrameRate());

	// Start the process
	processor.run();

	std::cout << processor.getFrameNumber() << std::endl;
	std::cout << processor.getPositionMS() << std::endl;

	cv::waitKey();




}
int main()
{
    // Open the video file
    cv::VideoCapture capture("../images/bike.avi");
    // check if video successfully opened
    if (!capture.isOpened())
        return 1;

    // Get the frame rate
    double rate = capture.get(cv::CAP_PROP_FPS);

    bool stop(false);
    cv::Mat frame; // current video frame
    cv::namedWindow("Extracted Frame");

    // Delay between each frame
    // corresponds to video frame rate
    int delay = 1000 / rate;

    // for all frames in video
    while (!stop)
    {

        // read next frame if any
        if (!capture.read(frame))
            break;

        cv::imshow("Extracted Frame", frame);

        // introduce a delay
        // or press key to stop
        if (cv::waitKey(delay) >= 0)
            stop = true;
    }

    // Close the video file
    capture.release();

    cv::waitKey();

    // Now using the VideoProcessor class

    // Create instance
    VideoProcessor processor;
    // Open video file
    processor.setInput("../images/bike.avi");
    // Declare a window to display the video
    processor.displayInput("Input Video");
    processor.displayOutput("Output Video");
    // Play the video at the original frame rate
    processor.setDelay(1000. / processor.getFrameRate());
    // Set the frame processor callback function
    processor.setFrameProcessor(canny);
    // Start the process
    processor.run();
    cv::waitKey();

    // Second test
    // Create instance
    //	VideoProcessor processor;
    // Open video file
    processor.setInput("../images/bike.avi");

    // Get basic info about video file
    cv::Size size = processor.getFrameSize();
    std::cout << size.width << " " << size.height << std::endl;
    std::cout << processor.getFrameRate() << std::endl;
    std::cout << processor.getTotalFrameCount() << std::endl;
    std::cout << processor.getFrameNumber() << std::endl;
    std::cout << processor.getPositionMS() << std::endl;

    // No processing
    processor.dontCallProcess();
    // Output filename
    //	processor.setOutput("bikeOut",".jpg");
    char codec[4];
    processor.setOutput("bike.avi", processor.getCodec(codec), processor.getFrameRate());
    std::cout << "Codec: " << codec[0] << codec[1] << codec[2] << codec[3] << std::endl;

    // Position the stream at frame 300
    //	processor.setFrameNumber(300);
    //	processor.stopAtFrameNo(120);

    // Declare a window to display the video
    processor.displayInput("Current Frame");
    processor.displayOutput("Output Frame");

    // Play the video at the original frame rate
    processor.setDelay(1000. / processor.getFrameRate());

    // Start the process
    processor.run();

    std::cout << processor.getFrameNumber() << std::endl;
    std::cout << processor.getPositionMS() << std::endl;

    cv::waitKey();
}
int main()
{
	// Open the video file
	cv::VideoCapture capture("bike.avi");
//	cv::VideoCapture capture("http://www.laganiere.name/bike.avi");
	// check if video successfully opened
	if (!capture.isOpened())
		return 1;

	// Get the frame rate
	double rate= capture.get(CV_CAP_PROP_FPS);
	std::cout << "Frame rate: " << rate << "fps" << std::endl;

	bool stop(false);
	cv::Mat frame; // current video frame
	cv::namedWindow("Extracted Frame");

	// Delay between each frame
	// corresponds to video frame rate
	int delay= 1000/rate;
	long long i=0;
	std::string b="bike";
	std::string ext=".bmp";
	// for all frames in video
	while (!stop) {

		// read next frame if any
		if (!capture.read(frame))
			break;

		cv::imshow("Extra	cted Frame",frame);

		std::string name(b);
        // note: some MinGW compilers generate an error for this line
        // this is a compiler bug
        // try: std::ostringstream ss; ss << i; name+= ss.rdbuf(); i++;
//		name+=std::to_string(i++);
        std::ostringstream ss; ss << i; name+= ss.str(); i++;
		name+=ext;

		std::cout << name <<std::endl;
		
		cv::imwrite(name,frame);

		// introduce a delay
		// or press key to stop
		if (cv::waitKey(delay)>=0)
				stop= true;
	}

	// Close the video file
	capture.release();

	cv::waitKey();

	// Now using the VideoProcessor class

	// Create instance
	VideoProcessor processor;

	// Open video file
	processor.setInput("bike.avi");

	// Declare a window to display the video
	processor.displayInput("Input Video");
	processor.displayOutput("Output Video");

	// Play the video at the original frame rate
	processor.setDelay(1000./processor.getFrameRate());

	// Set the frame processor callback function
	processor.setFrameProcessor(canny);

	// output a video
	processor.setOutput("bikeCanny.avi",-1,15);

	// stop the process at this frame
	processor.stopAtFrameNo(51);

	// Start the process
	processor.run();

	cv::waitKey();	

	return 0;
}