How to increase framerate of display video after hough's transform?

1 次查看(过去 30 天)
Hello,
I've been trying to do a basic lane detection using Hough's transform, from a video from file. This is the method I followed.
1. Used mmreader to acquire video.
2. Used read command in a loop to acquire one frame at a time.
3. Ran a canny edge detector.
4. Gave the output to a standard Hough's transform.
5. Used vision.ShapeInserter to insert lines into co-ordinates I acquire from the Hough's transform.
6. Output video with the lines added, using step command.
The code works but it's agonizingly slow. Starting from the Canny edge detector the code starts to get slow. I've utilized Computer vision toolboxes of matlab for all the above algorithms. Could you kindly recommend an alternative way or some edits which might help my existing code?
clear all
close all
obj = mmreader('C:\Users\hj\computer vision\road.mp4');
nFrames = obj.NumberOfFrames;
% For Inserting lines into the video
shapeInserter = vision.ShapeInserter('Shape','Lines','BorderColor','Custom',... 'CustomBorderColor',[0 1 0] );
% for output video stream
rgbvideo = vision.VideoPlayer;
for k=1:nFrames
% read one frame
I_color=read(obj,k);
I=rgb2gray(I_color);
BW = edge(I,'canny');
[H,T,R]=hough(BW);
P=houghpeaks(H,5);
%plot(T(P(:,2)),R(P(:,1)),'s','color','white');
lines = houghlines(BW,T,R,P,'FillGap',5);
%figure, imshow(I), hold on
% Storing coordinates in M-by-2L matrix, where M specifies the number of polylines.
% Each row specifies a polyline as a series of consecutive point locations, [x1, y1, x2, y2, ..., xL, yL].
for j=1:length(lines)
for p=1:2
jk(j,p)=lines(j).point1(p);
jk(j,p+2)=lines(j).point2(p);
end
end
% inserting lines
rgb1 = step(shapeInserter, I_color, int32(jk));
%imshow(rgb1);
% output video stream
step(rgbvideo,rgb1);
end
% release memory
release(rgbvideo);

回答(1 个)

Dima Lisin
Dima Lisin 2014-9-3
If you know the approximate orientation of the lines in the image, you can try restricting the range of theta using the 'Theta' parameters of the hough function.

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by