It's been a virtual reality job for one months, and our group wants to do a program like face recognition in the video stream that the camera reads and adding objects to the facial features.
of course, face recognition and so on the use of some of the existing online programs, we have to do is to load the picture in the image on the specific coordinates.
about how to overlay the picture I refer to the following two articles, if you want to do watermark, image overlay related code recommendations first look at this inside has been explained pretty clear:
Http://www.cnblogs.com/mfryf/archive/2012/03/08/2385304.html
Http://www.tuicool.com/articles/EvyEfq
* * * * There is a problem, in the reply below the first article is also mentioned, with the background transparent PNG image can not achieve a transparent effect, transparent part of the reality is white, PNG image is to use Photoshop to dig the background. After I looked around for information or something, the probable cause of the result should be the version issue. The Imread function of the OPENCV after 2.4 cannot display the fourth channel (.
This conclusion is doubtful, I also see in other articles).
However, I think Cvshowimage () can show four channels, but the Iplimage and mat format conversion and function is not common also have some difficulties, this attempt failed. Reference to a lot of places of the article and Code are not able to solve the problem, some of the head of the feeling may be unable to achieve the desired effect of the work ... But also good looking others ' articles are inspired by some, even if the version is not the same will have some problems, the use of masks should also be able to solve it.
And then holding on to try the idea of experimenting with a small program (based on the code in the previous article changed a bit). Mask masks are single-channel images and are only black and white (two values of 0 and 1), 0 are not displayed, and 1 is displayed. So I consider converting a PNG image into a grayscale image for binary processing to get a mask image. Since the background is already white, setting a threshold directly is set to 254 (because I don't know how to set it to 255).
However, the result of this threshold segmentation is to keep the background part, the target part of the value is 0, so the reverse color processing, 255 minus a bit better. Set the area of interest to find a problem (probably in the big eye is not the problem of the problem OTL), is because the logo image is also a size, so rect () in the coordinates set to calculate the size of the logo, otherwise it will exceed the boundaries of the original picture, there is memory overflow r6010
Abort () has been called problem. In fact, think of the PNG format of the image as if the image of various formats can be treated like this ...
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <cv.h>
using namespace CV;
int main () {
Mat image = Imread ("1.jpg");
Mat logo = Imread ("2.png");
Mat mask = imread ("2.png", 0); Note If the grayscale map is
threshold (mask,mask,254,255,cv_thresh_binary);
Mat mask1 = 255-mask; Mask Inverse color
//imshow ("img", MASK1);
Mat Imageroi;
Imageroi = Image (Rect (480,320,logo.cols,logo.rows));
Logo.copyto (IMAGEROI,MASK1);
Namedwindow ("result");
Imshow ("result", image);
Imwrite ("result.jpg", image);
Waitkey ();
return 0;
}
The result of processing is the following, of course, I do not follow the watermark approach to do, did not change the transparency or something ... Write this thing is to record the idea of solving problems, in fact, the code and ideas are can be perfected, mainly on the internet there is no solution to the problem (or I could not find) so hurriedly write down to save later forget .../(ㄒoㄒ)/~~
Image:
Logo
Result