teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

修正と追加です

2021/12/05 10:27

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -11,7 +11,72 @@
11
11
  申し訳ございませんが宜しくおねがい致します。
12
12
 
13
13
  ###
14
+ ```
15
+ def process(self):
16
+ # Defining world dimensions
17
+ world_size = (720, 900)
18
+ image_path ="/program/main/resize_map.jpg"
19
+     #マップの読み込み
20
+ image = cv2.imread(image_path)
21
+     #スタート地点
22
+ agent = Agent(Position(720,75), scan_radius=0.60, possible_moves=30)
23
+ #第1ゴール地点
24
+ goal = Goal(Position(588,218), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2))
25
+     #描写
26
+ agent.draw(image)
27
+ goal.draw(image)
28
+ cv2.imshow('Output', image)
29
+ cv2.moveWindow('Output', 1950, 100)
30
+ cv2.waitKey(100)
31
+
32
+ #ポテンシャル法による画像に点描写するプログラム
33
+ navi = 0
34
+ args = self.arg_parse()
35
+ confidence = float(args.confidence)
36
+ nms_thesh = float(args.nms_thresh)
37
+ CUDA = torch.cuda.is_available()
38
+ num_classes = 80
39
+ print("Loading network.....")
40
+ model = Darknet(args.cfgfile)
41
+ model.load_weights(args.weightsfile)
42
+ print("Network successfully loaded")
43
+ if CUDA:
44
+ model.cuda()
45
+ #ここまでしか来ず、「進みますがターミナルに出力されません
46
+ #whileループ内のループというのが無限ループ
47
+ # ストリーム(Color/Depth)の設定
48
+ config = rs.config()
49
+     #撮影した動画を読み込む
50
+ config.enable_device_from_file('/48A9A14C31288186/12_2_thu.bag',repeat_playback=False)
51
+ config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
52
+ config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
53
+
54
+ # ストリーミング開始
55
+ pipeline = rs.pipeline()
56
+ profile = pipeline.start(config)
57
+ align = rs.align(rs.stream.color)
58
+ print("進みます")
59
+ playsound('/home/limlab/program/voice/go_straight.mp3')
60
+ try:
61
+ #ゴールまで0.3以上の距離があるのでゴールに向かって点の描写が始まる
62
+ while Position.calculate_distance(agent.position, goal.position) > 0.3:
63
+ try:
64
+ frames = pipeline.wait_for_frames()
65
+ color_frame = frames.get_color_frame()
66
+ depth_frame = frames.get_depth_frame()
67
+ if not depth_frame or not color_frame:
68
+ continue
69
+ frames = align.process(frames)
70
+ profile = frames.get_profile()
71
+ #画像データに変換
72
+ color_image = np.asanyarray(color_frame.get_data())
73
+ depth_color_frame = rs.colorizer().colorize(depth_frame)
74
+ depth_color_image = np.asanyarray(depth_color_frame.get_data())
75
+ #これ以降,点描写がされつつ、yoloによる認識が始まり認識した場合、count_image_pathが保存されます、
14
76
 
77
+
78
+ ```
79
+
15
80
  ```python3.8
16
81
  def main():
17
82
  if os.path.exists(count_image_path):
@@ -21,18 +86,26 @@
21
86
  print("text_reading_image_pathが存在するので削除します")
22
87
  os.remove(text_reading_image_path)
23
88
  m = Main()
24
- r = Run_image()
25
89
  executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)
90
+ executor.submit(m.process)
91
+ r_running = False
26
92
 
27
- executor.submit(m.process)
28
-
29
93
  while True:
30
-
94
+ print("ループ")
95
+ # プロセスrが動作していなくて、プロセスmの情報ができたらプロセスrを起動
31
- if os.path.exists(count_image_path)== True:
96
+ if not r_running and os.path.exists(count_image_path)== True:
97
+ r = Run_image()
32
98
  executor.submit(r.run)
99
+ r_running = True
100
+
101
+ # プロセスrが終了したら、フラグを落す。
33
- os.remove(count_image_path)
102
+ if os.path.exists(text_reading_image_path):
103
+ r_running = False
104
+
34
105
 
106
+ # プロセスmが終章したらループを抜ける
107
+ #if not r_running and #プロセスmの終了検知:
108
+ #break
35
109
 
36
110
 
37
-
38
111
  ```

4

修正

2021/12/05 10:27

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -14,17 +14,21 @@
14
14
 
