Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
初级会员
注册日期: 2009-03-30
年龄: 44
帖子: 3
声望力: 0 ![]() |
![]()
我在做hough变换检测直线,在
function lines=houghlines(f,theta,rho,rr,cc,fillgap,minlength) %HOUGHLINES Extract line segments based on the Hough transform. % LINES=HOUGHLINES(F,THETA,RHO,RR,CC,FILLGAP,MINLENGTH) % extracts line segments in the image F associated with particular % bins in a Hough. Vectors RR and CC specify the rows and columns % of the Hough transform bins to use in searching for line % segments. If HOUGHLINES finds two line segments associated with % the same Hough transform bin that are separated by less than % FILLGAP pixels, HOUGHLINES merges them into a single line % segment. FILLGAP defaults to 20 if omitted. Merged line % segments less than MINLENGTH pixels long are discarded. % MINLENGTH defaults to 40 if omitted. % % LINES is a structure array whose length equals the number of % merged line segments found. Each element of the structure array % has these fields: % % point1 End-point of the line segment; two-element vector % point2 End-point of the line segment; two-element vector % length Distance between point1 and point2 % theta Angle (in degrees) of the Hough transform bin % rho Rho-axis position of the Hough transform bin if nargin < 6 fillgap=20; end if nargin < 7 minlength=40; end numlines=0; lines=struct; for k=1:length(rr) rbin=rr(k);cbin=cc(k); % Get all pixels associated with Hough transform cell. [r,c]=houghpixels(f,theta,rho,rbin,cbin); if isempty(r) continue end % Rotate the pixels locations about(1,1) so that they lie % approximately along a vertical line. omega=(90-theta(cbin))*pi/180; T=[cos(omega) sin(omega); -sin(omega) cos(omega)]; xy=[r-1 c-1]*T; x=sort(xy(:,1)); % Find the gaps larger than the threshold. diff_x=[diff(x);inf]; idx=[0;find(diff_x>fillgap)]; for p=1:length(idx)-1 x1=x(idx(p)+1); x2=x(idx(p+1)); linelength=x2-x1; if linelength >=minlength point1=[x1 rho(rbin)]; point2=[x2 rho(rbin)]; % Rotate the end_point location back to the original % angle. Tinv=inv(T); point1=point1*Tinv; point2=point2*Tinv; numlines=numlines+1; lines(numlines).point1=point1+1; lines(numlines).point2=point2+1; lines(numlines).length=length+1; lines(numlines).theta=theta(cbin); lines(numlines).rho=rho(rbin); end end end 中遇到一个问题,在matlab命令界面输入lines=houghlines(f,theta,rho,r,c)的时候 提示的是lines是一个1x1的没有fields的struct。我觉得应该是上面代码红色的那个句子 出了问题,但是我看了help以后还是不知道怎么修改,麻烦哪位帮帮我,急用啊!! 非常感谢!!!!!!! |
![]() |
![]() |
![]() |
#2 |
初级会员
注册日期: 2009-03-20
年龄: 42
帖子: 26
声望力: 17 ![]() |
![]()
一同学习吧!我也查了一下help,你起码应该给struct赋初值吧?
struct([]) 这个是创建一个空结构体 s = struct('strings',{{'hello','yes'}},'lengths',[5 3]) 这个命令创建了一个1*1的结构体,该结构体的元素是一个Cell数组,这个Cell数组中有两个字符,一个长度为5,一个长度为3,结果如下: s = strings: {'hello' 'yes'} lengths: [5 3]
__________________
不到马里亚纳,不知道大海的深度 不到珠穆朗玛,不知道大山的高度 不到Labfans,不知道自己的无知 |
![]() |
![]() |
![]() |
#3 |
高级会员
注册日期: 2008-11-07
住址: 湖南长沙
帖子: 233
声望力: 21 ![]() |
![]()
结构体的创建需要同时给定初值
|
![]() |
![]() |