Developing and Fiddling with the G'MIC Python Binding

The problem here is with opencv4: By default there is no pkg-config file.

I’ve built a local version that provides opencv4.pc, and copies it into the default pkgconfig directory.

However, something is still going wrong, as I have to manually add the include and library paths in setup.py. Further it generates '/opt/local/libexec/opencv4//opt/local/include/opencv4' as a include dir.

1 Like

I now get

Thor:ports marius$ otool -L /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gmic.cpython-37m-darwin.so
/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gmic.cpython-37m-darwin.so:
	/opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
	/opt/local/lib/libX11.6.dylib (compatibility version 11.0.0, current version 11.0.0)
	/opt/local/lib/libpng16.16.dylib (compatibility version 54.0.0, current version 54.0.0)
	/opt/local/lib/libtiff.5.dylib (compatibility version 12.0.0, current version 12.0.0)
	/opt/local/lib/libjpeg.8.dylib (compatibility version 8.0.0, current version 8.2.2)
	/opt/local/lib/libfftw3.3.dylib (compatibility version 9.0.0, current version 9.8.0)
	/opt/local/lib/opencv4/libopencv_gapi.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_highgui.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_ml.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_objdetect.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_photo.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_stitching.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_video.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_calib3d.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_features2d.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_flann.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_videoio.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_imgcodecs.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_imgproc.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/opt/local/lib/opencv4/libopencv_core.4.5.dylib (compatibility version 4.5.0, current version 4.5.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)
	/opt/local/lib/libfftw3_threads.3.dylib (compatibility version 9.0.0, current version 9.8.0)
	/opt/local/lib/libomp/libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)

The matter with openmp is up next.

Ah. opencv4 creates the double paths. I’ll have to fix that there.

@Schamschula Marius, that’s what I did too. Here is my pc trial of opencv4. Its derived from opencv.pc

Package Information for pkg-config

prefix=/opt/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib/opencv4
includedir=${prefix}/include/opencv4

Name: OpenCV4
Description: Open Source Computer Vision Library
Version: 4.5.0
Libs: -L${exec_prefix}/lib/opencv4 -lopencv_calib3d.4.5 -lopencv_core.4.5 -lopencv_features2d.4.5 -lopencv_flann.4.5 -lopencv_gapi.4.5 -lopencv_highgui.4.5 -lopencv_imgcodecs.4.5 -lopencv_imgproc.4.5 -lopencv_ml.4.5 -lopencv_objdetect.4.5 -lopencv_photo.4.5 -lopencv_stitching.4.5 -lopencv_video.4.5 -lopencv_videoio.4.5
Libs.private:
Cflags: -I${includedir}

I’ve done a bit of reimplacing in opencv4.pc to fix this. I’ll put up a MacPorts PR to fix this latter today.

I’ve opened a MacPorts Pull Request: opencv4: generate pkg-config file by Schamschula · Pull Request #9972 · macports/macports-ports · GitHub

1 Like

Just wanted to say, I am glad things are getting up-to-speed for G’MIC-py! Looking forward to implementing it into my project(s)…:smiley:

2 Likes

Thank you for your encouragements!

Marius thank you very much for joining in this topic just to fix gmic-py for MacOS!! My not being a MacOS user, this place is better than my doing some mediation. You are awesome!!

Just tested py-gmic @2.9.4-alpha1_2
My test file:

import gmic
# gmic.run("+v up")
gmic.run(‘https://placekitten.com/g/200/300 d 200,200,1,3 fill_color. 200,230,0 d’)
gmic.run(“sp lena eval. “end(run('echo_stdout[] ',merge(t,max)))””)
gmic.run(‘sp apples display’)
gmic.run(“dc”)

Very good work Marius, Jonathan, display, threads etc. Only the version is a little bit in behind.

By the way, there is actually no need anymore for opencv (3). Only the actual MacPorts gmic cli asks still for opencv. I have locally build zart (tv processor), gimp, gmic-qt. With py-gmic from Macports all elements needing possibly opencv seemingly build and work with opencv4!

1 Like

Nice!
Monday evening (France time) I can create a 2.9.6 alpha tag for Marius to pick it up.
In the days after I hope to fix the gmic-py 2.9.6 tests suite to get out of alpha.

After dealing with opencv and opencv4 being installed in parallel, gmic, gmic-clib, and gmic-gt are now being built against opencv4 under MacPorts!
https://github.com/macports/macports-ports/commit/7dc764e1aa65504b335596b4b4dffa027b9ec817
I had to invoke conflicts_build for the user to deactivate opencv prior to building any of those packages.

1 Like

Hi @Schamschula Marius, I have just updated gmic 2.9.6.
Is it by purpose build without openMP?

If OpenCV is not linked (the G’MIC library leverages it for camera & video file/stream parsing/saving), gmic-py users can also use GmicImage.to_numpy() and from there use some PyOpenCV like library to work in OpenCV, but they would have to program what G’MIC’s OpenCV support would do natively.
gmic-py OpenCV support is a nice to have…

@myselfhimself @Schamschula Hi Jonathon, Marius

just updated to Big Sur and migrated MacPorts.
py-gmic works well even build with openMP
gmic is build without openMP, unluckily, openCV works well
gmic-gimp works well too. Surprisingly it is linked against libgmic library with openCV. Don#t know if gimp can handle the camera.

Many thanks Marius (and Jonathan for the py-gmic). Perhaps for gmic a variant with openMP would be good.

2 Likes

Thanks for this feedback.
‘gmic’ do you mean the gmic CLI executable?

Yes! Similar to MacPorts gmic is the port for gmic cli.

1 Like

Hello all,
gmic-py could be released for all supported operating systems (especially by the Github Actions environment, which is MacOS, Windows and Linux), for each new libgmic Git version tag, as long as unit tests and builds keep working, which should be quite stable if I dedicate more time. For now new gmic-py versions have not been done for a long time, because of my doing other things in life.
I just do not know how to get a build system (Github Action… or another non-Github platform is preferable) to be triggered from the outside, when libgmic tag is released. There could be REST API call or so… Any ideas?

the gmic-blender project could also benefit from this…
The pipeline would be:

  • the (lib)gmic project gets a new git tag
  • the gmic-py project gets notified of new libgmic and builds and tests for macos, linux, (windows when ready) then pushes to pypi.org
  • the gmic-blender project gets notified of new gmic-py release and builds a single cross-platform gmic-blender addon
  • I sleep in the meantime and fix and improve gmic-py very few times a year (or community friends do), without taking much care of releases…

The Github project to project triggering feasibility is unclear to me… unless with some daemon running, which I could script… only if Github or some other service is not able to achieve this already.