#include "cv.h"
#include "highgui.h"
#include <string.h>
#define LINE 5
#define ROW 5
using namespace std;
void GetImageRect(IplImage* orgImage, CvRect rectInImage, IplImage* imgRect)
{
IplImage *result=imgRect;
CvSize size;
size.width=rectInImage.width;
size.height=rectInImage.height;
//result=cvCreateImage( size, orgImage->depth, orgImage->nChannels );
//从图像中提取子图像
cvSetImageROI(orgImage,rectInImage);
cvCopy(orgImage,result);
cvResetImageROI(orgImage);
}
int ImageBlock(char * filename)
{
int i,j;
IplImage *orgImage = cvLoadImage(filename,1);
CvSize size = cvGetSize(orgImage);
CvSize sizePart;//矩阵框大小,以像素为精度
int RowWidth,LineHeight;
int partImageID[ROW][LINE]={0};
char* folderPath="./Images/";
char filePath[50]={'0'};
char imageID[3];
printf("%d\n",size.width);
IplImage* partImage[ROW][LINE];
CvRect rectImage[ROW][LINE];
sizePart.width = size.width/LINE;
sizePart.height = size.height/ROW;
printf("%d\n",sizePart.width);
for(i=0;i<ROW;i++)
for(j=0;j<LINE;j++)
{
rectImage[i][j].x=sizePart.width*j;
rectImage[i][j].y=sizePart.height*i;
rectImage[i][j].width=sizePart.width;
rectImage[i][j].height=sizePart.height;
}
for(i=0;i<ROW;i++)
for(j=0;j<LINE;j++)
{
partImage[i][j]=cvCreateImage(sizePart,orgImage->depth,orgImage->nChannels);
}
for(i=0;i<ROW;i++)
for(j=0;j<LINE;j++)
{
GetImageRect(orgImage,rectImage[i][j],partImage[i][j]);
}
for(i=0;i<ROW;i++)
for(j=0;j<LINE;j++)
{
partImageID[i][j]=i*10+j;
}
filePath[0]='\0';
for(i=0;i<ROW;i++)
for(j=0;j<LINE;j++)
{
sprintf(filePath, ".//Images//%02d%02d.jpg", i,j);
cvSaveImage(filePath,partImage[i][j]);
}
for(i=0;i<ROW;i++)
for(j=0;j<LINE;j++)
{
cvReleaseImage(&partImage[i][j]);
}
cvReleaseImage(&orgImage);
return 0;
}
图片分块保存的C++代码,调用OpenCV实现,开发平台VS2010.rar
版权申诉
138 浏览量
2023-09-02
10:26:32
上传
评论
收藏 6KB RAR 举报
N201871643
- 粉丝: 795
- 资源: 2280