Esempio n. 1
0
    cv::Point2f pyramidIteration(char& status, const cv::Point2f& pointI, const cv::Point2f& pointJ, const cv::Mat& I,
                                 const cv::Mat& J, const int patchSize = 5)
    {
        try
        {
            cv::Point2f result;

            // Extract a patch around the image
            std::vector<std::vector<float>> patch(patchSize + 2, std::vector<float>(patchSize + 2));
            std::vector<std::vector<float>> patchIt(patchSize, std::vector<float>(patchSize));

            status = extractPatch(patch, (int)pointI.x,(int)pointI.y, patchSize + 2, I);
        //    if (status)
        //        return result;

            status = extractPatchIt(patchIt, pointI.x, pointI.y, pointJ.x, pointJ.y, I, J, patchSize);

        //    if (status)
        //        return result;

            // Get the Ix, Iy and It vectors
            std::vector<float> ix, iy, it;
            getVectors(ix, iy, it, patch, patchIt, patchSize);

            // Calculate optical flow
            cv::Point2f delta;
            status = computeLK(delta, ix, iy, it);

        //    if (status)
        //        return result;

            result = pointJ + delta;

            return result;
        }
        catch (const std::exception& e)
        {
            error(e.what(), __LINE__, __FUNCTION__, __FILE__);
            return cv::Point2f{};
        }
    }
Esempio n. 2
0
// The compute() method does the actual work of the node using the inputs
// of the node to generate its output.
//
// Compute takes two parameters: plug and data.
// - Plug is the the data value that needs to be recomputed
// - Data provides handles to all of the nodes attributes, only these
//   handles should be used when performing computations.
//
MStatus motionPathNode::compute( const MPlug& plug, MDataBlock& data )
{
    double	f;
    MStatus status;

    // Read the attributes we need from the datablock.
    //
    double	uVal			= data.inputValue( uValue ).asDouble();
    bool	fractionModeVal	= data.inputValue( fractionMode ).asBool();
    bool	followVal		= data.inputValue( follow ).asBool();
    int		frontAxisVal	= data.inputValue( frontAxis ).asShort();
    int		upAxisVal		= data.inputValue( upAxis ).asShort();
    bool	bankVal			= data.inputValue( bank ).asBool();
    double  bankScaleVal	= data.inputValue( bankScale ).asDouble();
    double  bankThresholdVal= data.inputValue( bankThreshold ).asDouble();
    double	offsetVal		= data.inputValue( offset ).asDouble();
    double	wobbleRateVal	= data.inputValue( wobbleRate ).asDouble();

    // Make sure the value is fractional.
    //
    if ( fractionModeVal ) {
        f = uVal;
    } else {
        f = parametricToFractional( uVal, &status );
    }
    CHECK_MSTATUS_AND_RETURN_IT( status );

    // To compute the sample location on the path, first wrap the fraction
    // around the start of the the path in case it goes past the end
    // to prevent clamping, then compute the sample location on the path.
    //
    f = wraparoundFractionalValue( f, &status );
    CHECK_MSTATUS_AND_RETURN_IT( status );

    MPoint location = position( data, f, &status );
    CHECK_MSTATUS_AND_RETURN_IT( status );

    // Get the orthogonal vectors on the motion path.
    //
    const MVector worldUp = MGlobal::upAxis();
    MVector	front, side, up;
    CHECK_MSTATUS_AND_RETURN_IT( getVectors( data, f, front, side, up,
                                 &worldUp ) );

    // If follow (i.e. rotation) is enabled, check if banking is also
    // enabled and if so, bank into the turn.
    //
    if ( followVal && bankVal ) {
        MQuaternion bankQuat = banking( data, f, worldUp,
                                        bankScaleVal, bankThresholdVal, &status );
        CHECK_MSTATUS_AND_RETURN_IT( status );
        up = up.rotateBy( bankQuat );
        side = front ^ up;
    }

    // Compute the wobble that moves the sphere back and forth as it
    // traverses the path.
    //
    if ( fabs( offsetVal ) > ALMOST_ZERO
            && fabs( wobbleRateVal ) > ALMOST_ZERO ) {
        double wobble = offsetVal * sin( TWO_PI * wobbleRateVal * f );
        MVector tmp = side * wobble;
        location += tmp;
    }

    // Write the result values to the output plugs.
    //
    data.outputValue( allCoordinates ).set( location.x, location.y,
                                            location.z );
    if ( followVal ) {
        MTransformationMatrix	resultOrientation = matrix( front, side,
                up, frontAxisVal, upAxisVal, &status );
        CHECK_MSTATUS_AND_RETURN_IT( status );
        MTransformationMatrix::RotationOrder ro
            = (MTransformationMatrix::RotationOrder)
              ( data.inputValue( rotateOrder ).asShort() + 1 );
        double  rot[3];
        status = MTransformationMatrix( resultOrientation ).getRotation(
                     rot, ro );
        CHECK_MSTATUS_AND_RETURN_IT( status );
        data.outputValue( rotate ).set( rot[0], rot[1], rot[2] );
    }

    return( MS::kSuccess );
}