转载:XNA Matrices Demystified

本文解释了矩阵在游戏开发中的基本概念及用途,详细介绍了3D向量和4x4矩阵的构成,并阐述了如何利用矩阵来表示方向、位置和缩放等,帮助读者摆脱传统的偏航-俯仰-翻滚旋转系统。
转自:http://www.nuclex.org/pages/introduction/xna-matrices-demystified

Matrices are often feared by non math-savvy programmers. Many a game resorted to the old Yaw/Pitch/Roll rotation system and only constructs matrices on-the-fly because the programmer felt more at ease with the conventional yaw-pitch-roll rotation system.

This article tries to uncloud the mystical matrix structure and explains why you needn't fear matrices and should, in fact, dump the good ol' yaw-pitch-roll rotation system for good.

Vectors

Let's start this by examining vectors, which you probably already know. A 3D vector carries an X, Y and Z coordinate. Vectors were originally meant to store directions exclusively, but they are also commonly used by programmers to store positions in space.

If the X axis of your world coordinate system was extending to the right, then a vector of {X:1 Y:0 Z:0} would be pointing to the right and a vector of {X:-1 Y:0 Z:0} would be pointing to the left.

It's really that simple. Just assume you're sitting in the center of your world's coordinate system at {X:0 Y:0 Z:0}. Take any vector and draw a point at the coordinates contained in it. Look at the point. There, you're looking in the direction that's stored in the vector!

Vectors can have different lengths. Going back to the previous example, a vector of {X:2 Y:0 Z:0} would still be pointing to the right, but have a length of 2 units. You'll often hear the term "normalized". A normalized vector is simply a vector with a length of exactly 1, or, in other words, it is a pure direction.

What's in a Matrix?

Your typical 4x4 matrix (that means an array of 4 times 4 numbers) looks like this:

M11 M12 M13 M14
M21 M22 M23 M24
M31 M32 M33 M34
M41 M42 M43 M44

It stores an orientation and a position. The orientation is contained in the upper left 3x3 values:

Right.X  Right.Y  Right.Z  ?
Up.X     Up.Y     Up.Z     ?
In.X     In.Y     In.Z     ?
?        ?        ?        ?

Right, those are three vectors pointing in different directions.

  • The first line contains the X, Y and Z coordinates of a vector pointing towards the right.
  • The second line carries the coordinates of a vector that's pointing upwards
  • The final line is a vector that's pointing forwards

All three vectors need to be normalized (as explained before, that means they need to have a length of exactly 1.0 units).

That's it, only 3 harmless vectors. When you come accross 3x3 matrices, well, that's all there is to them!

The additional fields in a 4x4 matrix are used to store two different things:

Right.X     Right.Y     Right.Z     Scale.X
Up.X        Up.Y        Up.Z        Scale.Y
In.X        In.Y        In.Z        Scale.Z
Position.X  Position.Y  Position.Z  <always 1.0>

At the bottom row (in fields M41, M42 and M43), a position is stored. This works just the same as when you would manually store the X, Y and Z coordinates of your object, camera, player or whatever the matrix is used for.

At the rightmost columns, in M14, M24 and M34, the matrix stores the scale of your object. If you would set them to 2.0 each, that would indicate that the object is twice as big as it normally is.

So, in two simple sentences, a 3x3 matrix stores an orientation using 3 vectors; one pointing right, one up and one into the direction the matrix is facing. A 4x4 matrix additionally stores the position and scale of an object.


转载于:https://www.cnblogs.com/jerryhong/articles/1086159.html

一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值