First, preface
QT's Qgraphicsview class has powerful view capabilities, along with the Qgraphicsscene class and the Qgraphicsitem class. The general idea is to construct the scene class, then add various elements to the scene object, and finally use the Qgraphicsview class to display the scene.
Second, draw the spectral curve
The main implementation features are:
1 Pass Click on the image line number, then draw the curve, the code is as follows:
1 voidSpectralprofiledialog::addpressslot ()2 {3 //setmodal (0);4Hyperprocess *ptr = (hyperprocess*) Parentwidget ();5Curfilename = ptr->Curfilename;6CurrentRow = ptr->Currow;7Currentcol = ptr->Curcol;8 9 if(Curfilename = ="")Ten { OneQmessagebox::information ( This,"Message Error","Current Scene is null!"); A return; - } - the if(Currentcol = =-1|| CurrentRow = =-1) - { -Qmessagebox::information ( This,"Message Error","Please Select A Pixel"); - return; + } - +Cv::mat curimg =Gdalopencv::gdal2mat (curfilename); A if(Currentcol > Curimg.cols | | currentrow >curimg.rows) at return; - - intCount =curimg.channels (); - -Std::vector<cv::mat>Curimgmat (count); - Cv::split (Curimg,curimgmat); in -Qvector<qpointf>Pixspectraldata (count); to DoubleTmpmaxvalue; + DoubleTmpminvalue; - DoubleMaxValue =0; the for(intc =0; c<count;c++) * { $Cv::minmaxidx (curimgmat[c],&tmpminvalue,&tmpmaxvalue);Panax Notoginseng if(MaxValue <tmpmaxvalue) -MaxValue =Tmpmaxvalue; thePixspectraldata[c].setx (curimgmat[c].at<float>(Currentcol,currentrow)); +Pixspectraldata[c].sety (c+1); A } the + floatX_scale =1.0* (Ui->spectralgraphicsview->height ()-1)/MaxValue; - floatY_scale =1.0* (Ui->spectralgraphicsview->width ()-1)/count; $ $ Qpen pen; -Pen.setwidth (2); -Qcolor QC=QCOLOR::FROMHSL (rand ()% the, rand ()% the, rand ()% $); the Pen.setcolor (Qcolor (qc.red (), Qc.green (), Qc.blue ()); - Wuyi for(intc =0; C<curimg.channels ()-1; C + +) the { -Myscene->addline (PIXSPECTRALDATA[C].Y () *y_scale,-1.0* (pixspectraldata[c].x () *X_scale), Wupixspectraldata[c+1].Y () *y_scale,-1.0* (pixspectraldata[c+1].x () *X_scale), pen); - } AboutUi->spectralgraphicsview->Setscene (myScene); $}
Three
4. Draw Spectral curve Qgraphicsview class