Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 1f54114

Browse files
committed
init commit
0 parents  commit 1f54114

File tree

8 files changed

+399
-0
lines changed

8 files changed

+399
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Deploy yolov7 wpf demo"
2+
3+
on:
4+
push:
5+
tags:
6+
- "yolov7-wpf/v*"
7+
8+
env:
9+
PROJECT_PATH: ml_yolov7_wpf_demo.csproj
10+
11+
jobs:
12+
deploy:
13+
runs-on: windows-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- uses: actions/setup-dotnet@v3
18+
with:
19+
dotnet-version: 6.0.x
20+
21+
- run: dotnet restore ${{ env.PROJECT_PATH }}
22+
23+
#- run: dotnet build ${{ env.PROJECT_PATH }} -c Release --no-restore --self-contained -r win-x64 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true
24+
25+
- run: dotnet publish ${{ env.PROJECT_PATH }} -c Release
26+
27+
- uses: actions/create-release@v1
28+
id: create_release
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
with:
32+
tag_name: ${{ github.ref }}
33+
release_name: ${{ github.ref }}
34+
35+
- uses: csexton/release-asset-action@v2
36+
with:
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
pattern: bin\Release\net6.0-windows\win-x64\publish\*.exe
39+
release-url: ${{ steps.create_release.outputs.upload_url }}

