Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using OpenCV in Python via a C# application


I'm looking to build a demo for a program that I've written using the Python bindings for OpenCV. I'm writing the demo in C#, and am wondering if anyone has any tips and tricks for when it comes to running a Python script from C#? Currently am defining a process like

            ProcessStartInfo myProcessStartInfo = new ProcessStartInfo();
            myProcessStartInfo.FileName = "C:\...path to my python.exe";
            myProcessStartInfo.Arguments = relevantArguments;
            myProcessStartInfo.UseShellExecute = false;
            myProcessStartInfo.UseShellExecute = false;
            myProcessStartInfo.CreateNoWindow = true;
            myProcessStartInfo.RedirectStandardOutput = true;
            myProcessStartInfo.RedirectStandardError = true;

and then I run a process like

            using (Process process = Process.Start(start))
                using (StreamReader reader = process.StandardOutput)
                    string stderr = process.StandardError.ReadToEnd(); 
                    string result = reader.ReadToEnd();

Problems arise when I start doing feature detection in my script, in particular I run .detectAndCompute on an image, and the application just breaks. I'm rather new to C#, so any ideas or hints are helpful.

Thanks, Nik