Esempio n. 1
0
 int main() {
   fA1(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fA1IiEEDTcmtlNS_1AELi1ELi2EEcvT__EES2_
   fA2(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fA2IiEEDTcmcvNS_1AEilLi1ELi2EEcvT__EES2_
   fB1(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fB1IiEEDTcmtlNS_1BELi1ELi2EEcvT__EES2_
   fB2(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fB2IiEEDTcmcvNS_1BEilLi1ELi2EEcvT__EES2_
   fC1(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fC1IiEEDTcmtlNS_1CEilLi1ELi2EEEcvT__EES2_
   fC2(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fC2IiEEDTcmcvNS_1CEilLi1ELi2EEcvT__EES2_
   fD1(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fD1IiEEDTcmtlNS_1DEL_ZNS_1bEEEcvT__EES2_
   fD2(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fD2IiEEDTcmcvNS_1DEL_ZNS_1bEEcvT__EES2_
   fE1(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fE1IiEEDTcmtlNS_1EELi1ELi2EEcvT__EES2_
   fE2(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fE2IiEEDTcmcvNS_1EEilLi1ELi2EEcvT__EES2_
   fF1(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fF1IiEEDTcmtlNS_1FEilLi1ELi2EEEcvT__EES2_
   fF2(1); // CHECK-LABEL: define {{.*}} @_ZN5test73fF2IiEEDTcmcvNS_1FEilLi1ELi2EEcvT__EES2_
 }
Func opticalFlow_estimate (Func stBasis, uint8_t nAngle, uint8_t * orders, \
                           Expr filterthreshold, Expr divisionthreshold,\
                           Expr divisionthreshold2) {
// This function estimates components of optical flow fields as well as its speed and direction of movement
// basis: from spatio-temporal filters, angle: number of considered angles
    // orders: x (spatial index), y ( spatial index ), t (time index) and s ?
// ColorMgather function in MATLAB
// Pipeline:
// 1. Compute oriented filter basis at a particular angle
// {
//     basis -> X
//           -> Y
//           -> T
//           -> Xrg
//           -> Yrg
//           -> Trg
//           -> Xk
//           -> Yk
//           -> Tk
// }
    // Expr M0,M1,M2,M3,temp_a,temp_b,Tkd;
    // Expr M0 = cast<float>(0.0f);
    // Expr M1 = cast<float>(0.0f);
    // Expr M2 = cast<float>(0.0f);
    // Expr M3 = cast<float>(0.0f);
    // Expr temp_a = cast<float>(0.0f);
    // Expr temp_b = cast<float>(0.0f);
    // Expr Tkd = cast<float>(0.0f);

    // Expr D0 = cast<float>(0.0f);
    // Expr D1 = cast<float>(0.0f);
    // Expr D2 = cast<float>(0.0f);
    // Expr D3 = cast<float>(0.0f);
    // Expr N0 = cast<float>(0.0f);
    // Expr N1 = cast<float>(0.0f);
    // Expr N2 = cast<float>(0.0f);
    // Expr N3 = cast<float>(0.0f);
    // Expr A0 = cast<float>(0.0f);
    // Expr A1 = cast<float>(0.0f);
    // Expr A2 = cast<float>(0.0f);
    // Expr A3 = cast<float>(0.0f);
    Func Tkd;
    Func fA0; fA0(x,y,t) = Expr(0.0f);
    Func fA1; fA1(x,y,t) = Expr(0.0f);
    Func fA2; fA2(x,y,t) = Expr(0.0f);
    Func fA3; fA3(x,y,t) = Expr(0.0f);
    Func fD0; fD0(x,y,t) = Expr(0.0f);
    Func fD1; fD1(x,y,t) = Expr(0.0f);
    Func fD2; fD2(x,y,t) = Expr(0.0f);
    Func fD3; fD3(x,y,t) = Expr(0.0f);
    Func fN0; fN0(x,y,t) = Expr(0.0f);
    Func fN1; fN1(x,y,t) = Expr(0.0f);
    Func fN2; fN2(x,y,t) = Expr(0.0f);
    Func fN3; fN3(x,y,t) = Expr(0.0f);

    // std::vector<Expr> basisAtAngleExpr(5,cast<float>(0.0f));
    // Tuple basisAtAngle = Tuple(basisAtAngleExpr);
    Func basisAtAngle[nAngle/2];

// Compute spatial-temporal basis
    for (int iA = 0; iA <= nAngle / 2 - 1; iA++) {
        float aAngle = 2*iA*M_PI/nAngle;
        basisAtAngle[iA] = ColorMgather(stBasis, aAngle, orders, filterthreshold,
                                        divisionthreshold, divisionthreshold2);
        basisAtAngle[iA].compute_root();

        Expr M0,M1,M2,M3;
        M0 = basisAtAngle[iA](x,y,t)[0]; M1 = basisAtAngle[iA](x,y,t)[1];
        M2 = basisAtAngle[iA](x,y,t)[2]; M3 = basisAtAngle[iA](x,y,t)[3];

        fD0(x,y,t) += M0 * M0;
        fD1(x,y,t) += M0 * M2;
        fD2(x,y,t) += M2 * M0;
        fD3(x,y,t) += M2 * M2;
        fN0(x,y,t) += M1 * M0;
        fN1(x,y,t) += M1 * M2;
        fN2(x,y,t) += M3 * M0;
        fN3(x,y,t) += M3 * M2;
        // temp_a = abs(M0) * M1;
        // temp_b = abs(M2) * M3;
        Expr cosaAngle((float) cos(aAngle));
        Expr sinaAngle((float) sin(aAngle));
        // A0  += temp_a  * cosaAngle;
        // A1  += temp_b  * sinaAngle;
        // A2  += temp_a  * sinaAngle;
        // A3  += temp_b  * cosaAngle;
        // fA0(x,y,c,t) += abs(M0) * M1 * cosaAngle;
        fA0(x,y,t) += abs(M0) * M1 * cosaAngle;
        fA1(x,y,t) += abs(M2) * M3 * sinaAngle;
        fA2(x,y,t) += abs(M0) * M1 * sinaAngle;
        fA3(x,y,t) += abs(M2) * M3 * cosaAngle;
    }

    Tkd(x,y,t) = basisAtAngle[nAngle/2-1](x,y,t)[4];
    // return basisAtAngle[0]; // 4 debug
    // // Schedule basis
    // for (int iA = 0; iA <= nAngle / 2 - 1; iA++) {
    //     fD0.update(iA);
    //     fD1.update(iA);
    //     fD2.update(iA);
    //     fD3.update(iA);
    //     fN0.update(iA);
    //     fN1.update(iA);
    //     fN2.update(iA);
    //     fN3.update(iA);
    //     fA0.update(iA);
    //     fA1.update(iA);
    //     fA2.update(iA);
    //     fA3.update(iA);
    // }

    fD0.compute_root();
    fD1.compute_root();
    fD2.compute_root();
    fD3.compute_root();
    fN0.compute_root();
    fN1.compute_root();
    fN2.compute_root();
    fN3.compute_root();
    fA0.compute_root();
    fA1.compute_root();
    fA2.compute_root();
    fA3.compute_root();
    Tkd.compute_root();

    Func top_func;
    Func bottom_func;
    Expr speed0;
    Expr speed1;

// Polar fig ?
    top_func(x,y,t) = fN0(x,y,t) * fN3(x,y,t) - fN1(x,y,t) * fN2(x,y,t);
    top_func.compute_root();
    bottom_func(x,y,t) = fD0(x,y,t)  * fD3(x,y,t)  - fD1(x,y,t)  * fD2(x,y,t);
    bottom_func.compute_root();

    speed0 = sqrt(sqrt(abs(Mdefdiv(top_func(x,y,t) , bottom_func(x,y,t), Expr(0.0f)))));
    speed1 = Manglecalc(fA0(x,y,t) , fA1(x,y,t) , fA2(x,y,t) , fA3(x,y,t));
// Display the results ?
    speed0 = select(abs(Tkd(x,y,t)) > filterthreshold,speed0,Expr(0.0f));
    speed1 = select(abs(Tkd(x,y,t)) > filterthreshold,speed1,Expr(0.0f));

    Func speed("speed"); speed(x,y,t) = Tuple(speed0,speed1);
    return speed;

//Bimg = [T0n speed0 speed1] ?
//    Func img = outputvelocity(T0n,Func(speed0),Func(speed1),16, speedthreshold, filterthreshold);
}