I have a 2D Mat data/image using OpenCV. I would like to plot a 3D graph from it, the row as x-axis, column as y-axis & the pixel values on each coordinate(row,column) as z-axis. I would like to plot the graph similar to the surf function in Matlab. I tried to use the
bool loadFromData (double **data, unsigned int columns, unsigned int rows, double minx, double maxx, double miny, double maxy)
function but my program crashed when I debugged till this line. I am actually very new in using this qwtplot3d & qt4, so please help me see where i go wrong.
What I did is copying all the pixel values into an array, then try to make it into a 2D array made of rows and columns and pass it to loadFromData like below:
//abs_outcorrisMattypeofopencvintrows=abs_outcorr.rows;intcolumns=abs_outcorr.cols*abs_outcorr.channels();doublefromMat[columns*rows];for(intj=0;j<rows;j++){double*data=abs_outcorr.ptr<double>(j);//accessthepixelvaluefromMatfor(inti=0;i<columns;i++){fromMat[i]=data[i];}}double**x=newdouble*[rows];for(inti=0;i<columns;i++)x[i]=newdouble[rows];for(inti=0;i<rows;i++)for(intj=0;j<columns;j++)x[j][i]=fromMat[columns*i + j];for(inti=0;i<columns;i++)deletex[i];delete[]x;/* My main project is based on mainwindow with some buttons. ALl these codes I implemented in a button clicked & I would like to pop out the graph, but not sure the codes below work */QWidgetwindow;window.setWindowTitle("plot 3d");QHBoxLayoutlayout;Qwt3D::SurfacePlotqsp(&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);for(unsignedi=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 are some of my pixel value of my Mat (32x32)
////////////////////////////////////////////////////
I have a 2D Mat data/image using OpenCV. I would like to plot a 3D graph from it, the row as x-axis, column as y-axis & the pixel values on each coordinate(row,column) as z-axis. I would like to plot the graph similar to the surf function in Matlab. I tried to use the
bool loadFromData (double **data, unsigned int columns, unsigned int rows, double minx, double maxx, double miny, double maxy)
function but my program crashed when I debugged till this line. I am actually very new in using this qwtplot3d & qt4, so please help me see where i go wrong.
What I did is copying all the pixel values into an array, then try to make it into a 2D array made of rows and columns and pass it to loadFromData like below:
////////////////////////////////////////////////////
//These are some of my pixel value of my 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 this Mat/image is a bright dot in the centre with value of 1, while the rest all black which are nearly 0. Thanks.
The expected result should look like a sharp straight peak in the middle of the plot.