pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

問題描述

限時(shí)送ChatGPT賬號..

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

額外問題:

  • 如果相機(jī)的角度更廣(180 度,甚至 360 度)
  • 如果這是我想與之互動的片段,延遲會有多大的問題
  • 除了常規(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.

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

連接到相機(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.

有時(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

每臺相機(jī)都是不同的.找到該網(wǎng)址的唯一方法是閱讀其手冊.如果該手冊不可用,請使用其官方應(yīng)用程序連接到它,然后使用 Wireshark 發(fā)現(xiàn)相機(jī)圖像的 url.usernamepassword(如果需要)也可以在手冊中找到.如果沒有,請?jiān)?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)頭.如果這兩個(gè)字節(jié)彼此相鄰,則開始讀取字節(jié)并繼續(xù)將它們保存到數(shù)組中.您可以使用 index(int) 變量來計(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í),檢查接下來的兩個(gè)字節(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ù)千個(gè))..... 然后是 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è)備上運(yùn)行,請不要為此使用 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)證(用戶名和密碼),請使用 HttpWebRequest.

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

對于不需要身份驗(yàn)證的用戶,請使用 UnityWebRequest.使用 UnityWebRequest 時(shí),您必須從 派生自己的類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派生你自己的類的例子:

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í)行步驟23、45CustomWebRequest 腳本中的/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ī)中都不同,但它很簡單,只需向相機(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 - 一個(gè)可以同時(shí)處理 JPEG/MJPES 和 FFMPEG 來自相機(jī).您必須修改它以使用 Unity,如果您不能執(zhí)行步驟 2、345.

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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)行身份驗(yà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)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
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)用程序在通過管理門戶更新之前無法運(yùn)行)
主站蜘蛛池模板: 注塑机-压铸机-塑料注塑机-卧式注塑机-高速注塑机-单缸注塑机厂家-广东联升精密智能装备科技有限公司 | 横河变送器-横河压力变送器-EJA变送器-EJA压力变送器-「泉蕴仪表」 | 冰晶石|碱性嫩黄闪蒸干燥机-有机垃圾烘干设备-草酸钙盘式干燥机-常州市宝康干燥 | 上海办公室装修公司_办公室设计_直营办公装修-羚志悦装 | PTFE接头|聚四氟乙烯螺丝|阀门|薄膜|消解罐|聚四氟乙烯球-嘉兴市方圆氟塑制品有限公司 | 2025福建平潭岛旅游攻略|蓝眼泪,景点,住宿攻略-趣平潭网 | 不锈钢电动球阀_气动高压闸阀_旋塞疏水调节阀_全立阀门-来自温州工业阀门巨头企业 | 智能门锁电机_智能门锁离合器_智能门锁电机厂家-温州劲力智能科技有限公司 | 顺景erp系统_erp软件_erp软件系统_企业erp管理系统-广东顺景软件科技有限公司 | 寮步纸箱厂_东莞纸箱厂 _东莞纸箱加工厂-东莞市寮步恒辉纸制品厂 | 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 比亚迪叉车-比亚迪电动叉车堆垛车托盘车仓储叉车价格多少钱报价 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | 北京租车公司_汽车/客车/班车/大巴车租赁_商务会议/展会用车/旅游大巴出租_北京桐顺创业租车公司 | 新疆十佳旅行社_新疆旅游报价_新疆自驾跟团游-新疆中西部国际旅行社 | 十字轴_十字轴万向节_十字轴总成-南京万传机械有限公司 | 喷砂机厂家_自动喷砂机生产_新瑞自动化喷砂除锈设备 | 水平垂直燃烧试验仪-灼热丝试验仪-漏电起痕试验仪-针焰试验仪-塑料材料燃烧检测设备-IP防水试验机 | 东莞注册公司-代办营业执照-东莞公司注册代理记账-极刻财税 | 苗木价格-苗木批发-沭阳苗木基地-沭阳花木-长之鸿园林苗木场 | 涂层测厚仪_漆膜仪_光学透过率仪_十大创新厂家-果欧电子科技公司 | 我车网|我关心的汽车资讯_汽车图片_汽车生活! | 一氧化氮泄露报警器,二甲苯浓度超标报警器-郑州汇瑞埔电子技术有限公司 | 宁夏活性炭_防护活性炭_催化剂载体炭-宁夏恒辉活性炭有限公司 | [官网]叛逆孩子管教_戒网瘾学校_全封闭问题青少年素质教育_新起点青少年特训学校 | 拉力机-万能试验机-材料拉伸试验机-电子拉力机-拉力试验机厂家-冲击试验机-苏州皖仪实验仪器有限公司 | 铁素体测量仪/检测仪/铁素体含量测试仪-苏州圣光仪器有限公司 | 西门子伺服电机维修,西门子电源模块维修,西门子驱动模块维修-上海渠利 | 金蝶帐无忧|云代账软件|智能财税软件|会计代账公司专用软件 | 等离子表面处理机-等离子表面活化机-真空等离子清洗机-深圳市东信高科自动化设备有限公司 | 木材烘干机,木炭烘干机,纸管/佛香烘干设备-河南蓝天机械制造有限公司 | 珠海冷却塔降噪维修_冷却塔改造报价_凉水塔风机维修厂家- 广东康明节能空调有限公司 | 电力测功机,电涡流测功机,磁粉制动器,南通远辰曳引机测试台 | 一点车讯-汽车网站,每天一点最新车讯! | 上海心叶港澳台联考一对一培训_上海心叶港澳台联考,港澳台联考一对一升学指导 | 全自动变压器变比组别测试仪-手持式直流电阻测试仪-上海来扬电气 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛调查出轨取证公司_青岛婚外情取证-青岛探真调查事务所 | 心肺复苏模拟人|医学模型|急救护理模型|医学教学模型上海康人医学仪器设备有限公司 | 快速门厂家-快速卷帘门-工业快速门-硬质快速门-西朗门业 | Copeland/谷轮压缩机,谷轮半封闭压缩机,谷轮涡旋压缩机,型号规格,技术参数,尺寸图片,价格经销商 CTP磁天平|小电容测量仪|阴阳极极化_双液系沸点测定仪|dsj电渗实验装置-南京桑力电子设备厂 | 东莞注册公司-代办营业执照-东莞公司注册代理记账-极刻财税 |