Skip to content

Commit

Permalink
added example_15-01.cpp and test.avi and tree.avi
Browse files Browse the repository at this point in the history
  • Loading branch information
garybradski committed May 22, 2017
1 parent 1ccb486 commit e3094b6
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ add_executable( example_09-03 example_09-03.cpp )
add_executable( example_10-01 example_10-01.cpp )
add_executable( example_10-02 example_10-02.cpp )
add_executable( example_10-03 example_10-03.cpp )
#...
add_executable( example_11-01 example_11-01.cpp )
add_executable( example_11-02 example_11-02.cpp )
add_executable( example_11-03 example_11-03.cpp )
Expand All @@ -46,6 +45,8 @@ add_executable( example_14-01 example_14-01.cpp )
add_executable( example_14-02 example_14-02.cpp )
add_executable( example_14-03 example_14-03.cpp )
add_executable( example_14-04 example_14-04.cpp )
add_executable( example_15-01 example_15-01.cpp )
#...
add_executable( example_16-01 example_16-01.cpp )

target_link_libraries( example_02-01 ${OpenCV_LIBS} )
Expand Down Expand Up @@ -76,7 +77,6 @@ target_link_libraries( example_09-03 ${OpenCV_LIBS} )
target_link_libraries( example_10-01 ${OpenCV_LIBS} )
target_link_libraries( example_10-02 ${OpenCV_LIBS} )
target_link_libraries( example_10-03 ${OpenCV_LIBS} )
# ...
target_link_libraries( example_11-01 ${OpenCV_LIBS} )
target_link_libraries( example_11-02 ${OpenCV_LIBS} )
target_link_libraries( example_11-03 ${OpenCV_LIBS} )
Expand All @@ -89,4 +89,6 @@ target_link_libraries( example_14-01 ${OpenCV_LIBS} )
target_link_libraries( example_14-02 ${OpenCV_LIBS} )
target_link_libraries( example_14-03 ${OpenCV_LIBS} )
target_link_libraries( example_14-04 ${OpenCV_LIBS} )
target_link_libraries( example_15-01 ${OpenCV_LIBS} )
#...
target_link_libraries( example_16-01 ${OpenCV_LIBS} )
66 changes: 66 additions & 0 deletions example_15-01.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//Example 15-1. Reading out the RGB values of all pixels in one row of a video and
// accumulating those values into three separate comma separated files
//
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>

using namespace std;

void help(char** argv ) {
cout << "\n"
<< "Read out RGB pixel values and store them to disk\nCall:\n"
<< argv[0] <<" avi_file\n"
<< "\n This will store to files blines.csv, glines.csv and rlines.csv\n\n"
<< endl;
}

int main( int argc, char** argv) {
// Argument handling
//
if(argc != 2) { help(argv); return -1; }
cv::namedWindow( argv[0], CV_WINDOW_AUTOSIZE );
cv::VideoCapture cap;
if((argc < 2)|| !cap.open(argv[1]))
{
cerr << "Couldn't open video file" << endl;
help(argv);
cap.open(0);
return -1;
}

//Prepare Output
//
cv::Point pt1(10,10), pt2(30,30);
int max_buffer;
cv::Mat rawImage;
ofstream b,g,r;
b.open("blines.csv");
g.open("glines.csv");
r.open("rlines.csv");

// MAIN PROCESSING LOOP:
//
for(;;) {
cap >> rawImage;
if( !rawImage.data ) break;
cv::LineIterator it( rawImage, pt1, pt2, 8);
for( int j=0; j<it.count; ++j,++it ) {
b << (int)(*it)[0] << ", ";
g << (int)(*it)[1] << ", ";
r << (int)(*it)[2] << ", ";
(*it)[2] = 255; // Mark this sample in red
}
cv::imshow( argv[0], rawImage );
int c = cv::waitKey(10);
b << "\n"; g << "\n"; r << "\n";
}

// CLEAN UP:
//
b << endl; g << endl; r << endl;
b.close(); g.close(); r.close();
cout << "\n"
<< "Data stored to files: blines.csv, glines.csv and rlines.csv\n\n"
<< endl;
}
Binary file added test.avi
Binary file not shown.
Binary file added tree.avi
Binary file not shown.

0 comments on commit e3094b6

Please sign in to comment.