@@ -168,7 +168,26 @@ namespace cv
168
168
else
169
169
plotSizeHeight = 300 ;
170
170
}
171
-
171
+ void setShowGrid (bool _needShowGrid)
172
+ {
173
+ needShowGrid = _needShowGrid;
174
+ }
175
+ void setShowText (bool _needShowText)
176
+ {
177
+ needShowText = _needShowText;
178
+ }
179
+ void setGridLinesNumber (int _gridLinesNumber)
180
+ {
181
+ if (_gridLinesNumber <= 0 )
182
+ _gridLinesNumber = 1 ;
183
+ gridLinesNumber = _gridLinesNumber;
184
+ }
185
+ void setPointIdxToPrint (int _cursorPos)
186
+ {
187
+ if (_cursorPos >= plotDataX.rows || _cursorPos < 0 )
188
+ _cursorPos = plotDataX.rows - 1 ;
189
+ cursorPos = _cursorPos;
190
+ }
172
191
// render the plotResult to a Mat
173
192
void render (OutputArray _plotResult)
174
193
{
@@ -189,8 +208,8 @@ namespace cv
189
208
int ImageXzero = (int )InterpXdataFindZero.at <double >(NumVecElements,0 );
190
209
int ImageYzero = (int )InterpYdataFindZero.at <double >(NumVecElements,0 );
191
210
192
- double CurrentX = plotDataX.at <double >(NumVecElements- 1 ,0 );
193
- double CurrentY = plotDataY.at <double >(NumVecElements- 1 ,0 );
211
+ double CurrentX = plotDataX.at <double >(cursorPos ,0 );
212
+ double CurrentY = plotDataY.at <double >(cursorPos ,0 );
194
213
195
214
drawAxis (ImageXzero,ImageYzero, CurrentX, CurrentY, plotAxisColor, plotGridColor);
196
215
@@ -245,6 +264,10 @@ namespace cv
245
264
double plotMinY_plusZero;
246
265
double plotMaxY_plusZero;
247
266
int plotLineWidth;
267
+ bool needShowGrid;
268
+ bool needShowText;
269
+ int gridLinesNumber;
270
+ int cursorPos;
248
271
249
272
// colors of each plot element
250
273
Scalar plotLineColor;
@@ -319,22 +342,30 @@ namespace cv
319
342
setPlotBackgroundColor (Scalar (0 , 0 , 0 ));
320
343
setPlotLineColor (Scalar (0 , 255 , 255 ));
321
344
setPlotTextColor (Scalar (255 , 255 , 255 ));
345
+ setShowGrid (true );
346
+ setShowText (true );
347
+ setGridLinesNumber (10 );
348
+ setPointIdxToPrint (-1 );
322
349
}
323
350
324
351
void drawAxis (int ImageXzero, int ImageYzero, double CurrentX, double CurrentY, Scalar axisColor, Scalar gridColor)
325
352
{
326
- drawValuesAsText (0 , ImageXzero, ImageYzero, 10 , 20 );
327
- drawValuesAsText (0 , ImageXzero, ImageYzero, -20 , 20 );
328
- drawValuesAsText (0 , ImageXzero, ImageYzero, 10 , -10 );
329
- drawValuesAsText (0 , ImageXzero, ImageYzero, -20 , -10 );
330
- drawValuesAsText (" X = %g" ,CurrentX, 0 , 0 , 40 , 20 );
331
- drawValuesAsText (" Y = %g" ,CurrentY, 0 , 20 , 40 , 20 );
353
+ if (needShowText)
354
+ {
355
+ drawValuesAsText (0 , ImageXzero, ImageYzero, 10 , 20 );
356
+ drawValuesAsText (0 , ImageXzero, ImageYzero, -20 , 20 );
357
+ drawValuesAsText (0 , ImageXzero, ImageYzero, 10 , -10 );
358
+ drawValuesAsText (0 , ImageXzero, ImageYzero, -20 , -10 );
359
+ drawValuesAsText ((format (" X_%d = " , cursorPos) + " %g" ).c_str (), CurrentX, 0 , 0 , 40 , 20 );
360
+ drawValuesAsText ((format (" Y_%d = " , cursorPos) + " %g" ).c_str (), CurrentY, 0 , 20 , 40 , 20 );
361
+ }
332
362
333
363
// Horizontal X axis and equispaced horizontal lines
334
- int LineSpace = 50 ;
364
+ int LineSpace = cvRound (plotSizeHeight / ( float )gridLinesNumber) ;
335
365
int TraceSize = 5 ;
336
366
drawLine (0 , plotSizeWidth, ImageYzero, ImageYzero, axisColor);
337
367
368
+ if (needShowGrid)
338
369
for (int i=-plotSizeHeight; i<plotSizeHeight; i=i+LineSpace){
339
370
340
371
if (i!=0 ){
@@ -349,7 +380,9 @@ namespace cv
349
380
350
381
// Vertical Y axis
351
382
drawLine (ImageXzero, ImageXzero, 0 , plotSizeHeight, axisColor);
383
+ LineSpace = cvRound (LineSpace * (float )plotSizeWidth / plotSizeHeight );
352
384
385
+ if (needShowGrid)
353
386
for (int i=-plotSizeWidth; i<plotSizeWidth; i=i+LineSpace){
354
387
355
388
if (i!=0 ){
@@ -420,13 +453,13 @@ namespace cv
420
453
421
454
};
422
455
423
- Ptr<Plot2d> createPlot2d (InputArray _plotData)
456
+ Ptr<Plot2d> Plot2d::create (InputArray _plotData)
424
457
{
425
458
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotData));
426
459
427
460
}
428
461
429
- Ptr<Plot2d> createPlot2d (InputArray _plotDataX, InputArray _plotDataY)
462
+ Ptr<Plot2d> Plot2d::create (InputArray _plotDataX, InputArray _plotDataY)
430
463
{
431
464
return Ptr<Plot2dImpl> (new Plot2dImpl (_plotDataX, _plotDataY));
432
465
}
0 commit comments