Update app.py
Browse files
app.py
CHANGED
@@ -165,7 +165,7 @@ def remove_bg(fl, s, l, v):
|
|
165 |
blur_s[i,j] = (d/512).astype(np.uint8)
|
166 |
|
167 |
#remove regions of low saturation and lightness (get scene without shadow)
|
168 |
-
m = cv2.inRange(cv2.cvtColor(frame_c, cv2.
|
169 |
mask = cv2.inRange(blur_s, 0, v)
|
170 |
masks = np.bitwise_and(m, mask)
|
171 |
frame_[masks==0] = (0,0,0)
|
@@ -196,15 +196,24 @@ def remove_bg(fl, s, l, v):
|
|
196 |
m_ = cv2.inRange(frame_, np.array([1,1,1]), np.array([127,127,127]))
|
197 |
frame_[m_>0] = (127,127,127)
|
198 |
|
199 |
-
|
200 |
#shadow is black, bg is white, fg is gray
|
201 |
-
frame_ = 255 - frame_
|
202 |
-
m_ = cv2.inRange(frame_,
|
203 |
-
frame_[m_>0] =
|
204 |
-
m_ = cv2.inRange(frame_,
|
205 |
-
frame_[m_>0] =
|
206 |
|
207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
return fl
|
209 |
|
210 |
def logscale(linear):
|
|
|
165 |
blur_s[i,j] = (d/512).astype(np.uint8)
|
166 |
|
167 |
#remove regions of low saturation and lightness (get scene without shadow)
|
168 |
+
m = cv2.inRange(cv2.cvtColor(frame_c, cv2.COLOR_BGR2HSV), np.array([0,0,0]), np.array([180,s,l]))
|
169 |
mask = cv2.inRange(blur_s, 0, v)
|
170 |
masks = np.bitwise_and(m, mask)
|
171 |
frame_[masks==0] = (0,0,0)
|
|
|
196 |
m_ = cv2.inRange(frame_, np.array([1,1,1]), np.array([127,127,127]))
|
197 |
frame_[m_>0] = (127,127,127)
|
198 |
|
199 |
+
|
200 |
#shadow is black, bg is white, fg is gray
|
201 |
+
frame_ = 255 - cv2.cvtColor(frame_, cv2.COLOR_BGR2GRAY)
|
202 |
+
m_ = cv2.inRange(frame_, 255, 255)
|
203 |
+
frame_[m_>0] = 127
|
204 |
+
m_ = cv2.inRange(frame_, 128, 128)
|
205 |
+
frame_[m_>0] = 255
|
206 |
|
207 |
+
|
208 |
+
#apply mask to output
|
209 |
+
m = cv2.inRange(frame, np.array([240,240,240]), np.array([255,255,255]))
|
210 |
+
frame[m>0] = (239,239,239)
|
211 |
+
m = cv2.inRange(frame, np.array([0,0,0]), np.array([15,15,15]))
|
212 |
+
frame[m>0] = (16,16,16)
|
213 |
+
frame[frame_==0] = (frame / 17).astype(np.uint8)
|
214 |
+
frame[frame_==255] = (255,255,255)
|
215 |
+
|
216 |
+
cv2.imwrite(fl, frame)
|
217 |
return fl
|
218 |
|
219 |
def logscale(linear):
|