1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| for(i=0; i<template_rect.width; i+=step)
{
int u = i + template_rect.x;
for(j=0; j<template_rect.height; j+=step)
{
int v = j + template_rect.y;
// Now we have viewport coordinates of current pixel in (u;v).
// Get pixel 3D coordinates (x;y;z).
float* pixel_coords = &CV_IMAGE_ELEM(pCoords, float, v, u*3);
float x = pixel_coords[0];
float y = pixel_coords[1];
float z = pixel_coords[2];
assert(z!=0);
// Set vector X with pixel 4D homogeneous coordinates (x, y, z, 1).
SET_VECTOR_4D(m_X, x, y, z, 1);
// Transform Z = W * X.
cvGEMM(m_W, m_X, 1, 0, 0, m_Z);
// Project X = P * Z.
cvGEMM(m_P, m_Z, 1, 0, 0, m_X);
// Get normalized device coordinates of the transformed pixel.
float Xd, Yd, Zd, Wd;
GET_VECTOR_4D(m_X, Xd, Yd, Zd, Wd);
// Convert normalized device coordinates (Xd, Yd, Zd, Wd) to window coordinates (u2;v2).
// We ignore Zd, because we don't need it here.
float u2 = fFrameWidth/2.0f * (1.0f + Xd/Wd);
float v2 = fFrameHeight/2.0f * (1.0f - Yd/Wd);
// Get the nearest integer pixel coords (u2i;v2i).
int u2i = cvFloor(u2);
int v2i = cvFloor(v2);
// Check if pixel (u2i, v2i) is inside pImgI.
if(u2i>=0 && u2i<pImgI->width &&
v2i>=0 && v2i<pImgI->height)
{
pixel_count++; // Increase count
.............. |
Partager