The objective is to receive an image path and pass that to a Python program as an argument, then receive the results.
This is done through a web app using VB (on the IIS server) and it works perfectly except when I import the python module OpenCV (imported in Python as cv2
, more specifically).
What’s even more confusing is that the script runs perfectly with the imported cv2
module when executed directly from cmd. It only fails to work when the VB code runs the script including the line import cv2
.
I’ll show some code below, for clarity.
VB code running Python script with image path as an argument:
Dim Processtask As New System.Diagnostics.Process() Processtask.StartInfo.FileName = "cmd.exe" Processtask.StartInfo.Arguments = "/c python " + path.ToString + " " + ImageURL.ToString Processtask.StartInfo.UseShellExecute = False Processtask.StartInfo.RedirectStandardOutput = True Processtask.StartInfo.RedirectStandardError = True Processtask.StartInfo.CreateNoWindow = True Processtask.Start() Processtask.WaitForExit() output = Processtask.StandardOutput.ReadToEnd()
Python code snippet receiving image path:
import sys import cv2 if __name__ == "__main__": im = str(sys.argv[1]) print(im)
I have run out of possible ideas as to what could cause this problem. Any advice would be greatly appreciated.
EDIT
I managed to find the full error message which reads as follows:
System.Exception: System.IO.StreamReader System.InvalidOperationException: Process has exited, so the requested information is not available. at System.Diagnostics.Process.EnsureState(State state) at System.Diagnostics.Process.get_ProcessName() at System.Diagnostics.Process.ToString()
Advertisement
Answer
Got the solution eventually, I’ll post it here in case anyone else ever runs into this problem:
The dll files of opencv installed onto the server which hosted the web app had different access rights. The files were denied access when being called from the web application, whereas the rest of the modules called had no issue.
I used sysinternals process monitor to trace which files were being denied access and was able to change the rights by hand. Not very elegant but it worked out.