【问题标题】:Can anybody explain cvRemap with a code using cvRemap in OpenCV?任何人都可以在 OpenCV 中使用 cvRemap 的代码来解释 cvRemap 吗?
【发布时间】:2026-02-05 08:10:02
【问题描述】:

OpenCV 用户知道 cvRemap 用于进行几何变换。 mapx 和 mapy 参数是提供映射的数据结构 目标图像中的信息。 我可以创建两个整数数组,其中包含从 1 到 1024 或从 1 到 768 的随机值 如果我处理图像(1024 X 768) 然后让 mapx 和 mapy 分配这些值? 然后在 cvRemap() 中使用它们? 它会完成这项工作还是使用 mapx 和 mapy 的唯一方法是使用函数 cvUndistortMap() 为其分配值? 我想知道,因为我想扭曲图像。 以防万一告诉你,我也已经签出了Learning OpenCV这本书。

【问题讨论】:

    标签: opencv


    【解决方案1】:

    我使用 cvRemap 来应用失真校正。 map_x 部分是图像分辨率,并为每个像素存储要应用的 x 偏移量,而 map_y 部分与 y 偏移量相同。

    在不失真的情况下

    # create map_x/map_y
    self.map_x = cvCreateImage(cvGetSize(self.image), IPL_DEPTH_32F, 1)
    self.map_y = cvCreateImage(cvGetSize(self.image), IPL_DEPTH_32F, 1)
    # I know the camera intrisic already so create a distortion map out
    # of it for each image pixel
    # this defined where each pixel has to go so the image is no longer
    # distorded
    cvInitUndistortMap(self.intrinsic, self.distortion, self.map_x, self.map_y)
    # later in the code:
    # "image_raw" is the distorted image, i want to store the undistorted into
    # "self.image"
    cvRemap(image_raw, self.image, self.map_x, self.map_y)
    

    因此:map_x/map_y 是浮点值,在图像分辨率中,就像 1024x768 中的两个图像。 cvRemap 中发生的事情基本上是这样的

    orig_pixel = input_image[x,y]
    new_x = map_x[x,y]
    new_y = map_y[x,y]
    output_image[new_x,new_y] = orig_pixel
    

    你想用这个做什么样的几何变换?

    【讨论】:

      最近更新 更多