⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segmentml.cc

📁 torch tracking code, it is a good code
💻 CC
字号:
const char *help = "\progname: segmentml.cc\n\code2html: This program reads a ppm image and segment it using diagonal GMM via ML.\n\version: Torch3 vision2.0, 2005\n\(c) Sebastien Marcel (marcel@idiap.ch)\n";#include "ImageRgb.h"#include "ImageGray.h"#include "ipSegmentDiagGMM.h"#include "DiskXFile.h"#include "xtprobeImageDiskXFile.h"//#include "Rectangle2D.h"//#include "Octon2D.h"#include "CmdLine.h"using namespace Torch;int main(int argc, char **argv){	char *image_filename;	int n_gaussians;	//bool octon;	bool gray;	bool xy;	bool norm;	bool verbose;  	// Construct the command line  	CmdLine cmd;	cmd.setBOption("write log", false);	  	// Put the help line at the beginning  	cmd.info(help);  	cmd.addText("\nArguments:");  	cmd.addSCmdArg("image filename", &image_filename, "image filename");  	cmd.addText("\nOptions:");  	cmd.addBCmdOption("-gray", &gray, false, "gray");  	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");  	cmd.addBCmdOption("-xy", &xy, false, "use also pixel coordinates for the segmentation");  	cmd.addBCmdOption("-norm", &norm, false, "use normalized pixels when using color");  	cmd.addICmdOption("-g", &n_gaussians, 3, "number of gaussians");  	//cmd.addBCmdOption("-octon", &octon, false, "uses octon instead of rectangles");	cmd.read(argc, argv);	Image *image_in = NULL;	if(gray) image_in = new ImageGray();	else image_in = new ImageRgb();	image_in->setBOption("verbose", verbose);		ImageDiskXFile *image_loader = new xtprobeImageDiskXFile(image_filename, "r");	image_in->loadImageXFile(image_loader);	delete image_loader;	if(verbose)	{		print("Image info:\n");		print("   width = %d\n", image_in->width);		print("   height = %d\n", image_in->height);		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);	}	ipCore *imachine = NULL;	if(gray) imachine = new ipSegmentDiagGMM(image_in->width, image_in->height, "gray", n_gaussians, xy);	else imachine = new ipSegmentDiagGMM(image_in->width, image_in->height, "rgb", n_gaussians, xy, norm);	imachine->setBOption("verbose", verbose);	imachine->process(image_in);	print("done.\n");	   	{		ImageRgb *blobimage = new ImageRgb(image_in->width, image_in->height);				for(int y = 0; y < image_in->height; y++)			for(int x = 0; x < image_in->width; x++)			{		   		int label_ = (int) imachine->seq_out->frames[0][y*image_in->width+x];							Color c;								if(label_ == 0) c = white;				else if(label_ == 1) c = red;				else if(label_ == 2) c = green;				else if(label_ == 3) c = blue;				else if(label_ == 4) c = yellow;				else if(label_ == 5) c = cyan;				else if(label_ == 6) c = pink;				else if(label_ == 7) c = orange;				else c = black;				blobimage->drawpixel(x, y, c);			}		blobimage->save("blob.ppm");				delete blobimage;	}		delete imachine;	delete image_in;	return(0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -