c++ - 如何在 OpenCV 中使用双类型映射进行重新映射

标签 c++ opencv floating-point double remap

cv::remap() 的问题:

我正在为我的图像坐标使用 double 值,并希望使用 cv::remap() 来创建扭曲的图像。

但是,OpenCV 只允许我使用 CV_32FC1 (float) 作为 map 类型,而不是 CV_64FC1 ()。

除了在重新映射之前将我的 double 值类型转换为 float 并为 cv::remap() 使用浮点类型映射外,是还有别的办法吗?

代码片段:

Eigen::Vector2d distort(Eigen::Vector2d & pointUndistorted);    

int main(int argc, char** argv) {
    cv::Mat image, dst;
    image = cv::imread(argv[1], 1);
    Eigen::Vector2d pointUndistorted;
    Eigen::Vector2d pointDistorted;
    int w = image.rows;
    int h = image.cols;
    cv::Mat map1(w,h,CV_64FC1);
    cv::Mat map2(w,h,CV_64FC1);

    for (int wIdx = 0; wIdx < w; ++wIdx)
    {
        for (int hIdx = 0; hIdx < h; ++hIdx)
        {
            pointUndistorted << (double)wIdx / (double)w -0.5, (double)hIdx / (double)h -0.5;
            pointDistorted = distort(pointUndistorted);

            map1.at<double>(wIdx,hIdx) = (pointDistorted[0] + 0.5) * h;
            map2.at<double>(wIdx,hIdx) = (pointDistorted[1] + 0.5) * w;
        }
    }

    cv::remap(image, dst, map1, map2, cv::INTER_LINEAR);
}

这给了我以下错误:

OpenCV Error: Assertion failed (((map1.type() == (((5) & ((1 << 3) - 1)) + (((2)-1) << 3)) || map1.type() == (((3) & ((1 << 3) - 1)) + (((2)-1) << 3))) && map2.empty()) || (map1.type() == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3)) && map2.type() == (((5) & ((1 << 3) - 1)) + (((1)-1) << 3)))) in remap, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgproc/src/imgwarp.cpp, line 1840

最佳答案

感谢@Yakk 的建议:

我用 map.convertTo(map, CV_32FC1) 破解了一个变通方法,这对我来说工作得很好。

关于c++ - 如何在 OpenCV 中使用双类型映射进行重新映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50135414/

相关文章:

c++ - ROS 中一个文件中的订阅者和发布者

python - 苹果操作系统 : Using python to capture screenshots of a specific window

java - 如何在JAVA中提取IEEE 754浮点表示

c++ - double 到 unsigned int/char

mysql - 检查以确保字段中的所有值都是 MySQL 中的整数

子类中的 C++ 收紧函数参数类型

c++ - 引用表溢出(最大值=1024)

c++ - Visual Studio 2008 中缺少代码分析节点

opencv - 获取 OpenCV 的当前 FPS

python - 如何从 cv2.HoughCircles 中找到最佳圆