staghado commited on
Commit
a526c29
·
1 Parent(s): a2e1a7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -16,13 +16,15 @@ def fourier_transform_drawing(input_image, frames, coefficients):
16
  img = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
17
 
18
  # processing
19
- imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
20
- blurred = cv2.GaussianBlur(imgray, (7, 7), 0)
21
-
22
- # apply Otsu threshold
 
 
 
 
23
  (_, thresh) = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
24
-
25
- # find contours of the binary image
26
  contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
27
 
28
  # take only the largest contour
@@ -47,7 +49,7 @@ def fourier_transform_drawing(input_image, frames, coefficients):
47
 
48
  t_list = np.linspace(0, tau, len(xs))
49
 
50
- # Compute the Fourier coefficients
51
  def f(t, t_list, xs, ys):
52
  return np.interp(t, t_list, xs + 1j*ys)
53
 
@@ -92,7 +94,11 @@ def fourier_transform_drawing(input_image, frames, coefficients):
92
 
93
  draw_x.append(center[0])
94
  draw_y.append(center[1])
95
- drawing.set_data(draw_x, draw_y)
 
 
 
 
96
 
97
  drawing_time = 1
98
  time = np.linspace(0, drawing_time, num=frames)
 
16
  img = cv2.cvtColor(input_image, cv2.COLOR_RGB2BGR)
17
 
18
  # processing
19
+ # Resize the image to a smaller size for faster processing
20
+ width = 224
21
+ height = 224
22
+ dim = (width, height)
23
+ resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
24
+
25
+ imgray = cv2.cvtColor(resized, cv2.COLOR_BGR2GRAY)
26
+ blurred = cv2.GaussianBlur(imgray, (5, 5), 0)
27
  (_, thresh) = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)
 
 
28
  contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
29
 
30
  # take only the largest contour
 
49
 
50
  t_list = np.linspace(0, tau, len(xs))
51
 
52
+ # compute the Fourier coefficients
53
  def f(t, t_list, xs, ys):
54
  return np.interp(t, t_list, xs + 1j*ys)
55
 
 
94
 
95
  draw_x.append(center[0])
96
  draw_y.append(center[1])
97
+
98
+ if i > 0:
99
+ drawing.set_data([draw_x[i-1], draw_x[i]], [draw_y[i-1], draw_y[i]])
100
+ else:
101
+ drawing.set_data(draw_x[i], draw_y[i])
102
 
103
  drawing_time = 1
104
  time = np.linspace(0, drawing_time, num=frames)