/* License:
Oct. 3, 2008
Right to use this code in any way you want without warrenty, support or any guarentee of it working.
BOOK: It would be nice if you cited it:
Learning OpenCV: Computer Vision with the OpenCV Library
by Gary Bradski and Adrian Kaehler
Published by O'Reilly Media, October 3, 2008
AVAILABLE AT:
http://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134
Or: http://oreilly.com/catalog/9780596516130/
ISBN-10: 0596516134 or: ISBN-13: 978-0596516130
OTHER OPENCV SITES:
* The source code is on sourceforge at:
http://sourceforge.net/projects/opencvlibrary/
* The OpenCV wiki page (As of Oct 1, 2008 this is down for changing over servers, but should come back):
http://opencvlibrary.sourceforge.net/
* An active user group is at:
http://tech.groups.yahoo.com/group/OpenCV/
* The minutes of weekly OpenCV development meetings are at:
http://pr.willowgarage.com/wiki/OpenCV
*/
#include <iostream>
using namespace std;
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "highgui.h"
using namespace cv;
//图片有121幅图
//选取第61, 71, 81, 91幅图
//将第61幅图和其他三个融合
//第61幅图是红图,其他三个是蓝图
string name[] = {"p1010799", "IMG_3633", "IMG_7645"};
int num = 3;
void getRb(string name)
{
//string name = "test";
Mat a61;
Mat a71;
Mat a81;
Mat a91;
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
//CvCapture* capture = cvCaptureFromAVI( argv[1] ); // either one will work
CvCapture* capture = cvCreateFileCapture( ("avi/"+name+".avi").c_str() );
IplImage* frame;
int i = 0;
while(1) {
i++;
frame = cvQueryFrame( capture );
if (i == 61)
{
a61 = Mat(frame->height, frame->width, CV_8UC3, Scalar::all(0));
for (int j = 0; j< a61.rows; j++)
{
for (int k = 0; k< a61.cols; k++)
{
uchar *tmp = (uchar *)(frame->imageData+j*frame->widthStep);
a61.at<Vec3b>(j, k) = Vec3b(tmp[k*3+0], tmp[k*3+1], tmp[k*3+2]);
}
}
}
if (i == 71)
{
a71 = Mat(frame->height, frame->width, CV_8UC3, Scalar::all(0));
for (int j = 0; j< a61.rows; j++)
{
for (int k = 0; k< a61.cols; k++)
{
uchar *tmp = (uchar *)(frame->imageData+j*frame->widthStep);
a71.at<Vec3b>(j, k) = Vec3b(tmp[k*3+0], tmp[k*3+1], tmp[k*3+2]);
}
}
}
if (i == 81)
{
a81 = Mat(frame->height, frame->width, CV_8UC3, Scalar::all(0));
for (int j = 0; j< a61.rows; j++)
{
for (int k = 0; k< a61.cols; k++)
{
uchar *tmp = (uchar *)(frame->imageData+j*frame->widthStep);
a81.at<Vec3b>(j, k) = Vec3b(tmp[k*3+0], tmp[k*3+1], tmp[k*3+2]);
}
}
}
if (i == 91)
{
a91 = Mat(frame->height, frame->width, CV_8UC3, Scalar::all(0));
for (int j = 0; j< a61.rows; j++)
{
for (int k = 0; k< a61.cols; k++)
{
uchar *tmp = (uchar *)(frame->imageData+j*frame->widthStep);
a91.at<Vec3b>(j, k) = Vec3b(tmp[k*3+0], tmp[k*3+1], tmp[k*3+2]);
}
}
}
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(1);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
//imshow("a61", a61);
//waitKey();
//imshow("a61", a71);
//waitKey();
//imshow("a61", a81);
//waitKey();
//imshow("a61", a91);
//waitKey();
for (int j = 0; j< a61.rows; j++)
{
for (int k = 0; k< a61.cols; k++)
{
a71.at<Vec3b>(j, k)[2] = a61.at<Vec3b>(j, k)[2];
}
}
for (int j = 0; j< a61.rows; j++)
{
for (int k = 0; k< a61.cols; k++)
{
a81.at<Vec3b>(j, k)[2] = a61.at<Vec3b>(j, k)[2];
}
}
for (int j = 0; j< a61.rows; j++)
{
for (int k = 0; k< a61.cols; k++)
{
a91.at<Vec3b>(j, k)[2] = a61.at<Vec3b>(j, k)[2];
}
}
i = 0;
stringstream ss1;
ss1<<i+1;
string rbname1 = "avi/"+name+ "_" + ss1.str() + ".png";
imwrite( rbname1, a71);
i = 1;
stringstream ss2;
ss2<<i+1;
string rbname2 = "avi/"+name+ "_" + ss2.str() + ".png";
imwrite( rbname2, a81);
i = 2;
stringstream ss3;
ss3<<i+1;
string rbname3 = "avi/"+name+ "_" + ss3.str() + ".png";
imwrite( rbname3, a91);
}
int main()
{
for (int i = 0; i< num; i++)
{
getRb(name[i]);
}
return 0;
}