#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"highgui.lib")
#pragma comment(lib,"ml.lib")
#pragma comment(lib,"cvcam.lib")
#pragma comment(lib,"cvaux.lib")
#include <stdio.h>
#include <iostream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
int main()
{
//头像替换
IplImage* img=cvLoadImage("img//big.jpg");
IplImage* sub_img=cvLoadImage("img//sub.jpg");
CvRect rect;
rect.x=190;
rect.y=10;
rect.width=sub_img->width;
rect.height=sub_img->height;
//自定义算法 实现方式
for (int y=0;y<sub_img->height;y++)
{
unsigned char* r_subimg=(uchar*)(sub_img->imageData + y*sub_img->widthStep);
unsigned char* r_img=(uchar*)(img->imageData + (y + rect.y)* img->widthStep);
for (int x=0;x<sub_img->width;x++)
{
//
r_img[3*(x+rect.x) + 0]=r_subimg[3*x + 0];
r_img[3*(x+rect.x) + 1]=r_subimg[3*x + 1];
r_img[3*(x+rect.x) + 2]=r_subimg[3*x + 2];
}
}
//利用opencv函数实现
// cvSetImageROI(img,rect);//ROI 感兴趣区域
// cvCopy(sub_img,img);
// cvResetImageROI(img);
cvNamedWindow("big");
cvShowImage("big",img);
// cvNamedWindow("sub");
// cvShowImage("sub",sub_img);
cvWaitKey(0);
return 0;
}
感兴趣区域ROI 和 替换算法
最新推荐文章于 2023-08-10 10:36:37 发布