-
Notifications
You must be signed in to change notification settings - Fork 748
Consuming more time to pass object from .net to python #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@48naveen yes contributions for docs are welcome! |
@48naveen Hi, I am working on converting c# Bitmap to CV2 numpy array image. May I know how you copy from memory pointer? for my scenario is, the c# program will call the python program and pass a Bitmap object to it, in which need to convert it to numpy array cv2 image compatible to further process. Would you mind to share your idea or solution? Thanks in advance. |
@gkomix88 you might want to look at Python Buffer Protocol and this PR (available in |
@lostmsu thanks for the feedback. Following are the codes to pass C# Bitmap to Python function. C# :dynamic np = Py.Import("numpy"); Python (ImgLib.py file):def ProcImage(img, w, h): ================= May I know how to implement Python Buffer Protocol? I tried adding memoryview(img). but the memoryview itself will took 1000ms too. If save the bitmap file from c# and cv2.imread from python only too 100++ms 10 times faster. I want it faster without secondary IO. Any suggestion? I also tried #514 using Numsharp NDArray. But it slower than the above method. |
You need to write something like https://github.com/koubaa/pythonnet/blob/0ed417ca4606f5f235cb938863bab6c96068f686/src/embed_tests/TestPyBuffer.cs#L29 Then pass |
Thanks for the feedback. Would it be the same as follows? def ProcImage(img, w, h): The processing time improved a bit to 1120ms but still quite slow. The image process is 1197w x 797h pixels. |
Hi, I follow your advice to build the pythonnet-master. However, the following error show when imported the built python.runtime.dll to the c# application: System.DllNotFoundException: 'Unable to load DLL 'python3.7': The specified module could not be found. (Exception from HRESULT: 0x8007007E)' I configured the build to x64, PYTHON37, pointing the PYTHONHOME path to python folder etc. The following is the code: string pythonPath = @"C:\Python37"; I tested with pythonnet git (not master) no error. But with pythonnet master the error show up. Can provide help? Thanks in advance. I need to use PyBuffer (only available in master) to speed up the Bitmap passing from C# to python without writing to disk. |
Hi, @lostmsu , I manage to make it run by install the python lib with local pythonnet source directory. Thanks. |
Environment
Details
Here is c# code
Here is python code
So c# code send image array of size 2992993 of float time to python , by which it gets converted into numpy array and makes the prediction on gpu .
if i run the standalone python code , it takes 90msec but if i call from .net 1.5 sec for passing an argument .
Kindly help me to reduce the timing since it is for real time application .
here is a attached screenshots

The text was updated successfully, but these errors were encountered: