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

質問編集履歴

2

コードの修正

2020/11/17 07:38

投稿

pythonnoob1
pythonnoob1

スコア18

title CHANGED
File without changes
body CHANGED
@@ -85,81 +85,11 @@
85
85
  btn3.clicked.connect(self.auto_move_on)
86
86
  btn4.clicked.connect(self.auto_move_off)
87
87
 
88
- self.textbox1 = QLineEdit(self)
88
+ #GUIレイアウト(省略)
89
- self.textbox2 = QLineEdit(self)
90
- self.textbox3 = QLineEdit(self)
91
- self.textbox4 = QLineEdit(self)
92
- self.textbox5 = QLineEdit(self)
93
- self.textbox6 = QLineEdit(self)
94
- self.textbox7 = QLineEdit(self)
95
- self.textbox8 = QLineEdit(self)
96
- self.textbox9 = QLineEdit(self)
97
89
 
98
- label0 = QLabel("正面カメラ")
99
- label1 = QLabel("更新時間")
100
- label2 = QLabel("ピッチ角")
101
- label3 = QLabel("ロール角")
102
- label4 = QLabel("deg")
103
- label5 = QLabel("deg")
104
- label6 = QLabel("変数")
105
- label7 = QLabel("右モーター出力")
106
- label8 = QLabel("左モーター出力")
107
-
108
- layout1 = QHBoxLayout()
109
- layout1.addWidget(btn1)
110
- layout1.addWidget(btn2)
111
- layout1.addWidget(btn3)
112
- layout1.addWidget(btn4)
113
-
114
- layout2 = QVBoxLayout()
115
- layout2.addWidget(label0)
116
- layout2.addWidget(self.view1)
117
-
118
-
119
- layout3_1 = QHBoxLayout()
120
- layout3_1.addWidget(label1)
121
- layout3_1.addWidget(self.textbox1)
122
-
123
- layout3_2 = QHBoxLayout()
124
- layout3_2.addWidget(label6)
125
- layout3_2.addWidget(self.textbox6)
126
-
127
- layout3_3 = QHBoxLayout()
128
- layout3_3.addWidget(label7)
129
- layout3_3.addWidget(self.textbox17)
130
-
131
- layout3_4 = QHBoxLayout()
132
- layout3_4.addWidget(label8)
133
- layout3_4.addWidget(self.textbox8)
134
-
135
- layout3_5 = QHBoxLayout()
136
- layout3_5.addWidget(label2)
137
- layout3_5.addWidget(self.textbox2)
138
- layout3_5.addWidget(label4)
139
-
140
- layout3_6 = QHBoxLayout()
141
- layout3_6.addWidget(label3)
142
- layout3_6.addWidget(self.textbox3)
143
- layout3_6.addWidget(label5)
144
-
145
- layout_3 = QGridLayout()
146
- layout_3.addLayout(layout3_1,0,0)
147
- layout_3.addLayout(layout3_2,0,1)
148
- layout_3.addLayout(layout3_3,1,0)
149
- layout_3.addLayout(layout3_4,1,1)
150
- layout_3.addLayout(layout3_5,2,0)
151
- layout_3.addLayout(layout3_6,3,0)
152
-
153
- layout_ALL = QVBoxLayout()
154
- layout_ALL.addLayout(layout1)
155
- layout_ALL.addLayout(layout2)
156
- layout_ALL.addLayout(layout3)
157
-
158
- self.setLayout(layout_ALL)
159
-
160
90
  self.show()
161
91
 
162
- #@pyqtSlot()
92
+
163
93
 
164
94
  def camera_on(self):
165
95
  self.camera = 1
@@ -198,17 +128,12 @@
198
128
  return
199
129
 
200
130
  def servo_angle(angle):
201
- #角度からデューティ比を求める
202
131
  duty = 2.5 + (12.0 - 2.5) * (angle + 90) / 180
203
- #デューティ比を変更
204
132
  self.Servo.ChangeDutyCycle(duty)
205
133
 
206
- #ピッチ角分サーボを回転
207
134
  servo_angle(round(self.Pitch))
208
- #サーボモータをストップ
209
135
  self.Servo.stop()
210
136
 
211
- #画像回転
212
137
  height = cv_img.shape[0]
213
138
  width = cv_img.shape[1]
214
139
  center = (int(width/2),int(height/2))
@@ -219,10 +144,10 @@
219
144
 
220
145
  self.img_src = self.cv_img
221
146
 
