0

I am working on a stereo vision project. My goal is to locate the 3D-coordinate of a point on a target that marked by a laser point.

I do the stereo calibration with full size pictures. After getting the parameters, "initUndistortRectifyMap" is applied to get the mapping data "map1" and "map2".

cv.initUndistortRectifyMap( cameraMatrix, distCoeffs, R, newCameraMatrix, size, m1type[, map1[, map2]] ) -> map1, map2

Since my target is just a small area and I would like to increase my acquiring fps, My cameras acquire the ROI instead of full size pictures.

Here comes my problem. Can I just map the ROI of an image instead of full picture? It is easy to map the same size picture as map1 and map2 with remap function, however, how can I just map the ROI of the picture.

cv.remap( src, map1, map2, interpolation[, dst[, borderMode[, borderValue]]] ) -> dst

Note, I try to crop the ROI of the "map1" and "map2" but it is not simply mapping pixels from source picture to destination picture. According to https://stackoverflow.com/a/34265822/18306909, I can not directly use map_x and map_y to get the destination of ROI.

As stated in the docs you refer to, it is dst(x, y) = src(map_x(x, y), map_y(x, y)). Transforming points dst -> src is easy (lookup in map_x and map_y), but the OP wants the other (more natural) direction: src -> dst. This is admittingly confusing because cv::remap works "inversely" (for numerical stability reasons). I.e., in order to map an image src -> dst, you supply a mapping from dst -> src. Unfortunately, that's only efficient when transforming many points on a regular grid (i.e. image). Transforming a single random point is pretty difficult. – pasbi Feb 24, 2021 at 10:17

  • I think the right way is to ajust the cameramatrix to your ROI (shift the principal point) and to use that virtual ubimage camera already during cv.initUndistortRectifyMap – Micka Feb 25 '22 at 10:17
  • 1
    if the camera merely crops the sensor data differently, shifting the principal point will be enough. if it does different binning, or even resampling, fx/fy will need scaling as well -- the effect on those maps is that shifting means addition/subtraction. -- distortion coefficients may need to be discarded and reestimated entirely. iirc the distortion equations have inconvenient formulations – Christoph Rackwitz Feb 25 '22 at 10:39
  • I think my question is similar to https://stackoverflow.com/questions/53701924/how-can-you-rectify-cropped-stereo-images-in-opencv – yctsaiiiii Mar 01 '22 at 09:16
  • I guess I need to adjust the camera matrix, however, I am not sure how to implement it. Please let me know if anyone has the same experience. Also, I Will come back and provide the implementation once I success. – yctsaiiiii Mar 01 '22 at 09:19
  • If I remember correctly, `remap` works in the opposite direction (it maps destination to origin). Maybe the easy solution is to pad the image with zeros to the expected resolution, so that intrinsic parameters are left unchanged? – decadenza Apr 04 '22 at 10:02

0 Answers0