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

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

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

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

假設(shè)我有一臺(tái)無(wú)線攝像機(jī),我想將鏡頭實(shí)時(shí)傳輸?shù)?Unity.有沒(méi)有辦法做到這一點(diǎn)?

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?

額外問(wèn)題:

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

提前致謝

推薦答案

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

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.

如何在沒(méi)有外部庫(kù)的情況下完成:

連接到相機(jī):

1.連接到與相機(jī)相同的本地網(wǎng)絡(luò),或者如果支持unpn,您也可以通過(guò)互聯(lián)網(wǎng)連接到它.通常,您需要攝像機(jī)的 IP 和端口來(lái)執(zhí)行此操作.假設(shè)攝像機(jī) IP 地址為 192.168.1.5,端口號(hào)為 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.

有時(shí),它只是一個(gè)以 .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

每臺(tái)相機(jī)都是不同的.找到該網(wǎng)址的唯一方法是閱讀其手冊(cè).如果該手冊(cè)不可用,請(qǐng)使用其官方應(yīng)用程序連接到它,然后使用 Wireshark 發(fā)現(xiàn)相機(jī)圖像的 url.usernamepassword(如果需要)也可以在手冊(cè)中找到.如果沒(méi)有,請(qǐng)?jiān)?Google 上搜索型號(hào),您需要的所有東西都應(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ī)會(huì)不斷地向您發(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)頭.如果這兩個(gè)字節(jié)彼此相鄰,則開(kāi)始讀取字節(jié)并繼續(xù)將它們保存到數(shù)組中.您可以使用 index(int) 變量來(lái)計(jì)算收到的字節(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ù)時(shí),檢查接下來(lái)的兩個(gè)字節(jié)是否是JPEG頁(yè)腳,即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ù)千個(gè))..... 然后是 0xFF 0xD9

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

receivedBytes 復(fù)制到 completeImageByte 變量中,以便以后可以使用它來(lái)顯示圖像.將 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 組件.因此,如果您希望它在移動(dòng)設(shè)備上運(yùn)行,請(qǐng)不要為此使用 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ī)需要身份驗(yàn)證(用戶(hù)名和密碼),請(qǐng)使用 HttpWebRequest.

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

對(duì)于不需要身份驗(yàn)證的用戶(hù),請(qǐng)使用 UnityWebRequest.使用 UnityWebRequest 時(shí),您必須從 派生自己的類(lèi)DownloadHandlerScript 否則您的應(yīng)用程序?qū)⒈罎ⅲ驗(yàn)槟鷮⒉煌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派生你自己的類(lèi)的例子:

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();
    }
}

您可以讓他們?cè)?code>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í)行其他功能的命令.這在每個(gè)相機(jī)中都不同,但它很簡(jiǎn)單,只需向相機(jī)的 url 發(fā)出 GET/POST 請(qǐng)求并提供查詢(xún).這些命令可以在相機(jī)手冊(cè)中找到.

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 - 一個(gè)可以同時(shí)處理 JPEG/MJPES 和 FFMPEG 來(lái)自相機(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)于將實(shí)時(shí)鏡頭從攝像機(jī)流式傳輸?shù)?Unity3D的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)行身份驗(yàn)證并跨請(qǐng)求保留自定義聲明)
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 訪問(wèn)令牌和刷新令牌) - IT屋-程序員軟件開(kāi)發(fā)技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應(yīng)用程序密碼從 oauth2/token 獲取訪問(wèn)令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應(yīng)用程序在通過(guò)管理門(mén)戶(hù)更新之前無(wú)法運(yùn)行)
主站蜘蛛池模板: 中文成人在线 | 日韩精品一区二区三区四区视频 | 精品久久久久久久人人人人传媒 | 久久se精品一区精品二区 | 国产一区精品 | 国产成人福利在线观看 | 中文字幕视频在线看5 | 中文字幕在线视频免费视频 | 久久久久久综合 | 青青久在线视频 | 国产精品久久在线观看 | 欧美一区不卡 | 国产探花在线精品一区二区 | 成人在线视频一区二区三区 | 青青草视频免费观看 | 久久亚洲国产 | 欧美精品v国产精品v日韩精品 | 国产一区二区三区在线 | 欧美一区二区 | 国产精品99久久久久久宅男 | 成人午夜免费视频 | 久久久99国产精品免费 | 中文字幕精品一区二区三区在线 | 成人欧美一区二区三区黑人孕妇 | 国产91在线视频 | 久久丝袜 | 91免费视频 | 国产精品久久久久久久岛一牛影视 | 欧美jizzhd精品欧美巨大免费 | 欧美日一区二区 | 高清成人免费视频 | 九色在线视频 | 伊色综合久久之综合久久 | av三级在线观看 | 久久精品女人天堂av | 一级特黄视频 | 亚洲人成网亚洲欧洲无码 | 91综合网 | 日韩激情视频一区 | www.午夜 | 在线一区视频 |