⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motion_estimation.c

📁 QccPack implementation in C
💻 C
📖 第 1 页 / 共 3 页
字号:
            {              QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateBilinear()");              goto Error;            }        }      else        if (QccIMGImageComponentInterpolateFilter(current_frame,                                                  &reference_frame2,                                                  filter1))          {            QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateFilter()");            goto Error;          }      if (filter2 == NULL)        {          if (QccIMGImageComponentInterpolateBilinear(&reference_frame2,                                                      reference_frame))            {              QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateBilinear()");              goto Error;            }        }      else        if (QccIMGImageComponentInterpolateFilter(&reference_frame2,                                                  reference_frame,                                                  filter2))          {            QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateFilter()");            goto Error;          }      break;    case QCCVID_ME_EIGHTHPIXEL:      if ((reference_frame->num_rows != 8 * current_frame->num_rows) ||          (reference_frame->num_cols != 8 * current_frame->num_cols))        {          QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Reference-frame size is inconsistent with current-frame size for eighth-pixel motion estimation");          goto Error;        }      reference_frame2.num_rows = 2 * current_frame->num_rows;      reference_frame2.num_cols = 2 * current_frame->num_cols;      if (QccIMGImageComponentAlloc(&reference_frame2))        {          QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentAlloc()");          goto Error;        }      reference_frame3.num_rows = 4 * current_frame->num_rows;      reference_frame3.num_cols = 4 * current_frame->num_cols;      if (QccIMGImageComponentAlloc(&reference_frame3))        {          QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentAlloc()");          goto Error;        }      if (filter1 == NULL)        {          if (QccIMGImageComponentInterpolateBilinear(current_frame,                                                      &reference_frame2))            {              QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateBilinear()");              goto Error;            }        }      else        if (QccIMGImageComponentInterpolateFilter(current_frame,                                                  &reference_frame2,                                                  filter1))          {            QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateFilter()");            goto Error;          }      if (filter2 == NULL)        {          if (QccIMGImageComponentInterpolateBilinear(&reference_frame2,                                                      &reference_frame3))            {              QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateBilinear()");              goto Error;            }        }      else        if (QccIMGImageComponentInterpolateFilter(&reference_frame2,                                                  &reference_frame3,                                                  filter2))          {            QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateFilter()");            goto Error;          }      if (filter3 == NULL)        {          if (QccIMGImageComponentInterpolateBilinear(&reference_frame3,                                                      reference_frame))            {              QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateBilinear()");              goto Error;            }        }      else        if (QccIMGImageComponentInterpolateFilter(&reference_frame3,                                                  reference_frame,                                                  filter3))          {            QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Error calling QccIMGImageComponentInterpolateFilter()");            goto Error;          }      break;    default:      QccErrorAddMessage("(QccVIDMotionEstimationCreateReferenceFrame): Unrecognized motion-estimation accuracy (%d)",                         subpixel_accuracy);      goto Error;    }  return_value = 0;  goto Return; Error:  return_value = 1; Return:  QccIMGImageComponentFree(&reference_frame2);  QccIMGImageComponentFree(&reference_frame3);  return(return_value);}int QccVIDMotionEstimationCreateCompensatedFrame(QccIMGImageComponent                                                 *motion_compensated_frame,                                                 const QccIMGImageComponent                                                 *reference_frame,                                                 const QccIMGImageComponent                                                 *motion_vectors_horizontal,                                                 const QccIMGImageComponent                                                 *motion_vectors_vertical,                                                 int block_size,                                                 int subpixel_accuracy){  int return_value;  QccMatrix reference_block = NULL;  int block_row, block_col;  int mv_row, mv_col;  if (motion_compensated_frame == NULL)    return(0);  if (reference_frame == NULL)    return(0);  if (motion_vectors_horizontal == NULL)    return(0);  if (motion_vectors_vertical == NULL)    return(0);  if (motion_compensated_frame->image == NULL)    return(0);  if (reference_frame->image == NULL)    return(0);  if (motion_vectors_horizontal->image == NULL)    return(0);  if (motion_vectors_vertical->image == NULL)    return(0);  if ((motion_vectors_horizontal->num_rows !=       motion_compensated_frame->num_rows / block_size) ||      (motion_vectors_horizontal->num_cols !=       motion_compensated_frame->num_cols / block_size))    {      QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Motion-vector field is inconsistent with current-frame size");      goto Error;    }  if ((motion_vectors_vertical->num_rows !=       motion_compensated_frame->num_rows / block_size) ||      (motion_vectors_vertical->num_cols !=       motion_compensated_frame->num_cols / block_size))    {      QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Motion-vector field is inconsistent with current-frame size");      goto Error;    }  switch (subpixel_accuracy)    {    case QCCVID_ME_FULLPIXEL:      if ((reference_frame->num_rows != motion_compensated_frame->num_rows) ||          (reference_frame->num_cols != motion_compensated_frame->num_cols))        {          QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Reference-frame size is inconsistent with current-frame size for full-pixel motion estimation");          goto Error;        }      break;    case QCCVID_ME_HALFPIXEL:      if ((reference_frame->num_rows !=           2 * motion_compensated_frame->num_rows) ||          (reference_frame->num_cols !=           2 * motion_compensated_frame->num_cols))        {          QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Reference-frame size is inconsistent with current-frame size for half-pixel motion estimation");          goto Error;        }      break;    case QCCVID_ME_QUARTERPIXEL:      if ((reference_frame->num_rows !=           4 * motion_compensated_frame->num_rows) ||          (reference_frame->num_cols !=           4 * motion_compensated_frame->num_cols))        {          QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Reference-frame size is inconsistent with current-frame size for quarter-pixel motion estimation");          goto Error;        }      break;    case QCCVID_ME_EIGHTHPIXEL:      if ((reference_frame->num_rows !=           8 * motion_compensated_frame->num_rows) ||          (reference_frame->num_cols !=           8 * motion_compensated_frame->num_cols))        {          QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Reference-frame size is inconsistent with current-frame size for eighth-pixel motion estimation");          goto Error;        }      break;    default:      QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Unrecognized motion-estimation accuracy (%d)",                         subpixel_accuracy);      goto Error;    }  if ((reference_block = QccMatrixAlloc(block_size, block_size)) == NULL)    {      QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Error calling QccMatrixAlloc()");      goto Error;    }  for (block_row = 0;       block_row < motion_compensated_frame->num_rows;       block_row += block_size)    for (block_col = 0;         block_col < motion_compensated_frame->num_cols;         block_col += block_size)      {        mv_row = block_row / block_size;        mv_col = block_col / block_size;        if (QccVIDMotionEstimationExtractBlock(reference_frame,                                               (double)block_row +                                               motion_vectors_vertical->image                                               [mv_row][mv_col],                                               (double)block_col +                                               motion_vectors_horizontal->image                                               [mv_row][mv_col],                                               reference_block,                                               block_size,                                               subpixel_accuracy))          {            QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Error calling QccVIDMotionEstimationExtractBlock()");            goto Error;          }        if (QccVIDMotionEstimationInsertBlock(motion_compensated_frame,                                              (double)block_row,                                              (double)block_col,                                              reference_block,                                              block_size,                                              QCCVID_ME_FULLPIXEL))          {            QccErrorAddMessage("(QccVIDMotionEstimationCreateCompensatedFrame): Error calling QccVIDMotionEstimationInsertBlock()");            goto Error;          }      }  return_value = 0;  goto Return; Error:  return_value = 1; Return:  QccMatrixFree(reference_block, block_size);  return(return_value);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -