Install opencv-contrib

Everything OAD-related that won't fit in the other categories: share general aspects of macro programming and discuss the OAD environment
Post Reply
Matthew Cottrell
Posts: 9
Joined: Sat Jul 24, 2021 4:10 pm

Install opencv-contrib

Post by Matthew Cottrell »

I would like to install opencv-contrib and use those functions in Zen macros.

Normally, I would install it using pip, but that does not seem to be the way it's done with the python installed with Zen blue.

Is it possible to install OpenCV-contrib using anaconda? There appears to be at least some anaconda stuff installed with Zen blue, but I can't figure out how to access it.

There is _anaconda.exe in the env directory under Py20037.2, but that doesn't seem to be the way to go. Or is it?

Anyway, how can I install Python packages that will work with the Python that came with Zen blue?
CarlZeissMicroscopy3
Posts: 79
Joined: Wed May 20, 2020 10:10 am

Re: Install opencv-contrib

Post by CarlZeissMicroscopy3 »

Hello Matthew Cottrell,

first of all I would like to clarify some very foundamental ideas:

'Standard' Python is based on 'unmaged code' (like C/C++ generates). Whereas 'Iron'Python is based on 'managed code' (which is generated by all .Net based languages like C#, VB.Net etc.).

It is not possible to integrate OpenCV ‘directly’ into IronPython, as OpenCV is written in unmanaged code and IronPython uses managed code.
There has to be an interface that manages this gap.

As many people use a .Net based languages OpenCV has written such an interface.

Please have a look at:
https://docs.opencv.org/3.4/db/d30/clas ... _1Net.html
or
https://github.com/shimat/opencvsharp
etc.

Every .Net based dll can be used by IronPython via importing the dll and its namespaces.

A very simple example:

Code: Select all

from System.IO import File, Directory
path = r'C:\Temp'
imageType = '*.CZI'
files = Directory.GetFiles(path,imageType)

This imports the functionality of the Directory class of .Net into an IronPython macro.

In a similar way this approach should work with the .Net libraries for OpenCV!
Matthew Cottrell
Posts: 9
Joined: Sat Jul 24, 2021 4:10 pm

Re: Install opencv-contrib

Post by Matthew Cottrell »

I'm making good progress with the OpenCV libraries for IronPython, but I need a little help with one of the libraries.

The NumpyDotNet.dll and OpenCvSharp.dll appear to load successfully.

But I get an error about OpenCvShaprExtern.dll saying:
The module was expected to contain an assembly manifest.

when the debugger breaks on the line:
"clr.AddReferenceToFileAndPath(r"C:\Users\Cottrell\Library\OpenCvSharpExtern.dll")"

Code: Select all

import clr
import sys

print sys.path

clr.AddReferenceToFileAndPath(r"C:\Users\Cottrell\Library\NumpyDotNet.dll")
import NumpyDotNet as np

clr.AddReferenceToFileAndPath(r"C:\Users\Cottrell\Library\OpenCvSharp.dll")
import OpenCvSharp as cv

clr.AddReferenceToFileAndPath(r"C:\Users\Cottrell\Library\OpenCvSharpExtern.dll")
import OpenCvSharpExtern

img = cv.Cv2.ImRead("/Volumes/GoogleDrive/My Drive/Laboratory/Documents/Projects/Zeiss/Images/Yeast5.tif")
If I don't include the OpenCvSharpExtern.dll I get the error:
The type initializer for OpenCvSharp.Internal.NativeMethods threw an exception
Unable to load the DLL OpenCvSharpExtern: The specified module could not be found.


when the debugger breaks at the line:
"img = cv.Cv2.ImRead("/Volumes/GoogleDrive/My Drive/Laboratory/Documents/Projects/Zeiss/Images/Yeast5.tif")"

I suspect that the error message is not especially informative. References that I've read in places like StackExchange have not been very helpful.

But maybe someone here will have a suggestion.
CarlZeissMicroscopy3
Posts: 79
Joined: Wed May 20, 2020 10:10 am

Re: Install opencv-contrib

Post by CarlZeissMicroscopy3 »

Hello Matthew Cottrell,

just some ideas ...

Maybe OpenCvSharp.dll, included with

Code: Select all

clr.AddReferenceToFileAndPath(r"C:\Users\Cottrell\Library\OpenCvSharp.dll")
import OpenCvSharp as cv
expects OpenCvSharpExtern.dll in a certain directory together with a proper installation of OpenCv.

Therefore including OpenCvSharpExtern.dll might bee too much ...

I just can recommed that you post your question in a forum for OpenCvSharp because to me it seems that you have reached a point that is OpenCvSharp specific and has most probably little to do with 'OAD-Macro-Programming'.
Fredrik Olsson
Posts: 5
Joined: Mon May 25, 2020 9:53 am

Re: Install opencv-contrib

Post by Fredrik Olsson »

Hi,
@Matthew Cottrell: If you happened to found a solution on how o incorporate a functioning OpenCvSharp with the OAD environment it would be nice if you could publish it here.

Kind regards
Fredrik Olsson
Post Reply