0
我是新來的OpenCV,我使用此代碼找到4個最外線爲了獲得角落的圖像中的矩形對象。opencv的確定4條最外角線從矩形對象
cv::Mat input(toOcv(surface));
cv::Mat output;
cv::medianBlur(input, output, 21);
Mat dst, cdst;
Canny(input, dst, 50, 200, 3);
cvtColor(dst, cdst, CV_GRAY2BGR);
//Standard Hough
vector<Vec2f> lines;
HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0);
// Draw the lines
for (size_t i = 0; i < lines.size(); i++)
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000 * (-b));
pt1.y = cvRound(y0 + 1000 * (a));
pt2.x = cvRound(x0 - 1000 * (-b));
pt2.y = cvRound(y0 - 1000 * (a));
line(cdst, pt1, pt2, Scalar(rand() % 255, rand() % 255, rand() % 255), 2, CV_AA);
}
我已經使用標準Hough變換來檢測線。
現在我有太多的線,但我只想要4個最外面的線,所以我可以檢測圖像的角落。
任何幫助將不勝感激! 在此先感謝。
需要注意的是有這個問題沒有確切的解決方案。 –