Read/Write Image and Read VideoFile/Camera and Show It

Read Image

  1. Mat color= imread("../lena.jpg");
  2. Mat gray= imread("../lena.jpg", 0);

Write Image

  1. imwrite("lenaGray.jpg", gray);

Show Image

  1. imshow("Lena Gray", gray);

Read VideoFile/Camera

  1. VideoCapture cap;
  2. cap.open(videoFile);
  3. cap.open(0);//default camera
  4.  
  5. if(!cap.isOpened())  // check if succeeded
  6.     return -1;
  7.  
  8. cap.release();

Show VideoFile/Camera

  1. namedWindow("Video",1);
  2. for(;;)
  3. {
  4.     Mat frame;
  5.     cap >> frame; // get a new frame from camera
  6.     imshow("Video", frame);
  7.     if(waitKey(30) >= 0) break;
  8. }

Leave a Reply

Your email address will not be published. Required fields are marked *