main.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 72 行
CPP
72 行
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#include <fstream>
#include <yarp/os/all.h>
#include <yarp/sig/all.h>
using namespace yarp::os;
using namespace yarp::sig;
using namespace yarp::sig::file;
using namespace std;
int main(int argc, char *argv[]) {
if (argc==1) {
printf("Please supply source image filename (e.g. \"in.ppm\")\n");
printf("Then I will make maze.txt and maze.ppm\n");
exit(1);
}
ImageOf<PixelRgb> img;
if (!read(img,argv[1])) {
printf("Failed to read image %s\n",argv[1]);
exit(1);
}
printf("Read a %dx%d image\n", img.width(), img.height());
printf("Converting to gray scale\n");
ImageOf<PixelMono> mono;
mono.copy(img);
printf("Thresholding\n");
IMGFOR(mono,x,y) {
mono.pixel(x,y) = 255*(mono.pixel(x,y)>=128);
}
img.copy(mono);
printf("Writing maze.ppm\n");
write(img,"maze.ppm");
printf("Writing maze.txt\n");
ofstream fout("maze.txt");
if (0) {
for (int x=0; x<mono.width(); x++) {
for (int y=0; y<mono.height(); y++) {
if (mono(x,y)<128) {
fout << "#";
} else {
fout << " ";
}
}
fout << endl;
}
} else {
for (int y=0; y<mono.height(); y++) {
for (int x=0; x<mono.width(); x++) {
if (mono(x,y)<128) {
fout << "#";
} else {
fout << " ";
}
}
fout << endl;
}
}
fout.close();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?