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机制。
340 2
|
Java
Java“解析时到达文件末尾”解决
在Java编程中,“解析时到达文件末尾”通常指在读取或处理文件时提前遇到了文件结尾,导致程序无法继续读取所需数据。解决方法包括:确保文件路径正确,检查文件是否完整,使用正确的文件读取模式(如文本或二进制),以及确保读取位置正确。合理设置缓冲区大小和循环条件也能避免此类问题。
1197 2
|
11月前
|
人工智能 自然语言处理 Java
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
FastExcel 是一款基于 Java 的高性能 Excel 处理工具,专注于优化大规模数据处理,提供简洁易用的 API 和流式操作能力,支持从 EasyExcel 无缝迁移。
2474 65
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
|
SQL 关系型数据库 MySQL
数据库导入SQL文件:全面解析与操作指南
在数据库管理中,将SQL文件导入数据库是一个常见且重要的操作。无论是迁移数据、恢复备份,还是测试和开发环境搭建,掌握如何正确导入SQL文件都至关重要。本文将详细介绍数据库导入SQL文件的全过程,包括准备工作、操作步骤以及常见问题解决方案,旨在为数据库管理员和开发者提供全面的操作指南。一、准备工作在导
1719 0
|
9月前
|
Java API 数据处理
深潜数据海洋:Java文件读写全面解析与实战指南
通过本文的详细解析与实战示例,您可以系统地掌握Java中各种文件读写操作,从基本的读写到高效的NIO操作,再到文件复制、移动和删除。希望这些内容能够帮助您在实际项目中处理文件数据,提高开发效率和代码质量。
241 4
|
10月前
|
Serverless 对象存储 人工智能
智能文件解析:体验阿里云多模态信息提取解决方案
在当今数据驱动的时代,信息的获取和处理效率直接影响着企业决策的速度和质量。然而,面对日益多样化的文件格式(文本、图像、音频、视频),传统的处理方法显然已经无法满足需求。
404 4
智能文件解析:体验阿里云多模态信息提取解决方案
|
自然语言处理 数据处理 Python
python操作和解析ppt文件 | python小知识
本文将带你从零开始,了解PPT解析的工具、工作原理以及常用的基本操作,并提供具体的代码示例和必要的说明【10月更文挑战第4天】
2269 60
|
12月前
|
消息中间件 存储 Java
RocketMQ文件刷盘机制深度解析与Java模拟实现
【11月更文挑战第22天】在现代分布式系统中,消息队列(Message Queue, MQ)作为一种重要的中间件,扮演着连接不同服务、实现异步通信和消息解耦的关键角色。Apache RocketMQ作为一款高性能的分布式消息中间件,广泛应用于实时数据流处理、日志流处理等场景。为了保证消息的可靠性,RocketMQ引入了一种称为“刷盘”的机制,将消息从内存写入到磁盘中,确保消息持久化。本文将从底层原理、业务场景、概念、功能点等方面深入解析RocketMQ的文件刷盘机制,并使用Java模拟实现类似的功能。
308 3
文件太大不能拷贝到U盘怎么办?实用解决方案全解析
当我们试图将一个大文件拷贝到U盘时,却突然跳出提示“对于目标文件系统目标文件过大”。这种情况让人感到迷茫,尤其是在急需备份或传输数据的时候。那么,文件太大为什么会无法拷贝到U盘?又该如何解决?本文将详细分析这背后的原因,并提供几个实用的方法,帮助你顺利将文件传输到U盘。
云解析分享文件
这座建筑结合了现代设计与和谐的自然景观。大面积的玻璃窗让居住者可以充分享受美景和阳光,同时保证了室内充足的自然光线。是体验宁静生活与自然之美的理想之地。图片展现了其优美的自然环境和现代建筑设计的完美融合。
109 6
云解析分享文件

推荐镜像

更多
  • DNS