-215 opencv type_error ai_generated true

cv::error: (-215:Assertion failed) (map1.type() == CV_32FC2 || map1.type() == CV_16SC2) in function 'remap'

ID: opencv/remap-invalid-map-type

Also available as: JSON · Markdown · 中文
85%Fix Rate
88%Confidence
1Evidence
2023-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.0 active
4.8.1 active
4.10.0 active

Root Cause

The map array passed to cv::remap has an unsupported data type; only CV_32FC2 or CV_16SC2 are accepted for the first map.

generic

中文

传递给 cv::remap 的映射数组数据类型不受支持;第一个映射仅接受 CV_32FC2 或 CV_16SC2。

Official Documentation

https://docs.opencv.org/4.x/da/d54/group__imgproc__transform.html#ga5ae0f1347a0e5b9e8f8f1f0a5b7c3e1f

Workarounds

  1. 95% success Ensure map1 is created with CV_32FC2 type: cv::Mat map1(rows, cols, CV_32FC2); then fill with floating-point coordinates.
    Ensure map1 is created with CV_32FC2 type: cv::Mat map1(rows, cols, CV_32FC2); then fill with floating-point coordinates.
  2. 85% success If using initUndistortRectifyMap, verify the output map type is CV_32FC2 or CV_16SC2 by checking the m1type parameter passed to the function.
    If using initUndistortRectifyMap, verify the output map type is CV_32FC2 or CV_16SC2 by checking the m1type parameter passed to the function.

中文步骤

  1. 确保 map1 使用 CV_32FC2 类型创建:cv::Mat map1(rows, cols, CV_32FC2); 然后填充浮点坐标。
  2. 如果使用 initUndistortRectifyMap,通过检查传递给函数的 m1type 参数,验证输出映射类型为 CV_32FC2 或 CV_16SC2。

Dead Ends

Common approaches that don't work:

  1. 75% fail

    remap requires exactly CV_32FC2 (two-channel float) or CV_16SC2 (two-channel signed short) for the first map; other types cause assertion failure regardless of conversion.

  2. 90% fail

    The function expects map1 to contain (x,y) coordinates; swapping reverses the mapping logic and may produce distorted output or a different assertion error.