starter_video.cpp hid local functions
authorKevin Hughes <kevin@kevin-M3920.(none)>
Tue, 23 Apr 2013 02:28:35 +0000 (22:28 -0400)
committerKevin Hughes <kevin@kevin-M3920.(none)>
Tue, 23 Apr 2013 02:28:35 +0000 (22:28 -0400)
samples/cpp/starter_video.cpp

index 987c4b8..87b414d 100644 (file)
 using namespace cv;
 using namespace std;
 
-void help(char** av) {
-    cout << "The program captures frames from a video file, image sequence (01.jpg, 02.jpg ... 10.jpg) or camera connected to your computer." << endl
-         << "Usage:\n" << av[0] << " <video file, image sequence or device number>" << endl
-         << "q,Q,esc -- quit" << endl
-         << "space   -- save frame" << endl << endl
-         << "\tTo capture from a camera pass the device number. To find the device number, try ls /dev/video*" << endl
-         << "\texample: " << av[0] << " 0" << endl
-         << "\tYou may also pass a video file instead of a device number" << endl
-         << "\texample: " << av[0] << " video.avi" << endl
-         << "\tYou can also pass the path to an image sequence and OpenCV will treat the sequence just like a video." << endl
-         << "\texample: " << av[0] << " right%%02d.jpg" << endl;
-}
+//hide the local functions in an anon namespace
+namespace {
+    void help(char** av) {
+        cout << "The program captures frames from a video file, image sequence (01.jpg, 02.jpg ... 10.jpg) or camera connected to your computer." << endl
+             << "Usage:\n" << av[0] << " <video file, image sequence or device number>" << endl
+             << "q,Q,esc -- quit" << endl
+             << "space   -- save frame" << endl << endl
+             << "\tTo capture from a camera pass the device number. To find the device number, try ls /dev/video*" << endl
+             << "\texample: " << av[0] << " 0" << endl
+             << "\tYou may also pass a video file instead of a device number" << endl
+             << "\texample: " << av[0] << " video.avi" << endl
+             << "\tYou can also pass the path to an image sequence and OpenCV will treat the sequence just like a video." << endl
+             << "\texample: " << av[0] << " right%%02d.jpg" << endl;
+    }
 
-int process(VideoCapture& capture) {
-    int n = 0;
-    char filename[200];
-    string window_name = "video | q or esc to quit";
-    cout << "press space to save a picture. q or esc to quit" << endl;
-    namedWindow(window_name, WINDOW_KEEPRATIO); //resizable window;
-    Mat frame;
-    
-    for (;;) {
-        capture >> frame;
-        if (frame.empty())
-            break;
-        
-        imshow(window_name, frame);
-        char key = (char)waitKey(30); //delay N millis, usually long enough to display and capture input
+    int process(VideoCapture& capture) {
+        int n = 0;
+        char filename[200];
+        string window_name = "video | q or esc to quit";
+        cout << "press space to save a picture. q or esc to quit" << endl;
+        namedWindow(window_name, WINDOW_KEEPRATIO); //resizable window;
+        Mat frame;
         
-        switch (key) {
-        case 'q':
-        case 'Q':
-        case 27: //escape key
-            return 0;
-        case ' ': //Save an image
-            sprintf(filename,"filename%.3d.jpg",n++);
-            imwrite(filename,frame);
-            cout << "Saved " << filename << endl;
-            break;
-        default:
-            break;
+        for (;;) {
+            capture >> frame;
+            if (frame.empty())
+                break;
+            
+            imshow(window_name, frame);
+            char key = (char)waitKey(30); //delay N millis, usually long enough to display and capture input
+            
+            switch (key) {
+            case 'q':
+            case 'Q':
+            case 27: //escape key
+                return 0;
+            case ' ': //Save an image
+                sprintf(filename,"filename%.3d.jpg",n++);
+                imwrite(filename,frame);
+                cout << "Saved " << filename << endl;
+                break;
+            default:
+                break;
+            }
         }
+        return 0;
     }
-    return 0;
 }
 
 int main(int ac, char** av) {