1.利用opencv实现图像滑动窗口操作

功能:利用opencv实现图像滑动窗口操作(即利用已知尺寸的窗口遍历整幅图像,形成许多子图像) 
vs2015+opencv3.1 
2016.10

函数实现

#ifndef SLIDINGWND_H_
#define SLIDINGWND_H_
//简单的滑动窗口的形成
#include<iostream>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
//基于矩形窗口的图像滑动窗口操作,返回值为滑动窗口的数目
//@src 输入图像
//@wnd 输出结果
//@wndSize 滑动窗口的大小
//@ x_percent 滑动窗口在x方向步长的百分比,x_step=x_percent*wndSize.width
//@ y_percent 滑动窗口在y方向步长的百分比,y_step=y_percent*wndSize.height
int slidingWnd(Mat& src, vector<Mat>& wnd, Size& wndSize, double x_percent, double y_percent)
{
int count = 0; //记录滑动窗口的数目
int x_step = cvCeil(x_percent*wndSize.width);
int y_step = cvCeil(y_percent*wndSize.height);
/*String wndName = "F:\\wnd\\";
char temp[1000];*/
int64 count1 = getTickCount();
double freq = getTickFrequency();
//利用窗口对图像进行遍历
for (int i = 0; i < src.cols- wndSize.width; i+=y_step)
{
for (int j = 0; j < src.rows- wndSize.height; j+=x_step)
{
Rect roi(Point(j, i), wndSize);
Mat ROI = src(roi);
wnd.push_back(ROI);
count++;
}
}
int64 count2 = getTickCount();
double time = (count2 - count1) / freq;
cout << "Time=" << time * 100 << "ms"<<endl;
cout << count << endl;
return count;
}
main.cpp

#include<iostream>
#include<opencv2\opencv.hpp>
#include"slidingWnd.h"
using namespace std;
using namespace cv; void main()
{
String imgName = "F:\\lena_gray.jpg";
Mat src = imread(imgName);
cvtColor(src, src, COLOR_RGB2GRAY); vector<Mat> wnd;
int count=slidingWnd(src, wnd, Size(30, 30),0.3,0.3);
imshow("src", src);
waitKey(0);

原文链接:http://blog.csdn.net/jiamuju84/article/details/52893320

2.matlab滑动窗口截取图片并保存

该代码的作用是对图片进行滑动截取保存

clc;
clear all; maindir = 'D:\MyDataSet\airplane\wheel\JPEGImages';
sundir = fullfile( maindir, '*.jpg' );
images = dir(sundir);% 在这个子文件夹下找后缀为jpg的文件
% 遍历每张图片
for j = 1 : length( images )
imagepath = fullfile( maindir,images( j ).name )
imgdata = imread( imagepath ); % 这里进行你的读取操作
new_folder = strcat('F:\matlab\tools\output\',num2str(j))
mkdir(new_folder); %num1,num2是你要设定的矩形框长和宽
num1=375;
num2=500;
[m,n,ch]=size(imgdata);
mm=m-num1;
nn=n-num2;
filenum=1;
for k=1:100:mm
for kk=1:100:nn
B=imgdata(k:k+num1,kk:kk+num2,:)
imshow(B);
% file = ['.\output\',num2str(floor((k+kk-1)/10)),'.jpg'];
file = [new_folder,'\',num2str(filenum),'.jpg'];
filenum=filenum+1;
imwrite(B,file);
if (kk+num2)>=n
break;
end
if (k+num1)>=m
break;
end
end
end
end 原文链接:http://blog.csdn.net/run_it_faraway/article/details/76862506

最新文章

  1. VS2013快捷键及技巧
  2. Jquery中的(function($){...})(jQuery)
  3. 解决Windows 8系统假死的方法
  4. Winform中进行MD5加密
  5. php--字符串函数分类总结
  6. 函数 swift
  7. TCP包头
  8. Lamda和Linq语法对比详细
  9. DropdownList控件绑定数据源显示system.data.datarowview的问题
  10. Oracle不能导入空表解决方案
  11. python 之 yield表达式
  12. js精要之对象属性
  13. mysql for windows(服务器)上的配置安装--实例
  14. PyQt4 的事件与信号 -- 重写事件处理方法
  15. HOG算法资源备忘
  16. springmvc组件--ViewResolver
  17. Git使用—第二讲
  18. item 12: 把重写函数声明为“override”的
  19. Laravel 5.x 启动过程分析
  20. JS替换地址栏参数值

热门文章

  1. 操作系统: 二级文件夹文件系统的实现(c/c++语言)
  2. luogu3358 最长k可重区间集问题 网络流
  3. 蓝桥杯--2011--购物券(dfs)
  4. RMAN 备份与恢复 实例
  5. 【区间DP】释放囚犯
  6. POJ 1149 PIGS (AC这道题很不容易啊)网络流
  7. Java算法——求出两个字符串的最长公共字符串
  8. 【HTTP】如何正常关闭连接
  9. opengl使用FreeType绘制字体
  10. 【JSP】简单登陆界面