虚拟主机创建虚拟lan_创建虚拟背景应用

虚拟主机创建虚拟lan

This is the Part 2 of the MediaPipe Series I am writing.

这是我正在编写的MediaPipe系列的第2部分。

Previously, we saw how to get started with MediaPipe and use it with your own tflite model. If you haven’t read it yet, check it out here.

以前,我们了解了如何开始使用MediaPipe并将其与您自己的tflite模型一起使用。 如果您尚未阅读,请在此处查看 。

We had tried using the portrait segmentation tflite model in the existing segmentation pipeline with the calculators already present in MediaPipe

我们尝试在现有的细分管道中使用人像细分tflite模型,并在MediaPipe中使用计算器

After getting bored with this Blue Background, I decided to have some fun with it by having some Zoom like Virtual Backgrounds like beautiful stars or some crazy clouds instead :)

在厌倦了这种蓝色背景后,我决定通过一些缩放(例如虚拟背景(例如美丽的星星或一些疯狂的云))来玩一些它:)

Image for post
Virtual Clouds Background — PART 2
虚拟云背景-第2部分

For this, I wrote a custom calculator and used it with the existing pipeline.

为此,我编写了一个自定义计算器,并将其与现有管道一起使用。

So today I’ll show how did I go about making this App

所以今天我将展示如何制作此应用程序

Before we get started, I would suggest you to go through this part of the documentation which explains the Flow of a basic calculator.

在我们开始之前,我建议您仔细阅读本文档的这一部分,其中介绍了基本计算器的流程。

https://google.github.io/mediapipe/framework_concepts/calculators.html

https://google.github.io/mediapipe/framework_concepts/calculators.html

Now, let’s get started with the code

现在,让我们开始使用代码

1.从Part1克隆Portrait Segmentation存储库 (1. Clone the Portrait Segmentation repository from Part1)

$ git clone https://github.com/SwatiModi/portrait-segmentation-mediapipe.git

2.管道的新流程(在图.pbtxt文件中进行更改) (2. New Flow of the Pipeline (making changes in the graph .pbtxt file))

So earlier, the rendering/coloring was done by the RecolorCalculator , it used to take image and mask gpu buffer as input and returned gpu buffer rendered output (rendered using opengl)

因此,较早之前,渲染/着色是由RecolorCalculator完成的它用于将图像和蒙版gpu缓冲区作为输入,并返回gpu缓冲区渲染的输出(使用opengl渲染)

Here, for replacing the Background with an Image(jpg/png), I have used OpenCV operations.

在这里,为了用Image(jpg / png)替换Background,我使用了OpenCV操作。

NOTE : OpenCV operations are performed on CPU — ImageFrame datatype where as opengl operations are performed on GPU — Image-buffer datatype

注意 :OpenCV操作在CPU — ImageFrame数据类型上执行,而opengl操作在GPU —图像缓冲区数据类型上执行

portrait_segmentation.pbtxt

portrait_segmentation.pbtxt

We will replace the RecolorCalculator with the BackgroundMaskingCalculator

我们将 BackgroundMaskingCalculator 替换 RecolorCalculator

node {
calculator: "BackgroundMaskingCalculator"
input_stream: "IMAGE_CPU:mask_embedded_input_video_cpu"
input_stream: "MASK_CPU:portrait_mask_cpu"
output_stream: "OUTPUT_VIDEO:output_video_cpu"
}

This calculator takes transformed Image and the Mask (Both ImageFrame Datatype) as input and changes the background with given image.

该计算器将转换后的图像和蒙版(两个ImageFrame数据类型)作为输入,并使用给定图像更改背景。

For converting the Image and Mask GpuBuffer to ImageFrame, I used the GpuBufferToImageFrameCalculator.

为了将Image和Mask GpuBuffer转换为ImageFrame,我使用了GpuBufferToImageFrameCalculator。

3.写入计算器文件(background_masking_calculator.cc文件) (3. Write the Calculator File (background_masking_calculator.cc file))

In this we will write the logic of processing and creating the background masking effect

在本文中,我们将编写处理和创建背景遮罩效果的逻辑

background_masking_calculator.cc

background_masking_calculator.cc

place this background_masking_calculator.cc in mediapipe/calculators/image/

放置这个background_masking_calculator.cc mediapipe /计算器/图像/

a. Extending the Base Calculator

一个。 扩展基础计算器

b. GetContract()

b。 GetContract()

