Skip to content
Snippets Groups Projects
Commit c230cac4 authored by Jon Gunnar Fossum's avatar Jon Gunnar Fossum
Browse files

Add UDPCameraSender script

This sript takes the feed from the clients camera and converts it to
pixel data. It is then supposed to ssend that data to the edge server,
but that has not ben successful yet.
parent ffc01018
No related branches found
No related tags found
No related merge requests found
fileFormatVersion: 2
guid: 6b8121de81bb8824c847588025c8509b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net.Sockets;
using System.Text;
public class UDPCameraSender : MonoBehaviour
{
private WebCamTexture camTexture = new WebCamTexture();
private UdpClient udpClient = new UdpClient();
// Start is called before the first frame update
void Start()
{
// TODO: REQUEST CAMERA PERMISSION!!
// OLD IMPLEMENTATION
var devices = WebCamTexture.devices;
if (devices.Length < 1) throw new System.Exception("No webcams was found");
camTexture.deviceName = devices[0].name;
foreach(var camDevice in devices)
{
if (camDevice.isFrontFacing)
{
camTexture.deviceName = camDevice.name;
break;
}
} //*/
}
// Update is called once per frame
void Update()
{
}
public void SendCamToEdge()
{
//try
{
// Define target
udpClient.Connect("192.0.0.0", 6767);
// convert Texture to jpeg
var tex2DData = Convert_WebCamTexture_To_Texture2d(camTexture);
//camTexture.GetPixels32();
//ImageConversion.EncodeArrayToJPG( */
// Send image
//byte[] sendbytes = Encoding.UTF8.GetBytes();
//udpClient.SendAsync()
}
}
private Texture2D Convert_WebCamTexture_To_Texture2d(WebCamTexture _webCamTexture)
{
Texture2D _texture2D = new Texture2D(_webCamTexture.width, _webCamTexture.height);
_texture2D.SetPixels32(_webCamTexture.GetPixels32());
return _texture2D;
}
}
fileFormatVersion: 2
guid: 8fa575f5b18c5d046b8923a8cc048bcb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment