我正在尝试在OpenCV 3.2中校准鱼眼相机。这是一个代码:
Mat newCamMat;
cameraMatrix= getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 0, imageSize, 0); //Does not change anything
fisheye::estimateNewCameraMatrixForUndistortRectify(cameraMatrix, distCoeffs, imageSize,
Matx33d::eye(), newCamMat, 1);
fisheye::initUndistortRectifyMap(cameraMatrix, distCoeffs, Matx33d::eye(), newCamMat, imageSize,
CV_16SC2, map1, map2);
我在校准中使用了这些标志:
fisheye::CALIB_FIX_SKEW | fisheye::CALIB_RECOMPUTE_EXTRINSIC | fisheye::CALIB_CHECK_COND
我希望在没有可用区域周围的黑色区域的情况下裁剪图像。对于非鱼眼校准,我通过设置alpha来实现。对于鱼眼,我不知道如何改变它。任何建议?
答案 0 :(得分:0)
您可以使用蒙版setTo
将Alpha通道值设置为透明。
Mat img = imread("fisheye.png",-1), gray, mask;
cvtColor(img, gray, cv::COLOR_BGR2GRAY);
threshold(gray, mask, 0, 255, cv::THRESH_BINARY_INV);
cvtColor(img, img, cv::COLOR_BGR2BGRA);
img.setTo(Scalar(0,0,0,0),mask);