Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
54afb85d
Commit
54afb85d
authored
May 14, 2013
by
Vadim Pisarevsky
Committed by
OpenCV Buildbot
May 14, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #823 from pickle27:starter_image_sequence
parents
14c50d2f
69c626e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
33 deletions
+38
-33
reading_and_writing_images_and_video.rst
modules/highgui/doc/reading_and_writing_images_and_video.rst
+4
-4
starter_video.cpp
samples/cpp/starter_video.cpp
+34
-29
No files found.
modules/highgui/doc/reading_and_writing_images_and_video.rst
View file @
54afb85d
...
...
@@ -191,8 +191,8 @@ VideoCapture
------------
.. ocv:class:: VideoCapture
Class for video capturing from video files or cameras.
The class provides C++ API for capturing video from cameras or for reading video files. Here is how the class can be used: ::
Class for video capturing from video files
, image sequences
or cameras.
The class provides C++ API for capturing video from cameras or for reading video files
and image sequences
. Here is how the class can be used: ::
#include "opencv2/opencv.hpp"
...
...
@@ -241,7 +241,7 @@ VideoCapture constructors.
.. ocv:cfunction:: CvCapture* cvCaptureFromCAM( int device )
.. ocv:cfunction:: CvCapture* cvCaptureFromFile( const char* filename )
:param filename: name of the opened video file
:param filename: name of the opened video file
(eg. video.avi) or image sequence (eg. img%02d.jpg)
:param device: id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0.
...
...
@@ -258,7 +258,7 @@ Open video file or a capturing device for video capturing
.. ocv:pyfunction:: cv2.VideoCapture.open(filename) -> retval
.. ocv:pyfunction:: cv2.VideoCapture.open(device) -> retval
:param filename: name of the opened video file
:param filename: name of the opened video file
(eg. video.avi) or image sequence (eg. img%02d.jpg)
:param device: id of the opened video capturing device (i.e. a camera index).
...
...
samples/cpp/starter_video.cpp
View file @
54afb85d
...
...
@@ -4,31 +4,34 @@
* Created on: Nov 23, 2010
* Author: Ethan Rublee
*
* A starter sample for using opencv, get a video stream and display the images
* Modified on: April 17, 2013
* Author: Kevin Hughes
*
* A starter sample for using OpenCV VideoCapture with capture devices, video files or image sequences
* easy as CV_PI right?
*/
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
using
namespace
cv
;
using
namespace
std
;
//hide the local functions in an anon namespace
namespace
{
void
help
(
char
**
av
)
{
cout
<<
"
\n
This program justs gets you started reading images from video
\n
"
"Usage:
\n
./"
<<
av
[
0
]
<<
" <video device number>
\n
"
<<
"q,Q,esc -- quit
\n
"
<<
"space -- save frame
\n\n
"
<<
"
\t
This is a starter sample, to get you up and going in a copy pasta fashion
\n
"
<<
"
\t
The program captures frames from a camera connected to your computer.
\n
"
<<
"
\t
To find the video device number, try ls /dev/video*
\n
"
<<
"
\t
You may also pass a video file, like my_vide.avi instead of a device number"
<<
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
<<
"Usage:
\n
"
<<
av
[
0
]
<<
" <video file, image sequence or device number>"
<<
endl
<<
"q,Q,esc -- quit"
<<
endl
<<
"space -- save frame"
<<
endl
<<
endl
<<
"
\t
To capture from a camera pass the device number. To find the device number, try ls /dev/video*"
<<
endl
<<
"
\t
example: "
<<
av
[
0
]
<<
" 0"
<<
endl
<<
"
\t
You may also pass a video file instead of a device number"
<<
endl
<<
"
\t
example: "
<<
av
[
0
]
<<
" video.avi"
<<
endl
<<
"
\t
You can also pass the path to an image sequence and OpenCV will treat the sequence just like a video."
<<
endl
<<
"
\t
example: "
<<
av
[
0
]
<<
" right%%02d.jpg"
<<
endl
;
}
int
process
(
VideoCapture
&
capture
)
{
...
...
@@ -38,29 +41,31 @@ namespace {
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
(
5
);
//delay N millis, usually long enough to display and capture input
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
;
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
;
}
}
int
main
(
int
ac
,
char
**
av
)
{
...
...
@@ -70,11 +75,11 @@ int main(int ac, char** av) {
return
1
;
}
std
::
string
arg
=
av
[
1
];
VideoCapture
capture
(
arg
);
//try to open string, this will attempt to open it as a video file
VideoCapture
capture
(
arg
);
//try to open string, this will attempt to open it as a video file
or image sequence
if
(
!
capture
.
isOpened
())
//if this fails, try to open as a video camera, through the use of an integer param
capture
.
open
(
atoi
(
arg
.
c_str
()));
if
(
!
capture
.
isOpened
())
{
cerr
<<
"Failed to open
a video device or video fil
e!
\n
"
<<
endl
;
cerr
<<
"Failed to open
the video device, video file or image sequenc
e!
\n
"
<<
endl
;
help
(
av
);
return
1
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment