uc伯克利人工分割图像.seg文件解析

简介: 之前看到  http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/ 提供的人工图像分割的.
之前看到


http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/

提供的人工图像分割的.seg格式的文件,他们提供了linux系统下面的matlab代码,什么的,但是我们要在windows平台下面用就比较麻烦,就心血来潮写一个试试,还请大牛们指点一二啊,嘿嘿嘿


下面是SegHuman.h

/*
// # Reload me!
// 
// SEGMENTATION FILE FORMAT
// 	David Martin
// 	8/2/2001
// 
// 	This document describes the segmentation file format.  Segmentation
// 	files end in ".seg".
// 
// 	The overall structure of the file is as follows:
// 
// <header>
// 	data
// 	<data>
// 
// 	The first part of the file is the header.  The header is ascii text,
// 	and can contain comments.  The comment character is '#'.  The header
// 	is separated from the data with a line containing the literal text
// 	"data".
// 
// 	The header can contain the following information, in any order:
// 
// format {*ascii|binary} {*cr|map}
// date <date string>
// 	image <int>	# image ID number
// 	user <int>	# user ID number
// 	width <int>	# width of image
// 	height <int>	# height of image
// 	segments <int>	# number of segments
// 	gray {*0|1}	# image presented in grayscale?
// 	invert {*0|1}	# image presented with pixel values inverted?
// 	flipflop {*0|1}	# image presented upside-down and backwards?
// 
// 	The {width,height,segments} lines are required.  All others lines are
// 	optional.  Default values are marked with a '*'.
// 
// 	The format line describes the format of the data section of the file.
// 	The default and recommended format is 'ascii cr' (cr = compressed
// 	row).  This document does not describe the other formats, as they are
// 	probably superfluous.
// 
// 	The 'ascii cr' format is designed to be very easy to parse; it is not
// 	optimized for space.  Use gzip if you want smaller files!  Each line
// 	in the data section contains 4 integers:
// 
// <s> <r> <c1> <c2>
// 
// 	All values start counting at 0.  <s> is the segment number; <r> is the
// 	row; <c1> and <c2> are column numbers.  The line means that columns
// 	[<c1>..<c2>] of row <r> belong to segment <s>.  Lines of this sort can
// 	appear in any order, and can be reordered without harm.  The only
// 	restriction is that each pixel must be named exactly once.
// 
// 	END
// 
// 
*/


#ifndef SEG_HUMAN
#define SEG_HUMAN



#include "stdafx.h"
#include "stdio.h"
#include <map>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <list>

#include <iostream>
using namespace std;

struct SEG
{
	int segment_number;
	int row;
	int column_number1;
	int column_number2;
};

class SegHuman
{
public:
	SegHuman(const char* path);
	bool LoadSEG(const char* path);

private:
	string name;
	int image_index;
	int segments_index;
	int height;
	int width;
	int gray;
	vector<SEG> MySeg;
};


#endif // SEGHMAN



下面是:SegHuman.cpp

#include "stdafx.h"
#include "SegHuman.h"

#include <iostream>
using namespace std;

SegHuman::SegHuman(const char* path)
{
	LoadSEG(path);
}

bool SegHuman::LoadSEG(const char* path)
{
int st = 0;
FILE* pfile = fopen(path, "r");
if (pfile)
{
	fseek(pfile,0,SEEK_END);
	int dwsize = ftell(pfile);
	rewind(pfile);

	char* filebuffer = new char[dwsize];
	fread(filebuffer, 1, dwsize, pfile);


	char* pBegin = filebuffer;
	char* pEnd = strchr(filebuffer, '\n');
	int uiIndex = 1;

	int st = 0;

	while (pEnd != NULL)
	{

		std::string strbuff;
		strbuff.insert(0, pBegin, pEnd-pBegin);
		if (strbuff.empty())
		{
			return false;
		}

		if (st==0) 
		{
		if (1 == sscanf(strbuff.c_str(),"image %d",&image_index)) st=1;
		} 
		else if (st==1)
		{
			if (1 == sscanf(strbuff.c_str(),"width %d",&width)) st=2;
		}
		else if (st==2)
		{
			if (1 == sscanf(strbuff.c_str(),"height %d",&height)) st=3;
		}
		else if (st==3)
		{
			if (1 == sscanf(strbuff.c_str(),"segments %d",&segments_index)) st=4;
		}
		else if (st==4)
		{
			if (1 == sscanf(strbuff.c_str(),"gray %d",&gray)) st=5;
		}
		else if (st==5)
		{
			if (0==strcmp(strbuff.c_str(),"data")) st=6;
		}
		else if (st==6)
		{
			SEG temp = { -1, -1, -1, -1};
if (4 == sscanf(strbuff.c_str(),"%d %d %d %d",&temp.segment_number, &temp.row, &temp.column_number1 , &temp.column_number2)) 
			{
				++uiIndex;
				MySeg.push_back(temp);
					
			}
	}


			pBegin = pEnd + 1;
			pEnd = strchr(pEnd + 1, '\n');
			
		}
		delete[] filebuffer;
		fclose(pfile);

		vector<SEG>::iterator iter = MySeg.begin();
		for (;iter !=MySeg.end(); ++iter)
		{
			cout<<iter->segment_number<<' ';
			cout<<iter->row<<' ';
			cout<<iter->column_number1 <<' ';
			cout<<iter->column_number2<<' ';
			cout<<endl;

		}
		getchar();

		return true;
	}

	return false;
}



