当前位置: 首页>>代码示例>>C++>>正文


C++ VideoWriter::write方法代码示例

本文整理汇总了C++中VideoWriter::write方法的典型用法代码示例。如果您正苦于以下问题:C++ VideoWriter::write方法的具体用法?C++ VideoWriter::write怎么用?C++ VideoWriter::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VideoWriter的用法示例。


在下文中一共展示了VideoWriter::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: detectAndDisplay

/** @function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
	std::vector<Rect> faces;
	Mat frame_gray;

	cvtColor( frame, frame_gray, CV_BGR2GRAY );
	equalizeHist( frame_gray, frame_gray );

	//-- Detect faces
	face_cascade.detectMultiScale( frame_gray, faces, 2, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

	for( size_t i = 0; i < faces.size(); i++ )
	{
		Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
		rectangle(frame,faces[i],Scalar(255,0,0));
		ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

		Mat faceROI = frame_gray( faces[i] );
		std::vector<Rect> eyes;

		//-- In each face, detect eyes
		eyes_cascade.detectMultiScale( faceROI, eyes, 2, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );

		for( size_t j = 0; j < eyes.size(); j++ )
		{
			Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
			int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
			circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
		}
	}
	//-- Show what you got
	imshow( window_name, frame );
	outputVideo.write(frame);
}
开发者ID:Mohit-Chachada,项目名称:Vision_Test,代码行数:35,代码来源:face_detection_demo.cpp

示例2: record_video

// function to record video taken by usb camera
int record_video(VideoWriter &oVideoWriter, VideoCapture &cap){

     namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
     if ( !oVideoWriter.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
      {
	  cout << "ERROR: Failed to write the video" << endl;
	  return -1;
      }
     is_recording=true;
     while (is_recording)
       {
    	 Mat frame;

         bool bSuccess = cap.read(frame); // read a new frame from video

         if (!bSuccess) //if not success, break loop
          {
    	     cout << "ERROR: Cannot read a frame from video file" << endl;
    	     break;
    	  }

    	 oVideoWriter.write(frame); //writer the frame into the file

    	 imshow("MyVideo", frame); //show the frame in "MyVideo" window
         if (waitKey(10) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
          {
            cout << "esc key is pressed by user" << endl;
            break;
          }
        }

}
开发者ID:wuyou33,项目名称:AeroTracker,代码行数:33,代码来源:capture_flight.cpp

示例3: main

int main(int argc, char* argv[])
{
    int i;
    namedWindow("Frame");
    ////////////////////////////////////////////////////
    Mat frame_4, frame;

    //double dWidth = 640; //get the width of frames of the video
    //double dHeight = 480; //get the height of frames of the video
    

    

    vector<Mat> layers;
    WebCore* web_core = WebCore::Initialize(WebConfig());
    WebView* view = web_core->CreateWebView(WIDTH, HEIGHT);
    WebURL url(WSLit(URL_polar));
    view->LoadURL(url);
    BitmapSurface* surface;

    Size frameSize(static_cast<int>(WIDTH), static_cast<int>(HEIGHT));
    VideoWriter writer ("polarbearchillin.avi", CV_FOURCC('D','I','V','3'), 15, frameSize, true); //initialize the VideoWriter object 


    for(int i=0; i<1000000; i++) //delay is added to pass advertisement on some of the URLs
    {
        web_core->Update();
    }
    ///////////////////////////////////////////////////

    if ( !writer.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
    {
        cout << "ERROR: Failed to write the video" << endl;
        return -1;
    }

    while(i != 27)
    {
        ////////////////////////////////////////////////

        web_core->Update();
        surface = (BitmapSurface*)view->surface();
        frame_4 = Mat(Size(WIDTH, HEIGHT), CV_8UC4, (unsigned char*)surface->buffer(), Mat::AUTO_STEP);
        split(frame_4, layers);
        layers.pop_back();
        merge(layers, frame);

        ////////////////////////////////////////////////
        writer.write(frame); //writer the frame into the file
        imshow("Frame", frame);
        i=waitKey(30);
    }
    ///////////////////////
    view->Destroy();
    WebCore::Shutdown();
    ///////////////////////
    destroyAllWindows();
    return 0;
}
开发者ID:akamus082,项目名称:CameraTrap,代码行数:59,代码来源:main.cpp

示例4: main

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // open the video camera no. 0

    if (!cap.isOpened())  // if not success, exit program
    {
        cout << "ERROR: Cannot open the video file" << endl;
        return -1;
    }

 namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

   double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
   double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

   cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

   Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

 VideoWriter oVideoWriter ("myVideo.avi", CV_FOURCC('P','I','M','1'), 20, frameSize, true); //initialize the VideoWriter object 

   if ( !oVideoWriter.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
   {
cout << "ERROR: Failed to write the video" << endl;
return -1;
   }

    while (1)
    {

        Mat frame;

        bool bSuccess = cap.read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
{
             cout << "ERROR: Cannot read a frame from video file" << endl;
             break;
        }

oVideoWriter.write(frame); //writer the frame into the file

        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        if (waitKey(10) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
       {
            cout << "esc key is pressed by user" << endl;
            break; 
       }
    }

    return 0;

}
开发者ID:Riddle4045,项目名称:OpenCV-experiments,代码行数:54,代码来源:wirteVideoFile.cpp

示例5: checkFrame

bool checkFrame(VideoCapture &cam, VideoWriter &video, std::vector<Vec3f> &circles) {
    Mat frame; //Mat to store current frame from camera
    Mat hsv; //Mat to store transformed HSV space image
    Mat upLim; //Mat to store HSV image with upper limit applied
    Mat downLim; //Mat to store HSV image with lower limit applied
    Mat redImg; //Mat to store HSV image with combined upper and lower limits

    //capture frame
    cam >> frame;
    resize(frame, frame, Size(640, 360), 0, 0, INTER_CUBIC);
    video.write(frame);

    //convert to HSV space
    cvtColor(frame, hsv, CV_BGR2HSV);

    // <TODO: remove hard coded limits>
    inRange(hsv, Scalar(0, 100, 100), Scalar(10, 255, 255), downLim);
    inRange(hsv, Scalar(160, 100, 100), Scalar(179, 255, 255), upLim);

    //combine two ranges into single image
    addWeighted(downLim, 1.0, upLim, 1.0, 0.0, redImg);

    //apply Gaussian blur to improve detection
    GaussianBlur(redImg, redImg, Size(9, 9), 2, 2);

    //apply Hough transform (configured to only really work at 7m)
    //inputArray, outputArray, method, dp, minDistance, param1, param2, minR, maxR
    //redImg is 320x240
    HoughCircles(redImg, circles, CV_HOUGH_GRADIENT, 1, redImg.rows / 2, 50, 24, 5, 9);
    //if circle is found, save image and return true
    if (circles.size() > 0) {

        // clone original frame to draw circle on
        Mat endFrame = frame.clone();

        // draw circle
        for (size_t i = 0; i < circles.size(); i++) {
            Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
            int radius = cvRound(circles[i][2]);
            // circle center
            circle(endFrame, center, 3, Scalar(0, 255, 0), -1, 8, 0);
            // circle outline
            circle(endFrame, center, radius, Scalar(0, 0, 255), 3, 8, 0);
        }

        // save images
        imwrite("/home/pi/NGCP/RPI_cpslo/Datalogs/OriginalImg.jpg", frame);
        imwrite("/home/pi/NGCP/RPI_cpslo/Datalogs/HSVImg.jpg", redImg);
        imwrite("/home/pi/NGCP/RPI_cpslo/Datalogs/FinalImg.jpg", endFrame);

        return true;
    }
    return false;
}
开发者ID:tmaudev,项目名称:RPI_cpslo,代码行数:54,代码来源:mavlink_control.cpp

示例6: main

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // otweranie kamery wideo

    if (!cap.isOpened())  // wyjscie w razie niepowodzenia
    {
        cout << "ERROR: Cannot open the video file" << endl;
        return -1;
    }

    namedWindow("Wideo",CV_WINDOW_AUTOSIZE); //twozenie okna wideo

    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //pobieranie szerokosci klatek
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //pobieranie wysokosci kaltek

    cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

    Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

    VideoWriter oVideoWriter ("wideo.avi", CV_FOURCC('P','I','M','1'), 20, frameSize, true); //twozenie obiektu VideoWriter

    if ( !oVideoWriter.isOpened() ) //jezliWideoWriter nie dziala zakoncz
    {
        cout << "Blad nie mozna odczytac  wideo" << endl;
        return -1;
    }

    while (1)
    {

        Mat frame;

        bool bSuccess = cap.read(frame); // cztanie wideo po klatce

        if (!bSuccess) //jezeli blad opusc petle
        {
            cout << "Blad nie mozna odczytac kaltki wideo" << endl;
            break;
        }

        oVideoWriter.write(frame); //zapisz klatke do pliku

        imshow("Wideo", frame); //pokaz ramke w oknie

        if (waitKey(10) == 27) //czekaj na kalwisz wyjcia -opusc petle
        {
            cout << "esc wcisniety koniec" << endl;
            break;
        }
    }

    return 0;

}
开发者ID:s5907,项目名称:NAI_Projekt,代码行数:54,代码来源:zapis_w.cpp

示例7: main

int main(){

    // Variables
    VideoCapture capture;
    VideoWriter writer;
    Mat frame;

    // Read from source
    capture.open(0);
    //capture.open("../Videos/chessboard-1.avi");

    // Check if the source was opened correctly
    if (!capture.isOpened()){
        cout << "Cannot open video device or file!" << endl;
        return -1;
    }

    // Read first frame (needed to configure VideoWriter)
    capture.read(frame);
    if (frame.empty()){
        printf("VideoCapture failed getting the first frame!\n");
        return -1;
    }

    // Open a video file for writing and check
    writer.open("./video.avi", CV_FOURCC('D','I','V','X'), 15, frame.size(), true);
    if( !writer.isOpened() ) {
        printf("VideoWriter failed to open!\n");
        return -1;
    }

    // Read the video
    while(true){

        // Read new frame
        capture.read(frame);
        if (frame.empty())
            break;

        // Write frame to a file
        writer.write(frame);

        // Show frame
        imshow("video", frame);

        if ((cvWaitKey(10) & 255) == 27) break;
    }

    // Release memory
    capture.release();
    frame.release();

    return 0;
}
开发者ID:88enrique,项目名称:ReadWriteVideo,代码行数:54,代码来源:main.cpp

示例8: main

int main(int, char**)
{
    Mat src;
    // use default camera as video source
    VideoCapture cap(0);
    // check if we succeeded
    if (!cap.isOpened()) {
        cerr << "ERROR! Unable to open camera\n";
        return -1;
    }
    // get one frame from camera to know frame size and type
    cap >> src;
    // check if we succeeded
    if (src.empty()) {
        cerr << "ERROR! blank frame grabbed\n";
        return -1;
    }
    bool isColor = (src.type() == CV_8UC3);

    //--- INITIALIZE VIDEOWRITER
    VideoWriter writer;
    int codec = CV_FOURCC('M', 'J', 'P', 'G');  // select desired codec (must be available at runtime)
    double fps = 25.0;                          // framerate of the created video stream
    string filename = "./live.avi";             // name of the output video file
    writer.open(filename, codec, fps, src.size(), isColor);
    // check if we succeeded
    if (!writer.isOpened()) {
        cerr << "Could not open the output video file for write\n";
        return -1;
    }

    //--- GRAB AND WRITE LOOP
    cout << "Writing videofile: " << filename << endl
         << "Press any key to terminate" << endl;
    for (;;)
    {
        // check if we succeeded
        if (!cap.read(src)) {
            cerr << "ERROR! blank frame grabbed\n";
            break;
        }
        // encode the frame into the videofile stream
        writer.write(src);
        // show live and wait for a key with timeout long enough to show images
        imshow("Live", src);
        if (waitKey(5) >= 0)
            break;
    }
    // the videofile will be closed and released automatically in VideoWriter destructor
    return 0;
}
开发者ID:chaokunyang,项目名称:opencv,代码行数:51,代码来源:videowriter_basic.cpp

示例9: main

int main(int argc, const char *argv[]) {


	VideoCapture cap("/home/mac/Documents/PROJECT/NewDataSets/krithika/book_k3.wmv");
	noframes=1;
	double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
	double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
	Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
	VideoWriter oVideoWriter ("/home/mac/Documents/PROJECT/Output/3spaces/kalmanfilter.avi", CV_FOURCC('P','I','M','1'), 20, frameSize, true); //initialize the VideoWriter object



	//notstarted=false;
	Mat3b frame;

	while(cap.read(frame))
	{

		skin = GetSkin(frame);
		//imshow("Skin",skin);
		cvtColor(skin,skin,CV_RGB2GRAY);
		skin1 = skin> 50;
		blur( skin1, skin1, Size(3,3) );
		char* source_window = "Source";
		namedWindow( source_window, CV_WINDOW_AUTOSIZE );
		src_gray=skin1;
		createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
		cv::SiftFeatureDetector detector;
		detector.detect(skin1, keypoints);
		Mat output;
		thresh_callback( 0, 0 );
		if(noframes>8)
		{
			Kalman_Perdict(H);Kalman_Perdict(R);Kalman_Perdict(L);
			imshow("Tracking",skin2);
			oVideoWriter.write(skin2);
		}
		drawKeypoints(skin1, keypoints, output);
		skin2=frame;
		medianBlur( skin1, skin1, 5 );
		noframes+=1;
		waitKey(5);
		keypoints.clear();

	}
    return 0;
}
开发者ID:divya-swaminathan,项目名称:B-Tech-Final-Year-Project,代码行数:47,代码来源:Segement1_0.cpp

示例10: vcap

int
main ()
{

  VideoCapture vcap (0);
  if (!vcap.isOpened ())
  {
    cout << "Error opening video stream or file" << endl;
    return -1;
  }

  cout << "Starting ..." << endl;
  int frame_width = vcap.get (CV_CAP_PROP_FRAME_WIDTH);
  int frame_height = vcap.get (CV_CAP_PROP_FRAME_HEIGHT);
  cout << "frame width:  " << frame_width << endl;
  cout << "frame height: " << frame_height << endl;

  VideoWriter video ("out.avi", CV_FOURCC ('M', 'J', 'P', 'G'), 10, Size (frame_width, frame_height), true);

  int i = 0;

  for (;;)
  {

    Mat frame;
    vcap >> frame;
    video.write (frame);
    imshow ("Frame", frame);
    if (i < 10)
    {
      ostringstream convert;
      convert << i;
      string name = "image_" + convert.str () + ".jpg";
      imwrite (name, frame);
      i++;
    }

    char c = (char) waitKey (33);
    if (c == 27)
      break;
  }
  return 0;
}
开发者ID:nqanh,项目名称:moveit_bigman,代码行数:43,代码来源:capture_video_webcam.cpp

示例11: mergeImgToVid

void Converter::mergeImgToVid(char* src, char* dst, double fps){
  path p(src);
  VideoWriter output;
  bool opened = false;

  if (exists(p) && is_directory(p)){
      for (directory_entry& x : directory_iterator(p)){
          if (is_regular_file(x.path())){
              string path = x.path().string();
              if (path.find( ".DS_Store" ) != string::npos )
                  continue;
              cv::Mat inImg = imread(path, CV_LOAD_IMAGE_COLOR);
              if (!output.isOpened()){
                output.open(dst, CV_FOURCC('M', 'J', 'P', 'G'), fps, inImg.size(), true);
              }
              output.write(inImg);
          }
      }
  }
}
开发者ID:marvinHao,项目名称:RPCA,代码行数:20,代码来源:Converter.cpp

示例12: RunVision

void RunVision()
{
//	pthread_t visionThread;
//
//	if(1 == pthread_create(&visionThread, NULL, VisionActionAsync, NULL))
//	{
//		fprintf(stderr, "Couldn't create Vision thread\n");
//		exit(1);
//	}
//}
//
//void* VisionActionAsync(void*)
//{
	Vision::GetInstance()->OpenFlyCapCamera();

	signal(SIGTERM, SigTermHandler);

	Vision::GetInstance()->IsVisionThreadRunning = true;

	const string outputFile =
			"/home/robot/workspace2/RoboCup2016/RoboCup2016/GoalKeeper2016/demo.avi";

	VideoWriter outputVideo;
	outputVideo.open(outputFile, CV_FOURCC('M', 'J', 'P', 'G'), 10,
			Size(FRAME_WIDTH, FRAME_HEIGHT), true);

	// capture loop
	char key = 0;
	while (key != 'q' && Vision::GetInstance()->IsVisionThreadRunning == true)
	{
		Mat currentFrame;
		Vision::GetInstance()->GetFrameFromFlyCap(currentFrame);
		Vision::GetInstance()->ProcessCurrentFrame(currentFrame);

		imshow("Outout", currentFrame);
		key = waitKey(30);
		outputVideo.write(currentFrame);
	}

	Vision::GetInstance()->CloseFlyCapCamera();
}
开发者ID:BIURoboCup,项目名称:RoboCup2016,代码行数:41,代码来源:Vision.cpp

示例13: grabVideoAndData

void Video::grabVideoAndData(string path, string ext, string buffer,
		VideoWriter &writer, const Mat &image)
{
	if (!writer.isOpened())
	{
		string source = path;

		source.append(buffer);
		source.append("." + ext);
		// Open the output
		writer.open(source, CV_FOURCC('X', 'V', 'I', 'D'), 12,
				cv::Size(image.size().width, image.size().height), true);

		if (!writer.isOpened())
		{
			printf("Could not open the output video for write: %s", source.c_str());
		}
	}

	writer.write(image);
}
开发者ID:Tiger66639,项目名称:ardrone-auto-control,代码行数:21,代码来源:Video.cpp

示例14: main

int main(){
	namedWindow("Video");
	namedWindow("erstes Video-Frame");
	VideoCapture videoCapture;
	// ACHTUNG: Pfad bitte anpassen!
	videoCapture.open("C:/Users/Andreas/Desktop/Micro-dance_2_.avi");	
	int width = videoCapture.get(CV_CAP_PROP_FRAME_WIDTH);
	int height = videoCapture.get(CV_CAP_PROP_FRAME_HEIGHT);


	// >>>>>>>>>> VideoWriter Objekt initialisieren
	VideoWriter videoWriter;
	//>>>>>>>>>> VideoWriter Datei öffnen
	videoWriter.open("Video.avi", CV_FOURCC('P','I','M','1'), 30, Size(width, height), true);


	Mat firstFrame;
	int frameNumber = 0;
	while(true){
		Mat videoFrame;
		if (false == videoCapture.read(videoFrame)){
			break;
		}
		//>>>>>>>>>> VideoWriter Frame schreiben
		videoWriter.write(videoFrame);
		
		frameNumber++;
		if (frameNumber == 1){
			videoFrame.copyTo(firstFrame);		// kopiert die Pixel des ersten Video Frames
		}


		imshow("erstes Video-Frame", firstFrame);
		imshow("Video", videoFrame);
		waitKey(30);
	}
	return 0;
}
开发者ID:SebastianBone,项目名称:avprg,代码行数:38,代码来源:videoabspielen.cpp

示例15: main

int main(){
	//Dimensions of Capture window
	int scale = 1;
	int width = 640/scale;
	int height = 480/scale;
	int lineSize;
	unsigned int start_time,stop_time;
	//Open capture device
	int device = 0; //assume we want first device

	bool gui = true;
	bool record = false;

	//create video capture device, set capture area
	VideoCapture capture = VideoCapture(device);
	capture.open(device);
	capture.set(CAP_PROP_FRAME_WIDTH,width);
	capture.set(CAP_PROP_FRAME_HEIGHT,height);


	//create recording object
	VideoWriter *recorder;
	//recorder = new VideoWriter ("test.avi",cv::CV_F FOURCC('D','I','V','X'), 30,Point(width,height));
	if (!recorder->isOpened() && record){
		return 0;
	}


	//Construct GUI object
	DebugGUI myGUI = DebugGUI(gui);

	//create image processing objects
	LineFinder imgproc = LineFinder(myGUI.getHSV(),scale);
	//imgproc.configWebcam("line");
	if(capture.isOpened()){  //check if we succeeded
		Mat raw;
		//main loop
		while(true){
			start_time = GetTimeMs64();

			//Pull a frame from the camera to the raw image
			// capture the current frame

			if (!capture.grab()){
				break;
			}
			capture >> raw;

			if (gui){
				imgproc.setFrame(raw.clone());
			}else{
				imgproc.setFrame(raw);
			}
			imgproc.setHSV(&myGUI);
			/*//imgproc.getGray();
			imgproc.thresholdHSV();
			imgproc.fillHoles();
			//imgproc.findObjects();
			//imgproc.printBiggestObject(raw)
			imgproc.findLines();
			double size =  imgproc.calculateBestGradient();
			LineObject* drawLine = imgproc.calculateErrorLine(height,width);
			if (drawLine != 0){
				lineSize = drawLine->size();
			}else{
				lineSize = 0;
			}
			if (gui){
				imgproc.drawErrorLine(raw,height,width);
				imgproc.printLines(raw);
			}
			//print (1/(time2-time1))

#ifdef time
			stop_time = GetTimeMs64();
			cout << "FPS: "  <<  1000/(stop_time - start_time) << endl;
#else
			cout << "Gradient: " << size << " " << "Offset: " << lineSize  << endl;
#endif
			*/
			if (gui){
				imshow("Raw",raw);
			}
			if (record){
				recorder->write(raw);
			}
			if(waitKey(30) >= 0){
				return 0;
			}
		}
	}
开发者ID:matthewAURA,项目名称:piCamera,代码行数:91,代码来源:lineTrack.cpp


注:本文中的VideoWriter::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。