---
# System prepended metadata

title: 2022/08/04 偏鄉醫療進度報告
tags: [偏鄉醫療進度報告]

---

---
tags: 偏鄉醫療進度報告
---

# 2022/08/04 偏鄉醫療進度報告
> 林興政、劉彥汝

    1.找交感神經（LF、HF）、分析HRV的論文
    2.做rPPG(臉部量心跳)
    3.套heartpy

### 1. 交感神經的論文(LF、HF)、分析HRV的論文
**論文1**：從自主神經彈性觀點探討類廣泛性焦慮疾患和高特質焦慮的自主神經反應、注意控制與情緒調節
[論文1](https://hdl.handle.net/11296/57v9p2)
[論文1整理](https://hackmd.io/y1cSQPXkRMmIET-90jaAxw?view)

**論文2**：使用心率變異性作為正常與心血管疾病之評估工具
[論文2整理](https://hackmd.io/LbQvnQqBSDuMc95EMhlRkA?view)

**論文3**：基於PPG訊號進行飲酒辨識
[論文3](https://hdl.handle.net/11296/vu2sqx)
[論文3整理](https://hackmd.io/3DTKzWR6RZ61FSSNlgmgew?view)

### 2. 臉部量測心跳
[連結](https://hackmd.io/5vPl-Iv-S2aEcXDWyWQDWQ?view)

### 3. 套heartpy
**整理原有程式碼:**
> - 新增了採樣頻率的function，以便計算心率
> - 註解掉的地方為套用Heartpy分析時使用
```python
import cv2
import numpy as np
#import matplotlib.pyplot as plt
#import heartpy as hp

#轉影片至圖片
def get_images_from_video(video_name, time_F):
    video_images = []
    vc = cv2.VideoCapture(video_name)
    c = 1    
    if vc.isOpened(): #判斷是否開啟影片
        rval, video_frame = vc.read()
    else:
        rval = False
    while rval:   #擷取影片至結束
        rval, video_frame = vc.read()
        if(c % time_F == 0): #每隔幾幀進行擷取
            video_images.append(video_frame)   
        c = c + 1
    vc.release()
    cv2.destroyAllWindows    
    return video_images

#轉圖片至灰階
def trans_img2gray(video_images):
    for i in range(0, len(video_images) - 1): # 顯示出所有擷取之圖片並儲存進screenshot
        bgr2gray = cv2.cvtColor(video_images[i], cv2.COLOR_BGR2GRAY)    # 轉成灰階 -> 較好分析
        cv2.imwrite('./screenshot/output' + str(i + 1) + '.jpg', bgr2gray, [cv2.IMWRITE_JPEG_QUALITY, 100])
    return bgr2gray

#計算採樣頻率(單位:Hz)    
def get_rate(video_name, video_images):
    cap = cv2.VideoCapture(video_name)
    if cap.isOpened():
        rate = cap.get(5)
        Fnumber = cap.get(7)
        duration = Fnumber/rate   
        getrate = len(video_images) / duration
    return getrate

#算出每一張照片的灰階平均值
def average_pixel(blood_img):
    r, c = blood_img.shape[:2]
    average = 0
    for row in blood_img:
        for column in row:
            average = average + column

    average = average / (r * c) * 1.0
    #average = format(average, '.2f')
    return average

def getdata(video_images):
    gray_value = np.array([])
    for i in range(1, len(video_images)):
        blood_img = cv2.imread('./screenshot/output' + str(i) + '.jpg', cv2.IMREAD_GRAYSCALE)
        gray_value = np.append(gray_value, float(average_pixel(blood_img)) * 10)
    return gray_value

def allprocess(video_name):
    time_F = 1  # time_F越小，取樣張數越多
    video_images = get_images_from_video(video_name, time_F)  # 讀取影片並轉成圖片
    #rate = get_rate(video_name, video_images)
    video_images = trans_img2gray(video_images)
    data = getdata(video_images)
    #wd, m = hp.process(data, rate)
    #plt.figure(figsize=(12,4))
    #hp.plotter(wd, m)
    #for measure in m.keys():
        #print('%s: %f' %(measure, m[measure]))
    return data
```
![](https://i.imgur.com/Xp0v118.jpg)
<br>
**結論：不是套不進去，而是heartpy認為訊號不佳無法判斷，所以heartpy可能無法使用，但有些觀念可以參考看看**
