当前位置: 首页 > news >正文

做网站必须认证吗制作宣传册用什么app

做网站必须认证吗,制作宣传册用什么app,小程序主题wordpress,wordpress新浪云平台Imgui(3) | 基于 imgui-SFML 的 mnist 数据集查看器 文章目录 Imgui(3) | 基于 imgui-SFML 的 mnist 数据集查看器0. 介绍1. 处理 mnist 数据集2. 显示单张图像和label2.1 显示单张图像2.2 点选列表后更新显示的图像2.3 显示 label2.4 使用完整的列表 总结 0. 介绍 把mnist数据…Imgui(3) | 基于 imgui-SFML 的 mnist 数据集查看器 文章目录 Imgui(3) | 基于 imgui-SFML 的 mnist 数据集查看器0. 介绍1. 处理 mnist 数据集2. 显示单张图像和label2.1 显示单张图像2.2 点选列表后更新显示的图像2.3 显示 label2.4 使用完整的列表 总结 0. 介绍 把mnist数据集保存为多张.png图像、 train-label.txt 后 编写一个 GUI 程序查看图像和对应的标签。 这是一个简陋的demo可以扩展它来支持其他数据集的显示。 规划: 处理 mnist 数据集显示单张图像和label图像文件名列表的显示点选列表item后切换显示的图像和label 1. 处理 mnist 数据集 from mnist import MNIST import matplotlib.pyplot as plt import numpy as np # 导入numpy import osdef save_images_and_labels(images, labels, directory, label_filename):将图像和标签保存到指定目录。if not os.path.exists(directory):os.makedirs(directory)label_file_path os.path.join(directory, label_filename)with open(label_file_path, w) as label_file:for i, (image, label) in enumerate(zip(images, labels), start1):image_filename f{i}.pngimage_path os.path.join(directory, image_filename)# 将图像数据转换为NumPy数组并重塑image_array np.array(image, dtypenp.uint8).reshape(28, 28)# 保存图像plt.imsave(image_path, image_array, cmapgray)# 写入标签label_file.write(f{image_filename} {label}\n)def main():# 加载MNIST数据集mndata MNIST(mnist_data)train_images, train_labels mndata.load_training()test_images, test_labels mndata.load_testing()# 保存训练数据集save_images_and_labels(train_images, train_labels, train, train-label.txt)# 保存测试数据集save_images_and_labels(test_images, test_labels, test, test-label.txt)if __name__ __main__:main()目录结构: train|-- 1.png|-- 2.png...|-- train-label.txt2. 显示单张图像和label 2.1 显示单张图像 简单起见 直接使用 imgui-SFML 进行窗口创建 方便后续直接添加 imgui 的 GUI widget. CMakeLists.txt 的写法查看之前的博客内容。 加载了 train/1.png 图像文件到 sf::Texture 对象通过 sf::Sprite 装载。 sprite 的好处是可以设定位置还可以缩放。 我放大了20倍。关键代码: sf::Texture texture;if (!texture.loadFromFile(../train/1.png)){std::cerr Error loading image std::endl;return -1;}sf::Sprite sprite;sprite.setTexture(texture);sprite.setScale(20, 20);sprite.setPosition(20, 20);完整代码: #include imgui.h #include imgui-SFML.h#include SFML/Graphics.hpp #include SFML/System/Clock.hpp #include SFML/Window/Event.hpp#include iostreamint main() {constexpr int win_width 960;constexpr int win_height 640;sf::RenderWindow window(sf::VideoMode(win_width, win_height), mnist viewer);window.setFramerateLimit(60);bool ret ImGui::SFML::Init(window); // [imgui-SFML]if (!ret)return -1;sf::CircleShape shape(100.f);shape.setFillColor(sf::Color::Green);sf::Texture texture;if (!texture.loadFromFile(../train/1.png)){std::cerr Error loading image std::endl;return -1;}sf::Sprite sprite;sprite.setTexture(texture);sprite.setScale(10, 10); // 水平和垂直方向都放大20倍sprite.setPosition(20, 20);sf::Clock deltaClock;while (window.isOpen()){sf::Event event;while (window.pollEvent(event)){ImGui::SFML::ProcessEvent(window, event); // [imgui-SFML]if (event.type sf::Event::Closed){window.close();}}ImGui::SFML::Update(window, deltaClock.restart()); // [imgui-SFML]window.clear();window.draw(sprite);ImGui::SFML::Render(window); // [imgui-SFML]window.display();}ImGui::SFML::Shutdown(); // [imgui-SFML]return 0; }2.2 点选列表后更新显示的图像 sprite 对象就是一个容器 或者说带有位置的放大镜 你随时可以换一个新的 texture 丢给它。 现在我们通过 imgui 显示一个 list 任意个一个 list item 被选中的时候就加载对应的图像文件获取 texture 后装到 sprite 里头界面上就看到更新的图像了: 关键代码: // 使用ImGui创建一个简单的列表ImGui::Begin(Image List);// 假设文件名为1.png到10.pngfor (int i 1; i 10; i) {std::string fileName std::to_string(i) .png;// 如果列表项被点击if (ImGui::Selectable(fileName.c_str(), currentFile fileName)) {currentFile fileName; // 更新当前选中的文件名// 加载对应的纹理if (!texture.loadFromFile(currentFile)) {std::cerr Failed to load currentFile std::endl;} else {sprite.setTexture(texture);}}}ImGui::End();2.3 显示 label train-label.txt 每一行是 image_name image_label 的形式 例如: 1.png 0使用哈希表存储这一映射关系 然后每当通过GUI交互选择了新的文件名字时 从字典里查询出对应的 label。 在 imgui 里显示当前图像的 label 很简单 只需要添加 ImGui::Text, 并用 ImGui::Begin() 和 End() 包裹即可: int currentLabel label_map[currentFile];ImGui::Begin(Label Info);ImGui::Text(Current Image: %s, currentFile.c_str());ImGui::Text(Label: %d, currentLabel);ImGui::End();增大显示的字体 label 是我们关注的重要信息 要用大字体显示 label 需要先加载字体并执行build和刷新 否则程序运行阶段会遇到 imgui 的检查失败。 关键代码: // 加载字体const std::string asset_dir ../../games/Resources;const std::string font_path asset_dir /Arial.ttf;// 在这里添加字体ImFont* bigFont ImGui::GetIO().Fonts-AddFontFromFileTTF(font_path.c_str(), 24.0f);if (!bigFont) {std::cerr Failed to load font. std::endl;}// 构建字体图集ImGui::GetIO().Fonts-Build();// 更新SFML中的字体纹理ret ImGui::SFML::UpdateFontTexture();if (!ret)return -2;while(){while(){// 显示当前图像的标签if (!currentFile.empty()) {int currentLabel label_map[currentFile];ImGui::Begin(Label Info, nullptr, ImGuiWindowFlags_AlwaysAutoResize);ImGui::PushFont(bigFont); // 使用更大的字体ImGui::Text(Label: %d, currentLabel);ImGui::PopFont(); // 恢复默认字体ImGui::End();}}}如果不这样设定 会遇到这些报错: Assertion failed: (g.IO.Fonts-IsBuilt() Font Atlas not built! Make sure you called ImGui_ImplXXXX_NewFrame() function for renderer backend, which should call io.Fonts-GetTexDataAsRGBA32() / GetTexDataAsAlpha8()), function ErrorCheckNewFrameSanityChecks, file imgui.cpp, line 9579.Assertion failed: (io.Fonts-TexID ! (ImTextureID) nullptr), function RenderDrawLists, file imgui-SFML.cpp, line 876.效果: 2.4 使用完整的列表 读取文件名字的时候原来是硬编码10张图现在改为从 unordered_map 里读取。 注意 由于这个数据量不大 因此没有另外开启线程。 for (int i 1; i 10; i) {std::string fileName std::to_string(i) .png;...}for (const auto kv : label_map){const std::string fileName kv.first;...}最终效果: 总结 通过使用 SFML 加载并显示了了图像(texture-sprite-window)。 通过使用 imgui, 显示了图像文件列表、 label 并且列表被选中元素和图像、 label 是联动的。 在设置 label 字体的时候 需要额外调用 imgui 的构建字体和 imgui-SFML 的刷新, 来避免运行时候的检查报错。 是一个很简陋的图像数据集查看工具可以进一步完善。 源码放在: https://github.com/zchrissirhcz/imgui-sfml-examples/tree/main/mnist-viewer
http://www.pierceye.com/news/196677/

