久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將實時鏡頭從攝像機(jī)流式傳輸?shù)?Unity3D

Streaming live footage from camera to Unity3D(將實時鏡頭從攝像機(jī)流式傳輸?shù)?Unity3D)
本文介紹了將實時鏡頭從攝像機(jī)流式傳輸?shù)?Unity3D的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

假設(shè)我有一臺無線攝像機(jī),我想將鏡頭實時傳輸?shù)?Unity.有沒有辦法做到這一點?

Let's say I have a wireless camera that I want to stream footage from to unity in real-time. Is there a way to achieve this?

額外問題:

  • 如果相機(jī)的角度更廣(180 度,甚至 360 度)
  • 如果這是我想與之互動的片段,延遲會有多大的問題
  • 除了常規(guī)鏡頭之外,是否可以發(fā)送更多數(shù)據(jù),例如深度感知(使用深度感知相機(jī))?
  • 我是瘋了還是已經(jīng)這樣做了?

提前致謝

推薦答案

我假設(shè)這是一個帶有以太網(wǎng)端口或 Wi-Fi 的相機(jī),您可以連接到它并從中實時流式傳輸圖像.

I assume this is a camera with Ethernet port or Wi-Fi that you can connect to and stream images from it live.

如果是這樣,那么是的,可以使用 Unity 完成.

If so, then yes, it can be done with Unity.

如何在沒有外部庫的情況下完成:

連接到相機(jī):

1.連接到與相機(jī)相同的本地網(wǎng)絡(luò),或者如果支持unpn,您也可以通過互聯(lián)網(wǎng)連接到它.通常,您需要攝像機(jī)的 IP 和端口來執(zhí)行此操作.假設(shè)攝像機(jī) IP 地址為 192.168.1.5,端口號為 900.要連接的 url 是 http://192.168.1.5:900.

1.Connect to the-same local network with the camera or if unpn is supported, you can also connect to it through internet. Usually, you need the IP and the port of the camera to do this. Let's say that the Camera IP Address is 192.168.1.5 and the port number is 900. The url to connect to is http://192.168.1.5:900.

有時,它只是一個以 .mjpg.bin 結(jié)尾的 url,例如 http://192.168.1.5/mjpg/video.mjpghttp://192.168.1.5/mjpg/video.bin

Sometimes, it is simply an url that ends with .mjpg or .bin such as http://192.168.1.5/mjpg/video.mjpg and http://192.168.1.5/mjpg/video.bin

每臺相機(jī)都是不同的.找到該網(wǎng)址的唯一方法是閱讀其手冊.如果該手冊不可用,請使用其官方應(yīng)用程序連接到它,然后使用 Wireshark 發(fā)現(xiàn)相機(jī)圖像的 url.usernamepassword(如果需要)也可以在手冊中找到.如果沒有,請在 Google 上搜索型號,您需要的所有東西都應(yīng)找到.

Every camera is different. The only way to find the url is to read its manual. If the manual is not available, connect to it with its official Application then use Wireshark to discover the url of the camera Image. The username and the password(if required) can also be found in the manual. If not available, google the model number and everything you need should be found.

從相機(jī)中提取 JPEG:

連接到相機(jī)后,相機(jī)會不斷地向您發(fā)送數(shù)據(jù).您可以掃描這些數(shù)據(jù)并從中檢索圖像.

When connected to the camera, the camera will be sending endless data to you. This data you can scan and retrieve the image from it.

2.搜索 0xFF 后跟 0xD8 的 JPEG 標(biāo)頭.如果這兩個字節(jié)彼此相鄰,則開始讀取字節(jié)并繼續(xù)將它們保存到數(shù)組中.您可以使用 index(int) 變量來計算收到的字節(jié)數(shù).

2.Search for the JPEG header which is 0xFF followed by 0xD8. If these two bytes are next to each other then start reading the bytes and continue to save them to an array. You can use an index(int) variable to keep count of how many bytes you have received.

int counter = 0;
byte[] completeImageByte = new byte[500000];
byte[] receivedBytes = new byte[500000];
receivedBytes[counter] = byteFromCamera;
counter++;

3.從攝像頭讀取數(shù)據(jù)時,檢查接下來的兩個字節(jié)是否是JPEG頁腳,即0xFF后跟0xD9.如果這是真的,那么您已經(jīng)收到了完整的圖像(1 幀).

3.While reading the data from the camera, check if the next two bytes is the JPEG footer which is 0xFF followed by 0xD9. If this is true then you have received the complete image(1 frame).

您的圖像字節(jié)應(yīng)如下所示:

Your image bytes should look something like:

0xFF 0xD8 someotherbytes(數(shù)千個)..... 然后是 0xFF 0xD9

0xFF 0xD8 someotherbytes(thousands of them)..... then 0xFF 0xD9

receivedBytes 復(fù)制到 completeImageByte 變量中,以便以后可以使用它來顯示圖像.將 counter 變量重置為 0.

Copy receivedBytes to the completeImageByte variable so that it can be used to display the image later on. Reset counter variable to 0.

Buffer.BlockCopy(receivedBytes, 0, completeImageByte, 0, counter);
counter = 0;

在屏幕上顯示 JPEG 圖像:

4.將圖像顯示到屏幕

由于您每秒將收到許多圖像,因此我發(fā)現(xiàn)顯示此圖像的最有效方式是使用RawImage 組件.因此,如果您希望它在移動設(shè)備上運行,請不要為此使用 ImageSprite Renderer.

Since you will be receiving many images per second, the most efficient way I found to display this is to use RawImage Component. So, don't use Image or Sprite Renderer for this if you want this to run on mobile devices.

