Leap Motion的Image类



const float * distortion() const

The distortion calibration map for this image.

此图像的失真校准图

The calibration map is a 64x64 grid of points. Each point is defined by a pair of 32-bit floating point values. Each point in the map represents a ray projected into the camera. The value of a grid point defines the pixel in the image data containing the brightness value produced by the light entering along the corresponding ray. By interpolating between grid data points, you can find the brightness value for any projected ray. Grid values that fall outside the range [0..1] do not correspond to a value in the image data and those points should be ignored.

标定图是64x64的网格点。每个点都是由一对32位浮点值定义的。图中的每一个点都代表一个射线投射到相机。网格点的值定义图像数据中的像素,所包含的光沿对应的射线产生的亮度值。通过在网格数据点之间进行插值,你可以找到任何投影射线的亮度值。在网格值[ 0 .. 1 ]范围外的不对应于图像数据中的一个值,这些点应该被忽略。

const float* distortion_buffer = image.distortion();

The calibration map can be used to render an undistorted image as well as to find the true angle from the camera to a feature in the raw image. The distortion map itself is designed to be used with GLSL shader programs. In non-realtime contexts, it may be more convenient to use the Image::rectify() and Image::warp() functions.

标定图可以用来渲染不失真的图像以及从相机找到正确的角度到原始图像中的特征。失真图本身是被设计和GLSL着色器程序一起使用 。在非实时的情况下,可以更方便的使用Image::rectify() Image::warp()  函数 。 rectify 矫正       warp弯曲变形

If using shaders is not possible, you can use the distortion map directly. This can be faster than using thewarp() function, if carefully optimized:

如果使用着色器是不可能的,你可以直接使用变形图。如果精心优化,这可比使用warp()函数更快:

float destinationWidth = 320;
float destinationHeight = 120;
unsigned char destination[(int)destinationWidth][(int)destinationHeight];

//define needed variables outside the inner loop
float calibrationX, calibrationY;
float weightX, weightY;
float dX, dX1, dX2, dX3, dX4;
float dY, dY1, dY2, dY3, dY4;
int x1, x2, y1, y2;
int denormalizedX, denormalizedY;
int i, j;

const unsigned char* raw = image.data();
const float* distortion_buffer = image.distortion();

//Local variables for values needed in loop
const int distortionWidth = image.distortionWidth();
const int width = image.width();
const int height = image.height();

for (i = 0; i < destinationWidth; i += 1) {
    for (j = 0; j < destinationHeight; j += 1) {
        //Calculate the position in the calibration map (still with a fractional part)
        calibrationX = 63 * i/destinationWidth;
        calibrationY = 62 * (1 - j/destinationHeight); // The y origin is at the bottom
        //Save the fractional part to use as the weight for interpolation
        weightX = calibrationX - truncf(calibrationX);
        weightY = calibrationY - truncf(calibrationY);

        //Get the x,y coordinates of the closest calibration map points to the target pixel
        x1 = calibrationX; //Note truncation to int
        y1 = calibrationY;
        x2 = x1 + 1;
        y2 = y1 + 1;

        //Look up the x and y values for the 4 calibration map points around the target
        dX1 = distortion_buffer[x1 * 2 + y1 * distortionWidth];
        dX2 = distortion_buffer[x2 * 2 + y1 * distortionWidth];
        dX3 = distortion_buffer[x1 * 2 + y2 * distortionWidth];
        dX4 = distortion_buffer[x2 * 2 + y2 * distortionWidth];
        dY1 = distortion_buffer[x1 * 2 + y1 * distortionWidth + 1];
        dY2 = distortion_buffer[x2 * 2 + y1 * distortionWidth + 1];
        dY3 = distortion_buffer[x1 * 2 + y2 * distortionWidth + 1];
        dY4 = distortion_buffer[x2 * 2 + y2 * distortionWidth + 1];

         std::cout << i << ", " << j << " -- " << x1 << ", " << y1 << ", " << x2 << ", " << y2 << " -- "
                   << (x1 * 2 + y1 * distortionWidth) << ", "
                   << (x1 * 2 + y1 * distortionWidth + 1) << " -- "
                   << (x2 * 2 + y2 * distortionWidth) << ", "
                   << (x2 * 2 + y2 * distortionWidth + 1) << std::endl;
        //Bilinear interpolation of the looked-up values:
        // X value
        dX = dX1 * (1 - weightX) * (1 - weightY) +
             dX2 * weightX * (1 - weightY) +
             dX3 * (1 - weightX) * weightY +
             dX4 * weightX * weightY;

        // Y value
        dY = dY1 * (1 - weightX) * (1 - weightY) +
             dY2 * weightX * (1 - weightY) +
             dY3 * (1 - weightX) * weightY +
             dY4 * weightX * weightY;

        // Reject points outside the range [0..1]
        if((dX >= 0) && (dX <= 1) && (dY >= 0) && (dY <= 1)) {
            //Denormalize from [0..1] to [0..width] or [0..height]
            denormalizedX = dX * width;
            denormalizedY = dY * height;

            //look up the brightness value for the target pixel
            destination[i][j] = raw[denormalizedX + denormalizedY * width];
        } else {
            destination[i][j] = -1;
        }
    }
}


Distortion is caused by the lens geometry as well as imperfections in the lens and sensor window. The calibration map is created by the calibration process run for each device at the factory (and which can be rerun by the user).

