130 CByteImage* pSobelXImageLeft, CByteImage* pSobelXImageRight, CByteImage* pSobelYImageLeft, CByteImage* pSobelYImageRight)
147 for (
int i = 0; i < m_nParticles; i++)
148 for (
int j = 0; j < m_nDimension; j++)
150 s[i][j] = pConfig[j];
159 for (
int i = 0; i < m_nParticles / 2; i++)
160 for (
int j = 0; j < m_nDimension; j++)
162 s[i][j] = pConfig[j];
171 if (nTenthIndex >= 0 && nTenthIndex <= 9)
173 for (
int i = m_nParticles / 10 * nTenthIndex; i < m_nParticles / 10 * (nTenthIndex + 1); i++)
174 for (
int j = 0; j < m_nDimension; j++)
176 s[i][j] = pConfig[j];
185 for (
int i = 0; i < m_nDimension; i++)
200 for (
int i = 0; i < m_nDimension; i++)
257 #pragma omp parallel for
258 for (
int nNewIndex = 0; nNewIndex < m_nParticles; nNewIndex++)
260 int nOldIndex = PickBaseSample();
262 for (
int i = 0; i < m_nDimension; i++)
264 double dNewValue =
s[nOldIndex][i] + dSigmaFactor * sigma[i] * gaussian_random();
265 s_temp[nNewIndex][i] = (dNewValue >= lower_limit[i] && dNewValue <= upper_limit[i]) ? dNewValue : (0.7 * 0.5 * (lower_limit[i] + upper_limit[i]) + 0.3 *
s[nOldIndex][i] + 0.5 * dSigmaFactor * sigma[i] * gaussian_random());
271 double** temp = s_temp;
291 const int width = pImage->width;
293 int leftBorderInt, rightBorderInt, up, down, indexLeft, indexRight, indexMain, nTempOffset;
294 float leftBorder = 0, rightBorder = 0, leftOffset = 0, rightOffset = 0;
301 for (indexMain = 0; indexMain < pol->
nCorners - 1; indexMain++)
303 if (pol->
hull[indexMain].z != 2)
306 leftBorder = pol->
hullLeft[indexLeft].x;
310 if (pol->
hull[indexMain].z != 1)
313 rightBorder = pol->
hullRight[indexRight].x;
317 up = (int) pol->
hull[indexMain].y;
318 down = (
int) pol->
hull[indexMain + 1].y;
320 if (pol->
hull[indexMain + 1].z != 2)
324 if (pol->
hull[indexMain + 1].z != 1)
344 for (
int j = up; j > down; j--, leftBorder -= leftOffset, rightBorder -= rightOffset)
347 leftBorderInt = (int)leftBorder;
348 rightBorderInt = (int)rightBorder;
356 if (leftBorderInt < 0)
365 nTempOffset = j * width;
367 for (
int k = leftBorderInt; k < rightBorderInt; k++)
369 region_sum += pImage->pixels[nTempOffset + k];
389 const int num_polygons = 5;
394 for (
int i = 0; i < num_polygons; i++)
401 for (
int i = 0; i < num_polygons; i++)
410 int polygon_interior_sum, polygon_interior_size;
415 for (
int i = 0; i < num_polygons; i++)
418 region_sum += polygon_interior_sum;
419 region_length += polygon_interior_size;
425 for (
int i = 1; i < num_polygons; i++)
431 region_sum -= polygon_interior_sum;
432 region_length -= polygon_interior_size;
436 for (
int i = 1; i < num_polygons - 1; i++)
443 region_sum -= polygon_interior_sum;
444 region_length -= polygon_interior_size;
453 region_sum -= polygon_interior_sum;
454 region_length -= polygon_interior_size;
471 int up, down, left, right, lineSum;
472 double xOffset, xDiff, yOffset, yDiff, lineLength;
474 #ifdef DSHT_USE_EDGE_DIRECTION
476 double angleSum, normalX, normalY;
477 #endif // DSHT_USE_EDGE_DIRECTION
484 const int width = pImage->width;
486 for (
int i = 0; i < nPoints - 1; i++)
490 lineLength =
sqrt((linePoints[i + 1].x - linePoints[i].x) * (linePoints[i + 1].x - linePoints[i].x) + (linePoints[i + 1].y - linePoints[i].y) * (linePoints[i + 1].y - linePoints[i].y));
492 #ifdef DSHT_USE_EDGE_DIRECTION
494 normalX = (linePoints[i + 1].y - linePoints[i].y);
495 normalY = -(linePoints[i + 1].x - linePoints[i].x);
496 #endif // DSHT_USE_EDGE_DIRECTION
498 if (linePoints[i].y > linePoints[i + 1].y)
500 up = (int)linePoints[i].y;
501 down = (int)linePoints[i + 1].y;
502 xOffset = linePoints[i + 1].x;
506 up = (int)linePoints[i + 1].y;
507 down = (int)linePoints[i].y;
508 xOffset = linePoints[i].x;
511 if (linePoints[i].x > linePoints[i + 1].x)
513 right = (int)linePoints[i].x;
514 left = (int)linePoints[i + 1].x;
515 yOffset = linePoints[i + 1].y;
519 right = (int)linePoints[i + 1].x;
520 left = (int)linePoints[i].x;
521 yOffset = linePoints[i].y;
524 if (up < DSHT_IMAGE_HEIGHT && down >= 0 && left >= 0 && right <
DSHT_IMAGE_WIDTH)
526 xDiff = (linePoints[i + 1].x - linePoints[i].x) / (linePoints[i + 1].y - linePoints[i].y);
527 yDiff = (linePoints[i + 1].y - linePoints[i].y) / (linePoints[i + 1].x - linePoints[i].x);
529 #ifdef DSHT_USE_EDGE_DIRECTION
530 for (
int j = down; j < up; j++, xOffset += xDiff)
532 absVal = pImage->pixels[j * width + (int)xOffset];
534 angleSum +=
abs(((
double)pImage->pixels[j * width + (
int)xOffset] * normalX + (
double)pImage->pixels[j * width + (
int)xOffset] * normalY) / ((
double)absVal + 0.001));
538 for (
int j = left; j < right; j++, yOffset += yDiff)
540 absVal = pImage->pixels[((int)yOffset) * width + j];
542 angleSum +=
abs(((
double)pImage->pixels[((
int)yOffset) * width + j] * normalX + (
double)pImage->pixels[((
int)yOffset) * width + j] * normalY) / ((
double)absVal + 0.001));
545 edge_length += (int)lineLength;
547 edge_sum += (int)((
double)lineSum * lineLength / ((double)(up - down + right - left) + 0.001));
548 angle_diffs += angleSum / ((double)(up - down + right - left) + 0.001);
551 for (
int j = down; j < up; j++, xOffset += xDiff)
553 lineSum += pImage->pixels[j * width + (int)xOffset];
556 for (
int j = left; j < right; j++, yOffset += yDiff)
558 lineSum += pImage->pixels[((int)yOffset) * width + j];
561 edge_length += (int)lineLength;
563 edge_sum += (int)((
double)lineSum * lineLength / ((double)(up - down + right - left) + 0.001));
564 #endif // DSHT_USE_EDGE_DIRECTION (else)
577 const int num_polygons = 5;
582 for (
int i = 0; i < num_polygons; i++)
589 for (
int i = 0; i < num_polygons; i++)
595 int temp_edge_sum, temp_edge_length;
596 double temp_angle_diffs;
601 for (
int i = 0; i < num_polygons; i++)
604 edge_sum += temp_edge_sum;
605 edge_length += temp_edge_length;
606 angle_diffs += temp_angle_diffs;
624 double dPosX, dPosY, dRadius;
638 dMinDistance = 1000000000;
645 if (dTempDist < dMinDistance)
647 dMinDistance = dTempDist;
657 if (std::isnan(dDistanceZ))
659 dDistanceZ = FLT_MAX;
671 dMinDistance = 1000000000;
678 if (dTempDist < dMinDistance)
680 dMinDistance = dTempDist;
708 int nRegionSumLeftImg, nRegionLengthLeftImg, nEdgeSumLeftImg, nEdgeLengthLeftImg;
709 int nRegionSumRightImg, nRegionLengthRightImg, nEdgeSumRightImg, nEdgeLengthRightImg;
710 double fAngleDiffsLeftImg, fAngleDiffsRightImg;
717 CalculateEdgeCue(nEdgeSumLeftImg, nEdgeLengthLeftImg, fAngleDiffsLeftImg, nModelIndex,
true);
718 CalculateEdgeCue(nEdgeSumRightImg, nEdgeLengthRightImg, fAngleDiffsRightImg, nModelIndex,
false);
720 double dTrBallDistXY, dTrBallDistZ;
725 m_ppProbabilities[0][nParticleIndex] = 0.5 * (nRegionSumLeftImg + nRegionSumRightImg);
726 m_ppProbabilities[1][nParticleIndex] = (double)(nRegionSumLeftImg + nRegionSumRightImg) / ((double)(nRegionLengthLeftImg + nRegionLengthRightImg) + 0.001);
728 m_ppProbabilities[2][nParticleIndex] = 0.5 * (nEdgeSumLeftImg + nEdgeSumRightImg);
729 m_ppProbabilities[3][nParticleIndex] = (double)(nEdgeSumLeftImg + nEdgeSumRightImg) / ((double)(nEdgeLengthLeftImg + nEdgeLengthRightImg) + 0.001);
730 #ifdef DSHT_USE_EDGE_DIRECTION
731 m_ppProbabilities[4][nParticleIndex] = -(fAngleDiffsLeftImg + fAngleDiffsRightImg) / ((
double)(nEdgeLengthLeftImg + nEdgeLengthRightImg) + 0.001);
734 #endif // DSHT_USE_EDGE_DIRECTION
739 return (
double)(nRegionSumLeftImg / 255) + ((
double)nRegionSumLeftImg / ((double)(nRegionLengthLeftImg * 255) + 0.001));
755 double min = 99999999;
756 double max = -99999999;
758 for (
int j = 0; j < m_nParticles; j++)
778 for (
int j = 0; j < m_nParticles; j++)
793 #pragma omp parallel for
794 for (
int j = 0; j < m_nParticles; j++)
796 #ifdef DSHT_USE_EDGE_DIRECTION
797 pi[j] = exp(15.0 / 31.0 * (
808 pi[j] = exp(15.0 / 31.0 * (
818 #endif // DSHT_USE_EDGE_DIRECTION
841 if (j % 100 == 0) printf(
"pi[i] is nan! m_ppProbabilities[0][j] = %f, m_ppProbabilities[1][j] = %f, m_ppProbabilities[2][j] = %f, m_ppProbabilities[3][j] = %f, m_ppProbabilities[4][j] = %f, m_ppProbabilities[5][j] = %f, m_ppProbabilities[6][j] = %f\n",
860 for (i = 0; i < m_nDimension; i++)
874 std::vector<double> temp(m_nDimension);
875 for (i = 0; i < m_nDimension; i++)
883 for (i = 0; i < m_nDimension; i++)
890 int nRegionLength = 0;
907 double dAngleDiffs = 0;
910 pRating->
dEdgePercentage = (double)nRegionSum / ((
double)nRegionLength + 0.001);
911 pRating->
dEdgeDirection = dAngleDiffs / ((double)nRegionLength + 0.001);
922 #ifdef DSHT_USE_EDGE_DIRECTION
941 #endif // DSHT_USE_EDGE_DIRECTION
1009 for (
int i = 0; i < 6; i++)
1013 for (
int i = 6; i < m_nDimension; i++)
1017 return sqrt(result);