Пример #1
0
void SubpelRefine::MatchPic(const PicArray& pic_data , const PicArray& refup_data , MEData& me_data ,
                             int ref_id)
{
    // Match a picture against a single reference. Loop over all the blocks
    // doing the matching

    // Initialisation //
    ////////////////////

    // Provide aliases for the appropriate motion vector data components
    MvArray& mv_array = me_data.Vectors( ref_id );
    TwoDArray<MvCostData>& pred_costs = me_data.PredCosts( ref_id );

    // Provide a block matching object to do the work
    BlockMatcher my_bmatch( pic_data , refup_data , m_predparams->LumaBParams(2) ,
                            m_predparams->MVPrecision() , mv_array , pred_costs );

    // Do the work //
    /////////////////

    // Loop over all the blocks, doing the work

    for (int yblock=0 ; yblock<m_predparams->YNumBlocks() ; ++yblock){
        for (int xblock=0 ; xblock<m_predparams->XNumBlocks() ; ++xblock){
            DoBlock(xblock , yblock , my_bmatch , me_data , ref_id );
        }// xblock
    }// yblock

}
Пример #2
0
void SubpelRefine::DoBlock(const int xblock , const int yblock ,
                           BlockMatcher& my_bmatch, MEData& me_data , const int ref_id )
{
    // For each block, home into the sub-pixel vector

    // Provide aliases for the appropriate motion vector data components
    MvArray& mv_array = me_data.Vectors( ref_id );

    const MVector mv_pred = GetPred( xblock , yblock , mv_array );
    const float loc_lambda = me_data.LambdaMap()[yblock][xblock];

    my_bmatch.RefineMatchSubp( xblock , yblock , mv_pred, loc_lambda );
}
Пример #3
0
void MotionEstimator::DoME(const FrameBuffer& my_buffer, int frame_num, MEData& me_data)
{

    const FrameParams& fparams = my_buffer.GetFrame(frame_num).GetFparams();

   // Step 1. 
   //Initial search gives vectors for each reference accurate to 1 pixel

    PixelMatcher pix_match( m_encparams );
    pix_match.DoSearch( my_buffer , frame_num , me_data);

    float lambda;
    // Get the references
    const std::vector<int>& refs = my_buffer.GetFrame(frame_num).GetFparams().Refs();

    const int num_refs = refs.size();
    if ( fparams.IsBFrame())
        lambda = m_encparams.L2MELambda();
    else
        lambda = m_encparams.L1MELambda();

    // Set up the lambda to be used
    me_data.SetLambdaMap( num_refs , lambda );

    MVPrecisionType orig_prec = m_encparams.MVPrecision();

    // Step 2. 
    // Pixel accurate vectors are then refined to sub-pixel accuracy

    if (orig_prec != MV_PRECISION_PIXEL)
    {
        SubpelRefine pelrefine( m_encparams );
        pelrefine.DoSubpel( my_buffer , frame_num , me_data );
    }
    else
    {
        // FIXME: HACK HACK
        // Mutiplying the motion vectors by 2 and setting MV precision to
        // HALF_PIXEL to implement pixel accurate motion estimate
        MvArray &mv_arr1 = me_data.Vectors(1);
        for (int j = 0; j < mv_arr1.LengthY(); ++j)
        {
            for (int i = 0; i < mv_arr1.LengthX(); ++i)
                mv_arr1[j][i] = mv_arr1[j][i] << 1;
        }
        if (num_refs > 1)
        {
            MvArray &mv_arr2 = me_data.Vectors(2);
            for (int j = 0; j < mv_arr2.LengthY(); ++j)
            {
                for (int i = 0; i < mv_arr2.LengthX(); ++i)
                    mv_arr2[j][i] = mv_arr2[j][i] << 1;
            }
        }
        m_encparams.SetMVPrecision(MV_PRECISION_HALF_PIXEL);
    }

    // Step3.
    // We now have to decide how each macroblock should be split 
    // and which references should be used, and so on.

    ModeDecider my_mode_dec( m_encparams );
    my_mode_dec.DoModeDecn( my_buffer , frame_num , me_data );
    
    if (orig_prec ==  MV_PRECISION_PIXEL)
    {
        // FIXME: HACK HACK
        // Divide the motion vectors by 2 to convert back to pixel
        // accurate motion vectors and reset MV precision to
        // PIXEL accuracy 
        MvArray &mv_arr1 = me_data.Vectors(1);
        for (int j = 0; j < mv_arr1.LengthY(); ++j)
        {
            for (int i = 0; i < mv_arr1.LengthX(); ++i)
                mv_arr1[j][i] = mv_arr1[j][i] >> 1;
        }
        if (num_refs > 1)
        {
            MvArray &mv_arr2 = me_data.Vectors(2);
            for (int j = 0; j < mv_arr2.LengthY(); ++j)
            {
                for (int i = 0; i < mv_arr2.LengthX(); ++i)
                    mv_arr2[j][i] = mv_arr2[j][i]>>1;
            }
        }