畸变是由透镜的几何形状以及透镜和传感器窗口中的缺陷引起的。标定图就是在工厂的每个设备的校准过程的创建(并可由用户重新运行)。

Note, in a future release, there may be two distortion maps per image; one containing the horizontal values and the other containing the vertical values.

请注意,在未来的版本中,每个图像可能有两个失真映射;一个包含水平值和另一个包含垂直值。

Return

The float array containing the camera lens distortion map.

返回:包含相机镜头失真图的浮动阵列。

int distortionHeight()const

The distortion map height. //失真图的高度

Currently fixed at 64.当前固定在64

int correctionGridHeight = image.distortionHeight();                                                                  Grid 格子  

int distortionWidth()const

The stride of the distortion map. 失真图的跨度

Since each point on the 64x64 element distortion map has two values in the buffer, the stride is 2 times the size of the grid. (Stride is currently fixed at 2 * 64 = 128).

因为在缓冲区中的64×64单元变形图中每个点都有两个值,步幅是网格大小的2倍。(目前固定在2 * 64 = 128)。

int correctionGridWidth = image.distortionWidth();

FormatTypeformat() const

The image format. 图像格式

if(image.format() == Leap::Image::INFRARED){
    std::string openGL_format = "GL_RED";
    std::string openGL_type = "GL_UNSIGNED_BYTE";
}

int height() const

The image height. 图像的高度

int height = image.height();

int32_t  id()const

The image ID. 图像的ID。

Images with ID of 0 are from the left camera; those with an ID of 1 are from the right camera (with the device in its standard operating position with the green LED facing the operator).

ID为0的图像是从左边的相机获得的;ID为1的图像是从右边的相机获得的(设备的标准方式位置是绿色LED面向操作者)。

Image()
</pre><pre class="cpp" name="code">Constructs a <a target=_blank class="reference internal" href="https://developer.leapmotion.com/documentation/cpp/api/Leap.Image.html#cppclass_leap_1_1_image"><em>Image</em></a> object. 构造一个图像对象。

An uninitialized image is considered invalid. Get valid Image objects from a ImageList object obtained from the Frame::images() method.

未初始化图像视为无效。从Frame::images() 方法中获得ImageList对象中的有效的图像对象。

bool isValid()const

Reports whether this Image instance contains valid data. 判断这个图像实例是否包含有效的数据。

Return

true, if and only if the image is valid. 只有图像是有效的才会返回True.

bool operator!=(const Image &)const

Compare Image object inequality. 比较图像对象不等式。

Two Image objects are equal if and only if both Image objects represent the exact same Image and both Images are valid.

当且仅当两个图像对象代表了确切的相同的图像并且两个图像都是有效的,则判断为两个图像是相等。

bool operator==(const Image &)const

Compare Image object equality.

Two Image objects are equal if and only if both Image objects represent the exact same Image and both Images are valid.

float rayOffsetX() const

The horizontal ray offset. 水平射线偏移。

Used to convert between normalized coordinates in the range [0..1] and the ray slope range [-4..4].

用于转换之间的归一化坐标的范围[ 0 , 1 ]和射线斜率范围[ - 4 ,4 ]。

Leap::Vector raySlopes(-3.28, 1.76, 0);
Leap::Vector normRay =
    Leap::Vector(raySlopes.x * image.rayScaleX() + image.rayOffsetX(),
                 raySlopes.y * image.rayScaleY() + image.rayOffsetY(), 0);

float rayOffsetY() const

The vertical ray offset.

Used to convert between normalized coordinates in the range [0..1] and the ray slope range [-4..4].

Leap::Vector normSlopes(.09, .72, 0);
Leap::Vector slope((normSlopes.x - image.rayOffsetX())/image.rayScaleX(),
                   (normSlopes.y - image.rayOffsetY())/image.rayScaleY(), 0);

float rayScaleX()const

The horizontal ray scale factor. 水平射线比例因子。

Used to convert between normalized coordinates in the range [0..1] and the ray slope range [-4..4].

用于转换之间的归一化坐标的范围[ 0 .. 1 ]和射线斜率范围[ - 4 .. 4 ]。

Leap::Vector raySlopes(-3.28, 1.76, 0);
Leap::Vector normRay =
    Leap::Vector(raySlopes.x * image.rayScaleX() + image.rayOffsetX(),
                 raySlopes.y * image.rayScaleY() + image.rayOffsetY(), 0);

Vectorrectify(constVector & uv) const

Provides the corrected camera ray intercepting the specified point on the image.

提供校正后的相机射线截取图像上的指定点。

Given a point on the image, rectify() corrects for camera distortion and returns the true direction from the camera to the source of that image point within the Leap Motion field of view.

给出了图像上的一个点,rectify() 矫正相机失真并且返回从相机到该图像点的源的正确方向,在LM视野中。

This direction vector has an x and y component [x, y, 0], with the third element always zero. Note that this vector uses the 2D camera coordinate system where the x-axis parallels the longer (typically horizontal) dimension and the y-axis parallels the shorter (vertical) dimension. The camera coordinate system does not correlate to the 3D Leap Motion coordinate system.

这个方向向量有一个X和Y分量[ X,Y,0 ],与第三个元素总是零。注意,这个向量使用2D摄像机坐标系统,该坐标系中,X轴与长(通常是水平的)尺寸平行与Y轴与(垂直)尺寸短平行。摄像机坐标系与三维LM坐标系无关。

Leap::Vector feature(127, 68, 0);
Leap::Vector slopes = image.rectify(feature);





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值