if文のエラーについて

7 Ansichten (letzte 30 Tage)
早汰 前川
早汰 前川 am 26 Apr. 2021
Beantwortet: Kojiro Saito am 26 Apr. 2021
if文を使って,顔検出したときに"おはよう”と,口検出したときに"こんにちは"と表示させたいです.
以下のコードでエラーが生じました.
エラーは”コード8行目のbboxBodyが変数として認識されない”という内容でした.
補足:顔検出した際の"ohayou"はコマンドウィンドウに表示されました.
わかる方がいらっしゃいましたら,ご教授ください.
faceDetector=vision.CascadeObjectDetector;
bodyDetector=vision.CascadeObjectDetector('Mouth');
bodyDetector.MinSize=[60 60];
bodyDetector.MeregeThreshold=10;
I=imread(写真の名前);
if(bboxes==faceDetector(I))
disp("ohayou")
elseif(bboxBody==bodyDetector(I))
disp("konnitiwa")
end

Akzeptierte Antwort

Kojiro Saito
Kojiro Saito am 26 Apr. 2021
bboxesbboxBodyはそれぞれfaceDetectorbodyDetectorの出力だと思われますので、以下のようにしてみたらいかがでしょうか。上記のコードでは顔検出と口検出をelseifで分岐させていますが、排他的では無いと思いますので、ifの入れ子にするかif end、if endで別の分岐にしてみました。
faceDetector=vision.CascadeObjectDetector;
bodyDetector=vision.CascadeObjectDetector('Mouth');
bodyDetector.MinSize=[60 60];
bodyDetector.MergeThreshold=10;
I = imread('visionteam.jpg');
%I=imread('写真の名前.jpg');
bboxes = faceDetector(I);
bboxBody = bodyDetector(I);
if ~isempty(bboxes)
disp("ohayou")
end
if ~isempty(bboxBody)
disp("konnitiwa")
end
% または
if ~isempty(bboxes)
disp("ohayou")
if ~isempty(bboxBody)
disp("konnitiwa")
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Computer Vision Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!