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地址: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++】十大排序算法之 归并排序 快速排序
本次介绍内容参考自:十大经典排序算法(C实现) - fengMisaka - 博客园 (cnblogs.com) 排序算法是《数据结构与算法》中最基本的算法之一。 十种常见排序算法可以分为两大类: 比较类排序:通过比较来决定元素间的相对次序…...
x-pack的破解方式和免费jar包!!可直接用!!
原理介绍 我们平时为es安装x-pack组件,用elasticsearch-plugin install x-pack ,安装成功后。 1.cd $es目录/pulgins/x-pack 里面有一个x-pack-5.6.2.jar ,将jar包反编译,然后将里面的licence的程序改下。再编译成jar包。 2…...
最新版本,Midjourney保姆级教程!
一、认识Midjourney 1.1、MidJourney是什么? 随着ChatGPT的横空出世,人类正式迈入AI元年,其中MidJourney便是AI绘图工具,它能根据用户输入的文字描述(提示词)生成绘画作品,不管是灵动的人物&a…...
Android中的几种定位方式调用详解
目前,移动端大致通过三种方式来进行设备定位:GPS、基站、wifi。本文就详细的讲解一下这几种定位方式和实现方法。 前言 android中我们一般使用LocationManager来获取位置信息,这里面有四中provider: public static final Strin…...
【软件测试】接口调不通排查分析+常遇面试题总结
目录:导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结(尾部小惊喜) 前言 1、接口调不通&am…...
c++基础学习第三天(指针,结构体)
c基础学习第三天(指针,结构体) 文章目录 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软件安装及使用(集群配置)【数仓】Hadoop集群配置常用参数说明 一、环境准备 准备3台虚拟机 Hadoop131:192.168.56.131Hadoop132ÿ…...
Qt 实现橡皮擦拭显示图片
1.简介 在一些游戏中看见类似解密破案的效果,使用手触摸去擦拭图片上的灰尘,然后显示最终的图片,所以也想试试Qt实现的效果。大家有自己想做的效果,都可以尝试。 以下是效果展示图。 可以控制橡皮擦的大小,进行擦拭…...
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++设计模式
单例模式 单例模式保证一个类只能创建一个对象,并提供全局访问点。通常用于全局共享例如日志、数据库连接池等。 Lazy Initialization 优点:需要时才初始化,节省空间 缺点:线程不安全 class Singleton{ private:static Singlet…...
反向代购业务系统|无货源代购中国商品|反向海淘代购系统
什么是淘宝代购 淘宝代购是近年兴起的一种购物模式,是帮国外客户购买中国商品。主要是通过万邦科技的外贸代购模式,把淘宝、 天猫等电商平台的全站商品通过API接入到你的网站上,瞬间就可以架设一个有数亿产品的大型网上商城,而且…...
Linux 进程间通信
目录 管道 匿名管道(pipe) 有名管道(fifo) 小结 共享内存 消息队列 信号量 System V IPC的结构设计 Posix与System V的关系 管道 匿名管道(pipe) 我们知道,在Linux中通过fork创建的子…...
hippy 调试demo运行联调-mac环境准备篇
适用对于终端编译环境不熟悉的人看,仅mac端 hippy 调试文档官网地址 前提:请使用node16 联调预览效果图: 编译iOS Demo环境准备 未跑通,待补充 编译Android Demo环境准备 1、正常安装Android Studio 2、下载Android NDK&a…...
【golang】go module依赖的git tag被覆盖 如何处理 | 因测试产生大量的git tag 如何清除 最佳实践
一、场景 当我们把本地和远程git仓库的 tag全部删除,我们另外的项目依赖于这个被删除tag无法更新版本 如何处理? 如上图: 这里我创建了一个 v0.0.1 的tag,然后删除了这个tag,然后又创建了一个新的 v0.0.1的tag…...
Spring Cloud原理详解
Spring Cloud 是基于 Spring Boot 的微服务架构开发工具包,旨在帮助开发人员快速构建分布式系统中的一些常见模式,例如配置管理、服务发现、断路器、智能路由、微代理、控制总线、全局锁、领导选举、分布式会话和集群状态。Spring Cloud 是 Spring 生态系…...
力扣76. 最小覆盖子串(滑动窗口)
Problem: 76. 最小覆盖子串 文章目录 题目描述思路复杂度Code 题目描述 思路 1.定义两个map集合need和window(以字符作为键,对应字符出现的个数作为值),将子串t存入need中; 2.定义左右指针left、right均指向0ÿ…...
使用华为云云函数functiongraph
之前使用腾讯云serverless,但是突然开始收费了。所以改用functiongraph 首先登陆华为云。 目录 1.登录华为云 2.在控制台找到functiongraph并开通 3.添加依赖包: 3.1 制作依赖包 3.2引入依赖包 4.发送请求 4.1直接发送 4.1.1uri 4.1.2 请求头…...
原神帧率解锁工具:如何安全突破60FPS限制获得流畅体验
原神帧率解锁工具:如何安全突破60FPS限制获得流畅体验 【免费下载链接】genshin-fps-unlock unlocks the 60 fps cap 项目地址: https://gitcode.com/gh_mirrors/ge/genshin-fps-unlock 《原神》作为一款画面精美的开放世界游戏,默认的60FPS帧率限…...
从RSSI走向信道探测,蓝牙设备的“距离感知”能力已至“厘米级”
长期以来,物联网(IoT)无线连接技术的发展重心主要聚焦于通信性能、通信功耗与组网效率等方面;然而,随着智能家居、数字车钥匙、工业自动化、智慧门禁、资产管理以及地理围栏等应用的快速扩张,行业正在提出一…...
专业做绝对值编码器的服务商
在工业自动化领域,绝对值编码器是不可或缺的关键组件。它能够直接输出轴或直线运动的“绝对位置”,断电后位置信息不会丢失,每次上电都能立刻知道当前的精确坐标,这使得其在各种精密应用中具有无可替代的优势。本文将通过具体数据…...
意法半导体STM32F407VET6现货
在当今快速发展的电子技术领域,选择一款合适的微控制器对于项目成功至关重要。意法半导体(STMicroelectronics)推出的STM32F407VET6凭借其卓越性能、丰富的外设接口及广泛的应用场景,成为了众多开发者和工程师的首选。本文将深入探…...
内网服务器福音:手把手教你搞定Supervisor 4.0.4离线安装(附CentOS 7.6 + Python 2.7.5环境避坑指南)
内网环境下的Supervisor 4.0.4离线部署全攻略:从依赖解析到避坑实践 在金融、政务等安全敏感领域,生产服务器往往部署在严格隔离的内网环境中。这种架构虽然保障了系统安全性,却给运维工具链的部署带来了独特挑战——无法直接通过pip install…...
揭秘硬件安全:ChipWhisperer如何成为嵌入式设备的安全守护神?
揭秘硬件安全:ChipWhisperer如何成为嵌入式设备的安全守护神? 【免费下载链接】chipwhisperer ChipWhisperer - the complete open-source toolchain for side-channel power analysis and glitching attacks 项目地址: https://gitcode.com/gh_mirror…...
终极指南:3分钟让Switch手柄变身PC游戏神器
终极指南:3分钟让Switch手柄变身PC游戏神器 【免费下载链接】BetterJoy Allows the Nintendo Switch Pro Controller, Joycons and SNES controller to be used with CEMU, Citra, Dolphin, Yuzu and as generic XInput 项目地址: https://gitcode.com/gh_mirrors…...
Unity节点化效率工具:ComfyUI范式赋能中大型项目开发
1. 这不是又一个“UI美化插件”,而是Unity开发者每天要敲十次的底层效率杠杆Efficiency Nodes ComfyUI——光看名字,很多人第一反应是“ComfyUI?那不是Stable Diffusion的可视化工作流工具吗?怎么跑Unity里来了?”这恰…...
选对服务商事半功倍!2026 全国头部综合型设计搭建会展服务商核心优势解读
本文详解 2026 年全国各大会展中心全国头部综合型设计搭建会展服务商的核心优势与价值,核心定义为全国头部综合型设计搭建会展服务商是指具备全产业链整合能力、全国化服务网络、丰富的行业经验与强大的技术实力,能够为客户提供一站式、全流程会展设计搭…...
知识竞赛裁判怎么当?评分标准与争议处理
知识竞赛裁判怎么当?评分标准与争议处理公平 专业 高效 守护竞赛的生命线🎯 一、裁判的角色与职责知识竞赛裁判是竞赛公平的守护者,不仅要掌握规则,还要具备快速判断和沟通能力。核心职责:📋 赛前熟悉题…...
