您的位置:首页 > 其它

按照50%重合区域,在横纵方向上截多幅图组成二维图像数组

2016-10-09 08:30 211 查看
// 使用ROI来截图
// 左上点是原点
//

#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include "cxcore.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
IplImage* src = cvLoadImage("Penguins.jpg");

cout<<"please input the number of the x-axis partiton: ";
int parx(0);cin>>parx;
cout<<"please input the number of the y-axis partiton: ";
int pary(0);cin>>pary;
cout<<endl;

int width = src->width; int height = src->height;

int half_width = width/(parx+1);
int full_width = 2*half_width;
int half_height = height/(pary+1);
int full_height =2*half_height;
CvRect rect;
int count(0);

char pa[50] = {NULL};

for(int j=0;j<pary;j++)
{
for(int i=0;i<parx;i++)
{
rect = cvRect( i*half_width, j*half_height, full_width, full_height);

cvSetImageROI(src,rect);
sprintf(pa,"%d.jpg",1+i+j*parx);
cvSaveImage(pa,src);
count++;
}
}

cvResetImageROI(src);
cvReleaseImage(&src);
cout<<"finished!total number of sub_pictures is"<<count<<endl;

return 0;
}


说明:

将一副图划分为几幅等大小的小图
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: