cv::Mat srcI420(cv::Size(W, H * 3 / 2), CV_8UC1); int W = 1280, H = 720; //Assume resolution of Y plane is 1280x720 //Pointer to Y plane unsigned char *pY = (unsigned char*)srcI420.data; //Y plane as cv::Mat, resolution of srcY is 1280x720 cv::Mat srcY = cv::Mat(cv::Size(W, H), CV_8UC1, (void*)pY); //UV plane as cv::Mat, resolution of srcUV is 640x360X2 (in memory buffer, UV plane is placed after Y). cv::Mat srcUV = cv::Mat(cv::Size(W/2, H/2), CV_8UC2, (void*)(pY + W*H)); cv::Mat map1, map2; cv::initUndistortRectifyMap(K, D, R, K, out_dim, CV_16SC2, map1, map2); // Resize mapx and mapy by a factor of x2 in each axis, and divide each element in the map by 2 cv::Mat shrunk_mapx, shrunk_mapy; cv::resize(map1, shrunk_mapx, cv::Size(map1.cols/2, map1.rows / 2)); cv::resize(map2, shrunk_mapy, cv::Size(map1.cols/2, map1.rows / 2)); shrunk_mapx /= 2; shrunk_mapy /= 2; // Remap Y cv::remap(srcY, srcY, map1, map2, cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar(0)); // Remap U and V using shunk maps cv::remap(srcUV , srcUV , shrunk_mapx, shrunk_mapy, cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar(128));