Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -422,18 +422,21 @@ def optimize(v, d):
|
|
422 |
if v == True:
|
423 |
ddepth = cv2.CV_16S
|
424 |
kernel_size = 3
|
425 |
-
l =
|
426 |
|
427 |
dcolor = []
|
428 |
for k, f in enumerate(frames):
|
429 |
frame = cv2.imread(frames[k]).astype(np.uint8)
|
430 |
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
|
|
|
|
|
|
437 |
|
438 |
dcolor.append(bincount(frame))
|
439 |
print(dcolor[k])
|
|
|
422 |
if v == True:
|
423 |
ddepth = cv2.CV_16S
|
424 |
kernel_size = 3
|
425 |
+
l = 16
|
426 |
|
427 |
dcolor = []
|
428 |
for k, f in enumerate(frames):
|
429 |
frame = cv2.imread(frames[k]).astype(np.uint8)
|
430 |
|
431 |
+
# convert to np.float32
|
432 |
+
f = np.float32(frame.reshape((-1,3)))
|
433 |
+
# define criteria, number of clusters(K) and apply kmeans()
|
434 |
+
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 10, 1.0)
|
435 |
+
ret,label,center=cv2.kmeans(f,l,None,criteria,10,cv2.KMEANS_RANDOM_CENTERS)
|
436 |
+
# Now convert back into uint8, and make original image
|
437 |
+
center = np.uint8(center)
|
438 |
+
res = center[label.flatten()]
|
439 |
+
frame = res.reshape((frame.shape))
|
440 |
|
441 |
dcolor.append(bincount(frame))
|
442 |
print(dcolor[k])
|