- 方式一,从本地读取到图片或帧,上传到flask服务器
def image_post():
data = {"type_code": type_code,
"area_id": area_id}
file = {"file": ("file_name.jpg",open("file_path", 'rb'), "image/jpg")}
res = requests.post(url=post_url, files=file, data=data)
@recognize.route("/save_scene", methods=['post'])
def save_scene():
type_code = request.form.get("type_code")
type_code = int(type_code)
area_id = request.form.get("area_id")
area_id = int(area_id)
scene_img = request.files["scene_img"]
dir_name = os.path.join(all_scene_picture_dir, type_code_d[type_code])
scene_picture_name = str(t) + '.jpg'
scene_picture_path = os.path.join(scene_picture_dir, scene_picture_name)
scene_img.save(scene_picture_path)
return “200”
- 方式二,从opencv图片或帧对象转换为二进制文件上传
def image_post():
data = {"type_code": type_code,
"area_id": area_id}
file = {"file": ("file_name.jpg", cv2.imencode(".jpg", frame)[1].tobytes(), "image/jpg")}
res = requests.post(url=post_url, files=file, data=data)
@recognize.route("/save_scene", methods=['post'])
def save_scene():
type_code = request.form.get("type_code")
type_code = int(type_code)
area_id = request.form.get("area_id")
area_id = int(area_id)
scene_img = request.files["scene_img"]
dir_name = os.path.join(all_scene_picture_dir, type_code_d[type_code])
scene_picture_name = str(t) + '.jpg'
scene_picture_path = os.path.join(scene_picture_dir, scene_picture_name)
scene_img.save(scene_picture_path)
return “200”