惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
C
Check Point Blog
B
Blog RSS Feed
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
About on SuperTechFans
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
小众软件
小众软件
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
GbyAI
GbyAI
The Cloudflare Blog
博客园 - 叶小钗
S
SegmentFault 最新的问题
博客园 - Franky
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
B
Blog
Jina AI
Jina AI

博客园 - 饭

This MySqlConnection is already in use. See https://fl.vu/mysql-conn-reuse EPPlus操作透视表过滤数据 JS/html5 文字转语音 关于IIS部署.NET7的记录 nginx伪静态过滤静态文件 阿里云Nginx伪静态 记录一些壁纸/图片网站 js四舍五入. javascript四舍五入 真正四舍五入 不是四舍六入五成双 比较两个相同类型的实例是否相同, 支持忽略指定字段. entity framework 实现按照距离排序[转] 正padding负margin实现多列等高布局(转) 在iframe内页触发顶层页面body的blur事件 bootstrap 模态窗口 多重/多个弹窗滚动条补丁 2019年6月车型数据Access数据库+缩略图 更新于2019年6月5日. sql server 2012 分页/dapper/C#拼sql/免储存过程/简易 正则: 匹配除了某些单词之外的其他单词 按顺序动态加载js, 可控版本, 有回调 asp.net mvc json数据缓存 知识点关键词(记录一下) TimeSpan格式化字符串格式(摘)
WinForm使用Python.Net调用Yolov8将图像显示在pictureBox控件上.
· 2025-06-19 · via 博客园 - 饭

前面就是Yolov8常见的目标识别代码, 由于跟业务有关太多就不贴出来了. 主要就是下面这部分,

cv2.VideoCapture(video_path);

dynamic result = cap.read();
bool success = (bool)result[0];
dynamic frame = result[1];

// 对当前帧进行目标检测
dynamic results = model.track(frame, persist: true);


// 可视化检测结果,调整边框宽度和文字大小
dynamic annotated_frame = results[0].plot(line_width: 1, font_size: 0.5, conf: false, labels: false);

int

width = annotated_frame.shape[1]; int height = annotated_frame.shape[0]; // 获取数组内存信息 这种做法只需要0-1ms处理一帧 dynamic arrayInterface = annotated_frame.__array_interface__;//numpy自带属性 dynamic data_info = arrayInterface["data"]; long address = (long)data_info[0]; // 将 Python int 转换为 long IntPtr ptr = new IntPtr(address); int stride = width * 3; // 24bpp RGB format byte[] imageData = new byte[height * stride]; System.Runtime.InteropServices.Marshal.Copy(ptr, imageData, 0, imageData.Length); var bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); var bitmapData = bitmap.LockBits( new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb ); System.Runtime.InteropServices.Marshal.Copy(imageData, 0, bitmapData.Scan0, imageData.Length); bitmap.UnlockBits(bitmapData); st.Stop(); var trasfer = st.ElapsedMilliseconds + "ms"; st.Restart(); UpdateUIOnNewThread(bitmap); st.Stop(); var update = st.ElapsedMilliseconds + "ms"; /* 0: 640x384 106 cans, 47.3ms Speed: 1.6ms preprocess, 47.3ms inference, 1.4ms postprocess per image at shape (1, 3, 640, 384) 1ms 0ms */
        // 在非UI线程中调用此方法更新UI
        private void UpdateUIOnNewThread(Bitmap bitmap)
        {
            if (this.InvokeRequired)
            {
                // 如果当前线程不是UI线程,使用Invoke将操作封送到UI线程
                this.Invoke(new Action(() =>
                {
                    // 这里可以安全地操作UI控件
                    pictureBox1.Image = bitmap;
                }));
            }
            else
            {
                // 如果已经在UI线程中,直接执行
                pictureBox1.Image = bitmap;
            }
        }