下面的任务就是修改代码,把它用在OpenCV中,来显示人工分割的图像啦!



相关文章
|
监控 Java 应用服务中间件
高级java面试---spring.factories文件的解析源码API机制
【11月更文挑战第20天】Spring Boot是一个用于快速构建基于Spring框架的应用程序的开源框架。它通过自动配置、起步依赖和内嵌服务器等特性,极大地简化了Spring应用的开发和部署过程。本文将深入探讨Spring Boot的背景历史、业务场景、功能点以及底层原理,并通过Java代码手写模拟Spring Boot的启动过程,特别是spring.factories文件的解析源码API机制。
705 2
|
Java
Java“解析时到达文件末尾”解决
在Java编程中,“解析时到达文件末尾”通常指在读取或处理文件时提前遇到了文件结尾,导致程序无法继续读取所需数据。解决方法包括:确保文件路径正确,检查文件是否完整,使用正确的文件读取模式(如文本或二进制),以及确保读取位置正确。合理设置缓冲区大小和循环条件也能避免此类问题。
1785 2
|
SQL 关系型数据库 MySQL
数据库导入SQL文件:全面解析与操作指南
在数据库管理中,将SQL文件导入数据库是一个常见且重要的操作。无论是迁移数据、恢复备份,还是测试和开发环境搭建,掌握如何正确导入SQL文件都至关重要。本文将详细介绍数据库导入SQL文件的全过程,包括准备工作、操作步骤以及常见问题解决方案,旨在为数据库管理员和开发者提供全面的操作指南。一、准备工作在导
2483 0
|
人工智能 自然语言处理 Java
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
FastExcel 是一款基于 Java 的高性能 Excel 处理工具,专注于优化大规模数据处理,提供简洁易用的 API 和流式操作能力,支持从 EasyExcel 无缝迁移。
4370 65
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
|
自然语言处理 数据处理 Python
python操作和解析ppt文件 | python小知识
本文将带你从零开始,了解PPT解析的工具、工作原理以及常用的基本操作,并提供具体的代码示例和必要的说明【10月更文挑战第4天】
5052 60
|
Serverless 对象存储 人工智能
智能文件解析:体验阿里云多模态信息提取解决方案
在当今数据驱动的时代,信息的获取和处理效率直接影响着企业决策的速度和质量。然而,面对日益多样化的文件格式(文本、图像、音频、视频),传统的处理方法显然已经无法满足需求。
675 4
智能文件解析:体验阿里云多模态信息提取解决方案
|
Java API 数据处理
深潜数据海洋:Java文件读写全面解析与实战指南
通过本文的详细解析与实战示例,您可以系统地掌握Java中各种文件读写操作,从基本的读写到高效的NIO操作,再到文件复制、移动和删除。希望这些内容能够帮助您在实际项目中处理文件数据,提高开发效率和代码质量。
1169 4
|
存储 机器学习/深度学习 数据可视化
解析exe文件
如何使用`objdump`工具解析exe文件,包括exe文件的组成、`objdump`的用法以及如何查看exe文件的节头信息和完整内容。
1371 0
解析exe文件
云解析分享文件
这座建筑结合了现代设计与和谐的自然景观。大面积的玻璃窗让居住者可以充分享受美景和阳光,同时保证了室内充足的自然光线。是体验宁静生活与自然之美的理想之地。图片展现了其优美的自然环境和现代建筑设计的完美融合。
242 6
云解析分享文件
|
数据处理 Python
Python 高级技巧:深入解析读取 Excel 文件的多种方法
在数据分析中,从 Excel 文件读取数据是常见需求。本文介绍了使用 Python 的三个库:`pandas`、`openpyxl` 和 `xlrd` 来高效处理 Excel 文件的方法。`pandas` 提供了简洁的接口,而 `openpyxl` 和 `xlrd` 则针对不同版本的 Excel 文件格式提供了详细的数据读取和处理功能。此外,还介绍了如何处理复杂格式(如合并单元格)和进行性能优化(如分块读取)。通过这些技巧,可以轻松应对各种 Excel 数据处理任务。
1352 16

热门文章

最新文章

推荐镜像

更多
  • DNS