Skip to content

ofxOpenCv: wrap OpenCV 5, keep OpenCV 4 - #8563

Open
danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:ofxopencv-cv5-compat
Open

danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:ofxopencv-cv5-compat

Conversation

@danoli3

@danoli3 danoli3 commented Sep 18, 2026

Copy link
Copy Markdown
Member

What

ofxOpenCv still uses OpenCV's legacy C API (IplImage, cvCopy, CV_INTER_NN, cv::cvarrToMat, cvFindContours, …). OpenCV 5 removed that API entirely, so a system OpenCV 5 install fails to compile the addon.

This showed up on MSYS2 ucrt64 when the pinned OpenCV 4.13.0-7 package could not be fetched and pacman fell back to mingw-w64-ucrt-x86_64-opencv 5.0.0. install_dependencies.sh already rewrote pkg-config to opencv5, then allAddonsExample died on:

  • IplImage was not declared
  • CV_INTER_NN was not declared
  • cv::cvarrToMat was not declared

MSYS2 is still being compiled against OpenCV 4; this is the fallback path.

Approach

Keep the public ofxOpenCv API. Branch on CV_MAJOR_VERSION:

OpenCV 4 OpenCV 5
Types real IplImage / CvMat via imgproc_c.h shim structs over cv::Mat
cv* helpers OpenCV C API thin wrappers around cv::resize / cvtColor / …
getCvMat() / Haar / undistort ofxCvToMatcv::cvarrToMat ofxCvToMat → ROI-aware cv::Mat view
contours cvFindContours + CvSeq cv::findContours

Haar CascadeClassifier lives in contrib xobjdetect on OpenCV 5; the compat header includes it when present (MSYS2's opencv 5 package ships it).

Also

  • addon_config.mk still defaults to opencv4. Install scripts now select opencv5 / opencv4 / opencv from pkg-config (MSYS2 + Linux distros).
  • MSYS2 still prefers the pinned 4.x package; 5.x fallback should compile.
  • Two CV examples that called cv::cvarrToMat now use getCvMat().

Test plan

  • MSYS2 ucrt64 with pinned OpenCV 4.13 (current path)
  • MSYS2 ucrt64 with OpenCV 5 fallback (pkg-config opencv5)
  • Linux with libopencv-dev / opencv4
  • allAddonsExample and opencv contour / Haar examples

OpenCV 5 removed the legacy C API (IplImage, cvarrToMat, CV_INTER_NN,
cvFindContours, …). MSYS2 already falls back to opencv 5.x when the
pinned 4.13 package is missing, which then fails to compile ofxOpenCv.

Add a compatibility layer that:
- keeps the OpenCV 4 path (imgproc_c.h + cv::cvarrToMat)
- shims IplImage/CvMat and the cv* helpers ofxOpenCv actually calls on
  OpenCV 5, wrapping cv::Mat
- uses cv::findContours for blob detection on OpenCV 5
- routes getCvMat / Haar / undistort through ofxCvToMat

Install scripts now pick opencv5, opencv4, or opencv via pkg-config.
MSYS2 still prefers the pinned 4.x package; the 5.x fallback should
compile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant