当前位置:网站首页>Transferring images using flask
Transferring images using flask
2022-07-03 05:16:00 【Qianyu QY】
client :
import requests
import os
import cv2
import time
import base64
url = "http://180.201.5.153:1212"
filename = '13_rgb.png'
start_time = time.time()
# Read images
img = cv2.imread(filename)
# The encoded image is bytes
success, encoded_image = cv2.imencode(".jpg", img)
img_bytes = encoded_image.tobytes()
img_bytes = base64.b64encode(img_bytes)
img_bytes = img_bytes.decode('ascii')
# Upload image Waiting for feedback
data = {
'img': img_bytes}
r = requests.post(url, data=data)
result = r.text
print(result)
sum_t = time.time() - start_time
print('sum time: ', sum_t)
Server side
# -*- coding: UTF-8 -*-
from flask import request, Flask
import os
import cv2
import torch
import base64
import math
import numpy as np
from sgdn.sgdn import SGDN
app = Flask(__name__)
@app.route("/", methods=['POST'])
def get_frame():
img = request.form.get('img')
if img:
# Decode image data
img = base64.b64decode(img.encode('ascii'))
image_data = np.fromstring(img, np.uint8)
image_data = cv2.imdecode(image_data, cv2.IMREAD_COLOR)
print(image_data.shape)
cv2.imwrite('/home/wangdx/research/mir_robot/grasp_server/1.png', image_data)
toClient = str({
'cls': 1})
print("success")
return toClient
else:
return 'failed'
if __name__ == "__main__":
app.run("0.0.0.0", port=1212)
边栏推荐
- [research materials] 2021 China's game industry brand report - Download attached
- leetcode452. Detonate the balloon with the minimum number of arrows
- Web APIs exclusivity
- How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in
- 【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
- (subplots usage) Matplotlib how to draw multiple subgraphs (axis field)
- Disassembly and installation of Lenovo r7000 graphics card
- XML Configuration File
- Configure and use Anaconda environment in pycharm
- Hotel public broadcasting background music - Design of hotel IP network broadcasting system based on Internet +
猜你喜欢
【实战项目】自主web服务器
Skip table: principle introduction, advantages and disadvantages of skiplist
Detailed explanation of yolov5 training own data set
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)
SSM framework integration
Botu uses peek and poke for IO mapping
Online VR model display - 3D visual display solution
Overview of basic knowledge of C language
2022-02-12 daily clock in: problem fine brush
随机推荐
Unity tool Luban learning notes 1
联想R7000显卡的拆卸与安装
XML配置文件
编译GCC遇到的“pthread.h” not found问题
Go practice -- factory mode of design patterns in golang (simple factory, factory method, abstract factory)
Configure and use Anaconda environment in pycharm
2022-02-12 daily clock in: problem fine brush
Introduction to deep learning (II) -- univariate linear regression
Notes | numpy-08 Advanced index
Based on RFC 3986 (unified resource descriptor (URI): general syntax)
leetcode860. Lemonade change
[set theory] relational power operation (relational power operation | examples of relational power operation | properties of relational power operation)
在PyCharm中配置使用Anaconda环境
JS scope
Deep embedding and alignment of Google | protein sequences
Botu uses peek and poke for IO mapping
Audio Focus Series: write a demo to understand audio focus and audiomananger
Technical analysis of qianyuantong multi card aggregation router
SSM framework integration
es7创建索引容易犯的错误