前提・実現したいこと
YOLOという物体検出モデルの実行結果から、1フレームごとに人々の数を検出するプログラムを考えています。
以下のようなテキストファイルから人の数だけ(dogやcatなど他の検出物を除いたもの)を抽出し、フレームごとに数を算出させたいのですが、解決策が見つからず行き詰っています。(Foundから次のFoundまでの間が1フレームで検出された物体の総数)
Found 3 boxes for img
person 0.76 (1112, 320) (1143, 367)
person 0.81 (862, 313) (887, 364)
dog 0.36 (1104, 320) (1132, 367)
Found 1 boxes for img
person 0.81 (1108, 321) (1138, 368)
Found 0 boxes for img
Found 3 boxes for img
person 0.72 (1105, 320) (1132, 368)
person 0.90 (862, 314) (885, 364)
cat 0.36 (1104, 320) (1132, 367)
Found 2 boxes for img
person 0.72 (1105, 320) (1130, 368)
person 0.91 (863, 315) (886, 364)
.
.
.
理想としては
total of person is:2
total of person is:1
total of person is:0
total of person is:2
total of person is:2
.
.
.
のように対応関係を出力できたらと考えています。
発生している問題・エラーメッセージ
フレームごとに検出された人の総数を求め、出力する方法が分からない状況です。
該当のソースコード
python3
1ld = open("textfile") 2lines = ld.readlines() 3ld.close() 4person = 0 5for line in lines: 6 if line.find('person') >= 0: 7 person += 1 8 print(person) 9 elif line.find("Found") >= 0: 10 print("total of person is:")
試したこと
様々な関数を試してみましたが、うまく実行できませんでした。
上記のコードでは、
sum of person is:
1
2
sum of person is:
3
sum of person is:
sum of person is:
4
5
.
.
.
と出力されてしまい、フレームごとに総数を対応させることができませんでした。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/30 09:47