虛擬主機創建虛擬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.pswp.cn/news/388716.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388716.shtml
英文地址,請注明出處:http://en.pswp.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…