Commit 251918e1 authored by Gary Bradski's avatar Gary Bradski

just added frame saving

parent 82856150
...@@ -10,15 +10,20 @@ ...@@ -10,15 +10,20 @@
#include <opencv2/highgui/highgui.hpp> #include <opencv2/highgui/highgui.hpp>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <stdio.h>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
//hide the local functions in an anon namespace //hide the local functions in an anon namespace
namespace { namespace {
void help(char** av) { void help(char** av) {
cout << "\nThis program justs gets you started reading images from video\n" cout << "\nThis program justs gets you started reading images from video\n"
"Usage:\n./" << av[0] << " <video device number>\n" "Usage:\n./" << av[0] << " <video device number>\n"
<< "q,Q,esc -- quit\n"
<< "space -- save frame\n\n"
<< "\tThis is a starter sample, to get you up and going in a copy pasta fashion\n" << "\tThis is a starter sample, to get you up and going in a copy pasta fashion\n"
<< "\tThe program captures frames from a camera connected to your computer.\n" << "\tThe program captures frames from a camera connected to your computer.\n"
<< "\tTo find the video device number, try ls /dev/video* \n" << "\tTo find the video device number, try ls /dev/video* \n"
...@@ -27,8 +32,10 @@ namespace { ...@@ -27,8 +32,10 @@ namespace {
} }
int process(VideoCapture& capture) { int process(VideoCapture& capture) {
int n = 0;
char filename[200];
string window_name = "video | q or esc to quit"; string window_name = "video | q or esc to quit";
cout << "press q or esc to quit" << endl; cout << "press space to save a picture. q or esc to quit" << endl;
namedWindow(window_name, CV_WINDOW_KEEPRATIO); //resizable window; namedWindow(window_name, CV_WINDOW_KEEPRATIO); //resizable window;
Mat frame; Mat frame;
for (;;) { for (;;) {
...@@ -42,6 +49,11 @@ namespace { ...@@ -42,6 +49,11 @@ namespace {
case 'Q': case 'Q':
case 27: //escape key case 27: //escape key
return 0; return 0;
case ' ': //Save an image
sprintf(filename,"filename%.3d.jpg",n++);
imwrite(filename,frame);
cout << "Saved " << filename << endl;
break;
default: default:
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment