Yalantis/uCrop · error · CImgIOException
load_camera(): This function requires features from the Open
Error message
load_camera(): This function requires features from the OpenCV library ('-Dcimg_use_opencv' must be defined). What it means
load_camera() is only implemented when CImg is compiled with OpenCV support (cimg_use_opencv defined). Without it, the #else branch throws CImgIOException telling the user the build lacks OpenCV features. The camera code path is entirely absent from the binary.
Source
Thrown at ucrop/src/main/jni/CImg.h:60134
captures[camera_index]->set(_cimg_cap_prop_frame_height,capture_height);
captures_h[camera_index] = capture_height;
}
for (unsigned int i = 0; i<skip_frames; ++i) captures[camera_index]->grab();
cv::Mat cvimg;
captures[camera_index]->read(cvimg);
if (cvimg.empty()) {
cimg::mutex(9,0);
load_camera(camera_index,0,0,0,true); // Release camera
throw CImgIOException(_cimg_instance
"load_camera(): Failed to retrieve a %ux%u frame from camera #%u.",
cimg_instance,
capture_width,capture_height,camera_index);
} else _cvmat2cimg(cvimg).move_to(*this);
cimg::mutex(9,0);
return *this;
#else
cimg::unused(camera_index,skip_frames,release_camera,capture_width,capture_height);
throw CImgIOException(_cimg_instance
"load_camera(): This function requires features from the OpenCV library "
"('-Dcimg_use_opencv' must be defined).",
cimg_instance);
#endif
}
//! Load image from a camera stream, using OpenCV \newinstance.
static CImg<T> get_load_camera(const unsigned int camera_index=0,
const unsigned int capture_width=0, const unsigned int capture_height=0,
const unsigned int skip_frames=0, const bool release_camera=true) {
return CImg<T>().load_camera(camera_index,capture_width,capture_height,skip_frames,release_camera);
}
//! Load image using various non-native ways.
/**
\param filename Filename, as a C-string.
**/
CImg<T>& load_other(const char *const filename) {View on GitHub (pinned to f788b534b4)
Solutions
- Recompile defining cimg_use_opencv and link against OpenCV (add -Dcimg_use_opencv -lopencv_videoio -lopencv_core ...).
- If OpenCV is not an option, capture frames with a platform API (V4L2, AVFoundation, CameraX) and load the buffers via CImg.
- Add a runtime/build-time feature check and avoid load_camera() in builds without it.
Example fix
// before img.load_camera(0); // throws: no OpenCV in build // after (build config) // CXXFLAGS: -Dcimg_use_opencv -I/usr/include/opencv4 // LDFLAGS: -lopencv_core -lopencv_videoio img.load_camera(0);
Defensive patterns
Strategy: fallback
Validate before calling
#ifndef cimg_use_opencv #error "load_camera() requires -Dcimg_use_opencv and OpenCV linked" #endif
Try / catch
try { img.load_camera(idx); }
catch (CImgIOException&) { /* use platform camera API or fail fast at startup */ } Prevention
- Fail at startup/build time if camera features are required but cimg_use_opencv is undefined
- Document required compile flags and link libraries in the build system
- Feature-detect at runtime and disable camera UI paths when unsupported
When it happens
Trigger: Any call to load_camera() in a build where cimg_use_opencv was not defined at compile time (missing -Dcimg_use_opencv and OpenCV headers/libs in the include/link line).
Common situations: Vendored CImg.h in an Android NDK/JNI build (like ucrop) compiled without OpenCV; third-party prebuilt CImg without the flag; dropping CImg.h into a project and expecting camera support out of the box.
Related errors
- save_video(): Cannot output streamed video, as this requires
- load_magick(): Unable to load file '%s' unless libMagick++ i
- _cimg2cvmat() : Instance image is empty.
- _cimg2cvmat() : Invalid number of channels (should be '1' or
- _cvmat2cimg() : pixel type '%s' is not supported.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/6b3ac75d26d4feae.
Report an issue: GitHub.