Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I integrate a python script into my WPF C# application?

I am currently building an app that displays the video feed of a webcam/external camera. I have written the GUI with C# and in WPF. I have been asked to integrate a python code which does image analysis of the displayed feed. I'm not sure exactly where to begin with this.

I have tried to look into IronPython but the documentation isn't too clear so I'm quite lost. If anyone can point me in the right direction, that would be greatly appreciated.

like image 734
KillSwitch Avatar asked Oct 21 '25 17:10

KillSwitch


2 Answers

There are at least two approaches you can take,

  1. Calling Python Script Using New Process Initialization
  2. Calling the Python Script Using IronPython Interpreter, Hosted in Your .NET Application

Check the below post for more information: https://betterprogramming.pub/running-python-script-from-c-and-working-with-the-results-843e68d230e5

Another option is just to separate your application to microservices, and use python as one.

check this: https://softwareengineering.stackexchange.com/questions/385936/how-can-i-integrate-python-code-with-c-code

like image 181
MikolajR Avatar answered Oct 23 '25 07:10

MikolajR


When it comes to using Python inside .NET applications so Python code can interact with .NET objects, Python.NET and IronPython are two popular choices.

We have implemented our code writing/scripting/debugging solutions for both of these engines, you may read a bit about pros and cons here

like image 24
Dmitry Avatar answered Oct 23 '25 06:10

Dmitry