Yalantis/uCrop · error · CImgArgumentException
load_camera(): Invalid request for camera #%u (no more than…
Error message
load_camera(): Invalid request for camera #%u (no more than 100 cameras can be managed simultaneously).
What it means
CImg manages a fixed static array of 64 cv::VideoCapture handles for load_camera(); requesting a camera_index >= 64 is rejected up-front with CImgArgumentException (note: the message text saying '100 cameras' is a stale comment — the real limit is 64).
Solutions
- Keep camera_index within 0..63; map higher device numbers to a smaller logical index.
- Release cameras (load_camera with release_camera=true, or stop captures) before opening more.
- Use cv::VideoCapture directly for more than 64 concurrent cameras.
Example fix
// before
img.load_camera(70); // throws
// after
if (cameraIndex < 64) img.load_camera(cameraIndex);
else throw std::runtime_error("camera index must be < 64"); Defensive patterns
Strategy: validation
Validate before calling
if (cameraIndex >= 64) throw std::invalid_argument("camera index must be < 64"); Try / catch
try { img.load_camera(cameraIndex); }
catch (CImgArgumentException& e) { /* clamp or remap index */ } Prevention
- Clamp/validate camera indices before opening
- Reuse a small pool of camera slots and release captures when done
- Do not blindly enumerate /dev/video* indices past 63
When it happens
Trigger: Calling load_camera(camera_index) with camera_index >= 64 (or any loop that enumerates cameras past index 63) when compiled with cimg_use_opencv.
Common situations: Probing /dev/video devices with a large range in a loop; passing a device ID from an external config that uses higher numbering; off-by-one assumptions about camera indexing.
Related errors
- load_camera(): Failed to initialize camera #%u.
- load_camera(): Failed to retrieve a %ux%u frame from camera…
- _cimg2cvmat() : Instance image is empty.
- _cimg2cvmat() : Invalid number of channels (should be '1'…
- _cvmat2cimg() : pixel type
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/53b1156a087967d8.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:60079
return res;
}
#endif
//! Load image from a camera stream, using OpenCV.
/**
\param index Index of the camera to capture images from (from 0 to 63).
\param capture_width Width of the desired image ('0' stands for default value).
\param capture_height Height of the desired image ('0' stands for default value).
\param skip_frames Number of frames to skip before the capture.
\param release_camera Tells if the camera resource must be released at the end of the method.
**/
CImg<T>& 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) {
#ifdef cimg_use_opencv
if (camera_index>=64)
throw CImgArgumentException(_cimg_instance
"load_camera(): Invalid request for camera #%u "
"(no more than 100 cameras can be managed simultaneously).",
cimg_instance,
camera_index);
static cv::VideoCapture *captures[64] = {};
static unsigned int captures_w[64], captures_h[64];
if (release_camera) {
cimg::mutex(9);
if (captures[camera_index]) captures[camera_index]->release();
delete captures[camera_index];
captures[camera_index] = 0;
captures_w[camera_index] = captures_h[camera_index] = 0;
cimg::mutex(9,0);
return *this;
}
if (!captures[camera_index]) {
cimg::mutex(9);
captures[camera_index] = new cv::VideoCapture(camera_index);View on GitHub (pinned to f788b534b4)