ROI Region Image Overlay & primary image Blending Synthesis example

Source: Internet
Author: User

Encapsulating the addweighted function and the ROI function into the roi_linearblending

//---------------------------------"roi_linearblending ()"-------------------------------------//function Name: roi_linearblending ()//Description: Linear mixed Implementation function that specifies the region linear image blending. Use the cv::addweighted () function to define//ROI for area of interest, for linear blending of custom regions//-------------------------------------------------------------------------------------------- BOOLroi_linearblending () {//"1" reads the imageMat srcimage4= Imread ("dota_pa.jpg",1); Mat Logoimage= Imread ("dota_logo.jpg"); if(!srcimage4.data) {printf ("Read SrcImage4 Error! \ n");return false; } if(!logoimage.data) {printf ("Read Logoimage Error! \ n");return false; } //"2" defines a mat type and sets the ROI area for itMat Imageroi; //Method OneImageroi=srcimage4 (Rect ( $, -, logoimage.cols,logoimage.rows)); //Method Two//imageroi=srcimage4 (Range (250,250+logoimage.rows), Range (200,200+logoimage.cols)); //"3" Add the logo to the originalAddweighted (Imageroi,0.5, Logoimage,0.3,0., Imageroi); //"4" Display resultsNamedwindow ("<1> Regional linear image blending sample window"); Imshow ("<1> Regional linear image blending sample window", SrcImage4); return true; }

#include <cv.h>#include#include<iostream>//-----------------------------------the Namespace Declarations section---------------------------------------//Description: Contains the namespace used by the program//-----------------------------------------------------------------------------------------------    using namespaceCV; using namespacestd; //-----------------------------------the Global Function declaration Section--------------------------------------//Description: global function Declaration//-----------------------------------------------------------------------------------------------  BOOLRoi_addimage (); BOOLlinearblending (); BOOLroi_linearblending (); //-----------------------------------the main () function--------------------------------------------//Description: The entry function of the console application, our program starts here//-----------------------------------------------------------------------------------------------  intMain () {System ("Color 5E"); if(Roi_addimage () && linearblending () &&roi_linearblending ()) {cout<<endl<<"uh. OK, I got the image you need! : )"; } waitkey (0); return 0; }     //----------------------------------the Roi_addimage () function----------------------------------//function Name: Roi_addimage ()//Description: Image overlay with ROI in region of interest//----------------------------------------------------------------------------------------------  BOOLRoi_addimage () {//"1" read in imageMat srcimage1= Imread ("Anne. jpg"); Mat Logoimage= Imread ("Lol.jpg"); if(!srcimage1.data) {printf ("your sister, read SRCIMAGE1 Error! \ n");return false; } if(!logoimage.data) {printf ("your sister, read Logoimage Error! \ n");return false; } //"2" defines a mat type and sets the ROI area for itMat imageroi= SrcImage1 (Rect ( -, -, logoimage.cols,logoimage.rows)); //"3" load mask (must be a grayscale image)Mat mask= Imread ("dota_logo.jpg",0); //"4" copies the mask to ROILogoimage.copyto (Imageroi,mask); //"5" Display resultsNamedwindow ("<1> using ROI to implement Image Overlay sample window"); Imshow ("<1> using ROI to implement Image Overlay sample window", SrcImage1); return true; }        //---------------------------------the linearblending () function-------------------------------------//function Name: linearblending ()//Description: Using the cv::addweighted () function to achieve linear image blending//--------------------------------------------------------------------------------------------  BOOLlinearblending () {//"0" defines some local variables       DoubleAlphavalue =0.5; DoubleBetavalue;            Mat SrcImage2, SrcImage3, dstimage; //"1" read the image (two images must be of the same type and size)Srcimage2= Imread ("Big Chill. jpg"); SrcImage3= Imread ("Xiaohan. jpg"); if(!srcimage2.data) {printf ("Read SrcImage2 Error! \ n");return false; } if(!srcimage3.data) {printf ("Read SrcImage3 Error! \ n");return false; } //"2" for image blending weighted operationBetavalue= (1.0-alphavalue); Addweighted (SrcImage2, Alphavalue, SrcImage3, Betavalue,0.0, Dstimage); //"3" creates and displays the original windowNamedwindow ("<2> Linear Mixing Example Window "original"",1); Imshow ("<2> Linear Mixing Example Window "original"", SrcImage2); Namedwindow ("<3> Linear Mixed Sample window """,1); Imshow ("<3> Linear Mixed Sample window """, Dstimage); return true; }     //---------------------------------"roi_linearblending ()"-------------------------------------//function Name: roi_linearblending ()//Description: Linear mixed Implementation function that specifies the region linear image blending. Use the cv::addweighted () function to define//ROI for area of interest, for linear blending of custom regions//--------------------------------------------------------------------------------------------  BOOLroi_linearblending () {//"1" reads the imageMat srcimage4= Imread ("Anne. jpg",1); Mat Logoimage= Imread ("lol.jpg"); if(!srcimage4.data) {printf ("Read SrcImage4 Error! \ n");return false; } if(!logoimage.data) {printf ("Read Logoimage Error! \ n");return false; } //"2" defines a mat type and sets the ROI area for itMat Imageroi; //Method OneImageroi=srcimage4 (Rect ( -, -, logoimage.cols,logoimage.rows)); //"3" Add the logo to the originalAddweighted (Imageroi,0.5, Logoimage,0.3,0., Imageroi); //"4" Display resultsNamedwindow ("<4> Regional linear image blending sample window"); Imshow ("<4> Regional linear image blending sample window", SrcImage4); return true; }

The first is the console window modified by the background color:

Then there are four, in turn:

ROI Region Image Overlay & primary image Blending Synthesis example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.