Skip to content

Commit

Permalink
fixe example 05-1
Browse files Browse the repository at this point in the history
  • Loading branch information
garybradski committed Jun 30, 2017
1 parent d07c438 commit b0e3f51
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Binary file added BlueCup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added adrian.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 26 additions & 12 deletions example_05-01.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// alphablend <imageA> <image B> <x> <y> <width> <height> <alpha> <beta>
// alphablend <imageA> <image B> <x> <y> <<alpha> <beta>
//
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
Expand All @@ -10,9 +10,12 @@ using namespace std;

void help(const char **argv) {
cout << "\n\n"
<< "This program alpha blends on image onto another \n"
<< "This program alpha blends the first image onto the other \n"
<< "alpha is the blending of the first image and beta onto the second\n"
<< "Call:\n"
<< argv[0] << " <imageA> <image B> <x> <y> <width> <height> <alpha> <beta>\n\n"
<< argv[0] << " <path/blend_this_img> <path/onto_this_img> <where_to_blend_x> <where_to_blend_y> <alpha> <beta>\n\n"
<< "Example:\n"
<< " ./example_05-01 ../faceTemplate.jpg ../faces.png 230 155 0.8 0.2\n"
<< endl;
}

Expand All @@ -21,8 +24,8 @@ void help(const char **argv) {
int main( int argc, const char** argv )
{
help(argv);
if(argc != 9) {
cout << "\nERROR: Wrong # of parameters (9), you had " << argc \n" << endl;
if(argc != 7) {
cout << "ERROR: Wrong # of parameters (7), you had " << argc << "\n" << endl;
return -1;
}

Expand All @@ -33,24 +36,35 @@ int main( int argc, const char** argv )
cv::Mat src1 = cv::imread(argv[1],1);
cv::Mat src2 = cv::imread(argv[2],1);

if( argc==9 && !src1.empty() && !src2.empty() ) {
int from_w = src1.size().width;
int from_h = src1.size().height;
int to_w = src2.size().width;
int to_h = src2.size().height;


if( argc==7 && !src1.empty() && !src2.empty() ) {

// Four more arguments tell where in src1 to paste the chunk taken from
// src2. Note that the width and height also specify what portion of
// src2 to actually use.
//
int x = atoi(argv[3]);
int y = atoi(argv[4]);
int w = atoi(argv[5]);
int h = atoi(argv[6]);

// Make sure we don't exceed bounds:
if((x < 0) || (y < 0) || (x > to_w - 1) || (y > to_h - 1) || (x+from_w > to_w - 1) || (y+from_h > to_h)) {
cout << "\nError, at (x,y) (" << x << ", " << y <<"), your input image [w,h] [" << from_w << ", "
<< from_h << "] doesn't fit within the blend to image [w,h] [" << to_w << ", " << to_h <<"]\n" << endl;
return -1;
}

// Two more arguments set the blending coefficients.
//
double alpha = (double)atof(argv[7]);
double beta = (double)atof(argv[8]);
double alpha = (double)atof(argv[5]);
double beta = (double)atof(argv[6]);

cv::Mat roi1( src1, cv::Rect(x,y,w,h) );
cv::Mat roi2( src2, cv::Rect(0,0,w,h) );
cv::Mat roi1( src1, cv::Rect(0,0,from_w - 1,from_h - 1) ); //Just take the whole thing
cv::Mat roi2( src2, cv::Rect(x,y,from_w - 1, from_h - 1) );

// Blend together the image src2 onto the image src1
// at the specified location.
Expand Down
Binary file added stuff.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b0e3f51

Please sign in to comment.