我想獲取行數的數據,但指針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
什麼都得不到?