我想将当前深度缓冲区获取到纹理,以在着色器中访问它.由于各种原因,我无法进行单独的深度传递,但需要复制已经渲染的深度.
glReadPixels将涉及CPU并可能杀死性能,据我所知glBlitFramebuffer,不能深入到颜色,只有深度到深度.
如何在GPU上执行此操作?
我阅读了很多关于使用片段着色器获取深度的信息.
如
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=234519
但我还是不知道这是否gl_FragCoord.z是线性的.
GLSL规范称屏幕上的范围为[0,1]而未提及线性与否.
我认为线性是至关重要的,因为我将使用渲染模型来匹配Kinect的深度图.
那么如果它不是线性的,那么如何在世界空间中线性化呢?
我已经为dft做了一些预处理,我试图通过imwrite保存这个图像.
我的裁剪图像有此信息
output.type() 5
output.channels() 1
output.depth() 5
Run Code Online (Sandbox Code Playgroud)
但每当我保存它时会产生黑色输出.我已经检查了堆栈流的旧现有线程,但似乎都不适合我.例如 OpenCV2.3 imwrite保存黑色图像
我也尝试了很多颜色转换和深度转换,但我不知道为什么它不起作用.
std::vector<int> qualityType;
qualityType.push_back(CV_IMWRITE_JPEG_QUALITY);
qualityType.push_back(90);
Mat out1,out2;
cv::cvtColor(output, out1, CV_GRAY2BGR);
//out1.convertTo(out2,CV_8U,1./256); // i tried this too
cv::imwrite("dft1.jpg",out1,qualityType); // tried even using quality type
Run Code Online (Sandbox Code Playgroud)
imshow显示这个图像很好只有问题来我保存它.
请帮忙
[编辑]也许我制作的dft类有问题,因为每当我使用dft函数时输出只能用于inshow但是为了保存它不起作用.
CDftRidgeAnalyses::CDftRidgeAnalyses(void)
{
}
CDftRidgeAnalyses::~CDftRidgeAnalyses(void)
{
}
Mat CDftRidgeAnalyses::GetRidgeAnalyses(Mat inpGray)
{
Mat img = inpGray;
int WidthPadded=0,HeightPadded=0;
WidthPadded=img.cols*2;
HeightPadded=img.rows*2;
int M = getOptimalDFTSize( img.rows );
//Create a Gaussian Highpass filter 5% the height of the Fourier transform
double db = 0.05 * HeightPadded;
Mat …Run Code Online (Sandbox Code Playgroud) 我必须使用XNA在3d模型上创建一个二维菜单.现在,我已经创建了2D的spritebatch和一个3d模型.但是,正如我已经注意到的,并且在其他地方被提及,由于z缓冲区问题,模型没有正确显示.根据教程,我应该在draw方法中再次启用DepthBuffer.但是,不知何故,当我使用时:
GraphicsDevice.DepthStencilState.DepthBufferEnable = true;
Run Code Online (Sandbox Code Playgroud)
调试期间代码抛出错误,说,
无法更改只读DepthStencilState.状态对象在第一次绑定到GraphicsDevice时变为只读.要更改属性值,请创建一个新的DepthStencilState实例.
现在,我也试图创建一个新的DepthStencilState实例,但是,即使这样似乎也不起作用.我总是得到相同的错误,即使帮助文档建议它的读/写值.
请帮我弄清楚如何正确显示3D模型.
这是Draw代码供参考.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
Matrix[] transforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in myModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
//effect.DirectionalLight0.Enabled = true;
//effect.DirectionalLight0.DiffuseColor = Color.AntiqueWhite.ToVector3();
//effect.DirectionalLight0.Direction = new Vector3(0, 0, 0);
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(myModelRotation) * Matrix.CreateTranslation(myModelPosition);
effect.View = Matrix.CreateLookAt(new Vector3(0, 0, 3000), Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f),
GraphicsDevice.Viewport.AspectRatio, 1, 5000);
}
mesh.Draw();
}
spriteBatch.Begin();
spriteBatch.Draw(myTexture, new Vector2(0, 0), Color.White);
spriteBatch.End();
DepthStencilState d …Run Code Online (Sandbox Code Playgroud) 我需要使用jquery的"find"选择器来获取所有具有"field_container"类的div.问题是我不能在DOM树中走得太深.
这是我简化的HTML结构:
<div id='tab_0'>
<div id='form_content'>
<div class='field_container'>
<span>Div 1</span>
<div class='field_container'>
<span>Div 1.1</span>
</div>
</div>
<div class='field_container'>
<span>Div 2</span>
</div>
<div class='field_container'>
<span>Div 3</span>
</div>
</div> <!-- Closing form_content div//-->
</div> <!-- Closing tab_0 div//-->
Run Code Online (Sandbox Code Playgroud)
我有一个"tab_0"div的初始引用.从它开始,我需要获取所有"field_container"div,不包括子"field_containers".
我试过这个:
$('#tab_0').children('.field_container') -> doesnt work, because the "field_container" divs arent direct children.
$('#tab_0').find('.field_container') -> doesnt work, because "Div 1.1" is also returned. I only need the first-level ones (Div1, Div2, Div3).
Run Code Online (Sandbox Code Playgroud)
我无法更改我的初始引用,它必须是"tab_0".
我有一对GLSL着色器,它为我提供了场景中对象的深度贴图.我现在得到的是每个像素到相机的距离.我需要的是获得从像素到相机平面的距离.让我用一点画来说明
* |--*
/ |
/ |
C-----* C-----*
\ |
\ |
* |--*
Run Code Online (Sandbox Code Playgroud)
3个星号是像素,C是相机.星号的线条是"深度".在第一种情况下,我得到像素到相机的距离.在第二个中,我希望得到每个像素到平面的距离.
必须有一种方法可以通过使用一些投影矩阵来做到这一点,但我很难过.
这是我正在使用的着色器.请注意,eyePosition是camera_position_object_space.
顶点着色器:
void main() {
position = gl_Vertex.xyz;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Run Code Online (Sandbox Code Playgroud)
像素着色器:
uniform vec3 eyePosition;
varying vec3 position;
void main(void) {
vec3 temp = vec3(1.0,1.0,1.0);
float depth = (length(eyePosition - position*temp) - 1.0) / 49.0;
gl_FragColor = vec4(depth, depth, depth, 1.0);
}
Run Code Online (Sandbox Code Playgroud) 我正在opencv做一个项目来检测使用立体声校准的盲人路径中的障碍物.我已经正确地计算了视差图.现在要找到障碍物距离相机的距离,我想要它的3D坐标[X,Y,Z],我猜是可以通过reprojectImageTo3D()找到,但是我没有Q矩阵在这个函数中使用,因为我从stereoRectify()获得的Q矩阵可能因为我使用预校准图像而变为零.虽然我确实拥有相机的内在和外在参数.所以我的问题是,如果我知道焦距,基线以及我相机的其他所有内容,如何手动创建Q矩阵以直接在函数reprojectImageTo3D()中使用?Q矩阵的基本格式是什么?
我希望从可变数量的数组中找到单个项目的所有组合.我如何在Ruby中执行此操作?
给定两个数组,我可以像这样使用Array.product:
groups = []
groups[0] = ["hello", "goodbye"]
groups[1] = ["world", "everyone"]
combinations = groups[0].product(groups[1])
puts combinations.inspect
# [["hello", "world"], ["hello", "everyone"], ["goodbye", "world"], ["goodbye", "everyone"]]
Run Code Online (Sandbox Code Playgroud)
当组包含可变数量的数组时,此代码如何工作?
我有这个功能,它在屏幕的左下角绘制一个小的3D轴坐标系,但根据我面前的情况,它可能会被剪裁.
例如,我在地面上绘制了一个平坦的地形,在XZ平面上Y = 0.摄像机位于Y = 1.75(模拟一般人的身高).如果我抬头,它工作正常,如果我向下看,它会被地平面夹住.
向上看
:http://i.stack.imgur.com/Q0i6g.png向下看:http://i.stack.imgur.com/D5LIx.png
我调用的函数在角落绘制轴系统是这样的:
void Axis3D::DrawCameraAxisSystem(float radius, float height, const Vector3D rotation) {
if(vpHeight == 0) vpHeight = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, vpWidth, vpHeight);
gluPerspective(45.0f, 1.0 * vpWidth / vpHeight, 1.0f, 5.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
glRotatef(-rotation.x, 1.0f, 0.0f, 0.0f);
glRotatef(-rotation.y, 0.0f, 1.0f, 0.0f);
DrawAxisSystem(radius, height);
}
Run Code Online (Sandbox Code Playgroud)
我认为现在有几个主要功能与问题相关:
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
void changeSize(int width, int height) {
if(height == 0) height = 1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, …Run Code Online (Sandbox Code Playgroud) 我遇到了一个给我这个错误的问题:
序列化类“App\Entity\User”的对象时检测到循环引用(配置限制:1)
我有一个企业实体,其中包含任务订单、车辆和用户。
与用户、公司和车辆有关系的订单实体。
和一个与订单和公司有关系的用户实体。
所以我有这个: Entreprise.php
class Entreprise
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="entreprise", orphanRemoval=true)
*/
private $users;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Vehicule", mappedBy="entreprise", orphanRemoval=true)
*/
private $vehicules;
/**
* @ORM\OneToMany(targetEntity="App\Entity\OrdreMission", mappedBy="entreprise", orphanRemoval=true)
*/
private $ordreMissions;
Run Code Online (Sandbox Code Playgroud)
OrdreMission.php:
class OrdreMission
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* Agent qui réalisera la mission
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="ordreMissions")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* Immatriculation de la voiture de …Run Code Online (Sandbox Code Playgroud)