eom*_*mer 7 c++ opencv image-processing
我想在我确定的坐标处将图像放在捕获的视频帧上.
我问那之前,我已被告知使用cvCopy和cvSetImageROI,但我不想裁剪这些坐标我想添加其他图像.也许这是正确的方式,但我不理解它(如果它的权利请解释).
小智 7
我刚刚使用SetRoi做过这个,就像这样.我有两个图像,一个是名为thumb_frame的缩略图,它是我将在大图像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);
Run Code Online (Sandbox Code Playgroud)
就是这样.
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用它
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.
Run Code Online (Sandbox Code Playgroud)
您必须将像素从源复制到目标。下面的代码正是这样做的,用坐标x和进行偏移y。我实际上没有尝试过这个,但我相当确定它应该或多或少地像你期望的那样工作。
只需确保目标图像至少是源图像的大小加上偏移量即可!
void drawImage(IplImage* target, IplImage* source, int x, int y) {
for (int ix=0; x<source->width; x++) {
for (int iy=0; y<source->height; y++) {
int r = cvGet2D(source, iy, ix).val[2];
int g = cvGet2D(source, iy, ix).val[1];
int b = cvGet2D(source, iy, ix).val[0];
CvScalar bgr = cvScalar(b, g, r);
cvSet2D(target, iy+y, ix+x, bgr);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18556 次 |
| 最近记录: |