Slide 22
Slide 22 text
Copyright © Fixstars
Group
DPテーブルの計算
● ペナルティ項を整理すると、最終的には以下の計算になる
● OpenCV風に書くとこんな感じ
static void updateCost(const cv::Mat1i& C, cv::Mat1i& L, int D, int xp, int yp, int xc, int yc, int P1, int P2)
{
int minLp = COST_INF;
for (int d = 0; d < D; d++)
minLp = std::min(minLp, L(yp, xp, d));
for (int d = 0; d < D; d++)
{
const int Lp0 = L(yp, xp, d);
const int Lp1 = d > 0 ? L(yp, xp, d - 1) + P1 : COST_INF;
const int Lp2 = d < D - 1 ? L(yp, xp, d + 1) + P1 : COST_INF;
const int Lp3 = minLp + P2;
L(yc, xc, d) = C(yc, xc) + std::min(std::min(Lp0, Lp1), std::min(Lp2, Lp3)) - minLp;
}
}
オーバーフロー対策
22