15
15
  ```python3.8
16
16
  def main():
17
+ if os.path.exists(count_image_path):
18
+ print("count_image_pathが存在するので削除します")
19
+ os.remove(count_image_path)
20
+ if os.path.exists(text_reading_image_path):
21
+ print("text_reading_image_pathが存在するので削除します")
22
+ os.remove(text_reading_image_path)
17
23
  m = Main()
18
24
  r = Run_image()
19
-
20
- if os.path.exists(count_image_path):
21
- print("ファイルが存在するので削除します")
22
- os.remove(count_image_path)
23
- executor = concurrent.futures.ThreadPoolExecutor(max_workers=2)
25
+ executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)
24
26
 
25
- if not os.path.exists(count_image_path):
26
- executor.submit(m.process)
27
+ executor.submit(m.process)
28
+
29
+ while True:
30
+
27
- if os.path.exists(count_image_path):
31
+ if os.path.exists(count_image_path)== True:
28
32
  executor.submit(r.run)
29
33
  os.remove(count_image_path)
30
34
 

3

修正

2021/12/05 07:31

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -6,8 +6,9 @@
6
6
 
7
7
  executor.submit(m.process)では1回のみ動画を回していて、その動画から得られた結果からexecutor.submit(m.process)を動かしつつexecutor.submit(r.run)で動画の解析をしています。また、動画の解析が終わったら終了し、executor.submit(m.process)だけにしていきたいです。
8
8
 
9
- executor.submit(m.process)は動画再生のため、1回の実行だけでよいのですがexecutor.submit(r.run)は動画の結果に応じて何度も実行する必要があります。解析するときだけ並列処理になるというプログラムを書くことはできますでしょうか。
9
+ executor.submit(m.process)は動画再生のため、1回の実行だけでよいのですがexecutor.submit(r.run)は動画の結果(count_image_pathは動画から得られた画像のパス)に応じて何度も実行する必要があります。解析するときだけ並列処理になるというプログラムを書くことはできますでしょうか。
10
10
 
11
+ 申し訳ございませんが宜しくおねがい致します。
11
12
 
12
13
  ###
13
14
 

2

修正

2021/12/03 07:49

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- 1つのプログラム内で並列処理をするしないを条件分岐したい
1
+ 1つのプログラム内で並列処理をするタイミングを決め、並列処理をしないときは1つの関数だけ動かしたい
body CHANGED
@@ -3,11 +3,12 @@
3
3
  python3.8
4
4
  ubuntu20.04を使用しています。
5
5
 
6
- 並列処理に関する質問ですが、基本的にexecutor.submit(m.process)を起動し、必要なときにexecutor.submit(r.run)を起動し並列処理していきたいと思っています。また、executor.submit(r.run)の処理が終了したらexecutor.submit(m.process)だけの処理に戻していきたいです。
7
6
 
8
- 現状、executor.submit(m.process)だけとなっおりcount_image_path(画像ファイル)は存在ますが並列処理に移っくれてない状態です。こちらコードにどのような誤りあるか教えていただきたいです。申し訳ございませんが宜しくおねがい致します。
7
+ executor.submit(m.process)では1回画を回しいてその動画から得られた結果からexecutor.submit(m.process)を動かしつつexecutor.submit(r.run)で動の解析をしていす。また、動画解析終わっら終了し、executor.submit(m.process)けにしていきたいです。
9
8
 
9
+ executor.submit(m.process)は動画再生のため、1回の実行だけでよいのですがexecutor.submit(r.run)は動画の結果に応じて何度も実行する必要があります。解析するときだけ並列処理になるというプログラムを書くことはできますでしょうか。
10
10
 
11
+
11
12
  ###
12
13
 
13
14
  ```python3.8

1

修正

2021/12/03 07:47

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  並列処理に関する質問ですが、基本的にexecutor.submit(m.process)を起動し、必要なときにexecutor.submit(r.run)を起動し並列処理していきたいと思っています。また、executor.submit(r.run)の処理が終了したらexecutor.submit(m.process)だけの処理に戻していきたいです。
7
7
 
8
- 現状、executor.submit(m.process)だけの起動となっており、count_image_path(画像ファイル)は存在しますが並列処理に移ってくれていない状態です。申し訳ございませんが宜しくおねがい致します。
8
+ 現状、executor.submit(m.process)だけの起動となっており、count_image_path(画像ファイル)は存在しますが並列処理に移ってくれていない状態です。こちらのコードにどのような誤りがあるか教えていただきたいです。申し訳ございませんが宜しくおねがい致します。
9
9
 
10
10
 
11
11
  ###