作者:夏至_krisyeol_582 | 来源:互联网 | 2023-02-04 15:54
这是我在Stack上的第一篇文章,所以我很抱歉我的笨拙.如果我能改进我的问题,请告诉我.
►我想实现的目标(从长远来看):
我尝试使用OpenCV Unity激光指针来操纵我的Unity3d演示文稿.
我相信一张图片的价值超过千言万语,所以这应该说得最多:
►问题是什么:
我尝试从摄像机视图(某种梯形)到平面空间进行简单的4点校准(投影).
我认为这将是非常基本和简单的事情,但我没有OpenCV的经验,我无法使其工作.
►样品:
我做了一个不太复杂的例子,没有任何激光检测和所有其他东西.我试图重新投射到平面空间只有4点梯形.
链接到整个示例项目:https://1drv.ms/u/s!AiDsGecSyzmuujXGQUapcYrIvP7b
我的例子中的核心脚本:
using OpenCVForUnity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class TestCalib : MonoBehaviour
{
public RawImage displayDummy;
public RectTransform[] handlers;
public RectTransform dummyCross;
public RectTransform dummyResult;
public Vector2 webcamSize = new Vector2(640, 480);
public Vector2 objectSize = new Vector2(1024, 768);
private Texture2D texture;
Mat cameraMatrix;
MatOfDouble distCoeffs;
MatOfPoint3f objectPoints;
MatOfPoint2f imagePoints;
Mat rvec;
Mat tvec;
Mat rotationMatrix;
Mat imgMat;
void Start()
{
texture = new Texture2D((int)webcamSize.x, (int)webcamSize.y, TextureFormat.RGB24, false);
if (displayDummy) displayDummy.texture = texture;
imgMat = new Mat(texture.height, texture.width, CvType.CV_8UC3);
}
void Update()
{
imgMat = new Mat(texture.height, texture.width, CvType.CV_8UC3);
Test();
DrawImagePoints();
Utils.matToTexture2D(imgMat, texture);
}
void DrawImagePoints()
{
Point[] pointsArray = imagePoints.toArray();
for (int i = 0; i points = new List();
foreach (RectTransform handler in handlers)
{
Point p = new Point(handler.anchoredPosition.x, handler.anchoredPosition.y);
points.Add(p);
}
m.fromList(points);
return m;
}
}
在此先感谢您的帮助.