★ wanayoo — archive 1999 https://github.com/EnoxSoftware/OpenCVForUnity/issues/68Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in Texture2DtoMat ! #68

Open
sufeidechabei opened this issue Aug 23, 2020 · 1 comment
Open

Errors in Texture2DtoMat ! #68

sufeidechabei opened this issue Aug 23, 2020 · 1 comment

Comments

@sufeidechabei
Copy link

@sufeidechabei sufeidechabei commented Aug 23, 2020

Here is the code, When Print out the leftimage after convert leftex to mat, it's a white image, and all the pixel values is 205
Texture2D lefttex = new Texture2D(UndistortedImageWidth, UndistortedImageHeight, TextureFormat.RGBA32, false); Texture2D righttex = new Texture2D(UndistortedImageWidth, UndistortedImageHeight, TextureFormat.RGBA32, false); Graphics.CopyTexture(TextureUndistortedDisplayRight, righttex); Graphics.CopyTexture(TextureUndistortedDisplayLeft, lefttex); Mat rightimage = new Mat(TextureUndistortedDisplayRight.height, TextureUndistortedDisplayRight.width, CvType.CV_8UC4); Mat leftimage = new Mat(TextureUndistortedDisplayLeft.height, TextureUndistortedDisplayLeft.width, CvType.CV_8UC4); OpenCVForUnity.ImgcodecsModule.Imgcodecs.imwrite("D:\\eeee.png", leftimage); Utils.texture2DToMat(lefttex, leftimage); Utils.matToTexture2D(leftimage, lefttex); Utils.texture2DToMat(righttex, rightimage); Utils.matToTexture2D(rightimage, righttex); Graphics.CopyTexture(lefttex, TextureUndistortedDisplayLeft); Graphics.CopyTexture(righttex, TextureUndistortedDisplayRight);

@EnoxSoftware
Copy link
Owner

@EnoxSoftware EnoxSoftware commented Aug 24, 2020

If you use the Graphics.CopyTexture() method to copy Texture2D, the format of TextureUndistortedDisplayRight must be the same as the format of righttex.
texture_format

        Texture2D TextureUndistortedDisplayRight = Resources.Load("face") as Texture2D;
        Texture2D TextureUndistortedDisplayLeft = Resources.Load("face") as Texture2D;

        int UndistortedImageWidth = 512;
        int UndistortedImageHeight = 512;


        Texture2D lefttex = new Texture2D(UndistortedImageWidth, UndistortedImageHeight, TextureFormat.RGBA32, false);
        Texture2D righttex = new Texture2D(UndistortedImageWidth, UndistortedImageHeight, TextureFormat.RGBA32, false);
        Graphics.CopyTexture(TextureUndistortedDisplayRight, righttex);
        Graphics.CopyTexture(TextureUndistortedDisplayLeft, lefttex);

        Mat rightimage = new Mat(TextureUndistortedDisplayRight.height, TextureUndistortedDisplayRight.width, CvType.CV_8UC4);
        Mat leftimage = new Mat(TextureUndistortedDisplayLeft.height, TextureUndistortedDisplayLeft.width, CvType.CV_8UC4);

        //OpenCVForUnity.ImgcodecsModule.Imgcodecs.imwrite("D:\\eeee.png", leftimage);

        Utils.texture2DToMat(lefttex, leftimage);

        OpenCVForUnity.ImgcodecsModule.Imgcodecs.imwrite("D:\\eeee.png", leftimage);


        Utils.matToTexture2D(leftimage, lefttex);
        Utils.texture2DToMat(righttex, rightimage);
        Utils.matToTexture2D(rightimage, righttex);
        Graphics.CopyTexture(lefttex, TextureUndistortedDisplayLeft);
        Graphics.CopyTexture(righttex, TextureUndistortedDisplayRight);

        //gameObject.GetComponent<Renderer>().material.mainTexture = lefttex;
        gameObject.GetComponent<Renderer>().material.mainTexture = TextureUndistortedDisplayLeft;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.