sách gpt4 ăn đã đi

c++ - 在 OpenCV 中调用 stereoRectify 导致异常 : invalid frame pointer

In lại 作者:搜寻专家 更新时间:2023-10-31 01:06:14 25 4
mua khóa gpt4 giày nike

对于我的雇主,我正在将已实现的图像校正方法的结果与相应的 OpenCV 实现的结果进行比较。但是,一旦调用 OpenCV 函数就会抛出异常。

OpenCV校正函数的头部是

void stereoRectify(InputArray cameraMatrix1, InputArray distCoeffs1, 
InputArray cameraMatrix2, InputArray distCoeffs2,
Size imageSize, InputArray R, InputArray T, OutputArray R1,
OutputArray R2, OutputArray P1, OutputArray P2,
OutputArray Q, int flags=CALIB_ZERO_DISPARITY,
double alpha=-1, Size newImageSize=Size(),
Rect* validPixROI1=0, Rect* validPixROI2=0);

作为 InputArray 和 OutputArray 我使用类型的对象

cv::Mát

.由于相机的校准是已知的,我用正确的值手动初始化了输入矩阵。根据 corresponding documentation page,矩阵具有以下大小:

cv::Mat cameraMatrix1; // 3x3 matrix
cv::Mat distCoeffs1; // 5x1 matrix for five distortion coefficients
cv::Mat cameraMatrix2; // 3x3 matrix
cv::Mat distCoeffs2; // 5x1 matrix
cv::Mat R; // 3x3 matrix, rotation left to right camera
cv::Mat T; // 4x1 matrix, translation left to right proj. center

我这样初始化矩阵:

T = cv::Mat::zeros(4, 1, CV_64F);
T.at(0, 0) = proj_center_right.x - proj_center_left.x;
T.at(1, 0) = proj_center_right.y - proj_center_left.y;
T.at(2, 0) = proj_center_right.z - proj_center_left.z;

对于所有矩阵,我都使用 CV_64F 作为值类型。

我在控制台上打印了矩阵的内容,以验证所有值都设置正确(四舍五入):

cameraMatrix1:
| 6654; 0, 1231 |
| 0; 6654; 1037 |
| 0; 0; 1 |

distCoeffs1:
| -4.57e-009; 5.94e-017; 3.68e-008; -3.46e-008; 6.37e-023 |

cameraMatrix2:
| 6689; 0, 1249 |
| 0; 6689; 991 |
| 0; 0; 1|

distCoeffs2:
| -4.72e-009; 2.88e-016; 6.2e-008; -8.74e-008; -8.18e-024 |

R:
| 0.87; -0.003, -0.46 |
| 0.001; 0.999; -0.003 |
| 0.46; 0.002; 0.89 |

T:
| 228; 0; 0; 0 |

到目前为止,一切对我来说似乎都是正确的。此外,我将输出矩阵初始化为单位矩阵(使用 cv::Mat::eye(...)),具有以下大小:

cv::Mat R1; // 3x3 matrix
cv::Mat R2; // 3x3 matrix
cv::Mat P1; // 3x4 matrix
cv::Mat P2; // 3x4 matrix
cv::Mat Q; // 4x4 matrix

最后,所需的 cv::Size 对象设置为宽度 2448 和高度 2050(相机获取的图像的大小)。一旦我将参数传递给 OpenCV 作为

cv::stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imgSize, R, T, R1, R2, P1, P2, Q);

,程序崩溃。控制台上的错误消息状态

opencv_core248, void cdecl cv::error(class cv::Exception const & ptr64) +0x152 (invalid frame pointer)

由于所有矩阵和 cv::Size 对象都已正确初始化,所以我看不出有什么问题。对于任何建议,我很感激。

câu trả lời hay nhất

您的代码最初在 gemm() 中对我来说崩溃了,将 T 更改为 3x1 vec 似乎有所帮助:

// Mat_ used here for easy << initialization
cv::Mat_ cameraMatrix1(3,3); // 3x3 matrix
cv::Mat_ distCoeffs1(5,1); // 5x1 matrix for five distortion coefficients
cv::Mat_ cameraMatrix2(3,3); // 3x3 matrix
cv::Mat_ distCoeffs2(5,1); // 5x1 matrix
cv::Mat_ R(3,3); // 3x3 matrix, rotation left to right camera
cv::Mat_ T(3,1); // * 3 * x1 matrix, translation left to right proj. center
// ^^ that's the main diff to your code, (3,1) instead of (4,1)

cameraMatrix1 << 6654, 0, 1231, 0, 6654, 1037, 0, 0, 1;
cameraMatrix2 << 6689, 0, 1249, 0, 6689, 991, 0, 0, 1;
distCoeffs1 << -4.57e-009, 5.94e-017, 3.68e-008, -3.46e-008, 6.37e-023;
distCoeffs2 << -4.72e-009, 2.88e-016, 6.2e-008, -8.74e-008, -8.18e-024;
R << 0.87, -0.003, -0.46, 0.001, 0.999, -0.003, 0.46, 0.002, 0.89;
T << 228, 0, 0;

cv::Mat R1,R2,P1,P2,Q; // you're safe to leave OutpuArrays empty !
Size imgSize(3000,3000); // wild guess from you cameramat ( not that it matters )

cv::stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imgSize, R, T, R1, R2, P1, P2, Q);

cerr << "Q" << Q << endl;

关于c++ - 在 OpenCV 中调用 stereoRectify 导致异常 : invalid frame pointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21163815/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress