12-06-2014, 12:24 PM
OpenCV Tutorial II: Video Processing
OpenCV Tutorial II.pdf (Size: 121.12 KB / Downloads: 109)
Outline
Reading video
Writing video
Edge Detection
Demo: Laplacian edge detection
Capturing a frame from a video sequence
Initializing capture from a camera:
CvCapture capture = cvCaptureF romCAM(0);
capture from video device 0
Initializing capture from a le:
CvCapture capture = cvCaptureF romAV I("infile:avi");
Capturing a frame:
cvGrabF rame(capture);
retrieve the captured frame:
img = cvRetrieveF rame(capture);
Releasing the capture source:
cvReleaseCapture(&capture);
Don't forget to release!
Get capture device properties
Get capture device properties:
cvQueryFrame(capture);
this call is necessary to get correct capture properties
cvGetCaptureP roperty(capture; property id; value);
property id:
CV CAP PROP FRAME HEIGHT
CV CAP PROP FRAME WIDTH
CV CAP PROP FPS
CV CAP PROP FRAME COUNT
Frame count does not seem to be working properly.
Set frame information
Set capture device properties:
cvSetCaptureProperty(capture; property id; value); sets the
specied property of camera or AVI.
property id:
The same as getting frame information
Example:
cvSetCaptureProperty
(capture;CV CAP PROP POS AV I RATIO; 0:9);
start capturing from a relative position of 0.9 of a video le
Write/save video
First initializing a video writer:
CvV ideoW ritercvCreateV ideoW riter
(filename; fourcc; fps; frame size; is color = 1)
fourcc: four-Character Codes
CV FOURCC(′P′;′ I′;′M′;′ 1′) : MPEG ? 1
CV FOURCC(′M′;′ J′;′ P′;′ G′) : motion ? jpeg
CV FOURCC(′M′;′ P′;′ 4′;′ 2′) : MPEG ? 4:2
CV FOURCC(′D′;′ I′;′ V ′;′ 3′) : MPEG ? 4:3
CV FOURCC(′D′;′ I′;′ V ′;′ X′) : MPEG ? 4 = MPEG ? 1
CV FOURCC(′U′;′ 2′;′ 6′;′ 3′) : H263
CV FOURCC(′I′;′ 2′;′ 6′;′ 3′) : H263I
CV FOURCC(′F′;′ L′;′ V ′;′ 1′) : FLV 1
Demo: Laplacian edge detection
Capture the video from WebCam
Function: cvCaptureF romCAM
.2.. Smoothing the frames
Function: cvSmooth
.3.. Split into dierent color spaces
Function: cvSplit
.4.. Add Laplacian lter in each color space
Function: cvLaplace
.5.. Merge the 3 color spaces
Function: cvMerge
.6.. Show the frame
Function: cvShowImage