---
# System prepended metadata

title: 程式碼

---

# 程式碼

```python=
import numpy as np
import matplotlib.pyplot as plt

import pywt
import pywt.data


# Load image
original = cv2.imread('US8925303B2.png', 0)

# Wavelet transform of image, and plot approximation and details
titles = ['Approximation', ' Horizontal detail',
          'Vertical detail', 'Diagonal detail']
coeffs2 = pywt.dwt2(original, 'bior1.3')
LL, (LH, HL, HH) = coeffs2
fig = plt.figure(figsize=(20, 20))
for i, a in enumerate([LL, LH, HL, HH]):
    ax = fig.add_subplot(1, 4, i + 1)
    ax.imshow(a, interpolation="nearest", cmap='gray')
    ax.set_title(titles[i], fontsize=10)
    ax.set_xticks([])
    ax.set_yticks([])

fig.tight_layout()
plt.show()
```
![](https://i.imgur.com/mqth97J.png)

detect 影片程式碼
```python=
import cv2
import numpy as np
from PIL import Image
import timeit
log_dir="/content/gdrive/My Drive/Data/keras-yolo3/logs/000/"
classes_path = '/content/gdrive/My Drive/Data/keras-yolo3/class.txt'

# %cd '/content/gdrive/My Drive/Day050/keras-yolo3-master/'
yolo_model = YOLO(model_path=log_dir + 'trained_weights_final.h5', classes_path=classes_path)

starttime = timeit.default_timer()
cap = cv2.VideoCapture('/content/Raccoon.mp4')

# 使用 XVID 編碼
fourcc = cv2.VideoWriter_fourcc(*'XVID')

# 建立 VideoWriter 物件，輸出影片至 output.avi
# FPS 值為 30.0，解析度為 1280*720
out = cv2.VideoWriter('raccoon.avi', fourcc, 30.0, (1280, 720))

# k = 0
# while(cap.isOpened()):
#     ret, frame = cap.read()
#     if ret == True:
#         # 寫入影格
#         image = Image.fromarray(frame)
#         image = np.array(yolo_model.detect_image(image))
#         out.write(image)
#         k += 1
#     else:
#         break
    
# 釋放所有資源
cap.release()
out.release()

print('共耗時:',round((timeit.default_timer() - starttime), 2), '秒，FPS:', round(k/(timeit.default_timer() - starttime), 2))
```

```python=

```


```python=

```

```python=

```

```python=

```