2

matlabスクリプトでコードを記述しました。センター用の関数を作成して仕上げる必要があります。

これが私が書いたサンプルコードです

while(1)        % infinite loop

trigger(obj); 
im=getdata(obj,1);   %get the image

trigger(obj); 
im1=getdata(obj,1);  % the first time triggering occurs the image is just
                              % noise. Thus the 2nd image is used.
b=rgb2gray(im1);      % convert to grayscale
a=roicolor(b,[100:118]);  %define a region of interest
a=~a;

c=center(a);
                  % use disp(c) to see the values, while testing
if (c(2)>190)
fwrite(ser,'r');  % send move right
elseif (c(2)<170 && c(2)>10)
fwrite(ser,'l');
elseif c(2)<170
fwrite(ser,'l'); % stop

現在、このセンターでは(a) matlabで事前定義された関数ではなく、ユーザー定義の関数です。

私が使用した関数センター(a)は組み込み関数ではありません。私が取り組むことができるセンター用の関数を書くことをお勧めします

matlabで関数を作成し、必要なときにいつでもユーザー定義関数を呼び出すのを手伝ってもらいたいです。

4

1 に答える 1

1

すべてのコードをそこに置くというファイルを作成し、center.m次のようなファイル(上部)を開始します。

function c = center(a);
于 2012-11-15T19:07:28.477 に答える