首页 > 编程语言 >NetCore+Python实现视频上传mediapipe骨骼标注

NetCore+Python实现视频上传mediapipe骨骼标注

时间:2022-12-21 15:25:54浏览次数:48  
标签:__ mediapipe string NetCore Python import json Path using

 

打开网页,选择视频,上传视频,解析完成后播放及视频下载

   

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using sportweb.Utility;
using System;
using System.Collections.Generic;
using System.IO; 

namespace sportweb.Controllers
{
    [Route("api/file/[action]")]
    [ApiController]
    public class FileController : ControllerBase
    {
        private IWebHostEnvironment WebHostEnvironment;

        public FileController(IWebHostEnvironment webHostEnvironment)
        {
            WebHostEnvironment = webHostEnvironment;
        }

        /// <summary>
        /// 上传mp4文件
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public string import([FromForm(Name = "file")] IFormFile formFile)
        {
            if (formFile == null) ResponseUtil.Message(false, "上传文件不能为空");
            string fileExt = Path.GetExtension(formFile.FileName);
            string fileName = Guid.NewGuid().ToString().ToLower() + fileExt;
            string inputFilePath = Path.Combine(WebHostEnvironment.WebRootPath, "input", fileName);
            //inputFilePath = inputFilePath.Replace("\\", "/").Replace("//", "/");

            if (!Directory.Exists(Path.GetDirectoryName(inputFilePath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(inputFilePath));
            }

            string outFileName1 = "out_" + fileName;
            string outPutFilePath1 = Path.Combine(WebHostEnvironment.WebRootPath, "output", outFileName1);
            if (!Directory.Exists(Path.GetDirectoryName(outPutFilePath1)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outPutFilePath1));
            }

            using (var stream = new FileStream(inputFilePath, FileMode.Create))
            {
                formFile.CopyTo(stream);
            }

            Dictionary<string, string> dicData = new Dictionary<string, string>();
            dicData["InputPath"] = inputFilePath;
            dicData["OutputPath"] = outPutFilePath1;

            Utility.HttpMethods.Post(Program.AiUrl, JsonConvert.SerializeObject(dicData));

            // mp4: mp4v转H264
            string outFileName2 = "final_" + outFileName1;
            string outPutFilePath2 = Path.Combine(WebHostEnvironment.WebRootPath, "output", outFileName2);
            string args = $"-i {outPutFilePath1} -c:v libx264 -crf 24 {outPutFilePath2}";
            ProcessHelper.RunProcess(Program.FFmpegPath, args); 

            string accessPath = $"/output/{outFileName2}";

            return ResponseUtil.Message(true, accessPath); 
        }
    }
}
#!/usr/bin/python
# -*- coding:utf-8 -*-

from commondlib.help.ini import *
from commondlib.help.data import *
from commondlib.help.pose import CPoseHelper
from commondlib.help.txt import *
from flask import Flask, abort, request, jsonify
import json

__name__ = '__main__'

__webapi = 8080

app = Flask(__name__)

def init():
    # log
    CTxtHelper.init("restserver")

    CTxtHelper.appendlog("soft start")

    # ini
    status = CIniHelper.getfile("config.ini")
    if not status:
        return False

    node = "systemparam"
    __webapi = CDataHelper.string2int(CIniHelper.read(node, "webapi"))

    return True


@app.route('/test/', methods=['GET'], strict_slashes=False)
def test():
    return jsonify({'code': 0, 'info': "ok", 'errmsg': ""})


@app.route('/pose/', methods=['POST'], strict_slashes=False)
def pose():
    if not request.json or 'InputPath' not in request.json or 'OutputPath' not in request.json:
        abort(400)
    code = 1
    info = "success"
    outmsg = []
    inputPath = request.json['InputPath']
    outputPath = request.json['OutputPath']
    #inputPath = "F:\\SportWeb\\wwwroot\\input\\00ec4451-95d1-4eea-991b-2c7eff332281.mp4" # "pose1.mp4" CDataHelper.fromate_utf(
    #outputPath = "F:\\SportWeb\\wwwroot\\output\\out_00ec4451-95d1-4eea-991b-2c7eff332281.mp4" # "save.mp4" CDataHelper.fromate_utf(
    CPoseHelper.Process(inputPath, outputPath, outmsg)

    errmsg = CDataHelper.list2string(outmsg)
    if not CDataHelper.string_empty(errmsg):
        code = 1000
        info = "fail"
    out = {'code': code, 'info': info, 'errmsg': errmsg}
    CTxtHelper.appendlog("[Info] pose,inputPath:" + inputPath + ",output:" + json.dumps(out))
    return jsonify(out)


if __name__ == '__main__':
    init()
    app.run("0.0.0.0", __webapi, True)

 

标签:__,mediapipe,string,NetCore,Python,import,json,Path,using
From: https://www.cnblogs.com/chen1880/p/16996319.html

相关文章

  • 【Python】关于print()、sys.stdout、sys.stderr的一些理解
    print()方法的语法:print(*objects,sep='',end='\n',file=sys.stdout,flush=False)其中file=sys.stdout的意思是,print函数会将内容打印输出到标准输出流(即sys.......
  • python-网络爬虫-爬取股票数据预测分析
    一、课题研究背景与意义有人把数据比喻为蕴藏能量的煤矿。煤炭按照性质有焦煤、无烟煤、肥煤、贫煤等分类,而露天煤矿、深山煤矿的挖掘成本又不一样。与此类似,大数据并不在......
  • asp.netcore Authentication
    Authenticationisforgettingtheuserinfomationfromcookie/token..Weuse Authenticationlikethis:builder.Services.AddAuthentication("cookie").AddCooki......
  • Electron Mac 打包报 Error: Exit code: ENOENT. spawn /usr/bin/python ENOENT 解决
     Electron项目使用vue-cli-electron-builder创建,原来我的Mac上编译都很正常自从Mac升级到macOSventuraversion13.0.1后打包报错,electron-builder编译dmg......
  • python 文件读写
    1.1文件夹与文件路径d:\python\1.py路径是:d:\python文件是:1.py1.1.1绝对路径与相对路径绝对路径:从根目录开始的路径相对路径:从当前工作目录开始的路径相对路......
  • Go/Python 基于gRPC传输图片
    python程序作为服务端,Go程序作为客户端,基于gPRC进行通信客户端定义proto文件:syntax="proto3";optiongo_package=".;transfer";serviceGreeter{rpcSendI......
  • web自动化selenium+python
      对于每一条selenium脚本,一个http请求会被创建并且发送给浏览器的驱动,浏览器驱动中包含了一个httpserver。用来接收这些请求,httpserver接收到请求后根据请求来具体......
  • Python中利用exec批量生成变量
    转载自:https://blog.csdn.net/qq_41710383/article/details/115758160exec和eval的区别函数概括eval():函数用来执行一个字符串表达式,并返回表达式的值。注意:计算指......
  • Python-实现斐波那契数列
    代码实现如下:#-*-coding:utf-8-*-#定义函数deffab(n):#判断n的有效性ifn<=0:return'传递的参数必须是大于0的正整数!'#当n为1时......
  • python编程实战案例--turtle图案绘制
    1.turtle库基本介绍(1)turtle(海龟库):是python的标准库之一,是python绘图体系的实现具体实现:海龟(画笔)处于画面正中央,当海龟落下,行走的所形成的的轨迹,就是我们所绘制的图案2.turt......