public RawImage screenDisplay;
if(updateFrame){
Texture2D camTexture = new Texture2D(2, 2);
camTexture.LoadImage(completeImageByte);
screenDisplay.texture = camTexture;
}

camTexture = new Texture2D(2, 2); 只需在 Start() 函數(shù)中執(zhí)行一次即可.

You only need to do camTexture = new Texture2D(2, 2); once in the Start() function.

5.跳回步驟2并繼續(xù)執(zhí)行,直到您想要完全為止.

5.Jump back to step 2 and continue doing it until you want to quite.

用于連接相機(jī)的 API:.

如果相機(jī)需要身份驗證(用戶名和密碼),請使用 HttpWebRequest.

Use HttpWebRequest if the camera requires authentication (username and password).

對于不需要身份驗證的用戶,請使用 UnityWebRequest.使用 UnityWebRequest 時,您必須從 派生自己的類DownloadHandlerScript 否則您的應(yīng)用程序?qū)⒈罎ⅲ驗槟鷮⒉煌5亟邮諗?shù)據(jù).

For those that does not require authentication, use UnityWebRequest. When using UnityWebRequest, you must derive your own classes from DownloadHandlerScript or your app will crash as you will be receiving data non stop.

DownloadHandlerScript派生你自己的類的例子:

Example of deriving your own class from DownloadHandlerScript:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class CustomWebRequest : DownloadHandlerScript
{    
    // Standard scripted download handler - will allocate memory on each ReceiveData callback
    public CustomWebRequest()
        : base()
    {
    }

    // Pre-allocated scripted download handler
    // Will reuse the supplied byte array to deliver data.
    // Eliminates memory allocation.
    public CustomWebRequest(byte[] buffer)
        : base(buffer)
    {
    }

    // Required by DownloadHandler base class. Called when you address the 'bytes' property.
    protected override byte[] GetData() { return null; }

    // Called once per frame when data has been received from the network.
    protected override bool ReceiveData(byte[] byteFromCamera, int dataLength)
    {
        if (byteFromCamera == null || byteFromCamera.Length < 1)
        {
            //Debug.Log("CustomWebRequest :: ReceiveData - received a null/empty buffer");
            return false;
        }

        //Search of JPEG Image here

        return true;
    }

    // Called when all data has been received from the server and delivered via ReceiveData
    protected override void CompleteContent()
    {
        //Debug.Log("CustomWebRequest :: CompleteContent - DOWNLOAD COMPLETE!");
    }

    // Called when a Content-Length header is received from the server.
    protected override void ReceiveContentLength(int contentLength)
    {
        //Debug.Log(string.Format("CustomWebRequest :: ReceiveContentLength - length {0}", contentLength));
    }
}

用法:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class Test : MonoBehaviour
{

    CustomWebRequest camImage;
    UnityWebRequest webRequest;
    byte[] bytes = new byte[90000];

    void Start()
    {
        string url = "http://camUrl/mjpg/video.mjpg";
        webRequest = new UnityWebRequest(url);
        webRequest.downloadHandler = new CustomWebRequest(bytes);
        webRequest.Send();
    }
}

您可以讓他們在ReceiveData<中執(zhí)行步驟2345CustomWebRequest 腳本中的/code> 函數(shù).

You can them perform step 2,3,4 and 5 in the ReceiveData function from the CustomWebRequest script.

控制攝像頭:

相機(jī)具有平移、旋轉(zhuǎn)、翻轉(zhuǎn)、鏡像和執(zhí)行其他功能的命令.這在每個相機(jī)中都不同,但它很簡單,只需向相機(jī)的 url 發(fā)出 GET/POST 請求并提供查詢.這些命令可以在相機(jī)手冊中找到.

Cameras have commands to pan, rotate, flip, mirror and perform other function.This is different in every camera but it is simple as making GET/POST request to a url of the camera and providing the queries. These commands can be found in the camera manual.

例如:http://192.168.1.5?pan=50&rotate=90

其他框架:

AForge - 一個可以同時處理 JPEG/MJPES 和 FFMPEG 來自相機(jī).您必須修改它以使用 Unity,如果您不能執(zhí)行步驟 2345.

AForge - A free framework that can handle both JPEG/MJPES and FFMPEG from the camera. You have to modify it to work with Unity and you should if you can't do step 2,3,4 and 5.

這篇關(guān)于將實時鏡頭從攝像機(jī)流式傳輸?shù)?Unity3D的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應(yīng)用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應(yīng)用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 欧美大片18 | 成人午夜免费视频 | 国产一区二区在线播放 | 日韩毛片网站 | 国产91在线播放 | 日韩精品观看 | 一区视频在线 | 欧美一区二区三区在线观看 | 欧洲一级片 | 一区二区三区四区在线视频 | 在线观看黄 | 91一区二区三区 | 亚洲精品欧美 | 日本视频一区二区三区 | 一本色道久久综合亚洲精品小说 | 久久久少妇 | 97视频在线观看免费 | 免费av网站在线观看 | 成人一级视频 | 欧美日本在线观看 | 啪啪免费网站 | 日韩不卡一区 | 成人毛片在线观看 | 免费在线看a| 少妇高潮av久久久久久 | 国产成人在线免费视频 | 香蕉视频一区二区 | 一级片黄色片 | 中文字幕亚洲一区 | 夜夜操天天操 | 亚洲精品一区二区三区蜜桃久 | 久久香蕉国产 | 国产日韩在线播放 | 曰韩av| 日韩欧美一区二区三区四区 | 成人av在线看 | 欧美日韩第一页 | 91精品一区| 黄色小视频免费看 | 亚洲精品综合 | 免费一级a毛片夜夜看 |