White bottom + transparent bottom map

Source: Internet
Author: User

<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

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.