【OpenCV学习】矩阵的单点读取与存储

作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/

/*
 * =====================================================================================
 *
 *       Filename:  array1.c
 *
 *    Description:  To show how to set and get a Array
 *
 *        Version:  1.0
 *        Created:  01/08/2009 09:17:17 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Futuredaemon (BUPT), gnuhpc@gmail.com
 *        Company:  BUPT_UNITED
 *
 * =====================================================================================
 */

#pragma comment( lib, "cxcore.lib" )
#include "cv.h"
#include <stdio.h>
int main()
{
  CvMat* mat = cvCreateMat(3,3,CV_32FC1);
  cvZero(mat);//将矩阵置0
//为矩阵元素赋值
  CV_MAT_ELEM( *mat, float, 0, 0 ) = 1.f;
  CV_MAT_ELEM( *mat, float, 0, 1 ) = 2.f;
  CV_MAT_ELEM( *mat, float, 0, 2 ) = 3.f;
  CV_MAT_ELEM( *mat, float, 1, 0 ) = 4.f;
  CV_MAT_ELEM( *mat, float, 1, 1 ) = 5.f;
  CV_MAT_ELEM( *mat, float, 1, 2 ) = 6.f;
  CV_MAT_ELEM( *mat, float, 2, 0 ) = 7.f;
  CV_MAT_ELEM( *mat, float, 2, 1 ) = 8.f;
  CV_MAT_ELEM( *mat, float, 2, 2 ) = 9.f;
//获得矩阵元素(0,2)的值
  float *p = (float*)cvPtr2D(mat, 0, 2);
  printf("%f/n",*p);
    return 0;
}

作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/


               作者:gnuhpc
               出处:http://www.cnblogs.com/gnuhpc/
               除非另有声明,本网站采用知识共享“署名 2.5 中国大陆”许可协议授权。


分享到:

原文地址:https://www.cnblogs.com/gnuhpc/p/2806662.html