其他
来了!新一代 App 视觉增强辅助方案它真的来了!
项目介绍
项目初心
主要功能
接受前端图像数据并进行深度预测
from PIL import Image
import base64
from io import BytesIO
def parse_img(url):
url = url.split(',')[1]
data = base64.decodebytes(url.encode())
return Image.open(BytesIO(data))
from sanic import Sanic
from sanic.response import json
from sanic_cors import CORS, cross_origin
app = Sanic()
CORS(app)
@app.route("/")
async def test(request):
return json({"hello": "world"})
@app.route("/json", methods=['POST', 'OPTIONS'])
def post_json(request):
ret = None
try:
img = parse_img(request.json['answer']).transpose(Image.ROTATE_90)
img.save('target_network.bmp')
except:
return json({ "received": True, "message": request.json })
ret = predict_depth(img, True, True)
返回预测的depth map
raw_data = base64.encodebytes(ret)
return json({ "received": True, "message": 'data:image/jpg;base64,' + raw_data.decode()})
Web端对视频数据的预处理
const width = video.videoWidth, height = video.videoHeight
canvas.width = width
canvas.height = height
context.drawImage(video, 0, 0, width, height)
const data = canvas.toDataURL('image/png')
if (data.indexOf('base64') != -1) {
result.style="position: absolute;left: 0;top: 0;width: 100vw;height: 100vh;background:white"
postData(`${api_entrypoint}/json`, {answer: data})
.then(data => {
console.log(data)
resultimg.src = data.message
cont()
})
.catch(error => {
console.error(error)
cont()
})
} else {
cont()
}
连接到Agora提供的RTC服务
client = AgoraRTC.createClient({mode: 'live'});
client.init(appId.value, function () {
client.join(channel_key, channel.value, null, function(uid) {
camera = videoSource.value;
localStream = AgoraRTC.createStream({streamID: uid, cameraId: camera, video: true, screen: false});
})
});
未来展望
开源链接
Repo:https://github.com/AgoraIO-Community/2019-Hackathon-Works-Vision-Enhancement-Guidoge 编译与运行指南已附在GitHub Repo中。 作者姚沧力:上海科技大学FemtoTech工作室创始人之一,全栈开发者,热衷视频创作和各类新兴技术,现于声网 Agora 实习。
姚沧力主页:https://github.com/nekowink
作者张启煊:上海科技大学GeekPie社团社长,MARS实验室成员,热衷于计算机视觉与区块链技术。
张启煊主页:https://github.com/eEhyQx
One More Thing
最后由声网 Agora 主办的 RTC 2020 编程挑战赛春季赛已经开启报名了!本次大赛准备了丰厚的大奖,获奖者更有机会进入声网 Agora 应聘快速通道,快拉上小伙伴报名吧!
点击「阅读原文」,报名参赛