commit 0d54e572b07436e10c1e89eab3045396d335dabb Author: 威勝 張 Date: Sun Oct 20 12:55:37 2024 +0800 img_up diff --git a/img/圖片1.png b/img/圖片1.png new file mode 100644 index 0000000..5413ab4 Binary files /dev/null and b/img/圖片1.png differ diff --git a/img/圖片2.png b/img/圖片2.png new file mode 100644 index 0000000..d6eb787 Binary files /dev/null and b/img/圖片2.png differ diff --git a/img/圖片3.png b/img/圖片3.png new file mode 100644 index 0000000..ffae741 Binary files /dev/null and b/img/圖片3.png differ diff --git a/img/圖片4.png b/img/圖片4.png new file mode 100644 index 0000000..ca90a3b Binary files /dev/null and b/img/圖片4.png differ diff --git a/img/圖片5.png b/img/圖片5.png new file mode 100644 index 0000000..45757e3 Binary files /dev/null and b/img/圖片5.png differ diff --git a/test_1020_api/img.jpg b/test_1020_api/img.jpg new file mode 100644 index 0000000..b3c7e43 Binary files /dev/null and b/test_1020_api/img.jpg differ diff --git a/test_1020_api/test_1020.py b/test_1020_api/test_1020.py new file mode 100644 index 0000000..6892592 --- /dev/null +++ b/test_1020_api/test_1020.py @@ -0,0 +1,120 @@ +import time +from datetime import datetime +from requests.structures import CaseInsensitiveDict +import os,base64 +import threading +import json +import pandas as pd +import requests +import cv2 + +# 寫進WEBAPI +#request_url = "https://localhost:7205" +request_url = "http://211.22.135.143:7500" +class Restful_api(): + def __init__(self, Fun, headers, *args): + self.headers = headers + self.Fun = Fun + + def post(self, data): + data_json = json.dumps(data) + response = requests.post(request_url + self.Fun, data=data_json, headers=self.headers, verify=False) + return response + + def get(self): + response = requests.get(request_url + self.Fun, headers=self.headers, verify=False) + if response.status_code == 200: + data = response.json() + df = pd.DataFrame.from_records(data) + return df + else: + return + + def put(self,data): + data_json = json.dumps(data) + response = requests.put(request_url + self.Fun, data=data_json, headers=self.headers, verify=False) + return response + + def delete(self): + response = requests.delete(request_url + self.Fun, headers=self.headers, verify=False) + return response + + def getSingleData(self): + response = requests.get(request_url + self.Fun, headers=self.headers, verify=False) + if response.status_code == 200: + data = response.json() + df = pd.DataFrame.from_records(data, index=[0]) + return df + else: + return + + +class Tongue_api(): + + def post_new_data(self,data): + API = "/api/Tongue_analysis_tw_1" + headers = {'Content-type': 'application/json'} + response =Restful_api(API, headers).post(data) + return response + + def check_data(self,img_name): + API = "/api/Tongue_analysis_detail/img_name-"+img_name + headers = CaseInsensitiveDict(); + headers['Accept'] = 'application/json' + data = Restful_api(API, headers).get() + return data + + def get_data(self,img_name): + API = "/api/Tongue_analysis_detail/" + img_name + headers = CaseInsensitiveDict(); + headers['Accept'] = 'application/json' + data = Restful_api(API, headers).getSingleData() + return data + + +#圖片 轉 base64 +def img_to_base64(image): + if image is None: + return "None" + _, buffer = cv2.imencode('.jpg', image) + data = base64.b64encode(buffer).decode('utf-8') + data = "data:image/jpeg;base64," + data + + return data + + +img = cv2.imread("img.jpg") # 讀取圖片 +img_base64 = img_to_base64(img) # 轉base64 + + +# 圖片名稱定義 +img_name = f'1{datetime.now().strftime("%Y%m%d%H%M%S")}' +print(img_name) + +# 上傳資料整理 +up_load_data = { + "img_name": img_name, + "test_id": "1", + "test_analyst": " ", + "test_time": " ", + "test_date": " ", + "img": img_base64, + "data_creat_time": "2023-01-11T12:53:25.381Z", +} +API = Tongue_api() +# 上傳資料 +res = API.post_new_data(up_load_data) + + +if res.status_code >= 200 and res.status_code < 300: + # 等待運算結果 + while True: + data = API.check_data(f'{img_name}.jpg') + if len(data)>0: + print(data) + break + time.sleep(0.5) + +# 確認運算資料 +img_data = API.get_data(f'{img_name}.jpg') +print(img_data)