opencvを使用して、空の駐車場にあるすべての駐車スポットを自動的に見つけて見つけようとしています。
現在、画像をしきい値設定し、キャニーエッジ検出を適用し、確率的ハフラインを使用して各駐車スポットをマークするラインを見つけるコードがあります。
次に、プログラムは線と線を構成する点を描画します
コードは次のとおりです。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int threshold_value = 150;
int threshold_type = 0;;
int const max_value = 255;
int const max_type = 4;
int const max_BINARY_value = 255;
int houghthresh = 50;
char* trackbar_value = "Value";
char* window_name = "Find Lines";
int main(int argc, char** argv)
{
const char* filename = argc >= 2 ? argv[1] : "pic1.jpg";
VideoCapture cap(0);
Mat src, dst, cdst, tdst, bgrdst;
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
createTrackbar( trackbar_value,
window_name, &threshold_value,
max_value);
while(1)
{
cap >> src;
cvtColor(src, dst, CV_RGB2GRAY);
threshold( dst, tdst, threshold_value, max_BINARY_value,threshold_type );
Canny(tdst, cdst, 50, 200, 3);
cvtColor(tdst, bgrdst, CV_GRAY2BGR);
vector<Vec4i> lines;
HoughLinesP(cdst, lines, 1, CV_PI/180, houghthresh, 50, 10 );
for( size_t i = 0; i < lines.size(); i++ )
{
Vec4i l = lines[i];
line( bgrdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,255,0), 2, CV_AA);
circle( bgrdst,
Point(l[0], l[1]),
5,
Scalar( 0, 0, 255 ),
-1,
8 );
circle( bgrdst,
Point(l[2], l[3]),
5,
Scalar( 0, 0, 255 ),
-1,
8 );
}
imshow("source", src);
imshow(window_name, bgrdst);
waitKey(1);
}
return 0;
}
現在、私の主な問題は、各駐車スペースの場所を見つけるためにラインデータを外挿する方法を理解することです。私の目標は、opencvに駐車スペースを見つけてもらい、各駐車スペースにスポットのラベルが付いた長方形を描くことです。
出力画像に示されているように、opencvは2つのエンドポイント以外のライン上の複数のポイントを検出しているため、現在使用している方法にはいくつかの大きな問題があると思います。そのため、opencvを使用して2つの隣接するエンドポイントを接続するのが非常に難しくなる可能性があります。
凸包の使用について何か読んだのですが、それが何をするのか、どのように機能するのか正確にはわかりません。
どんな助けでもありがたいです。これが私のプログラムからの出力画像です:http: //imageshack.us/photo/my-images/22/test1hl.png/