222
- #RGB変換
147
+
223
148
  cv_img_RGB = cv2.cvtColor(self.cv_img,cv2.COLOR_BGR2RGB)
224
149
 
225
- #リサイズ
150
+
226
151
  cv_img_RGB = cv2.resize(cv_img_RGB,(320,240))
227
152
 
228
153
  height, width, dim = cv_img_RGB.shape
@@ -243,7 +168,7 @@
243
168
  self.auto = 1
244
169
  GPIO.cleanup()
245
170
  motor.init_GPIO()
246
- self.p18 , self.p17 , self.p11 , self.p9 , self.p27 , self.p22 = motor.init_GPIO_PWM()
171
+ self.pin1 , self.pin2 , self.pin3 , self.pin4 , self.pin5 , self.pin6 = motor.init_GPIO()
247
172
  self.auto_move_set()
248
173
  repeatTime = 10
249
174
  timer = QTimer(self.view1)
@@ -253,7 +178,7 @@
253
178
  def auto_move_off(self):
254
179
 
255
180
  self.auto = 0
256
- self.manual_motor_S()
181
+ self.motor_S()
257
182
  GPIO.cleanup()
258
183
  print("cleanup")
259
184
 
@@ -264,7 +189,7 @@
264
189
  variable, img_src0, elapsed_time = Image_Processing.I_P(self.auto,self.img_src,self.Roll)
265
190
 
266
191
  #モーターを動かすプログラム。画像処理(Image_Processing.py)にて得られた変数(variable)を基にモータの出力を変更
267
- self.Duty_R , self.Duty_L = motor.motor_PWM(p_vaiue3,self.p18 , self.p17 , self.p11 , self.p9 , self.p27 , self.p22 )
192
+ self.Duty_R , self.Duty_L = motor.motor_PWM(p_vaiue3,self.pin1 , self.pin2 , self.pin3 , self.pin4 , self.pin5 , self.pin6 )
268
193
 
269
194
  variable = str(round(variable,3))
270
195
  self.textbox6.setText(variable)
@@ -292,9 +217,8 @@
292
217
  t1 = time.time()
293
218
  if auto == 0:
294
219
  return
295
- F = F2 = F3 = P = 0
220
+ F= 0
296
- row_mean_p = row_mean_p2 = h3 = 0
221
+
297
- row_mean_p3 = 320
298
222
 
299
223
  img_src=cv2.resize(img_src,(180,60))
300
224
  img_src=img_src[20:60, 20-round(75*math.cos(math.radians(90-Roll))):140-round(75*math.cos(math.radians(90-Roll)))]
@@ -304,7 +228,7 @@
304
228
  GREEN_min = np.array([30, 64, 30])
305
229
  GREEN_max = np.array([90, 255,255])
306
230
  img_mask = cv2.inRange(hsv,GREEN_min ,GREEN_max)
307
- # 8近傍の定義
231
+
308
232
  neiborhood8 = np.array([[1, 1, 1],[1, 1, 1],[1, 1, 1]],np.uint8)
309
233
  img_erosion = cv2.erode(img_mask,neiborhood8,iterations=2)
310
234
  img_erosion = cv2.erode(img_erosion,neiborhood8,iterations=2)
@@ -314,9 +238,8 @@
314
238
  img_dst2 = cv2.bitwise_and(img_src, img_src, mask=img_mask)
315
239
 
316
240
  #Value.pyで変数(variable)を計算
317
- row_mean_L , row_mean_R ,variable = Value.Get_MotorParameter(img_mask,1 ,F3)
241
+ row_L , row_R ,variable = Value.Get_MotorParameter(img_mask,1 ,F)
318
242
 
319
- F3 = int(variable)
320
243
 
321
244
  t2 = time.time()
322
245
  elapsed_time = t2 - t1

1

質問の訂正

2020/11/17 07:38

投稿

pythonnoob1
pythonnoob1

スコア18

title CHANGED
File without changes
body CHANGED
@@ -22,6 +22,8 @@
22
22
  ラズパイの動作が重くなると画像処理が出来なくなり、画像が読み込めなくなるのでしょうか?
23
23
  どうかご教授を頂けますと幸いです。
24
24
 
25
+ また、現在の私の環境上返信に時間を要してしまいます。質問をしている身分で大変申し訳ありませんがよろしくお願いします。
26
+
25
27
  以下に作成したコード(必要そうなもの)を載せます。
26
28
  ###作成したコード(必要そうなもの)
27
29
  ```python