c++ - How to plot a 3D graph (surfaceplot) from a Mat type of OpenCV using qwtplot3D? -
i have 2d mat data/image using opencv. plot 3d graph it, row x-axis, column y-axis & pixel values on each coordinate(row,column) z-axis. plot graph similar surf function in matlab. tried use bool loadfromdata (double **data, unsigned int columns, unsigned int rows, double minx, double maxx, double miny, double maxy) function program crashed when debugged till line. new in using qwtplot3d & qt4, please me see go wrong.
what did copying pixel values array, try make 2d array made of rows , columns , pass loadfromdata below:
//abs_outcorr mat type of opencv int rows= abs_outcorr.rows; int columns= abs_outcorr.cols * abs_outcorr.channels(); double frommat[columns*rows]; (int j=0; j<rows; j++) { double* data= abs_outcorr.ptr<double>(j); //access pixel value mat (int i=0; i<columns; i++) { frommat[i] = data[i]; } } double** x = new double * [rows]; for(int i=0; i<columns; i++) x[i] = new double[rows]; for(int i=0; i<rows; i++) for(int j=0; j<columns; j++) x[j][i] = frommat[columns*i + j]; for( int i=0; i<columns; i++) delete x[i]; delete []x; /* main project based on mainwindow buttons. these codes implemented in button clicked & pop out graph, not sure codes below work, please me */ qwidget window; window.setwindowtitle("plot 3d"); qhboxlayout layout; qwt3d::surfaceplot qsp(&window); qsp.loadfromdata(x, columns, rows, 0, columns, 0, rows); qsp.setrotation(30,0,15); qsp.setscale(1,1,1); qsp.setshift(0.15,0,0); qsp.setzoom(0.9); (unsigned i=0; i!=qsp.coordinates()->axes.size(); ++i) { qsp.coordinates()->axes[i].setmajors(7); qsp.coordinates()->axes[i].setminors(4); } qsp.coordinates()->axes[qwt3d::x1].setlabelstring("x"); qsp.coordinates()->axes[qwt3d::y1].setlabelstring("y"); qsp.coordinates()->axes[qwt3d::z1].setlabelstring("z"); qsp.setcoordinatestyle(qwt3d::box); qsp.updatedata(); qsp.updategl(); qsp.show(); layout.addwidget(&qsp); window.setlayout(&layout); window.resize(1000,800); window.show(); ////////////////////////////////////////////////////////////// //these of pixel value of mat (32x32) ////////////////////////////////////////////////////////////// row 0 column 0 9.61749e-08 row 0 column 1 2.16608e-09 row 0 column 2 3.25873e-08 row 0 column 3 2.65754e-08 row 0 column 4 2.93116e-08 row 0 column 5 6.55923e-08 row 0 column 6 4.56592e-08 row 0 column 7 4.91113e-08 row 0 column 8 1.73816e-08 row 0 column 9 2.27045e-10 row 0 column 10 7.36088e-08 . . . row 16 column 16 1 . . . row 31 column 23 5.1846e-08 row 31 column 24 1.01708e-07 row 31 column 25 4.25331e-09 row 31 column 26 2.77903e-08 row 31 column 27 1.14044e-08 row 31 column 28 6.03817e-08 row 31 column 29 2.65248e-08 row 31 column 30 1.46648e-08 row 31 column 31 8.05808e-08
basically mat/image bright dot in centre value of 1, while rest black 0. expected result should sharp straight peak in middle of plot. thanks.