.gitignore

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
[Dd]ebug/
11+
[Dd]ebugPublic/
12+
[Rr]elease/
13+
[Rr]eleases/
14+
x64/
15+
build/
16+
bld/
17+
[Bb]in/
18+
[Oo]bj/
19+
20+
# Roslyn cache directories
21+
*.ide/
22+
23+
# MSTest test Results
24+
[Tt]est[Rr]esult*/
25+
[Bb]uild[Ll]og.*
26+
27+
#NUNIT
28+
*.VisualState.xml
29+
TestResult.xml
30+
31+
# Build Results of an ATL Project
32+
[Dd]ebugPS/
33+
[Rr]eleasePS/
34+
dlldata.c
35+
36+
*_i.c
37+
*_p.c
38+
*_i.h
39+
*.ilk
40+
*.meta
41+
*.obj
42+
*.pch
43+
*.pdb
44+
*.pgc
45+
*.pgd
46+
*.rsp
47+
*.sbr
48+
*.tlb
49+
*.tli
50+
*.tlh
51+
*.tmp
52+
*.tmp_proj
53+
*.log
54+
*.vspscc
55+
*.vssscc
56+
.builds
57+
*.pidb
58+
*.svclog
59+
*.scc
60+
61+
# Chutzpah Test files
62+
_Chutzpah*
63+
64+
# Visual C++ cache files
65+
ipch/
66+
*.aps
67+
*.ncb
68+
*.opensdf
69+
*.sdf
70+
*.cachefile
71+
72+
# Visual Studio profiler
73+
*.psess
74+
*.vsp
75+
*.vspx
76+
77+
# TFS 2012 Local Workspace
78+
$tf/
79+
80+
# Guidance Automation Toolkit
81+
*.gpState
82+
83+
# ReSharper is a .NET coding add-in
84+
_ReSharper*/
85+
*.[Rr]e[Ss]harper
86+
*.DotSettings.user
87+
88+
# JustCode is a .NET coding addin-in
89+
.JustCode
90+
91+
# TeamCity is a build add-in
92+
_TeamCity*
93+
94+
# DotCover is a Code Coverage Tool
95+
*.dotCover
96+
97+
# NCrunch
98+
_NCrunch_*
99+
.*crunch*.local.xml
100+
101+
# MightyMoose
102+
*.mm.*
103+
AutoTest.Net/
104+
105+
# Web workbench (sass)
106+
.sass-cache/
107+
108+
# Installshield output folder
109+
[Ee]xpress/
110+
111+
# DocProject is a documentation generator add-in
112+
DocProject/buildhelp/
113+
DocProject/Help/*.HxT
114+
DocProject/Help/*.HxC
115+
DocProject/Help/*.hhc
116+
DocProject/Help/*.hhk
117+
DocProject/Help/*.hhp
118+
DocProject/Help/Html2
119+
DocProject/Help/html
120+
121+
# Click-Once directory
122+
publish/
123+
124+
# Publish Web Output
125+
*.[Pp]ublish.xml
126+
*.azurePubxml
127+
## TODO: Comment the next line if you want to checkin your
128+
## web deploy settings but do note that will include unencrypted
129+
## passwords
130+
*.pubxml
131+
132+
# NuGet Packages Directory
133+
packages/*
134+
## TODO: If the tool you use requires repositories.config
135+
## uncomment the next line
136+
#!packages/repositories.config
137+
138+
# Enable "build/" folder in the NuGet Packages folder since
139+
# NuGet packages use it for MSBuild targets.
140+
# This line needs to be after the ignore of the build folder
141+
# (and the packages folder if the line above has been uncommented)
142+
!packages/build/
143+
144+
# Windows Azure Build Output
145+
csx/
146+
*.build.csdef
147+
148+
# Windows Store app package directory
149+
AppPackages/
150+
151+
# Others
152+
sql/
153+
*.Cache
154+
ClientBin/
155+
[Ss]tyle[Cc]op.*
156+
~$*
157+
*~
158+
*.dbmdl
159+
*.dbproj.schemaview
160+
*.pfx
161+
*.publishsettings
162+
node_modules/
163+
164+
# RIA/Silverlight projects
165+
Generated_Code/
166+
167+
# Backup & report files from converting an old project file
168+
# to a newer Visual Studio version. Backup files are not needed,
169+
# because we have git ;-)
170+
_UpgradeReport_Files/
171+
Backup*/
172+
UpgradeLog*.XML
173+
UpgradeLog*.htm
174+
175+
# SQL Server files
176+
*.mdf
177+
*.ldf
178+
179+
# Business Intelligence projects
180+
*.rdl.data
181+
*.bim.layout
182+
*.bim_*.settings
183+
184+
# Microsoft Fakes
185+
FakesAssemblies/
186+
187+
git_stats/*
188+
189+
*.ncrunchproject
190+
StyleCop.Cache
191+
bin
192+
obj

App.xaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="ml_yolov7_wpf_demo.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
StartupUri="MainWindow.xaml">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>

App.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
namespace ml_yolov7_wpf_demo;
4+
5+
/// <summary>
6+
/// Interaction logic for App.xaml
7+
/// </summary>
8+
public partial class App : Application
9+
{
10+
}

AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

MainWindow.xaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Window x:Class="ml_yolov7_wpf_demo.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
mc:Ignorable="d"
7+
WindowStartupLocation="CenterScreen"
8+
Title="yolov7_wpf" Height="450" Width="800">
9+
<Grid>
10+
<Grid.ColumnDefinitions>
11+
<ColumnDefinition Width="30*" />
12+
<ColumnDefinition Width="349*" />
13+
<ColumnDefinition Width="30*" />
14+
</Grid.ColumnDefinitions>
15+
<Image Margin="12,12,16,71" Name="imgPhoto"
16+
Stretch="Uniform" Grid.Column="1" />
17+
<Button Height="23" HorizontalAlignment="Left"
18+
Margin="20,0,0,34" Name="btnLoadModel" VerticalAlignment="Bottom"
19+
Width="75" Grid.Column="1" Click="btnLoadModel_Click">
20+
_Load Model
21+
</Button>
22+
<Button Height="23" HorizontalAlignment="Center"
23+
Margin="20,0,0,34" Name="btnLoad" VerticalAlignment="Bottom"
24+
Width="75" Grid.Column="1" Click="btnLoad_Click">
25+
_Load Image
26+
</Button>
27+
<Button Height="23" HorizontalAlignment="right"
28+
Margin="12,0,20,34" Name="btnProcess" VerticalAlignment="Bottom"
29+
Width="75" Grid.Column="1" Click="btnProcess_Click">
30+
_Process
31+
</Button>
32+
</Grid>
33+
</Window>

MainWindow.xaml.cs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Drawing.Imaging;
5+
using System.IO;
6+
using System.Windows;
7+
using System.Windows.Media.Imaging;
8+
using Microsoft.Win32;
9+
using Yolov5Net.Scorer;
10+
using Yolov5Net.Scorer.Models;
11+
12+
namespace ml_yolov7_wpf_demo;
13+
14+
/// <summary>
15+
/// Interaction logic for MainWindow.xaml
16+
/// </summary>
17+
public partial class MainWindow : Window
18+
{
19+
public string ImageFilePath = "";
20+
public YoloScorer<YoloCocoP5Model> Scorer;
21+
22+
public MainWindow()
23+
{
24+
InitializeComponent();
25+
}
26+
27+
private void btnLoad_Click(object sender, RoutedEventArgs e)
28+
{
29+
var op = new OpenFileDialog();
30+
op.Title = "Select an image";
31+
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
32+
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
33+
"Portable Network Graphic (*.png)|*.png";
34+
if (op.ShowDialog() == true)
35+
{
36+
ImageFilePath = op.FileName;
37+
imgPhoto.Source = new BitmapImage(new Uri(op.FileName));
38+
}
39+
}
40+
41+
private void btnProcess_Click(object sender, RoutedEventArgs e)
42+
{
43+
var image = Image.FromFile(ImageFilePath);
44+
List<YoloPrediction> predictions = Scorer.Predict(image);
45+
46+
using var graphics = Graphics.FromImage(image);
47+
foreach (var prediction in predictions)
48+
{
49+
var score = Math.Round(prediction.Score, 2);
50+
51+
graphics.DrawRectangles(new Pen(prediction.Label.Color, 3),
52+
new[] { prediction.Rectangle });
53+
54+
var (x, y) = (prediction.Rectangle.X - 3, prediction.Rectangle.Y - 23);
55+
56+
graphics.DrawString($"{prediction.Label.Name} ({score})",
57+
new Font("Consolas", 16, GraphicsUnit.Pixel), new SolidBrush(prediction.Label.Color),
58+
new PointF(x, y));
59+
}
60+
61+
var bitmap = new BitmapImage();
62+
63+
using (var stream = new MemoryStream())
64+
{
65+
image.Save(stream, ImageFormat.Jpeg);
66+
67+
stream.Seek(0, SeekOrigin.Begin);
68+
69+
bitmap.BeginInit();
70+
bitmap.StreamSource = stream;
71+
bitmap.CacheOption = BitmapCacheOption.OnLoad;
72+
bitmap.EndInit();
73+
}
74+
75+
imgPhoto.Source = bitmap;
76+
}
77+
78+
private void btnLoadModel_Click(object sender, RoutedEventArgs e)
79+
{
80+
var op = new OpenFileDialog();
81+
op.Title = "Select an ONNX model file";
82+
op.Filter = "Onnx mode file|*.onnx;";
83+
if (op.ShowDialog() == true)
84+
{
85+
var modelFilePath = op.FileName;
86+
Scorer = new YoloScorer<YoloCocoP5Model>(modelFilePath);
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)