使用OpenCV检测停车位 [英] Using OpenCV to detect parking spots

查看:1213
本文介绍了使用OpenCV检测停车位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用opencv自动查找并找到空旷停车场内的所有停车位。

I am trying to use opencv to automatically find and locate all parking spots in an empty parking lot.

目前,我有一个阈值图像的代码,适用canny边缘检测,然后使用概率hough线找到标记每个停车位的线。

Currently, I have a code that thresholds the image, applies canny edge detection, and then uses probabilistic hough lines to find the lines that mark each parking spot.

程序然后绘制线条和构成线条的点数

The program then draws the lines and the points that make up the lines

以下是代码:

#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找到停车位,并在每个停车位上绘制矩形,并在上面标注点。

Currently, my main problem is figuring out how to extrapolate the line data to find the locations of each parking space. My goal is to have opencv find the parking spaces and draw out rectangles on each parking space with a number labeling the spots.

我认为我目前正在使用的方法存在一些主要问题,因为如输出图像所示,opencv检测到除2之外的其他线路上的多个点端点。这可能会使用opencv很难连接两个相邻的端点。

I think there are some major problems with the method I am currently using, because as shown in the output images, opencv is detecting multiple points on the line other than the 2 endpoints. That might make it very hard to use opencv to connect 2 adjacent endpoints.

我读过一些关于使用凸包的信息,但我不确定它是做什么的以及它是如何做的作品。

I read something about using convex hull, but I am not exactly sure what it does and how it works.

任何帮助将不胜感激。
以下是我程序的输出图像:
http ://imageshack.us/photo/my-images/22/test1hl.png/

Any help will be appreciated. Here are the output images from my program: http://imageshack.us/photo/my-images/22/test1hl.png/

http://imageshack.us/photo/my-images/822/test2lw.png/

推荐答案

考虑细化二进制图像,然后检测终点和分支点。这是基于所提供的图像的一个这样的结果;终点为红色,分支点为蓝色。

Consider thinning your binary image, and then detect the end points and the branch points. Here is one such result based on the images provided; end points are in red and branch points are in blue.

现在您可以找到停车位的位置。一对蓝点总是通过单个边连接。每个蓝点连接到两个或三个红点。然后有几种方法可以找到由两个蓝点和两个红点组成的停车位,最简单的是沿着这条线:找到最近的一对红点,其中一个点连接到某个蓝点,另一个红点连接到另一个蓝点。此步骤还可以通过检查所考虑边缘的平行线的接近程度来补充。

Now you can find the locations of the parking spaces. A pair of blue dots is always connected by a single edge. Each blue dot is connected to either two or three red points. Then there are several ways to find the parking space formed by two blue dots and two red dots, the simplest is along the lines: find the closest pair of red dots where one dot is connected to a certain blue dot, and the other red point is connected to the other blue dot. This step can also be complemented by checking how close to parallel lines are the edges considered.

这篇关于使用OpenCV检测停车位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