相关文章:

  • 青海做网站找谁wordpress gif缩略图
  • 手机网站全屏显示如何把自己做的网站放到微信上
  • 网站建设云雅淇wordpress
  • 工作室网站需要备案吗python基础教程编程题
  • 建设工程人才招聘信息网站响应式网站 cms
  • 设计签名免费网站福州的网站建设
  • 太原这边有做网站的吗wordpress实现pdf浏览
  • 制作微信公众号的网站开发30岁做网站运营
  • 松江手机网站开发正规免费代理
  • 太原市建设路小学网站昆山住房与城乡建设局网站
  • 石家庄的网站的公司计算机应用技术专业网站开发方向
  • 网站优化软件排行榜八年级微机网站怎么做
  • 织梦网站漏洞cms网站开发流程
  • 网站开发规划书怎么写企业cms开源
  • html网站免费下载海珠区建网站
  • 石家庄住房城乡建设厅网站宿迁网站建设推广公司
  • 广州模板网站建设费用2024新闻热点摘抄
  • 河北秦皇岛建设局网站做网站简单的软件
  • 上海网站开发外包公司最新新闻热点事件短篇
  • wordpress实现网站勋章功能网站建设需要什么资质
  • 河北沙河市建设局网站威海好的网站建设公司
  • 网站建设怎么放到云空间上海企业网站模板
  • 设计和建设企业网站心得和体会wordpress和新浪微博同步
  • 网站底部横条导航代码制造业erp系统软件有哪些
  • 网站建设公司antnw企业营销型网站制作
  • 接口网站开发wordpress安装网站无法
  • 九九9九九9视频在线观看优化网站结构一般包括
  • 网站缺点国外网站素材
  • 网站域名到期如何续费淘宝客绑定网站备案号
  • 什么是自建站常州 网站制作