手写Findhomography,能否考虑引入ocvm中
futz12 opened this issue · 1 comments
futz12 commented
手写过Findhomography(在不显著增加体积情况下,增加一些功能),个人感觉比较有用。能否考虑引入ocvm中
// 对OpenCV的findHomography的重写,利用SVD求解
cv::Mat Findhomography(std::vector<cv::Point2f> src, std::vector<cv::Point2f> target) {
// 求解系统为 A*X - B = 0
const int n = src.size();
float x[9] = {0};
cv::Mat A = cv::Mat::zeros(2 * n, 8, CV_32F);
cv::Mat B = cv::Mat::zeros(2 * n, 1, CV_32F);
cv::Mat X(8, 1, CV_32F, x);
for (int i = 0; i < n; i++) {
A.at<float>(i, 0) = src[i].x;
A.at<float>(i + n, 3) = src[i].x;
A.at<float>(i, 1) = src[i].y;
A.at<float>(i + n, 4) = src[i].y;
A.at<float>(i, 2) = 1;
A.at<float>(i + n, 5) = 1;
A.at<float>(i, 6) = -src[i].x * target[i].x;
A.at<float>(i, 7) = -src[i].y * target[i].x;
A.at<float>(i + n, 6) = -src[i].x * target[i].y;
A.at<float>(i + n, 7) = -src[i].y * target[i].y;
B.at<float>(i, 0) = target[i].x;
B.at<float>(i + n, 0) = target[i].y;
}
cv::solve(A, B, X, cv::DECOMP_SVD);
x[8] = 1;
cv::Mat H = cv::Mat(3, 3, CV_32F, x).clone();
return H;
}
···
nihui commented
如果你的实现和标准 opencv findHomography 行为保持一致,欢迎 pull request