環境 :
この講義の 8 ページ目では、OpenCV のHoughLines関数がライン パラメーターrhoとthetaの N x 2 配列を返し、これはlinesという配列に格納されていると述べています。
次に、これらの角度から実際に線を作成するために、いくつかの式を用意し、後でline関数を使用します。式は、以下のコードで説明されています。
コード :
//Assuming we start our program with the Input Image as shown below.
//This array will be used for storing rho and theta as N x 2 array
vector<Vec2f> lines;
//The input bw_roi is a canny image with detected edges
HoughLines(bw_roi, lines, 1, CV_PI/180, 70, 0, 0); '
//These formulae below do the line estimation based on rho and theta
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point2d pt1, pt2;
double m;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
//When we use 1000 below we get Observation 1 output.
//But if we use 200, we get Observation 2 output.
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
//This line function is independent of HoughLines function
//and is used for drawing any type of line in OpenCV
line(frame, pt1, pt2, Scalar(0,0,255), 3, LINE_AA);
}
入力画像:
観察 1:
観察 2:
問題:
上記のコードで、a、-a、b、-b で乗算した数値をいじると、さまざまな長さの行が得られます。観察 2 は、1000 の代わりに 200 を掛けたときに得られました (観察 1 につながります)。
詳細については、上記のコードの 18 行目と 19 行目のコメントを参照してください。
質問:
HoughLines 出力から線を描画するとき、線の開始点と終了点をどのように制御できますか?
たとえば、観測 2 の右車線 (左上隅から右下を指す赤い線) を画面の右下から開始し、画面の左上を指すようにします (左車線の鏡像のように) )。