使用OpenCVForUnity拼接图片
2017-12-29 18:20
405 查看
沿着上一篇关于图片裁切反向操作。演示Core.hconcat()水平拼接, Core.vconcat()垂直拼接函数的使用。
输出:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using OpenCVForUnity; public class Pano : MonoBehaviour { public Texture2D t2d; public RawImage output; public AspectRatioFitter fitter; void Start() { // 读取图像 Mat _image0 = Imgcodecs.imread(Application.dataPath + "/0.jpg"); Mat _image1 = Imgcodecs.imread(Application.dataPath + "/1.jpg"); Mat _image2 = Imgcodecs.imread(Application.dataPath + "/2.jpg"); Mat _image3 = Imgcodecs.imread(Application.dataPath + "/3.jpg"); Mat image0 = new Mat(); Mat image1 = new Mat(); ac1d Mat image2 = new Mat(); Mat image3 = new Mat(); // 统一尺寸 Imgproc.resize(_image0, image0, new Size(512, 512)); Imgproc.resize(_image1, image1, new Size(512, 512)); Imgproc.resize(_image2, image2, new Size(512, 512)); Imgproc.resize(_image3, image3, new Size(512, 512)); /* 竖向矩阵排列 Mat combine = new Mat(256, 1024, CvType.CV_8UC3); combine.push_back(image0); combine.push_back(image1); combine.push_back(image2); combine.push_back(image3); Debug.Log(combine.width() + "*" + combine.height()); */ Debug.Log(image0.width() + "*" + image0.height()); List<Mat> list1 = new List<Mat>(); list1.Add(image0); list1.Add(image1); List<Mat> list2 = new List<Mat>(); list2.Add(image2); list2.Add(image3); Mat combine = new Mat(2048, 512, CvType.CV_8UC3); Mat combine1 = new Mat(1024,512, CvType.CV_8UC3); Mat combine2 = new Mat(1024, 512, CvType.CV_8UC3); List<Mat> list3 = new List<Mat>(); list3.Add(combine1); list3.Add(combine2); //两两拼接 Core.hconcat(list1, combine1); //横向拼接 Core.hconcat(list2, combine2); //Core.hconcat(list3, combine); Core.vconcat(list3, combine); //竖向拼接 float ratio = (float)combine.width() / (float)combine.height(); fitter.aspectRatio = ratio; t2d = new Texture2D(combine.width(), combine.height()); Debug.Log(t2d.width + "*" + t2d.height); Utils.matToTexture2D(combine, t2d); output.texture = t2d; } }
输出:
相关文章推荐
- 使用opencv把图片拼接成视频
- 使用OpenCVForUnity分割图片
- 使用OpenCV实现WebCam摄像头保存JPEG图片(改良1版)
- linux下使用opencv接口函数对图片边缘化操作
- 使用OpenCV 读取图片 ,再用OpenGL显示,图像有错位
- OpenCV1-读写图片,使用Matplotlib
- 关于全景(360)图片拼接的方法(Opencv3.0 Stitcher)
- opencv图片全景拼接详解
- OpenCV探索之路(十八):使用imwrite调整保存的图片质量
- C# 使用OpenCV在一张图片里寻找人脸
- HTML静态网页(图片热点、网页划区、拼接及表单的使用)
- python使用opencv将灰度图人脸图片转化为RGB
- 使用Qt和OpenCV做的图片平滑器
- opencv 保存图片操作:sprintf连续保存文件命名的使用
- 使用opencv比较两个图片的相似性
- 使用openCV进行视频拼接
- VS2013 MFC使用opencv3.0显示图片
- OpenCVForUnity使用Haar分类器检测人脸和眼睛
- iOS开发之opencv学习笔记四:使用feature2d识别图片
- 使用php的GD库拼接图片