Debian Bookworm - cv2 import - osgeo::proj::io::ParsingException

Hello,

I had installed OpenCV on an RPI4 with Bookworm to use optical flow, and during the same boot session, it worked fine (using calcOpticalFlowFarneback).

The O/S advised of updates available, so I proceeded with those. Opencv was fine for the remainder of the same boot session. I shutdown the Pi, rebooted the next day and was met with the following error in python 3.11.2. Worked it for hours, still no joy. Why this cartographic parsing error occurs is way beyond my knowledge of Python (gdal/qgis).

terminate called after throwing an instance of ‘osgeo::proj::io::ParsingException’

---------- FINISHED ----------
exit code: 6 status: 1

OpenCV can depend on GDAL for some file I/O capabilities.

depends on what all OpenCVs you installed, both with apt and with pip and with conda, and what virtual environments you might or might not have created.

usually, a system update doesn’t affect OpenCV because you’re supposed to not bother with C++ but use Python instead, install the Python package using pip from PyPI, and not use any system package.

Finally, I clued in on an import I had not used that was in an example, and that fixed the problem. Adding the following before importing cv2 solved it:

import argparse

for real? if that did it, I can’t imagine how that’d be possible. there is no import-time interaction between python built-in modules and python.

I am entry level Python, only done perhaps 100 hours of coding, and am also surprised. I uninstalled and reinstalled a couple of times, never resolved it, but after putting that line in (which I didn’t see why the example had it), problem went away. However, I booted the Pi this morning and the problem is back, regardless of that line. So why is it that the last install worked, once again I reboot, and back to the original problem.
Quite a hassle every time I need to work my laser speckle position sensing imager using optical flow as Scikit-image was 40x slower than using OpenCV (3 ms vs 130 ms per frame 64x64 pixels mono 8 bit)… I digress.

Only way that works at the moment is to remove python-opencv, reboot, reinstall. use it… Repeat at next boot.

I don’t envy you.

you could try your luck with python’s virtual environments. you can install whatever into such an environment and it won’t affect the system.

I think these environments are even shielded from the system environment, so even if you had opencv-python installed at the system level, you would initially not see that in the activated environment. you’d have to install the package, or create an environment with the option of system packages being visible.

Merci, my Googling came to the same conclusion. I’ll try that out tonight after work.