Exemple #1
0
		bool PredictModel::CPredictModel::load(const FilePath& path)
		{
			if (m_model)
			{
				release();
			}

			m_model = svm_load_model(path.narrow().c_str());

			return (m_model != nullptr);
		}
	bool VideoWriter::CVideoWriter::open(const FilePath& path, const Size& size, const double fps)
	{
		if (isOpened())
		{
			close();
		}
		
		if (FileSystem::Exists(path))
		{
			FileSystem::Remove(path);
		}

		const bool result = m_writer.open(path.narrow(), cv::VideoWriter::fourcc('H', '2', '6', '4'), fps, cv::Size(size.x, size.y), true);

		if (result)
		{
			m_frameSize = size;
		}

		return result;
	}
Exemple #3
0
		bool Problem::CProblem::trainAndSaveModel(const FilePath& path, const Paramter& param) const
		{
			if (!m_hasData)
			{
				return false;
			}

			svm_model* model = svm_train(&m_problem, &param);

			const FilePath parentFilePath = FileSystem::ParentPath(path);

			if (!FileSystem::Exists(parentFilePath) && !FileSystem::CreateDirectories(parentFilePath))
			{
				return false;
			}

			const int32 result = svm_save_model(path.narrow().c_str(), model);

			svm_free_and_destroy_model(&model);

			return (result == 0);
		}
Exemple #4
0
	FontData::FontData(const FT_Library library, const FilePath& filePath, const FilePath& emojiFilePath, const int32 fontSize, const FontStyle style)
	{
		if (!InRange(fontSize, 1, 256))
		{
			return;
		}

		if (const FT_Error error = ::FT_New_Face(library, filePath.narrow().c_str(), 0, &m_faceText.face))
		{
			if (error == FT_Err_Unknown_File_Format)
			{
				// unsupported format
			}
			else if (error)
			{
				// failed to open or load
			}

			return;
		}

		if (const FT_Error error = ::FT_Set_Pixel_Sizes(m_faceText.face, 0, fontSize))
		{
			return;
		}

		if (const FT_Error error = ::FT_New_Face(library, emojiFilePath.narrow().c_str(), 0, &m_faceEmoji.face))
		{
			if (error == FT_Err_Unknown_File_Format)
			{
				// unsupported format
			}
			else if (error)
			{
				// failed to open or load
			}
		}
		else
		{
			if (const FT_Error error2 = ::FT_Set_Pixel_Sizes(m_faceEmoji.face, 0, fontSize))
			{
				//
			}
		}

		m_familyName	= Unicode::Widen(m_faceText.face->family_name);
		m_styleName		= Unicode::Widen(m_faceText.face->style_name);

		m_fontSize		= fontSize;
		m_ascender		= static_cast<int32>(m_faceText.face->size->metrics.ascender / 64);
		m_descender		= -static_cast<int32>(m_faceText.face->size->metrics.descender / 64);
		m_lineSpacing	= m_ascender + m_descender;
		m_bold			= static_cast<uint32>(style) & static_cast<uint32>(FontStyle::Bold);
		m_italic		= static_cast<uint32>(style) & static_cast<uint32>(FontStyle::Italic);
		m_noBitmap		= !(static_cast<uint32>(style) & static_cast<uint32>(FontStyle::Bitmap));

		const FT_UInt spaceGlyphIndex = ::FT_Get_Char_Index(m_faceText.face, U' ');

		if (const FT_Error error = ::FT_Load_Glyph(m_faceText.face, spaceGlyphIndex, FT_LOAD_DEFAULT | (m_noBitmap ? FT_LOAD_NO_BITMAP : 0)))
		{
			m_tabWidth = fontSize * 4;
		}
		else
		{
			m_tabWidth = static_cast<int32>(m_faceText.face->glyph->metrics.horiAdvance * 4 / 64);
		}	

		m_initialized	= true;
	}
Exemple #5
0
		bool Problem::CProblem::load(const FilePath& path)
		{
			int max_index, inst_max_index, i;
			size_t elements, j;
			FILE *fp = fopen(path.narrow().c_str(), "r");
			char *endptr;
			char *idx, *val, *label;

			if (fp == NULL)
			{
				LOG_FAIL(U"Could not open `{}`"_fmt(path));

				return false;
			}

			m_problem.l = 0;
			elements = 0;

			m_max_line_len = 1024;
			m_line = (char*)::malloc(m_max_line_len);
			while (readline(fp) != NULL)
			{
				char *p = strtok(m_line, " \t"); // label

											   // features
				while (1)
				{
					p = strtok(NULL, " \t");
					if (p == NULL || *p == '\n') // check '\n' as ' ' may be after the last feature
						break;
					++elements;
				}
				++elements;
				++m_problem.l;
			}
			rewind(fp);

			m_problem.y = new double[m_problem.l];
			m_problem.x = new svm_node*[m_problem.l];
			m_nodes.resize(elements);

			max_index = 0;
			j = 0;
			for (i = 0; i<m_problem.l; i++)
			{
				inst_max_index = -1; // strtol gives 0 if wrong format, and precomputed kernel has <index> start from 0
				readline(fp);
				m_problem.x[i] = &m_nodes[j];
				label = strtok(m_line, " \t\n");

				if (label == NULL) // empty line
				{
					return detail::ExitInputError(i + 1);
				}

				m_problem.y[i] = strtod(label, &endptr);
				if (endptr == label || *endptr != '\0')
				{
					return detail::ExitInputError(i + 1);
				}

				while (1)
				{
					idx = strtok(NULL, ":");
					val = strtok(NULL, " \t");

					if (val == NULL)
						break;

					errno = 0;
					m_nodes[j].index = (int)strtol(idx, &endptr, 10);
					if (endptr == idx || errno != 0 || *endptr != '\0' || m_nodes[j].index <= inst_max_index)
					{
						return detail::ExitInputError(i + 1);
					}
					else
						inst_max_index = m_nodes[j].index;

					errno = 0;
					m_nodes[j].value = strtod(val, &endptr);
					if (endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr)))
					{
						return detail::ExitInputError(i + 1);
					}

					++j;
				}

				if (inst_max_index > max_index)
					max_index = inst_max_index;
				m_nodes[j++].index = -1;
			}

			fclose(fp);

			m_maxIndex = max_index;
			m_hasData = true;

			return true;
		}