{"record":{"id":"6b3ac75d26d4feae","repo":"Yalantis/uCrop","slug":"load-camera-this-function-requires-features-fro","errorCode":null,"errorMessage":"load_camera(): This function requires features from the OpenCV library ('-Dcimg_use_opencv' must be defined).","messagePattern":"load_camera\\(\\): This function requires features from the OpenCV library \\('-Dcimg_use_opencv' must be defined\\)\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":60134,"sourceCode":"        captures[camera_index]->set(_cimg_cap_prop_frame_height,capture_height);\n        captures_h[camera_index] = capture_height;\n      }\n      for (unsigned int i = 0; i<skip_frames; ++i) captures[camera_index]->grab();\n      cv::Mat cvimg;\n      captures[camera_index]->read(cvimg);\n      if (cvimg.empty()) {\n        cimg::mutex(9,0);\n        load_camera(camera_index,0,0,0,true); // Release camera\n        throw CImgIOException(_cimg_instance\n                              \"load_camera(): Failed to retrieve a %ux%u frame from camera #%u.\",\n                              cimg_instance,\n                              capture_width,capture_height,camera_index);\n      } else _cvmat2cimg(cvimg).move_to(*this);\n      cimg::mutex(9,0);\n      return *this;\n#else\n      cimg::unused(camera_index,skip_frames,release_camera,capture_width,capture_height);\n      throw CImgIOException(_cimg_instance\n                            \"load_camera(): This function requires features from the OpenCV library \"\n                            \"('-Dcimg_use_opencv' must be defined).\",\n                            cimg_instance);\n#endif\n    }\n\n    //! Load image from a camera stream, using OpenCV \\newinstance.\n    static CImg<T> get_load_camera(const unsigned int camera_index=0,\n                                   const unsigned int capture_width=0, const unsigned int capture_height=0,\n                                   const unsigned int skip_frames=0, const bool release_camera=true) {\n      return CImg<T>().load_camera(camera_index,capture_width,capture_height,skip_frames,release_camera);\n    }\n\n    //! Load image using various non-native ways.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    CImg<T>& load_other(const char *const filename) {","sourceCodeStart":60116,"sourceCodeEnd":60152,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L60116-L60152","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nimg.load_camera(0); // throws: no OpenCV in build\n// after (build config)\n// CXXFLAGS: -Dcimg_use_opencv -I/usr/include/opencv4\n// LDFLAGS: -lopencv_core -lopencv_videoio\nimg.load_camera(0);","handlingStrategy":"fallback","validationCode":"#ifndef cimg_use_opencv\n#error \"load_camera() requires -Dcimg_use_opencv and OpenCV linked\"\n#endif","typeGuard":null,"tryCatchPattern":"try { img.load_camera(idx); }\ncatch (CImgIOException&) { /* use platform camera API or fail fast at startup */ }","preventionTips":["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"],"tags":["cimg","opencv","compile-time","feature-not-enabled"],"backgroundTag":"feature-not-enabled","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}