您的位置:首页 > 运维架构

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

2012-12-07 10:14 120 查看
作者: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/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: