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

C# Onnx segment-anything 分割万物 一键抠图

目录

介绍

效果

模型信息

sam_vit_b_decoder.onnx

sam_vit_b_encoder.onnx

项目

代码

下载


C# Onnx segment-anything 分割万物 一键抠图

介绍

github地址:GitHub - facebookresearch/segment-anything: The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.

The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model. 

效果

C# Onnx segment-anything 分割万物

模型信息

sam_vit_b_decoder.onnx

Model Properties
-------------------------
---------------------------------------------------------------

Inputs
-------------------------
name:image_embeddings
tensor:Float[1, 256, 64, 64]
name:point_coords
tensor:Float[1, -1, 2]
name:point_labels
tensor:Float[1, -1]
name:mask_input
tensor:Float[1, 1, 256, 256]
name:has_mask_input
tensor:Float[1]
name:orig_im_size
tensor:Float[2]
---------------------------------------------------------------

Outputs
-------------------------
name:masks
tensor:Float[-1, -1, -1, -1]
name:iou_predictions
tensor:Float[-1, 4]
name:low_res_masks
tensor:Float[-1, -1, -1, -1]
---------------------------------------------------------------

sam_vit_b_encoder.onnx

Model Properties
-------------------------
---------------------------------------------------------------

Inputs
-------------------------
name:image
tensor:Float[1, 3, 1024, 1024]
---------------------------------------------------------------

Outputs
-------------------------
name:image_embeddings
tensor:Float[1, 256, 64, 64]
---------------------------------------------------------------

项目

代码