Here we are just verifying our inputs and their data types

在这里,我们只是在验证我们的输入及其数据类型

c. Open()

C。 打开()

Prepares the calculator’s per-graph-run state.

准备计算器的每图运行状态。

d. Process()

d。 处理()

Small overview of the Process() method in background_masking_calculator
background_masking_calculator中的Process()方法的简要概述

Taking the inputs, converting to OpenCV Mat and further processing for desired output

接收输入,转换为OpenCV Mat并进一步处理以获得所需的输出

4.将background_masking_calculator.cc添加到具有依赖项的图像文件夹的BUILD文件中 (4. Add the background_masking_calculator.cc to BUILD file of image folder with the dependencies)

BUILD file in mediapipe/calculators/image

Mediapipe / calculators / image中的 BUILD文件

We need to do this so the calculator is available and accessible while compilation and execution

我们需要这样做,以便计算器在编译和执行时可用并且可访问

the deps (dependencies) you see here are the imports you are using in your calculator

您在此处看到的Deps(依赖项)是您在计算器中使用的导入

The name used here is referred in graph BUILD file as well

图BUILD文件中也引用了此处使用的名称

5.将background_masking_calculator.cc添加到图形BUILD文件中 (5. Add the background_masking_calculator.cc to the graph BUILD file)

BUILD file in graphs/portrait_segmentation

图形/ portrait_segmentation中的BUILD文件

Add background_masking_calculator to deps and remove recolor_calculator which we are not using now

background_masking_calculator添加到deps并删除我们现在不使用的recolor_calculator

Now we are ready to build, we just have to add the asset(image to be masked on the background)

现在我们准备好构建,我们只需要添加资产(要在背景上遮盖的图像)

NOTE: This asset reading method is straight forward when trying on Desktop but quite different for the Android Build.

注意 :在桌面上尝试时,这种资产读取方法很简单,但对于Android Build则大不相同。

So we will look at the Desktop and Android build one by one

因此,我们将逐一研究台式机和Android

桌面版本: (Desktop Build:)

In the background_masking_calculator.cc , read the asset file as

在background_masking_calculator.cc中,将资产文件读取为

Now, we are ready to build

现在,我们准备建立

Image for post
bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11  mediapipe/examples/desktop/portrait_segmentation:portrait_segmentation_gpu

The build will finish successfully in around 10–15 minutes

构建将在大约10-15分钟内成功完成

INFO: Build completed successfully, 635 total actions

Now, you can run the Pipeline using the following

现在,您可以使用以下命令运行管道

GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/portrait_segmentation/portrait_segmentation_gpu   --calculator_graph_config_file=mediapipe/graphs/portrait_segmentation/portrait_segmentation.pbtxt

the webcam starts and you’ll be able to see the output window

网络摄像头启动,您将能够看到输出窗口

Image for post
Virtual Background App — Desktop Build
虚拟背景应用程序-桌面构建

Android版本: (Android Build:)

1.导出背景遮罩图像 (1. Exporting the background masking images)

Add the following code to the BUILD file in testdata folder (folder containing the background asset images)

将以下代码添加到testdata文件夹(包含背景资产图像的文件夹)中的BUILD文件中

exports_files(
srcs = glob(["**"]),
)

2.将资产添加到Android应用程序使用的android_library (2. Adding the assets to android_library used by the Android App)

Adding the files to android_library along with the tflite model

将文件与tflite模型一起添加到android_library

Modify in android project BUILD file in examples/android/…./portraitsegmentationgpu/

examples / android /…。/ portraitsegmentationgpu /中的android项目BUILD文件中进行修改

3.在background_masking_calculator中读取此图像文件 (3. Reading this image file in background_masking_calculator)

Here, first using the MediaPipe’s PathToResourceAsFile method, we try to look if the asset is available and if available we read it using it’s value as path to file

在这里,首先使用MediaPipe的PathToResourceAsFile方法,尝试查看资产是否可用,如果可用,我们将其值用作文件路径来读取资产

On a side note, this method was a part of resource_util.h present in mediapipe/util/ folder. So whenever you import a new file into your calculator, make sure to add it to BUILD file mentioned in pt. 4

另外,此方法是存在于mediapipe / util /文件夹中的resource_util.h的一部分。 所以每当你导入一个新的文件到您的计算器,请务必将其添加 PT提到的BUILD文件 4

现在我们准备构建APK (Now we are ready to Build the APK)

