Client
- 필요 package :
http
,convert
(내장)
import 'package:http/http.dart' as http;
import 'dart:convert';
postRequest() async {
File imageFile = File(imagePath);
List<int> imageBytes = imageFile.readAsBytesSync();
String base64Image = base64Encode(imageBytes);
print(base64Image);
Uri url = Uri.parse('your_server_ip/test');
http.Response response = await http.post(
url,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
}, // this header is essential to send json data
body: jsonEncode([
{'image': '$base64Image'}
]),
);
print(response.body);
}
주의....!
header 추가 안하면 json 파일 안보내짐....
Server
- 환경 : flask webserver
from flask import Flask, request
import base64
import numpy as np
import cv2
app = Flask(__name__)
@app.route('/test', methods=['POST','GET'])
def test():
base64Image = request.json[0]['image']
imageStr = base64.b64decode(base64Image)
nparr = np.fromstring(imageStr, np.uint8)
img_np = cv2.imdecode(nparr, cv2.IMREAD_COLOR) # cv2.IMREAD_COLOR in OpenCV 3.1
return 'send_complete'
프레임별로 stream만 안하면 반응속도 나쁘지 않음