Difference between image processing in a loop

I'm currently doing object counting on a traffic light model. After I can count the vehicle, I'm trying to put the codes into a loop to get same results. The variables gotten in the loop is similar to the one that without the loop but I couldn't get the same results.
The area that it is counting is the road beside the vehicle while doing it in the loop.
bgd=snapshot(cam)
hfig = figure;
while isvalid(hfig)
img = snapshot(cam);
('segmentation and counting code')
end
pause(1)
end
Are there any solutions to this?

回答 (1 件)

Image Analyst
Image Analyst 2018 年 7 月 13 日

1 投票

There is nothing wrong with the loop itself. The problem is with this:
('segmentation and counting code')
That code is not robust. Fix that.

8 件のコメント

Adrian Lim
Adrian Lim 2018 年 7 月 13 日
Thank you for the reply! Is it okay if i attach my code here to ask for opinions on how to improve them?
Image Analyst
Image Analyst 2018 年 7 月 13 日
編集済み: Image Analyst 2018 年 7 月 13 日
Sure.
But first make sure that it's well commented and you use descriptive variable names.
No one wants to look at 10 pages of alphabet soup. If it is, the line above would be my first improvement suggestion.
Adrian Lim
Adrian Lim 2018 年 7 月 13 日
Thank you for willing to help. The codes are attached and also the inputs if you need them. From what I understand, the problem that occurs are before %getting vehicles which mainly focus on removing the background from the image that contains vehicle. I only fully understands the codes after %getting vehicless but not doing well i removing background. Thanks in advance,
Image Analyst
Image Analyst 2018 年 7 月 13 日
The first part of the code is missing, like the part where you read your image or video into img.
Adrian Lim
Adrian Lim 2018 年 7 月 14 日
I have to do the thing similar to live streaming so I decided to use this to fetch images
cam=webcam('1')
bgd=snapshot(cam)
hfig = figure;
while isvalid(hfig)
img = snapshot(cam);
('segmentation and counting code')
end
pause(1)
end
The segmentation and code part is the one which I attached on the previous comment.
Image Analyst
Image Analyst 2018 年 7 月 14 日
Sorry but my camera is not looking at your scene.
Adrian Lim
Adrian Lim 2018 年 7 月 14 日
I guess it can't be helped. Doing it as a live streaming part is kind of headache one. Thank you for your time!
Adrian Lim
Adrian Lim 2018 年 7 月 14 日
There's images with and without the car at the third comment which are matlab.mat. Those are my inputs.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

リリース

R2017a

質問済み:

2018 年 7 月 13 日

コメント済み:

2018 年 7 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by