/*
Author:Duyang
Data: 2018.10.25
Object:cutting patches-images from only one satellit image
*/
# define _CRT_SECURE_NO_DEPRECATE
# include<iostream>
# include<opencv.hpp>
# include<string>
# include<stdio.h>
using namespace std;
using namespace cv;
# define image_row 500//define the resolution of row and col;
# define image_col 500
void int_to_str(const int &int_temp, string &string_temp)
{
stringstream stream;
stream << int_temp;
string_temp = stream.str();
}
int main()
{
Mat source;
source = imread("C:\\Users\\93970\\Desktop\\conv5x5 300张训练结果\\cut.tif",1);
string path = "C:\\Users\\93970\\Desktop\\1000x1000\\";//the path of cut images
string image_name;
string l,h;//the necessity of int 2 string
int num=0;
for (int H = 1; H <= source.rows / image_row; H++)//the number of patches original image can produce;
{
int_to_str(H, h);
for (int L = 1; L<= source.cols / image_col; L++)//the number of patches original image can produce;
{
int_to_str(L, l);
Mat image(image_row, image_col, CV_8UC3);//creat the NULL images
for (int row = (H - 1)*image_row; row<H*image_row; row++)
{
Vec3b *p1 = image.ptr<Vec3b>(row - (H - 1)*image_row);
Vec3b *p = source.ptr<Vec3b>(row);
for (int col = (L - 1)*image_col; col<image_col*L; col++)
{
*(p1 + col - (L - 1)*image_col) = *(p + col);
}
}
//imshow(image_name, image);
//waitKey(0);
imwrite(path + h + "_" + l + ".png", image);
num++;
printf("第%4d张\n", num);
}
}
printf("共计%d张影像",num);
getchar();
return 0;
}
从一张影像中批量裁剪子影像
猜你喜欢
转载自blog.csdn.net/qq_33661910/article/details/85059840
今日推荐
周排行