I want to place an image on a captured video frame at the coordinates which I determined.
I asked that before and I have been told to use cvCopy
and cvSetImageROI
but I dont want to crop on those coordinates I want to add another image.
Maybe it's the right way but I didn't understand it (if its right please explain it).
How to Insert an Image in HTML. To insert an image in HTML, use the image tag and include a source and alt attribute. Like any other HTML element, you'll add images to the body section of your HTML file. The HTML image element is an “empty element,” meaning it does not have a closing tag.
You can easily put a photo on top of another photo using Fotor, a free online photo editor. Simply drag and drop the image you want to overlay into Fotor- this will become your background picture. Then add a new image over it. You can adjust the transparency levels to blend two images together perfectly.
I did this a while ago using SetRoi, it was something like this. I have two images, one is a thumbnail called thumb_frame that is the small picture I will include in the large image show_frame
//I set the ROI to the same size as the thumb_frame
cvSetImageROI(show_frame.image, cvRect(thumbnail_x_pos,
thumbnail_y_pos, thumb_frame->width, thumb_frame->height));
//I add the image to the designated ROI
cvAddWeighted(thumb_frame, alpha, show_frame, beta, 0, show_frame);
That's about it.
void cvOverlayImage(IplImage* src, IplImage* overlay, CvPoint location, CvScalar S, CvScalar D)
{
int x,y,i;
for(x=0;x < overlay->width -10;x++)
//replace '-10' by whatever x position you want your overlay image to begin.
//say '-varX'
{
if(x+location.x>=src->width) continue;
for(y=0;y < overlay->height -10;y++)
//replace '-10' by whatever y position you want your overlay image to begin.
//say '-varY'
{
if(y+location.y>=src->height) continue;
CvScalar source = cvGet2D(src, y+location.y, x+location.x);
CvScalar over = cvGet2D(overlay, y, x);
CvScalar merged;
for(i=0;i<4;i++)
merged.val[i] = (S.val[i]*source.val[i]+D.val[i]*over.val[i]);
cvSet2D(src, y+location.y, x+location.x, merged);
}
}
}
To use it
cvOverlayImage(largerimage, overlayimage, cvPoint(10, 10), cvScalar(0.5,0.5,0.5,0.5), cvScalar(0.5,0.5,0.5,0.5));
//The cvPoint(10,10) can be the cvPoint(varX,varY) depending on how you write the function
//and how you want to use it.
//You cannot choose values less than 'varX' and 'varY' in this case
//else you would see a runtime error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With