1.halcon绘制gnuplot
gnuplot_open_file ('C:/colors_mono.gp', GnuplotFileID)
read_funct_1d ('C:/f', SmoothedFunction_N)
gnuplot_plot_funct_1d (GnuplotFileID, SmoothedFunction_N)
gnuplot_plot_image(TiledImage, GnuplotFileID, 64, 64, 60, 30, 'nohidden3d')
gnuplot_plot_ctrl (GnuplotFileID, Area)
gnuplot_open_pipe (GnuplotFileID1)
gnuplot_close (GnuplotFileID)
2.opencv绘制函数
if(0){
using namespace cv;
Mat data_x(1, 151, CV_64F);
Mat data_y(1, 151, CV_64F);
for (int i = 0; i < data_x.cols; i++) {
double x = (i - data_x.cols / 2);
data_x.at<double>(0, i) = x;
data_y.at<double>(0, i) = 2*x * x * x + 5*x*x +3;
}
std::cout << "data_x : " << data_x << std::endl;
std::cout << "data_y : " << data_y << std::endl;
Mat plot_result;
Ptr<plot::Plot2d> plot = plot::Plot2d::create(data_x, data_y);
plot->render(plot_result);
imshow("plot 2d data in default way!", plot_result);
plot->setShowText(false);
plot->setShowGrid(false);
plot->setPlotBackgroundColor(Scalar(255, 200, 200));
plot->setPlotLineColor(Scalar(255, 0, 0));
plot->setPlotLineWidth(2);
plot->setInvertOrientation(true);
plot->render(plot_result);
imshow("The plot rendered with some of custom visualization options", plot_result);
waitKey();
}
3.matplotlib绘制函数
if (0)
{
std::vector<double> x;
std::vector<double> y;
for (double i = 0; i < 10; i += 0.1) {
x.push_back(i);
y.push_back(std::sin(i));
}
matplot::plot(x, y);
matplot::xticks({ 0, 2.5, 5, 7.5, 10 });
matplot::xlim({ 0, 10 });
matplot::ylim({ -1, 1 });
matplot::show();
matplot::save("demo.png");
}
4.c++绘制gnoplot
ofstream outFile("file.txt");
for (auto& xx : res)
{
outFile << xx << endl;
}
outFile.close();
if(0){
FILE* pipe = _popen("gnuplot -persist", "w");
if (!pipe) {
return ;
}
const char* cmd = "plot \"C:\\data.txt\" with linespoints, \"C:\\data1.txt\" with linespoints\n";
fprintf(pipe, cmd);
fflush(pipe);
_pclose(pipe);
}
5.c++读写本vector
if (1)
{
std::ifstream f1("C:\\data.txt");
std::string line; std::vector<double> vec;
while (std::getline(f1, line))
{
std::cout << line << endl;
vec.push_back((double)std::atof(line.c_str()));
}
std::vector<std::vector<double>> tt, res;
tt.push_back(vec);
cv::Sobel(tt, res, CV_32F, 1, 0, 3);
}
std::ifstream file("C:\\data.txt");
std::string line; std::vector<double> vec,res;
while (std::getline(file, line))
{
std::cout << line << std::endl;
vec.push_back((double)std::atof(line.c_str()));
}
file.close();
ofstream outFile("file.txt");
for (auto& xx : res)
{
outFile << xx << endl;
}
outFile.close();