
Hi !
A couple of days ago, Scott Hanselman posted about a super cool feature (see references):
… you can make a single EXE that will run on any Windows Machine in two commands
How to make a WinForms app with .NET 5 entirely from the command line and publish as one self-contained file
and I was wondering, how this would work with my Winform tests with OpenCV. So, I pick up my Face Recognition using DNN app and decided to give it a try.
When I just build my Face Recognition using DNN app, it creates an output with
- 22 files
- 9 folders
Of course, including the Caffe model and the proto file. And I know, I can remove some unnecessary files, this is just for reference.

Back to Scott’s post, I decided to clean this and run the publish command
dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true
And the output was amazing:
- My application (exe) self-contained file
- My ML Models, prototxt and caffe model
- OpenCVSharp dependency for Windows

This is great ! But wait, there is still an option here to PACK everything, that’s mean add the parameter IncludeAllContentForSelfExtract=True
dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:IncludeAllContentForSelfExtract=True
And, it really packs everything. However, it does not work in my default code. OpenCVSharp load the models from a physical location, and using the IncludeNativeLibrariesForSelfExtract option, the caffe model and prototxt are embedded as resources.
_netPose = CvDnn.ReadNetFromCaffe(PoseProtoTxt, PoseCaffeModel);
_netPose.SetPreferableBackend(Net.Backend.OPENCV);
There should be a trick here, for sure. I’ll spend some time to figure out, how we can load models directly from a single package app file!
Happy coding!
Greetings
El Bruno
More posts in my blog ElBruno.com.
More info in https://beacons.ai/elbruno
References
- OpenCVSharp, https://github.com/s
- Scott Hanselman, How to make a WinForms app with .NET 5 entirely from the command line and publish as one self-contained file
Net 5 and OpenCV
- 13 lines to display a 🎦 camera feed with OpenCV and Net5
- Detecting edges on the 🎦 camera feed with Canny algorithm, OpenCV and Net5
- Detecting corners on the 🎦 camera feed with FAST algorithm, OpenCV and Net 5
- Display the 🎦 camera feed in a WinForm using OpenCV and Net5
- Face Detection using Face Cascades on the 🎦 camera feed using OpenCV and Net 5
- Face Detection using DNN on the 🎦 camera feed using OpenCV and Net 5
- Face Detection, DNN vs Haar Cascades on the 🎦 camera feed using OpenCV and Net 5
- Age and Gender estimation on the 🎦 camera feed using OpenCV and Net 5
- Caffe Model Zoo (GoogleNet) detection from the 🎦 camera feed using OpenCV and Net5
- Pose detection from the 🎦 camera feed using OpenCV and Net5
- Packaging a WinForm OpenCV and Net5 App in a one-self contained file
- Display a video file 🎥 in Winform using OpenCV and Net5
- Open a video file 🎥 and save each frame as a PNG 🖼 file to a folder 📂
- (Coming Soon) QR Codes detection on the 🎦 camera feed using OpenCV and Net 5
1 comment