c++ - Copy / blend images of different sizes using opencv -


i trying blend 2 images. easy if have same size, if 1 of images smaller or larger cv::addweighted fails.

image (expected larger) image b (expected smaller)

i tried create roi - tried create third image of size of , copy b inside - can't seem right. please help.

double alpha = 0.7; // int min_x = ( a.cols - b.cols)/2 ); int min_y = ( a.rows - b.rows)/2 ); int width, height; if(min_x < 0) {   min_x = 0; width = (*input_images).at(0).cols - 1; } else         width = (*input_images).at(1).cols - 1; if(min_y < 0) {   min_y = 0; height = (*input_images).at(0).rows - 1; } else         height = (*input_images).at(1).rows - 1; cv::rect roi = cv::rect(min_x, min_y, width, height);             cv::mat larger_image(a); // not sure how copy b roi, or if necessary... , keep images same size cv::addweighted( larger_image, alpha, a, 1-alpha, 0.0, out_image, a.depth()); 

even cvsetimageroi - may work can't find c++ equivalent - may - don't know how use still keep image content, place image inside roi...

// min_x, min_y should valid in , [width height] = size(b) cv::rect roi = cv::rect(min_x, min_y, b.cols, b.rows);    // "out_image" output ; i.e. part of blended b cv::mat out_image = a.clone();  // set rois selected sections of , out_image (the same @ moment) cv::mat a_roi= a(roi); cv::mat out_image_roi = out_image(roi);  // blend roi of b roi of out_image cv::addweighted(a_roi,alpha,b,1-alpha,0.0,out_image_roi); 

note if want blend b directly a, need roi.

cv::addweighted(a(roi),alpha,b,1-alpha,0.0,a(roi)); 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -

Does Firefox offer AppleScript support to get URL of windows? -