Importing cv2 through VB for web app

asked 2018-05-16 04:45:27 -0500

Attropos gravatar image

updated 2018-05-16 05:14:32 -0500

I have a functional python script that performs facial recognition using dlib and opencv.

My problem: as soon as I run the python script through VB as a web app, I receive an error "System.Exception: 1".

I have isolated the problem; the error only occurs when I include the line "import cv2" in the python script being executed.

Once again, this only happens when I run the python script through VB. When I run the python script through Spyder or command prompt it runs perfectly. I have successfully installed OpenCV in the the environment that VB is using, and I have reinstalled the module in an attempt to solve the issue, but to no avail.

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 ideas as to what could cause this problem. Any advice on this would be greatly appreciated.

edit retag flag offensive close merge delete

Comments

though VB is entirely off-topic here, please add your code to the question.

and one of the problems might be: while your python ide properly sets environment vars, before running it, your VB script might inherit some other env, thus not finding the path to the site-libs and such.

berak gravatar imageberak ( 2018-05-16 04:55:12 -0500 )edit

Thanks for the response. It is strange that my .py script run through VB is able to import all the other modules used in the program (quite a long list of them). Only cv2 produces an error.

Attropos gravatar imageAttropos ( 2018-05-16 05:17:27 -0500 )edit

do you have more than 1 python on your box ?

there must also be a way to reach the printed error msg

berak gravatar imageberak ( 2018-05-16 06:58:31 -0500 )edit