我想获取行数的数据,但指针CvMat* data, CvMat* responses
在main()
中什么也没有。最小,完整,varifiable例子显示如下:指针无法获取数据
#include "opencv2/core/core_c.h"
#include "opencv2/ml/ml.hpp"
#include <cstdio>
#include <fstream>
#include <iomanip>
#define ATTRIBUTES_PER_SAMPLE 9
#define NUM_OF_ALL_SAMPLES 950
using namespace std;
int read_data(CvMat* data, CvMat* responses)
{
float temp=1.0;
data = cvCreateMat(NUM_OF_ALL_SAMPLES, ATTRIBUTES_PER_SAMPLE, CV_32F);
responses = cvCreateMat(NUM_OF_ALL_SAMPLES, 1, CV_32F);
for(int line = 0; line < NUM_OF_ALL_SAMPLES; line++)
for(int attribute = 0; attribute <= ATTRIBUTES_PER_SAMPLE ; attribute++){
if(attribute < ATTRIBUTES_PER_SAMPLE){
CV_MAT_ELEM(*data, float, line, attribute) = temp;
}
else if(attribute == ATTRIBUTES_PER_SAMPLE){
CV_MAT_ELEM(*responses, float, line, 0) = temp;
}
}
return 1;
}
///////////////////////////////////////////////////////////////////////////
int main()
{
CvMat* data = 0;
CvMat* responses = 0;
int ok = read_data(data, responses);
int nsamples_all = data->rows; // <--------- error happens here
cvReleaseMat(&data);
cvReleaseMat(&responses);
return 0;
return 0;
}
的错误是在0x013715c2在opencv_pointer.exe
未处理的异常:0000005: 访问冲突读取位置0x00000014。
我的编译器是VS2008。为什么指针CvMat* data, CvMat* responses
什么都得不到?