Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 在团结中获得正确的位置_Opencv_Unity3d - Fatal编程技术网

Opencv 在团结中获得正确的位置

Opencv 在团结中获得正确的位置,opencv,unity3d,Opencv,Unity3d,在OpenCV中,当检测到某个对象时,会显示一个矩形 Imgproc.rectangle (rgbaMat, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (0, 0, 255, 255), 2); 我想把一个3D对象或者一个立方体放在矩形的一个角上 myCube.transform.posit

在OpenCV中,当检测到某个对象时,会显示一个矩形

Imgproc.rectangle (rgbaMat, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (0, 0, 255, 255), 2);
我想把一个3D对象或者一个立方体放在矩形的一个角上

myCube.transform.position = new Vector3(rects[0].x, rects[0].y);
问题在于立方体的位置不在矩形中,但在变换中它显示了正确的矢量3(float,float,float)

我怎样才能把我的立方体放在矩形角的位置呢?

经过大量挖掘(所以我不怪你),我发现了以下几点,我想这就是你想要的:

有一个问题

对于你来说,我想最有趣的方法是最底层的方法:

//
///结果矩形生成游戏对象。
/// 
///矩形。
///颜色。
///Z位置。
私有void ResultRectsToResultGameObjects(IList rects、Color-Color、float zPos)
{
Vector3[]resultPoints=新Vector3[rects.Count];
float textureWidth=GetComponent().material.mainTexture.width;
float textureHeight=GetComponent().material.mainTexture.height;
Matrix4x4 transCenterM=Matrix4x4.TRS(新向量3(-textureWidth/2,-textureHeight/2,0),四元数.identity,新向量3(1,1,1));
Vector3 translation=newvector3(gameObject.transform.localPosition.x,gameObject.transform.localPosition.y,gameObject.transform.localPosition.z);
四元数旋转=四元数.Euler(gameObject.transform.localEulerAngles.x,gameObject.transform.localEulerAngles.y,gameObject.transform.localEulerAngles.z);
Vector3 scale=newvector3(gameObject.transform.localScale.x/textureWidth,gameObject.transform.localScale.y/textureHight,1);
Matrix4x4 trans2Dto3DM=Matrix4x4.TRS(平移、旋转、缩放);
for(int i=0;i
当然,我没有测试它,但它看起来像是做了你想要的事情:将对象放置在矩形位置上


当然,您必须根据自己的需要采用它,但我希望这是一个很好的起点。

我也遇到了类似的问题。我想在检测到的对象的中心放置一个3d对象。我在unity论坛的OpenCV上询问,得到了开发者的回复

他们为我提供了一个解决方案包

在您的情况下,可以将DetectFace2DTo3DExample.cs中的第68行更改为rect的位置

Matrix4x4点3dmartrix4x4=get2dto3dmartrix4x4x4(新向量2(rects[0].x,rects[0].y),游戏对象)


两个对象(矩形或立方体)中的一个是缩放或平移的父对象的子对象吗?@derHugo起初它是在一个四边形中,位置类似于0.12、0.11,然后我将其从四边形中取出,现在变换与矩形[0]相同。x,矩形[0].y立方体仍然不在房间的角落里rectangle@derHugo例如,rects[0].x=196和rects[0].y=213,那么在我的多维数据集中的变换是196213,0。但是,立方体不在矩形屏幕空间与世界空间的角上。@Draco18s我尝试过Camera.main.ScreenToWorldPoint()但仍然是一样的