Hello,
i have problem. In moment run project i get error:
ArgumentException: The output Mat object has to be of the same size
OpenCVForUnity.Utils.texture2DToMat (UnityEngine.Texture2D texture2D, OpenCVForUnity.Mat mat) (at Assets/OpenCVForUnity/org/opencv/unity/Utils.cs:521)
In debug i checked my table Mat imgMat is null and i don’t know why.
I have two method,
first is to capture view and show him in little window in view
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
public class Nowy : MonoBehaviour
{
Texture2D screenCap;
Texture2D border;
bool shot = false;
void Start()
{
screenCap = new Texture2D(200, 200, TextureFormat.RGB24, false); // 1
border = new Texture2D(2, 2, TextureFormat.ARGB32, false); // 2
border.Apply();
}
void Update()
{
StartCoroutine("Capture");
}
void OnGUI()
{
foto sc = gameObject.GetComponent<foto>();
sc.returnView(screenCap);
GUI.DrawTexture(new Rect(0, 85, 246, 2), border, ScaleMode.StretchToFill); // top
GUI.DrawTexture(new Rect(0, 300, 246, 2), border, ScaleMode.StretchToFill); // bottom
if (shot)
{
GUI.DrawTexture(new Rect(600, 10, 150, 120), screenCap, ScaleMode.StretchToFill);
}
}
IEnumerator Capture()
{
yield return new WaitForEndOfFrame();
screenCap.ReadPixels(new Rect(0, 110, 240, 199), 0, 0);
screenCap.Apply();
shot = true;
}
}
and second where are operation on the image (texture from screenshot view)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenCVForUnity;
public class foto : MonoBehaviour
{
public Texture2D returnView(Texture2D texture)
{
Size ksize = new Size(7, 7);
Mat edges = new Mat();
Mat imgMat = new Mat(texture.width, texture.height, CvType.CV_8UC4);
Utils.texture2DToMat(texture, imgMat);
Imgproc.cvtColor(imgMat, edges, Imgproc.COLOR_RGBA2GRAY);
Imgproc.GaussianBlur(edges, edges, ksize, 1.5, 1.5);
Imgproc.Canny(edges, edges, 30, 3);
Utils.matToTexture2D(edges, texture);
return texture;
}
}
what is wrong here?