unity opecv addWeighted

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using OpenCVForUnity;
using UnityEngine.UI;

public class Scanner : MonoBehaviour {

    public Texture2D baseTexture;
    public RawImage sourceRawImage;
    public RawImage targetRawImage;



	
	void Start () {


    

    }


    public void Update()
    {
        if (Input.GetKeyUp(KeyCode.K))
        {
            Mat BgMat = Imgcodecs.imread(@"C:\Users\Aidenxl\Desktop\bg.jpg");
            Mat LogoMat = Imgcodecs.imread(@"C:\Users\Aidenxl\Desktop\5.jpg");

            Imgproc.cvtColor(BgMat,BgMat, Imgproc.COLOR_BGR2RGB);
            Imgproc.cvtColor(LogoMat, LogoMat, Imgproc.COLOR_BGR2RGB);


            Mat dest = new Mat(BgMat, new OpenCVForUnity.Rect(100,200, LogoMat.cols(), LogoMat.rows()));

            Core.addWeighted(dest, 0, LogoMat, 1, 0, dest);


            Texture2D bg = new Texture2D(BgMat.width(), BgMat.height());
            Texture2D Logo = new Texture2D(LogoMat.width(), LogoMat.height());

            Utils.matToTexture2D(BgMat, bg);
            Utils.matToTexture2D(LogoMat, Logo);


            targetRawImage.texture = bg;

            Imgproc.cvtColor(BgMat,BgMat,Imgproc.COLOR_RGB2BGR);

            Imgcodecs.imwrite(@"C:\Users\Aidenxl\Desktop\8888888.jpg", BgMat);
        }
    }


}

猜你喜欢

转载自blog.csdn.net/weixin_37744986/article/details/80634545