我是 matlab 的新手,matlab 在代码段的最后一行给出错误"下标索引必须是实正整数或逻辑"(如果 th<0.01 || rank(A'*A)~=2) 如下所示,请指导我:
function [u,v] = optical_flow( im1,im2,windowSize )
x_c=im1(1:end-1,2:end)-im2(1:end-1,1:end-1);%(define rows 1~479,2~639 columns)-(rows 1~479,1~639)
y_c=im2(2:end,1:end-1)-im1(1:end-1,1:end-1);
t_c=im2(1:end-1,1:end-1)-im1(1:end-1,1:end-1);
%initialize for speed
u = zeros(size(x_c));
v = u;
for x = 1:size(x_c,1)-windowSize %fpr all x
for y = 1:size(x_c,2)-windowSize
%Get the windows of the dimensions
win_x=imcrop(x_c,[x y windowSize windowSize]);
win_y=imcrop(y_c,[x y windowSize windowSize]);
win_t=imcrop(t_c,[x y windowSize windowSize]);
%Convert windows to vectors to produce A for solving later
A = [win_x(:) win_y(:)];
%Compute threshold t (smallest eigenvalue of A'A)
th=min(eig(A'*A));
%Optical flow is only valid in regions with t<0.01 and
rank =2;
%if true, then it should not be computed
if th<0.01 || rank(A'*A)~=2
你给rank
赋值,这意味着 MATLAB 现在rank
视为变量。稍后,当您尝试计算rank(A'*A)
时,您将rank
视为函数。您应该重命名rank
变量。
%Optical flow is only valid in regions with t<0.01 and
rank =2; % <--- RENAME THIS
%if true, then it should not be computed