当前位置: 首页 > 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 请求头…...

OpenClaw学术研究助手:Qwen3-14b_int4_awq自动生成文献综述

OpenClaw学术研究助手&#xff1a;Qwen3-14b_int4_awq自动生成文献综述 1. 为什么需要AI辅助文献调研 作为一名计算机视觉方向的研究生&#xff0c;我每周需要阅读数十篇论文来跟踪领域进展。传统文献调研方式存在几个痛点&#xff1a;首先&#xff0c;手动下载和整理PDF文件…...

CUDA12.4环境适配:OpenClaw调用Qwen3-14B镜像的驱动配置详解

CUDA12.4环境适配&#xff1a;OpenClaw调用Qwen3-14B镜像的驱动配置详解 1. 为什么需要关注CUDA环境适配 上周我在本地部署Qwen3-14B镜像时&#xff0c;遇到了一个典型问题&#xff1a;模型加载到一半突然崩溃&#xff0c;控制台只留下一行模糊的CUDA错误提示。经过两天排查才…...

B0505S-2WR3 适配优选 DB2-05S05LS,DC-DC 电源模块参数与场景深度解析

在工业控制、仪器仪表、通信接口等标准化电路设计中&#xff0c;2W 级 5V 转 5V 隔离 DC-DC 模块是高频应用的核心器件。DB2-05S05LS 和 B0505S-2WR3 作为该功率段的主流型号&#xff0c;在电气规格、物理规格与场景适配性上呈现高度契合&#xff0c;为硬件工程师的标准化选型提…...

光储并网直流微电网仿真模型(matlab/simulink,2018),包含: 1.MPPT模块

光储并网直流微电网仿真模型&#xff08;matlab/simulink&#xff0c;2018&#xff09;&#xff0c;包含&#xff1a; 1.MPPT模块&#xff0c;实现光伏输入最大功率跟踪&#xff1b; 2.储能电池模块&#xff1b; 3.超级电容模块&#xff1b; 控制策略简介&#xff1a; 糸统使用…...

OpenClaw与企业微信/飞书/钉钉深度集成方案

第1章 引言 1.1 OpenClaw简介与定位 OpenClaw是一个现代化的AI Agent运行框架,专为构建企业级智能助手和应用而设计。它采用模块化架构,通过统一的Gateway接口支持多种通信渠道的接入,让AI能力能够无缝融入企业现有的协作生态中。 OpenClaw的核心特性包括: 多渠道统一接…...

华人辍学博士揪出Claude Code 51万行源码泄露,官方请求下架超8000个GitHub代码库并回应:这次是人为失误,无人被解雇!

整理 | 苏宓 出品 | CSDN&#xff08;ID&#xff1a;CSDNnews&#xff09; 这两天 AI 圈的热点话题&#xff0c;莫过于 Claude Code 51 万行核心源码意外泄露事件。而这场风波的起点&#xff0c;并非什么高明的黑客攻击、也没有复杂的攻击路径&#xff0c;而是一位安全研究员的…...

从‘滋滋’声到过认证:一个Buck电源的EMI实战整改笔记(附PCB布局优化技巧)

从‘滋滋’声到过认证&#xff1a;一个Buck电源的EMI实战整改笔记&#xff08;附PCB布局优化技巧&#xff09; 1. 问题浮现&#xff1a;EMI测试中的异常现象 那是一个周五的下午&#xff0c;实验室的EMI测试仪屏幕上跳动的红色曲线格外刺眼。我们团队开发的IoT设备在CE认证测试…...

Windows下IDEA远程开发全离线配置指南(含JetBrainsClient避坑)

Windows下IDEA远程开发全离线配置实战指南 最近在给某金融机构做内部开发环境迁移时&#xff0c;遇到了一个棘手问题&#xff1a;他们的生产网络完全隔离外网&#xff0c;但开发团队又急需使用IDEA的远程开发功能。经过两周的反复试验&#xff0c;终于摸索出一套完整的离线配置…...

用YOLOv8-pose玩点不一样的:手把手教你用Python+OpenCV把姿态关键点画成卡通小人

用YOLOv8-pose玩转创意姿态可视化&#xff1a;从骨架连线到卡通角色设计 当计算机视觉遇上创意表达&#xff0c;枯燥的骨架连线就能变身活灵活现的卡通角色。想象一下&#xff0c;你的健身应用里不再是单调的线条小人&#xff0c;而是穿着背带裤跳舞的虚拟形象&#xff1b;教学…...

企业AI应用开发:从零构建企业级AI智能体的全流程指南

一文讲透智能体开发的核心要素&#xff0c;让AI真正融入业务系统随着大模型技术的成熟&#xff0c;AI智能体正从概念走向企业核心业务。对于信息中心和软件开发团队而言&#xff0c;如何低成本、高效率地将AI能力嵌入业务流程&#xff0c;已成为技术选型的核心考量。本文将系统…...