Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- //For the CV stuff
- //using UnityEngine;
- //using System.Collections;
- using Emgu.CV;
- using Emgu.CV.Util;
- using Emgu.CV.UI;
- using Emgu.CV.CvEnum;
- using Emgu.CV.Structure;
- using System.Runtime.InteropServices;
- using System;
- using System.Drawing;
- public class WebcamTextureScript : MonoBehaviour {
- public Material mat;
- public GameObject quad;
- public GameObject cam;
- public float imageOffsetX;
- public float imageOffsetY;//
- private TextureBridge bridge;
- private WebCamDevice[] devices;
- private WebCamTexture texture;
- private int deviceHeight;
- private int deviceWidth;
- private int scaleFactor;//
- private int totalFPS;
- private int cameraFPS; //
- private Color32[] data;
- private Image<Bgr, byte> picture;
- private Texture2D augmentedTexture;
- // private int current = 0;
- // Use this for initialization
- void Start () {
- devices = WebCamTexture.devices;
- deviceHeight = 480;
- deviceWidth = 640;
- scaleFactor = 30;
- data = new Color32[deviceWidth * deviceHeight];
- bridge = new TextureBridge();
- if (devices.Length > 0)
- {
- if (cam.name == "CameraLeft")
- {
- texture = new WebCamTexture( devices[ 0 ].name, deviceWidth, deviceHeight, 60 );
- }
- if (cam.name == "CameraRight")
- {
- texture = new WebCamTexture( devices[ 1 ].name, deviceWidth, deviceHeight, 60 );
- }
- texture.requestedFPS = 100.0f;
- texture.Play();
- quad.transform.localScale = new Vector3 ( scaleFactor * ( (float)texture.width / (float)texture.height ), scaleFactor, 1.0f );
- quad.transform.Translate(imageOffsetX , imageOffsetY, 0 );
- mat.mainTexture = texture;
- }
- }
- // Update is called once per frame
- void Update () {
- if ( texture != null && texture.didUpdateThisFrame )
- {
- //CVTests
- // print(texture.GetPixels32(data).ToString());
- // picture = new Image<Bgra, byte>(data);
- //picture = bridge.WebcamTextureToEmguCVImage(texture.GetPixels32(data), texture.width, texture.height);
- // Bgr myWhiteColor = new Bgr (255, 255, 255);
- // for (int i=0; i<200; i++) {
- // picture [i, i] = myWhiteColor;
- // }
- //augmentedTexture = bridge.EmguCVImageToTexture2D(picture, deviceWidth, deviceHeight);
- //End CVTests
- quad.transform.rotation = cam.transform.rotation;
- quad.transform.Rotate( 0, 0, -90);
- //print(1/Time.deltaTime); //Print Framerate to console
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement