<pre name= "code" class= "CPP" >//white, when traversing pixels, if white, then ignore, otherwise copy the pixel value to the background//because the target picture may contain white dots, and the key out of the picture requirements are very high, otherwise it will appear the effect of the second picture , so the limitations of this approach are large.
Mat hero = Imread ("2.jpg"), for (int i = 0, i < hero.rows; i++) {for (int j = 0; J < Hero.cols; J + +) {int a = HERO.AT&L T Vec3b> (i, j) [2];int B = hero.at<vec3b> (i, j) [1];int C = hero.at<vec3b> (i, J) [0];if (!) [ A = = 255 && b = = 255 && c = 255)) {background.at<vec3b> (i + pos_x, j + pos_y) [2] = hero.at<vec3b& gt; (i, J) [2];background.at<vec3b> (i + pos_x, j + pos_y) [1] = Hero.at<vec3b> (i, j) [1];background.at<vec3b > (i + pos_x, j + pos_y) [0] = hero.at<vec3b> (i, J) [0];}}}
The transparent bottom is not affixed, the alpha value is judged by saving the picture to a PNG format containing four channels! =0, non-stick transparent bottom
Mat background = Imread ("back.jpg"); Mat hero = Imread ("2.png", -1), for (int i = 0; i < hero.rows; i++) {for (int j = 0; J < Hero.cols; J + +) {int a = HERO.A T<vec3b> (i, j) [2];int B = hero.at<vec3b> (i, j) [1];int C = hero.at<vec3b> (i, J) [0];if (hero.at<vec4b > (i, j) [3] !=0) {background.at<vec3b> (i + pos_x, j + pos_y) [2] = Hero.at<vec4b> (i, J) [2]; Background.at<vec3b> (i + pos_x, j + pos_y) [1] = Hero.at<vec4b> (i, J) [1];background.at<vec3b> (i + pos_x , j + pos_y) [0] = hero.at<vec4b> (i, J) [0];}}}
Put a target object on the selected background here are two ways to do this, in fact the same.
Using the key drawing software to key out the image, the first is to have a picture on a white background, the second is a transparent background, the effect is as follows:
White bottom + transparent bottom map