代码备份:椭圆轨迹

 已改为:圆形目标+5*5均值滤波模糊处理

存在问题:以Y轴为自变量(表示观测远近);会产生突变

clc;
clear;
close all;

I=imread('black_image.bmp');
I=rgb2gray(I);
[m,n]=size(I);%m是行数,高
a=floor(n-20)/2;%长轴长度
b=1;%短轴长度
num=0;
w2=fspecial('average',[5 5]);
for i=1:2
for y=1:-0.01:0
     x=sqrt(a^2*(1-y^2/b^2));
     r=ceil(3+2*y);
    for t=0:pi/20:2*pi;
     cx= r*cos(t); % x 轴数据
     cy= r*sin(t); % y 轴数据
     I(-cx+m/2:1:cx+m/2,-cy+x+m/2:1:cy+x+m/2)=155+100*y; 
    end
     I=imfilter(I,w2); 
     %imshow(I);
     str=num2str(num);
     imwrite(I,['video\',str,'.bmp']);
     I(:,:)=0;%覆盖前一帧
     num=num+1;
end

for y=0:-0.01:-1
     x=sqrt(a^2*(1-y^2/b^2));
     r=ceil(3+2*y);
    for t=0:pi/20:2*pi;
     cx= r*cos(t); % x 轴数据
     cy= r*sin(t); % y 轴数据
     I(-cx+m/2:1:cx+m/2,-cy+x+m/2:1:cy+x+m/2)=155+100*y; 
    end
    I=imfilter(I,w2); 
    % imshow(I);
     str=num2str(num);
     imwrite(I,['video\',str,'.bmp']);
     I(:,:)=0;
     num=num+1;
end

for y=-1:0.01:0
     x=-sqrt(a^2*(1-y^2/b^2));
     r=ceil(3+2*y);
     for t=0:pi/20:2*pi;
          cx= r*cos(t); % x 轴数据
          cy= r*sin(t); % y 轴数据
          I(-cx+m/2:1:cx+m/2,-cy+x+m/2:1:cy+x+m/2)=155+100*y; 
     end
     I=imfilter(I,w2); 
     %imshow(I);
     str=num2str(num);
     imwrite(I,['video\',str,'.bmp']);
     I(:,:)=0;
     num=num+1;
end

for y=0:0.01:1
     x=-sqrt(a^2*(1-y^2/b^2));
     r=ceil(3+2*y);
         for t=0:pi/20:2*pi;
          cx= r*cos(t); % x 轴数据
          cy= r*sin(t); % y 轴数据
          I(-cx+m/2:1:cx+m/2,-cy+x+m/2:1:cy+x+m/2)=155+100*y; 
         end
     I=imfilter(I,w2); 
     %imshow(I);
     str=num2str(num);
     imwrite(I,['video\',str,'.bmp']);
     I(:,:)=0;
     num=num+1;
     i=i+1;
end

end
path = 'video\';                  %'whiteCar2\'为当前目录下的whiteCar2文件夹
writerObj = VideoWriter('target.avi');   %将生成的视频保存为名称为'car.avi'的视频
open(writerObj);
for i = 0:num-10
   frame = imread(strcat(path,num2str(i),'.bmp'));%从文件夹中读取图像
   writeVideo(writerObj,frame);
end
close(writerObj);

 后半段改为存成MP4型视频文件:

path = 'video\';                  %'whiteCar2\'为当前目录下的whiteCar2文件夹
writerObj = VideoWriter('target','MPEG-4');  %将生成的视频保存为名称为'target.mp4'的视频
open(writerObj);
for i = 0:num-10
   frame = imread(strcat(path,num2str(i),'.bmp'));%从文件夹中读取图像
   writeVideo(writerObj,frame);
end
close(writerObj);

 

posted @ 2018-09-04 16:16  ostartech  阅读(208)  评论(0编辑  收藏  举报