资源简介
MATLAB代码,实现背景减除目标检测,并判断鱼头朝向,鱼头截取
代码片段和文件信息
function [ZnumOfFishes] = video2Z(videograyThresholdareaThresholdhandles)
seqName = handles.seqName;
load([seqName‘/‘seqName‘_background.mat‘]‘background‘);
background = double(background);
totalframes = video.NumberOfframes;
tam = [video.Heightvideo.Width];
X = repmat(1:tam(2)[tam(1) 1]);%处理大矩阵:以1:tam(2)的矩阵内容堆叠在[tam(1) 1]中,最终矩阵大小1*tam(1):tam(2)*1
Y = repmat((1:tam(1))‘[1 tam(2)]);
% alloct space
Z = struct(‘centerCoor‘[]‘imageCroped‘[]);
Z(1totalframes).centerCoor = [];
numOfFishes = 0;
% folder = ‘OriginalPic‘;
% if ~exist(folder‘dir‘)
% dos([‘mkdir ‘folder]);
% end
meanValue = [];
for frame_act=1:totalframes %num
set(handles.txtInfo‘String‘[‘video2Z: ‘ num2str(frame_act) ‘/‘ num2str(totalframes)]);
% disp([‘video2Z: ‘ num2str(frame_act) ‘/‘ num2str(totalframes)]);
frame=read(videoframe_act);
if size(frame3)==3
frame =rgb2gray(frame);
end
if isempty(meanValue)
meanValue = mean(mean(frame));
end
frame(frame>meanValue + 10) = meanValue + 10;
frame_doub=double(frame); %视频大小
imgFilter2D=abs(frame_doub-background)>grayThreshold;%灰度阈值
% 椭圆拟合
manchas=bwconncomp(imgFilter2D); %背景减除算法得到目标数量
tams=cellfun(@(x) length(x)manchas.PixelIdxList);%求元胞数组manchas.PixelIdxList每个元胞的长度:length(x)
% 筛选面积大于 areaThreshold 的部分
listapixels=manchas.PixelIdxList(tams > areaThreshold);
if length(listapixels)>numOfFishes
numOfFishes = length(listapixels);
end
for c_buenos=1:length(listapixels)
imgFilter2D=false(manchas.ImageSize);%生成逻辑0矩阵
imgFilter2D(listapixels{c_buenos})=true;%返回值为1
% ind=find(imgFilter2D); %返回非零元素所在位置
x = X(imgFilter2D);
y = Y(imgFilter2D);
lim=[min(x) max(x) min(y) max(y)];
[coorXcoorY~~thetaaxisLongaxisShort]=minOuterRect(imgFilter2D0);
Z(frame_act).centerCoor(:c_buenos)= [sum(coorX(1:4:))/4sum(coorY(1:4:))/4]; % 中心坐标
if axisLong/axisShort >3
%% 计算鱼头的方向
[nRownCol~] =
- 上一篇:matlab实现文件读写波形处理,小波变换
- 下一篇:布谷鸟算法的matlab代码
相关资源
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
- k近邻算法matlab实现
- matlab识别系统
- 神经网络分类matlab程序
- matlab正弦信号发生器的设计
- matlab程序用Hopfield网络解决TSP
- 实例matlab 编程100个常用程序
- 用MATLAB(BPSK仿真 直接扩频)
评论
共有 条评论