Image for post
# BUILD 
bazel build -c opt --config=android_arm64 mediapipe/examples/android/src/java/com/google/mediapipe/apps/portraitsegmentationgpu# On successfully building the APK, it printsINFO: Elapsed time: 1499.898s, Critical Path: 753.09s
INFO: 2002 processes: 1849 linux-sandbox, 1 local, 152 worker.
INFO: Build completed successfully, 2140 total actions

This would take around 20–25 minutes when building for the first time because it downloads all the external dependencies for the Build. Next time it uses the cached dependencies, so it builds much faster.

首次构建时大约需要20-25分钟,因为它会下载Build的所有外部依赖项。 下次使用缓存的依赖项时,它的构建速度要快得多。

# INSTALL
adb install bazel-bin/mediapipe/examples/android/src/java/com/google/mediapipe/apps/portraitsegmentationgpu/portraitsegmentationgpu.apk

Now, you are ready to run the APK and test it.

现在,您可以运行APK并进行测试了。

Image for post
Virtual Background App — Android Build
虚拟背景应用程序-Android构建

Here we successfully added our own calculator and modified the pipeline and graph according by first testing it on Desktop and then finally on Android with minimal changes.

在这里,我们成功地添加了自己的计算器,并通过首先在桌面上对其进行测试,然后以最小的更改最终在Android上对其进行了修改,从而修改了管道和图形。

Feel free to ask any questions in the comments or you can reach me out personally.

随时问评论中的任何问题,或者您可以亲自与我联系。

You can find more about me on swatimodi.com

您可以在swatimodi.com上找到有关我的更多信息

翻译自: https://towardsdatascience.com/custom-calculators-in-mediapipe-5a245901d595

虚拟主机创建虚拟lan

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388716.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

.net程序员安全注意代码及服务器配置

概述 本人.net架构师,软件行业为金融资讯以及股票交易类的软件产品设计开发。由于长时间被黑客攻击以及骚扰。从事高量客户访问的服务器解决架构设计以及程序员编写指导工作。特此总结一些.net程序员在代码编写安全以及服务器设置安全常用到的知识。希望能给对大家…

文件的读写及其相关

将软件布置在第三方电脑上会出现无法提前指定绝对路径的情况,这回影响到后续的文件读写;json文件是数据交换的一种基本方法,为了减少重复造轮子,经行标准化代码。关于路径: import os workspaceos.getcwd() pathos.pat…

接口测试框架2

现在市面上做接口测试的工具很多,比如Postman,soapUI, JMeter, Python unittest等等,各种不同的测试工具拥有不同的特色。但市面上的接口测试工具都存在一个问题就是无法完全吻合的去适用没一个项目,比如数据的处理,加…

python 传不定量参数_Python中的定量金融

python 传不定量参数The first quantitative class for vanilla finance and quantitative finance majors alike has to do with the time value of money. Essentially, it’s a semester-long course driving notions like $100 today is worth more than $100 a year from …

axis为amchart左右轴的参数

<axis>left</axis> <!-- [left] (left/ right) indicates which y axis should be used --> <title>流通股</title> <!-- [] (graph title) --> <…

雷军宣布红米 Redmi 品牌独立,这对小米意味着什么?

雷锋网消息&#xff0c;1 月 3 日&#xff0c;小米公司宣布&#xff0c;将在 1 月 10 日召开全新独立品牌红米 Redmi 发布会。从小米公布的海报来看&#xff0c;Redmi 品牌标识出现的倒影中&#xff0c;有 4800 的字样&#xff0c;这很容易让人联想起此前小米总裁林斌所宣布的 …

JAVA的rotate怎么用,java如何利用rotate旋转图片_如何在Java中旋转图形

I have drawn some Graphics in a JPanel, like circles, rectangles, etc.But I want to draw some Graphics rotated a specific degree amount, like a rotated ellipse. What should I do?解决方案If you are using plain Graphics, cast to Graphics2D first:Graphics2D …

贝叶斯 朴素贝叶斯_手动执行贝叶斯分析

贝叶斯 朴素贝叶斯介绍 (Introduction) Bayesian analysis offers the possibility to get more insights from your data compared to the pure frequentist approach. In this post, I will walk you through a real life example of how a Bayesian analysis can be perform…

vs2005 vc++ 生成非托管的 不需要.net运行环境的exe程序方法

在VS2005里开发的VC程序在编译的时候&#xff0c;微软默认会加入自己的 .Net Framework &#xff08;方便推广自家产品&#xff09;&#xff0c;让你的VC程序依赖它&#xff0c;这就导致程序编译后&#xff0c;无法跟往常一样直接打包&#xff0c;在别的机器就能正常运行。如果…

西工大java实验报告给,西工大数字集成电路实验 实验课6 加法器的设计

西工大数字集成电路实验练习六 加法器的设计一、使用与非门(NAND)、或非门(NOR)、非门(INV)等布尔逻辑器件实现下面的设计。1、仿照下图的全加器&#xff0c;实现一个N位的减法器。要求仿照图1画出N位减法器的结构。ABABABAB0123图1 四位逐位进位加法器的结构2、根据自己构造的…

DS二叉树--二叉树之数组存储

二叉树可以采用数组的方法进行存储&#xff0c;把数组中的数据依次自上而下,自左至右存储到二叉树结点中&#xff0c;一般二叉树与完全二叉树对比&#xff0c;比完全二叉树缺少的结点就在数组中用0来表示。&#xff0c;如下图所示 从上图可以看出&#xff0c;右边的是一颗普通的…

VS IIS Express 支持局域网访问

使用Visual Studio开发Web网页的时候有这样的情况&#xff1a;想要在调试模式下让局域网的其他设备进行访问&#xff0c;以便进行测试。虽然可以部署到服务器中&#xff0c;但是却无法进行调试&#xff0c;就算是注入进程进行调试也是无法达到自己的需求&#xff1b;所以只能在…

前复权后复权程序C# .net

if (win32apitest.MDIMain.SFSDA.FuQuan "前复权") { if (mytime DateTime.Parse("2009-04-29")) { //if (svalue 34.89) …

一天一个js知识

原型继承和class继承 class&#xff1a;js中并不存在类的概念&#xff0c;class只是语法糖&#xff0c;本质还是函数&#xff1b; 提升&暂时性死区 console.log(a)// ƒ a() {} var a8 function a(){} 复制代码 1、这里说明函数的提升要优先于变量的提升&#xff1b;函数提…

构建图像金字塔_我们如何通过转移学习构建易于使用的图像分割工具

构建图像金字塔Authors: Jenny Huang, Ian Hunt-Isaak, William Palmer作者&#xff1a; 黄珍妮 &#xff0c; 伊恩亨特伊萨克 &#xff0c; 威廉帕尔默 GitHub RepoGitHub回购 介绍 (Introduction) Training an image segmentation model on new images can be daunting, es…

PHP mongodb运用,MongoDB在PHP下的应用学习笔记

1、连接mongodb默认端口是&#xff1a;27017&#xff0c;因此我们连接mongodb&#xff1a;$mongodb new Mongo(localhost) 或者指定IP与端口 $mongodb new Mongo(192.168.127.1:27017) 端口可改变若mongodb开启认证&#xff0c;即--auth,则连接为&#xff1a; $mongodb new …

a标签

a标签定义超链接&#xff0c;用于从一张页面链接到另一张页面&#xff0c;它最重要的属性是 href 属性&#xff0c;它指示链接的目标。 <a href"http://www.w3school.com.cn">W3School</a> 最常用的就像这样添加一个链接&#xff0c;如果是点击事件的话&…

MFC程序执行过程剖析

一 MFC程序执行过程剖析 1&#xff09;我们知道在WIN32API程序当中&#xff0c;程序的入口为WinMain函数&#xff0c;在这个函数当中我们完成注册窗口类&#xff0c;创建窗口&#xff0c;进入消息循环&#xff0c;最后由操作系统根据发送到程序窗口的消息调用程序的窗口函数。而…

CF888E Maximum Subsequence(meet in the middle)

给一个数列和m&#xff0c;在数列任选若干个数&#xff0c;使得他们的和对m取模后最大&#xff08; \(1<n<35\) , \(1<m<10^{9}\)&#xff09; 考虑把数列分成两份&#xff0c;两边分别暴力求出所有的可能&#xff0c;那么对于一个数列中每一个数字\(x\)&#xff0…

virtualbox php mac,详解mac下通过docker搭建LEMP环境

在mac下通过docker搭建LEMP环境境1.安装virtualbox。由于docker是在lxc环境的容器2.安装boot2docker&#xff0c;用于与docker客户端通讯> brew update> brew install docker> brew install boot2docker3.初始化boot2docker&#xff0c;也就是在virtualbox上安装一个d…