Added the How to create videos with OpenCV Tutorial. Made some corrections to the feature2d, to get rid of some documentation build errors.

This commit is contained in:
Bernat Gabor 2011-08-13 14:02:18 +00:00
parent d2da81401f
commit bdfc0201de
10 changed files with 133 additions and 11 deletions

View File

@ -3,7 +3,7 @@
*feature2d* module. 2D Features framework
-----------------------------------------------------------
Learn about how to use the feature points detectors, descriptors and matching framework found inside OpenCV.ddddddd
Learn about how to use the feature points detectors, descriptors and matching framework found inside OpenCV.
.. include:: ../../definitions/tocDefinitions.rst
@ -190,7 +190,11 @@ Learn about how to use the feature points detectors, descriptors and matching f
.. toctree::
:hidden:
../feature_description/feature_description
../feature_detection/feature_detection
../trackingmotion/harris_detector/harris_detector
../feature_flann_matcher/feature_flann_matcher
../feature_homography/feature_homography
../trackingmotion/good_features_to_track/good_features_to_track.rst
../trackingmotion/generic_corner_detector/generic_corner_detector
../trackingmotion/corner_subpixeles/corner_subpixeles

View File

@ -116,7 +116,7 @@ Explanation
Result
======
.. image:: images/Shi_Tomasi_Detector_Result.jpg
.. image:: images/Feature_Detection_Result_a.jpg
:align: center

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@ -45,6 +45,26 @@ This section contains valuable tutorials about how to read/save your image/video
:height: 90pt
:width: 90pt
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
=============== ======================================================
|hVideoWrite| *Title:* :ref:`videoWriteHighGui`
*Compatibility:* > OpenCV 2.0
*Author:* |Author_BernatG|
Whenever you work with video feeds you may eventually want to save your image processing result in a form of a new video file. Here's how to do it.
=============== ======================================================
.. |hVideoWrite| image:: images/video-write.png
:height: 90pt
:width: 90pt
.. raw:: latex
\pagebreak

View File

@ -18,7 +18,7 @@ The source code
As a test case where to show off these using OpenCV I've created a small program that reads in two video files and performs a similarity check between them. This is something you could use to check just how well a new video compressing algorithms works. Let there be a reference (original) video like :download:`this small Megamind clip <../../../../samples/cpp/tutorial_code/highgui/video-input-psnr-ssim/video/Megamind.avi>` and :download:`a compressed version of it <../../../../samples/cpp/tutorial_code/highgui/video-input-psnr-ssim/video/Megamind_bugy.avi>`. You may also find the source code and these video file in the :file:`samples/cpp/tutorial_code/highgui/video-input-psnr-ssim/` folder of the OpenCV source library.
.. literalinclude:: ../../../../samples/cpp/tutorial_code/HighGUI\video-input-psnr-ssim\video-input-psnr-ssim.cpp
.. literalinclude:: ../../../../samples/cpp/tutorial_code/HighGUI/video-input-psnr-ssim/video-input-psnr-ssim.cpp
:language: cpp
:linenos:
:tab-width: 4

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,97 @@
#include <iostream> // for standard I/O
#include <string> // for strings
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat)
#include <opencv2/highgui/highgui.hpp> // Video write
using namespace std;
using namespace cv;
void help()
{
cout
<< "\n--------------------------------------------------------------------------" << endl
<< "This program shows how to write video files. You can extract the R or G or B color channel "
<< " of the input video.write " << endl
<< "Usage:" << endl
<< "./video-write inputvideoName [ R | G | B] [Y | N]" << endl
<< "--------------------------------------------------------------------------" << endl
<< endl;
}
int main(int argc, char *argv[], char *window_name)
{
help();
if (argc != 4)
{
cout << "Not enough parameters" << endl;
return -1;
}
const string source = argv[1]; // the source file name
const bool askOutputType = argv[3][0] =='Y'; // If false it will use the inputs codec type
VideoCapture inputVideo(source); // Open input
if ( !inputVideo.isOpened())
{
cout << "Could not open the input video." << source << endl;
return -1;
}
string::size_type pAt = source.find_last_of('.'); // Find extension point
const string NAME = source.substr(0, pAt) + argv[2][0] + ".avi"; // Form the new name with container
int ex = static_cast<int>(inputVideo.get(CV_CAP_PROP_FOURCC)); // Get Codec Type- Int form
// Transform from int to char via Bitwise operators
char EXT[] = {ex & 0XFF , (ex & 0XFF00) >> 8,(ex & 0XFF0000) >> 16,(ex & 0XFF000000) >> 24, 0};
Size S = Size((int) inputVideo.get(CV_CAP_PROP_FRAME_WIDTH), //Acquire input size
(int) inputVideo.get(CV_CAP_PROP_FRAME_HEIGHT));
VideoWriter outputVideo; // Open the output
if (askOutputType)
outputVideo.open(NAME , ex=-1, inputVideo.get(CV_CAP_PROP_FPS),S, true);
else
outputVideo.open(NAME , ex, inputVideo.get(CV_CAP_PROP_FPS),S, true);
if (!outputVideo.isOpened())
{
cout << "Could not open the output video for write: " << source << endl;
return -1;
}
union { int v; char c[5];} uEx ;
uEx.v = ex; // From Int to char via union
uEx.c[4]='\0';
cout << "Input frame resolution: Width=" << S.width << " Height=" << S.height
<< " of nr#: " << inputVideo.get(CV_CAP_PROP_FRAME_COUNT) << endl;
cout << "Input codec type: " << EXT << endl;
int channel = 2; // Select the channel to save
switch(argv[2][0])
{
case 'R' : {channel = 2; break;}
case 'G' : {channel = 1; break;}
case 'B' : {channel = 0; break;}
}
Mat src,res;
vector<Mat> spl;
while( true) //Show the image captured in the window and repeat
{
inputVideo >> src; // read
if( src.empty()) break; // check if at end
split(src, spl); // process - extract only the correct channel
for( int i =0; i < 3; ++i)
if (i != channel)
spl[i] = Mat::zeros(S, spl[0].type());
merge(spl, res);
//outputVideo.write(res); //save or
outputVideo << res;
}
cout << "Finished writing" << endl;
return 0;
}