您的位置:首页 > 编程语言 > MATLAB

matlab中批量读取图像序列并进行简单目标跟踪

2017-09-19 10:53 1176 查看
File=dir('D:\Desktop\图像采集文件夹\test\450\*.bmp'); %读取该路径下的全部bmp图片

img_num = length(File);%获取图像总数量

n=0;

if img_num > 0 %有满足条件的图像

        for j = 1:img_num %逐一读取图像

            image_name = File(j).name;% 图像名

            image =  imread(strcat('D:\Desktop\图像采集文件夹\test\450\',image_name));%读入一张图像

            A1_bw=im2bw(image,graythresh(image));

            se1=strel('disk',3);

            A1_open=imopen(A1_bw,se1);

            A1_max=maxLianTongYu(A1_bw);               %最大连通区域

            D=regionprops(A1_max,'Centroid');          %求取到的质心,D是struct结构体,注意

            xCircle=D.Centroid(1);yCircle=D.Centroid(2);  %提取质心坐标

            imagedouble=im2double(image);

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%             image1=A1_max.*imagedouble; %620nm的时候用,截取单个右边的圆

            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

            hold on;                                    %在原图上标注跟踪圈

            imshow(image);

            hold on

            Circle( xCircle,yCircle,70);

            hold off

            F=getframe(gcf); % 获取整个窗口内容的图像,使得跟踪的框框也进入图里边,F是个结构体了

            n=n+1;

            F1=imcrop(F.cdata,[83 31 624 528]);   %需要减掉显示窗口周边的白晕

            image_name_out=sprintf('%d.bmp',n);%给图片名称进行变量定义

            imwrite(F1,strcat('D:\Desktop\图像采集文件夹\test\450out\',image_name_out));%批量写入图片

        end
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: