starter_video.cpp hid local functions

This commit is contained in:
Kevin Hughes 2013-04-22 22:28:35 -04:00
parent 3441b2df65
commit 69c626e720

View File

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