using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using System.Windows.Forms;namespace Onnx_Demo
{public partial class Form1 : Form{public Form1(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";DateTime dt1 = DateTime.Now;DateTime dt2 = DateTime.Now;Mat image;private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);textBox1.Text = "";image = new Mat(image_path);pictureBox2.Image = null;pictureBox3.Image = null;sam.SetImage(image_path);image = new Mat(image_path);pictureBox1.Image = new Bitmap(image_path);}private void button2_Click(object sender, EventArgs e){pictureBox3.Image = null;button2.Enabled = false;Application.DoEvents();List<MatInfo> masks_list = sam.GetPointMask(roi);if (masks_list.Count>0){int MaxInde = 0;float maxiou_pred = masks_list[0].iou_pred;for (int i = 0; i < masks_list.Count; i++){float temp = masks_list[i].iou_pred;if (temp > maxiou_pred){MaxInde = i;}}pictureBox3.Image = BitmapConverter.ToBitmap(masks_list[MaxInde].mask);}button2.Enabled = true;}SamInferenceSession sam;private void Form1_Load(object sender, EventArgs e){string encoderPath = "model/sam_vit_b_encoder.onnx";string decoderPath = "model/sam_vit_b_decoder.onnx";sam = new SamInferenceSession(encoderPath, decoderPath);sam.Initialize();image_path = "test_img/test.jpg";sam.SetImage(image_path);image = new Mat(image_path);pictureBox1.Image = new Bitmap(image_path);}private void pictureBox1_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox1.Image);}private void pictureBox2_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox2.Image);}SaveFileDialog sdf = new SaveFileDialog();private void button3_Click(object sender, EventArgs e){if (pictureBox2.Image == null){return;}Bitmap output = new Bitmap(pictureBox2.Image);sdf.Title = "保存";sdf.Filter = "Images (*.jpg)|*.jpg|Images (*.png)|*.png|Images (*.bmp)|*.bmp|Images (*.emf)|*.emf|Images (*.exif)|*.exif|Images (*.gif)|*.gif|Images (*.ico)|*.ico|Images (*.tiff)|*.tiff|Images (*.wmf)|*.wmf";if (sdf.ShowDialog() == DialogResult.OK){switch (sdf.FilterIndex){case 1:{output.Save(sdf.FileName, ImageFormat.Jpeg);break;}case 2:{output.Save(sdf.FileName, ImageFormat.Png);break;}case 3:{output.Save(sdf.FileName, ImageFormat.Bmp);break;}case 4:{output.Save(sdf.FileName, ImageFormat.Emf);break;}case 5:{output.Save(sdf.FileName, ImageFormat.Exif);break;}case 6:{output.Save(sdf.FileName, ImageFormat.Gif);break;}case 7:{output.Save(sdf.FileName, ImageFormat.Icon);break;}case 8:{output.Save(sdf.FileName, ImageFormat.Tiff);break;}case 9:{output.Save(sdf.FileName, ImageFormat.Wmf);break;}}MessageBox.Show("保存成功,位置:" + sdf.FileName);}}bool m_mouseDown = false;bool m_mouseMove = false;System.Drawing.Point startPoint = new System.Drawing.Point();System.Drawing.Point endPoint = new System.Drawing.Point();Mat currentFrame = new Mat();Rect roi = new Rect();private void pictureBox1_MouseMove(object sender, MouseEventArgs e){if (pictureBox1.Image == null)return;if (!m_mouseDown) return;m_mouseMove = true;endPoint = e.Location;pictureBox1.Invalidate();}private void pictureBox1_Paint(object sender, PaintEventArgs e){if (!m_mouseDown || !m_mouseMove)return;Graphics g = e.Graphics;Pen p = new Pen(Color.Blue, 2);Rectangle rect = new Rectangle(startPoint.X, startPoint.Y, (endPoint.X - startPoint.X), (endPoint.Y - startPoint.Y));g.DrawRectangle(p, rect);}private void pictureBox1_MouseUp(object sender, MouseEventArgs e){if (!m_mouseDown || !m_mouseMove)return;m_mouseDown = false;m_mouseMove = false;System.Drawing.Point image_startPoint = ConvertCooridinate(startPoint);System.Drawing.Point image_endPoint = ConvertCooridinate(endPoint);if (image_startPoint.X < 0)image_startPoint.X = 0;if (image_startPoint.Y < 0)image_startPoint.Y = 0;if (image_endPoint.X < 0)image_endPoint.X = 0;if (image_endPoint.Y < 0)image_endPoint.Y = 0;if (image_startPoint.X > image.Cols)image_startPoint.X = image.Cols;if (image_startPoint.Y > image.Rows)image_startPoint.Y = image.Rows;if (image_endPoint.X > image.Cols)image_endPoint.X = image.Cols;if (image_endPoint.Y > image.Rows)image_endPoint.Y = image.Rows;label1.Text = String.Format("ROI:({0},{1})-({2},{3})", image_startPoint.X, image_startPoint.Y, image_endPoint.X, image_endPoint.Y);int w = (image_endPoint.X - image_startPoint.X);int h = (image_endPoint.Y - image_startPoint.Y);if (w > 10 && h > 10){roi = new Rect(image_startPoint.X, image_startPoint.Y, w, h);//Console.WriteLine(String.Format("ROI:({0},{1})-({2},{3})", image_startPoint.X, image_startPoint.Y, image_endPoint.X, image_endPoint.Y));//test//OpenCvSharp.Point pointinfo = new OpenCvSharp.Point(910, 641);//roi = new Rect(pointinfo.X - 160, pointinfo.Y - 430, 380, 940);Mat roi_mat = image[roi];pictureBox2.Image = BitmapConverter.ToBitmap(roi_mat);}//pictureBox1.Invalidate();}private void pictureBox1_MouseDown(object sender, MouseEventArgs e){if (pictureBox1.Image == null)return;m_mouseDown = true;startPoint = e.Location;}private System.Drawing.Point ConvertCooridinate(System.Drawing.Point point){System.Reflection.PropertyInfo rectangleProperty = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);Rectangle pictureBox = (Rectangle)rectangleProperty.GetValue(this.pictureBox1, null);int zoomedWidth = pictureBox.Width;int zoomedHeight = pictureBox.Height;int imageWidth = pictureBox1.Image.Width;int imageHeight = pictureBox1.Image.Height;double zoomRatex = (double)(zoomedWidth) / (double)(imageWidth);double zoomRatey = (double)(zoomedHeight) / (double)(imageHeight);int black_left_width = (zoomedWidth == this.pictureBox1.Width) ? 0 : (this.pictureBox1.Width - zoomedWidth) / 2;int black_top_height = (zoomedHeight == this.pictureBox1.Height) ? 0 : (this.pictureBox1.Height - zoomedHeight) / 2;int zoomedX = point.X - black_left_width;int zoomedY = point.Y - black_top_height;System.Drawing.Point outPoint = new System.Drawing.Point();outPoint.X = (int)((double)zoomedX / zoomRatex);outPoint.Y = (int)((double)zoomedY / zoomRatey);return outPoint;}}
}

下载

源码下载

相关文章:

C# Onnx segment-anything 分割万物 一键抠图

目录 介绍 效果 模型信息 sam_vit_b_decoder.onnx sam_vit_b_encoder.onnx 项目 代码 下载 C# Onnx segment-anything 分割万物 一键抠图 介绍 github地址&#xff1a;GitHub - facebookresearch/segment-anything: The repository provides code for running infere…...

Linux配置网卡功能

提示:工具下载链接在文章最后 目录 一.network功能介绍二.配置network功能2.1 network_ip配置检查 2.2 network_br配置2.2.1 配置的网桥原先不存在检查2.2.2 配置的网桥已存在-修改网桥IP检查2.2.3 配置的网桥已存在-只添加网卡到网桥里检查 2.3 network_bond配置检查 2.4 netw…...

【C++】十大排序算法之 归并排序 快速排序

本次介绍内容参考自&#xff1a;十大经典排序算法&#xff08;C实现&#xff09; - fengMisaka - 博客园 (cnblogs.com) 排序算法是《数据结构与算法》中最基本的算法之一。 十种常见排序算法可以分为两大类&#xff1a; 比较类排序&#xff1a;通过比较来决定元素间的相对次序…...

x-pack的破解方式和免费jar包!!可直接用!!

原理介绍 我们平时为es安装x-pack组件&#xff0c;用elasticsearch-plugin install x-pack &#xff0c;安装成功后。 1.cd $es目录/pulgins/x-pack 里面有一个x-pack-5.6.2.jar &#xff0c;将jar包反编译&#xff0c;然后将里面的licence的程序改下。再编译成jar包。 2…...

最新版本,Midjourney保姆级教程!

一、认识Midjourney 1.1、MidJourney是什么&#xff1f; 随着ChatGPT的横空出世&#xff0c;人类正式迈入AI元年&#xff0c;其中MidJourney便是AI绘图工具&#xff0c;它能根据用户输入的文字描述&#xff08;提示词&#xff09;生成绘画作品&#xff0c;不管是灵动的人物&a…...

Android中的几种定位方式调用详解

目前&#xff0c;移动端大致通过三种方式来进行设备定位&#xff1a;GPS、基站、wifi。本文就详细的讲解一下这几种定位方式和实现方法。 前言 android中我们一般使用LocationManager来获取位置信息&#xff0c;这里面有四中provider&#xff1a; public static final Strin…...

【软件测试】接口调不通排查分析+常遇面试题总结

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 1、接口调不通&am…...

c++基础学习第三天(指针,结构体)

c基础学习第三天&#xff08;指针&#xff0c;结构体&#xff09; 文章目录 1、指针1.1、指针的基本概念1.2、指针变量的定义和使用1.3、 指针所占内存空间1.4、空指针和野指针1.5、 const修饰指针1.5.1、const修饰指针-常量指针1.5.2、const修饰常量-指针常量1.5.3、const即修…...

【数仓】zookeeper软件安装及集群配置

相关文章 【数仓】基本概念、知识普及、核心技术【数仓】数据分层概念以及相关逻辑【数仓】Hadoop软件安装及使用&#xff08;集群配置&#xff09;【数仓】Hadoop集群配置常用参数说明 一、环境准备 准备3台虚拟机 Hadoop131&#xff1a;192.168.56.131Hadoop132&#xff…...

Qt 实现橡皮擦拭显示图片

1.简介 在一些游戏中看见类似解密破案的效果&#xff0c;使用手触摸去擦拭图片上的灰尘&#xff0c;然后显示最终的图片&#xff0c;所以也想试试Qt实现的效果。大家有自己想做的效果&#xff0c;都可以尝试。 以下是效果展示图。 可以控制橡皮擦的大小&#xff0c;进行擦拭…...

Vue3+Element-Plus中ELMessage样式丢失处理

Vu3Element-Plus项目中,element-plus使用按需引入有时会出现样式失效和在vscode中使用会报错[找不到名称“ElMessage”。ts(2304)]错误 ELMessage弹框样式丢失处理方法 使用按需引入就不能手动再引入 import { ElMessage } from "element-plus";ElMessage.success…...

97 spring 中的泛型类型注入

前言 呵呵 同样是 最近同事碰到的一个问题 他不太懂 英语, 看到的说明是 缺少一个 RedisTemplate 的实例, 但是找到了一个 RedisTemplate 的实例 呵呵 和我这里 spring 版本似乎是不太一样, 错误信息 有一些差异 以下环境基于 jdk8 spring-5.0.4-RELEASE 测试用例 BeanCon…...

C++设计模式

单例模式 单例模式保证一个类只能创建一个对象&#xff0c;并提供全局访问点。通常用于全局共享例如日志、数据库连接池等。 Lazy Initialization 优点&#xff1a;需要时才初始化&#xff0c;节省空间 缺点&#xff1a;线程不安全 class Singleton{ private:static Singlet…...

反向代购业务系统|无货源代购中国商品|反向海淘代购系统

什么是淘宝代购 淘宝代购是近年兴起的一种购物模式&#xff0c;是帮国外客户购买中国商品。主要是通过万邦科技的外贸代购模式&#xff0c;把淘宝、 天猫等电商平台的全站商品通过API接入到你的网站上&#xff0c;瞬间就可以架设一个有数亿产品的大型网上商城&#xff0c;而且…...

Linux 进程间通信

目录 管道 匿名管道&#xff08;pipe&#xff09; 有名管道&#xff08;fifo&#xff09; 小结 共享内存 消息队列 信号量 System V IPC的结构设计 Posix与System V的关系 管道 匿名管道&#xff08;pipe&#xff09; 我们知道&#xff0c;在Linux中通过fork创建的子…...

hippy 调试demo运行联调-mac环境准备篇

适用对于终端编译环境不熟悉的人看&#xff0c;仅mac端 hippy 调试文档官网地址 前提&#xff1a;请使用node16 联调预览效果图&#xff1a; 编译iOS Demo环境准备 未跑通&#xff0c;待补充 编译Android Demo环境准备 1、正常安装Android Studio 2、下载Android NDK&a…...

【golang】go module依赖的git tag被覆盖 如何处理 | 因测试产生大量的git tag 如何清除 最佳实践

一、场景 当我们把本地和远程git仓库的 tag全部删除&#xff0c;我们另外的项目依赖于这个被删除tag无法更新版本 如何处理&#xff1f; 如上图&#xff1a; 这里我创建了一个 v0.0.1 的tag&#xff0c;然后删除了这个tag&#xff0c;然后又创建了一个新的 v0.0.1的tag&#xf…...

Spring Cloud原理详解

Spring Cloud 是基于 Spring Boot 的微服务架构开发工具包&#xff0c;旨在帮助开发人员快速构建分布式系统中的一些常见模式&#xff0c;例如配置管理、服务发现、断路器、智能路由、微代理、控制总线、全局锁、领导选举、分布式会话和集群状态。Spring Cloud 是 Spring 生态系…...

力扣76. 最小覆盖子串(滑动窗口)

Problem: 76. 最小覆盖子串 文章目录 题目描述思路复杂度Code 题目描述 思路 1.定义两个map集合need和window&#xff08;以字符作为键&#xff0c;对应字符出现的个数作为值&#xff09;&#xff0c;将子串t存入need中&#xff1b; 2.定义左右指针left、right均指向0&#xff…...

使用华为云云函数functiongraph

之前使用腾讯云serverless&#xff0c;但是突然开始收费了。所以改用functiongraph 首先登陆华为云。 目录 1.登录华为云 2.在控制台找到functiongraph并开通 3.添加依赖包&#xff1a; 3.1 制作依赖包 3.2引入依赖包 4.发送请求 4.1直接发送 4.1.1uri 4.1.2 请求头…...

AIGlasses OS Pro保姆级教程:从环境配置到四大模式实战体验

AIGlasses OS Pro保姆级教程&#xff1a;从环境配置到四大模式实战体验 1. 系统概述与核心价值 AIGlasses OS Pro是一款专为智能眼镜设计的本地化视觉辅助系统&#xff0c;它巧妙融合了YOLO11目标检测与MediaPipe骨骼识别两大引擎。与市面上依赖云服务的方案不同&#xff0c;…...

适配器模式设计思路

01.适配器模式基础适配器模式是一种结构型设计模式&#xff0c;用于将不兼容的接口转换为可兼容的接口&#xff0c;使原本不能一起工作的类可以协同工作。本文详细介绍了适配器模式的基础、实现方式&#xff08;类适配器和对象适配器&#xff09;、应用场景&#xff08;如封装有…...

Janus-Pro-7B播客制作:音频波形图识别+内容摘要与章节标记生成

Janus-Pro-7B播客制作&#xff1a;音频波形图识别内容摘要与章节标记生成 1. 引言&#xff1a;播客制作的新思路 播客制作通常需要大量的人工工作&#xff1a;听完整期节目、标记关键章节、撰写内容摘要、制作时间轴标记。这个过程耗时耗力&#xff0c;特别是对于长篇播客内容…...

Qwen2.5-72B大模型实战指南:GPTQ-Int4量化+128K上下文+Chainlit可视化交互全流程

Qwen2.5-72B大模型实战指南&#xff1a;GPTQ-Int4量化128K上下文Chainlit可视化交互全流程 1. 模型简介 Qwen2.5-72B-Instruct-GPTQ-Int4是Qwen大型语言模型系列的最新版本&#xff0c;代表了当前开源大模型领域的顶尖水平。这个72.7B参数的模型经过GPTQ 4-bit量化处理&#…...

【回眸】系统读书笔记(十)盘点调动资源

目录 前言 资源盘点可以帮你创造选择 三类人生资源 直接价值资源 知识技能类&#xff1a;认知储备和实操能力、学科知识、行业认知、上手操作的技能 记录行为和结果&#xff1a;干成过什么、搞定过什么、负责过什么&#xff1f; 能力逆向推导&#xff1a;把行为翻译成资源…...

pinyinjs自定义字典扩展指南:打造专属拼音转换系统

pinyinjs自定义字典扩展指南&#xff1a;打造专属拼音转换系统 【免费下载链接】pinyinjs 一个实现汉字与拼音互转的小巧web工具库&#xff0c;演示地址&#xff1a; 项目地址: https://gitcode.com/gh_mirrors/pi/pinyinjs pinyinjs是一个实现汉字与拼音互转的小巧web工…...

Changelog.com贡献指南:如何参与这个活跃的开源项目

Changelog.com贡献指南&#xff1a;如何参与这个活跃的开源项目 【免费下载链接】changelog.com Changelog is news and podcast for developers. This is our open source platform. 项目地址: https://gitcode.com/gh_mirrors/ch/changelog.com Changelog.com是一个使…...

市场知名的光伏项目品牌找哪家

这两年不少做企业的、建农村自建房的业主都盯上了光伏项目——发了电自己用&#xff0c;余电还能卖&#xff0c;长期收益稳定&#xff0c;不少人靠着光伏每年多赚几万甚至几十万。但我接触过至少几十个踩坑的业主&#xff1a;要么找了小品牌装完就跑路&#xff0c;发电量比承诺…...

OpenClaw安全实践:Qwen3.5-9B本地化部署防数据泄露方案

OpenClaw安全实践&#xff1a;Qwen3.5-9B本地化部署防数据泄露方案 1. 为什么需要关注OpenClaw的安全问题&#xff1f; 去年冬天&#xff0c;我在整理公司财报时突然意识到一个问题&#xff1a;如果让AI助手帮我处理这些敏感文件&#xff0c;数据会不会被意外上传到云端&…...

Echarts异步数据加载场景下,如何设计优雅的Loading动画以优化用户感知

1. 为什么需要优雅的Loading动画 当我们在网页中使用Echarts展示数据图表时&#xff0c;经常会遇到数据需要从服务器异步加载的情况。想象一下这样的场景&#xff1a;用户打开页面后&#xff0c;看到一个空白的坐标轴在那里"发呆"&#xff0c;既没有数据也没有任何提…...