remotewith commited on
Commit
ebb7c5f
·
1 Parent(s): 3af03af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -10
app.py CHANGED
@@ -48,22 +48,48 @@ def normalize_2d(matrix):
48
  def detect(imagepath):
49
 
50
  pix=model.predict(imagepath, confidence=40, overlap=30)
51
- pix=np.array(pix)
52
  img=cv2.imread(imagepath)
53
 
54
- for a,b,c,d,_,_,_,_ in pix.items():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  cv2.rectangle(
56
- img,
57
- (a,b),
58
- (a+c,b+d),
59
- color=(0, 0, 255),
60
- thickness=2,
61
- lineType=cv2.LINE_AA)
 
 
 
 
62
 
63
- return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
64
 
65
 
66
-
 
67
 
68
  def predict(img):
69
 
 
48
  def detect(imagepath):
49
 
50
  pix=model.predict(imagepath, confidence=40, overlap=30)
51
+ pix=pix.json()
52
  img=cv2.imread(imagepath)
53
 
54
+ x1,x2,y1,y2=[],[],[],[]
55
+ for i in pix.keys():
56
+ if i=="predictions":
57
+ for j in pix["predictions"]:
58
+ for a,b in j.items():
59
+ if a=="x":
60
+ x1.append(b)
61
+ if a=="y":
62
+ y1.append(b)
63
+ if a=="width":
64
+ x2.append(b)
65
+ if a=="height":
66
+ y2.append(b)
67
+
68
+
69
+
70
+ for p in range(0,len(x1)):
71
+ x2[p]=x2[p]+x1[p]
72
+
73
+ for p in range(0,len(x1)):
74
+ y2[p]=y2[p]+x1[p]
75
+
76
+ for (x11,y11,x12,y12) in zip(x1,y1,x2,y2):
77
  cv2.rectangle(
78
+ img,
79
+ (x11,y11),
80
+ (x12,y12),
81
+ color=(0, 0, 255),
82
+ thickness=2,
83
+ lineType=cv2.LINE_AA
84
+ )
85
+
86
+ return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
87
+ #cv2.imshow("kamehamehaa",img)
88
 
 
89
 
90
 
91
+
92
+
93
 
94
  def predict(img):
95