質問編集履歴

1

全体的に見やすくしたつもりです。申し訳ありませんでした。

2018/09/12 00:58

投稿

Nao1117
Nao1117

スコア17

test CHANGED
File without changes
test CHANGED
@@ -30,7 +30,7 @@
30
30
 
31
31
  では
32
32
 
33
- [{'label': 'bicycle', 'confidence': 0.84797806, 'topleft': {'x': 80, 'y': 113},
33
+ [{'label': 'car', 'confidence': 0.84797806, 'topleft': {'x': 80, 'y': 113},
34
34
 
35
35
  'bottomright': {'x': 555, 'y': 467}}, {'label': 'truck', 'confidence': 0.8014206
36
36
 
@@ -41,6 +41,14 @@
41
41
 
42
42
 
43
43
  26行目でこれを構造体のように扱いたいのですがjson.loadではエラーを吐きます。
44
+
45
+
46
+
47
+ print(result[0])で
48
+
49
+ [{'label': 'car', 'confidence': 0.84797806, 'topleft': {'x': 80, 'y': 113},'bottomright': {'x': 555, 'y': 467}}]
50
+
51
+ にアクセスはできたのですが、labelの情報をif文の条件に使い、x,yの座標を適宜呼び出す方法が分かりません。
44
52
 
45
53
 
46
54
 
@@ -56,27 +64,11 @@
56
64
 
57
65
 
58
66
 
59
- # YOLOによる物体検出
60
-
61
- options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.8}
62
-
63
-
64
-
65
- class_names = ['car', 'person']
66
-
67
- tfnet = TFNet(options)
68
-
69
-
70
-
71
- imgcv = cv2.imread("./sample_img/sample_dog.jpg")
72
-
73
- result = tfnet.return_predict(imgcv)
74
-
75
67
  print(result)
76
68
 
77
69
 
78
70
 
79
- # 結果の画像の作成および出力
71
+ % 作成したい画像下地の画像の読み込み
80
72
 
81
73
  bImg = cv2.imread("../../image/road1.jpg")
82
74
 
@@ -92,7 +84,7 @@
92
84
 
93
85
 
94
86
 
95
- # 各ラベルに対応した出力の画像の取得
87
+ % 各ラベルに対応した出力の画像の取得
96
88
 
97
89
  if result(x) == 'car':
98
90
 
@@ -104,71 +96,15 @@
104
96
 
105
97
 
106
98
 
107
- # 物体を描画したときの倍率の計算
99
+ % 物体を描画したときの倍率の計算
108
100
 
109
101
  scale = (ob_dict(bottomright,x) - ob_dect(topleft,x)) * (ob_dict(bottomright,y) - ob_dect(topleft,y)) / (bSize[0] * bsize[1])
110
102
 
111
103
 
112
104
 
113
- # 画像の書き込み
105
+ % 画像の書き込み
114
106
 
115
107
  resultImage = transparentOverlay(bImg,pngImage,(ob_dect(bottomright,x),ob_dect(bottomright,y)),scale)
116
-
117
-
118
-
119
- #Display the result
120
-
121
- cv2.namedWindow("Result",cv2.WINDOW_NORMAL)
122
-
123
- cv2.imshow("Result" ,resultImage)
124
-
125
- cv2.waitKey()
126
-
127
- cv2.destroyAllWindows()
128
-
129
-
130
-
131
- def transparentOverlay(src , overlay , pos=(0,0),scale = 1):
132
-
133
- """
134
-
135
- :param src: Input Color Background Image
136
-
137
- :param overlay: transparent Image (BGRA)
138
-
139
- :param pos: position where the image to be blit.
140
-
141
- :param scale : scale factor of transparent image.
142
-
143
- :return: Resultant Image
144
-
145
- """
146
-
147
- overlay = cv2.resize(overlay,(0,0),fx=scale,fy=scale)
148
-
149
- h,w,_ = overlay.shape # Size of pngImg
150
-
151
- rows,cols,_ = src.shape # Size of background Image
152
-
153
- y,x = pos[0],pos[1] # Position of PngImage
154
-
155
-
156
-
157
-
158
-
159
- for i in range(h):
160
-
161
- for j in range(w):
162
-
163
- if x+i >= rows or y+j >= cols:
164
-
165
- continue
166
-
167
- alpha = float(overlay[i][j][3]/255.0) # read the alpha channel
168
-
169
- src[x+i][y+j] = alpha*overlay[i][j][:3]+(1-alpha)*src[x+i][y+j]
170
-
171
- return src
172
108
 
173
109
 
174
110