工作我試圖讓在Unity3D的平面上的攝像頭表演。我使用的代碼從AForge文檔:http://www.aforgenet.com/framework/docs/html/f4d3c2ba-605c-f066-f969-68260ce5e141.htm 除了我將通過統一,而不是通常的AForges方式一個攝像頭,它希望讓FilterInfoCollection。如果我沒有錯,Unity需要識別攝像頭。製作AForge VideoCaptureDevice使用Unity
但是我的代碼是不工作什麼那麼,攝像頭開始(因爲我webCam.Play的()),但沒有什麼事情發生。通過調試,我發現程序沒有達到我的video_NewFrame函數,我相信在使用Unity時需要以某種方式進行初始化?
如何設置這個正確?
using UnityEngine;
using System.Collections;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Imaging.Filters;
using AForge.Imaging;
using AForge;
public class LoadVideo : MonoBehaviour {
public VideoCaptureDevice videoSource;
WebCamTexture webCam;
void Start(){
webCam = new WebCamTexture();
webCam.Play();
}
// Update is called once per frame
object b;
public WebCamDevice wc;
public GameObject originalFeed;
void Update() {
videoSource = new VideoCaptureDevice(webCam.deviceName);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
videoSource.Start();
originalFeed.GetComponent<Renderer>().material.mainTexture = originalFeedTexture;
}
public delegate void EventPrototype(System.EventArgs args);
Texture2D originalFeedTexture;
void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Debug.Log("you here mate");
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
MemoryStream memoryStream = new MemoryStream();
video.Save(memoryStream, ImageFormat.Jpeg);
byte[] bitmapRecord = memoryStream.ToArray();
originalFeedTexture.LoadImage(bitmapRecord);
}
}
您正在使用什麼版本的'AForge'的? –
@ AlessandroD'Andria 2.2.5 –
我有'2.2.5'和降級到'2.2.0'的問題(在我的情況下,事件從未提出過)。 –