티스토리 뷰

 

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만 안하면 반응속도 나쁘지 않음

'Mobile > Flutter' 카테고리의 다른 글

[Flutter] splash image 추가하기  (0) 2022.04.20
Dart 기본 문법 정리  (1) 2021.08.18
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함