코드 4-5 카메라 입력을 반전하여 동영상 파일로 저장하기 [ch04/video]
01 void camera_in_video_out() 02 { 03 VideoCapture cap(0); 04 05 if (!cap.isOpened()) { 06 cerr << "Camera open failed!" << endl; 07 return; 08 } 09 10 int w = cvRound(cap.get(CAP_PROP_FRAME_WIDTH)); 11 int h = cvRound(cap.get(CAP_PROP_FRAME_HEIGHT)); 12 double fps = cap.get(CAP_PROP_FPS); 13 14 int fourcc = VideoWriter::fourcc('D', 'I', 'V', 'X'); 15 int delay = cvRound(1000 / fps); 16 17 VideoWriter outputVideo("output.avi", fourcc, fps, Size(w, h)); 18 19 if (!outputVideo.isOpened()) { 20 cout << "File open failed!" << endl; 21 return; 22 } 23 24 Mat frame, inversed; 25 while (true) { 26 cap >> frame; 27 if (frame.empty()) 28 break; 29 30 inversed = ~frame; 31 outputVideo << inversed; 32 33 imshow("frame", frame); 34 imshow("inversed", inversed); 35 36 if (waitKey(delay) = = 27) 37 break; 38 } 39 40 destroyAllWindows(); 41 }