122 lines
3.7 KiB
C#
122 lines
3.7 KiB
C#
using DG.Tweening;
|
|
using Evereal.VideoCapture;
|
|
using Newtonsoft.Json;
|
|
using OpenCVForUnity.CoreModule;
|
|
using OpenCVForUnity.ImgcodecsModule;
|
|
using OpenCVForUnity.ImgprocModule;
|
|
using OpenCVForUnity.ObjdetectModule;
|
|
using OpenCVForUnity.UnityUtils.Helper;
|
|
using OpenCVForUnityExample;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using uLipSync;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class RobotUIManager : MonoBehaviour
|
|
{
|
|
|
|
CascadeClassifier cascade;
|
|
public WebCamTextureToMatHelper webCamTextureToMatHelper;
|
|
public RawImage camRawImage;
|
|
private Texture2D webtexture;
|
|
public static RobotUIManager instance;
|
|
public Button photoBtn;
|
|
public RawImage m_rawImage;
|
|
Button m_rawImage_button;
|
|
public GameObject photoPanel;
|
|
public GameObject textToSpeekPanel;
|
|
Texture2D tex;
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
m_rawImage_button = m_rawImage.GetComponent<Button>();
|
|
m_rawImage_button.onClick.AddListener(BigScale);
|
|
photoBtn.onClick.AddListener(Photo);
|
|
|
|
}
|
|
void BigScale()
|
|
{
|
|
m_rawImage.gameObject.SetActive(false);
|
|
photoPanel.SetActive(true);
|
|
photoPanel.GetComponent<PhotoPanel>().Init(tex);
|
|
}
|
|
public void AssignmentCam()
|
|
{
|
|
camRawImage.gameObject.SetActive(true);
|
|
webCamTextureToMatHelper.Initialize();
|
|
Mat mat = webCamTextureToMatHelper.GetMat();
|
|
webtexture = new Texture2D(mat.cols(), mat.rows(), TextureFormat.RGBA32, false);
|
|
camRawImage.texture = webtexture;
|
|
// imgMat = new Mat(webtexture.height, webtexture.width, CvType.CV_8UC4);
|
|
// grayMat = new Mat(webtexture.height, webtexture.width, CvType.CV_8UC1);
|
|
}
|
|
void Close_M_RawImage()
|
|
{
|
|
Debug.Log("1");
|
|
m_rawImage.gameObject.SetActive(false);
|
|
CancelInvoke("Close_M_RawImage");
|
|
}
|
|
void Photo()
|
|
{
|
|
CancelInvoke("Close_M_RawImage");
|
|
m_rawImage.gameObject.SetActive(true);
|
|
byte[] bytes = webtexture.EncodeToPNG();
|
|
tex = new Texture2D(webtexture.width, webtexture.height, TextureFormat.ARGB32, false);
|
|
tex.LoadImage(bytes);
|
|
m_rawImage.texture = tex;
|
|
if (m_rawImage.gameObject.activeSelf == true)
|
|
{
|
|
InvokeRepeating("Close_M_RawImage", 3, 0);
|
|
}
|
|
}
|
|
int targetRadius = 30;//小球半径
|
|
Mat imgMat;
|
|
Mat grayMat;
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (webCamTextureToMatHelper.IsPlaying() && webCamTextureToMatHelper.DidUpdateThisFrame())
|
|
{
|
|
Mat rgbMat = webCamTextureToMatHelper.GetMat();
|
|
OpenCVForUnity.UnityUtils.Utils.fastMatToTexture2D(rgbMat, webtexture);
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 让机器人说话
|
|
/// </summary>
|
|
/// <param name="text">内容</param>
|
|
/// <param name="tone"></param>
|
|
/// <param name="speed">语速</param>
|
|
/// <param name="saveflag"></param>
|
|
/// <param name="filename"></param>
|
|
public void OpenTextToSpeekPanel(string text, string tone, int speed,AudioSource audioSource)
|
|
{
|
|
//textToSpeekPanel.SetActive(true);
|
|
//textToSpeekPanel.GetComponent<TextToSpeekPanel>().Init(text, tone, speed);
|
|
textToSpeekPanel.GetComponent<TextToSpeekPanel>().PlayWithoutShow(text, tone, speed, audioSource);
|
|
|
|
}
|
|
public void CloseWebCam()
|
|
{
|
|
if (webCamTextureToMatHelper.IsPlaying())
|
|
{
|
|
webCamTextureToMatHelper.Stop();
|
|
camRawImage.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
public void CloseTextToSpeakPanel()
|
|
{
|
|
if (textToSpeekPanel!=null)
|
|
{
|
|
textToSpeekPanel.SetActive(false);
|
|
}
|
|
}
|
|
} |