---
# System prepended metadata

title: '**2021/08/20 (LINE Notify)**'
tags: [藍柏婷, 2021/08/20]

---

# **2021/08/20 (LINE Notify)**

###### tags: `藍柏婷`
###### tags: `2021/08/20`

### **== 將程式碼弄進 jetson nano 試試 ==**
**#輸入**
```p
$ cd Desktop
$ python3 LINE_Notify_2.py
```
**#輸出**
```p
/usr/lib/python3/dist-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.26.6) or chardet (3.0.4) doesn't match a supported version!
  RequestsDependencyWarning)
{"status":200,"message":"ok"}
```
![](https://i.imgur.com/l1QHkLY.jpg)

**#my_detection_3.py**
```python=
import jetson.inference
import jetson.utils
import requests

def send_to_line(category='',pic=''):
    send={  
        'message':("嗨陌生人你用到我們的pincode了 所以傳不到你那邊啦"),
        'imageThumbnail':pic, 
        'imageFullsize':pic,
        } 
    header={
        'Content-Type':'application/x-www-form-urlencoded', 
        'Authorization':'Bearer ' + "gOljwt8lLAnbpWSIXUk3RJP34Syw6NQADBtorl2GoCP" 
        }
    r=requests.post("https://notify-api.line.me/api/notify", headers=header, data=send)
    print(r.text) # {"status":200,"message":"ok"}

net = jetson.inference.detectNet("ssd-mobilenet-v2", threshold=0.5)
camera = jetson.utils.videoSource("/dev/video0")  # usb camera
display = jetson.utils.videoOutput("display://0") # 'my_video.mp4' for file

while True:
	img = camera.Capture()
	detections = net.Detect(img)

	if len(detections)>=1:
		category="book"
		pic='https://memeprod.sgp1.digitaloceanspaces.com/user-wtf/1622455521876.jpg'
		send_to_line(category,pic)

	display.Render(img)
	display.SetStatus("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))
	if not camera.IsStreaming() or not display.IsStreaming():
		break
```

**#裝cv2**
```p
pip install opencv-python
```
**#LINE_Notify_4.py**
```python=
import cv2
import requests

def send_to_line(category,pic):
    params = {'message':"\n嗨，你好\n這是 \"火災警示\" 通知\n請注意!!\n偵測到 \"{0}\" 溫度過高".format(category)} 
    files = {'imageFile': open(pic, 'rb')}
    headers = {'Authorization':'Bearer ' + "gOljwt8lLAnbpWSIXUk3RJP34Syw6NQADBtorl2GoCP"}
    r = requests.post("https://notify-api.line.me/api/notify", headers=headers, params=params, files=files)
    print(r.text)

cap = cv2.VideoCapture(1)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) # 畫面寬度設定為 1920
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080) # 畫面高度設定為 1080
cv2.namedWindow('image_win',flags=cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO | cv2.WINDOW_GUI_EXPANDED)

img_count = 1
while(True):
    ret, frame = cap.read()
    cv2.imshow('image_win',frame) # 更新窗口“image_win”中的圖片 # 不可以刪掉，否則會沒有畫面
    key = cv2.waitKey(1) # 等待按鍵事件發生 等待1ms
    if key == ord('q'): 
        break
    elif key == ord('c'): # 如果c键按下，則進行圖片保存
        cv2.imwrite("{}.png".format(img_count), frame) # 寫入圖片 并命名圖片為 <img_count>.png

        category = "microwave"
        pic = 'C:/Users/藍柏婷/Desktop/Python/{}.png'.format(img_count)
        send_to_line(category,pic)

        img_count += 1

cap.release() # 釋放VideoCapture
cv2.destroyAllWindows() # 銷毀所有的窗口
```
:::success
[**OpenCV读入USB摄像头拍摄的画面**](http://www.1zlab.com/wiki/python-opencv-tutorial/opencv-read-usb-camera-image/) **: 拍攝鏡頭畫面，存成png檔，上傳至line notify**
:::
:::success
**它可以傳圖片了!!!
(原來是多一行`'Content-Type':'application/x-www-form-urlencoded'`)
-> 參考 https://ithelp.ithome.com.tw/questions/10201732**
:::
![](https://i.imgur.com/8vowNUg.jpg)