-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_sample.cpp
82 lines (65 loc) · 1.83 KB
/
plot_sample.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Matlab style plot functions for OpenCV by Changbo (zoccob@gmail).
#include "cv.h"
#include "highgui.h"
#include "cvplot.h"
#define rowPtr(imagePtr, dataType, lineIndex) \
(dataType *)(imagePtr->imageData + (lineIndex) * imagePtr->widthStep)
int main(int argc, char* argv[])
{
// load an image
char *imagefile = "test.jpg";
IplImage *image = cvLoadImage(imagefile);
if (image == NULL)
{
std::cout << "image error: " << imagefile << std::endl << std::flush;
return -1;
}
// show an image
cvShowImage("original", image);
// plot and label:
//
// template<typename T>
// void plot(const string figure_name, const T* p, int count, int step = 1,
// int R = -1, int G = -1, int B = -1);
//
// figure_name: required. multiple calls of this function with same figure_name
// plots multiple curves on a single graph.
// p : required. pointer to data.
// count : required. number of data.
// step : optional. step between data of two points, default 1.
// R, G,B : optional. assign a color to the curve.
// if not assigned, the curve will be assigned a unique color automatically.
//
// void label(string lbl):
//
// label the most recently added curve with lbl.
//
// specify a line to plot
int the_line = 100;
int key = -1;
while (the_line < image->height)
{
unsigned char *pb = rowPtr(image, unsigned char, the_line);
int width = image->width;
CvPlot::plot("RGB", pb+0, width, 3);
CvPlot::label("B");
CvPlot::plot("RGB", pb+1, width, 3, 255, 0, 0);
CvPlot::label("G");
CvPlot::plot("RGB", pb+2, width, 3, 0, 0, 255);
CvPlot::label("R");
key = cvWaitKey(0);
if (key == 32)
{
// plot the next line
the_line++;
// clear previous plots
CvPlot::clear("RGB");
}
else
{
break;
}
}
cvReleaseImage(&image);
return 0;
}