2016-09-17 2 views
0

私のプログラムを実行中にこのエラーが発生しました。OpenCVとC、cvPreprocessCategoricalResponsesの不正な引数(応答#0は整数ではありません)

私は

void calcolaSubpixel(IplImage *GT, costi ** totalCostMatrix, float ** subpixelM, int h, int w){ 
    int modulo; 
    int subpixel; 
    int i,j; 
    for (i = 0; i < h; i++) { 
     for (j = 0; j < w; j++) { 
      //TODO i valori ottneuti vanno 0-1, io li voglio da -0.5,0.5 
      int modulo = (CV_IMAGE_ELEM(GT, ushort, i, j))%256; 
      float subpixel01 = modulo/256.0f; 
      subpixelM[i][j] = subpixel01; 
     } 
    } 
} 

この機能を使用して値のfloatマトリックスを作成し、その後、私は

void fillLabels(IplImage *GT, float** subpixelM, float * labels){ 
    int h = GT->height, w = GT->width; 
    int i,j,L = 0; 

    for (i = 0; i < h; i++) { 
     for (j = 0; j < w; j++) { 
     //se il pixel in esame della ground truth non ha intensita 0 lo considero, 
     //altrimenti lo inserisco nella label: 
      if (CV_IMAGE_ELEM(GT, ushort, i, j) != 0) {  
       labels[L] = subpixelM[i][j]; 
       L++; 
      } 
     } 
    } 
} 

この機能でフロートの配列に入れとMat labelsMat(nRighe, 1, CV_32FC1, labels);場所のために、この配列のラベルを使用nRigheはSVMを教える前に計算された値です

CvSVM SVM; 
SVM.train(trainingDatasMat, labelsMat, Mat(), Mat(), params); 

trainingDatasMatは私に何かトラブルを与えませんが、ラベルはそのように構築されました。返信

OpenCV Error: Bad argument (response #0 is not integral) in cvPreprocessCategoricalResponses, file /home/vision/opencv-2.4.11/modules/ml/src/inner_functions.cpp, line 715 terminate called after throwing an instance of 'cv::Exception' what(): /home/vision/opencv-2.4.11/modules/ml/src/inner_functions.cpp:715: error: (-5) response #0 is not integral in function cvPreprocessCategoricalResponses

この問題を克服するための提案はありますか?これはSVMのためにこれらの設定では、メイン

#include "cost.h" 
#include "disparity.h" 
#include "fixed_window.h" 
#include "confidence.h" 
#include "utils.h" 
#include "stereoPipeline.h" 
#include "interpolation.h" 
#include "SGM.h" 
#include "learning.h" 
#include<iostream> 
#include<iomanip> 
#include<cv.h> 

using namespace cv; 
using namespace std; 


int main(int argc, char *argv[]) { 
int dMax=15; 
if (argc != 4) 
{ 
    printf("Usage: %s <image_id> <gaps> < <algo>\n", argv[0]); 
    return -1; 
} 
int id=atoi(argv[1]); 

//sistema l'id per evitare problemi con il numero di cifre 
char q[10]; 
if(id < 10){sprintf(q, "00%d", id); } 
if(id >= 10 && id <= 99){sprintf(q, "0%d", id); } 
if(id >= 100){sprintf(q, "%d", id); } 

int gaps=atoi(argv[2]); 
int algo=atoi(argv[3]); 

IplImage *L, *R, *GT; 
// *********************************************************** 
// *********************************************************** 
// ******  STEREO ALGORITHM  ****** 
// *********************************************************** 
// *********************************************************** 
char filenameL[100]; 
char filenameR[100]; 
char filenameGT[100]; 


//carico il nome delle immagini 
sprintf(filenameL,"/KITTI/image_0/000%s_10.png",q); 
sprintf(filenameR,"/KITTI/image_1/000%s_10.png",q); 
sprintf(filenameGT,"/KITTI/disp_occ/000%s_10.png",q); 


// load grayscale images 
L = cvLoadImage(filenameL, CV_LOAD_IMAGE_GRAYSCALE); 
R = cvLoadImage(filenameR, CV_LOAD_IMAGE_GRAYSCALE); 
GT= cvLoadImage(filenameGT, CV_LOAD_IMAGE_UNCHANGED);  

dMax=kitti_dMax(GT); 


int h = L->height, w = L->width; 
IplImage* DisparityL = cvCreateImage(cvGetSize(L),8,1); 
IplImage* DisparityR = cvCreateImage(cvGetSize(R),8,1); 

t_DSI* DSI=create_DSI(w,h,dMax); 
t_DSI *boxFilteredDSI=create_DSI(w,h,dMax); 
t_DSI* outDSI=create_DSI(w,h,dMax); 


// point-wise cost (Absolute Difference or Hamming distance on Census transforms) 
if (algo == 0) 
    AbsoluteDifferenceCost(L, R, dMax, DSI);  
else  
    HammingDistanceCost(L, R, dMax, 5, DSI); 

// TAD aggregation 
BoxFiltering(DSI, boxFilteredDSI, 5, 100); 

disparity_map(boxFilteredDSI,DisparityL, true); 
disparity_map_R(boxFilteredDSI,DisparityR, true); 
// show results 
/*cvShowImage("Left",L); 
cvShowImage("FW Left",DisparityL); 
cvShowImage("FW Right",DisparityR); 
cvWaitKey(0);*/ 

//matrice disparità 
int **disparityMatrix; 
disparityMatrix= (int **) calloc(h,sizeof(int *)); 
int z=0; 
for (z;z<h;z++){ 
disparityMatrix[z]=(int *) calloc(w,sizeof (int)); 
} 

//matrice dei costi 
costi ** totalCostMatrix; 
totalCostMatrix= (costi **) calloc(h,sizeof(costi *)); 
for (z=0;z<h;z++){ 
    totalCostMatrix[z]=(costi *) calloc(w,sizeof (costi)); 
} 


SGM(boxFilteredDSI, outDSI, dMax, 30, 300, 255); 
disparity_map(outDSI,DisparityL, true); 
disparity_map_R(outDSI,DisparityR, true); 

//findtotalcost riempie la matrice ---->> test con outdSI usata per SGM 
findTotalCost(outDSI,totalCostMatrix); 

int nRighe = linesLength(GT); 
printf ("\n\n%d\n", nRighe); 
float * labels; 
labels = (float *) calloc(nRighe, sizeof(float)); 
float ** trainingDatas; 
trainingDatas = (float **) calloc(nRighe, sizeof(float *)); 
for (z=0;z<nRighe;z++){ 
    trainingDatas[z] = (float *) calloc(3, sizeof(float)); 
} 

//matricisubpixels 
float ** subpixelM; 
subpixelM= (float **) calloc(h,sizeof(float *)); 
for (z=0;z<h;z++){ 
    subpixelM[z]=(float *) calloc(w,sizeof (float)); 
} 

//riempio i vettori labels e traingDatas 
//labels -> valori della GT 
//traingDatas -> i costi 
calcolaSubpixel(GT, totalCostMatrix, subpixelM, h, w); 
fillLabels(GT, subpixelM, labels); 
fillTrainingdatas(GT, totalCostMatrix, trainingDatas); 



//test 
labels[5] = 1.0; 
//trainingDatas[0][0] = 1; 
//trainingDatas[0][1] = 1; 
//trainingDatas[0][2] = 1; 


//imposto le label e i dati di training per effettuare il learning 
Mat labelsMat(nRighe, 1, CV_32FC1, labels); 
Mat trainingDatasMat(nRighe, 3, CV_32FC1, trainingDatas); 

// Set up SVM's parameters 
CvSVMParams params; 
params.svm_type = CvSVM::C_SVC; 
params.kernel_type = CvSVM::LINEAR; 
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6); 

// Train the SVM 
CvSVM SVM; 
SVM.train(trainingDatasMat, labelsMat, Mat(), Mat(), params); 
+0

paramsを設定するコードを投稿できますか? –

+0

答えはありませんが、 'sprintf(q、"%03d "....' '' –

+0

に感謝していますが、上記の部分を見つけてください// SGMあたりのテストアウトアウトうまく動作するファイル – heartlex

答えて

0

あります

に感謝し、labelsMat内のすべての値は整数でなければなりません。考えられる解決策は、calcolaSubpixelから次の行を削除することです。

float subpixel01 = modulo/256.0f; 

ただし、コードには他にも問題があります。特に、データポインタでcv :: Matを初期化する場合、そのポインタは、必要な基底型(次元と刻み幅を尊重)に対する連続したメモリへのポインタでなければなりません。あなたのコードでは、データポインタはfloat *ポインタの配列に設定されています(trainingDatasはfloat **です)。これを行う正しい方法は、float *(nRighe*3浮動小数点を指す)をtrainingDatasMatのコンストラクタに渡すことです。

これは簡単な方法では、cv :: Matがあなたのためにメモリ管理を行うことを許可することです。次の行に沿って何か:

Mat trainingDatasMat(nRighe, 3, CV_32FC1); 
fillTrainingdatas(GT, totalCostMatrix, (float*) trainingDatasMat.data); 
関連する問題