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
| for (int disp = 0; disp < maxdisp; ++disp)
{
for (unsigned int i = 0; i < left->width; ++i)
{
for (unsigned int j = 0; j < left->height; ++j)
{
CvPoint center = cvPoint(i + (winsize - 1) / 2, j + (winsize - 1) / 2);
for (unsigned int x = 0; x < winsize; ++x)
{
for (unsigned int y = 0; y < winsize; ++y)
{
//center diff color
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3)
- CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3));
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 1)
- CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 1));
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 2)
- CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 2));
//left center to point color
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3)
- CV_IMAGE_ELEM(left, uchar, j + y, (i + x) * 3));
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 1)
- CV_IMAGE_ELEM(left, uchar, j + y, (i + x) * 3 + 1));
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(left, uchar, center.y, center.x * 3 + 2)
- CV_IMAGE_ELEM(left, uchar, j + y, (i + x) * 3 + 2));
// right center to point color
if (i + x + disp < left->width)
{
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3)
- CV_IMAGE_ELEM(right, uchar, j + y, (i + x + disp) * 3));
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 1)
- CV_IMAGE_ELEM(right, uchar, j + y, (i + x + disp) * 3 + 1));
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += abs(CV_IMAGE_ELEM(right, uchar, center.y, (center.x + disp) * 3 + 2)
- CV_IMAGE_ELEM(right, uchar, j + y, (i + x + disp) * 3 + 2));
}
// distance
CV_IMAGE_ELEM(ret[disp], float, j + y, i + x) += sqrtf((center.x - (i + x)) * (center.x - (i + x)) + (center.y - (j + y)) * (center.y - (j + y)));
}
}
} |
Partager