



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Edge DetectionThis demo uses the Computer Vision System Toolbox System objects to find the edges of objects in a video stream.IntroductionThis demo illustrates how to use the EdgeDetector System object to identify the edges of objects in a video stream using the Prewitt method. The demo also shows the use of the AlphaBlender System object to overlay the edges on the original video frames.InitializationUse these next sections of code to initialize the required System objects.%Create a VideoFileReader System object to read video from a file.hVideoSrc = vision.VideoFileReader(vipmen.avi, . ImageColorSpace, Intensity);%Create an EdgeDetector System object to detect the edges in the video frame.hEdge = vision.EdgeDetector( . Method, Prewitt, . ThresholdSource, Property, . Threshold, 15/256, . EdgeThinning, true);%Create an AlphaBlender System object to overlay the edges on the original video frame.hAB = vision.AlphaBlender(Operation, Highlight selected pixels);%Create three VideoPlayer System objects to display the original video, the edges, and the edges overlaying the original video.WindowSize = 190 150;hVideoOrig = vision.VideoPlayer(Name, Original);hVideoOrig.Position = 10 hVideoOrig.Position(2) WindowSize;hVideoEdges = vision.VideoPlayer(Name, Edges);hVideoEdges.Position = 210 hVideoOrig.Position(2) WindowSize;hVideoOverlay = vision.VideoPlayer(Name, Overlay);hVideoOverlay.Position = 410 hVideoOrig.Position(2) WindowSize;Stream Processing Loop%Create a processing loop to perform edge detection on the input video. This loop uses the objects you instantiated above.while isDone(hVideoSrc) frame = step(hVideoSrc); % Read input video edges = step(hEdge, frame); % Edge detection composite = step(hAB, frame, edges); % AlphaBlender step(hVideoOrig, frame); % Display original step(hVideoEdges, edges); % Display edges step(hVideoOverlay, composite); % Display edges overlayedendRelease%Here you call the release method on the object to close any open files and devices.release(hVideoSrc);SummaryThe EdgeDetector object outputs a binary image with the edges shown in white. This output is displayed in the Edges window. The inputs to the AlphaBlender object are the original video frames, shown in the Original window, and the binary image output by the EdgeDetector object. The AlphaBlender object uses this binary image as a mask that specifies which original pixels to overwrite. The AlphaBlender object outputs a composite image, shown in the Overlay window, where the original pixel values are overwritten by the white edge values.Tracking Cars Using Optical FlowThis demo tracks cars in a video by detecting motion using optical flow. The cars are segmented from the background by thresholding the motion vector magnitudes. Then, blob analysis is used to identify the cars.Initialization%Create the System objects outside of the main video processing loop.% Object for reading video file.filename = viptraffic.avi;hVidReader = vision.VideoFileReader(filename, ImageColorSpace, RGB,. VideoOutputDataType, single);%Optical flow object for estimating direction and speed of object motion.hOpticalFlow = vision.OpticalFlow( . OutputValue, Horizontal and vertical components in complex form, . ReferenceFrameDelay, 3);%Create two objects for analyzing optical flow vectors.hMean1 = vision.Mean;hMean2 = vision.Mean(RunningMean, true);%Filter object for removing speckle noise introduced during segmentation.hMedianFilt = vision.MedianFilter;%Morphological closing object for filling holes in blobs.hclose = vision.MorphologicalClose(Neighborhood, strel(line,5,45);%Create a blob analysis System object to segment cars in the video.hblob = vision.BlobAnalysis(. CentroidOutputPort, false, AreaOutputPort, true, . BoundingBoxOutputPort, true, OutputDataType, double, . MinimumBlobArea, 250, MaximumBlobArea, 3600, MaximumCount, 80);%Morphological erosion object for removing portions of the road and other unwanted objects.herode = vision.MorphologicalErode(Neighborhood, strel(square,2);%Create objects for drawing the bounding boxes and motion vectors.hshapeins1 = vision.ShapeInserter(BorderColor, Custom, . CustomBorderColor, 0 1 0);hshapeins2 = vision.ShapeInserter( Shape,Lines, . BorderColor, Custom, . CustomBorderColor, 255 255 0);%This object will write the number of tracked cars in the output image.htextins = vision.TextInserter(Text, %4d, Location, 1 1, . Color, 1 1 1, FontSize, 12);%Create System objects to display the original video, motion vector video, the thresholded video and the final result.sz = get(0,ScreenSize);pos = 20 sz(4)-300 200 200;hVideo1 = vision.VideoPlayer(Name,Original Video,Position,pos);pos(1) = pos(1)+220; % move the next viewer to the righthVideo2 = vision.VideoPlayer(Name,Motion Vector,Position,pos);pos(1) = pos(1)+220;hVideo3 = vision.VideoPlayer(Name,Thresholded Video,Position,pos);pos(1) = pos(1)+220;hVideo4 = vision.VideoPlayer(Name,Results,Position,pos);% Initialize variables used in plotting motion vectors.lineRow = 22;firstTime = true;motionVecGain = 20;borderOffset = 5;decimFactorRow = 5;decimFactorCol = 5;Tracking Cars in Video%Create the processing loop to track the cars in video.while isDone(hVidReader) % Stop when end of file is reached frame = step(hVidReader); % Read input video frame grayFrame = rgb2gray(frame); ofVectors = step(hOpticalFlow, grayFrame); % Estimate optical flow % The optical flow vectors are stored as complex numbers. Compute their % magnitude squared which will later be used for thresholding. y1 = ofVectors .* conj(ofVectors); % Compute the velocity threshold from the matrix of complex velocities. vel_th = 0.5 * step(hMean2, step(hMean1, y1); % Threshold the image and then filter it to remove speckle noise. segmentedObjects = step(hMedianFilt, y1 = vel_th); % Thin-out the parts of the road and fill holes in the blobs. segmentedObjects = step(hclose, step(herode, segmentedObjects); % Estimate the area and bounding box of the blobs. area, bbox = step(hblob, segmentedObjects); % Select boxes inside ROI (below white line). Idx = bbox(:,1) lineRow; % Based on blob sizes, filter out objects which can not be cars. % When the ratio between the area of the blob and the area of the % bounding box is above 0.4 (40%), classify it as a car. ratio = zeros(length(Idx), 1); ratio(Idx) = single(area(Idx,1)./single(bbox(Idx,3).*bbox(Idx,4); ratiob = ratio 0.4; count = int32(sum(ratiob); % Number of cars bbox(ratiob, :) = int32(-1); % Draw bounding boxes around the tracked cars. y2 = step(hshapeins1, frame, bbox); % Display the number of cars tracked and a white line showing the ROI. y2(22:23,:,:) = 1; % The white line. y2(1:15,1:30,:) = 0; % Background for displaying count result = step(htextins, y2, count); % Generate coordinates for plotting motion vectors. if firstTime R C = size(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 课件汇报表格
- 车间导师师傅培训
- 环宇物流文员培训
- 特教语言课课件
- 枇杷美术创意课件
- 创意美术花瓶课件
- 课件最后的人生寄语
- 课件显示无法复制问题
- 雷达液位计考试题及答案
- 蓝山教练考试题及答案
- 中国阅兵仪式课件
- 中医特色在手术室护理中的应用
- 肺结核的课件
- 渝23TG02 钢管桁架预应力混凝土叠合板图集 DJBT50-165
- 海洋弧菌护理查房
- 2025-2030中国玉米脱粒机行业现状供需分析及市场深度研究发展前景及规划可行性分析研究报告
- 生产精益培训
- 《第十四届全国交通运输行业“大象科技杯”城市轨道交通行车调度员(职工组)职业技能大赛技术方案》
- 2025年柳州市城中区人民法院招录聘用人员考试试题
- 教师节主题班会课件尊师重教不忘师恩
- 中医针灸活动方案
评论
0/150
提交评论